Compare commits

..

5 Commits

Author SHA1 Message Date
Tariel Hlontsi 014eccba7e Merge branch 'dev' 2016-10-19 20:00:05 +03:00
Tariel Hlontsi 493e3c1f10 Merge branch 'dev' 2016-09-10 19:21:11 +03:00
Tariel Hlontsi 3ace787762 Merge branch 'dev' 2016-07-24 11:11:25 +03:00
Tariel Hlontsi 0a13a72df2 Merge branch 'dev' 2016-05-15 17:04:05 +03:00
Tariel Hlontsi eaa2ba996e Merge branch 'dev' 2016-05-03 18:49:24 +03:00
14 changed files with 465 additions and 546 deletions

View File

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -177,6 +177,7 @@ public class MainActivity extends Activity implements View.ActivityCallback {
SetModel model = new SetModel();
view.setPresenter(presenter);
//presenter.setView(view);
presenter.setModel(model);
model.setPresenter(presenter);

View File

@ -47,7 +47,7 @@ public class ItemModel implements Model.Item {
public void onEvent(Message event) {
switch (event.what) {
case Event.SET_ITEMS_LOAD_ERROR:
case Event.SET_ITEMS_LOAD_ERROR : // TODO check
if (presenter != null) {
if (packedQty == -1)
packedQty = presenter.getCurrentSet().getPackedQty();
@ -116,17 +116,17 @@ public class ItemModel implements Model.Item {
case Event.ITEM_FROM_SET_DELETED:
executeQuery();
break;
case Event.ITEM_DELETED:
case Event.ITEM_DELETED :
break;
case Event.ITEM_PACKED:
case Event.ITEM_PACKED :
executeQuery();
if (getPackedQty() == getActiveItemsCount())
NetworkUtil.sendGoogleAnalyticsEvent("SET PACKED", String.format("Set #%d", currentSet));
break;
case Event.ITEM_UNPACKED:
case Event.ITEM_UNPACKED :
executeQuery();
break;
case Event.ITEM_INSERTED:
case Event.ITEM_INSERTED :
break;
case Event.SET_RESTORE_COMPLETED:
executeQuery();
@ -184,11 +184,7 @@ public class ItemModel implements Model.Item {
@Override
public Item getItemByPosition(int position) {
Item ret = null;
try {
ret = itemsCache.get(position);
} catch (Exception ex) {
}
ret = itemsCache.get(position);
return ret;
}
@ -211,28 +207,12 @@ public class ItemModel implements Model.Item {
@Override
public int getHeaderId(int position) {
int ret;
try {
ret = itemsCache.get(position).getCategory();
} catch (Exception ex) {
try {
ret = itemsCache.get(position-1).getCategory();
} catch (Exception e) {
ret = -1;
}
}
return ret;
return itemsCache.get(position).getCategory();
}
@Override
public int getItemId(int position) {
int ret;
try {
ret = itemsCache.get(position).getId();
} catch (Exception ex) {
ret = -1;
}
return ret;
return itemsCache.get(position).getId();
}
@Override

View File

@ -153,14 +153,12 @@ public class ItemListPresenter implements Presenter.ItemList {
@Override
public void setVisibility() {
/*if (model.getPackedQty() > 0 && model.getPackedQty() == model.getActiveItemsCount()) {
//showPackedItems();
} else*/ if (model.getPackedQty() > 0) {
if (model.getPackedQty() > 0 && model.getPackedQty() == model.getActiveItemsCount()) {
footer.setVisibility(android.view.View.VISIBLE);
} else if ( model.getPackedQty() > 0) {
footer.setVisibility(android.view.View.VISIBLE);
adapter.addEmptyToTheEnd();
} else {
footer.setVisibility(android.view.View.GONE);
adapter.removeEmptyFromTheEnd();
}
}

View File

@ -39,72 +39,66 @@ public class PackedListPresenter extends ItemListPresenter {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try {
if (savedInstanceState != null)
set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY);
else
set = getView().getSet();
android.view.View view = inflater.inflate(R.layout.fragment_packed_list, container, false);
LinearLayoutManager llm = new LinearLayoutManager(getActivityContext());
recycler = (RecyclerView) view.findViewById(R.id.items_recycler);
recycler.setLayoutManager(llm);
recycler.setAdapter(adapter);
if (savedInstanceState != null)
set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY);
else
set = getView().getSet();
android.view.View view = inflater.inflate(R.layout.fragment_packed_list, container, false);
LinearLayoutManager llm = new LinearLayoutManager(getActivityContext());
recycler = (RecyclerView) view.findViewById(R.id.items_recycler);
recycler.setLayoutManager(llm);
recycler.setAdapter(adapter);
final StickyHeaderDecoration decoration = new StickyHeaderDecoration(adapter);
recycler.addItemDecoration(decoration);
//recycler.addItemDecoration(new DividerDecoration(getActivityContext()));
recycler.addItemDecoration(new DividerDecoration2(getActivityContext(), R.drawable.divider, Util.dp2px(getAppContext(), 16)));
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
decoration.invalidateHeaders();
}
});
recycler.setHasFixedSize(true);
model.executeQuery();
recycler.scrollToPosition(model.getLastVisiblePosition());
backToList = (TextView) view.findViewById(R.id.back_to_list);
packedCount = (TextView) view.findViewById(R.id.header_packed_count);
unpackButton = (Button) view.findViewById(R.id.unpack_button);
setVisibility();
unpackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
model.unpackSet(set.getId());
}
});
backToList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment fragment = (Fragment) getView();
if (fragment != null)
fragment.getFragmentManager().popBackStack();
}
});
Activity activity = (Activity) getActivityContext();
if (activity != null) {
activity.invalidateOptionsMenu();
ActionBar actionBar = activity.getActionBar();
if (actionBar != null) {
actionBar.show();
actionBar.setTitle(set.getName());
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
}
final StickyHeaderDecoration decoration = new StickyHeaderDecoration(adapter);
recycler.addItemDecoration(decoration);
//recycler.addItemDecoration(new DividerDecoration(getActivityContext()));
recycler.addItemDecoration(new DividerDecoration2(getActivityContext(), R.drawable.divider, Util.dp2px(getAppContext(), 16)));
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
decoration.invalidateHeaders();
}
NetworkUtil.sendGoogleAnalyticsScreen(TAG);
return view;
});
recycler.setHasFixedSize(true);
model.executeQuery();
recycler.scrollToPosition(model.getLastVisiblePosition());
backToList = (TextView) view.findViewById(R.id.back_to_list);
packedCount = (TextView) view.findViewById(R.id.header_packed_count);
unpackButton = (Button) view.findViewById(R.id.unpack_button);
} catch (Exception ex) {
setVisibility();
unpackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
model.unpackSet(set.getId());
}
});
backToList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Fragment fragment = (Fragment) getView();
if (fragment != null)
fragment.getFragmentManager().popBackStack();
}
});
Activity activity = (Activity) getActivityContext();
if (activity != null) {
activity.invalidateOptionsMenu();
ActionBar actionBar = activity.getActionBar();
if (actionBar != null) {
actionBar.show();
actionBar.setTitle(set.getName());
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayShowCustomEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
return null;
NetworkUtil.sendGoogleAnalyticsScreen(TAG);
return view;
}

View File

@ -28,21 +28,16 @@ public class AddListAdapter extends RecyclerView.Adapter<AddItemViewHolder> {
@Override
public void onBindViewHolder(AddItemViewHolder holder, int position) {
try {
final Item item = presenter.getModel().getItemByPosition(position);
holder.name.setText(item.getName());
holder.category.setText(presenter.getModel().getCategoryById(item.getCategory()).getName());
holder.alreadyInList.setVisibility(item.InList ? View.VISIBLE : View.GONE);
holder.item.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.onAddItemClick(item);
}
});
} catch (Exception ex) {
}
final Item item = presenter.getModel().getItemByPosition(position);
holder.name.setText(item.getName());
holder.category.setText(presenter.getModel().getCategoryById(item.getCategory()).getName());
holder.alreadyInList.setVisibility(item.InList ? View.VISIBLE : View.GONE);
holder.item.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.onAddItemClick(item);
}
});
}
@Override

