Bugs fixing

This commit is contained in:
Tariel Hlontsi 2016-05-03 18:34:19 +03:00
parent 501a3f80ca
commit 24964451d8
7 changed files with 30 additions and 24 deletions

View File

@ -38,10 +38,10 @@ public class MainActivity extends Activity implements View.ActivityCallback {
stateMaintainer.init(); stateMaintainer.init();
if (fragmentManager.getBackStackEntryCount() == 0) {
if (fragmentManager.getBackStackEntryCount() == 0 && savedInstanceState == null) {
startSetListFragment(); startSetListFragment();
} else { } else {
Fragment fragment = fragmentManager.findFragmentByTag(SetListFragment.class.getName()); Fragment fragment = fragmentManager.findFragmentByTag(SetListFragment.class.getName());
if (fragment != null) { if (fragment != null) {
SetListFragment view = (SetListFragment) fragment; SetListFragment view = (SetListFragment) fragment;
@ -52,7 +52,6 @@ public class MainActivity extends Activity implements View.ActivityCallback {
presenter.setView(view); presenter.setView(view);
presenter.setModel(model); presenter.setModel(model);
model.setPresenter(presenter); model.setPresenter(presenter);
} }
fragment = fragmentManager.findFragmentByTag(ItemListFragment.class.getName()); fragment = fragmentManager.findFragmentByTag(ItemListFragment.class.getName());
@ -129,12 +128,11 @@ public class MainActivity extends Activity implements View.ActivityCallback {
SetModel model = new SetModel(); SetModel model = new SetModel();
view.setPresenter(presenter); view.setPresenter(presenter);
presenter.setView(view); //presenter.setView(view);
presenter.setModel(model); presenter.setModel(model);
model.setPresenter(presenter); model.setPresenter(presenter);
replaceFragment(view, true, SetListFragment.class.getName()); replaceFragment(view, false, SetListFragment.class.getName());
stateMaintainer.put(presenter); stateMaintainer.put(presenter);
stateMaintainer.put(model); stateMaintainer.put(model);

View File

@ -59,10 +59,6 @@ public class ItemModel implements Model.Item {
return ret; return ret;
} }
@Override
public int getCategoriesCount() {
return categoriesCache.size();
}
// categories <-- // categories <--
@ -89,13 +85,17 @@ public class ItemModel implements Model.Item {
@Override @Override
public Item findItem(int id) { public Item findItem(int id) {
List<Item> items = cache.get(currentSet);
Item item = null; Item item = null;
for (Item i : rawItems) { if (items != null)
{
for (Item i : items) {
if (i.getId() == id) { if (i.getId() == id) {
item = i; item = i;
break; break;
} }
} }
}
return item; return item;
} }
@Override @Override
@ -187,6 +187,7 @@ public class ItemModel implements Model.Item {
private void sendMessage(String message) { private void sendMessage(String message) {
presenter.showMessage(message); presenter.showMessage(message);
} }
// events <-- // events <--
// process --> // process -->

View File

@ -44,12 +44,10 @@ public interface Model {
void pendingRemoveCancel(hikapro.com.backpack.model.entities.Item item); void pendingRemoveCancel(hikapro.com.backpack.model.entities.Item item);
int getItemsCount(); int getItemsCount();
hikapro.com.backpack.model.entities.Item findItem(int id); hikapro.com.backpack.model.entities.Item findItem(int id);
hikapro.com.backpack.model.entities.Item getItemByPosition(int position); hikapro.com.backpack.model.entities.Item getItemByPosition(int position);
hikapro.com.backpack.model.entities.Category getCategoryByPosition(int position); hikapro.com.backpack.model.entities.Category getCategoryByPosition(int position);
int getCategoriesCount();
void setPresenter(Presenter.ItemList presenter); void setPresenter(Presenter.ItemList presenter);
Presenter.ItemList getPresenter(); Presenter.ItemList getPresenter();
} }

View File

@ -51,8 +51,9 @@ public class ItemListPresenter implements Presenter.ItemList {
} }
@Override @Override
public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public android.view.View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
/*
if (savedInstanceState != null) 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); android.view.View view = inflater.inflate(R.layout.fragment_item_list, container, false);
LinearLayoutManager llm = new LinearLayoutManager(getActivityContext()); LinearLayoutManager llm = new LinearLayoutManager(getActivityContext());
recycler = (RecyclerView) view.findViewById(R.id.items_recycler); recycler = (RecyclerView) view.findViewById(R.id.items_recycler);

View File

@ -47,7 +47,7 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
} }
@Override @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); final Item item = presenter.getModel().getItemByPosition(position);
if (presenter.getModel().isPendingRemoval(item)) { if (presenter.getModel().isPendingRemoval(item)) {
@ -71,6 +71,12 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
holder.title.setVisibility(View.VISIBLE); holder.title.setVisibility(View.VISIBLE);
holder.title.setText(item.getName()); holder.title.setText(item.getName());
holder.id = item.getId(); 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.categoryId = item.getCategory();
holder.itemView.setBackgroundColor(0x33FF99); holder.itemView.setBackgroundColor(0x33FF99);
holder.undoButton.setVisibility(View.GONE); holder.undoButton.setVisibility(View.GONE);

View File

@ -105,8 +105,8 @@ public class ItemListFragment extends Fragment implements hikapro.com.backpack.v
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = presenter.onCreateView(inflater, container, savedInstanceState);
presenter.setView(this); presenter.setView(this);
View view = presenter.onCreateView(inflater, container, savedInstanceState);
Log.i(this.toString(), "onCreateView"); Log.i(this.toString(), "onCreateView");
return view; return view;
} }

View File

@ -1,6 +1,5 @@
package hikapro.com.backpack.view.fragments; package hikapro.com.backpack.view.fragments;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.Context; 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.Presenter;
import hikapro.com.backpack.presenter.adapters.helper.sets.OnStartDragListener; 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 Presenter.SetList presenter;
private hikapro.com.backpack.view.View.ActivityCallback activityCallback; private hikapro.com.backpack.view.View.ActivityCallback activityCallback;
@ -59,10 +59,12 @@ public class SetListFragment extends Fragment implements hikapro.com.backpack.vi
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = presenter.onCreateView(inflater, container, savedInstanceState);
presenter.setView(this);
Log.i(this.toString(), "onCreateView"); Log.i(this.toString(), "onCreateView");
// Inflate the layout for this fragment
presenter.setView(this);
View view = presenter.onCreateView(inflater, container, savedInstanceState);
return view; return view;
} }
@Override @Override