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();
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);

View File

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

View File

@ -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();
}

View File

@ -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);

View File

@ -47,7 +47,7 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> 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<ItemViewHolder> 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);

View File

@ -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;
}

View File

@ -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