View File

@ -37,114 +37,110 @@ public class ItemDetailAdapter extends RecyclerView.Adapter<ItemViewHolder> {
@Override
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
try {
final Item item = presenter.getModel().getCurrentItem();
holder.cb_item.setChecked(item.isPacked());
holder.tv_text.setText(item.getName());
holder.im_info.setVisibility(View.GONE);
if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.cb_item.setVisibility(View.GONE);
} else {
holder.cb_item.setVisibility(View.VISIBLE);
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
holder.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.cb_item.isChecked()) {
pack(item);
} else {
unpack(item);
}
}
});
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
menuLayout.removeAllViews();
// create menu items here
if (!item.isPendingRemoval()) {
// create "leave at home" item
SwipeMenuItem leaveAtHomeItem = new SwipeMenuItem(menu.getContext());
// set id
leaveAtHomeItem.setId(ItemListAdapter.ID_LEAVE_AT_HOME);
// set item background
leaveAtHomeItem.setBackground(R.color.colorLeaveAtHomeBtnBackground);
// set item width
leaveAtHomeItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
leaveAtHomeItem.setTitle(R.string.leave_at_home_button);
// set item title font size
leaveAtHomeItem.setTitleSize(14);
// set item title font color
leaveAtHomeItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(leaveAtHomeItem);
} else {
// create "add to bag" item
SwipeMenuItem addToBagItem = new SwipeMenuItem(menu.getContext());
// set id
addToBagItem.setId(ItemListAdapter.ID_ADD_TO_BAG);
// set item background
addToBagItem.setBackground(R.color.colorAddToBagBtnBackground);
// set item width
addToBagItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
addToBagItem.setTitle(R.string.add_to_bag_button);
// set item title font size
addToBagItem.setTitleSize(14);
// set item title font color
addToBagItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(addToBagItem);
// create "return to list" item
SwipeMenuItem returnToListItem = new SwipeMenuItem(menu.getContext());
// set id
returnToListItem.setId(ItemListAdapter.ID_RETURN_TO_LIST);
// set item background
returnToListItem.setBackground(R.color.colorReturnToListBtnBackground);
// set item width
returnToListItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
returnToListItem.setTitle(R.string.return_to_list_button);
// set item title font size
returnToListItem.setTitleSize(14);
// set item title font color
returnToListItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(returnToListItem);
}
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case ItemListAdapter.ID_DELETE:
// no delete
break;
case ItemListAdapter.ID_LEAVE_AT_HOME:
leave(item);
break;
case ItemListAdapter.ID_RETURN_TO_LIST:
leaveCancel(item);
break;
case ItemListAdapter.ID_ADD_TO_BAG:
pack(item);
break;
}
menuLayout.notifyOnMenuItemClick();
}
};
menuLayout.addMenu(menu, onClickListener);
} catch (Exception ex) {
final Item item = presenter.getModel().getCurrentItem();
holder.cb_item.setChecked(item.isPacked());
holder.tv_text.setText(item.getName());
holder.im_info.setVisibility(View.GONE);
if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.cb_item.setVisibility(View.GONE);
} else {
holder.cb_item.setVisibility(View.VISIBLE);
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
holder.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.cb_item.isChecked()) {
pack(item);
} else {
unpack(item);
}
}
});
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
menuLayout.removeAllViews();
// create menu items here
if (!item.isPendingRemoval()) {
// create "leave at home" item
SwipeMenuItem leaveAtHomeItem = new SwipeMenuItem(menu.getContext());
// set id
leaveAtHomeItem.setId(ItemListAdapter.ID_LEAVE_AT_HOME);
// set item background
leaveAtHomeItem.setBackground(R.color.colorLeaveAtHomeBtnBackground);
// set item width
leaveAtHomeItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
leaveAtHomeItem.setTitle(R.string.leave_at_home_button);
// set item title font size
leaveAtHomeItem.setTitleSize(14);
// set item title font color
leaveAtHomeItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(leaveAtHomeItem);
} else {
// create "add to bag" item
SwipeMenuItem addToBagItem = new SwipeMenuItem(menu.getContext());
// set id
addToBagItem.setId(ItemListAdapter.ID_ADD_TO_BAG);
// set item background
addToBagItem.setBackground(R.color.colorAddToBagBtnBackground);
// set item width
addToBagItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
addToBagItem.setTitle(R.string.add_to_bag_button);
// set item title font size
addToBagItem.setTitleSize(14);
// set item title font color
addToBagItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(addToBagItem);
// create "return to list" item
SwipeMenuItem returnToListItem = new SwipeMenuItem(menu.getContext());
// set id
returnToListItem.setId(ItemListAdapter.ID_RETURN_TO_LIST);
// set item background
returnToListItem.setBackground(R.color.colorReturnToListBtnBackground);
// set item width
returnToListItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
returnToListItem.setTitle(R.string.return_to_list_button);
// set item title font size
returnToListItem.setTitleSize(14);
// set item title font color
returnToListItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(returnToListItem);
}
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case ItemListAdapter.ID_DELETE:
// no delete
break;
case ItemListAdapter.ID_LEAVE_AT_HOME:
leave(item);
break;
case ItemListAdapter.ID_RETURN_TO_LIST:
leaveCancel(item);
break;
case ItemListAdapter.ID_ADD_TO_BAG:
pack(item);
break;
}
menuLayout.notifyOnMenuItemClick();
}
};
menuLayout.addMenu(menu, onClickListener);
}
@Override

