完成账户收藏管理

This commit is contained in:
seven332 committed 2014-06-12 23:12:32 +08:00
1 parent 535a6297af
commit 8cecf200eb
10 files changed
+695 -106

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source Project
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.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="match_parent">
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dip"
android:layout_marginBottom="1dip"
android:layout_marginStart="16dip"
android:layout_marginEnd="16dip"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/progress_percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dip"
android:layout_marginStart="16dip"
android:layout_marginEnd="16dip"
android:layout_alignParentStart="true"
android:layout_below="@id/progress"
/>
<TextView
android:id="@+id/progress_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="16dip"
android:layout_marginStart="16dip"
android:layout_marginEnd="16dip"
android:layout_alignParentEnd="true"
android:layout_below="@id/progress"
/>
</RelativeLayout>
+43
View File
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2011, The Android Open Source Project
**
** 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.
*/
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/body"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:padding="16dip">
<ProgressBar android:id="@android:id/progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="10000"
android:layout_marginEnd="16dip" />
<TextView android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
</FrameLayout>
+4 -1
View File
@@ -147,6 +147,9 @@
<string name="action_refresh">刷新</string>
<string name="action_settings">设置</string>
<!-- Favorite -->
<string name="local_favorite">本地收藏</string>
<!-- Settings -->
<string name="display_settings_title">显示</string>
<string name="screen_display_settings_title">屏幕</string>
@@ -303,7 +306,7 @@
<string name="reply">回复</string>
<string name="read">阅读</string>
<string name="rate">评价</string>
<string name="last_page">最后一页!</string>
<string name="last_page">最后一页</string>
<string name="unfinished">未完成的功能</string>
<string name="period">。</string>
<string name="refresh">刷新</string>
+4 -1
View File
@@ -149,6 +149,9 @@
<string name="action_refresh">Refresh</string>
<string name="action_settings">Settings</string>
<!-- Favorite -->
<string name="local_favorite">Local Favorite</string>
<!-- Settings -->
<string name="display_settings_title">Display</string>
<string name="screen_display_settings_title">Screen</string>
@@ -307,7 +310,7 @@
<string name="reply">Reply</string>
<string name="read">Read</string>
<string name="rate">Rate</string>
<string name="last_page">Last page !</string>
<string name="last_page">Last page</string>
<string name="sadpanda" translatable="false">Sad Panda</string>
<string name="unfinished">Unfinished</string>
<string name="period">.&#160;</string>
+13
View File
@@ -181,4 +181,17 @@
<item name="android:isIndicator">true</item>
</style>
<style name="AlertDialogStyle">
<!--item name="android:fullDark">@android:drawable/popup_full_dark</item-->
<!--item name="android:topDark">@android:drawable/popup_top_dark</item-->
<!--item name="android:centerDark">@android:drawable/popup_center_dark</item-->
<!--item name="android:bottomDark">@android:drawable/popup_bottom_dark</item-->
<!--item name="android:fullBright">@android:drawable/popup_full_bright</item-->
<!--item name="android:topBright">@android:drawable/popup_top_bright</item-->
<!-- item name="android:centerBright">@android:drawable/popup_center_bright</item-->
<!-- item name="android:bottomBright">@android:drawable/popup_bottom_bright</item -->
<!-- item name="android:bottomMedium">@android:drawable/popup_bottom_medium</item-->
<!--item name="android:centerMedium">@android:drawable/popup_center_medium</item-->
<!--item name="android:layout">@android:layout/alert_dialog_holo</item-->
</style>
</resources>
+5
View File
@@ -40,6 +40,11 @@
<!-- item name="@android:dialogTitleDecorLayout">@layout/dialog_title</item -->
<!-- item name="@android:searchViewVoiceIcon">@android:drawable/ic_voice_search_api_holo_light</item -->
<!-- Dialog attributes -->
<!-- AlertDialog attributes -->
<!-- item name="@android:alertDialogStyle">@style/AlertDialogStyle</item -->
</style>
<style name="AppTheme.Main">
@@ -64,8 +64,8 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
protected EhClient mClient;
protected ImageGeterManager mImageGeterManager;
protected List<GalleryInfo> mGiList;
protected GalleryAdapter mGalleryAdapter;
private List<GalleryInfo> mGiList;
private GalleryAdapter mGalleryAdapter;
private RelativeLayout mMainView;
private HfListView mHlv;
@@ -128,7 +128,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
return re;
}
protected void onlyShowList() {
public void onlyShowList() {
mHlv.setVisibility(View.VISIBLE);
mWaitProgressBar.setVisibility(View.GONE);
mFreshButton.setVisibility(View.GONE);
@@ -136,6 +136,14 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
mSadPanda.setVisibility(View.GONE);
}
public void onlyShowNone() {
mHlv.setVisibility(View.GONE);
mWaitProgressBar.setVisibility(View.GONE);
mFreshButton.setVisibility(View.GONE);
mNoneTextView.setVisibility(View.VISIBLE);
mSadPanda.setVisibility(View.GONE);
}
protected void firstTimeRefresh() {
// set mHlv gone, make wait view show
mHlv.setVisibility(View.GONE);
@@ -341,6 +349,42 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
return mMaxPage;
}
public int getCurPage() {
return mCurPage;
}
public GalleryInfo getGalleryInfo(int position) {
return mGiList.get(position);
}
public void setGalleryInfos(List<GalleryInfo> gis) {
setGalleryInfos(gis, 1);
}
public void setGalleryInfos(List<GalleryInfo> gis, int maxPage) {
mGiList = gis;
mGalleryAdapter.notifyDataSetChanged();
mFirstIndex = 0;
mLastIndex = mGiList.size() - 1;
mCurPage = 0;
mFirstPage = 0;
mLastPage = 0;
mMaxPage = maxPage;
mItemPerPage = mGiList.size();
if (mItemPerPage == 0)
onlyShowNone();
else
onlyShowList();
}
public void notifyDataSetChanged() {
mGalleryAdapter.notifyDataSetChanged();
if (mGiList.isEmpty())
onlyShowNone();
}
protected class GalleryAdapter extends BaseAdapter {
@Override
public int getCount() {
@@ -414,7 +458,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
int visibleItemCount, int totalItemCount) {
mHlv.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
if (visibleItemCount < 2)
if (visibleItemCount < 2 || mItemPerPage == 0)
return;
if (mLastIndex == 0)
mLastIndex = mItemPerPage - 1;
@@ -462,7 +506,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
mFirstPage = 0;
mLastPage = 0;
mGiList.clear();
mGiList = new ArrayList<GalleryInfo>();
mGalleryAdapter.notifyDataSetChanged();
} else {
mNoneTextView.setVisibility(View.GONE);
@@ -542,7 +586,7 @@ public abstract class AbstractGalleryActivity extends AbstractSlidingActivity
case REFRESH:
mHlv.setVisibility(View.GONE);
mFreshButton.setVisibility(View.VISIBLE);
break;
default:
mFreshButton.setVisibility(View.GONE);
}
+214 -93
View File
@@ -17,14 +17,18 @@
package com.hippo.ehviewer.ui;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Path;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.PathShape;
@@ -58,6 +62,7 @@ import com.hippo.ehviewer.widget.FswView;
import com.hippo.ehviewer.widget.HfListView;
import com.hippo.ehviewer.widget.OnFitSystemWindowsListener;
import com.hippo.ehviewer.widget.ActionableToastBar.ActionClickedListener;
import com.hippo.ehviewer.widget.ProgressDialogBulider;
import com.hippo.ehviewer.widget.SuperToast;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
@@ -80,10 +85,16 @@ public class FavouriteActivity extends AbstractGalleryActivity
private String[] mMenuTitles;
private ActionableToastBar mActionableToastBar;
private Set<GalleryInfo> mChoiceGiSet; // Store gid
private Set<GalleryInfo> mChoiceGiSet;
private Set<GalleryInfo> mChoiceGiSetCopy; // Store selected GalleryInfo
private Iterator<GalleryInfo> mSetIter; // For move from local to cloud
private GalleryInfo mTargetGi;
private int mMenuIndex;
private int mTargetCat;
private AlertDialog mMoveDialog;
private ProgressDialogBulider mPdb;
private AlertDialog mProgressDialog;
private DownloadServiceConnection mServiceConn = new DownloadServiceConnection();
@@ -100,6 +111,24 @@ public class FavouriteActivity extends AbstractGalleryActivity
super.onBackPressed();
}
private void initLocalFavorite() {
mHlv.setEnabledHeader(false);
mHlv.setEnabledFooter(false);
setTitle(mMenuTitles[mMenuIndex]);
setGalleryInfos(mData.getAllLocalFavourites());
if (mData.getAllLocalFavourites().isEmpty())
onlyShowNone();
else
onlyShowList();
}
private void initFavorite() {
mHlv.setEnabledHeader(true);
mHlv.setEnabledFooter(true);
setTitle(mMenuTitles[mMenuIndex]);
refresh(true);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -110,7 +139,12 @@ public class FavouriteActivity extends AbstractGalleryActivity
mImageGeterManager = mAppContext.getImageGeterManager();
mClient = mAppContext.getEhClient();
Ui.translucent(this);
int color = getResources().getColor(android.R.color.holo_blue_dark)
& 0x00ffffff | 0xdd000000;
Drawable drawable = new ColorDrawable(color);
Ui.translucent(this, drawable);
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(drawable);
getActionBar().setDisplayHomeAsUpEnabled(true);
// Download service
@@ -139,16 +173,16 @@ public class FavouriteActivity extends AbstractGalleryActivity
mMainView.setOnTouchListener(this);
mMenuTitles = new String[EhClient.FAVORITE_SLOT_NUM + 1];
mMenuTitles[0] = "本地收藏"; // TODO
mMenuTitles[0] = mResources.getString(R.string.local_favorite);
for (int i = 1; i < EhClient.FAVORITE_SLOT_NUM + 1; i++) {
mMenuTitles[i] = "收藏 " + (i - 1); // TODO
mMenuTitles[i] = mResources.getString(R.string.favourite) + " "+ (i - 1);
}
mMenuIndex = 0;
mHlv.setEnabledHeader(false);
mHlv.setEnabledFooter(false);
setTitle(mMenuTitles[mMenuIndex]);
mGiList = mData.getAllLocalFavourites();
initLocalFavorite();
mChoiceGiSet = new LinkedHashSet<GalleryInfo>();
mChoiceGiSetCopy = new LinkedHashSet<GalleryInfo>();
mList.setOnTouchListener(this);
mList.setOnItemClickListener(new OnItemClickListener() {
@Override
@@ -156,7 +190,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
int position, long arg3) {
Intent intent = new Intent(FavouriteActivity.this,
MangaDetailActivity.class);
GalleryInfo gi = mGiList.get(position);
GalleryInfo gi = getGalleryInfo(position);
intent.putExtra("url", EhClient.getDetailUrl(gi.gid, gi.token));
intent.putExtra(MangaDetailActivity.KEY_G_INFO, gi);
startActivity(intent);
@@ -215,44 +249,20 @@ public class FavouriteActivity extends AbstractGalleryActivity
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
showContent();
// If same index, do nothing
if (mMenuIndex == position)
return;
showContent();
mMenuIndex = position;
setTitle(mMenuTitles[mMenuIndex]);
if (mMenuIndex == 0) {
mHlv.setEnabledHeader(false);
mHlv.setEnabledFooter(false);
mGiList = mData.getAllLocalFavourites();
mGalleryAdapter.notifyDataSetChanged();
} else {
mHlv.setEnabledHeader(true);
mHlv.setEnabledFooter(true);
mClient.getMangaList(EhClient.getFavoriteUrl(mMenuIndex - 1, 0),
null, new EhClient.OnGetMangaListListener() {
@Override
public void onSuccess(Object checkFlag, ArrayList<GalleryInfo> lmdArray,
int indexPerPage, int maxPage) {
mGiList = lmdArray;
mGalleryAdapter.notifyDataSetChanged();
}
@Override
public void onFailure(Object checkFlag, String eMsg) {
new SuperToast(FavouriteActivity.this)
.setIcon(R.drawable.ic_warning)
.setMessage(eMsg).show();
}
});
// TODO
}
if (mMenuIndex == 0)
initLocalFavorite();
else
initFavorite();
}
});
FswView alignment = (FswView)findViewById(R.id.alignment);
alignment.addOnFitSystemWindowsListener(new OnFitSystemWindowsListener() {
@Override
@@ -272,6 +282,13 @@ public class FavouriteActivity extends AbstractGalleryActivity
mMenuList.getPaddingRight(), paddingBottom);
}
});
// Check login
if (!mClient.isLogin()) {
SuperToast superToast = new SuperToast(this, "未检测到登陆状态,仅可使用本地收藏。由于开发者的问题,本地收藏不可靠,请尽快登陆,将本地收藏转移至账户中的收藏。");
superToast.setDuration(SuperToast.LENGTH_LONG);
superToast.show();
}
}
@Override
@@ -314,7 +331,7 @@ public class FavouriteActivity extends AbstractGalleryActivity
// Avoid touches inside the undo bar.
return;
}
mActionableToastBar.hide(true);
mActionableToastBar.hide(false);
}
}
@@ -339,101 +356,205 @@ public class FavouriteActivity extends AbstractGalleryActivity
return true;
}
private int[] getGids(Set<GalleryInfo> giSet) {
int[] gids = new int[giSet.size()];
int i = 0;
for (GalleryInfo gi : giSet)
gids[i++] = gi.gid;
return gids;
}
private void startMoveFromLocal2Cloud() {
mPdb = new ProgressDialogBulider(FavouriteActivity.this);
mPdb.setCancelable(true).setTitle("正在移动...");
mPdb.setMax(mChoiceGiSetCopy.size()).setProgress(0);
mProgressDialog = mPdb.create();
mProgressDialog.show();
moveFromLocal2Cloud();
}
private void moveFromLocal2Cloud() {
if (mSetIter == null)
mSetIter = mChoiceGiSetCopy.iterator();
if (mSetIter.hasNext() || mTargetGi != null) {
if (mTargetGi == null)
mTargetGi = mSetIter.next();
mClient.addToFavorite(mTargetGi.gid, mTargetGi.token,
mTargetCat, null, new EhClient.OnAddToFavoriteListener() {
@Override
public void onSuccess() {
// remove from set iterator, favorite data
mSetIter.remove();
mData.deleteLocalFavourite(mTargetGi.gid);
// set mGiLocal2Cloud null for above
mTargetGi = null;
mPdb.setProgress(mPdb.getProgress() + 1);
moveFromLocal2Cloud();
}
@Override
public void onFailure(String eMsg) {
notifyDataSetChanged();
mPdb = null;
mProgressDialog.dismiss();
mProgressDialog = null;
showToastBar(new ActionClickedListener() {
@Override
public void onActionClicked() {
startMoveFromLocal2Cloud();
}
}, 0, "移动失败", R.drawable.ic_warning, "重试", true);
}
});
} else {
notifyDataSetChanged();
mSetIter = null;
mPdb = null;
mProgressDialog.dismiss();
mProgressDialog = null;
new SuperToast(this, "移动成功").show(); // TODO
}
}
private AlertDialog createMoveDialog(final ActionMode mode) {
return new DialogBuilder(this).setTitle("移动至何处?") //
return new DialogBuilder(this).setTitle("移动至何处?") // TODO
.setItems(mMenuTitles, new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int[] gids = new int[mChoiceGiSet.size()];
int i = 0;
for (GalleryInfo gi : mChoiceGiSet)
gids[i++] = gi.gid;
mClient.modifyFavorite(gids, position, mMenuIndex -1,
new EhClient.OnModifyFavoriteListener() {
@Override
public void onSuccess(ArrayList<GalleryInfo> gis,
int indexPerPage, int maxPage) {
new SuperToast(FavouriteActivity.this)
.setMessage("移动成功").show();
mGiList = gis;
mGalleryAdapter.notifyDataSetChanged();
}
@Override
public void onFailure(String eMsg) {
new SuperToast(FavouriteActivity.this)
.setIcon(R.drawable.ic_warning)
.setMessage("移动失败\n" + eMsg).show(); // TODO
}
});
if (mMenuIndex == position) {
new SuperToast(FavouriteActivity.this, "目标与源相同", SuperToast.WARNING).show();
return;
}
mMoveDialog.dismiss();
mMoveDialog = null;
mode.finish();
mTargetCat = position - 1;
if (mMenuIndex == 0) { // From local favorite to cloud
mMoveDialog.dismiss();
mMoveDialog = null;
startMoveFromLocal2Cloud();
} else {
if (position == 0) { // From cloud to local favorite
mMoveDialog.dismiss();
mMoveDialog = null;
mClient.modifyFavorite(getGids(mChoiceGiSetCopy), mTargetCat,
mMenuIndex -1, new Modify("移动成功", "移动失败", true));
mHlv.setRefreshing(true);
} else { // change cloud dir
mMoveDialog.dismiss();
mMoveDialog = null;
mClient.modifyFavorite(getGids(mChoiceGiSetCopy), mTargetCat,
mMenuIndex -1, new Modify("移动成功", "移动失败", false));
mHlv.setRefreshing(true);
}
}
}
}).setSimpleNegativeButton().create();
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// get a copy of mChoiceGiSet
mSetIter = null;
mChoiceGiSetCopy.clear();
for (GalleryInfo gi : mChoiceGiSet)
mChoiceGiSetCopy.add(gi);
switch (item.getItemId()) {
case R.id.action_delete:
if (mMenuIndex == 0) {
for (GalleryInfo gi : mChoiceGiSet)
mData.deleteLocalFavourite(gi.gid);
mGalleryAdapter.notifyDataSetChanged();
notifyDataSetChanged();
} else {
int[] gids = new int[mChoiceGiSet.size()];
int i = 0;
for (GalleryInfo gi : mChoiceGiSet)
gids[i++] = gi.gid;
mClient.modifyFavorite(gids, -1, mMenuIndex -1, new EhClient.OnModifyFavoriteListener() {
@Override
public void onSuccess(ArrayList<GalleryInfo> gis, int indexPerPage,
int maxPage) {
new SuperToast(FavouriteActivity.this)
.setMessage("删除成功").show(); // TODO
mGiList = gis;
mGalleryAdapter.notifyDataSetChanged();
}
@Override
public void onFailure(String eMsg) {
new SuperToast(FavouriteActivity.this)
.setIcon(R.drawable.ic_warning)
.setMessage("删除失败\n" + eMsg).show(); // TODO
}
});
mTargetCat = -1;
mClient.modifyFavorite(getGids(mChoiceGiSet), mTargetCat,
mMenuIndex -1, new Modify("删除成功", "删除失败", false));
mHlv.setRefreshing(true);
}
mode.finish();
return true;
case R.id.action_move:
mMoveDialog = createMoveDialog(mode);
mMoveDialog.show();
mode.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mChoiceGiSet.clear();
showToastBar(null, R.drawable.ic_warning, "haha", R.drawable.ic_action_redo, "nimei", true);
}
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
if (checked)
mChoiceGiSet.add(mGiList.get(position));
mChoiceGiSet.add(getGalleryInfo(position));
else
mChoiceGiSet.remove(mGiList.get(position));
mChoiceGiSet.remove(getGalleryInfo(position));
}
@Override
protected String getTargetUrl(int targetPage) {
return EhClient.getFavoriteUrl(mMenuIndex-1, targetPage);
}
private class Modify implements EhClient.OnModifyFavoriteListener {
private String mSuccStr;
private String mFailStr;
private boolean mToLocal;
public Modify(String succStr, String failStr, boolean toLocal) {
mSuccStr = succStr;
mFailStr = failStr;
mToLocal = toLocal;
}
@Override
public void onSuccess(ArrayList<GalleryInfo> gis, int indexPerPage,
int maxPage) {
setGalleryInfos(gis, maxPage);
mHlv.setRefreshing(false);
new SuperToast(FavouriteActivity.this, mSuccStr).show();
// add to local
if (mToLocal)
for (GalleryInfo gi : mChoiceGiSetCopy)
mData.addLocalFavourite(gi);
}
@Override
public void onFailure(String eMsg) {
mHlv.setRefreshing(false);
showToastBar(new Remodify(mSuccStr, mFailStr, mToLocal), 0, mFailStr + ": " + eMsg,
R.drawable.ic_action_redo, "重试", true); // TODO
}
}
/**
* Redelete when delete error
* @author Hippo
*
*/
private class Remodify implements ActionableToastBar.ActionClickedListener {
private String mSuccStr;
private String mFailStr;
private boolean mToLocal;
public Remodify(String succStr, String failStr, boolean toLocal) {
mSuccStr = succStr;
mFailStr = failStr;
mToLocal = toLocal;
}
@Override
public void onActionClicked() {
mClient.modifyFavorite(getGids(mChoiceGiSetCopy), -1, mMenuIndex -1, new Modify(mSuccStr, mFailStr, mToLocal));
}
}
}
@@ -503,12 +503,12 @@ public class MangaListActivity extends AbstractGalleryActivity
GalleryInfo lmd;
switch (position) {
case 0: // Add favourite item
lmd = mGiList.get(longClickItemIndex);
lmd = getGalleryInfo(longClickItemIndex);
mData.addLocalFavourite(lmd);
new SuperToast(MangaListActivity.this, R.string.toast_add_favourite).show();
break;
case 1:
lmd = mGiList.get(longClickItemIndex);
lmd = getGalleryInfo(longClickItemIndex);
Intent it = new Intent(MangaListActivity.this, DownloadService.class);
startService(it);
mServiceConn.getService().add(String.valueOf(lmd.gid), lmd.thumb,
@@ -929,10 +929,9 @@ public class MangaListActivity extends AbstractGalleryActivity
int color = getResources().getColor(android.R.color.holo_blue_dark)
& 0x00ffffff | 0xdd000000;
Drawable drawable = new ColorDrawable(color);
Ui.translucent(this, drawable);
final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(drawable);
Ui.translucent(this, drawable);
// Download service
Intent it = new Intent(MangaListActivity.this, DownloadService.class);
@@ -1114,7 +1113,7 @@ public class MangaListActivity extends AbstractGalleryActivity
int position, long arg3) {
Intent intent = new Intent(MangaListActivity.this,
MangaDetailActivity.class);
GalleryInfo gi = mGiList.get(position);
GalleryInfo gi = getGalleryInfo(position);
intent.putExtra("url", EhClient.getDetailUrl(gi.gid, gi.token));
intent.putExtra(MangaDetailActivity.KEY_G_INFO, gi);
// Maybe shoud use other method
@@ -0,0 +1,310 @@
/*
* 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.widget;
import java.text.NumberFormat;
import com.hippo.ehviewer.R;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
public class ProgressDialogBulider extends DialogBuilder{
/** Creates a ProgressDialog with a circular, spinning progress
* bar. This is not the default.
*/
public static final int STYLE_SPINNER = 0;
/** Creates a ProgressDialog with a horizontal progress bar.
*/
public static final int STYLE_HORIZONTAL = 1;
private ProgressBar mProgress;
private TextView mMessageView;
private int mProgressStyle = STYLE_HORIZONTAL;
private TextView mProgressNumber;
private String mProgressNumberFormat;
private TextView mProgressPercent;
private NumberFormat mProgressPercentFormat;
private int mMax;
private int mProgressVal;
private int mSecondaryProgressVal;
private int mIncrementBy;
private int mIncrementSecondaryBy;
private Drawable mProgressDrawable;
private Drawable mIndeterminateDrawable;
private CharSequence mMessage;
private boolean mIndeterminate;
private boolean mHasStarted = true;
private Handler mViewUpdateHandler;
private void initFormats() {
mProgressNumberFormat = "%1d/%2d";
mProgressPercentFormat = NumberFormat.getPercentInstance();
mProgressPercentFormat.setMaximumFractionDigits(0);
}
@SuppressLint("HandlerLeak")
public ProgressDialogBulider(Context context) {
super(context);
initFormats();
LayoutInflater inflater = LayoutInflater.from(context);
if (mProgressStyle == STYLE_HORIZONTAL) {
/* Use a separate handler to update the text views as they
* must be updated on the same thread that created them.
*/
mViewUpdateHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
/* Update the number and percent */
int progress = mProgress.getProgress();
int max = mProgress.getMax();
if (mProgressNumberFormat != null) {
String format = mProgressNumberFormat;
mProgressNumber.setText(String.format(format, progress, max));
} else {
mProgressNumber.setText("");
}
if (mProgressPercentFormat != null) {
double percent = (double) progress / (double) max;
SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),
0, tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mProgressPercent.setText(tmp);
} else {
mProgressPercent.setText("");
}
}
};
View view = inflater.inflate(R.layout.alert_dialog_progress, null);
mProgress = (ProgressBar) view.findViewById(R.id.progress);
mProgressNumber = (TextView) view.findViewById(R.id.progress_number);
mProgressPercent = (TextView) view.findViewById(R.id.progress_percent);
setView(view, false);
} else {
View view = inflater.inflate(R.layout.progress_dialog, null);
mProgress = (ProgressBar) view.findViewById(R.id.progress);
mMessageView = (TextView) view.findViewById(R.id.message);
setView(view, false);
}
if (mMax > 0) {
setMax(mMax);
}
if (mProgressVal > 0) {
setProgress(mProgressVal);
}
if (mSecondaryProgressVal > 0) {
setSecondaryProgress(mSecondaryProgressVal);
}
if (mIncrementBy > 0) {
incrementProgressBy(mIncrementBy);
}
if (mIncrementSecondaryBy > 0) {
incrementSecondaryProgressBy(mIncrementSecondaryBy);
}
if (mProgressDrawable != null) {
setProgressDrawable(mProgressDrawable);
}
if (mIndeterminateDrawable != null) {
setIndeterminateDrawable(mIndeterminateDrawable);
}
if (mMessage != null) {
setMessage(mMessage);
}
setIndeterminate(mIndeterminate);
onProgressChanged();
}
/*
@Override
public AlertDialog create() {
mHasStarted = true;
return super.create();
}*/
public ProgressDialogBulider setProgress(int value) {
if (mHasStarted) {
mProgress.setProgress(value);
onProgressChanged();
} else {
mProgressVal = value;
}
return this;
}
public ProgressDialogBulider setSecondaryProgress(int secondaryProgress) {
if (mProgress != null) {
mProgress.setSecondaryProgress(secondaryProgress);
onProgressChanged();
} else {
mSecondaryProgressVal = secondaryProgress;
}
return this;
}
public int getProgress() {
if (mProgress != null) {
return mProgress.getProgress();
}
return mProgressVal;
}
public int getSecondaryProgress() {
if (mProgress != null) {
return mProgress.getSecondaryProgress();
}
return mSecondaryProgressVal;
}
public int getMax() {
if (mProgress != null) {
return mProgress.getMax();
}
return mMax;
}
public ProgressDialogBulider setMax(int max) {
if (mProgress != null) {
mProgress.setMax(max);
onProgressChanged();
} else {
mMax = max;
}
return this;
}
public void incrementProgressBy(int diff) {
if (mProgress != null) {
mProgress.incrementProgressBy(diff);
onProgressChanged();
} else {
mIncrementBy += diff;
}
}
public void incrementSecondaryProgressBy(int diff) {
if (mProgress != null) {
mProgress.incrementSecondaryProgressBy(diff);
onProgressChanged();
} else {
mIncrementSecondaryBy += diff;
}
}
public ProgressDialogBulider setProgressDrawable(Drawable d) {
if (mProgress != null) {
mProgress.setProgressDrawable(d);
} else {
mProgressDrawable = d;
}
return this;
}
public ProgressDialogBulider setIndeterminateDrawable(Drawable d) {
if (mProgress != null) {
mProgress.setIndeterminateDrawable(d);
} else {
mIndeterminateDrawable = d;
}
return this;
}
public ProgressDialogBulider setIndeterminate(boolean indeterminate) {
if (mProgress != null) {
mProgress.setIndeterminate(indeterminate);
} else {
mIndeterminate = indeterminate;
}
return this;
}
public boolean isIndeterminate() {
if (mProgress != null) {
return mProgress.isIndeterminate();
}
return mIndeterminate;
}
@Override
public ProgressDialogBulider setMessage(CharSequence message) {
if (mProgress != null) {
if (mProgressStyle == STYLE_HORIZONTAL) {
super.setMessage(message);
} else {
mMessageView.setText(message);
}
} else {
mMessage = message;
}
return this;
}
public void setProgressStyle(int style) {
mProgressStyle = style;
}
/**
* Change the format of the small text showing current and maximum units
* of progress. The default is "%1d/%2d".
* Should not be called during the number is progressing.
* @param format A string passed to {@link String#format String.format()};
* use "%1d" for the current number and "%2d" for the maximum. If null,
* nothing will be shown.
*/
public void setProgressNumberFormat(String format) {
mProgressNumberFormat = format;
onProgressChanged();
}
/**
* Change the format of the small text showing the percentage of progress.
* The default is
* {@link NumberFormat#getPercentInstance() NumberFormat.getPercentageInstnace().}
* Should not be called during the number is progressing.
* @param format An instance of a {@link NumberFormat} to generate the
* percentage text. If null, nothing will be shown.
*/
public void setProgressPercentFormat(NumberFormat format) {
mProgressPercentFormat = format;
onProgressChanged();
}
private void onProgressChanged() {
if (mProgressStyle == STYLE_HORIZONTAL) {
if (mViewUpdateHandler != null && !mViewUpdateHandler.hasMessages(0)) {
mViewUpdateHandler.sendEmptyMessage(0);
}
}
}
}