Add select site scene

This commit is contained in:
seven332 committed 2016-03-20 16:16:29 +08:00
1 parent 9e2c5715ed
commit 1166c0d547
10 files changed
+237 -4

No files matched your search

@@ -209,6 +209,17 @@ public class Settings {
putBoolean(KEY_NEED_SIGN_IN, value);
}
private static final String KEY_SELECT_SITE = "select_site";
private static final boolean DEFAULT_SELECT_SITE = true;
public static boolean getSelectSite() {
return getBoolean(KEY_SELECT_SITE, DEFAULT_SELECT_SITE);
}
public static void putSelectSite(boolean value) {
putBoolean(KEY_SELECT_SITE, value);
}
/********************
****** Eh
********************/
@@ -58,6 +58,7 @@ import com.hippo.ehviewer.ui.scene.GalleryPreviewsScene;
import com.hippo.ehviewer.ui.scene.HistoryScene;
import com.hippo.ehviewer.ui.scene.ProgressScene;
import com.hippo.ehviewer.ui.scene.QuickSearchScene;
import com.hippo.ehviewer.ui.scene.SelectSiteScene;
import com.hippo.ehviewer.ui.scene.SignInScene;
import com.hippo.ehviewer.ui.scene.WarningScene;
import com.hippo.ehviewer.ui.scene.WebViewSignInScene;
@@ -83,6 +84,7 @@ public final class MainActivity extends StageActivity
public static final int CHECK_STEP_ANALYTICS = 1;
public static final int CHECK_STEP_CRASH = 2;
public static final int CHECK_STEP_SIGN_IN = 3;
public static final int CHECK_STEP_SELECT_SITE = 4;
public static final String KEY_TARGET_SCENE = "target_scene";
public static final String KEY_TARGET_ARGS = "target_args";
@@ -110,6 +112,7 @@ public final class MainActivity extends StageActivity
registerLaunchMode(SignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(WebViewSignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(CookieSignInScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(SelectSiteScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(GalleryListScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TOP);
registerLaunchMode(QuickSearchScene.class, SceneFragment.LAUNCH_MODE_SINGLE_TASK);
registerLaunchMode(GalleryDetailScene.class, SceneFragment.LAUNCH_MODE_STANDARD);
@@ -141,6 +144,11 @@ public final class MainActivity extends StageActivity
break;
}
case CHECK_STEP_SIGN_IN:
if (Settings.getSelectSite()) {
startScene(new Announcer(SelectSiteScene.class).setArgs(args));
break;
}
case CHECK_STEP_SELECT_SITE:
String targetScene = null;
Bundle targetArgs = null;
if (null != args) {
@@ -184,6 +192,8 @@ public final class MainActivity extends StageActivity
return new Announcer(CrashScene.class);
} else if (EhUtils.needSignedIn(this)) {
return new Announcer(SignInScene.class);
} else if (Settings.getSelectSite()) {
return new Announcer(SelectSiteScene.class);
} else {
Bundle args = new Bundle();
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_HOMEPAGE);
@@ -214,6 +224,11 @@ public final class MainActivity extends StageActivity
newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(SignInScene.class).setArgs(newArgs);
} else if (Settings.getSelectSite()) {
Bundle newArgs = new Bundle();
newArgs.putString(KEY_TARGET_SCENE, announcer.getClazz().getName());
newArgs.putBundle(KEY_TARGET_ARGS, announcer.getArgs());
return new Announcer(SelectSiteScene.class).setArgs(newArgs);
}
}
return announcer;
@@ -0,0 +1,93 @@
/*
* 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.ehviewer.ui.scene;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhUrl;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.yorozuya.ViewUtils;
public class SelectSiteScene extends BaseScene implements View.OnClickListener {
private RadioGroup mRadioGroup;
private View mOk;
@Override
public boolean needShowLeftDrawer() {
return false;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scene_select_site, container, false);
mRadioGroup = (RadioGroup) ViewUtils.$$(view, R.id.radio_group);
mOk = ViewUtils.$$(view, R.id.ok);
mOk.setOnClickListener(this);
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
mRadioGroup = null;
mOk = null;
}
@Override
public void onClick(View v) {
MainActivity activity = getActivity2();
if (null == activity || null == mRadioGroup) {
return;
}
if (v == mOk) {
int id = mRadioGroup.getCheckedRadioButtonId();
switch (id) {
case R.id.site_e:
Settings.putSelectSite(false);
Settings.putGallerySite(EhUrl.SITE_G);
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_SELECT_SITE, getArguments());
finish();
break;
case R.id.site_ex:
Settings.putSelectSite(false);
Settings.putGallerySite(EhUrl.SITE_EX);
activity.startSceneForCheckStep(MainActivity.CHECK_STEP_SELECT_SITE, getArguments());
finish();
break;
default:
Toast.makeText(activity, R.string.no_select, Toast.LENGTH_SHORT).show();
break;
}
}
}
}