添加默认收藏设置
This commit is contained in:
1 parent
bcba2f556b
commit
9aecbf9e66
14 files changed
+282
-33
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<ListView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" >
|
||||
</ListView>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/set_default"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12.0dp"
|
||||
android:layout_marginTop="8.0dp"
|
||||
android:layout_marginBottom="8.0dp"
|
||||
android:checked="false"
|
||||
android:text="@string/set_default_favorite" />
|
||||
|
||||
</merge>
|
||||
@@ -25,4 +25,5 @@
|
||||
android:paddingRight="24dp"
|
||||
android:minHeight="48dp"
|
||||
android:maxHeight="48dp"
|
||||
android:singleLine="true" />
|
||||
android:singleLine="true"
|
||||
android:textColor="@android:color/black" />
|
||||
@@ -150,6 +150,8 @@
|
||||
<!-- Favorite -->
|
||||
<string name="local_favorite">本地收藏</string>
|
||||
<string name="select_item">选择项目</string>
|
||||
<string name="where_to_add">添加至何处?</string>
|
||||
<string name="failed_to_add">添加失败</string>
|
||||
<string name="where_to_move">移动至何处?</string>
|
||||
<string name="moving">正在移动…</string>
|
||||
<string name="move_successfully">移动成功</string>
|
||||
@@ -157,6 +159,7 @@
|
||||
<string name="dst_src_same">目标与源相同</string>
|
||||
<string name="delete_successfully">删除成功</string>
|
||||
<string name="failed_to_delete">删除失败</string>
|
||||
<string name="set_default_favorite">设为默认收藏夹</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="display_settings_title">显示</string>
|
||||
@@ -182,6 +185,8 @@
|
||||
<string name="media_scan_title">允许媒体扫描</string>
|
||||
<string name="media_scan_summary_on">请避免他人翻看你的图库应用</string>
|
||||
<string name="media_scan_summary_off">大多数图库应用将不会显示下载目录中的图片</string>
|
||||
<string name="favorite_data_settings_title">收藏</string>
|
||||
<string name="default_favorite">默认收藏夹</string>
|
||||
|
||||
<string name="about_settings_title">关于</string>
|
||||
<string name="author_title">作者</string>
|
||||
@@ -197,7 +202,6 @@
|
||||
<string name="check_for_update_summary">点击检查更新</string>
|
||||
<string name="update_server_title">更新服务器</string>
|
||||
|
||||
|
||||
<string name="preference_category_display">显示</string>
|
||||
<string name="preference_screen_ori">屏幕方向</string>
|
||||
<string name="portrait">竖屏</string>
|
||||
|
||||
@@ -107,4 +107,19 @@
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="default_favorite_entry_values" translatable="false">
|
||||
<item>-2</item>
|
||||
<item>-1</item>
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>5</item>
|
||||
<item>6</item>
|
||||
<item>7</item>
|
||||
<item>8</item>
|
||||
<item>9</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
@@ -151,6 +151,8 @@
|
||||
<!-- Favorite -->
|
||||
<string name="local_favorite">Local Favorite</string>
|
||||
<string name="select_item">Select item</string>
|
||||
<string name="where_to_add">Where to add ?</string>
|
||||
<string name="failed_to_add">Failed to add</string>
|
||||
<string name="where_to_move">Where to move ?</string>
|
||||
<string name="moving">Moving…</string>
|
||||
<string name="move_successfully">Move successfully</string>
|
||||
@@ -158,6 +160,7 @@
|
||||
<string name="dst_src_same">The same Source and Destination</string>
|
||||
<string name="delete_successfully">Delete successfully</string>
|
||||
<string name="failed_to_delete">Failed to delete</string>
|
||||
<string name="set_default_favorite">Set it as default favorite</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="display_settings_title">Display</string>
|
||||
@@ -183,6 +186,8 @@
|
||||
<string name="media_scan_title">Allow media scan</string>
|
||||
<string name="media_scan_summary_on">Please keep your gallery apps away from other people</string>
|
||||
<string name="media_scan_summary_off">Most gallery apps will ignore pictures in download path</string>
|
||||
<string name="favorite_data_settings_title">Favorite</string>
|
||||
<string name="default_favorite">Default Favorite</string>
|
||||
|
||||
<string name="about_settings_title">About</string>
|
||||
<string name="author_title">Author</string>
|
||||
|
||||
@@ -47,4 +47,16 @@
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/favorite_data_settings_title">
|
||||
|
||||
<com.hippo.ehviewer.preference.AutoListPreference
|
||||
android:key="default_favorite"
|
||||
android:title="@string/default_favorite"
|
||||
android:entryValues="@array/default_favorite_entry_values"
|
||||
android:defaultValue="-2"
|
||||
android:summary="%s" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -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);
|
||||
|
||||
@@ -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<GalleryInfo> 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<GalleryInfo>();
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<String>(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();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user