Always show WarningScene and LoginScene if necessary
This commit is contained in:
1 parent
1905fa526e
commit
f213254e2b
6 files changed
+141
-53
No files matched your search
@@ -26,6 +26,9 @@ import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.util.CustomTabsHelper;
|
||||
|
||||
public final class UrlOpener {
|
||||
@@ -41,8 +44,16 @@ public final class UrlOpener {
|
||||
Intent intent;
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
if (ehUrl && EhUrlOpener.openUrl(activity, url)) {
|
||||
return;
|
||||
if (ehUrl) {
|
||||
Announcer announcer = EhUrlOpener.parseUrl(url);
|
||||
if (null != announcer) {
|
||||
intent = new Intent(activity, MainActivity.class);
|
||||
intent.setAction(StageActivity.ACTION_START_SCENE);
|
||||
intent.putExtra(StageActivity.KEY_SCENE_NAME, announcer.getClazz().getName());
|
||||
intent.putExtra(StageActivity.KEY_SCENE_ARGS, announcer.getArgs());
|
||||
activity.startActivity(intent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// CustomTabs
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -26,34 +25,27 @@ import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryListUrlParser;
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryDetailScene;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene;
|
||||
import com.hippo.ehviewer.ui.scene.ProgressScene;
|
||||
import com.hippo.scene.StageActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
|
||||
public class EhUrlOpener {
|
||||
|
||||
private static final String TAG = EhUrlOpener.class.getSimpleName();
|
||||
|
||||
public static boolean openUrl(Activity activity, String url) {
|
||||
@Nullable
|
||||
public static Announcer parseUrl(String url) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
Intent intent;
|
||||
|
||||
ListUrlBuilder listUrlBuilder = GalleryListUrlParser.parse(url);
|
||||
if (listUrlBuilder != null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_LIST_URL_BUILDER);
|
||||
args.putParcelable(GalleryListScene.KEY_LIST_URL_BUILDER, listUrlBuilder);
|
||||
intent = new Intent(activity, MainActivity.class);
|
||||
intent.setAction(StageActivity.ACTION_START_SCENE);
|
||||
intent.putExtra(StageActivity.KEY_SCENE_NAME, GalleryListScene.class.getName());
|
||||
intent.putExtra(StageActivity.KEY_SCENE_ARGS, args);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
return new Announcer(GalleryListScene.class).setArgs(args);
|
||||
}
|
||||
|
||||
GalleryDetailUrlParser.Result result1 = GalleryDetailUrlParser.parse(url);
|
||||
@@ -62,12 +54,7 @@ public class EhUrlOpener {
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
|
||||
args.putLong(GalleryDetailScene.KEY_GID, result1.gid);
|
||||
args.putString(GalleryDetailScene.KEY_TOKEN, result1.token);
|
||||
intent = new Intent(activity, MainActivity.class);
|
||||
intent.setAction(StageActivity.ACTION_START_SCENE);
|
||||
intent.putExtra(StageActivity.KEY_SCENE_NAME, GalleryDetailScene.class.getName());
|
||||
intent.putExtra(StageActivity.KEY_SCENE_ARGS, args);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
return new Announcer(GalleryDetailScene.class).setArgs(args);
|
||||
}
|
||||
|
||||
GalleryPageUrlParser.Result result2 = GalleryPageUrlParser.parse(url);
|
||||
@@ -77,16 +64,11 @@ public class EhUrlOpener {
|
||||
args.putLong(ProgressScene.KEY_GID, result2.gid);
|
||||
args.putString(ProgressScene.KEY_PTOKEN, result2.pToken);
|
||||
args.putLong(ProgressScene.KEY_PAGE, result2.page);
|
||||
intent = new Intent(activity, MainActivity.class);
|
||||
intent.setAction(StageActivity.ACTION_START_SCENE);
|
||||
intent.putExtra(StageActivity.KEY_SCENE_NAME, ProgressScene.class.getName());
|
||||
intent.putExtra(StageActivity.KEY_SCENE_ARGS, args);
|
||||
activity.startActivity(intent);
|
||||
return true;
|
||||
return new Announcer(ProgressScene.class).setArgs(args);
|
||||
}
|
||||
|
||||
Log.i(TAG, "Can't parse url: " + url);
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -97,19 +97,34 @@ public final class MainActivity extends StageActivity
|
||||
@Override
|
||||
protected Announcer getLaunchAnnouncer() {
|
||||
if (Settings.getShowWarning()) {
|
||||
//setDrawerLayoutEnable(false);
|
||||
return new Announcer(WarningScene.class);
|
||||
} else if (!EhUtils.hasSignedIn(this)) {
|
||||
//setDrawerLayoutEnable(false);
|
||||
return new Announcer(LoginScene.class);
|
||||
} else {
|
||||
//setDrawerLayoutEnable(true);
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
|
||||
return new Announcer(GalleryListScene.class).setArgs(args);
|
||||
}
|
||||
}
|
||||
|
||||
// Sometimes scene can't show directly
|
||||
private Announcer processAnnouncer(Announcer announcer) {
|
||||
if (0 == getSceneCount()) {
|
||||
if (Settings.getShowWarning()) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(WarningScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(WarningScene.KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(WarningScene.class).setArgs(newArgs);
|
||||
} else if (!EhUtils.hasSignedIn(this)) {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(LoginScene.KEY_TARGET_SCENE, announcer.getClazz().getName());
|
||||
newArgs.putBundle(LoginScene.KEY_TARGET_ARGS, announcer.getArgs());
|
||||
return new Announcer(LoginScene.class).setArgs(newArgs);
|
||||
}
|
||||
}
|
||||
return announcer;
|
||||
}
|
||||
|
||||
private boolean handleIntent(Intent intent) {
|
||||
if (intent == null) {
|
||||
return false;
|
||||
@@ -117,7 +132,11 @@ public final class MainActivity extends StageActivity
|
||||
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_VIEW.equals(action)) {
|
||||
return EhUrlOpener.openUrl(this, intent.getData().toString());
|
||||
Announcer announcer = EhUrlOpener.parseUrl(intent.getData().toString());
|
||||
if (announcer != null) {
|
||||
startScene(processAnnouncer(announcer));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -138,8 +157,7 @@ public final class MainActivity extends StageActivity
|
||||
@Nullable
|
||||
@Override
|
||||
protected Announcer onStartSceneFromIntent(@NonNull Class<?> clazz, @Nullable Bundle args) {
|
||||
// TODO start login scene or warning scene
|
||||
return super.onStartSceneFromIntent(clazz, args);
|
||||
return processAnnouncer(new Announcer(clazz).setArgs(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -49,6 +50,11 @@ import com.hippo.util.ExceptionUtils;
|
||||
public final class LoginScene extends BaseScene implements EditText.OnEditorActionListener,
|
||||
View.OnClickListener {
|
||||
|
||||
private static final String TAG = LoginScene.class.getSimpleName();
|
||||
|
||||
public static final String KEY_TARGET_SCENE = "target_scene";
|
||||
public static final String KEY_TARGET_ARGS = "target_args";
|
||||
|
||||
private static final String KEY_REQUEST_ID = "request_id";
|
||||
|
||||
private View mProgress;
|
||||
@@ -205,12 +211,33 @@ 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(new Announcer(GalleryListScene.class).setArgs(args));
|
||||
String targetScene = null;
|
||||
Bundle targetArgs = null;
|
||||
|
||||
Bundle args = getArguments();
|
||||
if (null != args) {
|
||||
targetScene = args.getString(KEY_TARGET_SCENE);
|
||||
targetArgs = args.getBundle(KEY_TARGET_ARGS);
|
||||
}
|
||||
|
||||
Class<?> clazz = null;
|
||||
if (targetScene != null) {
|
||||
try {
|
||||
clazz = Class.forName(targetScene);
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e(TAG, "Can't find class with name: " + targetScene);
|
||||
}
|
||||
}
|
||||
|
||||
if (clazz != null) {
|
||||
startScene(new Announcer(clazz).setArgs(targetArgs));
|
||||
} else {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
|
||||
startScene(new Announcer(GalleryListScene.class).setArgs(newArgs));
|
||||
}
|
||||
|
||||
finish();
|
||||
// Enable drawer
|
||||
setDrawerLayoutEnable(true);
|
||||
}
|
||||
|
||||
private void whetherToSkip() {
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.ui.scene;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -25,13 +26,24 @@ import android.view.ViewGroup;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.ui.annotation.ViewLifeCircle;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.yorozuya.ViewUtils;
|
||||
|
||||
public final class WarningScene extends BaseScene implements View.OnClickListener {
|
||||
|
||||
private static final String TAG = WarningScene.class.getSimpleName();
|
||||
|
||||
public static final String KEY_TARGET_SCENE = "target_scene";
|
||||
public static final String KEY_TARGET_ARGS = "target_args";
|
||||
|
||||
@Nullable
|
||||
@ViewLifeCircle
|
||||
private View mCancel;
|
||||
@Nullable
|
||||
@ViewLifeCircle
|
||||
private View mOk;
|
||||
|
||||
@Nullable
|
||||
@@ -40,8 +52,8 @@ public final class WarningScene extends BaseScene implements View.OnClickListene
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.scene_warning, container, false);
|
||||
|
||||
mCancel = view.findViewById(R.id.cancel);
|
||||
mOk = view.findViewById(R.id.ok);
|
||||
mCancel = ViewUtils.$$(view, R.id.cancel);
|
||||
mOk = ViewUtils.$$(view, R.id.ok);
|
||||
|
||||
mCancel.setOnClickListener(this);
|
||||
mOk.setOnClickListener(this);
|
||||
@@ -76,17 +88,47 @@ public final class WarningScene extends BaseScene implements View.OnClickListene
|
||||
// Never show this warning anymore
|
||||
Settings.putShowWarning(false);
|
||||
|
||||
if (EhUtils.hasSignedIn(getContext())) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
|
||||
startScene(new Announcer(GalleryListScene.class).setArgs(args));
|
||||
finish();
|
||||
// Enable drawer
|
||||
setDrawerLayoutEnable(true);
|
||||
} else {
|
||||
startScene(new Announcer(LoginScene.class));
|
||||
finish();
|
||||
}
|
||||
redirectTo();
|
||||
}
|
||||
}
|
||||
|
||||
public void redirectTo() {
|
||||
String targetScene = null;
|
||||
Bundle targetArgs = null;
|
||||
|
||||
Bundle args = getArguments();
|
||||
if (null != args) {
|
||||
targetScene = args.getString(KEY_TARGET_SCENE);
|
||||
targetArgs = args.getBundle(KEY_TARGET_ARGS);
|
||||
}
|
||||
|
||||
if (EhUtils.hasSignedIn(getContext())) {
|
||||
Class<?> clazz = null;
|
||||
if (targetScene != null) {
|
||||
try {
|
||||
clazz = Class.forName(targetScene);
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e(TAG, "Can't find class with name: " + targetScene);
|
||||
}
|
||||
}
|
||||
|
||||
if (clazz != null) {
|
||||
startScene(new Announcer(clazz).setArgs(targetArgs));
|
||||
} else {
|
||||
Bundle newArgs = new Bundle();
|
||||
newArgs.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
|
||||
startScene(new Announcer(GalleryListScene.class).setArgs(newArgs));
|
||||
}
|
||||
} else {
|
||||
Bundle newArgs = null;
|
||||
if (null != targetScene) {
|
||||
newArgs = new Bundle();
|
||||
newArgs.putString(LoginScene.KEY_TARGET_SCENE, targetScene);
|
||||
newArgs.putBundle(LoginScene.KEY_TARGET_ARGS, targetArgs);
|
||||
}
|
||||
startScene(new Announcer(LoginScene.class).setArgs(newArgs));
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -30,11 +30,19 @@ public final class Announcer {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public Class<?> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public Announcer setArgs(Bundle args) {
|
||||
this.args = args;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Bundle getArgs() {
|
||||
return args;
|
||||
}
|
||||
|
||||
public Announcer setTranHelper(TransitionHelper tranHelper) {
|
||||
this.tranHelper = tranHelper;
|
||||
return this;
|
||||
|
||||
Reference in new issue
Block a user