Fix warnings
This commit is contained in:
12 files changed
+164
-497
No files matched your search
@@ -34,8 +34,6 @@ import com.hippo.util.ExceptionUtils;
|
||||
|
||||
public class DownloadFragment extends BasePreferenceFragment {
|
||||
|
||||
public static final int REQUEST_CODE_PICK_IMAGE_DIR_L = 1;
|
||||
|
||||
public static final String KEY_DOWNLOAD_LOCATION = "download_location";
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -83,7 +83,6 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadLabel;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
@@ -117,6 +116,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
public class DownloadsScene extends ToolbarScene
|
||||
implements DownloadManager.DownloadInfoListener,
|
||||
FabLayout.OnClickFabListener, FastScroller.OnDragHandlerListener {
|
||||
@@ -159,6 +159,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
private int mType = -1;
|
||||
|
||||
private static void deleteFileAsync(UniFile... files) {
|
||||
//noinspection deprecation
|
||||
new AsyncTask<UniFile, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(UniFile... params) {
|
||||
@@ -518,63 +519,56 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_filter: {
|
||||
new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setSingleChoiceItems(R.array.download_state, mType + 1, (dialog, which) -> {
|
||||
mType = which - 1;
|
||||
updateForLabel();
|
||||
updateView();
|
||||
dialog.dismiss();
|
||||
})
|
||||
.show();
|
||||
if (id == R.id.action_filter) {
|
||||
new MaterialAlertDialogBuilder(requireActivity())
|
||||
.setSingleChoiceItems(R.array.download_state, mType + 1, (dialog, which) -> {
|
||||
mType = which - 1;
|
||||
updateForLabel();
|
||||
updateView();
|
||||
dialog.dismiss();
|
||||
})
|
||||
.show();
|
||||
return true;
|
||||
} else if (id == R.id.action_start_all) {
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START_ALL);
|
||||
ContextCompat.startForegroundService(activity, intent);
|
||||
return true;
|
||||
} else if (id == R.id.action_stop_all) {
|
||||
if (null != mDownloadManager) {
|
||||
mDownloadManager.stopAllDownload();
|
||||
}
|
||||
return true;
|
||||
} else if (id == R.id.action_open_download_labels) {
|
||||
openDrawer(Gravity.RIGHT);
|
||||
return true;
|
||||
} else if (id == R.id.action_reset_reading_progress) {
|
||||
new MaterialAlertDialogBuilder(getContext())
|
||||
.setMessage(R.string.reset_reading_progress_message)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
if (mDownloadManager != null) {
|
||||
mDownloadManager.resetAllReadingProgress();
|
||||
}
|
||||
}).show();
|
||||
return true;
|
||||
} else if (id == R.id.action_start_all_reversed) {
|
||||
List<DownloadInfo> list = mList;
|
||||
if (list == null) {
|
||||
return true;
|
||||
}
|
||||
case R.id.action_start_all: {
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START_ALL);
|
||||
ContextCompat.startForegroundService(activity, intent);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_stop_all: {
|
||||
if (null != mDownloadManager) {
|
||||
mDownloadManager.stopAllDownload();
|
||||
LongList gidList = new LongList();
|
||||
for (int i = list.size() - 1; i > -1; i--) {
|
||||
DownloadInfo info = list.get(i);
|
||||
if (info.state != DownloadInfo.STATE_FINISH) {
|
||||
gidList.add(info.gid);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case R.id.action_open_download_labels: {
|
||||
openDrawer(Gravity.RIGHT);
|
||||
return true;
|
||||
}
|
||||
case R.id.action_reset_reading_progress: {
|
||||
new MaterialAlertDialogBuilder(getContext())
|
||||
.setMessage(R.string.reset_reading_progress_message)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
|
||||
if (mDownloadManager != null) {
|
||||
mDownloadManager.resetAllReadingProgress();
|
||||
}
|
||||
}).show();
|
||||
return true;
|
||||
}
|
||||
case R.id.action_start_all_reversed: {
|
||||
List<DownloadInfo> list = mList;
|
||||
if (list == null) {
|
||||
return true;
|
||||
}
|
||||
LongList gidList = new LongList();
|
||||
for (int i = list.size() - 1; i > -1; i--) {
|
||||
DownloadInfo info = list.get(i);
|
||||
if (info.state != DownloadInfo.STATE_FINISH) {
|
||||
gidList.add(info.gid);
|
||||
}
|
||||
}
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START_RANGE);
|
||||
intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
|
||||
ContextCompat.startForegroundService(activity, intent);
|
||||
return true;
|
||||
}
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START_RANGE);
|
||||
intent.putExtra(DownloadService.KEY_GID_LIST, gidList);
|
||||
ContextCompat.startForegroundService(activity, intent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -602,44 +596,43 @@ public class DownloadsScene extends ToolbarScene
|
||||
toolbar.inflateMenu(R.menu.drawer_download);
|
||||
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);
|
||||
if (id == 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;
|
||||
} else if (id == 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, (dialog1, which) -> {
|
||||
if (which == 0) {
|
||||
Settings.putHasDefaultDownloadLabel(false);
|
||||
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 {
|
||||
Settings.putHasDefaultDownloadLabel(true);
|
||||
String label;
|
||||
if (which == 1) {
|
||||
label = null;
|
||||
} else {
|
||||
label = items[which];
|
||||
}
|
||||
Settings.putDefaultDownloadLabel(label);
|
||||
label = items[which];
|
||||
}
|
||||
}).show();
|
||||
return true;
|
||||
Settings.putDefaultDownloadLabel(label);
|
||||
}
|
||||
}).show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@@ -819,7 +812,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
for (int i = 0, n = labelRawList.size(); i < n; i++) {
|
||||
labelList.add(labelRawList.get(i).getLabel());
|
||||
}
|
||||
String[] labels = labelList.toArray(new String[labelList.size()]);
|
||||
String[] labels = labelList.toArray(new String[0]);
|
||||
|
||||
MoveDialogHelper helper = new MoveDialogHelper(labels, downloadInfoList);
|
||||
|
||||
@@ -1060,29 +1053,25 @@ public class DownloadsScene extends ToolbarScene
|
||||
popupMenu.inflate(R.menu.download_label_option);
|
||||
popupMenu.show();
|
||||
popupMenu.setOnMenuItemClickListener(item -> {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_label_rename: {
|
||||
EditTextDialogBuilder builder = new EditTextDialogBuilder(
|
||||
context, label, 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, label);
|
||||
break;
|
||||
}
|
||||
case R.id.menu_label_remove: {
|
||||
new MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(getString(R.string.delete_label_title))
|
||||
.setMessage(getString(R.string.delete_label_message, label))
|
||||
.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||
mDownloadManager.deleteLabel(label);
|
||||
mLabels.remove(position);
|
||||
notifyDataSetChanged();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
break;
|
||||
}
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.menu_label_rename) {
|
||||
EditTextDialogBuilder builder = new EditTextDialogBuilder(
|
||||
context, label, 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, label);
|
||||
} else if (itemId == R.id.menu_label_remove) {
|
||||
new MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(getString(R.string.delete_label_title))
|
||||
.setMessage(getString(R.string.delete_label_message, label))
|
||||
.setPositiveButton(R.string.delete, (dialog, which) -> {
|
||||
mDownloadManager.deleteLabel(label);
|
||||
mLabels.remove(position);
|
||||
notifyDataSetChanged();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@@ -1143,44 +1132,6 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
}
|
||||
|
||||
private class DeleteDialogHelper implements DialogInterface.OnClickListener {
|
||||
|
||||
private final GalleryInfo mGalleryInfo;
|
||||
private final CheckBoxDialogBuilder mBuilder;
|
||||
|
||||
public DeleteDialogHelper(GalleryInfo galleryInfo, CheckBoxDialogBuilder builder) {
|
||||
mGalleryInfo = galleryInfo;
|
||||
mBuilder = builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which != DialogInterface.BUTTON_POSITIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete
|
||||
if (null != mDownloadManager) {
|
||||
mDownloadManager.deleteDownload(mGalleryInfo.gid);
|
||||
}
|
||||
|
||||
// Delete image files
|
||||
boolean checked = mBuilder.isChecked();
|
||||
Settings.putRemoveImageFiles(checked);
|
||||
if (checked) {
|
||||
// Remove download path
|
||||
EhDB.removeDownloadDirname(mGalleryInfo.gid);
|
||||
// Delete file
|
||||
UniFile file = SpiderDen.getGalleryDownloadDir(mGalleryInfo);
|
||||
deleteFileAsync(file);
|
||||
}
|
||||
if (mLabelAdapter != null) {
|
||||
initLabels();
|
||||
mLabelAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DeleteRangeDialogHelper implements DialogInterface.OnClickListener {
|
||||
|
||||
private final List<DownloadInfo> mDownloadInfoList;
|
||||
@@ -1346,7 +1297,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
mInflater = getLayoutInflater();
|
||||
AssertUtils.assertNotNull(mInflater);
|
||||
|
||||
View calculator = mInflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
@SuppressLint("InflateParams") View calculator = mInflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mListThumbHeight = calculator.getMeasuredHeight();
|
||||
mListThumbWidth = mListThumbHeight * 2 / 3;
|
||||
@@ -1386,7 +1337,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
holder.rating.setRating(info.rating);
|
||||
TextView category = holder.category;
|
||||
String newCategoryText = EhUtils.getCategory(info.category);
|
||||
if (!newCategoryText.equals(category.getText())) {
|
||||
if (!newCategoryText.contentEquals(category.getText())) {
|
||||
category.setText(newCategoryText);
|
||||
category.setBackgroundColor(EhUtils.getCategoryColor(info.category));
|
||||
}
|
||||
@@ -1435,7 +1386,7 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
}
|
||||
|
||||
private class ThumbDataContainer implements DataContainer {
|
||||
private static class ThumbDataContainer implements DataContainer {
|
||||
|
||||
private final DownloadInfo mInfo;
|
||||
@Nullable
|
||||
|
||||
@@ -90,6 +90,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
// TODO Get favorite, modify favorite, add favorite, what a mess!
|
||||
@SuppressLint("RtlHardcoded")
|
||||
public class FavoritesScene extends BaseScene implements
|
||||
FastScroller.OnDragHandlerListener, SearchBarMover.Helper, SearchBar.Helper,
|
||||
FabLayout.OnClickFabListener, FabLayout.OnExpandListener,
|
||||
@@ -509,9 +510,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
|
||||
// Ensure outOfCustomChoiceMode to avoid error
|
||||
if (mRecyclerView != null) {
|
||||
mRecyclerView.isInCustomChoice();
|
||||
}
|
||||
//if (mRecyclerView != null) {
|
||||
// mRecyclerView.isInCustomChoice();
|
||||
//}
|
||||
|
||||
exitSearchMode(true);
|
||||
|
||||
@@ -544,7 +545,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean onItemLongClick(View view, int position) {
|
||||
public boolean onItemLongClick(int position) {
|
||||
// Can not into
|
||||
if (mRecyclerView != null && !mSearchMode) {
|
||||
if (!mRecyclerView.isInCustomChoice()) {
|
||||
@@ -638,9 +639,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
|
||||
// Ensure outOfCustomChoiceMode to avoid error
|
||||
if (mRecyclerView != null) {
|
||||
mRecyclerView.isInCustomChoice();
|
||||
}
|
||||
//if (mRecyclerView != null) {
|
||||
// mRecyclerView.isInCustomChoice();
|
||||
//}
|
||||
|
||||
exitSearchMode(true);
|
||||
|
||||
@@ -1026,7 +1027,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
}
|
||||
|
||||
private class FavDrawerHolder extends RecyclerView.ViewHolder {
|
||||
private static class FavDrawerHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private final TextView key;
|
||||
private final TextView value;
|
||||
@@ -1196,7 +1197,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
|
||||
@Override
|
||||
boolean onItemLongClick(View view, int position) {
|
||||
return FavoritesScene.this.onItemLongClick(view, position);
|
||||
return FavoritesScene.this.onItemLongClick(position);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -1264,12 +1265,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
} else if (mUrlBuilder.getFavCat() == FavListUrlBuilder.FAV_CAT_LOCAL) {
|
||||
final String keyword = mUrlBuilder.getKeyword();
|
||||
SimpleHandler.getInstance().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onGetFavoritesLocal(keyword, taskId);
|
||||
}
|
||||
});
|
||||
SimpleHandler.getInstance().post(() -> onGetFavoritesLocal(keyword, taskId));
|
||||
} else {
|
||||
mUrlBuilder.setIndex(page);
|
||||
String url = mUrlBuilder.build();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
@@ -77,7 +78,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
mRecyclerView.setAdapter(this);
|
||||
mRecyclerView.setLayoutManager(mLayoutManager);
|
||||
|
||||
View calculator = inflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
@SuppressLint("InflateParams") View calculator = inflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mListThumbHeight = calculator.getMeasuredHeight();
|
||||
mListThumbWidth = mListThumbHeight * 2 / 3;
|
||||
@@ -147,8 +148,9 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public GalleryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public GalleryHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
int layoutId;
|
||||
switch (viewType) {
|
||||
default:
|
||||
@@ -184,8 +186,9 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
@Nullable
|
||||
public abstract GalleryInfo getDataAt(int position);
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onBindViewHolder(GalleryHolder holder, int position) {
|
||||
public void onBindViewHolder(@NonNull GalleryHolder holder, int position) {
|
||||
GalleryInfo gi = getDataAt(position);
|
||||
if (null == gi) {
|
||||
return;
|
||||
@@ -231,7 +234,7 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
|
||||
int color = EhUtils.getCategoryColor(gi.category);
|
||||
if (!(drawable instanceof TriangleDrawable)) {
|
||||
drawable = new TriangleDrawable(color);
|
||||
category.setBackgroundDrawable(drawable);
|
||||
category.setBackground(drawable);
|
||||
} else {
|
||||
((TriangleDrawable) drawable).setColor(color);
|
||||
}
|
||||
|
||||
@@ -1535,20 +1535,18 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
|
||||
@Override
|
||||
protected void onSceneResult(int requestCode, int resultCode, Bundle data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_COMMENT_GALLERY:
|
||||
if (resultCode != RESULT_OK || data == null) {
|
||||
break;
|
||||
}
|
||||
GalleryCommentList comments = data.getParcelable(GalleryCommentsScene.KEY_COMMENT_LIST);
|
||||
if (mGalleryDetail == null && comments == null) {
|
||||
break;
|
||||
}
|
||||
mGalleryDetail.comments = comments;
|
||||
bindComments(comments.comments);
|
||||
break;
|
||||
default:
|
||||
super.onSceneResult(requestCode, resultCode, data);
|
||||
if (requestCode == REQUEST_CODE_COMMENT_GALLERY) {
|
||||
if (resultCode != RESULT_OK || data == null) {
|
||||
return;
|
||||
}
|
||||
GalleryCommentList comments = data.getParcelable(GalleryCommentsScene.KEY_COMMENT_LIST);
|
||||
if (mGalleryDetail == null && comments == null) {
|
||||
return;
|
||||
}
|
||||
mGalleryDetail.comments = comments;
|
||||
bindComments(comments.comments);
|
||||
} else {
|
||||
super.onSceneResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -255,14 +255,15 @@ public final class GalleryInfoScene extends ToolbarScene {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public InfoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
return new InfoHolder(mInflater.inflate(viewType == TYPE_HEADER ?
|
||||
R.layout.item_gallery_info_header : R.layout.item_gallery_info_data, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(InfoHolder holder, int position) {
|
||||
public void onBindViewHolder(@NonNull InfoHolder holder, int position) {
|
||||
if (mKeys != null && mValues != null) {
|
||||
holder.key.setText(mKeys.get(position));
|
||||
holder.value.setText(mValues.get(position));
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
@@ -122,12 +123,12 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
public final class GalleryListScene extends BaseScene
|
||||
implements SearchBar.Helper, SearchBar.OnStateChangeListener, FastScroller.OnDragHandlerListener,
|
||||
SearchLayout.Helper, SearchBarMover.Helper, View.OnClickListener, FabLayout.OnClickFabListener,
|
||||
FabLayout.OnExpandListener {
|
||||
|
||||
public final static int REQUEST_CODE_SELECT_IMAGE = 0;
|
||||
public final static String KEY_ACTION = "action";
|
||||
public final static String ACTION_HOMEPAGE = "action_homepage";
|
||||
public final static String ACTION_SUBSCRIPTION = "action_subscription";
|
||||
@@ -992,7 +993,7 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onItemLongClick(View view, int position) {
|
||||
public boolean onItemLongClick(int position) {
|
||||
final Context context = getContext();
|
||||
final MainActivity activity = getMainActivity();
|
||||
if (null == context || null == activity || null == mHelper) {
|
||||
@@ -1458,17 +1459,6 @@ public final class GalleryListScene extends BaseScene
|
||||
return mState == STATE_SIMPLE_SEARCH || mState == STATE_SEARCH_SHOW_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (REQUEST_CODE_SELECT_IMAGE == requestCode) {
|
||||
if (Activity.RESULT_OK == resultCode && null != mSearchLayout && null != data) {
|
||||
mSearchLayout.setImageUri(data.getData());
|
||||
}
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
private void onGetGalleryListSuccess(GalleryListParser.Result result, int taskId) {
|
||||
if (mHelper != null && mSearchBarMover != null &&
|
||||
mHelper.isCurrentTask(taskId)) {
|
||||
@@ -1818,7 +1808,7 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
@Override
|
||||
boolean onItemLongClick(View view, int position) {
|
||||
return GalleryListScene.this.onItemLongClick(view, position);
|
||||
return GalleryListScene.this.onItemLongClick(position);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
@@ -290,6 +291,7 @@ public class HistoryScene extends ToolbarScene {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
@Override
|
||||
public void onNavigationClick() {
|
||||
toggleDrawer(Gravity.LEFT);
|
||||
@@ -312,7 +314,9 @@ public class HistoryScene extends ToolbarScene {
|
||||
updateLazyList();
|
||||
mAdapter.notifyDataSetChanged();
|
||||
updateView(true);
|
||||
}).show();
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -324,11 +328,9 @@ public class HistoryScene extends ToolbarScene {
|
||||
}
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_clear_all: {
|
||||
showClearAllDialog();
|
||||
return true;
|
||||
}
|
||||
if (id == R.id.action_clear_all) {
|
||||
showClearAllDialog();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -561,6 +563,7 @@ public class HistoryScene extends ToolbarScene {
|
||||
simpleLanguage = itemView.findViewById(R.id.simple_language);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View getSwipeableContainerView() {
|
||||
return card;
|
||||
@@ -577,7 +580,7 @@ public class HistoryScene extends ToolbarScene {
|
||||
public HistoryAdapter() {
|
||||
mInflater = getLayoutInflater();
|
||||
|
||||
View calculator = mInflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
@SuppressLint("InflateParams") View calculator = mInflater.inflate(R.layout.item_gallery_list_thumb_height, null);
|
||||
ViewUtils.measureView(calculator, 1024, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
mListThumbHeight = calculator.getMeasuredHeight();
|
||||
mListThumbWidth = mListThumbHeight * 2 / 3;
|
||||
@@ -592,8 +595,9 @@ public class HistoryScene extends ToolbarScene {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public HistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
public HistoryHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
HistoryHolder holder = new HistoryHolder(mInflater.inflate(R.layout.item_history, parent, false));
|
||||
|
||||
ViewGroup.LayoutParams lp = holder.thumb.getLayoutParams();
|
||||
@@ -605,7 +609,7 @@ public class HistoryScene extends ToolbarScene {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(HistoryHolder holder, int position) {
|
||||
public void onBindViewHolder(@NonNull HistoryHolder holder, int position) {
|
||||
if (null == mLazyList) {
|
||||
return;
|
||||
}
|
||||
@@ -617,7 +621,7 @@ public class HistoryScene extends ToolbarScene {
|
||||
holder.rating.setRating(gi.rating);
|
||||
TextView category = holder.category;
|
||||
String newCategoryText = EhUtils.getCategory(gi.category);
|
||||
if (!newCategoryText.equals(category.getText())) {
|
||||
if (!newCategoryText.contentEquals(category.getText())) {
|
||||
category.setText(newCategoryText);
|
||||
category.setBackgroundColor(EhUtils.getCategoryColor(gi.category));
|
||||
}
|
||||
@@ -638,25 +642,28 @@ public class HistoryScene extends ToolbarScene {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onGetSwipeReactionType(HistoryHolder holder, int position, int x, int y) {
|
||||
public int onGetSwipeReactionType(@NonNull HistoryHolder holder, int position, int x, int y) {
|
||||
return SwipeableItemConstants.REACTION_CAN_SWIPE_LEFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwipeItemStarted(HistoryHolder holder, int position) {
|
||||
public void onSwipeItemStarted(@NonNull HistoryHolder holder, int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetSwipeBackground(HistoryHolder holder, int position, int type) {
|
||||
public void onSetSwipeBackground(@NonNull HistoryHolder holder, int position, int type) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwipeResultAction onSwipeItem(HistoryHolder holder, int position, int result) {
|
||||
public SwipeResultAction onSwipeItem(@NonNull HistoryHolder holder, int position, int result) {
|
||||
switch (result) {
|
||||
case SwipeableItemConstants.RESULT_SWIPED_LEFT:
|
||||
return new SwipeResultActionClear(position);
|
||||
case SwipeableItemConstants.RESULT_SWIPED_RIGHT:
|
||||
case SwipeableItemConstants.RESULT_CANCELED:
|
||||
case SwipeableItemConstants.RESULT_NONE:
|
||||
case SwipeableItemConstants.RESULT_SWIPED_DOWN:
|
||||
case SwipeableItemConstants.RESULT_SWIPED_UP:
|
||||
default:
|
||||
return new SwipeResultActionDefault();
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
redirectTo();
|
||||
}
|
||||
|
||||
private class SignInListener extends EhCallback<SignInScene, String> {
|
||||
private static class SignInListener extends EhCallback<SignInScene, String> {
|
||||
|
||||
public SignInListener(Context context, int stageId, String sceneTag) {
|
||||
super(context, stageId, sceneTag);
|
||||
@@ -395,7 +395,7 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc
|
||||
}
|
||||
}
|
||||
|
||||
private class GetProfileListener extends EhCallback<SignInScene, ProfileParser.Result> {
|
||||
private static class GetProfileListener extends EhCallback<SignInScene, ProfileParser.Result> {
|
||||
|
||||
public GetProfileListener(Context context, int stageId, String sceneTag) {
|
||||
super(context, stageId, sceneTag);
|
||||
|
||||
@@ -1,272 +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.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// TODO GridLayoutManager do not work at all ! SpaceGroupIndex is useless for layout! I need to create one by myself
|
||||
public class ThumbSpanHelper {
|
||||
|
||||
private static final int MIN_ARRAY_LENGTH = 50;
|
||||
private static final int MAX_ROW_INTERVAL = 3;
|
||||
|
||||
private final List<GalleryInfo> mData;
|
||||
|
||||
// true for occupied, false for free
|
||||
private boolean[] mCells = new boolean[MIN_ARRAY_LENGTH];
|
||||
|
||||
private int mNextIndex;
|
||||
private int mNextGroupIndex;
|
||||
private int mNearSpaceIndex;
|
||||
private int mNearSpaceGroupIndex;
|
||||
private int mAttachedCount;
|
||||
|
||||
private int mSpanCount;
|
||||
|
||||
private boolean mEnable;
|
||||
|
||||
public ThumbSpanHelper(List<GalleryInfo> data) {
|
||||
mData = data;
|
||||
}
|
||||
|
||||
public void setEnable(boolean enable) {
|
||||
if (enable == mEnable) {
|
||||
return;
|
||||
}
|
||||
mEnable = enable;
|
||||
|
||||
if (!enable) {
|
||||
clear();
|
||||
mSpanCount = 0;
|
||||
} else {
|
||||
if (mSpanCount > 0) {
|
||||
rebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSpanCount(int spanCount) {
|
||||
if (!mEnable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spanCount == mSpanCount) {
|
||||
return;
|
||||
}
|
||||
mSpanCount = spanCount;
|
||||
if (spanCount > 0) {
|
||||
rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged() {
|
||||
if (!mEnable || mSpanCount <= 0) {
|
||||
return;
|
||||
}
|
||||
rebuild();
|
||||
}
|
||||
|
||||
public void notifyItemRangeRemoved(int positionStart, int itemCount) {
|
||||
if (!mEnable || mSpanCount <= 0) {
|
||||
return;
|
||||
}
|
||||
rebuild();
|
||||
}
|
||||
|
||||
protected void notifyItemRangeInserted(int positionStart, int itemCount) {
|
||||
if (!mEnable || mSpanCount <= 0) {
|
||||
return;
|
||||
}
|
||||
if (mAttachedCount == positionStart) {
|
||||
append();
|
||||
} else {
|
||||
rebuild();
|
||||
}
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
|
||||
Log.d("TAG", "=======================clear=======================");
|
||||
|
||||
if (mSpanCount > 0) {
|
||||
if (mNextGroupIndex > 0 || mNextIndex > 0) {
|
||||
Arrays.fill(mCells, 0, mNextGroupIndex * mSpanCount + mNextIndex, false);
|
||||
}
|
||||
} else {
|
||||
Arrays.fill(mCells, false);
|
||||
}
|
||||
mNextIndex = 0;
|
||||
mNextGroupIndex = 0;
|
||||
mNearSpaceIndex = 0;
|
||||
mNearSpaceGroupIndex = 0;
|
||||
mAttachedCount = 0;
|
||||
}
|
||||
|
||||
private void rebuild() {
|
||||
clear();
|
||||
append();
|
||||
}
|
||||
|
||||
private void append() {
|
||||
if (1 == mSpanCount) {
|
||||
for (int i = mAttachedCount, n = mData.size(); i < n; i++) {
|
||||
GalleryInfo gi = mData.get(i);
|
||||
gi.spanSize = 1;
|
||||
gi.spanGroupIndex = i;
|
||||
gi.spanIndex = 0;
|
||||
}
|
||||
mAttachedCount = mData.size();
|
||||
} else if (mSpanCount >= 2) {
|
||||
for (int i = mAttachedCount, n = mData.size(); i < n; i++) {
|
||||
GalleryInfo gi = mData.get(i);
|
||||
int spanSize = gi.thumbWidth <= gi.thumbHeight ? 1 : 2;
|
||||
gi.spanSize = spanSize;
|
||||
|
||||
if (1 == spanSize) {
|
||||
// Update near space
|
||||
updateNearSpace();
|
||||
|
||||
Log.d("TAG", "Update mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
|
||||
if (mNextIndex == mNearSpaceIndex && mNextGroupIndex == mNearSpaceGroupIndex) {
|
||||
// No space, just append
|
||||
gi.spanIndex = mNextIndex;
|
||||
gi.spanGroupIndex = mNextGroupIndex;
|
||||
|
||||
// Update cell
|
||||
int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
|
||||
fillCell(start, start + 1);
|
||||
|
||||
// Update field
|
||||
mNextIndex++;
|
||||
if (mSpanCount == mNextIndex) {
|
||||
mNextIndex = 0;
|
||||
mNextGroupIndex++;
|
||||
}
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
|
||||
Log.d("TAG", "type 0");
|
||||
Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
|
||||
Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
|
||||
Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
|
||||
} else {
|
||||
// Found space
|
||||
gi.spanIndex = mNearSpaceIndex;
|
||||
gi.spanGroupIndex = mNearSpaceGroupIndex;
|
||||
|
||||
// Update cell
|
||||
int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
|
||||
fillCell(start, start + 1);
|
||||
|
||||
// Find near space
|
||||
findNearSpace(start + 1);
|
||||
|
||||
Log.d("TAG", "type 1");
|
||||
Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
|
||||
Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
|
||||
Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
}
|
||||
} else {
|
||||
boolean syncNear = mNextIndex == mNearSpaceIndex && mNextGroupIndex == mNearSpaceGroupIndex;
|
||||
// false for old, true for new
|
||||
boolean oldOrNew;
|
||||
if (mSpanCount - mNextIndex >= 2) {
|
||||
gi.spanIndex = mNextIndex;
|
||||
gi.spanGroupIndex = mNextGroupIndex;
|
||||
oldOrNew = true;
|
||||
} else {
|
||||
// Go to next row
|
||||
gi.spanIndex = 0;
|
||||
gi.spanGroupIndex = mNextGroupIndex + 1;
|
||||
oldOrNew = false;
|
||||
}
|
||||
|
||||
// Update cell
|
||||
int start = gi.spanGroupIndex * mSpanCount + gi.spanIndex;
|
||||
fillCell(start, start + 2);
|
||||
|
||||
// Update field
|
||||
if (syncNear && !oldOrNew) {
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
}
|
||||
mNextIndex = gi.spanIndex + 2;
|
||||
mNextGroupIndex = gi.spanGroupIndex;
|
||||
if (mSpanCount == mNextIndex) {
|
||||
mNextIndex = 0;
|
||||
mNextGroupIndex++;
|
||||
}
|
||||
if (syncNear && oldOrNew) {
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
}
|
||||
|
||||
Log.d("TAG", "type 2");
|
||||
Log.d("TAG", "i = " + i + ", spanSize = " + spanSize + ", spanGroupIndex = " + gi.spanGroupIndex + ", spanIndex = " + gi.spanIndex);
|
||||
Log.d("TAG", "mNextGroupIndex = " + mNextGroupIndex + ", mNextIndex = " + mNextIndex);
|
||||
Log.d("TAG", "mNearSpaceGroupIndex = " + mNearSpaceGroupIndex + ", mNearSpaceIndex = " + mNearSpaceIndex);
|
||||
}
|
||||
}
|
||||
mAttachedCount = mData.size();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNearSpace() {
|
||||
// Check is space is near enough
|
||||
if (mNextGroupIndex - mNearSpaceGroupIndex <= MAX_ROW_INTERVAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The space is too far, find a near one
|
||||
int start = Math.max(0, mNextGroupIndex - MAX_ROW_INTERVAL) * mSpanCount;
|
||||
findNearSpace(start);
|
||||
}
|
||||
|
||||
private void findNearSpace(int start) {
|
||||
int end = mNextGroupIndex * mSpanCount + mNextIndex;
|
||||
boolean[] cells = mCells;
|
||||
for (int i = start; i < end; i++) {
|
||||
if (!cells[i]) {
|
||||
// Find space !
|
||||
mNearSpaceIndex = i % mSpanCount;
|
||||
mNearSpaceGroupIndex = i / mSpanCount;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Can't find space
|
||||
mNearSpaceIndex = mNextIndex;
|
||||
mNearSpaceGroupIndex = mNextGroupIndex;
|
||||
}
|
||||
|
||||
private void fillCell(int start, int end) {
|
||||
boolean[] array = mCells;
|
||||
// Avoid IndexOutOfBoundsException
|
||||
if (end >= array.length) {
|
||||
boolean[] newArray = new boolean[end + (end < (MIN_ARRAY_LENGTH / 2) ? MIN_ARRAY_LENGTH : end >> 1)];
|
||||
System.arraycopy(array, 0, newArray, 0, array.length);
|
||||
mCells = array = newArray;
|
||||
}
|
||||
Arrays.fill(array, start, end, true);
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,6 @@ public abstract class ToolbarScene extends BaseScene {
|
||||
if (menuResId != 0) {
|
||||
mToolbar.inflateMenu(menuResId);
|
||||
mToolbar.setOnMenuItemClickListener(ToolbarScene.this::onMenuItemClick);
|
||||
onMenuCreated(mToolbar.getMenu());
|
||||
}
|
||||
mToolbar.setNavigationOnClickListener(v -> onNavigationClick());
|
||||
}
|
||||
@@ -99,9 +98,6 @@ public abstract class ToolbarScene extends BaseScene {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void onMenuCreated(Menu menu) {
|
||||
}
|
||||
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ public class WebViewSignInScene extends SolidScene {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
Reference in new issue
Block a user