From 24964451d87924c41509772d4fb64918691aa83f Mon Sep 17 00:00:00 2001 From: Tariel Hlontsi Date: Tue, 3 May 2016 18:34:19 +0300 Subject: [PATCH] Bugs fixing --- .../java/hikapro/com/backpack/MainActivity.java | 10 ++++------ .../hikapro/com/backpack/model/ItemModel.java | 17 +++++++++-------- .../java/hikapro/com/backpack/model/Model.java | 2 -- .../backpack/presenter/ItemListPresenter.java | 3 ++- .../presenter/adapters/ItemListAdapter.java | 8 +++++++- .../view/fragments/ItemListFragment.java | 2 +- .../view/fragments/SetListFragment.java | 12 +++++++----- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/hikapro/com/backpack/MainActivity.java b/app/src/main/java/hikapro/com/backpack/MainActivity.java index 8034220..17865ff 100644 --- a/app/src/main/java/hikapro/com/backpack/MainActivity.java +++ b/app/src/main/java/hikapro/com/backpack/MainActivity.java @@ -38,10 +38,10 @@ public class MainActivity extends Activity implements View.ActivityCallback { stateMaintainer.init(); - if (fragmentManager.getBackStackEntryCount() == 0) { + + if (fragmentManager.getBackStackEntryCount() == 0 && savedInstanceState == null) { startSetListFragment(); } else { - Fragment fragment = fragmentManager.findFragmentByTag(SetListFragment.class.getName()); if (fragment != null) { SetListFragment view = (SetListFragment) fragment; @@ -52,7 +52,6 @@ public class MainActivity extends Activity implements View.ActivityCallback { presenter.setView(view); presenter.setModel(model); model.setPresenter(presenter); - } fragment = fragmentManager.findFragmentByTag(ItemListFragment.class.getName()); @@ -129,12 +128,11 @@ public class MainActivity extends Activity implements View.ActivityCallback { SetModel model = new SetModel(); view.setPresenter(presenter); - presenter.setView(view); + //presenter.setView(view); presenter.setModel(model); model.setPresenter(presenter); - replaceFragment(view, true, SetListFragment.class.getName()); - + replaceFragment(view, false, SetListFragment.class.getName()); stateMaintainer.put(presenter); stateMaintainer.put(model); diff --git a/app/src/main/java/hikapro/com/backpack/model/ItemModel.java b/app/src/main/java/hikapro/com/backpack/model/ItemModel.java index e63a1b4..459617b 100644 --- a/app/src/main/java/hikapro/com/backpack/model/ItemModel.java +++ b/app/src/main/java/hikapro/com/backpack/model/ItemModel.java @@ -59,10 +59,6 @@ public class ItemModel implements Model.Item { return ret; } - @Override - public int getCategoriesCount() { - return categoriesCache.size(); - } // categories <-- @@ -89,11 +85,15 @@ public class ItemModel implements Model.Item { @Override public Item findItem(int id) { + List items = cache.get(currentSet); Item item = null; - for (Item i : rawItems) { - if (i.getId() == id) { - item = i; - break; + if (items != null) + { + for (Item i : items) { + if (i.getId() == id) { + item = i; + break; + } } } return item; @@ -187,6 +187,7 @@ public class ItemModel implements Model.Item { private void sendMessage(String message) { presenter.showMessage(message); } + // events <-- // process --> diff --git a/app/src/main/java/hikapro/com/backpack/model/Model.java b/app/src/main/java/hikapro/com/backpack/model/Model.java index 08f0bdb..157a71b 100644 --- a/app/src/main/java/hikapro/com/backpack/model/Model.java +++ b/app/src/main/java/hikapro/com/backpack/model/Model.java @@ -44,12 +44,10 @@ public interface Model { void pendingRemoveCancel(hikapro.com.backpack.model.entities.Item item); int getItemsCount(); - hikapro.com.backpack.model.entities.Item findItem(int id); hikapro.com.backpack.model.entities.Item getItemByPosition(int position); hikapro.com.backpack.model.entities.Category getCategoryByPosition(int position); - int getCategoriesCount(); void setPresenter(Presenter.ItemList presenter); Presenter.ItemList getPresenter(); } diff --git a/app/src/main/java/hikapro/com/backpack/presenter/ItemListPresenter.java b/app/src/main/java/hikapro/com/backpack/presenter/ItemListPresenter.java index 28652f3..1ee0ebb 100644 --- a/app/src/main/java/hikapro/com/backpack/presenter/ItemListPresenter.java +++ b/app/src/main/java/hikapro/com/backpack/presenter/ItemListPresenter.java @@ -51,8 +51,9 @@ public class ItemListPresenter implements Presenter.ItemList { } @Override public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + /* if (savedInstanceState != null) - set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY); + set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY);*/ android.view.View view = inflater.inflate(R.layout.fragment_item_list, container, false); LinearLayoutManager llm = new LinearLayoutManager(getActivityContext()); recycler = (RecyclerView) view.findViewById(R.id.items_recycler); diff --git a/app/src/main/java/hikapro/com/backpack/presenter/adapters/ItemListAdapter.java b/app/src/main/java/hikapro/com/backpack/presenter/adapters/ItemListAdapter.java index bdc93d4..230c723 100644 --- a/app/src/main/java/hikapro/com/backpack/presenter/adapters/ItemListAdapter.java +++ b/app/src/main/java/hikapro/com/backpack/presenter/adapters/ItemListAdapter.java @@ -47,7 +47,7 @@ public class ItemListAdapter extends RecyclerView.Adapter implem } @Override - public void onBindViewHolder(ItemViewHolder holder, final int position) { + public void onBindViewHolder(final ItemViewHolder holder, final int position) { final Item item = presenter.getModel().getItemByPosition(position); if (presenter.getModel().isPendingRemoval(item)) { @@ -71,6 +71,12 @@ public class ItemListAdapter extends RecyclerView.Adapter implem holder.title.setVisibility(View.VISIBLE); holder.title.setText(item.getName()); holder.id = item.getId(); + holder.title.setOnClickListener(new android.view.View.OnClickListener() { + @Override + public void onClick(View v) { + presenter.clickItem(holder.id); + } + }); holder.categoryId = item.getCategory(); holder.itemView.setBackgroundColor(0x33FF99); holder.undoButton.setVisibility(View.GONE); diff --git a/app/src/main/java/hikapro/com/backpack/view/fragments/ItemListFragment.java b/app/src/main/java/hikapro/com/backpack/view/fragments/ItemListFragment.java index 67a4c3a..ccb05a8 100644 --- a/app/src/main/java/hikapro/com/backpack/view/fragments/ItemListFragment.java +++ b/app/src/main/java/hikapro/com/backpack/view/fragments/ItemListFragment.java @@ -105,8 +105,8 @@ public class ItemListFragment extends Fragment implements hikapro.com.backpack.v public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View view = presenter.onCreateView(inflater, container, savedInstanceState); presenter.setView(this); + View view = presenter.onCreateView(inflater, container, savedInstanceState); Log.i(this.toString(), "onCreateView"); return view; } diff --git a/app/src/main/java/hikapro/com/backpack/view/fragments/SetListFragment.java b/app/src/main/java/hikapro/com/backpack/view/fragments/SetListFragment.java index 9537794..4feaf63 100644 --- a/app/src/main/java/hikapro/com/backpack/view/fragments/SetListFragment.java +++ b/app/src/main/java/hikapro/com/backpack/view/fragments/SetListFragment.java @@ -1,6 +1,5 @@ package hikapro.com.backpack.view.fragments; - import android.app.Activity; import android.app.Fragment; import android.content.Context; @@ -15,7 +14,8 @@ import hikapro.com.backpack.model.entities.Set; import hikapro.com.backpack.presenter.Presenter; import hikapro.com.backpack.presenter.adapters.helper.sets.OnStartDragListener; -public class SetListFragment extends Fragment implements hikapro.com.backpack.view.View.SetList, OnStartDragListener{ +public class SetListFragment extends Fragment implements hikapro.com.backpack.view.View.SetList, + OnStartDragListener { private Presenter.SetList presenter; private hikapro.com.backpack.view.View.ActivityCallback activityCallback; @@ -59,10 +59,12 @@ public class SetListFragment extends Fragment implements hikapro.com.backpack.vi @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment - View view = presenter.onCreateView(inflater, container, savedInstanceState); - presenter.setView(this); Log.i(this.toString(), "onCreateView"); + // Inflate the layout for this fragment + presenter.setView(this); + View view = presenter.onCreateView(inflater, container, savedInstanceState); + + return view; } @Override