fixed last element inaccessability and scroll crash
This commit is contained in:
parent
52b0c71eb2
commit
b09b5d4867
|
@ -37,7 +37,7 @@
|
||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<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">
|
<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">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|
|
@ -177,7 +177,6 @@ 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.setModel(model);
|
presenter.setModel(model);
|
||||||
model.setPresenter(presenter);
|
model.setPresenter(presenter);
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class ItemModel implements Model.Item {
|
||||||
public void onEvent(Message event) {
|
public void onEvent(Message event) {
|
||||||
|
|
||||||
switch (event.what) {
|
switch (event.what) {
|
||||||
case Event.SET_ITEMS_LOAD_ERROR : // TODO check
|
case Event.SET_ITEMS_LOAD_ERROR:
|
||||||
if (presenter != null) {
|
if (presenter != null) {
|
||||||
if (packedQty == -1)
|
if (packedQty == -1)
|
||||||
packedQty = presenter.getCurrentSet().getPackedQty();
|
packedQty = presenter.getCurrentSet().getPackedQty();
|
||||||
|
@ -116,17 +116,17 @@ public class ItemModel implements Model.Item {
|
||||||
case Event.ITEM_FROM_SET_DELETED:
|
case Event.ITEM_FROM_SET_DELETED:
|
||||||
executeQuery();
|
executeQuery();
|
||||||
break;
|
break;
|
||||||
case Event.ITEM_DELETED :
|
case Event.ITEM_DELETED:
|
||||||
break;
|
break;
|
||||||
case Event.ITEM_PACKED :
|
case Event.ITEM_PACKED:
|
||||||
executeQuery();
|
executeQuery();
|
||||||
if (getPackedQty() == getActiveItemsCount())
|
if (getPackedQty() == getActiveItemsCount())
|
||||||
NetworkUtil.sendGoogleAnalyticsEvent("SET PACKED", String.format("Set #%d", currentSet));
|
NetworkUtil.sendGoogleAnalyticsEvent("SET PACKED", String.format("Set #%d", currentSet));
|
||||||
break;
|
break;
|
||||||
case Event.ITEM_UNPACKED :
|
case Event.ITEM_UNPACKED:
|
||||||
executeQuery();
|
executeQuery();
|
||||||
break;
|
break;
|
||||||
case Event.ITEM_INSERTED :
|
case Event.ITEM_INSERTED:
|
||||||
break;
|
break;
|
||||||
case Event.SET_RESTORE_COMPLETED:
|
case Event.SET_RESTORE_COMPLETED:
|
||||||
executeQuery();
|
executeQuery();
|
||||||
|
@ -184,7 +184,11 @@ public class ItemModel implements Model.Item {
|
||||||
@Override
|
@Override
|
||||||
public Item getItemByPosition(int position) {
|
public Item getItemByPosition(int position) {
|
||||||
Item ret = null;
|
Item ret = null;
|
||||||
ret = itemsCache.get(position);
|
try {
|
||||||
|
ret = itemsCache.get(position);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,12 +211,28 @@ public class ItemModel implements Model.Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHeaderId(int position) {
|
public int getHeaderId(int position) {
|
||||||
return itemsCache.get(position).getCategory();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemId(int position) {
|
public int getItemId(int position) {
|
||||||
return itemsCache.get(position).getId();
|
int ret;
|
||||||
|
try {
|
||||||
|
ret = itemsCache.get(position).getId();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -153,12 +153,14 @@ public class ItemListPresenter implements Presenter.ItemList {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setVisibility() {
|
public void setVisibility() {
|
||||||
if (model.getPackedQty() > 0 && model.getPackedQty() == model.getActiveItemsCount()) {
|
/*if (model.getPackedQty() > 0 && model.getPackedQty() == model.getActiveItemsCount()) {
|
||||||
footer.setVisibility(android.view.View.VISIBLE);
|
//showPackedItems();
|
||||||
} else if ( model.getPackedQty() > 0) {
|
} else*/ if (model.getPackedQty() > 0) {
|
||||||
footer.setVisibility(android.view.View.VISIBLE);
|
footer.setVisibility(android.view.View.VISIBLE);
|
||||||
|
adapter.addEmptyToTheEnd();
|
||||||
} else {
|
} else {
|
||||||
footer.setVisibility(android.view.View.GONE);
|
footer.setVisibility(android.view.View.GONE);
|
||||||
|
adapter.removeEmptyFromTheEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,66 +39,72 @@ public class PackedListPresenter extends ItemListPresenter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
if (savedInstanceState != null)
|
try {
|
||||||
set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY);
|
if (savedInstanceState != null)
|
||||||
else
|
set = (Set) savedInstanceState.getSerializable(BUNDLE_SET_LIST_KEY);
|
||||||
set = getView().getSet();
|
else
|
||||||
android.view.View view = inflater.inflate(R.layout.fragment_packed_list, container, false);
|
set = getView().getSet();
|
||||||
LinearLayoutManager llm = new LinearLayoutManager(getActivityContext());
|
android.view.View view = inflater.inflate(R.layout.fragment_packed_list, container, false);
|
||||||
recycler = (RecyclerView) view.findViewById(R.id.items_recycler);
|
LinearLayoutManager llm = new LinearLayoutManager(getActivityContext());
|
||||||
recycler.setLayoutManager(llm);
|
recycler = (RecyclerView) view.findViewById(R.id.items_recycler);
|
||||||
recycler.setAdapter(adapter);
|
recycler.setLayoutManager(llm);
|
||||||
|
recycler.setAdapter(adapter);
|
||||||
|
|
||||||
final StickyHeaderDecoration decoration = new StickyHeaderDecoration(adapter);
|
final StickyHeaderDecoration decoration = new StickyHeaderDecoration(adapter);
|
||||||
recycler.addItemDecoration(decoration);
|
recycler.addItemDecoration(decoration);
|
||||||
//recycler.addItemDecoration(new DividerDecoration(getActivityContext()));
|
//recycler.addItemDecoration(new DividerDecoration(getActivityContext()));
|
||||||
recycler.addItemDecoration(new DividerDecoration2(getActivityContext(), R.drawable.divider, Util.dp2px(getAppContext(), 16)));
|
recycler.addItemDecoration(new DividerDecoration2(getActivityContext(), R.drawable.divider, Util.dp2px(getAppContext(), 16)));
|
||||||
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
|
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged() {
|
public void onChanged() {
|
||||||
decoration.invalidateHeaders();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
NetworkUtil.sendGoogleAnalyticsScreen(TAG);
|
||||||
recycler.setHasFixedSize(true);
|
return view;
|
||||||
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();
|
} catch (Exception ex) {
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
NetworkUtil.sendGoogleAnalyticsScreen(TAG);
|
return null;
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,16 +28,21 @@ public class AddListAdapter extends RecyclerView.Adapter<AddItemViewHolder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(AddItemViewHolder holder, int position) {
|
public void onBindViewHolder(AddItemViewHolder holder, int position) {
|
||||||
final Item item = presenter.getModel().getItemByPosition(position);
|
try {
|
||||||
holder.name.setText(item.getName());
|
final Item item = presenter.getModel().getItemByPosition(position);
|
||||||
holder.category.setText(presenter.getModel().getCategoryById(item.getCategory()).getName());
|
holder.name.setText(item.getName());
|
||||||
holder.alreadyInList.setVisibility(item.InList ? View.VISIBLE : View.GONE);
|
holder.category.setText(presenter.getModel().getCategoryById(item.getCategory()).getName());
|
||||||
holder.item.setOnClickListener(new View.OnClickListener() {
|
holder.alreadyInList.setVisibility(item.InList ? View.VISIBLE : View.GONE);
|
||||||
@Override
|
holder.item.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
@Override
|
||||||
presenter.onAddItemClick(item);
|
public void onClick(View v) {
|
||||||
}
|
presenter.onAddItemClick(item);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -37,110 +37,114 @@ public class ItemDetailAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
|
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
|
||||||
final Item item = presenter.getModel().getCurrentItem();
|
try {
|
||||||
holder.cb_item.setChecked(item.isPacked());
|
final Item item = presenter.getModel().getCurrentItem();
|
||||||
holder.tv_text.setText(item.getName());
|
holder.cb_item.setChecked(item.isPacked());
|
||||||
holder.im_info.setVisibility(View.GONE);
|
holder.tv_text.setText(item.getName());
|
||||||
if (item.isPendingRemoval()) {
|
holder.im_info.setVisibility(View.GONE);
|
||||||
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
if (item.isPendingRemoval()) {
|
||||||
holder.cb_item.setVisibility(View.GONE);
|
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||||
} else {
|
holder.cb_item.setVisibility(View.GONE);
|
||||||
holder.cb_item.setVisibility(View.VISIBLE);
|
} else {
|
||||||
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
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.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
|
||||||
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
|
@Override
|
||||||
SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
|
public void onClick(View v) {
|
||||||
|
if (holder.cb_item.isChecked()) {
|
||||||
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);
|
pack(item);
|
||||||
break;
|
} else {
|
||||||
|
unpack(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
menuLayout.notifyOnMenuItemClick();
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
menuLayout.addMenu(menu, onClickListener);
|
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) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
||||||
|
|
||||||
protected Presenter.ItemList presenter;
|
protected Presenter.ItemList presenter;
|
||||||
protected boolean checkAll;
|
protected boolean checkAll;
|
||||||
|
protected int addToCount = 0;
|
||||||
|
|
||||||
public ItemListAdapter(Presenter.ItemList presenter) {
|
public ItemListAdapter(Presenter.ItemList presenter) {
|
||||||
this.presenter = presenter;
|
this.presenter = presenter;
|
||||||
|
@ -41,8 +42,8 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
int res = presenter.getModel().getItemsCount();
|
int ret = presenter.getModel().getItemsCount();
|
||||||
return res;
|
return ret + addToCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,135 +55,145 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
|
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
|
||||||
|
|
||||||
final Item item = presenter.getModel().getItemByPosition(position);
|
try {
|
||||||
holder.cb_item.setChecked(checkAll);
|
final Item item = presenter.getModel().getItemByPosition(position);
|
||||||
holder.tv_text.setText(item.getName());
|
if (item != null) {
|
||||||
//holder.tv_text.setTypeface(mainFace);
|
setVisibility(holder, View.VISIBLE);
|
||||||
if (item.isPendingRemoval()) {
|
holder.cb_item.setChecked(checkAll);
|
||||||
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
holder.tv_text.setText(item.getName());
|
||||||
holder.cb_item.setVisibility(View.GONE);
|
if (item.isPendingRemoval()) {
|
||||||
} else {
|
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||||
holder.cb_item.setVisibility(View.VISIBLE);
|
holder.cb_item.setVisibility(View.GONE);
|
||||||
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 {
|
} else {
|
||||||
unpack(item);
|
//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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
holder.im_info.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
presenter.showDetails(position);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
|
} catch (Exception ex) {
|
||||||
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
|
@Override
|
||||||
|
@ -257,4 +268,22 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
||||||
public void setCheckAll(boolean checkAll) {
|
public void setCheckAll(boolean checkAll) {
|
||||||
this.checkAll = 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,135 +22,145 @@ public class PackedListAdapter extends ItemListAdapter {
|
||||||
super(presenter);
|
super(presenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return presenter.getModel().getItemsCount();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
|
public void onBindViewHolder(final ItemViewHolder holder, final int position) {
|
||||||
|
|
||||||
final Item item = presenter.getModel().getItemByPosition(position);
|
try {
|
||||||
holder.cb_item.setChecked(checkAll);
|
final Item item = presenter.getModel().getItemByPosition(position);
|
||||||
holder.tv_text.setText(item.getName());
|
holder.cb_item.setChecked(checkAll);
|
||||||
if (item.isPendingRemoval()) {
|
holder.tv_text.setText(item.getName());
|
||||||
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
if (item.isPendingRemoval()) {
|
||||||
holder.cb_item.setVisibility(View.GONE);
|
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
||||||
} else {
|
holder.cb_item.setVisibility(View.GONE);
|
||||||
holder.cb_item.setVisibility(View.VISIBLE);
|
} else {
|
||||||
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
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;
|
holder.cb_item.setOnClickListener(new android.view.View.OnClickListener() {
|
||||||
SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
menuLayout.removeAllViews();
|
if (holder.cb_item.isChecked()) {
|
||||||
|
|
||||||
// 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);
|
pack(item);
|
||||||
break;
|
} else {
|
||||||
|
unpack(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
menuLayout.notifyOnMenuItemClick();
|
});
|
||||||
}
|
holder.im_info.setOnClickListener(new View.OnClickListener() {
|
||||||
};
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
presenter.showDetails(position);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
menuLayout.addMenu(menu, onClickListener);
|
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) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,40 +25,42 @@ public class SetListAdapter extends RecyclerView.Adapter<SetViewHolder> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final SetViewHolder holder, int position) {
|
public void onBindViewHolder(final SetViewHolder holder, int position) {
|
||||||
|
try {
|
||||||
|
final com.hikapro.backpack.model.entities.Set set = presenter.getModel().getSetByPosition(position);
|
||||||
|
|
||||||
final com.hikapro.backpack.model.entities.Set set = presenter.getModel().getSetByPosition(position);
|
if (rightBracket == null || rightBracket.isEmpty()) {
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
|
} catch (Exception ex) {
|
||||||
|
|
||||||
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
|
@Override
|
||||||
|
|
|
@ -78,7 +78,11 @@ public class SwipeMenuItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBackground(int resId) {
|
public void setBackground(int resId) {
|
||||||
this.background = mContext.getResources().getDrawable(resId);
|
try {
|
||||||
|
this.background = mContext.getResources().getDrawable(resId);
|
||||||
|
} catch (Exception ex) { ;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="70dp"
|
android:layout_height="@dimen/item_height"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:id="@+id/item_list_footer"
|
android:id="@+id/item_list_footer"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="70dp"
|
android:layout_height="@dimen/item_height"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:id="@+id/item_list_header"
|
android:id="@+id/item_list_header"
|
||||||
android:layout_gravity="top"
|
android:layout_gravity="top"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<dimen name="text_item_description">17sp</dimen>
|
<dimen name="text_item_description">17sp</dimen>
|
||||||
|
|
||||||
<dimen name="card_height">150dp</dimen>
|
<dimen name="card_height">150dp</dimen>
|
||||||
<dimen name="item_height">56dp</dimen>
|
<dimen name="item_height">66dp</dimen>
|
||||||
<dimen name="card_margin">2dp</dimen>
|
<dimen name="card_margin">2dp</dimen>
|
||||||
<dimen name="card_margin_txt">24dp</dimen>
|
<dimen name="card_margin_txt">24dp</dimen>
|
||||||
<dimen name="card_margin_packed_top">16dp</dimen>
|
<dimen name="card_margin_packed_top">16dp</dimen>
|
||||||
|
|
Loading…
Reference in New Issue