From 875509be6832859fce32bfd1c45d10aca48336de Mon Sep 17 00:00:00 2001 From: seven332 Date: Sat, 6 Feb 2016 15:02:44 +0800 Subject: [PATCH] Add comment gallery, add Announcer --- .../com/hippo/ehviewer/client/EhClient.java | 14 + .../com/hippo/ehviewer/client/EhEngine.java | 30 +++ .../com/hippo/ehviewer/ui/MainActivity.java | 11 +- .../ui/scene/GalleryCommentsScene.java | 247 +++++++++++++++++- .../ehviewer/ui/scene/GalleryDetailScene.java | 7 +- .../ehviewer/ui/scene/GalleryListScene.java | 9 +- .../hippo/ehviewer/ui/scene/LoginScene.java | 3 +- .../hippo/ehviewer/ui/scene/WarningScene.java | 5 +- .../main/java/com/hippo/scene/Announcer.java | 52 ++++ .../java/com/hippo/scene/SceneFragment.java | 22 +- .../java/com/hippo/scene/StageActivity.java | 24 +- .../java/com/hippo/util/ActivityHelper.java | 24 ++ app/src/main/res/drawable/ic_send.xml | 29 ++ app/src/main/res/drawable/shadow_top.xml | 27 ++ .../res/layout/scene_gallery_comments.xml | 39 +++ app/src/main/res/values/pathdata.xml | 1 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/themes.xml | 6 + 18 files changed, 497 insertions(+), 55 deletions(-) create mode 100644 app/src/main/java/com/hippo/scene/Announcer.java create mode 100644 app/src/main/res/drawable/ic_send.xml create mode 100644 app/src/main/res/drawable/shadow_top.xml 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 ac3cc2afe..30e92eeda 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java @@ -42,6 +42,7 @@ public class EhClient { public static final int METHOD_GET_GALLERY_DETAIL = 2; public static final int METHOD_GET_LARGE_PREVIEW_SET = 3; public static final int METHOD_GET_RATE_GALLERY = 4; + public static final int METHOD_GET_COMMENT_GALLERY = 5; private final ThreadPoolExecutor mRequestThreadPool; private final OkHttpClient mOkHttpClient; @@ -161,6 +162,17 @@ public class EhClient { } } + private Object commentGallery(EhConfig ehConfig, Object... params) throws Exception { + Call call = EhEngine.prepareCommentGallery(mOkHttpClient, ehConfig, + (String) params[0], (String) params[1]); + if (!mStop) { + mCall = call; + return EhEngine.doCommentGallery(call); + } else { + throw new CancelledException(); + } + } + @Override protected Object doInBackground(Object... params) { try { @@ -175,6 +187,8 @@ public class EhClient { return getLargePreviewSet(mEhConfig, params); case METHOD_GET_RATE_GALLERY: return rateGallery(mEhConfig, params); + case METHOD_GET_COMMENT_GALLERY: + return commentGallery(mEhConfig, params); default: return new IllegalStateException("Can't detect method " + mMethod); } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java index 2f5ada70f..dd83e570b 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java @@ -20,6 +20,7 @@ import android.support.annotation.Nullable; import android.util.Log; import android.util.Pair; +import com.hippo.ehviewer.client.data.GalleryComment; import com.hippo.ehviewer.client.data.GalleryDetail; import com.hippo.ehviewer.client.data.GalleryInfo; import com.hippo.ehviewer.client.data.LargePreviewSet; @@ -312,5 +313,34 @@ public class EhEngine { } } + public static Call prepareCommentGallery(OkHttpClient okHttpClient, + EhConfig ehConfig, String url, String comment) { + FormBody.Builder builder = new FormBody.Builder() + .add("commenttext", comment) + .add("postcomment", "Post New"); + + Log.d(TAG, url); + Request request = new EhRequestBuilder(url, ehConfig) + .post(builder.build()) + .build(); + return okHttpClient.newCall(request); + } + + public static GalleryComment[] doCommentGallery(Call call) throws Exception { + String body = null; + Headers headers = null; + int code = -1; + try { + Response response = call.execute(); + code = response.code(); + headers = response.headers(); + body = response.body().string(); + return GalleryDetailParser.parseComment(body); + } catch (Exception e) { + throwException(call, code, headers, body, e); + throw e; + } + } + // TODO Add get gallery api info } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java index 9fce17ff7..cf638aefe 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/MainActivity.java @@ -32,6 +32,7 @@ import com.hippo.ehviewer.client.EhUtils; import com.hippo.ehviewer.ui.scene.GalleryListScene; import com.hippo.ehviewer.ui.scene.LoginScene; import com.hippo.ehviewer.ui.scene.WarningScene; +import com.hippo.scene.Announcer; import com.hippo.scene.SceneFragment; import com.hippo.scene.StageActivity; @@ -69,15 +70,15 @@ public final class MainActivity extends StageActivity private void onInit() { if (Settings.getShowWarning()) { setDrawerLayoutEnable(false); - startScene(WarningScene.class); + startScene(new Announcer(WarningScene.class)); } else if (!EhUtils.hasSignedIn(this)) { setDrawerLayoutEnable(false); - startScene(LoginScene.class); + startScene(new Announcer(LoginScene.class)); } else { setDrawerLayoutEnable(true); Bundle args = new Bundle(); args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE); - startScene(GalleryListScene.class, args); + startScene(new Announcer(GalleryListScene.class).setArgs(args)); } } @@ -144,7 +145,9 @@ public final class MainActivity extends StageActivity if (id == R.id.nav_homepage) { Bundle args = new Bundle(); args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE); - startScene(GalleryListScene.class, args, null, SceneFragment.FLAG_REMOVE_ALL_THE_OTHER_SCENES); + startScene(new Announcer(GalleryListScene.class) + .setArgs(args) + .setFlag(SceneFragment.FLAG_REMOVE_ALL_THE_OTHER_SCENES)); } else if (id == R.id.nav_whats_hot) { } else if (id == R.id.nav_favourite) { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java index 3658a535d..01ac7cf24 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.java @@ -16,6 +16,10 @@ package com.hippo.ehviewer.ui.scene; +import android.animation.Animator; +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; import android.os.Bundle; import android.os.Parcelable; import android.support.annotation.NonNull; @@ -23,22 +27,34 @@ import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.text.TextUtils; import android.text.style.ClickableSpan; import android.text.style.URLSpan; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewAnimationUtils; import android.view.ViewGroup; +import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; +import com.hippo.anani.AnimationUtils; +import com.hippo.anani.SimpleAnimatorListener; import com.hippo.easyrecyclerview.EasyRecyclerView; import com.hippo.easyrecyclerview.LinearDividerItemDecoration; import com.hippo.ehviewer.EhApplication; +import com.hippo.ehviewer.OpenUrlHelper; import com.hippo.ehviewer.R; +import com.hippo.ehviewer.client.EhClient; +import com.hippo.ehviewer.client.EhRequest; +import com.hippo.ehviewer.client.EhUrl; import com.hippo.ehviewer.client.data.GalleryComment; import com.hippo.rippleold.RippleSalon; +import com.hippo.scene.SceneFragment; +import com.hippo.scene.StageActivity; import com.hippo.text.Html; import com.hippo.text.URLImageGetter; -import com.hippo.ehviewer.OpenUrlHelper; +import com.hippo.util.ActivityHelper; import com.hippo.util.ReadableTime; import com.hippo.util.TextUrl; import com.hippo.vector.VectorDrawable; @@ -49,15 +65,26 @@ import com.hippo.yorozuya.LayoutUtils; public final class GalleryCommentsScene extends ToolbarScene implements EasyRecyclerView.OnItemClickListener, - EasyRecyclerView.OnItemLongClickListener { + EasyRecyclerView.OnItemLongClickListener, View.OnClickListener { + public static final String KEY_GID = "gid"; + public static final String KEY_TOKEN = "token"; public static final String KEY_COMMENTS = "comments"; + private int mGid; + private String mToken; private GalleryComment[] mComments; + private FloatingActionButton mFab; + private View mEditPanel; + private SimpleImageView mSendImage; + private EditText mEditText; + private CommentAdapter mAdapter; private ViewTransition mViewTransition; + private boolean mInAnimation = false; + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -74,6 +101,8 @@ public final class GalleryCommentsScene extends ToolbarScene return; } + mGid = args.getInt(KEY_GID, -1); + mToken = args.getString(KEY_TOKEN, null); Parcelable[] parcelables = args.getParcelableArray(KEY_COMMENTS); if (parcelables instanceof GalleryComment[]) { mComments = (GalleryComment[]) parcelables; @@ -85,6 +114,8 @@ public final class GalleryCommentsScene extends ToolbarScene } private void onRestore(@NonNull Bundle savedInstanceState) { + mGid = savedInstanceState.getInt(KEY_GID, -1); + mToken = savedInstanceState.getString(KEY_TOKEN, null); Parcelable[] parcelables = savedInstanceState.getParcelableArray(KEY_COMMENTS); if (parcelables instanceof GalleryComment[]) { mComments = (GalleryComment[]) parcelables; @@ -94,6 +125,8 @@ public final class GalleryCommentsScene extends ToolbarScene @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); + outState.putInt(KEY_GID, mGid); + outState.putString(KEY_TOKEN, mToken); outState.putParcelableArray(KEY_COMMENTS, mComments); } @@ -105,7 +138,10 @@ public final class GalleryCommentsScene extends ToolbarScene EasyRecyclerView recyclerView = (EasyRecyclerView) view.findViewById(R.id.recycler_view); View tip = view.findViewById(R.id.tip); SimpleImageView tipImage = (SimpleImageView) tip.findViewById(R.id.tip_image); - FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); + mEditPanel = view.findViewById(R.id.edit_panel); + mSendImage = (SimpleImageView) mEditPanel.findViewById(R.id.send); + mEditText = (EditText) mEditPanel.findViewById(R.id.edit_text); + mFab = (FloatingActionButton) view.findViewById(R.id.fab); mAdapter = new CommentAdapter(); recyclerView.setAdapter(mAdapter); @@ -123,7 +159,11 @@ public final class GalleryCommentsScene extends ToolbarScene tipImage.setDrawable(VectorDrawable.create(getContext(), R.drawable.sadpanda_head)); - fab.setImageDrawable(VectorDrawable.create(getContext(), R.drawable.ic_reply)); + mSendImage.setDrawable(VectorDrawable.create(getContext(), R.drawable.ic_send)); + mSendImage.setOnClickListener(this); + + mFab.setImageDrawable(VectorDrawable.create(getContext(), R.drawable.ic_reply)); + mFab.setOnClickListener(this); mViewTransition = new ViewTransition(recyclerView, tip); @@ -179,6 +219,153 @@ public final class GalleryCommentsScene extends ToolbarScene return false; } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private void showEditPanelWithAnimationL() { + mInAnimation = true; + mFab.setTranslationX(0); + mFab.setTranslationY(0); + int fabEndX = mEditPanel.getLeft() + (mEditPanel.getWidth() / 2) - (mFab.getWidth() / 2); + int fabEndY = mEditPanel.getTop() + (mEditPanel.getHeight() / 2) - (mFab.getHeight() / 2); + mFab.animate().x(fabEndX).y(fabEndY) + .setInterpolator(AnimationUtils.SLOW_FAST_SLOW_INTERPOLATOR) + .setDuration(300).setListener(new SimpleAnimatorListener() { + @Override + public void onAnimationEnd(Animator animation) { + mFab.setVisibility(View.INVISIBLE); + mEditPanel.setVisibility(View.VISIBLE); + int halfW = mEditPanel.getWidth() / 2; + int halfH = mEditPanel.getHeight() / 2; + Animator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH, 0, + (float) Math.hypot(halfW, halfH)).setDuration(300); + animator.addListener(new SimpleAnimatorListener() { + @Override + public void onAnimationEnd(Animator animation) { + mInAnimation = false; + } + }); + animator.start(); + } + }).start(); + int halfW = mFab.getWidth() / 2; + int halfH = mFab.getHeight() / 2; + ViewAnimationUtils.createCircularReveal(mFab, halfW, halfH, (float) Math.hypot(halfW, halfH), 0) + .setDuration(300).start(); + } + + private void showEditPanel(boolean animation) { + if (animation) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + showEditPanelWithAnimationL(); + } else { + // TODO Add animation for pre-L + mFab.setVisibility(View.INVISIBLE); + mEditPanel.setVisibility(View.VISIBLE); + } + } else { + mFab.setVisibility(View.INVISIBLE); + mEditPanel.setVisibility(View.VISIBLE); + } + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private void hideEditPanelWithAnimationL() { + mInAnimation = true; + int halfW = mEditPanel.getWidth() / 2; + int halfH = mEditPanel.getHeight() / 2; + Animator animator = ViewAnimationUtils.createCircularReveal(mEditPanel, halfW, halfH, + (float) Math.hypot(halfW, halfH), 0).setDuration(300); + animator.addListener(new SimpleAnimatorListener() { + @Override + public void onAnimationEnd(Animator animation) { + mEditPanel.setVisibility(View.GONE); + mFab.setVisibility(View.VISIBLE); + int fabStartX = mEditPanel.getLeft() + (mEditPanel.getWidth() / 2) - (mFab.getWidth() / 2); + int fabStartY = mEditPanel.getTop() + (mEditPanel.getHeight() / 2) - (mFab.getHeight() / 2); + mFab.setX(fabStartX); + mFab.setY(fabStartY); + mFab.animate().translationX(0).translationY(0) + .setInterpolator(AnimationUtils.SLOW_FAST_SLOW_INTERPOLATOR) + .setDuration(300).setListener(new SimpleAnimatorListener() { + @Override + public void onAnimationEnd(Animator animation) { + mInAnimation = false; + } + }).start(); + int halfW = mFab.getWidth() / 2; + int halfH = mFab.getHeight() / 2; + ViewAnimationUtils.createCircularReveal(mFab, halfW, halfH, 0, (float) Math.hypot(halfW, halfH)) + .setDuration(300).start(); + } + }); + animator.start(); + } + + private void hideEditPanel(boolean animation) { + if (animation) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + hideEditPanelWithAnimationL(); + } else { + // TODO Add animation for pre-L + mFab.setVisibility(View.VISIBLE); + mEditPanel.setVisibility(View.INVISIBLE); + } + } else { + mFab.setVisibility(View.VISIBLE); + mEditPanel.setVisibility(View.INVISIBLE); + } + } + + @Nullable + private String getGalleryDetailUrl() { + if (mGid != -1 && mToken != null) { + return EhUrl.getGalleryDetailUrl(mGid, mToken, 0, true); + } else { + return null; + } + } + + @Override + public void onClick(View v) { + if (mFab == v) { + if (!mInAnimation) { + showEditPanel(true); + } + } else if (mSendImage == v) { + if (!mInAnimation) { + String comment = mEditText.getText().toString(); + if (TextUtils.isEmpty(comment)) { + // Comment is empty + return; + } + String url = getGalleryDetailUrl(); + if (url == null) { + return; + } + // Request + EhRequest request = new EhRequest() + .setMethod(EhClient.METHOD_GET_COMMENT_GALLERY) + .setArgs(url, comment) + .setCallback(new CommentGalleryListener(getContext(), + ((StageActivity) getActivity()).getStageId(), getTag())); + EhApplication.getEhClient(getContext()).execute(request); + ActivityHelper.hideSoftInput(getActivity()); + hideEditPanel(true); + } + } + } + + @Override + public void onBackPressed() { + if (mInAnimation) { + return; + } + if (mEditPanel.getVisibility() == View.VISIBLE) { + hideEditPanel(true); + } else { + finish(); + } + } + private class CommentHolder extends RecyclerView.ViewHolder { public TextView user; @@ -215,4 +402,56 @@ public final class GalleryCommentsScene extends ToolbarScene return mComments == null ? 0 : mComments.length; } } + + private void onCommentGallerySuccess(GalleryComment[] result) { + mComments = result; + mAdapter.notifyDataSetChanged(); + } + + private static class CommentGalleryListener implements EhClient.Callback { + + private EhApplication mApplication; + private int mStageId; + private String mSceneTag; + + public CommentGalleryListener(Context context, int stageId, String sceneTag) { + mApplication = (EhApplication) context.getApplicationContext(); + mStageId = stageId; + mSceneTag = sceneTag; + } + + private GalleryCommentsScene getScene() { + StageActivity stage = mApplication.findStageActivityById(mStageId); + if (stage == null) { + return null; + } + SceneFragment scene = stage.findSceneByTag(mSceneTag); + if (scene instanceof GalleryCommentsScene) { + return (GalleryCommentsScene) scene; + } else { + return null; + } + } + + @Override + public void onSuccess(GalleryComment[] result) { + // Show toast + Toast.makeText(mApplication, R.string.comment_successfully, Toast.LENGTH_SHORT).show(); + + GalleryCommentsScene scene = getScene(); + if (scene != null) { + scene.onCommentGallerySuccess(result); + } + } + + @Override + public void onFailure(Exception e) { + // Show toast + Toast.makeText(mApplication, R.string.comment_failed, Toast.LENGTH_SHORT).show(); + } + + @Override + public void onCancel() { + } + } } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java index 3a05963aa..83bbfc51a 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java @@ -58,6 +58,7 @@ import com.hippo.ehviewer.client.data.LargePreviewSet; import com.hippo.ehviewer.client.data.ListUrlBuilder; import com.hippo.ehviewer.client.parser.RateGalleryParser; import com.hippo.rippleold.RippleSalon; +import com.hippo.scene.Announcer; import com.hippo.scene.SceneFragment; import com.hippo.scene.StageActivity; import com.hippo.scene.TransitionHelper; @@ -857,7 +858,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene } else if (mInfo == v) { Bundle args = new Bundle(); args.putParcelable(GalleryInfoScene.KEY_GALLERY_DETAIL, mGalleryDetail); - startScene(GalleryInfoScene.class, args); + startScene(new Announcer(GalleryInfoScene.class).setArgs(args)); } else if (mShare == v) { String url = getGalleryDetailUrl(false); if (url != null) { @@ -882,7 +883,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene args.putInt(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid); args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token); args.putParcelableArray(GalleryCommentsScene.KEY_COMMENTS, mGalleryDetail.comments); - startScene(GalleryCommentsScene.class, args); + startScene(new Announcer(GalleryCommentsScene.class).setArgs(args)); } else if (mPreviews == v) { int gid = getGid(); String token = getToken(); @@ -892,7 +893,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene Bundle args = new Bundle(); args.putInt(GalleryPreviewsScene.KEY_GID, gid); args.putString(GalleryPreviewsScene.KEY_TOKEN, token); - startScene(GalleryPreviewsScene.class, args); + startScene(new Announcer(GalleryPreviewsScene.class).setArgs(args)); } else { Object tag; tag = v.getTag(R.id.tag); 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 1a01ebf2d..bc70b463d 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 @@ -66,6 +66,7 @@ import com.hippo.ehviewer.widget.SearchBar; import com.hippo.ehviewer.widget.SearchLayout; import com.hippo.ehviewer.widget.SimpleRatingView; import com.hippo.rippleold.RippleSalon; +import com.hippo.scene.Announcer; import com.hippo.scene.SceneApplication; import com.hippo.scene.SceneFragment; import com.hippo.scene.StageActivity; @@ -449,12 +450,12 @@ public final class GalleryListScene extends BaseScene Bundle args = new Bundle(); args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO); args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi); + Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args); if (ApiHelper.SUPPORT_TRANSITION) { GalleryListHolder holder = (GalleryListHolder) mRecyclerView.getChildViewHolder(view); - startScene(GalleryDetailScene.class, args, new EnterGalleryDetailTransaction(holder)); - } else { - startScene(GalleryDetailScene.class, args); + announcer.setTranHelper(new EnterGalleryDetailTransaction(holder)); } + startScene(announcer); return true; } @@ -883,7 +884,7 @@ public final class GalleryListScene extends BaseScene Bundle args = new Bundle(); args.putString(KEY_ACTION, ACTION_LIST_URL_BUILDER); args.putParcelable(KEY_LIST_URL_BUILDER, lub); - scene.startScene(GalleryListScene.class, args); + scene.startScene(new Announcer(GalleryListScene.class).setArgs(args)); } private class GalleryListHolder extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/LoginScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/LoginScene.java index 011bb311f..47c948160 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/LoginScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/LoginScene.java @@ -41,6 +41,7 @@ import com.hippo.ehviewer.client.EhClient; import com.hippo.ehviewer.client.EhCookieStore; import com.hippo.ehviewer.client.EhRequest; import com.hippo.rippleold.RippleSalon; +import com.hippo.scene.Announcer; import com.hippo.util.ExceptionUtils; public final class LoginScene extends BaseScene implements EditText.OnEditorActionListener, @@ -224,7 +225,7 @@ public final class LoginScene extends BaseScene implements EditText.OnEditorActi private void redirectTo() { Bundle args = new Bundle(); args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE); - startScene(GalleryListScene.class, args); + startScene(new Announcer(GalleryListScene.class).setArgs(args)); finish(); // Enable drawer setDrawerLayoutEnable(true); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/WarningScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/WarningScene.java index 35871ec8c..f2abb3ae5 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/WarningScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/WarningScene.java @@ -27,6 +27,7 @@ import com.hippo.ehviewer.R; import com.hippo.ehviewer.Settings; import com.hippo.ehviewer.client.EhUtils; import com.hippo.rippleold.RippleSalon; +import com.hippo.scene.Announcer; import com.hippo.vector.VectorDrawable; import com.hippo.widget.SimpleImageView; @@ -68,12 +69,12 @@ public final class WarningScene extends BaseScene implements View.OnClickListene if (EhUtils.hasSignedIn(getContext())) { Bundle args = new Bundle(); args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE); - startScene(GalleryListScene.class, args); + startScene(new Announcer(GalleryListScene.class).setArgs(args)); finish(); // Enable drawer setDrawerLayoutEnable(true); } else { - startScene(LoginScene.class); + startScene(new Announcer(LoginScene.class)); finish(); } } diff --git a/app/src/main/java/com/hippo/scene/Announcer.java b/app/src/main/java/com/hippo/scene/Announcer.java new file mode 100644 index 000000000..84628439f --- /dev/null +++ b/app/src/main/java/com/hippo/scene/Announcer.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 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.scene; + +import android.os.Bundle; + +public final class Announcer { + + Class clazz; + Bundle args; + TransitionHelper tranHelper; + int flag; + int requestId; + + public Announcer(Class clazz) { + this.clazz = clazz; + } + + public Announcer setArgs(Bundle args) { + this.args = args; + return this; + } + + public Announcer setTranHelper(TransitionHelper tranHelper) { + this.tranHelper = tranHelper; + return this; + } + + public Announcer setFlag(int flag) { + this.flag = flag; + return this; + } + + public Announcer setRequestId(int requestId) { + this.requestId = requestId; + return this; + } +} diff --git a/app/src/main/java/com/hippo/scene/SceneFragment.java b/app/src/main/java/com/hippo/scene/SceneFragment.java index 2b7559967..52d200c3f 100644 --- a/app/src/main/java/com/hippo/scene/SceneFragment.java +++ b/app/src/main/java/com/hippo/scene/SceneFragment.java @@ -52,28 +52,10 @@ public class SceneFragment extends Fragment { public void onNewArguments(@NonNull Bundle args) {} - public void startScene(Class clazz) { - startScene(clazz, null, null, 0); - } - - public void startScene(Class clazz, Bundle args) { - startScene(clazz, args, null, 0); - } - - public void startScene(Class clazz, TransitionHelper transitionHelper) { - startScene(clazz, null, transitionHelper, 0); - } - - public void startScene(Class clazz, Bundle args, - TransitionHelper transitionHelper) { - startScene(clazz, args, transitionHelper, 0); - } - - public void startScene(Class clazz, Bundle args, - TransitionHelper transitionHelper, int flag) { + public void startScene(Announcer announcer) { FragmentActivity activity = getActivity(); if (activity instanceof StageActivity) { - ((StageActivity) activity).startScene(clazz, args, transitionHelper, flag); + ((StageActivity) activity).startScene(announcer); } } diff --git a/app/src/main/java/com/hippo/scene/StageActivity.java b/app/src/main/java/com/hippo/scene/StageActivity.java index 845eb83ef..adf185e10 100644 --- a/app/src/main/java/com/hippo/scene/StageActivity.java +++ b/app/src/main/java/com/hippo/scene/StageActivity.java @@ -70,7 +70,7 @@ public abstract class StageActivity extends AppCompatActivity { Bundle args = intent.getBundleExtra(KEY_SCENE_ARGS); - startScene(clazz, args); + startScene(new Announcer(clazz).setArgs(args)); } } @@ -121,22 +121,12 @@ public abstract class StageActivity extends AppCompatActivity { } } - public void startScene(Class clazz) { - startScene(clazz, null, null, 0); - } - - public void startScene(Class clazz, Bundle args) { - startScene(clazz, args, null, 0); - } - - public void startScene(Class clazz, TransitionHelper transitionHelper) { - startScene(clazz, null, transitionHelper, 0); - } - - public void startScene(Class clazz, - Bundle args, TransitionHelper transitionHelper, int flag) { + public void startScene(Announcer announcer) { + Class clazz = announcer.clazz; + Bundle args = announcer.args; + TransitionHelper tranHelper = announcer.tranHelper; boolean createNewScene = true; - boolean removeAllTheOthers = (flag & SceneFragment.FLAG_REMOVE_ALL_THE_OTHER_SCENES) != 0; + boolean removeAllTheOthers = (announcer.flag & SceneFragment.FLAG_REMOVE_ALL_THE_OTHER_SCENES) != 0; FragmentManager fragmentManager = getSupportFragmentManager(); @@ -188,7 +178,7 @@ public abstract class StageActivity extends AppCompatActivity { FragmentTransaction transaction = fragmentManager.beginTransaction(); // Animation if (newScene != null && currentFragment != null) { - if (transitionHelper == null || !transitionHelper.onTransition( + if (tranHelper == null || !tranHelper.onTransition( this, transaction, currentFragment, newScene)) { // Clear shared item currentFragment.setSharedElementEnterTransition(null); diff --git a/app/src/main/java/com/hippo/util/ActivityHelper.java b/app/src/main/java/com/hippo/util/ActivityHelper.java index b5ba70bab..525cdea85 100644 --- a/app/src/main/java/com/hippo/util/ActivityHelper.java +++ b/app/src/main/java/com/hippo/util/ActivityHelper.java @@ -17,11 +17,15 @@ package com.hippo.util; import android.app.Activity; +import android.app.Service; import android.content.ActivityNotFoundException; +import android.content.Context; import android.content.Intent; import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.view.View; +import android.view.inputmethod.InputMethodManager; import android.widget.Toast; import com.hippo.ehviewer.R; @@ -62,4 +66,24 @@ public class ActivityHelper { return false; } } + + public static void showSoftInput(Context context, View view) { + showSoftInput(context, view, true); + } + + public static void showSoftInput(Context context, View view, boolean requestFocus) { + if (requestFocus) { + view.requestFocus(); + } + InputMethodManager imm = (InputMethodManager) context.getSystemService(Service.INPUT_METHOD_SERVICE); + imm.showSoftInput(view, 0); + } + + public static void hideSoftInput(Activity activity) { + View view = activity.getCurrentFocus(); + if (view != null) { + InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } } diff --git a/app/src/main/res/drawable/ic_send.xml b/app/src/main/res/drawable/ic_send.xml new file mode 100644 index 000000000..87168919d --- /dev/null +++ b/app/src/main/res/drawable/ic_send.xml @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/app/src/main/res/drawable/shadow_top.xml b/app/src/main/res/drawable/shadow_top.xml new file mode 100644 index 000000000..4a4014fd5 --- /dev/null +++ b/app/src/main/res/drawable/shadow_top.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/app/src/main/res/layout/scene_gallery_comments.xml b/app/src/main/res/layout/scene_gallery_comments.xml index 12072a1ba..4062575f3 100644 --- a/app/src/main/res/layout/scene_gallery_comments.xml +++ b/app/src/main/res/layout/scene_gallery_comments.xml @@ -57,6 +57,45 @@ + + + + + + + + + + + + + M12,12L12,12L12,12C12,12 12,12 12,12C12,12 12,12 12,12C12,12 12,12 12,12H12C12,12 12,12 12,12C12,12 12,12 12,12C12,12 12,12 12,12M16.5,3C14.76,3 13.09,3.81 12,5.08C10.91,3.81 9.24,3 7.5,3C4.42,3 2,5.41 2,8.5C2,12.27 5.4,15.36 10.55,20.03L12,21.35L13.45,20.03C18.6,15.36 22,12.27 22,8.5C22,5.41 19.58,3 16.5,3Z M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z M10,9V5L3,12L10,19V14.9C15,14.9 18.5,16.5 21,20C20,15 17,10 10,9Z + M2,21L23,12L2,3V10L17,12L2,14V21Z M13,0C20.2,0,26,5.9,26,13.2,26,16.9,24,20.8,18.7,26.1L13,32,7.2,26.2C2,20.8,0,16.9,0,13.3,0,5.9,5.8,0,13,0Z diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3eb9f5b86..8c568a52f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -195,6 +195,8 @@ Gallery Comments No one comments on this gallery + Comment successfully + Comment failed Gallery Previews diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 8001a9d84..a1cd66fee 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -47,4 +47,10 @@ + +