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="Remove" />
|
||||
</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" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -177,7 +177,6 @@ public class MainActivity extends Activity implements View.ActivityCallback {
|
|||
SetModel model = new SetModel();
|
||||
|
||||
view.setPresenter(presenter);
|
||||
//presenter.setView(view);
|
||||
presenter.setModel(model);
|
||||
model.setPresenter(presenter);
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class ItemModel implements Model.Item {
|
|||
public void onEvent(Message event) {
|
||||
|
||||
switch (event.what) {
|
||||
case Event.SET_ITEMS_LOAD_ERROR : // TODO check
|
||||
case Event.SET_ITEMS_LOAD_ERROR:
|
||||
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,7 +184,11 @@ public class ItemModel implements Model.Item {
|
|||
@Override
|
||||
public Item getItemByPosition(int position) {
|
||||
Item ret = null;
|
||||
try {
|
||||
ret = itemsCache.get(position);
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -207,12 +211,28 @@ public class ItemModel implements Model.Item {
|
|||
|
||||
@Override
|
||||
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
|
||||
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
|
||||
|
|
|
@ -153,12 +153,14 @@ public class ItemListPresenter implements Presenter.ItemList {
|
|||
|
||||
@Override
|
||||
public void setVisibility() {
|
||||
if (model.getPackedQty() > 0 && model.getPackedQty() == model.getActiveItemsCount()) {
|
||||
footer.setVisibility(android.view.View.VISIBLE);
|
||||
} else if ( model.getPackedQty() > 0) {
|
||||
/*if (model.getPackedQty() > 0 && model.getPackedQty() == model.getActiveItemsCount()) {
|
||||
//showPackedItems();
|
||||
} else*/ if (model.getPackedQty() > 0) {
|
||||
footer.setVisibility(android.view.View.VISIBLE);
|
||||
adapter.addEmptyToTheEnd();
|
||||
} else {
|
||||
footer.setVisibility(android.view.View.GONE);
|
||||
adapter.removeEmptyFromTheEnd();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ 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
|
||||
|
@ -99,6 +100,11 @@ public class PackedListPresenter extends ItemListPresenter {
|
|||
}
|
||||
NetworkUtil.sendGoogleAnalyticsScreen(TAG);
|
||||
return view;
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ 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());
|
||||
|
@ -38,6 +39,10 @@ public class AddListAdapter extends RecyclerView.Adapter<AddItemViewHolder> {
|
|||
presenter.onAddItemClick(item);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -37,6 +37,7 @@ 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());
|
||||
|
@ -60,7 +61,6 @@ public class ItemDetailAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
|
||||
SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
|
||||
|
||||
|
@ -141,6 +141,10 @@ public class ItemDetailAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
|||
}
|
||||
};
|
||||
menuLayout.addMenu(menu, onClickListener);
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,6 +34,7 @@ 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;
|
||||
|
@ -41,8 +42,8 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
|||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
int res = presenter.getModel().getItemsCount();
|
||||
return res;
|
||||
int ret = presenter.getModel().getItemsCount();
|
||||
return ret + addToCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,15 +55,17 @@ 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());
|
||||
//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.cb_item.setVisibility(View.VISIBLE);
|
||||
holder.tv_text.setPaintFlags(holder.tv_text.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
||||
}
|
||||
|
||||
|
@ -83,7 +86,7 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
|||
}
|
||||
});
|
||||
|
||||
final SwipeMenuLayout menuLayout = (SwipeMenuLayout)holder.menu;
|
||||
final SwipeMenuLayout menuLayout = (SwipeMenuLayout) holder.menu;
|
||||
final SwipeMenu menu = new SwipeMenu(presenter.getActivityContext());
|
||||
|
||||
menuLayout.removeAllViews();
|
||||
|
@ -149,7 +152,7 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
|||
// set item background
|
||||
deleteItem.setBackground(R.color.colorDeleteBtnBackground);
|
||||
// set item width
|
||||
deleteItem.setWidth(Util.dp2px(presenter.getActivityContext(),120));
|
||||
deleteItem.setWidth(Util.dp2px(presenter.getActivityContext(), 120));
|
||||
// set item title
|
||||
deleteItem.setTitle(R.string.delete_button);
|
||||
// set item title font size
|
||||
|
@ -182,7 +185,15 @@ public class ItemListAdapter extends RecyclerView.Adapter<ItemViewHolder> implem
|
|||
};
|
||||
|
||||
menuLayout.addMenu(menu, onClickListener);
|
||||
} else {
|
||||
if (presenter.getModel().getPackedQty() > 0) {
|
||||
setVisibility(holder, View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -257,4 +268,22 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,15 @@ 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());
|
||||
|
@ -151,6 +157,10 @@ public class PackedListAdapter extends ItemListAdapter {
|
|||
};
|
||||
|
||||
menuLayout.addMenu(menu, onClickListener);
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ 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()) {
|
||||
|
@ -58,8 +58,10 @@ public class SetListAdapter extends RecyclerView.Adapter<SetViewHolder> impleme
|
|||
});
|
||||
holder.applyBackground(presenter.getAppContext(), set.getId());
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
|
|
|
@ -78,7 +78,11 @@ public class SwipeMenuItem {
|
|||
}
|
||||
|
||||
public void setBackground(int resId) {
|
||||
try {
|
||||
this.background = mContext.getResources().getDrawable(resId);
|
||||
} catch (Exception ex) { ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/item_list_footer"
|
||||
android:layout_gravity="bottom"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="70dp"
|
||||
android:layout_height="@dimen/item_height"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/item_list_header"
|
||||
android:layout_gravity="top"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<dimen name="text_item_description">17sp</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_txt">24dp</dimen>
|
||||
<dimen name="card_margin_packed_top">16dp</dimen>
|
||||
|
|
Loading…
Reference in New Issue