Add DownloadScene multiple check
No files matched your search
@@ -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<DownloadInfo> 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<DownloadInfo> 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<DownloadInfo> 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<DownloadInfo> list = mList;
|
||||
@@ -615,6 +707,14 @@ public class DownloadScene extends ToolbarScene
|
||||
|
||||
private class DownloadAdapter extends RecyclerView.Adapter<DownloadHolder> {
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 194 B |
|
After Width: | Height: | Size: 171 B |
|
After Width: | Height: | Size: 188 B |
|
After Width: | Height: | Size: 166 B |
|
After Width: | Height: | Size: 137 B |
|
After Width: | Height: | Size: 135 B |
|
After Width: | Height: | Size: 220 B |
|
After Width: | Height: | Size: 198 B |
|
After Width: | Height: | Size: 190 B |
|
After Width: | Height: | Size: 271 B |
|
After Width: | Height: | Size: 251 B |
|
After Width: | Height: | Size: 248 B |
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright 2016 Hippo Seven
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<selector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:state_activated="true" android:drawable="@drawable/card_teal_2dp"/>
|
||||
<item android:drawable="@drawable/card_white_2dp"/>
|
||||
|
||||
</selector>
|
||||
@@ -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">
|
||||
|
||||
<com.hippo.ehviewer.widget.ThumbImageView
|
||||
android:id="@+id/thumb"
|
||||
|
||||
@@ -51,4 +51,52 @@
|
||||
android:text="@string/no_download_info"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<com.hippo.widget.FabLayout
|
||||
android:id="@+id/fab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingRight="@dimen/corner_fab_margin"
|
||||
android:paddingBottom="@dimen/corner_fab_margin"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
style="@style/Widget.Design.FloatingActionButton.Mini"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_check_all_dark_x24"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
style="@style/Widget.Design.FloatingActionButton.Mini"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_play_dark_x24"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
style="@style/Widget.Design.FloatingActionButton.Mini"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_pause_dark_x24"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
style="@style/Widget.Design.FloatingActionButton.Mini"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_close_dark_x24"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
style="@style/Widget.Design.FloatingActionButton.Mini"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_folder_move_dark_x24"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
style="@style/Widget.Design.FloatingActionButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/ic_close_dark_x24"/>
|
||||
|
||||
</com.hippo.widget.FabLayout>
|
||||
|
||||
</FrameLayout>
|
||||