Add select download label
This commit is contained in:
1 parent
a0b273bb72
commit
d2553b39a6
11 files changed
+183
-17
No files matched your search
@@ -273,6 +273,28 @@ public class Settings {
|
||||
putString(KEY_RECENT_DOWNLOAD_LABEL, value);
|
||||
}
|
||||
|
||||
private static final String KEY_HAS_DEFAULT_DOWNLOAD_LABEL = "has_default_download_label";
|
||||
private static final boolean DEFAULT_HAS_DOWNLOAD_LABEL = false;
|
||||
|
||||
public static boolean getHasDefaultDownloadLabel() {
|
||||
return getBoolean(KEY_HAS_DEFAULT_DOWNLOAD_LABEL, DEFAULT_HAS_DOWNLOAD_LABEL);
|
||||
}
|
||||
|
||||
public static void putHasDefaultDownloadLabel(boolean hasDefaultDownloadLabel) {
|
||||
putBoolean(KEY_HAS_DEFAULT_DOWNLOAD_LABEL, hasDefaultDownloadLabel);
|
||||
}
|
||||
|
||||
private static final String KEY_DEFAULT_DOWNLOAD_LABEL = "default_download_label";
|
||||
private static final String DEFAULT_DOWNLOAD_LABEL = null;
|
||||
|
||||
public static String getDefaultDownloadLabel() {
|
||||
return getString(KEY_DEFAULT_DOWNLOAD_LABEL, DEFAULT_DOWNLOAD_LABEL);
|
||||
}
|
||||
|
||||
public static void putDefaultDownloadLabel(String value) {
|
||||
putString(KEY_DEFAULT_DOWNLOAD_LABEL, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Favorites
|
||||
********************/
|
||||
|
||||
@@ -174,6 +174,10 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containDownloadInfo(int gid) {
|
||||
return mAllInfoMap.indexOfKey(gid) >= 0;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<DownloadLabelRaw> getLabelList() {
|
||||
return mLabelList;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import com.hippo.app.ListCheckBoxDialogBuilder;
|
||||
@@ -27,6 +28,11 @@ import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.client.EhRequest;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.dao.DownloadLabelRaw;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.download.DownloadService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class CommonOperations {
|
||||
|
||||
@@ -63,10 +69,10 @@ public final class CommonOperations {
|
||||
public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) {
|
||||
int slot = position - 1;
|
||||
doAddToFavorites(activity, galleryInfo, slot, listener);
|
||||
if (!builder.isChecked()) {
|
||||
Settings.putDefaultFavSlot(Settings.INVALID_DEFAULT_FAV_SLOT);
|
||||
} else {
|
||||
if (builder.isChecked()) {
|
||||
Settings.putDefaultFavSlot(slot);
|
||||
} else {
|
||||
Settings.putDefaultFavSlot(Settings.INVALID_DEFAULT_FAV_SLOT);
|
||||
}
|
||||
}
|
||||
}, activity.getString(R.string.remember_favorite_slot), false)
|
||||
@@ -84,4 +90,63 @@ public final class CommonOperations {
|
||||
request.setCallback(listener);
|
||||
client.execute(request);
|
||||
}
|
||||
|
||||
public static void startDownload(final Activity activity, final GalleryInfo galleryInfo) {
|
||||
final DownloadManager dm = EhApplication.getDownloadManager(activity);
|
||||
|
||||
boolean justStart = dm.containDownloadInfo(galleryInfo.gid);
|
||||
String label = null;
|
||||
if (!justStart && Settings.getHasDefaultDownloadLabel()) {
|
||||
label = Settings.getDefaultDownloadLabel();
|
||||
justStart = label == null || dm.containLabel(label);
|
||||
}
|
||||
|
||||
if (justStart) {
|
||||
// Already in download list or get default label
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_LABEL, label);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
|
||||
activity.startService(intent);
|
||||
} else {
|
||||
// Let use chose label
|
||||
List<DownloadLabelRaw> list = dm.getLabelList();
|
||||
final String[] items = new String[list.size() + 1];
|
||||
items[0] = activity.getString(R.string.default_download_label_name);
|
||||
for (int i = 0, n = list.size(); i < n; i++) {
|
||||
items[i + 1] = list.get(i).getLabel();
|
||||
}
|
||||
|
||||
new ListCheckBoxDialogBuilder(activity, items,
|
||||
new ListCheckBoxDialogBuilder.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) {
|
||||
String label;
|
||||
if (position == 0) {
|
||||
label = null;
|
||||
} else {
|
||||
label = items[position];
|
||||
if (!dm.containLabel(label)) {
|
||||
label = null;
|
||||
}
|
||||
}
|
||||
// Start download
|
||||
Intent intent = new Intent(activity, DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_LABEL, label);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
|
||||
activity.startService(intent);
|
||||
// Save settings
|
||||
if (builder.isChecked()) {
|
||||
Settings.putHasDefaultDownloadLabel(true);
|
||||
Settings.putDefaultDownloadLabel(label);
|
||||
} else {
|
||||
Settings.putHasDefaultDownloadLabel(false);
|
||||
}
|
||||
}
|
||||
}, activity.getString(R.string.remember_download_label), false)
|
||||
.setTitle(R.string.download)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,6 +308,35 @@ public class DownloadScene extends ToolbarScene
|
||||
case R.id.action_settings:
|
||||
startScene(new Announcer(DownloadLabelScene.class));
|
||||
return true;
|
||||
case R.id.action_default_download_label:
|
||||
DownloadManager dm = EhApplication.getDownloadManager(getContext());
|
||||
List<DownloadLabelRaw> 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 AlertDialog.Builder(getContext())
|
||||
.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);
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
switch (id) {
|
||||
case R.id.action_default_favorites_slot:
|
||||
String[] items = new String[12];
|
||||
items[0] = getString(R.string.let_me_select_favorites_slot);
|
||||
items[0] = getString(R.string.let_me_select);
|
||||
items[1] = getString(R.string.local_favorites);
|
||||
String[] favCat = Settings.getFavCat();
|
||||
System.arraycopy(favCat, 0, items, 2, 10);
|
||||
|
||||
@@ -71,7 +71,6 @@ import com.hippo.ehviewer.client.data.GalleryTagGroup;
|
||||
import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.parser.RateGalleryParser;
|
||||
import com.hippo.ehviewer.download.DownloadService;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.ui.annotation.ViewLifeCircle;
|
||||
@@ -992,10 +991,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
galleryInfo = mGalleryDetail;
|
||||
}
|
||||
if (galleryInfo != null) {
|
||||
Intent intent = new Intent(getActivity(), DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, galleryInfo);
|
||||
getActivity().startService(intent);
|
||||
CommonOperations.startDownload(getActivity(), galleryInfo);
|
||||
}
|
||||
} else if (mRead == v) {
|
||||
GalleryInfo galleryInfo = null;
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.animation.Animator;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
@@ -60,7 +59,7 @@ import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListParser;
|
||||
import com.hippo.ehviewer.download.DownloadService;
|
||||
import com.hippo.ehviewer.ui.CommonOperations;
|
||||
import com.hippo.ehviewer.widget.FitPaddingLayout;
|
||||
import com.hippo.ehviewer.widget.SearchBar;
|
||||
import com.hippo.ehviewer.widget.SearchLayout;
|
||||
@@ -460,13 +459,10 @@ public final class GalleryListScene extends BaseScene
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0: // Download
|
||||
Intent intent = new Intent(getActivity(), DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_START);
|
||||
intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi);
|
||||
getActivity().startService(intent);
|
||||
CommonOperations.startDownload(getActivity(), gi);
|
||||
break;
|
||||
case 1: // Favorites
|
||||
// TODO
|
||||
CommonOperations.addToFavorites(getActivity(), gi, new addToFavoriteListener());
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -892,4 +888,20 @@ public final class GalleryListScene extends BaseScene
|
||||
return scene instanceof GalleryListScene;
|
||||
}
|
||||
}
|
||||
|
||||
private class addToFavoriteListener implements EhClient.Callback<Void> {
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void result) {
|
||||
Toast.makeText(getContext(), R.string.add_to_favorite_success, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
Toast.makeText(getContext(), R.string.add_to_favorite_failure, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/primary_drawable_dark"
|
||||
android:pathData="@string/pd_download_box"/>
|
||||
|
||||
</vector>
|
||||
@@ -25,4 +25,10 @@
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_default_download_label"
|
||||
android:icon="@drawable/v_download_box_dark_x24"
|
||||
android:title="@string/default_download_label"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
</menu>
|
||||
@@ -50,6 +50,7 @@
|
||||
<string name="pd_star_outline" translatable="false">M12,15.39L8.24,17.66L9.23,13.38L5.91,10.5L10.29,10.13L12,6.09L13.71,10.13L18.09,10.5L14.77,13.38L15.76,17.66M22,9.24L14.81,8.63L12,2L9.19,8.63L2,9.24L7.45,13.97L5.82,21L12,17.27L18.18,21L16.54,13.97L22,9.24Z</string>
|
||||
<string name="pd_info" translatable="false">M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2Z</string>
|
||||
<string name="pd_heart_box" translatable="false">M5,3H19A2,2 0 0,1 21,5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V5A2,2 0 0,1 5,3M12,17L12.72,16.34C15.3,14 17,12.46 17,10.57C17,9.03 15.79,7.82 14.25,7.82C13.38,7.82 12.55,8.23 12,8.87C11.45,8.23 10.62,7.82 9.75,7.82C8.21,7.82 7,9.03 7,10.57C7,12.46 8.7,14 11.28,16.34L12,17Z</string>
|
||||
<string name="pd_download_box" translatable="false">M19,3H5C3.9,3,3,3.9,3,5V19C3,20.1,3.9,21,5,21H19C20.1,21,21,20.1,21,19V5C21,3.9,20.1,3,19,3ZM12,17L7,12H10V8H14V12H17L12,17Z</string>
|
||||
|
||||
<string name="pd_slider_bubble" translatable="false">M13,0C20.2,0,26,5.9,26,13.2,26,16.9,24,20.8,18.7,26.1L13,32,7.2,26.2C2,20.8,0,16.9,0,13.3,0,5.9,5.8,0,13,0Z</string>
|
||||
|
||||
|
||||
@@ -254,6 +254,8 @@
|
||||
<string name="download_service_label">EhViewer Download Service</string>
|
||||
<string name="download_speed_text">%s</string>
|
||||
<string name="download_speed_text_2">%1$s, %2$s</string>
|
||||
<string name="remember_download_label">Remember download label</string>
|
||||
<string name="default_download_label">Default download label</string>
|
||||
|
||||
<!-- Download label -->
|
||||
<string name="no_download_label">No labels</string>
|
||||
@@ -325,7 +327,7 @@
|
||||
<string name="delete_favorites_dialog_message">Delete %d items from favorites</string>
|
||||
<string name="move_favorites_dialog_title">Move favorites</string>
|
||||
<string name="default_favorites_slot">Default favorites slot</string>
|
||||
<string name="let_me_select_favorites_slot">Let me select when necessary</string>
|
||||
<string name="let_me_select">Let me select</string>
|
||||
|
||||
<!-- Progress Scene -->
|
||||
<string name="error_something_wrong_happened">Something wrong happened</string>
|
||||
|
||||
Reference in new issue
Block a user