Update download drawer

This commit is contained in:
onlymash authored and NekoInverter committed 2020-09-01 21:31:37 +08:00
1 parent 1eddae30ee
commit b2fc899cab
9 files changed
+330 -529

No files matched your search

@@ -61,7 +61,6 @@ import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
import com.hippo.ehviewer.ui.scene.AnalyticsScene;
import com.hippo.ehviewer.ui.scene.BaseScene;
import com.hippo.ehviewer.ui.scene.CookieSignInScene;
import com.hippo.ehviewer.ui.scene.DownloadLabelsScene;
import com.hippo.ehviewer.ui.scene.DownloadsScene;
import com.hippo.ehviewer.ui.scene.FavoritesScene;
import com.hippo.ehviewer.ui.scene.GalleryCommentsScene;
@@ -119,7 +118,6 @@ public final class MainActivity extends StageActivity
registerLaunchMode(GalleryCommentsScene.class, SceneFragment.LAUNCH_MODE_STANDARD);
registerLaunchMode(GalleryPreviewsScene.class, SceneFragment.LAUNCH_MODE_STANDARD);
registerLaunchMode(DownloadsScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(DownloadLabelsScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(FavoritesScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(HistoryScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TOP);
registerLaunchMode(ProgressScene.class, SceneFragment.LAUNCH_MODE_STANDARD);
@@ -1,391 +0,0 @@
/*
* 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.
*/
package com.hippo.ehviewer.ui.scene;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter;
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange;
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableItemViewHolder;
import com.hippo.app.EditTextDialogBuilder;
import com.hippo.easyrecyclerview.EasyRecyclerView;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.dao.DownloadLabel;
import com.hippo.util.DrawableManager;
import com.hippo.view.ViewTransition;
import com.hippo.yorozuya.AssertUtils;
import com.hippo.yorozuya.ViewUtils;
import java.util.List;
public class DownloadLabelsScene extends ToolbarScene {
/*---------------
Whole life cycle
---------------*/
@Nullable
public List<DownloadLabel> mList = null;
/*---------------
View life cycle
---------------*/
@Nullable
private EasyRecyclerView mRecyclerView;
@Nullable
private ViewTransition mViewTransition;
@Nullable
private RecyclerView.Adapter mAdapter;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mList = EhApplication.getDownloadManager(getContext2()).getLabelList();
}
@Override
public void onDestroy() {
super.onDestroy();
mList = null;
}
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scene_label_list, container, false);
mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
mViewTransition = new ViewTransition(mRecyclerView, tip);
Context context = getContext2();
AssertUtils.assertNotNull(context);
Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_label);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
tip.setCompoundDrawables(null, drawable, null, null);
tip.setText(R.string.no_download_label);
// drag & drop manager
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
dragDropManager.setDraggingItemShadowDrawable(
(NinePatchDrawable) context.getResources().getDrawable(R.drawable.shadow_8dp));
RecyclerView.Adapter adapter = new LabelAdapter();
adapter.setHasStableIds(true);
adapter = dragDropManager.createWrappedAdapter(adapter); // wrap for dragging
mAdapter = adapter;
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
mRecyclerView.setAdapter(adapter);
mRecyclerView.setItemAnimator(animator);
dragDropManager.attachRecyclerView(mRecyclerView);
updateView();
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setTitle(R.string.download_labels);
setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (null != mRecyclerView) {
mRecyclerView.stopScroll();
mRecyclerView = null;
}
mViewTransition = null;
mAdapter = null;
}
@Override
public void onNavigationClick() {
onBackPressed();
}
@Override
public int getMenuResId() {
return R.menu.scene_download_label;
}
@Override
public boolean onMenuItemClick(MenuItem item) {
Context context = getContext2();
if (null == context) {
return false;
}
int id = item.getItemId();
switch (id) {
case R.id.action_add: {
EditTextDialogBuilder builder = new EditTextDialogBuilder(context, null, getString(R.string.download_labels));
builder.setTitle(R.string.new_label_title);
builder.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.show();
new NewLabelDialogHelper(builder, dialog);
}
}
return false;
}
private void updateView() {
if (mViewTransition != null) {
if (mList != null && mList.size() > 0) {
mViewTransition.showView(0);
} else {
mViewTransition.showView(1);
}
}
}
private class NewLabelDialogHelper implements View.OnClickListener {
private final EditTextDialogBuilder mBuilder;
private final AlertDialog mDialog;
public NewLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog) {
mBuilder = builder;
mDialog = dialog;
Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
Context context = getContext2();
if (null == context) {
return;
}
String text = mBuilder.getText();
if (TextUtils.isEmpty(text)) {
mBuilder.setError(getString(R.string.label_text_is_empty));
} else if (getString(R.string.default_download_label_name).equals(text)) {
mBuilder.setError(getString(R.string.label_text_is_invalid));
} else if (EhApplication.getDownloadManager(context).containLabel(text)) {
mBuilder.setError(getString(R.string.label_text_exist));
} else {
mBuilder.setError(null);
mDialog.dismiss();
EhApplication.getDownloadManager(context).addLabel(text);
if (mAdapter != null && mList != null) {
mAdapter.notifyItemInserted(mList.size() - 1);
}
if (mViewTransition != null) {
if (mList != null && mList.size() > 0) {
mViewTransition.showView(0);
} else {
mViewTransition.showView(1);
}
}
}
}
}
private class RenameLabelDialogHelper implements View.OnClickListener {
private final EditTextDialogBuilder mBuilder;
private final AlertDialog mDialog;
private final String mOriginalLabel;
private final int mPosition;
public RenameLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog,
String originalLabel, int position) {
mBuilder = builder;
mDialog = dialog;
mOriginalLabel = originalLabel;
mPosition = position;
Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
Context context = getContext2();
if (null == context) {
return;
}
String text = mBuilder.getText();
if (TextUtils.isEmpty(text)) {
mBuilder.setError(getString(R.string.label_text_is_empty));
} else if (getString(R.string.default_download_label_name).equals(text)) {
mBuilder.setError(getString(R.string.label_text_is_invalid));
} else if (EhApplication.getDownloadManager(context).containLabel(text)) {
mBuilder.setError(getString(R.string.label_text_exist));
} else {
mBuilder.setError(null);
mDialog.dismiss();
EhApplication.getDownloadManager(context).renameLabel(mOriginalLabel, text);
if (mAdapter != null) {
mAdapter.notifyItemChanged(mPosition);
}
}
}
}
private class LabelHolder extends AbstractDraggableItemViewHolder
implements View.OnClickListener {
public final TextView label;
public final View dragHandler;
public final View delete;
public LabelHolder(View itemView) {
super(itemView);
label = (TextView) ViewUtils.$$(itemView, R.id.label);
dragHandler = ViewUtils.$$(itemView, R.id.drag_handler);
delete = ViewUtils.$$(itemView, R.id.delete);
label.setOnClickListener(this);
delete.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int position = getAdapterPosition();
Context context = getContext2();
if (null == context || null == mList || null == mRecyclerView) {
return;
}
if (label == v) {
DownloadLabel raw = mList.get(position);
EditTextDialogBuilder builder = new EditTextDialogBuilder(
context, raw.getLabel(), getString(R.string.download_labels));
builder.setTitle(R.string.rename_label_title);
builder.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.show();
new RenameLabelDialogHelper(builder, dialog, raw.getLabel(), position);
} else if (delete == v) {
final DownloadLabel label = mList.get(position);
new MaterialAlertDialogBuilder(context)
.setTitle(R.string.delete_label_title)
.setMessage(getString(R.string.delete_label_message, label.getLabel()))
.setPositiveButton(android.R.string.ok, (dialog, which) -> EhApplication.getDownloadManager(context).deleteLabel(label.getLabel()))
.setOnDismissListener(dialog -> {
if (null != mAdapter) {
mAdapter.notifyDataSetChanged();
}
updateView();
}).show();
}
}
}
private class LabelAdapter extends RecyclerView.Adapter<LabelHolder>
implements DraggableItemAdapter<LabelHolder> {
private final LayoutInflater mInflater;
public LabelAdapter() {
mInflater = getLayoutInflater2();
AssertUtils.assertNotNull(mInflater);
}
@Override
public LabelHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new LabelHolder(mInflater.inflate(R.layout.item_download_label, parent, false));
}
@Override
public void onBindViewHolder(LabelHolder holder, int position) {
if (mList != null) {
holder.label.setText(mList.get(position).getLabel());
}
}
@Override
public long getItemId(int position) {
return mList != null ? mList.get(position).getId() : 0;
}
@Override
public int getItemCount() {
return mList != null ? mList.size() : 0;
}
@Override
public boolean onCheckCanStartDrag(LabelHolder holder, int position, int x, int y) {
return ViewUtils.isViewUnder(holder.dragHandler, x, y, 0);
}
@Override
public ItemDraggableRange onGetItemDraggableRange(LabelHolder holder, int position) {
return null;
}
@Override
public void onMoveItem(int fromPosition, int toPosition) {
Context context = getContext2();
if (null == context || fromPosition == toPosition) {
return;
}
EhApplication.getDownloadManager(context).moveLabel(fromPosition, toPosition);
}
@Override
public boolean onCheckCanDrop(int draggingPosition, int dropPosition) {
return true;
}
@Override
public void onItemDragStarted(int position) {
}
@Override
public void onItemDragFinished(int fromPosition, int toPosition, boolean result) {
}
}
}
@@ -27,6 +27,7 @@ import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.Display;
@@ -36,11 +37,15 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
import androidx.drawerlayout.widget.DrawerLayout;
@@ -56,8 +61,15 @@ import com.github.amlcurran.showcaseview.targets.PointTarget;
import com.github.amlcurran.showcaseview.targets.ViewTarget;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.h6ah4i.android.widget.advrecyclerview.animator.DraggableItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator;
import com.h6ah4i.android.widget.advrecyclerview.draggable.DraggableItemAdapter;
import com.h6ah4i.android.widget.advrecyclerview.draggable.ItemDraggableRange;
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager;
import com.h6ah4i.android.widget.advrecyclerview.utils.AbstractDraggableItemViewHolder;
import com.hippo.android.resource.AttrResources;
import com.hippo.app.CheckBoxDialogBuilder;
import com.hippo.app.EditTextDialogBuilder;
import com.hippo.conaco.DataContainer;
import com.hippo.conaco.ProgressNotifier;
import com.hippo.drawable.DrawerArrowDrawable;
@@ -309,7 +321,7 @@ public class DownloadsScene extends ToolbarScene
}
@Override
public void onSaveInstanceState(Bundle outState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_LABEL, mLabel);
}
@@ -594,59 +606,67 @@ public class DownloadsScene extends ToolbarScene
Toolbar toolbar = view.findViewById(R.id.toolbar);
toolbar.setTitle(R.string.download_labels);
toolbar.inflateMenu(R.menu.drawer_download);
toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.action_settings:
startScene(new Announcer(DownloadLabelsScene.class));
toolbar.setOnMenuItemClickListener(item -> {
int id = item.getItemId();
switch (id) {
case R.id.action_add:
EditTextDialogBuilder builder = new EditTextDialogBuilder(context, null, getString(R.string.download_labels));
builder.setTitle(R.string.new_label_title);
builder.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.show();
new NewLabelDialogHelper(builder, dialog);
return true;
case R.id.action_default_download_label:
DownloadManager dm = mDownloadManager;
if (null == dm) {
return true;
case R.id.action_default_download_label:
DownloadManager dm = mDownloadManager;
if (null == dm) {
return true;
}
}
List<DownloadLabel> list = dm.getLabelList();
final String[] items = new String[list.size() + 2];
items[0] = getString(R.string.let_me_select);
items[1] = getString(R.string.default_download_label_name);
for (int i = 0, n = list.size(); i < n; i++) {
items[i + 2] = list.get(i).getLabel();
}
new MaterialAlertDialogBuilder(context)
.setTitle(R.string.default_download_label)
.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
Settings.putHasDefaultDownloadLabel(false);
} else {
Settings.putHasDefaultDownloadLabel(true);
String label;
if (which == 1) {
label = null;
} else {
label = items[which];
}
Settings.putDefaultDownloadLabel(label);
}
List<DownloadLabel> list = dm.getLabelList();
final String[] items = new String[list.size() + 2];
items[0] = getString(R.string.let_me_select);
items[1] = getString(R.string.default_download_label_name);
for (int i = 0, n = list.size(); i < n; i++) {
items[i + 2] = list.get(i).getLabel();
}
new MaterialAlertDialogBuilder(context)
.setTitle(R.string.default_download_label)
.setItems(items, (dialog1, which) -> {
if (which == 0) {
Settings.putHasDefaultDownloadLabel(false);
} else {
Settings.putHasDefaultDownloadLabel(true);
String label;
if (which == 1) {
label = null;
} else {
label = items[which];
}
}).show();
return true;
}
return false;
Settings.putDefaultDownloadLabel(label);
}
}).show();
return true;
}
return false;
});
initLabels();
RecyclerViewDragDropManager dragDropManager = new RecyclerViewDragDropManager();
dragDropManager.setInitiateOnLongPress(true);
dragDropManager.setInitiateOnTouch(false);
dragDropManager.setDraggingItemAlpha(0.8f);
mLabelAdapter = new DownloadLabelAdapter(inflater);
final EasyRecyclerView recyclerView = view.findViewById(R.id.recycler_view_drawer);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
recyclerView.setAdapter(mLabelAdapter);
mLabelAdapter.setHasStableIds(true);
final GeneralItemAnimator animator = new DraggableItemAnimator();
recyclerView.setItemAnimator(animator);
recyclerView.setAdapter(dragDropManager.createWrappedAdapter(mLabelAdapter));
dragDropManager.attachRecyclerView(recyclerView);
return view;
}
@@ -973,19 +993,19 @@ public class DownloadsScene extends ToolbarScene
holder.speed.setText(FileUtils.humanReadableByteCount(speed, false) + "/S");
}
private class DownloadLabelHolder extends RecyclerView.ViewHolder {
private static class DownloadLabelHolder extends AbstractDraggableItemViewHolder {
private final TextView key;
private final TextView value;
private final TextView label;
private final ImageView option;
private DownloadLabelHolder(View itemView) {
super(itemView);
key = (TextView) ViewUtils.$$(itemView, R.id.key);
value = (TextView) ViewUtils.$$(itemView, R.id.value);
label = (TextView) ViewUtils.$$(itemView, R.id.tv_key);
option = (ImageView) ViewUtils.$$(itemView, R.id.iv_option);
}
}
private class DownloadLabelAdapter extends RecyclerView.Adapter<DownloadLabelHolder> {
private class DownloadLabelAdapter extends RecyclerView.Adapter<DownloadLabelHolder> implements DraggableItemAdapter<DownloadLabelHolder> {
private final LayoutInflater mInflater;
@@ -996,9 +1016,10 @@ public class DownloadsScene extends ToolbarScene
@NonNull
@Override
public DownloadLabelHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new DownloadLabelHolder(mInflater.inflate(R.layout.item_drawer_favorites, parent, false));
return new DownloadLabelHolder(mInflater.inflate(R.layout.item_drawer_list, parent, false));
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull DownloadLabelHolder holder, int position) {
if (mLabels != null) {
@@ -1017,9 +1038,10 @@ public class DownloadsScene extends ToolbarScene
list = mDownloadManager.getLabelDownloadInfoList(label);
}
}
holder.key.setText(label);
if (list != null) {
holder.value.setText(String.valueOf(list.size()));
holder.label.setText(label + " [" + list.size() + "]");
} else {
holder.label.setText(label);
}
holder.itemView.setOnClickListener(v -> {
String label1;
@@ -1035,12 +1057,85 @@ public class DownloadsScene extends ToolbarScene
closeDrawer(Gravity.RIGHT);
}
});
if (position > 0) {
holder.option.setVisibility(View.VISIBLE);
holder.option.setOnClickListener(v -> {
if (context != null) {
PopupMenu popupMenu = new PopupMenu(context, holder.option);
popupMenu.inflate(R.menu.download_label_option);
popupMenu.show();
popupMenu.setOnMenuItemClickListener(item -> {
switch (item.getItemId()) {
case R.id.menu_label_rename:
if (mListLabel != null && position <= mListLabel.size()) {
DownloadLabel raw = mListLabel.get(position - 1);
EditTextDialogBuilder builder = new EditTextDialogBuilder(
context, raw.getLabel(), getString(R.string.download_labels));
builder.setTitle(R.string.rename_label_title);
builder.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.show();
new RenameLabelDialogHelper(builder, dialog, raw.getLabel());
}
break;
case R.id.menu_label_remove:
mDownloadManager.deleteLabel(label);
mLabels.remove(position);
notifyDataSetChanged();
break;
}
return false;
});
}
});
} else {
holder.option.setVisibility(View.GONE);
}
}
}
@Override
public long getItemId(int position) {
return mLabels != null ? mLabels.get(position).hashCode() : 0;
}
@Override
public int getItemCount() {
return mLabels.size();
return mLabels != null ? mLabels.size() : 0;
}
@Override
public boolean onCheckCanStartDrag(@NonNull DownloadLabelHolder holder, int position, int x, int y) {
return position != 0;
}
@Override
public ItemDraggableRange onGetItemDraggableRange(@NonNull DownloadLabelHolder holder, int position) {
return new ItemDraggableRange(1, getItemCount() - 1);
}
@Override
public void onMoveItem(int fromPosition, int toPosition) {
Context context = getContext2();
if (null == context || fromPosition == toPosition || toPosition == 0) {
return;
}
EhApplication.getDownloadManager(context).moveLabel(fromPosition - 1, toPosition - 1);
final String item = mLabels.remove(fromPosition);
mLabels.add(toPosition, item);
}
@Override
public boolean onCheckCanDrop(int draggingPosition, int dropPosition) {
return dropPosition != 0;
}
@Override
public void onItemDragStarted(int position) {
}
@Override
public void onItemDragFinished(int fromPosition, int toPosition, boolean result) {
}
}
@@ -1261,8 +1356,9 @@ public class DownloadsScene extends ToolbarScene
return mList.get(position).gid;
}
@NonNull
@Override
public DownloadHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public DownloadHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
DownloadHolder holder = new DownloadHolder(mInflater.inflate(R.layout.item_download, parent, false));
ViewGroup.LayoutParams lp = holder.thumb.getLayoutParams();
@@ -1274,7 +1370,7 @@ public class DownloadsScene extends ToolbarScene
}
@Override
public void onBindViewHolder(DownloadHolder holder, int position) {
public void onBindViewHolder(@NonNull DownloadHolder holder, int position) {
if (mList == null) {
return;
}
@@ -1405,4 +1501,97 @@ public class DownloadsScene extends ToolbarScene
}
}
}
private class RenameLabelDialogHelper implements View.OnClickListener {
private final EditTextDialogBuilder mBuilder;
private final AlertDialog mDialog;
private final String mOriginalLabel;
private RenameLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog,
String originalLabel) {
mBuilder = builder;
mDialog = dialog;
mOriginalLabel = originalLabel;
Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
Context context = getContext2();
if (null == context) {
return;
}
String text = mBuilder.getText();
if (TextUtils.isEmpty(text)) {
mBuilder.setError(getString(R.string.label_text_is_empty));
} else if (getString(R.string.default_download_label_name).equals(text)) {
mBuilder.setError(getString(R.string.label_text_is_invalid));
} else if (EhApplication.getDownloadManager(context).containLabel(text)) {
mBuilder.setError(getString(R.string.label_text_exist));
} else {
mBuilder.setError(null);
mDialog.dismiss();
EhApplication.getDownloadManager(context).renameLabel(mOriginalLabel, text);
if (mLabelAdapter != null) {
initLabels();
mLabelAdapter.notifyDataSetChanged();
}
}
}
}
private class NewLabelDialogHelper implements View.OnClickListener {
private final EditTextDialogBuilder mBuilder;
private final AlertDialog mDialog;
private NewLabelDialogHelper(EditTextDialogBuilder builder, AlertDialog dialog) {
mBuilder = builder;
mDialog = dialog;
Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
Context context = getContext2();
if (null == context) {
return;
}
String text = mBuilder.getText();
if (TextUtils.isEmpty(text)) {
mBuilder.setError(getString(R.string.label_text_is_empty));
} else if (getString(R.string.default_download_label_name).equals(text)) {
mBuilder.setError(getString(R.string.label_text_is_invalid));
} else if (EhApplication.getDownloadManager(context).containLabel(text)) {
mBuilder.setError(getString(R.string.label_text_exist));
} else {
mBuilder.setError(null);
mDialog.dismiss();
EhApplication.getDownloadManager(context).addLabel(text);
if (mAdapter != null && mLabels != null) {
mAdapter.notifyItemInserted(mLabels.size() - 1);
}
if (mViewTransition != null) {
if (mLabels != null && mLabels.size() > 0) {
mViewTransition.showView(0);
} else {
mViewTransition.showView(1);
}
}
}
if (mLabelAdapter != null) {
initLabels();
mLabelAdapter.notifyDataSetChanged();
}
}
}
}
@@ -197,11 +197,11 @@ public final class GalleryListScene extends BaseScene
@Nullable
private final RecyclerView.OnScrollListener mOnScrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy >= mHideActionFabSlop) {
hideActionFab();
} else if (dy <= -mHideActionFabSlop / 2) {
@@ -387,7 +387,7 @@ public final class GalleryListScene extends BaseScene
}
@Override
public void onSaveInstanceState(Bundle outState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
boolean hasFirstRefresh;
@@ -512,7 +512,7 @@ public final class GalleryListScene extends BaseScene
mNavCheckedId = checkedItemId;
}
@Nullable
@NonNull
@Override
public View onCreateView2(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
@@ -680,14 +680,11 @@ public final class GalleryListScene extends BaseScene
final CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(
context, getString(R.string.add_quick_search_tip), getString(R.string.get_it), false);
builder.setTitle(R.string.readme);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (builder.isChecked()) {
Settings.putQuickSearchTip(false);
}
showAddQuickSearchDialog(adapter, recyclerView, tip);
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (builder.isChecked()) {
Settings.putQuickSearchTip(false);
}
showAddQuickSearchDialog(adapter, recyclerView, tip);
}).show();
}
@@ -719,40 +716,37 @@ public final class GalleryListScene extends BaseScene
builder.setTitle(R.string.add_quick_search_dialog_title);
builder.setPositiveButton(android.R.string.ok, null);
final AlertDialog dialog = builder.show();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = builder.getText().trim();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
String text = builder.getText().trim();
// Check name empty
if (TextUtils.isEmpty(text)) {
builder.setError(getString(R.string.name_is_empty));
// Check name empty
if (TextUtils.isEmpty(text)) {
builder.setError(getString(R.string.name_is_empty));
return;
}
// Check name duplicate
for (QuickSearch q : mQuickSearchList) {
if (text.equals(q.name)) {
builder.setError(getString(R.string.duplicate_name));
return;
}
}
// Check name duplicate
for (QuickSearch q : mQuickSearchList) {
if (text.equals(q.name)) {
builder.setError(getString(R.string.duplicate_name));
return;
}
}
builder.setError(null);
dialog.dismiss();
QuickSearch quickSearch = urlBuilder.toQuickSearch();
quickSearch.name = text;
EhDB.insertQuickSearch(quickSearch);
mQuickSearchList.add(quickSearch);
adapter.notifyDataSetChanged();
builder.setError(null);
dialog.dismiss();
QuickSearch quickSearch = urlBuilder.toQuickSearch();
quickSearch.name = text;
EhDB.insertQuickSearch(quickSearch);
mQuickSearchList.add(quickSearch);
adapter.notifyDataSetChanged();
if (0 == mQuickSearchList.size()) {
tip.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
tip.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
if (0 == mQuickSearchList.size()) {
tip.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);
} else {
tip.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
});
}
@@ -787,14 +781,12 @@ public final class GalleryListScene extends BaseScene
toolbar.inflateMenu(R.menu.drawer_gallery_list);
toolbar.setOnMenuItemClickListener(item -> {
int id = item.getItemId();
switch (id) {
case R.id.action_add:
if (Settings.getQuickSearchTip()) {
showQuickSearchTipDialog(qsDrawerAdapter, recyclerView, tip);
} else {
showAddQuickSearchDialog(qsDrawerAdapter, recyclerView, tip);
}
break;
if (id == R.id.action_add) {
if (Settings.getQuickSearchTip()) {
showQuickSearchTipDialog(qsDrawerAdapter, recyclerView, tip);
} else {
showAddQuickSearchDialog(qsDrawerAdapter, recyclerView, tip);
}
}
return true;
});
@@ -913,31 +905,28 @@ public final class GalleryListScene extends BaseScene
final AlertDialog dialog = builder.setTitle(R.string.go_to)
.setPositiveButton(android.R.string.ok, null)
.show();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null == mHelper) {
dialog.dismiss();
return;
}
String text = builder.getText().trim();
int goTo;
try {
goTo = Integer.parseInt(text) - 1;
} catch (NumberFormatException e) {
builder.setError(getString(R.string.error_invalid_number));
return;
}
if (goTo < 0 || goTo >= pages) {
builder.setError(getString(R.string.error_out_of_range));
return;
}
builder.setError(null);
mHelper.goTo(goTo);
AppHelper.hideSoftInput(dialog);
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
if (null == mHelper) {
dialog.dismiss();
return;
}
String text = builder.getText().trim();
int goTo;
try {
goTo = Integer.parseInt(text) - 1;
} catch (NumberFormatException e) {
builder.setError(getString(R.string.error_invalid_number));
return;
}
if (goTo < 0 || goTo >= pages) {
builder.setError(getString(R.string.error_out_of_range));
return;
}
builder.setError(null);
mHelper.goTo(goTo);
AppHelper.hideSoftInput(dialog);
dialog.dismiss();
});
}
@@ -1501,7 +1490,7 @@ public final class GalleryListScene extends BaseScene
}
}
private class QsDrawerHolder extends AbstractDraggableItemViewHolder {
private static class QsDrawerHolder extends AbstractDraggableItemViewHolder {
private final TextView key;
private final ImageView option;
@@ -1525,7 +1514,7 @@ public final class GalleryListScene extends BaseScene
@NonNull
@Override
public QsDrawerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new QsDrawerHolder(mInflater.inflate(R.layout.item_quicksearch_list, parent, false));
return new QsDrawerHolder(mInflater.inflate(R.layout.item_drawer_list, parent, false));
}
@Override
@@ -1584,7 +1573,7 @@ public final class GalleryListScene extends BaseScene
}
@Override
public ItemDraggableRange onGetItemDraggableRange(QsDrawerHolder holder, int position) {
public ItemDraggableRange onGetItemDraggableRange(@NonNull QsDrawerHolder holder, int position) {
return null;
}