diff --git a/bin/EhViewer.apk b/bin/EhViewer.apk index 2225f62a6..29b106f3a 100644 Binary files a/bin/EhViewer.apk and b/bin/EhViewer.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index 6dcf1ff17..bf2842245 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/res/crunch/drawable-hdpi/drawer_shadow_left.9.png b/bin/res/crunch/drawable-hdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..a0920be8e Binary files /dev/null and b/bin/res/crunch/drawable-hdpi/drawer_shadow_left.9.png differ diff --git a/bin/res/crunch/drawable-hdpi/drawer_shadow_right.9.png b/bin/res/crunch/drawable-hdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..247ec5310 Binary files /dev/null and b/bin/res/crunch/drawable-hdpi/drawer_shadow_right.9.png differ diff --git a/bin/res/crunch/drawable-mdpi/drawer_shadow_left.9.png b/bin/res/crunch/drawable-mdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..3dc42d4b7 Binary files /dev/null and b/bin/res/crunch/drawable-mdpi/drawer_shadow_left.9.png differ diff --git a/bin/res/crunch/drawable-mdpi/drawer_shadow_right.9.png b/bin/res/crunch/drawable-mdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..51a71aa5b Binary files /dev/null and b/bin/res/crunch/drawable-mdpi/drawer_shadow_right.9.png differ diff --git a/bin/res/crunch/drawable-xhdpi/drawer_shadow_left.9.png b/bin/res/crunch/drawable-xhdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..0c5e98d3d Binary files /dev/null and b/bin/res/crunch/drawable-xhdpi/drawer_shadow_left.9.png differ diff --git a/bin/res/crunch/drawable-xhdpi/drawer_shadow_right.9.png b/bin/res/crunch/drawable-xhdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..659ba1a73 Binary files /dev/null and b/bin/res/crunch/drawable-xhdpi/drawer_shadow_right.9.png differ diff --git a/bin/res/crunch/drawable-xxhdpi/drawer_shadow_left.9.png b/bin/res/crunch/drawable-xxhdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..5d0e1273a Binary files /dev/null and b/bin/res/crunch/drawable-xxhdpi/drawer_shadow_left.9.png differ diff --git a/bin/res/crunch/drawable-xxhdpi/drawer_shadow_right.9.png b/bin/res/crunch/drawable-xxhdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..2897fdeaf Binary files /dev/null and b/bin/res/crunch/drawable-xxhdpi/drawer_shadow_right.9.png differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 99ab41ed4..7692c617b 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/res/drawable-hdpi/drawer_shadow_left.9.png b/res/drawable-hdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..aebc557fe Binary files /dev/null and b/res/drawable-hdpi/drawer_shadow_left.9.png differ diff --git a/res/drawable-hdpi/drawer_shadow_right.9.png b/res/drawable-hdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..f9d58bfd1 Binary files /dev/null and b/res/drawable-hdpi/drawer_shadow_right.9.png differ diff --git a/res/drawable-mdpi/drawer_shadow_left.9.png b/res/drawable-mdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..47253804d Binary files /dev/null and b/res/drawable-mdpi/drawer_shadow_left.9.png differ diff --git a/res/drawable-mdpi/drawer_shadow_right.9.png b/res/drawable-mdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..64a5ca737 Binary files /dev/null and b/res/drawable-mdpi/drawer_shadow_right.9.png differ diff --git a/res/drawable-xhdpi/drawer_shadow_left.9.png b/res/drawable-xhdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..0fe08f4f3 Binary files /dev/null and b/res/drawable-xhdpi/drawer_shadow_left.9.png differ diff --git a/res/drawable-xhdpi/drawer_shadow_right.9.png b/res/drawable-xhdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..db87b66da Binary files /dev/null and b/res/drawable-xhdpi/drawer_shadow_right.9.png differ diff --git a/res/drawable-xxhdpi/drawer_shadow_left.9.png b/res/drawable-xxhdpi/drawer_shadow_left.9.png new file mode 100644 index 000000000..56c56b11f Binary files /dev/null and b/res/drawable-xxhdpi/drawer_shadow_left.9.png differ diff --git a/res/drawable-xxhdpi/drawer_shadow_right.9.png b/res/drawable-xxhdpi/drawer_shadow_right.9.png new file mode 100644 index 000000000..542346adf Binary files /dev/null and b/res/drawable-xxhdpi/drawer_shadow_right.9.png differ diff --git a/res/layout/list.xml b/res/layout/list.xml index 083db0009..726757bf1 100644 --- a/res/layout/list.xml +++ b/res/layout/list.xml @@ -1,4 +1,4 @@ - @@ -55,4 +55,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index e26053c67..015e9d512 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -1,6 +1,9 @@ + 打开侧边栏 + 关闭侧边栏 + 警告 该应用内容来自互联网,部分内容可能对您的生理及心理造成难以恢复的伤害。该应用作者不会对由该应用造成的后果负责。您是否愿意继续使用该应用? diff --git a/res/values/strings.xml b/res/values/strings.xml index 22ba154bb..f9ed1e547 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3,6 +3,9 @@ EhViewer + Open navigation drawer + Close navigation drawer + Waring 该应用内容来自互联网,部分内容可能对您的生理及心理造成难以恢复的伤害。该应用作者不会对由该应用造成的后果负责。您是否愿意继续使用该应用? diff --git a/res/values/styles.xml b/res/values/styles.xml index a1822cae4..16481f796 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -1,11 +1,17 @@ - + + diff --git a/src/com/hippo/ehviewer/GalleryDetail.java b/src/com/hippo/ehviewer/GalleryDetail.java new file mode 100644 index 000000000..8edbce96c --- /dev/null +++ b/src/com/hippo/ehviewer/GalleryDetail.java @@ -0,0 +1,70 @@ +package com.hippo.ehviewer; + +import android.os.Parcel; +import android.os.Parcelable; + +public class GalleryDetail extends GalleryInfo{ + + public String pages; + public String size; + public String resized; + public String parent; + public String visible; + public String language; + public String people; + public String firstPage; + public String[][] tags; + + // For Preview + public int previewSum; + public int previewPerPage; + public PageList[] previewLists; + + /* + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public GalleryDetail createFromParcel(Parcel source) { + GalleryDetail p = + new GalleryDetail(GalleryInfo.CREATOR.createFromParcel(source)); + p.pages = source.readString(); + p.size = source.readString(); + p.resized = source.readString(); + p.parent = source.readString(); + p.visible = source.readString(); + p.language = source.readString(); + p.people = source.readString(); + p.firstPage = source.readString(); + int tagsNum = source.readInt(); + p.tags = new String[tagsNum][]; + for (int i = 0; i < tagsNum; i++) { + int num = source.readInt(); + String[] tag = new String[num]; + p.tags[i] = tag; + for (int j = 0; j < num; j++) { + tag[j] = source.readString(); + } + } + p.previewSum = source.readInt(); + p.previewPerPage = source.readInt(); + source.readParcelable(loader); + return p; + } + + @Override + public GalleryDetail[] newArray(int size) { + return new GalleryDetail[size]; + } + };*/ + + public GalleryDetail(GalleryInfo galleryInfo) { + gid = galleryInfo.gid; + token = galleryInfo.token; + title = galleryInfo.title; + posted = galleryInfo.posted; + category = galleryInfo.category; + thumb = galleryInfo.thumb; + uploader = galleryInfo.uploader; + rating = galleryInfo.rating; + } +} diff --git a/src/com/hippo/ehviewer/GalleryInfo.java b/src/com/hippo/ehviewer/GalleryInfo.java new file mode 100644 index 000000000..3447c845d --- /dev/null +++ b/src/com/hippo/ehviewer/GalleryInfo.java @@ -0,0 +1,54 @@ +package com.hippo.ehviewer; + +import android.os.Parcel; +import android.os.Parcelable; + +public class GalleryInfo implements Parcelable{ + public String gid; + public String token; + public String title; + public String posted; + public int category; + public String thumb; + public String uploader; + public String rating; + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public GalleryInfo createFromParcel(Parcel source) { + GalleryInfo p = new GalleryInfo(); + p.gid = source.readString(); + p.token = source.readString(); + p.title = source.readString(); + p.posted = source.readString(); + p.category = source.readInt(); + p.thumb = source.readString(); + p.uploader = source.readString(); + p.rating = source.readString(); + return null; + } + + @Override + public GalleryInfo[] newArray(int size) { + return new GalleryInfo[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(gid); + dest.writeString(token); + dest.writeString(title); + dest.writeString(posted); + dest.writeInt(category); + dest.writeString(thumb); + dest.writeString(uploader); + dest.writeString(rating); + } +} diff --git a/src/com/hippo/ehviewer/MangaDetail.java b/src/com/hippo/ehviewer/MangaDetail.java deleted file mode 100644 index 888adeb06..000000000 --- a/src/com/hippo/ehviewer/MangaDetail.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.hippo.ehviewer; - -public class MangaDetail extends ListMangaDetail{ - - public String pages; - public String size; - public String resized; - public String parent; - public String visible; - public String language; - public String people; - public String firstPage; - - // For Preview - public int previewSum; - public int previewPerPage; - public PageList[] previewLists; - -} diff --git a/src/com/hippo/ehviewer/activity/DownloadActivity.java b/src/com/hippo/ehviewer/activity/DownloadActivity.java index b8b2ffa5f..8235a87af 100644 --- a/src/com/hippo/ehviewer/activity/DownloadActivity.java +++ b/src/com/hippo/ehviewer/activity/DownloadActivity.java @@ -4,9 +4,10 @@ import java.io.File; import java.io.IOException; import java.util.List; +import org.apache.commons.lang3.StringEscapeUtils; + import com.hippo.ehviewer.BeautifyScreen; import com.hippo.ehviewer.DownloadInfo; -import com.hippo.ehviewer.ListMangaDetail; import com.hippo.ehviewer.R; import com.hippo.ehviewer.service.DownloadService; import com.hippo.ehviewer.service.DownloadServiceConnection; @@ -33,7 +34,9 @@ import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; import android.os.IBinder; + import com.hippo.ehviewer.util.Log; + import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; @@ -76,7 +79,7 @@ public class DownloadActivity extends Activity { mServiceConn.getService().cancel(Download.getKey(longClickItemIndex)); mDlAdapter.notifyDataSetChanged(); // TODO 有人反馈 Download.get(longClickItemIndex).title 为空,看来很有必要在正则抓取时检查是否为空 - File dir = new File(Config.getDownloadPath(), Download.get(longClickItemIndex).title); + File dir = new File(Config.getDownloadPath(), StringEscapeUtils.escapeHtml4(Download.get(longClickItemIndex).title)); try { Util.deleteContents(dir); } catch (IOException e) { diff --git a/src/com/hippo/ehviewer/activity/FavouriteActivity.java b/src/com/hippo/ehviewer/activity/FavouriteActivity.java index 808f55899..790cf9e62 100644 --- a/src/com/hippo/ehviewer/activity/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/activity/FavouriteActivity.java @@ -8,7 +8,9 @@ import android.content.Intent; import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; + import com.hippo.ehviewer.util.Log; + import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -24,8 +26,8 @@ import android.widget.AdapterView.OnItemLongClickListener; import android.widget.Toast; import com.hippo.ehviewer.BeautifyScreen; +import com.hippo.ehviewer.GalleryInfo; import com.hippo.ehviewer.ImageLoadManager; -import com.hippo.ehviewer.ListMangaDetail; import com.hippo.ehviewer.R; import com.hippo.ehviewer.service.DownloadService; import com.hippo.ehviewer.service.DownloadServiceConnection; @@ -43,7 +45,7 @@ public class FavouriteActivity extends Activity{ private static final String TAG = "FavouriteActivity"; private FlAdapter flAdapter; - private ArrayList mFavouriteLmd; + private ArrayList mFavouriteLmd; private int longClickItemIndex; private ImageLoadManager mImageLoadManager; @@ -65,7 +67,7 @@ public class FavouriteActivity extends Activity{ flAdapter.notifyDataSetChanged(); break; case 1: - ListMangaDetail lmd = mFavouriteLmd.get(longClickItemIndex); + GalleryInfo lmd = mFavouriteLmd.get(longClickItemIndex); Intent it = new Intent(FavouriteActivity.this, DownloadService.class); startService(it); mServiceConn.getService().add(lmd.gid, lmd.thumb, @@ -111,7 +113,7 @@ public class FavouriteActivity extends Activity{ @Override public View getView(int position, View convertView, ViewGroup parent) { - ListMangaDetail lmd= mFavouriteLmd.get(position); + GalleryInfo lmd= mFavouriteLmd.get(position); if (convertView == null) convertView = mInflater.inflate(R.layout.list_item, null); @@ -191,24 +193,9 @@ public class FavouriteActivity extends Activity{ int position, long arg3) { Intent intent = new Intent(FavouriteActivity.this, MangaDetailActivity.class); - ListMangaDetail lmd = mFavouriteLmd.get(position); - intent.putExtra("url", EhClient.detailHeader + lmd.gid + "/" + lmd.token); - - intent.putExtra("gid", lmd.gid); - intent.putExtra("token", lmd.token); - intent.putExtra("archiver_key", lmd.archiver_key); - intent.putExtra("title", lmd.title); - intent.putExtra("title_jpn", lmd.title_jpn); - intent.putExtra("category", lmd.category); - intent.putExtra("thumb", lmd.thumb); - intent.putExtra("uploader", lmd.uploader); - intent.putExtra("posted", lmd.posted); - intent.putExtra("filecount", lmd.filecount); - intent.putExtra("filesize", lmd.filesize); - intent.putExtra("expunged", lmd.expunged); - intent.putExtra("rating", lmd.rating); - intent.putExtra("torrentcount", lmd.torrentcount); - + GalleryInfo gi = mFavouriteLmd.get(position); + intent.putExtra("url", EhClient.detailHeader + gi.gid + "/" + gi.token); + intent.putExtra(MangaDetailActivity.KEY_G_INFO, gi); startActivity(intent); } }); diff --git a/src/com/hippo/ehviewer/activity/MangaDetailActivity.java b/src/com/hippo/ehviewer/activity/MangaDetailActivity.java index 868c5460b..7b8499e9d 100644 --- a/src/com/hippo/ehviewer/activity/MangaDetailActivity.java +++ b/src/com/hippo/ehviewer/activity/MangaDetailActivity.java @@ -4,8 +4,9 @@ import java.util.ArrayList; import com.hippo.ehviewer.AppContext; import com.hippo.ehviewer.BeautifyScreen; +import com.hippo.ehviewer.GalleryDetail; +import com.hippo.ehviewer.GalleryInfo; import com.hippo.ehviewer.ListUrls; -import com.hippo.ehviewer.MangaDetail; import com.hippo.ehviewer.PageList; import com.hippo.ehviewer.R; import com.hippo.ehviewer.service.DownloadService; @@ -33,7 +34,9 @@ import android.graphics.drawable.ColorDrawable; import android.os.Build; import android.os.Bundle; import android.util.DisplayMetrics; + import com.hippo.ehviewer.util.Log; + import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -59,6 +62,8 @@ public class MangaDetailActivity extends Activity { private static final String TAG = "MangaDetailActivity"; + public static final String KEY_G_INFO = "gallery_info"; + private AppContext mAppContext; private EhClient mEhClient; @@ -83,7 +88,7 @@ public class MangaDetailActivity extends Activity { private AlertDialog goToDialog; - private MangaDetail mangaDetail; + private GalleryDetail mangaDetail; private int curPage; private int screenHeight; private int columnCount; @@ -155,7 +160,7 @@ public class MangaDetailActivity extends Activity { } }); // Set white drawable for temp - ColorDrawable white = new ColorDrawable(getResources().getColor(android.R.color.white)); + ColorDrawable white = new ColorDrawable(Ui.HOLO_WHITE); white.setBounds(0, 0, item.width, item.height); tvu.setCompoundDrawables(null, white, null, null); @@ -218,7 +223,7 @@ public class MangaDetailActivity extends Activity { private class MangaDetailGetListener implements EhClient.OnGetMangaDetailListener { @Override - public void onSuccess(MangaDetail md) { + public void onSuccess(GalleryDetail md) { Cache.mdCache.put(mangaDetail.gid, md); layout(md); } @@ -463,22 +468,7 @@ public class MangaDetailActivity extends Activity { mangaDetail = Cache.mdCache.get(gid); if (mangaDetail == null) { getFromCache = false; - mangaDetail = new MangaDetail(); - mangaDetail.gid = gid; - mangaDetail.token = intent.getStringExtra("token"); - mangaDetail.archiver_key = intent.getStringExtra("archiver_key"); - mangaDetail.title = intent.getStringExtra("title"); - mangaDetail.title_jpn = intent.getStringExtra("title_jpn"); - mangaDetail.category = intent.getIntExtra("category", ListUrls.UNKNOWN); - mangaDetail.thumb = intent.getStringExtra("thumb"); - mangaDetail.uploader = intent.getStringExtra("uploader"); - mangaDetail.posted = intent.getStringExtra("posted"); - mangaDetail.filecount = intent.getStringExtra("filecount"); - mangaDetail.filesize = intent.getLongExtra("filesize", 0); - mangaDetail.expunged = intent.getBooleanExtra("expunged", false); - mangaDetail.rating = intent.getStringExtra("rating"); - mangaDetail.torrentcount = intent.getStringExtra("torrentcount"); - mangaDetail.tags = null; + mangaDetail = new GalleryDetail((GalleryInfo)(intent.getParcelableExtra(KEY_G_INFO))); } getActionBar().setDisplayHomeAsUpEnabled(true); @@ -522,7 +512,7 @@ public class MangaDetailActivity extends Activity { mEhClient.getMangaDetail(url, mangaDetail, new MangaDetailGetListener()); } - private void layout(MangaDetail md) { + private void layout(GalleryDetail md) { // Delete progress bar waitPb.setVisibility(View.GONE); diff --git a/src/com/hippo/ehviewer/activity/MangaListActivity.java b/src/com/hippo/ehviewer/activity/MangaListActivity.java index 8144fa447..0ce1baa01 100644 --- a/src/com/hippo/ehviewer/activity/MangaListActivity.java +++ b/src/com/hippo/ehviewer/activity/MangaListActivity.java @@ -5,8 +5,8 @@ import java.util.ArrayList; import com.hippo.ehviewer.AppContext; import com.hippo.ehviewer.BeautifyScreen; +import com.hippo.ehviewer.GalleryInfo; import com.hippo.ehviewer.ImageLoadManager; -import com.hippo.ehviewer.ListMangaDetail; import com.hippo.ehviewer.ListUrls; import com.hippo.ehviewer.R; import com.hippo.ehviewer.UpdateHelper; @@ -26,7 +26,6 @@ import com.hippo.ehviewer.view.GetPaddingRelativeLayout; import com.hippo.ehviewer.view.TagListView; import com.hippo.ehviewer.view.TagsAdapter; import com.hippo.ehviewer.widget.DialogBuilder; -import com.hippo.ehviewer.widget.DrawerLayout; import com.hippo.ehviewer.widget.LoadImageView; import com.hippo.ehviewer.widget.PullListView; import com.hippo.ehviewer.widget.SuperDialogUtil; @@ -43,6 +42,8 @@ import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Color; +import android.support.v4.app.ActionBarDrawerToggle; +import android.support.v4.widget.DrawerLayout; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; @@ -81,7 +82,7 @@ public class MangaListActivity extends Activity { private AppContext mAppContext; private EhClient mEhClient; - private DrawerLayout drawer; + private DrawerLayout mDrawerLayout; private GetPaddingRelativeLayout mainLayout; private TagListView listMenu; private RelativeLayout loginMenu; @@ -101,6 +102,8 @@ public class MangaListActivity extends Activity { private Button logoutButton; private View waitlogoutView; + private ActionBarDrawerToggle mDrawerToggle; + private TagsAdapter tagsAdapter; private ListUrls lus; @@ -108,7 +111,7 @@ public class MangaListActivity extends Activity { private ArrayList listMenuTitle = new ArrayList(); private int mStableItemCount; - private ArrayList lmdArray = new ArrayList(); + private ArrayList lmdArray = new ArrayList(); private ImageLoadManager mImageLoadManager; @@ -216,7 +219,7 @@ public class MangaListActivity extends Activity { @Override public void onClick(View v) { ((AlertButton)v).dialog.dismiss(); - drawer.closeDrawers(); + mDrawerLayout.closeDrawers(); ListUrls listUrls = getLus(filterDialog); String search = listUrls.getSearch(); String t = null; @@ -358,7 +361,7 @@ public class MangaListActivity extends Activity { @Override public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) { - ListMangaDetail lmd; + GalleryInfo lmd; switch (position) { case 0: // Add favourite item lmd = lmdArray.get(longClickItemIndex); @@ -718,7 +721,7 @@ public class MangaListActivity extends Activity { private class MangaListGetListener implements EhClient.OnGetMangaListListener { @Override - public void onSuccess(Object checkFlag, ArrayList newLmdArray, + public void onSuccess(Object checkFlag, ArrayList newLmdArray, int indexPerPage, int maxPage) { MangaListGetPackage getPackage = (MangaListGetPackage)checkFlag; if (getPackage.stamp != lastGetStamp) @@ -974,7 +977,7 @@ public class MangaListActivity extends Activity { @Override public View getView(int position, View convertView, ViewGroup parent) { - ListMangaDetail lmd= lmdArray.get(position); + GalleryInfo lmd= lmdArray.get(position); boolean isNew = false; if (convertView == null) { isNew = true; @@ -1013,11 +1016,19 @@ public class MangaListActivity extends Activity { @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); + mDrawerToggle.onConfigurationChanged(newConfig); if (Build.VERSION.SDK_INT >= 19) { BeautifyScreen.fixColour(this); } } - + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + // Sync the toggle state after onRestoreInstanceState has occurred. + mDrawerToggle.syncState(); + } + @Override protected void onResume() { super.onResume(); @@ -1058,15 +1069,13 @@ public class MangaListActivity extends Activity { // mImageLoadManager = new ImageLoadManager(getApplicationContext(), Cache.memoryCache, Cache.cpCache); - getActionBar().setDisplayHomeAsUpEnabled(true); - // For colourfy the activity if (Build.VERSION.SDK_INT >= 19) { BeautifyScreen.ColourfyScreen(this); } // Get View - drawer = (DrawerLayout)findViewById(R.id.drawer_layout); + mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); mainLayout = (GetPaddingRelativeLayout)findViewById(R.id.list_main); listMenu = (TagListView) findViewById(R.id.list_menu_list); loginMenu = (RelativeLayout)findViewById(R.id.list_menu_login); @@ -1089,6 +1098,32 @@ public class MangaListActivity extends Activity { // fitsSystemWindows for menu mainLayout.setView(listMenu, loginMenu); + // Drawer + getActionBar().setDisplayHomeAsUpEnabled(true); + getActionBar().setHomeButtonEnabled(true); + mDrawerToggle = new ActionBarDrawerToggle( + this, /* host Activity */ + mDrawerLayout, /* DrawerLayout object */ + R.drawable.ic_navigation_drawer, /* nav drawer image to replace 'Up' caret */ + R.string.drawer_open, /* "open drawer" description for accessibility */ + R.string.drawer_close /* "close drawer" description for accessibility */ + ) { + public void onDrawerClosed(View view) { + getActionBar().setTitle(title); + invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() + } + + public void onDrawerOpened(View drawerView) { + getActionBar().setTitle(R.string.app_name); + invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() + } + }; + mDrawerLayout.setDrawerListener(mDrawerToggle); + + // set drawer shadow + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT); + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT); + // leftDrawer String[] menuTitles = getResources().getStringArray(R.array.list_list_title); mStableItemCount = menuTitles.length; @@ -1108,23 +1143,23 @@ public class MangaListActivity extends Activity { int position, long arg3) { if (position == 0) { // Home page if (refresh(new ListUrls(ListUrls.ALL_TYPE, null, 0), listMenuTitle.get(position))) - drawer.closeDrawers(); + mDrawerLayout.closeDrawers(); } else if (position == 1) { // Favourite Intent intent = new Intent(MangaListActivity.this, FavouriteActivity.class); startActivity(intent); - drawer.closeDrawers(); + mDrawerLayout.closeDrawers(); } else if (position == 2) { // filter filterDialog.show(); } else if (position == 3) { // Download Intent intent = new Intent(MangaListActivity.this, DownloadActivity.class); startActivity(intent); - drawer.closeDrawers(); + mDrawerLayout.closeDrawers(); } else if (position >= mStableItemCount){ ListUrls listUrls = Tag.get(listMenuTitle.get(position)); if (listUrls != null && refresh(listUrls, listMenuTitle.get(position))) - drawer.closeDrawers(); + mDrawerLayout.closeDrawers(); } } }); @@ -1137,12 +1172,12 @@ public class MangaListActivity extends Activity { listMenu.setOnMoveLister(new TagListView.OnMoveLister() { @Override public void onMoveStart() { - drawer.setEnabled(false); + mDrawerLayout.setEnabled(false); } @Override public void onMoveOver() { - drawer.setEnabled(true); + mDrawerLayout.setEnabled(true); } }); @@ -1203,7 +1238,7 @@ public class MangaListActivity extends Activity { if (isChanged) { isExhentaiListAdapter.notifyDataSetChanged(); refresh(new ListUrls(ListUrls.ALL_TYPE, null, 0), listMenuTitle.get(0)); - drawer.closeDrawers(); // TODO + mDrawerLayout.closeDrawers(); // TODO } } }); @@ -1266,23 +1301,9 @@ public class MangaListActivity extends Activity { int position, long arg3) { Intent intent = new Intent(MangaListActivity.this, MangaDetailActivity.class); - ListMangaDetail lmd = lmdArray.get(position); - intent.putExtra("url", EhClient.detailHeader + lmd.gid + "/" + lmd.token); - intent.putExtra("gid", lmd.gid); - intent.putExtra("token", lmd.token); - intent.putExtra("archiver_key", lmd.archiver_key); - intent.putExtra("title", lmd.title); - intent.putExtra("title_jpn", lmd.title_jpn); - intent.putExtra("category", lmd.category); - intent.putExtra("thumb", lmd.thumb); - intent.putExtra("uploader", lmd.uploader); - intent.putExtra("posted", lmd.posted); - intent.putExtra("filecount", lmd.filecount); - intent.putExtra("filesize", lmd.filesize); - intent.putExtra("expunged", lmd.expunged); - intent.putExtra("rating", lmd.rating); - intent.putExtra("torrentcount", lmd.torrentcount); - + GalleryInfo gi = lmdArray.get(position); + intent.putExtra("url", EhClient.detailHeader + gi.gid + "/" + gi.token); + intent.putExtra(MangaDetailActivity.KEY_G_INFO, gi); startActivity(intent); } }); @@ -1369,6 +1390,18 @@ public class MangaListActivity extends Activity { return true; } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + // If the nav drawer is open, hide action items related to the content view + boolean drawerOpen = mDrawerLayout.isDrawerOpen(Gravity.LEFT) + | mDrawerLayout.isDrawerOpen(Gravity.RIGHT); + menu.findItem(R.id.action_search).setVisible(!drawerOpen); + menu.findItem(R.id.action_refresh).setVisible(!drawerOpen); + menu.findItem(R.id.action_jump).setVisible(!drawerOpen); + menu.findItem(R.id.action_settings).setVisible(!drawerOpen); + return super.onPrepareOptionsMenu(menu); + } + // Double click back exit @Override public void onBackPressed() { @@ -1388,10 +1421,10 @@ public class MangaListActivity extends Activity { // Handle item selection switch (item.getItemId()) { case android.R.id.home: - if (drawer.isDrawerOpen(Gravity.START)) - drawer.closeDrawers(); + if (mDrawerLayout.isDrawerOpen(Gravity.START)) + mDrawerLayout.closeDrawers(); else - drawer.openDrawer(Gravity.START); + mDrawerLayout.openDrawer(Gravity.START); return true; case R.id.action_refresh: // TODO 点击刷新,pullviewheader 不会自动出来 refresh(lus.clone(), listMenuTitle.get(0)); diff --git a/src/com/hippo/ehviewer/ListMangaDetail.java b/src/com/hippo/ehviewer/apiGetGalleryInfo.java similarity index 50% rename from src/com/hippo/ehviewer/ListMangaDetail.java rename to src/com/hippo/ehviewer/apiGetGalleryInfo.java index 51a5ef28e..0180a76b5 100644 --- a/src/com/hippo/ehviewer/ListMangaDetail.java +++ b/src/com/hippo/ehviewer/apiGetGalleryInfo.java @@ -1,19 +1,11 @@ package com.hippo.ehviewer; -public class ListMangaDetail { - public String gid; - public String token; +public class apiGetGalleryInfo extends GalleryInfo{ public String archiver_key; - public String title; public String title_jpn; - public int category; - public String thumb; - public String uploader; - public String posted; public String filecount; public long filesize; public boolean expunged; - public String rating; public String torrentcount; public String[][] tags; } diff --git a/src/com/hippo/ehviewer/gallery/glrenderer/UploadedTexture.java b/src/com/hippo/ehviewer/gallery/glrenderer/UploadedTexture.java index ba54e9d71..783b9f8bc 100644 --- a/src/com/hippo/ehviewer/gallery/glrenderer/UploadedTexture.java +++ b/src/com/hippo/ehviewer/gallery/glrenderer/UploadedTexture.java @@ -144,8 +144,9 @@ public abstract class UploadedTexture extends BasicTexture { } private void freeBitmap() { - Assert.assertTrue(mBitmap != null); - onFreeBitmap(mBitmap); + //Assert.assertTrue(mBitmap != null); + if (mBitmap != null) + onFreeBitmap(mBitmap); mBitmap = null; } diff --git a/src/com/hippo/ehviewer/util/Cache.java b/src/com/hippo/ehviewer/util/Cache.java index 8ade04ead..000024fad 100644 --- a/src/com/hippo/ehviewer/util/Cache.java +++ b/src/com/hippo/ehviewer/util/Cache.java @@ -6,10 +6,10 @@ import android.graphics.Bitmap; import android.os.Build; import android.os.Environment; import android.support.v4.util.LruCache; -import com.hippo.ehviewer.util.Log; +import com.hippo.ehviewer.util.Log; import com.hippo.ehviewer.DiskCache; -import com.hippo.ehviewer.MangaDetail; +import com.hippo.ehviewer.GalleryDetail; public class Cache { private static final String TAG = "Cache"; @@ -19,7 +19,7 @@ public class Cache { public static final String cpCachePath = "/EhViewer/cache/cover"; public static DiskCache cpCache = null; public static LruCache memoryCache = null; - public static LruCache mdCache = null; + public static LruCache mdCache = null; private static final int MD_CACHE_SIZE = 5; @@ -62,9 +62,9 @@ public class Cache { } }; - mdCache = new LruCache(MD_CACHE_SIZE) { + mdCache = new LruCache(MD_CACHE_SIZE) { @Override - protected int sizeOf(String key, MangaDetail md) { + protected int sizeOf(String key, GalleryDetail md) { return 1; } }; diff --git a/src/com/hippo/ehviewer/util/EhClient.java b/src/com/hippo/ehviewer/util/EhClient.java index 3662f8898..6b75ea306 100644 --- a/src/com/hippo/ehviewer/util/EhClient.java +++ b/src/com/hippo/ehviewer/util/EhClient.java @@ -24,9 +24,9 @@ import org.apache.http.conn.ConnectTimeoutException; import com.hippo.ehviewer.AppContext; import com.hippo.ehviewer.DiskCache; import com.hippo.ehviewer.DownloadInfo; -import com.hippo.ehviewer.ListMangaDetail; +import com.hippo.ehviewer.GalleryDetail; +import com.hippo.ehviewer.GalleryInfo; import com.hippo.ehviewer.ListUrls; -import com.hippo.ehviewer.MangaDetail; import com.hippo.ehviewer.PageList; import com.hippo.ehviewer.R; import com.hippo.ehviewer.gallery.data.ImageSet; @@ -43,6 +43,7 @@ import android.graphics.Movie; import android.os.Handler; import android.os.Message; import android.support.v4.util.LruCache; + import com.hippo.ehviewer.util.Log; // TODO Stringbuffer to StringBuild @@ -51,7 +52,6 @@ public class EhClient { private static final String TAG = "EhClient"; - private static String API_URL = "http://g.e-hentai.org/api.php"; private static String loginUrl = "http://forums.e-hentai.org/index.php?act=Login&CODE=01"; private static final String E_HENTAI_LIST_HEADER = "http://g.e-hentai.org/"; @@ -59,14 +59,12 @@ public class EhClient { public static final String E_HENTAI_DETAIL_HEADER = "http://g.e-hentai.org/g/"; public static final String EXHENTAI_DETAIL_HEADER = "http://exhentai.org/g/"; - public static final String UPDATE_URL = "http://ehviewersu.appsp0t.com/"; - public static final String UPDATE_URI_QINIU = "http://ehviewer.qiniudn.com/"; - public static String listHeader; public static String detailHeader; private boolean mLogin = false; - private String mName; + private String mUsername; + private String mDisplayName; private String mLogoutUrl; private AppContext mAppContext; @@ -88,13 +86,13 @@ public class EhClient { } public interface OnGetMangaListListener { - public void onSuccess(Object checkFlag, ArrayList lmdArray, + public void onSuccess(Object checkFlag, ArrayList lmdArray, int indexPerPage, int maxPage); public void onFailure(Object checkFlag, String eMsg); } public interface OnGetMangaDetailListener { - public void onSuccess(MangaDetail md); + public void onSuccess(GalleryDetail md); public void onFailure(String eMsg); } @@ -114,7 +112,7 @@ public class EhClient { } public interface OnGetGalleryMetadataListener { - public void onSuccess(Map lmds); + public void onSuccess(Map lmds); public void onFailure(String eMsg); } @@ -156,7 +154,7 @@ public class EhClient { } public String getUsername() { - return mName; + return mUsername; } private static final int LOGIN = 0x0; @@ -364,7 +362,7 @@ public class EhClient { public void onFutureDone(Future future) { if (task.ok) { mLogin = true; - mName = task.name; + mUsername = task.name; mLogoutUrl = task.logoutUrl; } Message msg = new Message(); @@ -432,13 +430,13 @@ public class EhClient { // Get Manga List private class GetMangaListPackage { public Object checkFlag; - public ArrayList lmdArray; + public ArrayList lmdArray; public int indexPerPage; public int maxPage; public OnGetMangaListListener listener; public String eMsg; - public GetMangaListPackage(Object checkFlag, ArrayList lmdArray, int indexPerPage, + public GetMangaListPackage(Object checkFlag, ArrayList lmdArray, int indexPerPage, int maxPage, OnGetMangaListListener listener, String eMsg) { this.checkFlag = checkFlag; this.lmdArray = lmdArray; @@ -453,7 +451,7 @@ public class EhClient { private String url; - public ArrayList lmdArray; + public ArrayList lmdArray; public int indexPerPage; public int maxPage; public String eMsg; @@ -491,10 +489,10 @@ public class EhClient { // To continue get list getPageCount = true; } else if (pageContent.contains("No hits found

")) { - lmdArray = new ArrayList(); + lmdArray = new ArrayList(); maxPage = 0; } else if (pageContent.contains("JFIF")) { // sad panda - lmdArray = new ArrayList(); + lmdArray = new ArrayList(); maxPage = -1; } else eMsg = mAppContext.getString(R.string.em_parser_error); @@ -507,8 +505,8 @@ public class EhClient { while (m.find()) { if (lmdArray == null) - lmdArray = new ArrayList(); - ListMangaDetail lmd = new ListMangaDetail(); + lmdArray = new ArrayList(); + GalleryInfo lmd = new GalleryInfo(); lmd.category = getType(m.group(1)); lmd.posted = m.group(2); @@ -630,11 +628,11 @@ public class EhClient { // Get Manga Detail private class GetMangaDetailPackage { public boolean ok; - public MangaDetail mangaDetail; + public GalleryDetail mangaDetail; public OnGetMangaDetailListener listener; public String eMsg; - public GetMangaDetailPackage(boolean ok, MangaDetail mangaDetail, + public GetMangaDetailPackage(boolean ok, GalleryDetail mangaDetail, OnGetMangaDetailListener listener, String eMsg) { this.ok = ok; this.mangaDetail = mangaDetail; @@ -646,12 +644,12 @@ public class EhClient { private class GetMangaDetailRunnable implements Runnable { private String url; - private MangaDetail md; + private GalleryDetail md; public boolean ok; public String eMsg; - public GetMangaDetailRunnable(String url, MangaDetail md) { + public GetMangaDetailRunnable(String url, GalleryDetail md) { this.url = url; this.md = md; } @@ -714,7 +712,7 @@ public class EhClient { } } - public void getMangaDetail(String url, final MangaDetail md, + public void getMangaDetail(String url, final GalleryDetail md, final OnGetMangaDetailListener listener) { final GetMangaDetailRunnable task = new GetMangaDetailRunnable(url, md); diff --git a/src/com/hippo/ehviewer/util/Favourite.java b/src/com/hippo/ehviewer/util/Favourite.java index ed53d9a7c..f6c7861ff 100644 --- a/src/com/hippo/ehviewer/util/Favourite.java +++ b/src/com/hippo/ehviewer/util/Favourite.java @@ -8,7 +8,7 @@ import java.io.ObjectOutputStream; import java.io.OptionalDataException; import java.util.ArrayList; -import com.hippo.ehviewer.ListMangaDetail; +import com.hippo.ehviewer.GalleryInfo; import android.content.Context; import android.content.SharedPreferences; @@ -23,7 +23,7 @@ public class Favourite { private static SharedPreferences mFavouritePre; //private static boolean isLru = false; // TODO float the last read favourite item private static ArrayList mListOrder = null; - private static ArrayList mFavouriteLmd = null; + private static ArrayList mFavouriteLmd = null; private static boolean mInit = false; @@ -53,7 +53,7 @@ public class Favourite { private static void getFavourite() { mListOrder = new ArrayList(); - mFavouriteLmd = new ArrayList(); + mFavouriteLmd = new ArrayList(); String[] allOrder = Util.getStrings(mFavouritePre, LIST_ORDER); if (allOrder == null) @@ -80,7 +80,7 @@ public class Favourite { * @param lmd * @return True if push successfully */ - public static boolean push(ListMangaDetail lmd) { + public static boolean push(GalleryInfo lmd) { if (!mInit) { throw new IllegalStateException("Please init Favourite first."); } @@ -121,7 +121,7 @@ public class Favourite { * * @return */ - public static ArrayList getFavouriteList() { + public static ArrayList getFavouriteList() { return mFavouriteLmd; } @@ -141,7 +141,7 @@ public class Favourite { // TODO } - protected static String encodeLmd(ListMangaDetail lmd) { + protected static String encodeLmd(GalleryInfo lmd) { ByteArrayOutputStream os = new ByteArrayOutputStream(); try { ObjectOutputStream outputStream = new ObjectOutputStream(os); @@ -159,10 +159,10 @@ public class Favourite { return Util.byteArrayToHexString(os.toByteArray()); } - protected static ListMangaDetail decodeLmd(String lmdStr) { + protected static GalleryInfo decodeLmd(String lmdStr) { byte[] bytes = Util.hexStringToByteArray(lmdStr); ByteArrayInputStream is = new ByteArrayInputStream(bytes); - ListMangaDetail lmd = null; + GalleryInfo lmd = null; try { ObjectInputStream ois = new ObjectInputStream(is); lmd = readObject(ois); @@ -178,40 +178,28 @@ public class Favourite { return lmd; } - public static void writeObject(ListMangaDetail lmd, ObjectOutputStream out) throws IOException { + public static void writeObject(GalleryInfo lmd, ObjectOutputStream out) throws IOException { out.writeObject(lmd.gid); out.writeObject(lmd.token); - out.writeObject(lmd.archiver_key); out.writeObject(lmd.title); - out.writeObject(lmd.title_jpn); out.writeObject((Integer)lmd.category); out.writeObject(lmd.thumb); out.writeObject(lmd.uploader); out.writeObject(lmd.posted); - out.writeObject(lmd.filecount); - out.writeObject((Long)lmd.filesize); - out.writeObject((Boolean)lmd.expunged); out.writeObject(lmd.rating); - out.writeObject(lmd.torrentcount); } - public static ListMangaDetail readObject(ObjectInputStream in) { - ListMangaDetail lmd = new ListMangaDetail(); + public static GalleryInfo readObject(ObjectInputStream in) { + GalleryInfo lmd = new GalleryInfo(); try { lmd.gid = (String)in.readObject(); lmd.token = (String)in.readObject(); - lmd.archiver_key = (String)in.readObject(); lmd.title = (String)in.readObject(); - lmd.title_jpn = (String)in.readObject(); lmd.category = (Integer)in.readObject(); lmd.thumb = (String)in.readObject(); lmd.uploader = (String)in.readObject(); lmd.posted = (String)in.readObject(); - lmd.filecount = (String)in.readObject(); - lmd.filesize = (Long)in.readObject(); - lmd.expunged = (Boolean)in.readObject(); lmd.rating = (String)in.readObject(); - lmd.torrentcount = (String)in.readObject(); } catch (OptionalDataException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { diff --git a/src/com/hippo/ehviewer/util/Tag.java b/src/com/hippo/ehviewer/util/Tag.java index 0e7963705..8a43641a9 100644 --- a/src/com/hippo/ehviewer/util/Tag.java +++ b/src/com/hippo/ehviewer/util/Tag.java @@ -1,280 +1,279 @@ -package com.hippo.ehviewer.util; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OptionalDataException; -import java.util.ArrayList; - -import com.hippo.ehviewer.ListMangaDetail; -import com.hippo.ehviewer.ListUrls; - -import android.content.Context; -import android.content.SharedPreferences; - -public class Tag { - - private static final String SHA_PRE_NAME = "tag"; - private static final String LIST_ORDER = "list_order"; - - private static Context mContext; - private static SharedPreferences mTagPre; - private static ArrayList mListOrder = new ArrayList(); - private static ArrayList mTags = new ArrayList(); - - private static boolean mInit = false; - /** - * Init Tag - * - * @param context Application context - */ - public static void init(Context context) { - if (mInit) - return; - mInit = true; - - mContext = context; - mTagPre = mContext.getSharedPreferences(SHA_PRE_NAME, 0); - - getTag(); - } - - /** - * Is init - * @return True if init - */ - public static boolean isInit() { - return mInit; - } - - private static void getTag() { - String[] allOrder = Util.getStrings(mTagPre, LIST_ORDER); - - if (allOrder == null) - return; - - boolean errorFlag = false; - for (String item : allOrder) { - mListOrder.add(item); - String strTag = mTagPre.getString(item, null); - if (strTag == null) { - mListOrder.remove(strTag); - errorFlag = true; - continue; - } - mTags.add(decode(strTag)); - } - if (errorFlag) - Util.putStrings(mTagPre, LIST_ORDER, mListOrder); - } - - /** - * Add a new tag item to the end of tag list - * - * @param key - * @param tag - * @return - */ - public static boolean add(String key, ListUrls tag) { - // Check contain this item or not - if (mListOrder.indexOf(key) == -1) { - mListOrder.add(key); - mTags.add(tag); - Util.putStrings(mTagPre, LIST_ORDER, mListOrder); - mTagPre.edit().putString(key, encode(tag)).apply(); - return true; - } else - return false; - } - - /** - * Swap tag list order - * - * @param oldIndex - * @param newIndex - * @return - */ - public static boolean swap(int indexOne, int indexTwo) { - if (indexOne < 0 || indexOne > mListOrder.size() - || indexTwo < 0 || indexTwo > mListOrder.size()) - return false; - - if (indexOne == indexTwo) - return true; - - String temp1 = mListOrder.get(indexOne); - mListOrder.set(indexOne, mListOrder.get(indexTwo)); - mListOrder.set(indexTwo, temp1); - Util.putStrings(mTagPre, LIST_ORDER, mListOrder); - - ListUrls temp2 = mTags.get(indexOne); - mTags.set(indexOne, mTags.get(indexTwo)); - mTags.set(indexTwo, temp2); - return true; - } - - public static boolean contains(String key) { - return mListOrder.contains(key); - } - - /** - * Remove Tag item - * - * @param index - * @return True if remove successfully - */ - public static boolean remove(String key) { - int index = mListOrder.indexOf(key); - if (index != -1) { - mListOrder.remove(index); - mTags.remove(index); - mTagPre.edit().remove(key).apply(); - Util.putStrings(mTagPre, LIST_ORDER, mListOrder); - return true; - } else - return false; - } - - /** - * Remove Tag item - * - * @param index - * @return True if remove successfully - */ - public static boolean remove(int index) { - mTags.remove(index); - String key = mListOrder.remove(index); - mTagPre.edit().remove(key).apply(); - Util.putStrings(mTagPre, LIST_ORDER, mListOrder); - return true; - } - - public static ListUrls get(String key) { - int index = mListOrder.indexOf(key); - if (index == -1) - return null; - return mTags.get(index); - } - - public static ListUrls get(int position) { - return mTags.get(position); - } - - public static String getKey(int position) { - return mListOrder.get(position); - } - - public static void set(int position, String newKey, ListUrls listUrls) { - String oldKey = mListOrder.set(position, newKey); - mTags.set(position, listUrls); - - Util.putStrings(mTagPre, LIST_ORDER, mListOrder); - mTagPre.edit().remove(oldKey).putString(newKey, encode(listUrls)).apply(); - } - - public static void set(int position, ListUrls listUrls) { - mTags.set(position, listUrls); - mTagPre.edit().putString(mListOrder.get(position), encode(listUrls)).apply(); - } - - /** - * You must not modify what you get - * - * @return - */ - public static ArrayList getTagList() { - return mTags; - } - - /** - * You must not modify what you get - * - * @return - */ - public static ArrayList getKeyList() { - return mListOrder; - } - - public static void set(String oldKey, String newKey, ListUrls lus) { - int index = mListOrder.indexOf(oldKey); - if (index == -1) { - mListOrder.set(index, newKey); - mTags.set(index, lus); - } - } - - protected static String encode(ListUrls tag) { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - try { - ObjectOutputStream outputStream = new ObjectOutputStream(os); - writeObject(tag, outputStream); - } catch (Exception e) { - e.printStackTrace(); - return null; - } finally { - try { - os.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return Util.byteArrayToHexString(os.toByteArray()); - } - - protected static ListUrls decode(String strTag) { - byte[] bytes = Util.hexStringToByteArray(strTag); - ByteArrayInputStream is = new ByteArrayInputStream(bytes); - ListUrls tag = null; - try { - ObjectInputStream ois = new ObjectInputStream(is); - tag = readObject(ois); - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - is.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return tag; - } - - public static void writeObject(ListUrls tag, ObjectOutputStream out) throws IOException { - out.writeObject((Integer)tag.getType()); - out.writeObject(tag.getSearch()); - out.writeObject((Boolean)tag.isAdvance()); - out.writeObject((Integer)tag.getAdvanceType()); - out.writeObject((Boolean)tag.isMinRating()); - out.writeObject((Integer)tag.getMinRating()); - } - - public static ListUrls readObject(ObjectInputStream in) { - ListUrls tag = null; - try { - int type = (Integer)in.readObject(); - String search = (String)in.readObject(); - tag = new ListUrls(type, search); - - boolean isAdvance = (Boolean)in.readObject(); - int advanceType = (Integer)in.readObject(); - boolean isMinRating = (Boolean)in.readObject(); - int minRating = (Integer)in.readObject(); - if (isAdvance) { - if (isMinRating) - tag.setAdvance(advanceType, minRating); - else - tag.setAdvance(advanceType); - } - } catch (OptionalDataException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return tag; - } -} +package com.hippo.ehviewer.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OptionalDataException; +import java.util.ArrayList; + +import com.hippo.ehviewer.ListUrls; + +import android.content.Context; +import android.content.SharedPreferences; + +public class Tag { + + private static final String SHA_PRE_NAME = "tag"; + private static final String LIST_ORDER = "list_order"; + + private static Context mContext; + private static SharedPreferences mTagPre; + private static ArrayList mListOrder = new ArrayList(); + private static ArrayList mTags = new ArrayList(); + + private static boolean mInit = false; + /** + * Init Tag + * + * @param context Application context + */ + public static void init(Context context) { + if (mInit) + return; + mInit = true; + + mContext = context; + mTagPre = mContext.getSharedPreferences(SHA_PRE_NAME, 0); + + getTag(); + } + + /** + * Is init + * @return True if init + */ + public static boolean isInit() { + return mInit; + } + + private static void getTag() { + String[] allOrder = Util.getStrings(mTagPre, LIST_ORDER); + + if (allOrder == null) + return; + + boolean errorFlag = false; + for (String item : allOrder) { + mListOrder.add(item); + String strTag = mTagPre.getString(item, null); + if (strTag == null) { + mListOrder.remove(strTag); + errorFlag = true; + continue; + } + mTags.add(decode(strTag)); + } + if (errorFlag) + Util.putStrings(mTagPre, LIST_ORDER, mListOrder); + } + + /** + * Add a new tag item to the end of tag list + * + * @param key + * @param tag + * @return + */ + public static boolean add(String key, ListUrls tag) { + // Check contain this item or not + if (mListOrder.indexOf(key) == -1) { + mListOrder.add(key); + mTags.add(tag); + Util.putStrings(mTagPre, LIST_ORDER, mListOrder); + mTagPre.edit().putString(key, encode(tag)).apply(); + return true; + } else + return false; + } + + /** + * Swap tag list order + * + * @param oldIndex + * @param newIndex + * @return + */ + public static boolean swap(int indexOne, int indexTwo) { + if (indexOne < 0 || indexOne > mListOrder.size() + || indexTwo < 0 || indexTwo > mListOrder.size()) + return false; + + if (indexOne == indexTwo) + return true; + + String temp1 = mListOrder.get(indexOne); + mListOrder.set(indexOne, mListOrder.get(indexTwo)); + mListOrder.set(indexTwo, temp1); + Util.putStrings(mTagPre, LIST_ORDER, mListOrder); + + ListUrls temp2 = mTags.get(indexOne); + mTags.set(indexOne, mTags.get(indexTwo)); + mTags.set(indexTwo, temp2); + return true; + } + + public static boolean contains(String key) { + return mListOrder.contains(key); + } + + /** + * Remove Tag item + * + * @param index + * @return True if remove successfully + */ + public static boolean remove(String key) { + int index = mListOrder.indexOf(key); + if (index != -1) { + mListOrder.remove(index); + mTags.remove(index); + mTagPre.edit().remove(key).apply(); + Util.putStrings(mTagPre, LIST_ORDER, mListOrder); + return true; + } else + return false; + } + + /** + * Remove Tag item + * + * @param index + * @return True if remove successfully + */ + public static boolean remove(int index) { + mTags.remove(index); + String key = mListOrder.remove(index); + mTagPre.edit().remove(key).apply(); + Util.putStrings(mTagPre, LIST_ORDER, mListOrder); + return true; + } + + public static ListUrls get(String key) { + int index = mListOrder.indexOf(key); + if (index == -1) + return null; + return mTags.get(index); + } + + public static ListUrls get(int position) { + return mTags.get(position); + } + + public static String getKey(int position) { + return mListOrder.get(position); + } + + public static void set(int position, String newKey, ListUrls listUrls) { + String oldKey = mListOrder.set(position, newKey); + mTags.set(position, listUrls); + + Util.putStrings(mTagPre, LIST_ORDER, mListOrder); + mTagPre.edit().remove(oldKey).putString(newKey, encode(listUrls)).apply(); + } + + public static void set(int position, ListUrls listUrls) { + mTags.set(position, listUrls); + mTagPre.edit().putString(mListOrder.get(position), encode(listUrls)).apply(); + } + + /** + * You must not modify what you get + * + * @return + */ + public static ArrayList getTagList() { + return mTags; + } + + /** + * You must not modify what you get + * + * @return + */ + public static ArrayList getKeyList() { + return mListOrder; + } + + public static void set(String oldKey, String newKey, ListUrls lus) { + int index = mListOrder.indexOf(oldKey); + if (index == -1) { + mListOrder.set(index, newKey); + mTags.set(index, lus); + } + } + + protected static String encode(ListUrls tag) { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try { + ObjectOutputStream outputStream = new ObjectOutputStream(os); + writeObject(tag, outputStream); + } catch (Exception e) { + e.printStackTrace(); + return null; + } finally { + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return Util.byteArrayToHexString(os.toByteArray()); + } + + protected static ListUrls decode(String strTag) { + byte[] bytes = Util.hexStringToByteArray(strTag); + ByteArrayInputStream is = new ByteArrayInputStream(bytes); + ListUrls tag = null; + try { + ObjectInputStream ois = new ObjectInputStream(is); + tag = readObject(ois); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return tag; + } + + public static void writeObject(ListUrls tag, ObjectOutputStream out) throws IOException { + out.writeObject((Integer)tag.getType()); + out.writeObject(tag.getSearch()); + out.writeObject((Boolean)tag.isAdvance()); + out.writeObject((Integer)tag.getAdvanceType()); + out.writeObject((Boolean)tag.isMinRating()); + out.writeObject((Integer)tag.getMinRating()); + } + + public static ListUrls readObject(ObjectInputStream in) { + ListUrls tag = null; + try { + int type = (Integer)in.readObject(); + String search = (String)in.readObject(); + tag = new ListUrls(type, search); + + boolean isAdvance = (Boolean)in.readObject(); + int advanceType = (Integer)in.readObject(); + boolean isMinRating = (Boolean)in.readObject(); + int minRating = (Integer)in.readObject(); + if (isAdvance) { + if (isMinRating) + tag.setAdvance(advanceType, minRating); + else + tag.setAdvance(advanceType); + } + } catch (OptionalDataException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return tag; + } +} diff --git a/src/com/hippo/ehviewer/util/ThreadPool.java b/src/com/hippo/ehviewer/util/ThreadPool.java index 0f1b41d9e..694f71b1c 100644 --- a/src/com/hippo/ehviewer/util/ThreadPool.java +++ b/src/com/hippo/ehviewer/util/ThreadPool.java @@ -89,7 +89,7 @@ public class ThreadPool { initPoolSize, maxPoolSize, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue(), new PriorityThreadFactory("thread-pool", - android.os.Process.THREAD_PRIORITY_BACKGROUND)); + android.os.Process.THREAD_PRIORITY_DEFAULT)); } // Submit a job to the thread pool. The listener will be called when the diff --git a/src/com/hippo/ehviewer/util/Ui.java b/src/com/hippo/ehviewer/util/Ui.java index db69bf459..17c71e1a9 100644 --- a/src/com/hippo/ehviewer/util/Ui.java +++ b/src/com/hippo/ehviewer/util/Ui.java @@ -18,11 +18,12 @@ import android.widget.ImageView; public class Ui { //private static final String TAG = "Ui"; - private static final Ui INSTANCE = new Ui(); - private static Context mContext; private static final BitmapFactory.Options opt = new BitmapFactory.Options(); + public static final int HOLO_WHITE = 0xfff3f3f3; + + private static boolean mInit = false; /** @@ -40,6 +41,8 @@ public class Ui { opt.inPreferredConfig = Bitmap.Config.RGB_565; opt.inPurgeable = true; opt.inInputShareable = true; + + // init color } /** diff --git a/src/com/hippo/ehviewer/widget/LoadImageView.java b/src/com/hippo/ehviewer/widget/LoadImageView.java index 281f0da43..aea2d9523 100644 --- a/src/com/hippo/ehviewer/widget/LoadImageView.java +++ b/src/com/hippo/ehviewer/widget/LoadImageView.java @@ -6,7 +6,9 @@ import com.hippo.ehviewer.util.Ui; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.util.AttributeSet; @@ -79,17 +81,19 @@ public class LoadImageView extends ImageView { public void setContextImage(Bitmap bmp) { Drawable oldDrawable = getDrawable(); - - if (oldDrawable == null) - setImageBitmap(bmp); - else { - Drawable[] layers = new Drawable[2]; - layers[0] = oldDrawable; - layers[1] = new BitmapDrawable(getContext().getResources(), bmp); - TransitionDrawable transitionDrawable = new TransitionDrawable(layers); - setImageDrawable(transitionDrawable); - transitionDrawable.startTransition(DURATION); + if (oldDrawable == null) { + oldDrawable = new ColorDrawable(Ui.HOLO_WHITE); + oldDrawable.setBounds(0, 0, bmp.getWidth(), bmp.getHeight()); + } else if (oldDrawable instanceof TransitionDrawable){ + oldDrawable = ((TransitionDrawable)oldDrawable).getDrawable(1); } + + Drawable[] layers = new Drawable[2]; + layers[0] = oldDrawable; + layers[1] = new BitmapDrawable(getContext().getResources(), bmp); + TransitionDrawable transitionDrawable = new TransitionDrawable(layers); + setImageDrawable(transitionDrawable); + transitionDrawable.startTransition(DURATION); } class OnClickListener implements View.OnClickListener {