View File

@ -34,7 +34,6 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
protected Presenter.ItemList presenter;
protected boolean checkAll;
protected int addToCount = 0;
public ItemListAdapter(Presenter.ItemList presenter) {
this.presenter = presenter;
@ -42,8 +41,8 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
@Override
public int getItemCount() {
int ret = presenter.getModel().getItemsCount();
return ret + addToCount;
int res = presenter.getModel().getItemsCount();
return res;
}
@Override
@ -55,145 +54,135 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
@Override
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
try {
final Item item = presenter.getModel().getItemByPosition(position);
if (item != null) {
setVisibility(holder, View.VISIBLE);
holder.cb_item.setChecked(checkAll);
holder.tv_text.setText(item.getName());
if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.cb_item.setVisibility(View.GONE);
final Item item = presenter.getModel().getItemByPosition(position);
holder.cb_item.setChecked(checkAll);
holder.tv_text.setText(item.getName());
//holder.tv_text.setTypeface(mainFace);
if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.cb_item.setVisibility(View.GONE);
} else {
holder.cb_item.setVisibility(View.VISIBLE);
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
holder.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.cb_item.isChecked()) {
pack(item);
} else {
//holder.cb_item.setVisibility(View.VISIBLE);
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
holder.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.cb_item.isChecked()) {
pack(item);
} else {
unpack(item);
}
}
});
holder.im_info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.showDetails(position);
}
});
final SwipeMenuLayout menuLayout = (SwipeMenuLayout) holder.menu;
final SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
menuLayout.removeAllViews();
// create menu items here
if (!item.isPendingRemoval()) {
// create "leave at home" item
SwipeMenuItem leaveAtHomeItem = new SwipeMenuItem(menu.getContext());
// set id
leaveAtHomeItem.setId(ID_LEAVE_AT_HOME);
// set item background
leaveAtHomeItem.setBackground(R.color.colorLeaveAtHomeBtnBackground);
// set item width
leaveAtHomeItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
leaveAtHomeItem.setTitle(R.string.leave_at_home_button);
// set item title font size
leaveAtHomeItem.setTitleSize(14);
// set item title font color
leaveAtHomeItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(leaveAtHomeItem);
} else {
// create "add to bag" item
SwipeMenuItem addToBagItem = new SwipeMenuItem(menu.getContext());
// set id
addToBagItem.setId(ID_ADD_TO_BAG);
// set item background
addToBagItem.setBackground(R.color.colorAddToBagBtnBackground);
// set item width
addToBagItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
addToBagItem.setTitle(R.string.add_to_bag_button);
// set item title font size
addToBagItem.setTitleSize(14);
// set item title font color
addToBagItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(addToBagItem);
// create "return to list" item
SwipeMenuItem returnToListItem = new SwipeMenuItem(menu.getContext());
// set id
returnToListItem.setId(ID_RETURN_TO_LIST);
// set item background
returnToListItem.setBackground(R.color.colorReturnToListBtnBackground);
// set item width
returnToListItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
returnToListItem.setTitle(R.string.return_to_list_button);
// set item title font size
returnToListItem.setTitleSize(14);
// set item title font color
returnToListItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(returnToListItem);
}
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(menu.getContext());
// set id
deleteItem.setId(ID_DELETE);
// set item background
deleteItem.setBackground(R.color.colorDeleteBtnBackground);
// set item width
deleteItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
deleteItem.setTitle(R.string.delete_button);
// set item title font size
deleteItem.setTitleSize(14);
// set item title font color
deleteItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(deleteItem);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case ID_DELETE:
remove(item);
break;
case ID_LEAVE_AT_HOME:
leave(item);
break;
case ID_RETURN_TO_LIST:
leaveCancel(item);
break;
case ID_ADD_TO_BAG:
pack(item);
break;
}
menuLayout.notifyOnMenuItemClick();
}
};
menuLayout.addMenu(menu, onClickListener);
} else {
if (presenter.getModel().getPackedQty() > 0) {
setVisibility(holder, View.GONE);
unpack(item);
}
}
});
holder.im_info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.showDetails(position);
}
});
} catch (Exception ex) {
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
final SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
menuLayout.removeAllViews();
// create menu items here
if (!item.isPendingRemoval()) {
// create "leave at home" item
SwipeMenuItem leaveAtHomeItem = new SwipeMenuItem(menu.getContext());
// set id
leaveAtHomeItem.setId(ID_LEAVE_AT_HOME);
// set item background
leaveAtHomeItem.setBackground(R.color.colorLeaveAtHomeBtnBackground);
// set item width
leaveAtHomeItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
leaveAtHomeItem.setTitle(R.string.leave_at_home_button);
// set item title font size
leaveAtHomeItem.setTitleSize(14);
// set item title font color
leaveAtHomeItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(leaveAtHomeItem);
} else {
// create "add to bag" item
SwipeMenuItem addToBagItem = new SwipeMenuItem(menu.getContext());
// set id
addToBagItem.setId(ID_ADD_TO_BAG);
// set item background
addToBagItem.setBackground(R.color.colorAddToBagBtnBackground);
// set item width
addToBagItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
addToBagItem.setTitle(R.string.add_to_bag_button);
// set item title font size
addToBagItem.setTitleSize(14);
// set item title font color
addToBagItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(addToBagItem);
// create "return to list" item
SwipeMenuItem returnToListItem = new SwipeMenuItem(menu.getContext());
// set id
returnToListItem.setId(ID_RETURN_TO_LIST);
// set item background
returnToListItem.setBackground(R.color.colorReturnToListBtnBackground);
// set item width
returnToListItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
returnToListItem.setTitle(R.string.return_to_list_button);
// set item title font size
returnToListItem.setTitleSize(14);
// set item title font color
returnToListItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(returnToListItem);
}
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(menu.getContext());
// set id
deleteItem.setId(ID_DELETE);
// set item background
deleteItem.setBackground(R.color.colorDeleteBtnBackground);
// set item width
deleteItem.setWidth(Util.dp2px(presenter.getActivityContext(),120));
// set item title
deleteItem.setTitle(R.string.delete_button);
// set item title font size
deleteItem.setTitleSize(14);
// set item title font color
deleteItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(deleteItem);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case ID_DELETE:
remove(item);
break;
case ID_LEAVE_AT_HOME:
leave(item);
break;
case ID_RETURN_TO_LIST:
leaveCancel(item);
break;
case ID_ADD_TO_BAG:
pack(item);
break;
}
menuLayout.notifyOnMenuItemClick();
}
};
menuLayout.addMenu(menu, onClickListener);
}
@Override
@ -268,22 +257,4 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
public void setCheckAll(boolean checkAll) {
this.checkAll = checkAll;
}
public void addEmptyToTheEnd() {
addToCount = 1;
notifyDataSetChanged();
}
public void removeEmptyFromTheEnd() {
addToCount = 0;
notifyDataSetChanged();
}
private void setVisibility(ItemViewHolder holder, int visibility) {
if (holder != null) {
holder.cb_item.setVisibility(visibility);
holder.im_info.setVisibility(visibility);
holder.menu.setVisibility(visibility);
holder.tv_text.setVisibility(visibility);
}
}
}

