Fix SceneDialog in multiple SceneManager
This commit is contained in:
1 parent
951e7323e3
commit
c832589ac6
11 files changed
+57
-30
No files matched your search
@@ -482,7 +482,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
public void onClose(SimpleDialog dialog, boolean cancel) {
|
||||
finish();
|
||||
}
|
||||
}).show();
|
||||
}).show(GalleryDetailScene.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -532,7 +532,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
mPreviewLayout.selectPreviewAt(which);
|
||||
return true;
|
||||
}
|
||||
}).show();
|
||||
}).show(GalleryDetailScene.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,11 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
private final static int FAB_STATE_NORMAL = 0;
|
||||
private final static int FAB_STATE_SEARCH = 1;
|
||||
|
||||
private static final int BACK_PRESSED_INTERVAL = 2000;
|
||||
|
||||
// Double click back exit
|
||||
private long mPressBackTime = 0;
|
||||
|
||||
private ContentActivity mActivity;
|
||||
private Resources mResources;
|
||||
private SearchDatabase mSearchDatabase;
|
||||
@@ -477,7 +482,14 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
} else {
|
||||
switch (mState) {
|
||||
case STATE_NORMAL:
|
||||
super.onBackPressed();
|
||||
long time = System.currentTimeMillis();
|
||||
if (getSceneCount() == 1 && time - mPressBackTime > BACK_PRESSED_INTERVAL) {
|
||||
// It is the last scene
|
||||
mPressBackTime = time;
|
||||
Toast.makeText(getStageActivity(), "Press twice to exit", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
break;
|
||||
case STATE_SIMPLE_SEARCH:
|
||||
setState(STATE_NORMAL);
|
||||
@@ -500,11 +512,11 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
public void showGoToDialog() {
|
||||
int[] center = new int[2];
|
||||
ViewUtils.getCenterInAncestor(mGoToFab, center, R.id.stage);
|
||||
new SimpleDialog.Builder(mActivity).setTitle(R.string._goto)
|
||||
new SimpleDialog.Builder(getStageActivity()).setTitle(R.string._goto)
|
||||
.setCustomView(R.layout.dialog_go_to, mGoToCreateCustomViewListener)
|
||||
.setOnButtonClickListener(mGoToButtonClickListener)
|
||||
.setPositiveButton(android.R.string.ok)
|
||||
.setStartPoint(center[0], center[1]).show();
|
||||
.setStartPoint(center[0], center[1]).show(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -714,6 +726,11 @@ public final class GalleryListScene extends Scene implements SearchBar.Helper,
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public Scene getScene() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
GalleryInfo gi = mGalleryListHelper.getDataAt(position);
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class EHSettingsScene extends PreferenceScene {
|
||||
|
||||
ValueChangeListener valueChangeListener = new ValueChangeListener();
|
||||
|
||||
ListPreference sourcePreference = new ListPreference(KEY_EH_SOURCE,
|
||||
ListPreference sourcePreference = new ListPreference(this, KEY_EH_SOURCE,
|
||||
resources.getString(R.string.settings_eh_source_title), null);
|
||||
sourcePreference.setKeys(resources.getStringArray(R.array.settings_eh_source_entries));
|
||||
sourcePreference.setValues(resources.getIntArray(R.array.settings_eh_source_entry_values));
|
||||
|
||||
@@ -38,6 +38,7 @@ import android.widget.TextView;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.SimpleDialog;
|
||||
import com.hippo.util.UiUtils;
|
||||
import com.hippo.util.ViewUtils;
|
||||
@@ -297,9 +298,10 @@ public class SearchLayout extends MonoRecyclerView implements CompoundButton.OnC
|
||||
} else if (v == mSearchTagHelp) {
|
||||
int[] center = new int [2];
|
||||
ViewUtils.getCenterInAncestor(mSearchTagHelp, center, R.id.stage);
|
||||
|
||||
new SimpleDialog.Builder(getContext()).setTitle(R.string.search_specify_tag)
|
||||
.setMessage(R.string.search_tag_help)
|
||||
.setStartPoint(center[0], center[1]).show();
|
||||
.setStartPoint(center[0], center[1]).show(mHelper.getScene());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,5 +388,7 @@ public class SearchLayout extends MonoRecyclerView implements CompoundButton.OnC
|
||||
void onChangeSearchMode();
|
||||
|
||||
void onRequestSelectImage();
|
||||
|
||||
Scene getScene();
|
||||
}
|
||||
}
|
||||
@@ -119,6 +119,10 @@ public abstract class Scene {
|
||||
return mSceneView;
|
||||
}
|
||||
|
||||
public int getSceneCount() {
|
||||
return mSceneManager.getSceneCount();
|
||||
}
|
||||
|
||||
public void startScene(@NonNull Class sceneClass) {
|
||||
mSceneManager.startScene(sceneClass, null, null);
|
||||
}
|
||||
@@ -140,7 +144,7 @@ public abstract class Scene {
|
||||
mState = state;
|
||||
}
|
||||
|
||||
protected SceneView createSceneView(Context context) {
|
||||
SceneView createSceneView(Context context) {
|
||||
return new SceneView(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,4 +27,8 @@ public abstract class SceneDialog extends Scene {
|
||||
public void show(@Nullable Curtain curtain) {
|
||||
mSceneManager.showDialog(this, curtain);
|
||||
}
|
||||
|
||||
protected static Scene createSceneDialog(Scene scene, Class clazz) {
|
||||
return scene.mSceneManager.createSceneByClass(clazz);
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,9 @@ public class SceneManager {
|
||||
|
||||
Scene createSceneByClass(@NonNull Class sceneClass) {
|
||||
try {
|
||||
return (Scene) sceneClass.newInstance();
|
||||
Scene scene = (Scene) sceneClass.newInstance();
|
||||
scene.setSceneManager(this);
|
||||
return scene;
|
||||
} catch (InstantiationException e) {
|
||||
throw new IllegalStateException("Can't instance " + sceneClass.getName());
|
||||
} catch (IllegalAccessException e) {
|
||||
@@ -154,7 +156,6 @@ public class SceneManager {
|
||||
}
|
||||
|
||||
Scene scene = createSceneByClass(sceneClass);
|
||||
scene.setSceneManager(this);
|
||||
scene.setAnnouncer(announcer);
|
||||
scene.setCurtain(curtain);
|
||||
|
||||
@@ -343,7 +344,7 @@ public class SceneManager {
|
||||
return mSceneStack;
|
||||
}
|
||||
|
||||
int getSceneSize() {
|
||||
int getSceneCount() {
|
||||
return mSceneStack.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -419,25 +419,16 @@ public class SimpleDialog extends SceneDialog implements View.OnClickListener,
|
||||
return this;
|
||||
}
|
||||
|
||||
public @NonNull SimpleDialog build() {
|
||||
public @NonNull SimpleDialog show(Scene scene) {
|
||||
// Avoid memory leak
|
||||
mContext = null;
|
||||
|
||||
SimpleDialog dialog = new SimpleDialog();
|
||||
SimpleDialog dialog = (SimpleDialog) SceneDialog.createSceneDialog(scene, SimpleDialog.class);
|
||||
dialog.setBuilder(this);
|
||||
dialog.show(new SimpleDialogCurtain(mStartX, mStartY));
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
show(null);
|
||||
}
|
||||
|
||||
public void show(Curtain curtain) {
|
||||
if (curtain == null) {
|
||||
curtain = new SimpleDialogCurtain(mStartX, mStartY);
|
||||
}
|
||||
build().show(curtain);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnCreateCustomViewListener {
|
||||
|
||||
@@ -67,7 +67,7 @@ public abstract class StageActivity extends StatsActivity {
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mSceneManager.getSceneSize() == 0) {
|
||||
if (mSceneManager.getSceneCount() == 0) {
|
||||
// Remove this SceneManager
|
||||
SceneApplication.removeSceneManager(this, mSceneManager);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public abstract class StageActivity extends StatsActivity {
|
||||
*/
|
||||
@Override
|
||||
public void finish() {
|
||||
if (mSceneManager.getSceneSize() == 0) {
|
||||
if (mSceneManager.getSceneCount() == 0) {
|
||||
super.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,18 +20,23 @@ import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
||||
import com.hippo.ehviewer.util.Config;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.SimpleDialog;
|
||||
|
||||
// TODO show current value as summary
|
||||
public class ListPreference extends Preference {
|
||||
|
||||
private Scene mScene;
|
||||
|
||||
private String[] mKeys;
|
||||
private int[] mValues;
|
||||
|
||||
private int mDefaultValue;
|
||||
|
||||
public ListPreference(String key, String title, String summary) {
|
||||
public ListPreference(Scene scene, String key, String title, String summary) {
|
||||
super(key, title, summary);
|
||||
|
||||
mScene = scene;
|
||||
}
|
||||
|
||||
public void setKeys(String[] keys) {
|
||||
@@ -83,7 +88,7 @@ public class ListPreference extends Preference {
|
||||
@Override
|
||||
public boolean onClick(RecyclerView.ViewHolder viewHolder, int x, int y) {
|
||||
if (!super.onClick(viewHolder, x, y)) {
|
||||
new SimpleDialog.Builder(viewHolder.itemView.getContext())
|
||||
new SimpleDialog.Builder(mScene.getStageActivity())
|
||||
.setTitle(getTitle())
|
||||
.setSingleChoiceItems(mKeys, getValuePosition(), null)
|
||||
.setStartPoint(x, y)
|
||||
@@ -97,7 +102,7 @@ public class ListPreference extends Preference {
|
||||
}
|
||||
}
|
||||
}
|
||||
}).show();
|
||||
}).show(mScene);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user