Add comment gallery, add Announcer

This commit is contained in:
seven332 committed 2016-02-06 15:02:44 +08:00
1 parent 596966b4ab
commit 875509be68
18 files changed
+497 -55

No files matched your search

@@ -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);
}
@@ -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
}
@@ -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) {
@@ -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<GalleryComment[]> {
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() {
}
}
}
@@ -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);
@@ -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 {
@@ -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);
@@ -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();
}
}
@@ -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;
}
}
@@ -52,28 +52,10 @@ public class SceneFragment extends Fragment {
public void onNewArguments(@NonNull Bundle args) {}
public <T extends SceneFragment> void startScene(Class<T> clazz) {
startScene(clazz, null, null, 0);
}
public <T extends SceneFragment> void startScene(Class<T> clazz, Bundle args) {
startScene(clazz, args, null, 0);
}
public <T extends SceneFragment> void startScene(Class<T> clazz, TransitionHelper transitionHelper) {
startScene(clazz, null, transitionHelper, 0);
}
public <T extends SceneFragment> void startScene(Class<T> clazz, Bundle args,
TransitionHelper transitionHelper) {
startScene(clazz, args, transitionHelper, 0);
}
public <T extends SceneFragment> void startScene(Class<T> 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);
}
}
@@ -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);
@@ -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);
}
}
}