View File

@ -22,145 +22,135 @@ public class PackedListAdapter extends ItemListAdapter {
super(presenter);
}
@Override
public int getItemCount() {
return presenter.getModel().getItemsCount();
}
@Override
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
try {
final Item item = presenter.getModel().getItemByPosition(position);
holder.cb_item.setChecked(checkAll);
holder.tv_text.setText(item.getName());
if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.cb_item.setVisibility(View.GONE);
} else {
holder.cb_item.setVisibility(View.VISIBLE);
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
holder.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.cb_item.isChecked()) {
pack(item);
} else {
unpack(item);
}
}
});
holder.im_info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.showDetails(position);
}
});
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
menuLayout.removeAllViews();
// create menu items here
if (!item.isPendingRemoval()) {
// create "leave at home" item
SwipeMenuItem leaveAtHomeItem = new SwipeMenuItem(menu.getContext());
// set id
leaveAtHomeItem.setId(ID_LEAVE_AT_HOME);
// set item background
leaveAtHomeItem.setBackground(R.color.colorLeaveAtHomeBtnBackground);
// set item width
leaveAtHomeItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
leaveAtHomeItem.setTitle(R.string.leave_at_home_button);
// set item title font size
leaveAtHomeItem.setTitleSize(14);
// set item title font color
leaveAtHomeItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(leaveAtHomeItem);
} else {
// create "add to bag" item
SwipeMenuItem addToBagItem = new SwipeMenuItem(menu.getContext());
// set id
addToBagItem.setId(ID_ADD_TO_BAG);
// set item background
addToBagItem.setBackground(R.color.colorAddToBagBtnBackground);
// set item width
addToBagItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
addToBagItem.setTitle(R.string.add_to_bag_button);
// set item title font size
addToBagItem.setTitleSize(14);
// set item title font color
addToBagItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(addToBagItem);
// create "return to list" item
SwipeMenuItem returnToListItem = new SwipeMenuItem(menu.getContext());
// set id
returnToListItem.setId(ID_RETURN_TO_LIST);
// set item background
returnToListItem.setBackground(R.color.colorReturnToListBtnBackground);
// set item width
returnToListItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
returnToListItem.setTitle(R.string.return_to_list_button);
// set item title font size
returnToListItem.setTitleSize(14);
// set item title font color
returnToListItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(returnToListItem);
}
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(menu.getContext());
// set id
deleteItem.setId(ID_DELETE);
// set item background
deleteItem.setBackground(R.color.colorDeleteBtnBackground);
// set item width
deleteItem.setWidth(Util.dp2px(presenter.getActivityContext(),120));
// set item title
deleteItem.setTitle(R.string.delete_button);
// set item title font size
deleteItem.setTitleSize(14);
// set item title font color
deleteItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(deleteItem);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case ID_DELETE:
remove(item);
break;
case ID_LEAVE_AT_HOME:
leave(item);
break;
case ID_RETURN_TO_LIST:
unpack(item);
break;
case ID_ADD_TO_BAG:
pack(item);
break;
}
menuLayout.notifyOnMenuItemClick();
}
};
menuLayout.addMenu(menu, onClickListener);
} catch (Exception ex) {
final Item item = presenter.getModel().getItemByPosition(position);
holder.cb_item.setChecked(checkAll);
holder.tv_text.setText(item.getName());
if (item.isPendingRemoval()) {
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.cb_item.setVisibility(View.GONE);
} else {
holder.cb_item.setVisibility(View.VISIBLE);
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
holder.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(View v) {
if (holder.cb_item.isChecked()) {
pack(item);
} else {
unpack(item);
}
}
});
holder.im_info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
presenter.showDetails(position);
}
});
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
menuLayout.removeAllViews();
// create menu items here
if (!item.isPendingRemoval()) {
// create "leave at home" item
SwipeMenuItem leaveAtHomeItem = new SwipeMenuItem(menu.getContext());
// set id
leaveAtHomeItem.setId(ID_LEAVE_AT_HOME);
// set item background
leaveAtHomeItem.setBackground(R.color.colorLeaveAtHomeBtnBackground);
// set item width
leaveAtHomeItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
leaveAtHomeItem.setTitle(R.string.leave_at_home_button);
// set item title font size
leaveAtHomeItem.setTitleSize(14);
// set item title font color
leaveAtHomeItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(leaveAtHomeItem);
} else {
// create "add to bag" item
SwipeMenuItem addToBagItem = new SwipeMenuItem(menu.getContext());
// set id
addToBagItem.setId(ID_ADD_TO_BAG);
// set item background
addToBagItem.setBackground(R.color.colorAddToBagBtnBackground);
// set item width
addToBagItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
addToBagItem.setTitle(R.string.add_to_bag_button);
// set item title font size
addToBagItem.setTitleSize(14);
// set item title font color
addToBagItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(addToBagItem);
// create "return to list" item
SwipeMenuItem returnToListItem = new SwipeMenuItem(menu.getContext());
// set id
returnToListItem.setId(ID_RETURN_TO_LIST);
// set item background
returnToListItem.setBackground(R.color.colorReturnToListBtnBackground);
// set item width
returnToListItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
// set item title
returnToListItem.setTitle(R.string.return_to_list_button);
// set item title font size
returnToListItem.setTitleSize(14);
// set item title font color
returnToListItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(returnToListItem);
}
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(menu.getContext());
// set id
deleteItem.setId(ID_DELETE);
// set item background
deleteItem.setBackground(R.color.colorDeleteBtnBackground);
// set item width
deleteItem.setWidth(Util.dp2px(presenter.getActivityContext(),120));
// set item title
deleteItem.setTitle(R.string.delete_button);
// set item title font size
deleteItem.setTitleSize(14);
// set item title font color
deleteItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(deleteItem);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case ID_DELETE:
remove(item);
break;
case ID_LEAVE_AT_HOME:
leave(item);
break;
case ID_RETURN_TO_LIST:
unpack(item);
break;
case ID_ADD_TO_BAG:
pack(item);
break;
}
menuLayout.notifyOnMenuItemClick();
}
};
menuLayout.addMenu(menu, onClickListener);
}
@Override

