diff --git a/res/layout/add_to_favorite.xml b/res/layout/add_to_favorite.xml
new file mode 100644
index 000000000..328e83fc0
--- /dev/null
+++ b/res/layout/add_to_favorite.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/list_item_text.xml b/res/layout/list_item_text.xml
index aee8fc361..767740934 100644
--- a/res/layout/list_item_text.xml
+++ b/res/layout/list_item_text.xml
@@ -25,4 +25,5 @@
android:paddingRight="24dp"
android:minHeight="48dp"
android:maxHeight="48dp"
- android:singleLine="true" />
\ No newline at end of file
+ android:singleLine="true"
+ android:textColor="@android:color/black" />
\ No newline at end of file
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index b77dff85e..02e8b1e38 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -150,6 +150,8 @@
本地收藏
选择项目
+ 添加至何处?
+ 添加失败
移动至何处?
正在移动…
移动成功
@@ -157,6 +159,7 @@
目标与源相同
删除成功
删除失败
+ 设为默认收藏夹
显示
@@ -182,6 +185,8 @@
允许媒体扫描
请避免他人翻看你的图库应用
大多数图库应用将不会显示下载目录中的图片
+ 收藏
+ 默认收藏夹
关于
作者
@@ -197,7 +202,6 @@
点击检查更新
更新服务器
-
显示
屏幕方向
竖屏
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 6e4b64a95..437acc61c 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -107,4 +107,19 @@
- 2
+
+ - -2
+ - -1
+ - 0
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ - 6
+ - 7
+ - 8
+ - 9
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 93b3dc812..d725a3fa2 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -151,6 +151,8 @@
Local Favorite
Select item
+ Where to add ?
+ Failed to add
Where to move ?
Moving…
Move successfully
@@ -158,6 +160,7 @@
The same Source and Destination
Delete successfully
Failed to delete
+ Set it as default favorite
Display
@@ -183,6 +186,8 @@
Allow media scan
Please keep your gallery apps away from other people
Most gallery apps will ignore pictures in download path
+ Favorite
+ Default Favorite
About
Author
diff --git a/res/xml/data_settings.xml b/res/xml/data_settings.xml
index 93a8378c9..164c05f20 100644
--- a/res/xml/data_settings.xml
+++ b/res/xml/data_settings.xml
@@ -47,4 +47,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/com/hippo/ehviewer/AppContext.java b/src/com/hippo/ehviewer/AppContext.java
index 004456ef2..b797ce030 100644
--- a/src/com/hippo/ehviewer/AppContext.java
+++ b/src/com/hippo/ehviewer/AppContext.java
@@ -27,6 +27,7 @@ import com.hippo.ehviewer.util.Cache;
import com.hippo.ehviewer.util.Config;
import com.hippo.ehviewer.util.Crash;
import com.hippo.ehviewer.util.Download;
+import com.hippo.ehviewer.util.Favorite;
import com.hippo.ehviewer.util.ThreadPool;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.widget.LoadImageView;
@@ -58,6 +59,7 @@ public class AppContext extends Application implements UncaughtExceptionHandler
Crash.init(this);
mEhClient = new EhClient(this);
Download.init(this);
+ Favorite.init(this);
mData = new Data(this);
HttpHelper.setCookieHelper(this);
diff --git a/src/com/hippo/ehviewer/ui/FavouriteActivity.java b/src/com/hippo/ehviewer/ui/FavouriteActivity.java
index 47caf9111..f4ccd1be3 100644
--- a/src/com/hippo/ehviewer/ui/FavouriteActivity.java
+++ b/src/com/hippo/ehviewer/ui/FavouriteActivity.java
@@ -55,6 +55,7 @@ import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.service.DownloadService;
import com.hippo.ehviewer.service.DownloadServiceConnection;
import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Favorite;
import com.hippo.ehviewer.util.Theme;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.widget.ActionableToastBar;
@@ -83,7 +84,6 @@ public class FavouriteActivity extends AbstractGalleryActivity
private SlidingMenu mSlidingMenu;
private ListView mMenuList;
- private String[] mMenuTitles;
private ActionableToastBar mActionableToastBar;
private Set mChoiceGiSet;
@@ -115,7 +115,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
private void initLocalFavorite() {
mHlv.setEnabledHeader(false);
mHlv.setEnabledFooter(false);
- setTitle(mMenuTitles[mMenuIndex]);
+ setTitle(Favorite.FAVORITE_TITLES[mMenuIndex]);
setGalleryInfos(mData.getAllLocalFavourites());
if (mData.getAllLocalFavourites().isEmpty())
onlyShowNone();
@@ -126,7 +126,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
private void initFavorite() {
mHlv.setEnabledHeader(true);
mHlv.setEnabledFooter(true);
- setTitle(mMenuTitles[mMenuIndex]);
+ setTitle(Favorite.FAVORITE_TITLES[mMenuIndex]);
refresh(true);
}
@@ -168,13 +168,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
mMainView.addView(mActionableToastBar);
mMainView.setOnTouchListener(this);
- mMenuTitles = new String[EhClient.FAVORITE_SLOT_NUM + 1];
- mMenuTitles[0] = mResources.getString(R.string.local_favorite);
- for (int i = 1; i < EhClient.FAVORITE_SLOT_NUM + 1; i++) {
- mMenuTitles[i] = mResources.getString(R.string.favourite) + " "+ (i - 1);
- }
mMenuIndex = 0;
-
initLocalFavorite();
mChoiceGiSet = new LinkedHashSet();
@@ -226,7 +220,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater li= LayoutInflater.from(FavouriteActivity.this);
TextView tv = (TextView)li.inflate(R.layout.menu_item, null);
- tv.setText(mMenuTitles[position]);
+ tv.setText(Favorite.FAVORITE_TITLES[position]);
if (position == 0) {
Drawable dr = mResources.getDrawable(R.drawable.ic_action_panda);
dr.setBounds(0, 0, Ui.dp2pix(36), Ui.dp2pix(36));
@@ -251,7 +245,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
return;
mMenuIndex = position;
- setTitle(mMenuTitles[mMenuIndex]);
+ setTitle(Favorite.FAVORITE_TITLES[mMenuIndex]);
if (mMenuIndex == 0)
initLocalFavorite();
else
@@ -423,7 +417,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
private AlertDialog createMoveDialog(final ActionMode mode) {
return new DialogBuilder(this).setTitle(R.string.where_to_move)
- .setItems(mMenuTitles, new AdapterView.OnItemClickListener() {
+ .setItems(Favorite.FAVORITE_TITLES, new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view,
int position, long id) {
diff --git a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java
index d41c32e72..8e30f00a6 100644
--- a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java
+++ b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java
@@ -28,6 +28,7 @@ import com.hippo.ehviewer.ehclient.EhClient;
import com.hippo.ehviewer.service.DownloadService;
import com.hippo.ehviewer.service.DownloadServiceConnection;
import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Favorite;
import com.hippo.ehviewer.util.Theme;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.widget.AlertButton;
@@ -206,8 +207,28 @@ public class MangaDetailActivity extends AbstractFragmentActivity
finish();
return true;
case R.id.action_favourite:
- ((AppContext)getApplication()).getData().addLocalFavourite(mGalleryInfo);
- new SuperToast(this).setMessage(R.string.toast_add_favourite).show();
+ int defaultFavorite = Config.getDefaultFavorite();
+ switch (defaultFavorite) {
+ case -2:
+ Favorite.getAddToFavoriteDialog(this, mGalleryInfo).show();
+ break;
+ case -1:
+ ((AppContext)getApplication()).getData().addLocalFavourite(mGalleryInfo);
+ new SuperToast(this).setMessage(R.string.toast_add_favourite).show();
+ break;
+ default:
+ ((AppContext)getApplication()).getEhClient().addToFavorite(mGalleryInfo.gid,
+ mGalleryInfo.token, defaultFavorite, null, new EhClient.OnAddToFavoriteListener() {
+ @Override
+ public void onSuccess() {
+ new SuperToast(MangaDetailActivity.this).setMessage(R.string.toast_add_favourite).show();
+ }
+ @Override
+ public void onFailure(String eMsg) {
+ new SuperToast(MangaDetailActivity.this).setMessage(R.string.failed_to_add).show();
+ }
+ });
+ }
return true;
case R.id.action_download:
if (mGalleryDetail.language == null) {
diff --git a/src/com/hippo/ehviewer/ui/MangaListActivity.java b/src/com/hippo/ehviewer/ui/MangaListActivity.java
index 1d37b0e5b..4e388ffa9 100644
--- a/src/com/hippo/ehviewer/ui/MangaListActivity.java
+++ b/src/com/hippo/ehviewer/ui/MangaListActivity.java
@@ -37,6 +37,7 @@ import com.hippo.ehviewer.network.Downloader;
import com.hippo.ehviewer.service.DownloadService;
import com.hippo.ehviewer.service.DownloadServiceConnection;
import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Favorite;
import com.hippo.ehviewer.util.Log;
import com.hippo.ehviewer.util.Theme;
import com.hippo.ehviewer.util.Ui;
@@ -502,19 +503,39 @@ public class MangaListActivity extends AbstractGalleryActivity
@Override
public void onItemClick(AdapterView> arg0, View arg1,
int position, long arg3) {
- GalleryInfo lmd;
+ GalleryInfo gi;
switch (position) {
case 0: // Add favourite item
- lmd = getGalleryInfo(longClickItemIndex);
- mData.addLocalFavourite(lmd);
- new SuperToast(MangaListActivity.this, R.string.toast_add_favourite).show();
+ gi = getGalleryInfo(longClickItemIndex);
+ int defaultFavorite = Config.getDefaultFavorite();
+ switch (defaultFavorite) {
+ case -2:
+ Favorite.getAddToFavoriteDialog(MangaListActivity.this, gi).show();
+ break;
+ case -1:
+ ((AppContext)getApplication()).getData().addLocalFavourite(gi);
+ new SuperToast(MangaListActivity.this).setMessage(R.string.toast_add_favourite).show();
+ break;
+ default:
+ ((AppContext)getApplication()).getEhClient().addToFavorite(gi.gid,
+ gi.token, defaultFavorite, null, new EhClient.OnAddToFavoriteListener() {
+ @Override
+ public void onSuccess() {
+ new SuperToast(MangaListActivity.this).setMessage(R.string.toast_add_favourite).show();
+ }
+ @Override
+ public void onFailure(String eMsg) {
+ new SuperToast(MangaListActivity.this).setMessage(R.string.failed_to_add).show();
+ }
+ });
+ }
break;
case 1:
- lmd = getGalleryInfo(longClickItemIndex);
+ gi = getGalleryInfo(longClickItemIndex);
Intent it = new Intent(MangaListActivity.this, DownloadService.class);
startService(it);
- mServiceConn.getService().add(String.valueOf(lmd.gid), lmd.thumb,
- EhClient.getDetailUrl(lmd.gid, lmd.token), lmd.title);
+ mServiceConn.getService().add(String.valueOf(gi.gid), gi.thumb,
+ EhClient.getDetailUrl(gi.gid, gi.token), gi.title);
new SuperToast(MangaListActivity.this, R.string.toast_add_download).show();
break;
default:
diff --git a/src/com/hippo/ehviewer/ui/SettingsActivity.java b/src/com/hippo/ehviewer/ui/SettingsActivity.java
index 7d94b659c..4af079db0 100644
--- a/src/com/hippo/ehviewer/ui/SettingsActivity.java
+++ b/src/com/hippo/ehviewer/ui/SettingsActivity.java
@@ -29,6 +29,7 @@ import com.hippo.ehviewer.R;
import com.hippo.ehviewer.UpdateHelper;
import com.hippo.ehviewer.util.Cache;
import com.hippo.ehviewer.util.Config;
+import com.hippo.ehviewer.util.Favorite;
import com.hippo.ehviewer.util.Theme;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.Util;
@@ -51,6 +52,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
+import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.view.LayoutInflater;
@@ -294,6 +296,7 @@ public class SettingsActivity extends AbstractPreferenceActivity {
private static final String KEY_CLEAR_CACHE = "clear_cache";
private static final String KEY_DOWNLOAD_PATH = "download_path";
private static final String KEY_MEDIA_SCAN = "media_scan";
+ private static final String KEY_DEFAULT_FAVORITE = "default_favorite";
private AlertDialog mDirSelectDialog;
@@ -301,6 +304,7 @@ public class SettingsActivity extends AbstractPreferenceActivity {
private Preference mClearCache;
private Preference mDownloadPath;
private CheckBoxPreference mMediaScan;
+ private ListPreference mDefaultFavorite;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -315,10 +319,18 @@ public class SettingsActivity extends AbstractPreferenceActivity {
mDownloadPath.setOnPreferenceClickListener(this);
mMediaScan = (CheckBoxPreference)findPreference(KEY_MEDIA_SCAN);
mMediaScan.setOnPreferenceChangeListener(this);
+ mDefaultFavorite = (ListPreference)findPreference(KEY_DEFAULT_FAVORITE);
// Set summary
updateClearCacheSummary();
mDownloadPath.setSummary(Config.getDownloadPath());
+
+ int i = 0;
+ String[] entrise = new String[Favorite.FAVORITE_TITLES.length + 1];
+ entrise[i++] = getString(R.string.none);
+ for (String str : Favorite.FAVORITE_TITLES)
+ entrise[i++] = str;
+ mDefaultFavorite.setEntries(entrise);
}
private void updateClearCacheSummary() {
diff --git a/src/com/hippo/ehviewer/util/Config.java b/src/com/hippo/ehviewer/util/Config.java
index 930a00683..a46193e83 100644
--- a/src/com/hippo/ehviewer/util/Config.java
+++ b/src/com/hippo/ehviewer/util/Config.java
@@ -59,6 +59,9 @@ public class Config {
private static final String KEY_THEME_COLOR = "theme_color";
private static final int DEFAULT_THEME_COLOR = 0xff0099cc;
+ private static final String KEY_DEFAULT_FAVORITE = "default_favorite";
+ private static final String DEFAULT_DEFAULT_FAVORITE = "-2";
+
private static boolean mInit = false;
private static Context mContext;
@@ -278,4 +281,12 @@ public class Config {
public static void setThemeColor(int themeColor) {
mConfigPre.edit().putInt(KEY_THEME_COLOR, themeColor).apply();
}
+
+ public static int getDefaultFavorite() {
+ return Integer.parseInt(mConfigPre.getString(KEY_DEFAULT_FAVORITE, DEFAULT_DEFAULT_FAVORITE));
+ }
+
+ public static void setDefaultFavorite(int defaultFavorite) {
+ mConfigPre.edit().putString(KEY_DEFAULT_FAVORITE, String.valueOf(defaultFavorite)).apply();
+ }
}
diff --git a/src/com/hippo/ehviewer/util/Favorite.java b/src/com/hippo/ehviewer/util/Favorite.java
new file mode 100644
index 000000000..961432673
--- /dev/null
+++ b/src/com/hippo/ehviewer/util/Favorite.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 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.util;
+
+import com.hippo.ehviewer.AppContext;
+import com.hippo.ehviewer.R;
+import com.hippo.ehviewer.data.GalleryInfo;
+import com.hippo.ehviewer.ehclient.EhClient;
+import com.hippo.ehviewer.ui.MangaDetailActivity;
+import com.hippo.ehviewer.widget.DialogBuilder;
+import com.hippo.ehviewer.widget.SuperToast;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.content.res.Resources;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.CheckBox;
+import android.widget.ListView;
+
+public class Favorite {
+
+ private static Context mContext;
+ private static Resources mResources;
+
+ private static AlertDialog lastAddToFavoriteDialog;
+
+ public static String[] FAVORITE_TITLES;
+
+ public static void init(Context context) {
+ mContext = context;
+ mResources = mContext.getResources();
+
+ FAVORITE_TITLES = new String[EhClient.FAVORITE_SLOT_NUM + 1];
+ FAVORITE_TITLES[0] = mResources.getString(R.string.local_favorite);
+ for (int i = 1; i < EhClient.FAVORITE_SLOT_NUM + 1; i++) {
+ FAVORITE_TITLES[i] = mResources.getString(R.string.favourite) + " "+ (i - 1);
+ }
+ }
+
+ public static AlertDialog getAddToFavoriteDialog(final Context context, final GalleryInfo gi) {
+ DialogBuilder db = new DialogBuilder(context).setView(R.layout.add_to_favorite, false);
+ db.setTitle(R.string.where_to_add);
+ db.setSimpleNegativeButton();
+ ViewGroup vg = db.getCustomLayout();
+ final CheckBox cb = (CheckBox)vg.findViewById(R.id.set_default);
+ ListView lv = (ListView)vg.findViewById(R.id.list);
+ lv.setAdapter(new ArrayAdapter(mContext,
+ R.layout.list_item_text, FAVORITE_TITLES));
+ lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> parent, View view,
+ int position, long id) {
+ lastAddToFavoriteDialog.dismiss();
+ lastAddToFavoriteDialog = null;
+
+ if (cb.isChecked())
+ Config.setDefaultFavorite(position - 1);
+
+ switch (position) {
+ case 0:
+ ((AppContext)mContext).getData().addLocalFavourite(gi);
+ new SuperToast(context).setMessage(R.string.toast_add_favourite).show();
+ break;
+ default:
+ ((AppContext)mContext).getEhClient().addToFavorite(gi.gid,
+ gi.token, position - 1, null, new EhClient.OnAddToFavoriteListener() {
+ @Override
+ public void onSuccess() {
+ new SuperToast(context).setMessage(R.string.toast_add_favourite).show();
+ }
+ @Override
+ public void onFailure(String eMsg) {
+ new SuperToast(context).setMessage(R.string.failed_to_add).show();
+ }
+ });
+ }
+ }
+ });
+ return lastAddToFavoriteDialog = db.create();
+ }
+}
diff --git a/src/com/hippo/ehviewer/widget/DialogBuilder.java b/src/com/hippo/ehviewer/widget/DialogBuilder.java
index 31c98bf1e..da421c4f1 100644
--- a/src/com/hippo/ehviewer/widget/DialogBuilder.java
+++ b/src/com/hippo/ehviewer/widget/DialogBuilder.java
@@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@@ -42,6 +43,7 @@ import android.widget.TextView;
public class DialogBuilder extends AlertDialog.Builder {
private View mView;
+ private LinearLayout mCustomLayout;
private Context mContext;
private int mThemeColor;
@@ -154,23 +156,38 @@ public class DialogBuilder extends AlertDialog.Builder {
public DialogBuilder setView(View view, LinearLayout.LayoutParams lp) {
ScrollView scrollView = (ScrollView)mView.findViewById(R.id.scroll_view);
scrollView.setVisibility(View.VISIBLE);
- LinearLayout customLayout = (LinearLayout)mView.findViewById(R.id.custom);
- customLayout.setVisibility(View.VISIBLE);
- customLayout.addView(view, lp);
+ mCustomLayout = (LinearLayout)mView.findViewById(R.id.custom);
+ mCustomLayout.setVisibility(View.VISIBLE);
+ mCustomLayout.addView(view, lp);
return this;
}
- public DialogBuilder setView(View view, LinearLayout.LayoutParams lp, boolean sroll) {
- LinearLayout customLayout;
- if (sroll)
- customLayout = (LinearLayout)mView.findViewById(R.id.custom);
+ public DialogBuilder setView(View view, LinearLayout.LayoutParams lp, boolean isSroll) {
+ if (isSroll)
+ mCustomLayout = (LinearLayout)mView.findViewById(R.id.custom);
else
- customLayout = (LinearLayout)mView.findViewById(R.id.custom_no_scroll);
- customLayout.setVisibility(View.VISIBLE);
- customLayout.addView(view, lp);
+ mCustomLayout = (LinearLayout)mView.findViewById(R.id.custom_no_scroll);
+ mCustomLayout.setVisibility(View.VISIBLE);
+ mCustomLayout.addView(view, lp);
return this;
}
+ public DialogBuilder setView(int resId, boolean isSroll) {
+ if (isSroll)
+ mCustomLayout = (LinearLayout)mView.findViewById(R.id.custom);
+ else
+ mCustomLayout = (LinearLayout)mView.findViewById(R.id.custom_no_scroll);
+ mCustomLayout.setVisibility(View.VISIBLE);
+ LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ inflater.inflate(resId, mCustomLayout);
+ return this;
+ }
+
+ public LinearLayout getCustomLayout() {
+ return mCustomLayout;
+ }
+
/**
* Set a listener to be invoked when the positive button of the dialog is pressed.
* @param textId The resource id of the text to display in the positive button