From 85d4bc814fff6dbb136ddebda41d4391743c7ebb Mon Sep 17 00:00:00 2001 From: seven332 Date: Sat, 27 Feb 2016 15:29:52 +0800 Subject: [PATCH] Add DownloadScene multiple check --- .../ehviewer/ui/scene/DownloadScene.java | 163 ++++++++++++++++-- .../drawable-hdpi/ic_check_all_dark_x24.png | Bin 0 -> 194 bytes .../res/drawable-hdpi/ic_close_dark_x24.png | Bin 0 -> 171 bytes .../drawable-hdpi/ic_folder_move_dark_x24.png | Bin 0 -> 188 bytes .../drawable-mdpi/ic_check_all_dark_x24.png | Bin 0 -> 166 bytes .../res/drawable-mdpi/ic_close_dark_x24.png | Bin 0 -> 137 bytes .../drawable-mdpi/ic_folder_move_dark_x24.png | Bin 0 -> 135 bytes .../drawable-xhdpi/ic_check_all_dark_x24.png | Bin 0 -> 220 bytes .../res/drawable-xhdpi/ic_close_dark_x24.png | Bin 0 -> 198 bytes .../ic_folder_move_dark_x24.png | Bin 0 -> 190 bytes .../drawable-xxhdpi/ic_check_all_dark_x24.png | Bin 0 -> 271 bytes .../res/drawable-xxhdpi/ic_close_dark_x24.png | Bin 0 -> 251 bytes .../ic_folder_move_dark_x24.png | Bin 0 -> 248 bytes app/src/main/res/drawable/card_background.xml | 24 +++ app/src/main/res/layout/item_download.xml | 2 +- app/src/main/res/layout/scene_download.xml | 48 ++++++ 16 files changed, 222 insertions(+), 15 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_check_all_dark_x24.png create mode 100644 app/src/main/res/drawable-hdpi/ic_close_dark_x24.png create mode 100644 app/src/main/res/drawable-hdpi/ic_folder_move_dark_x24.png create mode 100644 app/src/main/res/drawable-mdpi/ic_check_all_dark_x24.png create mode 100644 app/src/main/res/drawable-mdpi/ic_close_dark_x24.png create mode 100644 app/src/main/res/drawable-mdpi/ic_folder_move_dark_x24.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_check_all_dark_x24.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_close_dark_x24.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_folder_move_dark_x24.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_check_all_dark_x24.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_close_dark_x24.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_folder_move_dark_x24.png create mode 100644 app/src/main/res/drawable/card_background.xml diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadScene.java index 131c59171..7f4f93860 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/DownloadScene.java @@ -26,6 +26,7 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; import android.support.v7.widget.LinearLayoutManager; @@ -67,6 +68,7 @@ import com.hippo.util.ActivityHelper; import com.hippo.util.ApiHelper; import com.hippo.vector.VectorDrawable; import com.hippo.view.ViewTransition; +import com.hippo.widget.FabLayout; import com.hippo.widget.LoadImageView; import com.hippo.widget.SimpleImageView; import com.hippo.yorozuya.FileUtils; @@ -77,7 +79,9 @@ import java.util.List; public class DownloadScene extends ToolbarScene implements DownloadManager.DownloadInfoListener, - EasyRecyclerView.OnItemClickListener { + EasyRecyclerView.OnItemClickListener, + EasyRecyclerView.OnItemLongClickListener, + FabLayout.OnClickFabListener { private static final String KEY_LABEL = "label"; @@ -85,6 +89,8 @@ public class DownloadScene extends ToolbarScene private EasyRecyclerView mRecyclerView; @Nullable private ViewTransition mViewTransition; + @Nullable + private FabLayout mFabLayout; @Nullable private DownloadAdapter mAdapter; @@ -125,9 +131,13 @@ public class DownloadScene extends ToolbarScene mList = manager.getDefaultDownloadInfoList(); } } + updateTitle(); + Settings.putRecentDownloadLabel(mLabel); + } + + private void updateTitle() { setTitle(getString(R.string.scene_download_title, mLabel != null ? mLabel : getString(R.string.default_download_label_name))); - Settings.putRecentDownloadLabel(mLabel); } private void onInit() { @@ -152,6 +162,7 @@ public class DownloadScene extends ToolbarScene @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.scene_download, container, false); mRecyclerView = (EasyRecyclerView) view.findViewById(R.id.recycler_view); + mFabLayout = (FabLayout) view.findViewById(R.id.fab_layout); View tip = view.findViewById(R.id.tip); SimpleImageView tipImage = (SimpleImageView) tip.findViewById(R.id.tip_image); tipImage.setDrawable(VectorDrawable.create(getContext(), R.xml.sadpanda_head)); @@ -159,6 +170,7 @@ public class DownloadScene extends ToolbarScene if (mRecyclerView != null) { mAdapter = new DownloadAdapter(); + mAdapter.setHasStableIds(true); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false)); @@ -166,11 +178,20 @@ public class DownloadScene extends ToolbarScene mRecyclerView.hasFixedSize(); mRecyclerView.setClipToPadding(false); mRecyclerView.setOnItemClickListener(this); + mRecyclerView.setOnItemLongClickListener(this); + mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM); + mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener()); int paddingH = getResources().getDimensionPixelOffset(R.dimen.list_content_margin_h); int paddingV = getResources().getDimensionPixelOffset(R.dimen.list_content_margin_v); mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH); } + if (mFabLayout != null) { + mFabLayout.setHidePrimaryFab(true); + mFabLayout.setAutoCancel(false); + mFabLayout.setOnClickFabListener(this); + } + if (mList == null || mList.isEmpty()) { mViewTransition.showView(1); } else { @@ -183,6 +204,7 @@ public class DownloadScene extends ToolbarScene @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + updateTitle(); setNavigationIcon(VectorDrawable.create(getContext(), R.xml.ic_arrow_left_dark_x24)); // Clear nav checked item @@ -194,7 +216,7 @@ public class DownloadScene extends ToolbarScene @Override public void onNavigationClick() { - finish(); + onBackPressed(); } @Override @@ -204,6 +226,11 @@ public class DownloadScene extends ToolbarScene @Override public boolean onMenuItemClick(MenuItem item) { + // Skip when in choice mode + if (mRecyclerView == null || mRecyclerView.isInCustomChoice()) { + return false; + } + int id = item.getItemId(); switch (id) { case R.id.action_start_all: { @@ -229,6 +256,7 @@ public class DownloadScene extends ToolbarScene DownloadManager manager = EhApplication.getDownloadManager(getContext()); manager.setDownloadInfoListener(null); mRecyclerView = null; + mFabLayout = null; mViewTransition = null; mAdapter = null; } @@ -299,22 +327,86 @@ public class DownloadScene extends ToolbarScene } @Override - public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) { - List list = mList; - if (list == null) { - return false; + public void onBackPressed() { + if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) { + mRecyclerView.outOfCustomChoiceMode(); + } else { + super.onBackPressed(); } - if (position < 0 && position >= list.size()) { + } + + @Override + public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) { + EasyRecyclerView recyclerView = mRecyclerView; + if (recyclerView == null) { return false; } - Intent intent = new Intent(getActivity(), GalleryActivity.class); - intent.setAction(GalleryActivity.ACTION_EH); - intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position).galleryInfo); - startActivity(intent); + if (recyclerView.isInCustomChoice()) { + recyclerView.toggleItemChecked(position); + return true; + } else { + List list = mList; + if (list == null) { + return false; + } + if (position < 0 && position >= list.size()) { + return false; + } + + Intent intent = new Intent(getActivity(), GalleryActivity.class); + intent.setAction(GalleryActivity.ACTION_EH); + intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position).galleryInfo); + startActivity(intent); + return true; + } + } + + @Override + public boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id) { + EasyRecyclerView recyclerView = mRecyclerView; + if (recyclerView == null) { + return false; + } + + if (!recyclerView.isInCustomChoice()) { + recyclerView.intoCustomChoiceMode(); + } + recyclerView.toggleItemChecked(position); + return true; } + @Override + public void onClickPrimaryFab(FabLayout view, FloatingActionButton fab) { + if (mRecyclerView != null && mRecyclerView.isInCustomChoice()) { + mRecyclerView.outOfCustomChoiceMode(); + } + } + + @Override + public void onClickSecondaryFab(FabLayout view, FloatingActionButton fab, int position) { + switch (position) { + case 0: // Check all + if (mRecyclerView != null) { + mRecyclerView.checkAll(); + } + break; + case 1: // Start + // TODO + break; + case 2: // Stop + // TODO + break; + case 3: // Delete + // TODO + break; + case 4: // Move + // TODO + break; + } + } + @Override public void onAdd(DownloadInfo info, List list, int position) { if (mList != list) { @@ -533,8 +625,8 @@ public class DownloadScene extends ToolbarScene @Override public void onClick(View v) { - RecyclerView recyclerView = mRecyclerView; - if (recyclerView == null) { + EasyRecyclerView recyclerView = mRecyclerView; + if (recyclerView == null || recyclerView.isInCustomChoice()) { return; } List list = mList; @@ -615,6 +707,14 @@ public class DownloadScene extends ToolbarScene private class DownloadAdapter extends RecyclerView.Adapter { + @Override + public long getItemId(int position) { + if (mList == null || position < 0 || position >= mList.size()) { + return 0; + } + return mList.get(position).galleryInfo.gid; + } + @Override public DownloadHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new DownloadHolder(getActivity().getLayoutInflater().inflate(R.layout.item_download, parent, false)); @@ -655,4 +755,39 @@ public class DownloadScene extends ToolbarScene return mList == null ? 0 : mList.size(); } } + + private class DownloadChoiceListener implements EasyRecyclerView.CustomChoiceListener { + + @Override + public void onIntoCustomChoice(EasyRecyclerView view) { + if (mRecyclerView != null) { + mRecyclerView.setOnItemLongClickListener(null); + mRecyclerView.setLongClickable(false); + } + if (mFabLayout != null) { + mFabLayout.setExpanded(true); + } + // Lock drawer + setDrawerLayoutEnable(false); + } + + @Override + public void onOutOfCustomChoice(EasyRecyclerView view) { + if (mRecyclerView != null) { + mRecyclerView.setOnItemLongClickListener(DownloadScene.this); + } + if (mFabLayout != null) { + mFabLayout.setExpanded(false); + } + // Unlock drawer + setDrawerLayoutEnable(true); + } + + @Override + public void onItemCheckedStateChanged(EasyRecyclerView view, int position, long id, boolean checked) { + if (view.getCheckedItemCount() == 0) { + view.outOfCustomChoiceMode(); + } + } + } } diff --git a/app/src/main/res/drawable-hdpi/ic_check_all_dark_x24.png b/app/src/main/res/drawable-hdpi/ic_check_all_dark_x24.png new file mode 100644 index 0000000000000000000000000000000000000000..1136ba8eba6f818a93123d8e8aea711c2bce8db1 GIT binary patch literal 194 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K8r>Bc!NCo5DOYV$J20U(wDlSYy zT8x@g8-!I{f|iCHdVJ(Zq-@R!>(aXAI`;xaCZ62npYu$jq2@@)f#(tq5)0cUHW^hI z#GiblUm7*HiSx?I7h9|v0(jjP+PX3>oMt{FT4Y&B^ULK?KK5IK(&jnM)XZuUT$SX+ rdD%boQeD1Cs@n>c>g2mWgj}P=tFFI|buC-~bQFW9tDnm{r-UW|rJO{K literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-hdpi/ic_close_dark_x24.png b/app/src/main/res/drawable-hdpi/ic_close_dark_x24.png new file mode 100644 index 0000000000000000000000000000000000000000..6df2fb4c15b4696064714be8c2ef3363c7db9b33 GIT binary patch literal 171 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K8k*AAeNCo5DE89gI3*vvPdHW3x7R&C*Jh*%P)}QUVf3C2}{r5{}-^9Kk UL*0?R8)!R&r>mdKI;Vst04)eWc>n+a literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-hdpi/ic_folder_move_dark_x24.png b/app/src/main/res/drawable-hdpi/ic_folder_move_dark_x24.png new file mode 100644 index 0000000000000000000000000000000000000000..9662b13255a77e88a1107fe7d8f6f40cf8d1233f GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K8v!{z=NCo5DE8&bxh5`&1rwVX- zI4}iG5K{MWIONsUvhX`!@t2+dr^iIq-bmU05T+z@Yo<$*k8w7WF`j O89ZJ6T-G@yGywqqia*c* literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_close_dark_x24.png b/app/src/main/res/drawable-mdpi/ic_close_dark_x24.png new file mode 100644 index 0000000000000000000000000000000000000000..d4d30f880cc7f0920db0623bda448a34c5d7b805 GIT binary patch literal 137 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+i08bakkP60RiH8sB5B>lCpVz>J zw_y=ygeimSzr$M;rZ~H7%rU|iF>fo;oz8U9Zgvy i3YjJXGk>&kGB7kfW#9bJy>KqjWCl-HKbLh*2~7ZXrYy9Vz0c>A{i>LzVW{dH5i*Iw(#;XeCy w_v;^i2v@6rx&QyoL-u=qEML4xW4{Z-j008snJli%0XmGq)78&qol`;+0316~vj6}9 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_folder_move_dark_x24.png b/app/src/main/res/drawable-xhdpi/ic_folder_move_dark_x24.png new file mode 100644 index 0000000000000000000000000000000000000000..a6b3fe743564c156a831611e3243f6f097cfccb2 GIT binary patch literal 190 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA0wn)(8}b0DR!sz9%by5{_*pz`5e5=}jNE7Qt^MwsadE}tGaipvJVRxi53zW# zf=T~^8D%FYo2d9#&2pYp|HAWpahAut%l@C{)J=N+WwOok`A;nWsvNEqK3V+B6Cy5T z8M{Q-gI8w42c9Ktd>$2SL89#{Hq0w$I19~d3_0);?8KK$dw(Zxf78;s8|Xs@Pgg&e IbxsLQ0I&veyZ`_I literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_close_dark_x24.png b/app/src/main/res/drawable-xxhdpi/ic_close_dark_x24.png new file mode 100644 index 0000000000000000000000000000000000000000..7d983009fa81c462435e1e79e5d387a9b8656dd2 GIT binary patch literal 251 zcmVnOu6a`TwZ2!rYv>k!y6)-oL;7^bZ>K}VhGWb$GUKb}eU zwMMQ{0M2HQ6F5Px~{Y*zfLxl&7STs}^ zUX%qnhV8%7Us#p6<%0QjySh6kUMlBU{MqmLcX38(j=~v3XX!OAv%hR(H?4a1fz^on lc?Fljoc|eXw_dx&%BAs9PiEOWMW9z0JYD@<);T3K0RT1^Th0Ig literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/card_background.xml b/app/src/main/res/drawable/card_background.xml new file mode 100644 index 000000000..3bf952060 --- /dev/null +++ b/app/src/main/res/drawable/card_background.xml @@ -0,0 +1,24 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/item_download.xml b/app/src/main/res/layout/item_download.xml index 47da739b2..9732499bc 100644 --- a/app/src/main/res/layout/item_download.xml +++ b/app/src/main/res/layout/item_download.xml @@ -19,7 +19,7 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@drawable/card_white_2dp"> + android:background="@drawable/card_background"> + + + + + + + + + + + + + + + + + +