View File

@ -25,42 +25,40 @@ public class SetListAdapter extends RecyclerView.Adapter<SetViewHolder> impleme
@Override
public void onBindViewHolder(final SetViewHolder holder, int position) {
try {
final com.hikapro.backpack.model.entities.Set set = presenter.getModel().getSetByPosition(position);
if (rightBracket == null || rightBracket.isEmpty()) {
final com.hikapro.backpack.model.entities.Set set = presenter.getModel().getSetByPosition(position);
if (presenter.getActivityContext() != null)
this.rightBracket = presenter.getActivityContext().getResources().
getString(R.string.right_angle_bracket);
else
this.rightBracket = "";
}
holder.textView.setText(set.getName() + " " + rightBracket);
holder.textView.setTypeface(App.getMainFace());
String info = String.format("%s %d / %d",
presenter.getActivityContext().getResources().getString(R.string.packed),
set.getPackedQty(),
set.getActiveQty());
holder.setInfo.setText(info);
holder.cardView.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
presenter.showItemList(set);
}
});
holder.cardView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
presenter.onLongClick(holder);
return false;
}
});
holder.applyBackground(presenter.getAppContext(), set.getId());
} catch (Exception ex) {
if (rightBracket == null || rightBracket.isEmpty()) {
if (presenter.getActivityContext() != null)
this.rightBracket = presenter.getActivityContext().getResources().
getString(R.string.right_angle_bracket);
else
this.rightBracket = "";
}
holder.textView.setText(set.getName() + " " + rightBracket);
holder.textView.setTypeface(App.getMainFace());
String info = String.format("%s %d / %d",
presenter.getActivityContext().getResources().getString(R.string.packed),
set.getPackedQty(),
set.getActiveQty());
holder.setInfo.setText(info);
holder.cardView.setOnClickListener(new android.view.View.OnClickListener() {
@Override
public void onClick(android.view.View v) {
presenter.showItemList(set);
}
});
holder.cardView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
presenter.onLongClick(holder);
return false;
}
});
holder.applyBackground(presenter.getAppContext(), set.getId());
}
@Override

View File

@ -78,11 +78,7 @@ public class SwipeMenuItem {
}
public void setBackground(int resId) {
try {
this.background = mContext.getResources().getDrawable(resId);
} catch (Exception ex) { ;
}
this.background = mContext.getResources().getDrawable(resId);
}
public int getWidth() {

View File

@ -21,7 +21,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/item_height"
android:layout_height="70dp"
android:orientation="vertical"
android:id="@+id/item_list_footer"
android:layout_gravity="bottom"

View File

@ -9,7 +9,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/item_height"
android:layout_height="70dp"
android:orientation="vertical"
android:id="@+id/item_list_header"
android:layout_gravity="top"

View File

@ -24,7 +24,7 @@
<dimen name="text_item_description">17sp</dimen>
<dimen name="card_height">150dp</dimen>
<dimen name="item_height">66dp</dimen>
<dimen name="item_height">56dp</dimen>
<dimen name="card_margin">2dp</dimen>
<dimen name="card_margin_txt">24dp</dimen>
<dimen name="card_margin_packed_top">16dp</dimen>