From 3c3dd4a7e2e725f2185ce1d69ec6eb1d8700e02d Mon Sep 17 00:00:00 2001 From: seven332 Date: Sun, 17 May 2015 00:51:58 +0800 Subject: [PATCH] Update --- .../java/com/hippo/ehviewer/Constants.java | 4 + .../com/hippo/ehviewer/client/EhClient.java | 70 +++++++- ...ListParser.java => GalleryListParser.java} | 2 +- .../hippo/ehviewer/client/PopularParser.java | 68 ++++++++ .../hippo/ehviewer/ui/ContentActivity.java | 59 ++++++- .../ehviewer/ui/scene/GalleryListScene.java | 160 +++++++++++++++--- .../java/com/hippo/ehviewer/util/EhUtils.java | 10 ++ .../ehviewer/widget/DrawerLeftPanel.java | 56 +++++- app/src/main/java/com/hippo/scene/Scene.java | 12 +- .../java/com/hippo/scene/SceneManager.java | 7 + .../main/java/com/hippo/util/FrescoUtils.java | 29 ++++ .../res/drawable-xhdpi/default_avatar.png | Bin 0 -> 1902 bytes .../res/drawable-xxhdpi/default_avatar.png | Bin 0 -> 2772 bytes app/src/main/res/values/strings.xml | 2 + 14 files changed, 438 insertions(+), 41 deletions(-) rename app/src/main/java/com/hippo/ehviewer/client/{ListParser.java => GalleryListParser.java} (99%) create mode 100644 app/src/main/java/com/hippo/ehviewer/client/PopularParser.java create mode 100644 app/src/main/java/com/hippo/util/FrescoUtils.java create mode 100644 app/src/main/res/drawable-xhdpi/default_avatar.png create mode 100644 app/src/main/res/drawable-xxhdpi/default_avatar.png diff --git a/app/src/main/java/com/hippo/ehviewer/Constants.java b/app/src/main/java/com/hippo/ehviewer/Constants.java index e8aabf056..50225142c 100644 --- a/app/src/main/java/com/hippo/ehviewer/Constants.java +++ b/app/src/main/java/com/hippo/ehviewer/Constants.java @@ -21,10 +21,14 @@ public final class Constants { public static final int MESSENGER_ID_EH_SOURCE; public static final int MESSENGER_ID_SHOW_APP_STATUS; + public static final int MESSENGER_ID_SIGN_IN_OR_OUT; + public static final int MESSENGER_ID_USER_AVATAR; static { Messenger messenger = Messenger.getInstance(); MESSENGER_ID_EH_SOURCE = messenger.newId(); MESSENGER_ID_SHOW_APP_STATUS = messenger.newId(); + MESSENGER_ID_SIGN_IN_OR_OUT = messenger.newId(); + MESSENGER_ID_USER_AVATAR = messenger.newId(); } } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java index ac83497e1..cd65830e3 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java @@ -23,6 +23,8 @@ import com.hippo.ehviewer.network.EhHttpHelper; import com.hippo.network.ResponseCodeException; import com.hippo.util.PriorityThreadFactory; +import org.json.JSONObject; + import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -30,6 +32,7 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +@SuppressWarnings("unchecked") public final class EhClient { @SuppressWarnings("unused") @@ -107,10 +110,6 @@ public final class EhClient { void onFailure(Exception e); } - public abstract static class OnGetGalleryListListener implements EhClientListener { - public abstract void onSuccess(List glList, int pageNum); - } - private void doBgJob(BgJobHelper bjh) { new AsyncTask() { @Override @@ -165,7 +164,6 @@ public final class EhClient { public abstract void doBgJob() throws Exception; public abstract void doSuccessCallback(); - } private void checkRequest(EhHttpHelper ehh) throws ResponseCodeException { @@ -176,16 +174,21 @@ public final class EhClient { } private Object[] doGetGalleryList(int source, String url) throws Exception { - EhHttpHelper ehh = new EhHttpHelper(); + EhHttpHelper ehh = EhHttpHelper.obtain(); String body = ehh.get(url); checkRequest(ehh); + EhHttpHelper.recycle(ehh); - ListParser parser = new ListParser(); + GalleryListParser parser = new GalleryListParser(); parser.parse(body, source); return new Object[]{parser.giList, parser.pageNum}; } + public abstract static class OnGetGalleryListListener implements EhClientListener { + public abstract void onSuccess(List glList, int pageNum); + } + private final class GetGalleryListHelper extends SimpleBgJobHelper { private int mSource; @@ -227,4 +230,57 @@ public final class EhClient { doBgJob(new GetGalleryListHelper(source, url, listener)); } + private Object[] doGetPopular() throws Exception { + final JSONObject json = new JSONObject(); + json.put("method", "popular"); + + EhHttpHelper ehh = EhHttpHelper.obtain(); + String body = ehh.postJson(API_EHVIEWER, json); + + checkRequest(ehh); + EhHttpHelper.recycle(ehh); + + PopularParser parser = new PopularParser(); + parser.parse(body); + return new Object[]{parser.galleryInfoList, parser.timeStamp}; + } + + public abstract static class OnGetPopularListener implements EhClientListener { + public abstract void onSuccess(List giList, long timeStamp); + } + + + private final class GetPopularHelper extends SimpleBgJobHelper { + + private OnGetPopularListener mListener; + + private List mGiList; + private long mTimeStamp; + + public GetPopularHelper(OnGetPopularListener listener) { + super(listener); + mListener = listener; + } + + @Override + public void doBgJob() throws Exception { + Object[] objs = doGetPopular(); + mGiList = (List) objs[0]; + mTimeStamp = (Long) objs[1]; + } + + @Override + public void doSuccessCallback() { + mListener.onSuccess(mGiList, mTimeStamp); + } + } + + /** + * Get popular gallery list + * + * @param listener the listener for callback + */ + public void getPopular(OnGetPopularListener listener) { + doBgJob(new GetPopularHelper(listener)); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/client/ListParser.java b/app/src/main/java/com/hippo/ehviewer/client/GalleryListParser.java similarity index 99% rename from app/src/main/java/com/hippo/ehviewer/client/ListParser.java rename to app/src/main/java/com/hippo/ehviewer/client/GalleryListParser.java index 3743a5f70..f233974a0 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/ListParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/GalleryListParser.java @@ -27,7 +27,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class ListParser { +public class GalleryListParser { private static final String PARSE_MESSAGE = "Gallery list parser error"; private static final int DEFAULT_LIST_SIZE = 25; diff --git a/app/src/main/java/com/hippo/ehviewer/client/PopularParser.java b/app/src/main/java/com/hippo/ehviewer/client/PopularParser.java new file mode 100644 index 000000000..97ba63402 --- /dev/null +++ b/app/src/main/java/com/hippo/ehviewer/client/PopularParser.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2015 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 + * 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.client; + +import com.hippo.ehviewer.data.GalleryInfo; +import com.hippo.ehviewer.util.EhUtils; +import com.hippo.util.Utils; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class PopularParser { + + public List galleryInfoList; + public long timeStamp; + + public void parse(String body) throws Exception { + galleryInfoList = new ArrayList<>(); + JSONObject js = new JSONObject(body); + js = js.getJSONObject("popular"); + + if (!js.has("galleries")) { + if (js.has("error")) { + throw new EhException(js.getString("error")); + } else { + throw new EhException("Parser error"); // TODO + } + } + + JSONArray ja = js.getJSONArray("galleries"); + for (int i = 0; i < ja.length(); i++) { + JSONObject j = ja.getJSONObject(i); + GalleryInfo gi = new GalleryInfo(); + gi.gid = j.getInt("gid"); + gi.token = j.getString("token"); + gi.title = Utils.unescapeXml(j.getString("title")); + gi.posted = EhUtils.formatPostDate(Long.parseLong(j.getString("posted")) * 1000); + gi.thumb = j.getString("thumb"); + gi.category = EhUtils.getCategory(j.getString("category")); + gi.uploader = j.getString("uploader"); + gi.rating = Float.parseFloat(j.getString("rating")); + gi.generateSLang(); + galleryInfoList.add(gi); + } + + if (js.has("time")) { + timeStamp = js.getLong("time"); + } else { + timeStamp = -1; + } + } +} diff --git a/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java index d89af7189..429e87b99 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/ContentActivity.java @@ -23,6 +23,8 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.widget.DrawerLayout; import android.view.Gravity; +import android.view.View; +import android.widget.AdapterView; import com.hippo.content.VectorContext; import com.hippo.ehviewer.R; @@ -30,6 +32,7 @@ import com.hippo.ehviewer.ui.scene.GalleryListScene; import com.hippo.ehviewer.util.Config; import com.hippo.ehviewer.widget.DrawerLeftPanel; import com.hippo.ehviewer.widget.StatusBarLayout; +import com.hippo.scene.Announcer; import com.hippo.scene.StageActivity; import com.hippo.scene.StageLayout; import com.hippo.widget.DrawerListView; @@ -37,6 +40,14 @@ import com.hippo.widget.DrawerListView; public class ContentActivity extends StageActivity implements StatusBarLayout.OnGetFitPaddingBottomListener { + public static final int DRAWER_LIST_NONE = -1; + public static final int DRAWER_LIST_HOMEPAGE = 0; + public static final int DRAWER_LIST_WHATS_HOT = 1; + public static final int DRAWER_LIST_HISTORY = 2; + public static final int DRAWER_LIST_FAVORITE = 3; + public static final int DRAWER_LIST_DOWNLOAD = 4; + public static final int DRAWER_LIST_SETTINGS = 5; + private Resources mResources; private DrawerLayout mDrawerLayout; @@ -45,11 +56,43 @@ public class ContentActivity extends StageActivity private DrawerLeftPanel mDrawerLeftPanel; private DrawerListView mDrawerListView; + private AdapterView.OnItemClickListener mDrawerListListener = new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (mDrawerListView.getActivatedPosition() != position) { + Announcer announcer; + switch (position) { + case DRAWER_LIST_HOMEPAGE: + announcer = new Announcer(); + announcer.putExtra(GalleryListScene.KEY_MODE, GalleryListScene.MODE_HOMEPAGE); + startScene(GalleryListScene.class, announcer); + break; + case DRAWER_LIST_WHATS_HOT: + announcer = new Announcer(); + announcer.putExtra(GalleryListScene.KEY_MODE, GalleryListScene.MODE_POPULAR); + startScene(GalleryListScene.class, announcer); + break; + case DRAWER_LIST_HISTORY: + break; + case DRAWER_LIST_FAVORITE: + break; + case DRAWER_LIST_DOWNLOAD: + break; + case DRAWER_LIST_SETTINGS: + break; + } + + mDrawerLayout.closeDrawers(); + } + } + }; + @Override protected boolean isShowStats() { return Config.getShowApplicationStats(); } + @SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,11 +126,11 @@ public class ContentActivity extends StageActivity mResources.getString(R.string.settings) }; mDrawerListView.setData(drawerListDrawables, drawerListStrings); + mDrawerListView.setOnItemClickListener(mDrawerListListener); // First time if (savedInstanceState == null) { startScene(GalleryListScene.class, null); - mDrawerListView.setActivatedPosition(0); } } @@ -101,6 +144,20 @@ public class ContentActivity extends StageActivity super.attachBaseContext(VectorContext.wrapContext(newBase)); } + @SuppressLint("RtlHardcoded") + @Override + public void onBackPressed() { + if (mDrawerLayout.isDrawerOpen(Gravity.LEFT) || mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) { + mDrawerLayout.closeDrawers(); + } else { + super.onBackPressed(); + } + } + + public void setDrawerListActivatedPosition(int position) { + mDrawerListView.setActivatedPosition(position); + } + @SuppressLint("RtlHardcoded") public void toggleDrawer() { if (mDrawerLayout.isDrawerOpen(Gravity.LEFT) || mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java index 9d567e374..dbe2793db 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryListScene.java @@ -47,7 +47,7 @@ import com.hippo.drawable.AddDeleteDrawable; import com.hippo.effect.ViewTransition; import com.hippo.ehviewer.R; import com.hippo.ehviewer.client.EhClient; -import com.hippo.ehviewer.client.ListParser; +import com.hippo.ehviewer.client.GalleryListParser; import com.hippo.ehviewer.data.GalleryInfo; import com.hippo.ehviewer.data.ListUrlBuilder; import com.hippo.ehviewer.data.UnsupportedSearchException; @@ -60,6 +60,7 @@ import com.hippo.ehviewer.widget.RatingView; import com.hippo.ehviewer.widget.SearchBar; import com.hippo.ehviewer.widget.SearchDatabase; import com.hippo.ehviewer.widget.SearchLayout; +import com.hippo.scene.Announcer; import com.hippo.scene.Scene; import com.hippo.scene.SimpleDialog; import com.hippo.util.AnimationUtils; @@ -79,6 +80,11 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, View.OnClickListener, FabLayout.OnCancelListener, SearchLayout.SearhLayoutHelper { + public static final String KEY_MODE = "mode"; + + public static final int MODE_HOMEPAGE = 0; + public static final int MODE_POPULAR = 1; + private static final long ANIMATE_TIME = 300l; private final static int STATE_NORMAL = 0; @@ -179,6 +185,11 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, } }; + @Override + public int getLaunchMode() { + return LAUNCH_MODE_SINGLE_TOP; + } + @Override protected void onReplace(@NonNull Scene oldScene) { super.onReplace(oldScene); @@ -188,6 +199,39 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, .newInstance(getStageActivity()); } + private void handleAnnouncer(Announcer announcer) { + int mode = MODE_HOMEPAGE; + if (announcer != null) { + mode = announcer.getIntExtra(KEY_MODE, MODE_HOMEPAGE); + } + + switch (mode) { + default: + case MODE_HOMEPAGE: + mActivity.setDrawerListActivatedPosition(ContentActivity.DRAWER_LIST_HOMEPAGE); + mListUrlBuilder.setMode(ListUrlBuilder.MODE_NORMAL); + break; + case MODE_POPULAR: + mActivity.setDrawerListActivatedPosition(ContentActivity.DRAWER_LIST_WHATS_HOT); + mListUrlBuilder.setMode(ListUrlBuilder.MODE_POPULAR); + break; + } + + if (announcer == null) { + mGalleryListHelper.firstRefresh(); + } else { + showSearchBar(true); + mGalleryListHelper.refresh(); + } + } + + @Override + protected void onNewAnnouncer(Announcer announcer) { + super.onNewAnnouncer(announcer); + + handleAnnouncer(announcer); + } + @SuppressWarnings("deprecation") @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -223,8 +267,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, ViewUtils.removeOnGlobalLayoutListener(mSearchBar.getViewTreeObserver(), this); mSearchBarOriginalTop = mSearchBar.getTop(); mSearchBarOriginalBottom = mSearchBar.getBottom(); - int fitPaddingTop = mSearchBar.getHeight() + - mResources.getDimensionPixelOffset(R.dimen.search_bar_padding_vertical); + int fitPaddingTop = mSearchBar.getHeight() + mResources.getDimensionPixelOffset(R.dimen.search_bar_padding_vertical); mContentLayout.setFitPaddingTop(fitPaddingTop); mSearchLayout.setFitPaddingTop(fitPaddingTop); } @@ -255,7 +298,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, // When scene start if (savedInstanceState == null) { - mGalleryListHelper.firstRefresh(); + handleAnnouncer(getAnnouncer()); } } @@ -447,6 +490,8 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, return; } + mActivity.setDrawerListActivatedPosition(ContentActivity.DRAWER_LIST_NONE); + mSearchDatabase.addQuery(query); if (mViewTransition.getShownViewIndex() == 0) { @@ -463,7 +508,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, mState = STATE_NORMAL; mViewTransition.showView(0); mSearchBar.setState(SearchBar.STATE_NORMAL); - returnSearchBarPosition(); + showSearchBar(true); setFabState(FAB_STATE_NORMAL); mGalleryListHelper.refresh(); @@ -486,17 +531,19 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, int offset = mSearchBarOriginalTop - mSearchBar.getTop(); if (offset != 0) { if (animation) { + final boolean needRequestLayout = mSearchBar.getBottom() <= 0 && offset > 0; final ValueAnimator va = ValueAnimator.ofInt(0, offset); va.setDuration(ANIMATE_TIME); va.addListener(new SimpleAnimatorListener() { @Override - public void onAnimationEnd(Animator animation) { + public void onAnimationEnd(Animator animation, boolean canceled) { + super.onAnimationEnd(animation, canceled); mSearchBarMoveAnimator = null; } }); va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { int lastValue; - + boolean hasRequestLayout; @Override public void onAnimationUpdate(ValueAnimator animation) { int value = (Integer) animation.getAnimatedValue(); @@ -504,8 +551,16 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, lastValue = value; mSearchBar.offsetTopAndBottom(offsetStep); ((OffsetLayout.LayoutParams) mSearchBar.getLayoutParams()).offsetY += offsetStep; + + if (!hasRequestLayout && needRequestLayout && mSearchBar.getBottom() > 0) { + hasRequestLayout = true; + mSearchBar.requestLayout(); + } } }); + if (mSearchBarMoveAnimator != null) { + mSearchBarMoveAnimator.cancel(); + } mSearchBarMoveAnimator = va; va.start(); } else { @@ -646,7 +701,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, private LayoutInflater mInflater; - private GalleryListListener mLastGalleryListListener; + private GalleryListHelperSettable mListener; private Runnable mSearchBarPositionTask = new Runnable() { @Override @@ -663,9 +718,9 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, private GalleryListHelper(Context context, GalleryListHelper oldContentHelper) { super(context, oldContentHelper); // Update gallery listener - mLastGalleryListListener = oldContentHelper.mLastGalleryListListener; - if (mLastGalleryListListener != null) { - mLastGalleryListListener.setGalleryListHelper(this); + mListener = oldContentHelper.mListener; + if (mListener != null) { + mListener.setGalleryListHelper(this); } init(); } @@ -678,9 +733,9 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, mInflater = mActivity.getLayoutInflater(); } - private void clearLastGalleryListListener(GalleryListListener listener) { - if (mLastGalleryListListener == listener) { - mLastGalleryListListener = null; + private void clearLastGalleryListHelperSettable(GalleryListHelperSettable listener) { + if (mListener == listener) { + mListener = null; } } @@ -708,17 +763,25 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, @Override protected void getPageData(int taskId, int type, int page) { - try { - int source = Config.getEhSource(); - mListUrlBuilder.setPageIndex(page); - String url = mListUrlBuilder.build(source); - GalleryListListener listener = new GalleryListListener(taskId, type, - page, source); + int mode = mListUrlBuilder.getMode(); + if (mode == ListUrlBuilder.MODE_POPULAR) { + PopularListener listener = new PopularListener(taskId); listener.setGalleryListHelper(this); - mLastGalleryListListener = listener; - EhClient.getInstance().getGalleryList(source, url, listener); - } catch (UnsupportedSearchException e) { - onGetPageData(taskId, e); + mListener = listener; + EhClient.getInstance().getPopular(listener); + } else { + try { + int source = Config.getEhSource(); + mListUrlBuilder.setPageIndex(page); + String url = mListUrlBuilder.build(source); + GalleryListListener listener = new GalleryListListener(taskId, + type, page, source); + listener.setGalleryListHelper(this); + mListener = listener; + EhClient.getInstance().getGalleryList(source, url, listener); + } catch (UnsupportedSearchException e) { + onGetPageData(taskId, e); + } } } @@ -746,7 +809,8 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, } } - private static class GalleryListListener extends EhClient.OnGetGalleryListListener { + private static class GalleryListListener extends EhClient.OnGetGalleryListListener + implements GalleryListHelperSettable { private int mTaskId; private int mTaskType; @@ -762,6 +826,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, mSource = source; } + @Override public void setGalleryListHelper(GalleryListHelper helper) { mHelper = helper; } @@ -770,7 +835,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, public void onSuccess(List glList, int pageNum) { if (mHelper != null) { if (mSource == EhClient.SOURCE_LOFI) { - if (pageNum == ListParser.CURRENT_PAGE_IS_LAST) { + if (pageNum == GalleryListParser.CURRENT_PAGE_IS_LAST) { mHelper.setPageSize(mTargetPage); } else if (mTaskType == ContentLayout.ContentHelper.TYPE_REFRESH) { mHelper.setPageSize(Integer.MAX_VALUE); @@ -780,7 +845,7 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, } mHelper.onGetPageData(mTaskId, glList); - mHelper.clearLastGalleryListListener(this); + mHelper.clearLastGalleryListHelperSettable(this); } } @@ -789,8 +854,47 @@ public class GalleryListScene extends Scene implements SearchBar.Helper, if (mHelper != null) { mHelper.onGetPageData(mTaskId, e); - mHelper.clearLastGalleryListListener(this); + mHelper.clearLastGalleryListHelperSettable(this); } } } + + private static class PopularListener extends EhClient.OnGetPopularListener + implements GalleryListHelperSettable { + + private int mTaskId; + private GalleryListHelper mHelper; + + public PopularListener(int taskId) { + mTaskId = taskId; + } + + @Override + public void setGalleryListHelper(GalleryListHelper helper) { + mHelper = helper; + } + + @Override + public void onSuccess(List glList, long timeStamp) { + if (mHelper != null) { + mHelper.setPageSize(1); + mHelper.onGetPageData(mTaskId, glList); + + mHelper.clearLastGalleryListHelperSettable(this); + } + } + + @Override + public void onFailure(Exception e) { + if (mHelper != null) { + mHelper.onGetPageData(mTaskId, e); + + mHelper.clearLastGalleryListHelperSettable(this); + } + } + } + + private interface GalleryListHelperSettable { + void setGalleryListHelper(GalleryListHelper helper); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java b/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java index b0a8aeb1b..450bdf25e 100644 --- a/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java +++ b/app/src/main/java/com/hippo/ehviewer/util/EhUtils.java @@ -17,8 +17,14 @@ package com.hippo.ehviewer.util; import android.graphics.Color; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Locale; + public final class EhUtils { + public static final DateFormat POST_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); + public static final String EH_DOWNLOAD_FILENAME = ".ehviewer"; public static final int NONE = -1; // Use it for homepage @@ -119,4 +125,8 @@ public final class EhUtils { return BG_COLOR_UNKNOWN; } } + + public static String formatPostDate(long date) { + return POST_DATE_FORMAT.format(date); + } } diff --git a/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java b/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java index f8951195f..18c1d504f 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/DrawerLeftPanel.java @@ -18,6 +18,7 @@ package com.hippo.ehviewer.widget; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Rect; +import android.net.Uri; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -30,7 +31,10 @@ import android.widget.TextView; import com.facebook.drawee.view.SimpleDraweeView; import com.hippo.effect.ripple.RippleSalon; +import com.hippo.ehviewer.Constants; import com.hippo.ehviewer.R; +import com.hippo.util.FrescoUtils; +import com.hippo.util.Messenger; import com.hippo.widget.DrawerListView; public class DrawerLeftPanel extends LinearLayout { @@ -40,6 +44,8 @@ public class DrawerLeftPanel extends LinearLayout { private static final int[] MAX_ATTRS = {android.R.attr.maxWidth}; + private static Uri DEFAULT_AVATAR_URI = FrescoUtils.getResourcesDrawableUri(R.drawable.default_avatar); + private int mMaxWidth = -1; private ViewGroup mSuperUserPanel; @@ -57,6 +63,32 @@ public class DrawerLeftPanel extends LinearLayout { private int mUserPanelOriginalPaddingTop; private int mDrawerListViewOriginalPaddingBottom; + private boolean mSignIn; + + private Messenger.Receiver mMessengerReceiver = new Messenger.Receiver() { + @Override + public void onReceive(int id, Object obj) { + if (id == Constants.MESSENGER_ID_SIGN_IN_OR_OUT) { + if (obj == null) { + // Sign out + mSignIn = false; + mAvatar.setImageURI(DEFAULT_AVATAR_URI); + mUsename.setText(""); + mAction.setText(mContext.getString(R.string.signin)); + } else if (obj instanceof String) { + // Sign in + mSignIn = true; + mUsename.setText((String) obj); + mAction.setText(mContext.getString(R.string.signout)); + } + } else if (id == Constants.MESSENGER_ID_USER_AVATAR) { + if (mSignIn && obj instanceof Uri) { + mAvatar.setImageURI((Uri) obj); + } + } + } + }; + public DrawerLeftPanel(Context context, AttributeSet attrs) { super(context, attrs); init(context, attrs); @@ -86,9 +118,9 @@ public class DrawerLeftPanel extends LinearLayout { RippleSalon.addRipple(mAction, false); - mAvatar.getHierarchy().setPlaceholderImage(R.drawable.theme_primary); - mUsename.setText("速度速度加快"); - mAction.setText("退出"); + mAvatar.setImageURI(DEFAULT_AVATAR_URI); + mUsename.setText(""); + mAction.setText(mContext.getString(R.string.signin)); mSuperUserPanelHeight = mSuperUserPanel.getLayoutParams().height; mUserPanelOriginalPaddingTop = mUserPanel.getPaddingTop(); @@ -99,6 +131,24 @@ public class DrawerLeftPanel extends LinearLayout { return mDrawerListView; } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + + Messenger.getInstance().register(Constants.MESSENGER_ID_SIGN_IN_OR_OUT, mMessengerReceiver); + Messenger.getInstance().register(Constants.MESSENGER_ID_USER_AVATAR, mMessengerReceiver); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + + Messenger.getInstance().unregister(Constants.MESSENGER_ID_SIGN_IN_OR_OUT, mMessengerReceiver); + Messenger.getInstance().register(Constants.MESSENGER_ID_USER_AVATAR, mMessengerReceiver); + } + + + @Override public Parcelable onSaveInstanceState() { final Bundle state = new Bundle(); diff --git a/app/src/main/java/com/hippo/scene/Scene.java b/app/src/main/java/com/hippo/scene/Scene.java index 5fdfdda6d..623f8166d 100644 --- a/app/src/main/java/com/hippo/scene/Scene.java +++ b/app/src/main/java/com/hippo/scene/Scene.java @@ -40,6 +40,9 @@ import com.hippo.util.ViewUtils; */ public abstract class Scene { + public static final int LAUNCH_MODE_STANDARD = 0; + public static final int LAUNCH_MODE_SINGLE_TOP = 1; + static final int SCENE_STATE_CREATE = 0; static final int SCENE_STATE_RUN = 1; static final int SCENE_STATE_DESTROY = 2; @@ -86,7 +89,7 @@ public abstract class Scene { return mCurtain; } - @Nullable Announcer getAnnouncer() { + public @Nullable Announcer getAnnouncer() { return mAnnouncer; } @@ -97,6 +100,10 @@ public abstract class Scene { return stageActivity; } + public int getLaunchMode() { + return LAUNCH_MODE_STANDARD; + } + /** * You will get null before onCreate and after onDestroy mostly * @@ -257,6 +264,9 @@ public abstract class Scene { mCurtain = oldScene.mCurtain; } + protected void onNewAnnouncer(Announcer announcer) { + } + /** * It will be called if nav bar is transparent. * @param b the nav bar's height diff --git a/app/src/main/java/com/hippo/scene/SceneManager.java b/app/src/main/java/com/hippo/scene/SceneManager.java index 3692b1701..1c6e232ce 100644 --- a/app/src/main/java/com/hippo/scene/SceneManager.java +++ b/app/src/main/java/com/hippo/scene/SceneManager.java @@ -76,6 +76,13 @@ class SceneManager { return; } + Scene topScene = getTopState(); + if (sceneClass.isInstance(topScene) && + topScene.getLaunchMode() == Scene.LAUNCH_MODE_SINGLE_TOP) { + topScene.onNewAnnouncer(announcer); + return; + } + Scene scene = createSceneByClass(sceneClass); scene.setAnnouncer(announcer); scene.setCurtain(curtain); diff --git a/app/src/main/java/com/hippo/util/FrescoUtils.java b/app/src/main/java/com/hippo/util/FrescoUtils.java new file mode 100644 index 000000000..29339c1ba --- /dev/null +++ b/app/src/main/java/com/hippo/util/FrescoUtils.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 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 + * 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.util; + +import android.annotation.IdRes; +import android.net.Uri; + +import com.facebook.common.util.UriUtil; + +public class FrescoUtils { + + public static Uri getResourcesDrawableUri(@IdRes int resId) { + return new Uri.Builder().scheme(UriUtil.LOCAL_RESOURCE_SCHEME) + .path(String.valueOf(resId)).build(); + } +} diff --git a/app/src/main/res/drawable-xhdpi/default_avatar.png b/app/src/main/res/drawable-xhdpi/default_avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..144578112784751f4f50f5054aba1ad1d15a8118 GIT binary patch literal 1902 zcmbW2`6JU01IIsRnEQB=W6BaSBo$HOnJYwSOLAn$m>e@Xn>m(Yn38fYLP>==*IX-1 zVc*ObiE>4bZ=~dAJf1(``Q`cH{eHb)f5DsLXm2Ghq9_6YfVhpd1@eIL{|y9m(01tOHWkZRyp$3@u~t86S?PRp52yfKDw*Yg)|_NH35gDR{G&gra^{?;n;${zVnH%g}E(Oin=NSxrD^DV4p;`qjn zZ}P0LoQd>{MR?IM7yv4U!~+^27?27;;#K~q_Ar5?yB#-{;W@HG=Qo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)Cxz*x@?Zv%VJ4o0fb8kg1Ke(i#^>|X% zK4kw3tW(r-q3;U7`drvRPB4Xz8b!f4$U( z5EAzxOpSW;($Z37$GwD!k&z1j^VsF+!fbsNCxE*P4%Okeb6OZS|F*H1UR&(m+K+uQ zcuES+&)qgAUPg6a6Pz@dvJd+xYJUB@2<=S#>p05Sr^xdme`K3S?LN8g_aR*jWr3(( zO@+&2I%UrzX0?8@7jfmY^uad_TfF_TI9sU4jE+Vs?ocXJ{iQ^$eOac^Pvabgc%N>E zyY|)E<=XNE*=oLMN-nWs=W>}|=T1cIxh~ZTc+n-3S`}lFmuIwyL*KggNKu(q!QVX^ z4BnE&a_lr@HJK6Jm(>3aTec|e$SX%@(Z|f)UTh&p9J1_Wgtr{zKU^xW{Y@Vv_h=3@ zlX@u?C((cVq&|*hq93H&|C9^FhGl>~FR@@yS`7~rHRmbl!$5O=!jKBbft__xu%|Z* zkVnE*;$JJ!z7bFFNh-P==92>W9Ki_S(7~_-zzFI8OAS%`!ny#)DHs(oo;-PQpn#2~ Ky+xIoC+R;n+Isf@ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/default_avatar.png b/app/src/main/res/drawable-xxhdpi/default_avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..55448328fce89a814cb1dd6112fc08461582ce3c GIT binary patch literal 2772 zcma);XEYlM8^<-Znj+NRvsTMBimIy6s8xGJt7=QDB8aM+P>q_`)+n)JUQ~tDsv=ZN zh*5jis9C$jsD0i0-uImM!@E8_i)iA* zCXbnO>>@VkULAIR1JCo79-isgQsLBUK5Z7de#w((3^l8r@^#A8?oJKmQwPS;w_N_P z=hU00u!YP5$o_PyPUO8IUv^d?M4B}R91395!7$Q^aYUMl==?1JA^#LGjDI=)ww^iu zVf{~82*6Mx$i81ohJ7(P79?BRRlE@j;H_Bv88uIy%7k7*$k+)l5S%Yw;Tyirfdigx=>pOT>@ww}gCk)I+T752J;vE$&xqXM`9?g!CstSF1qsaU(FpwmO!6l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