Add refresh top scene

This commit is contained in:
seven332 committed 2016-03-25 14:34:26 +08:00
1 parent 2ee792c6a8
commit df01343c97
9 files changed
+53 -68

No files matched your search

@@ -1,31 +0,0 @@
/*
* 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;
import com.hippo.yorozuya.Messenger;
public final class Constants {
public static final int MESSAGE_ID_LIST_MODE;
static {
Messenger messenger = Messenger.getInstance();
MESSAGE_ID_LIST_MODE = messenger.newId();
}
private Constants(){}
}
@@ -79,6 +79,8 @@ public final class MainActivity extends StageActivity
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
private static final int REQUEST_CODE_SETTINGS = 0;
private static final String KEY_NAV_CHECKED_ITEM = "nav_checked_item";
public static final int CHECK_STEP_SECURITY = 0;
@@ -522,7 +524,7 @@ public final class MainActivity extends StageActivity
startScene(new Announcer(DownloadsScene.class));
} else if (id == R.id.nav_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
startActivityForResult(intent, REQUEST_CODE_SETTINGS);
}
if (id != R.id.nav_stub && mDrawerLayout != null) {
@@ -531,4 +533,18 @@ public final class MainActivity extends StageActivity
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_SETTINGS:
if (RESULT_OK == resultCode) {
refreshTopScene();
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
}
@@ -189,7 +189,7 @@ public final class SettingsActivity extends EhPreferenceActivity {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_FRAGMENT) {
if (resultCode == RESULT_OK) {
setResult(RESULT_OK, data);
setResult(RESULT_OK);
}
} else {
super.onActivityResult(requestCode, resultCode, data);
@@ -314,6 +314,8 @@ public class DownloadFragment extends PreferenceFragment implements Preference.O
Toast.LENGTH_SHORT).show();
mDialog.dismiss();
getActivity().setResult(Activity.RESULT_OK);
}
@Override
@@ -16,14 +16,13 @@
package com.hippo.ehviewer.ui.fragment;
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import com.hippo.ehviewer.Constants;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.yorozuya.Messenger;
public class EhFragment extends PreferenceFragment
implements Preference.OnPreferenceChangeListener {
@@ -33,16 +32,21 @@ public class EhFragment extends PreferenceFragment
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.eh_settings);
Preference gallerySite = findPreference(Settings.KEY_GALLERY_SITE);
Preference listMode = findPreference(Settings.KEY_LIST_MODE);
gallerySite.setOnPreferenceChangeListener(this);
listMode.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String key = preference.getKey();
if (Settings.KEY_LIST_MODE.equals(key)) {
Messenger.getInstance().notify(Constants.MESSAGE_ID_LIST_MODE, null);
if (Settings.KEY_GALLERY_SITE.equals(key)) {
getActivity().setResult(Activity.RESULT_OK);
return true;
} else if (Settings.KEY_LIST_MODE.equals(key)) {
getActivity().setResult(Activity.RESULT_OK);
return true;
}
return true;
@@ -261,7 +261,6 @@ public class FavoritesScene extends BaseScene implements
contentLayout.getFastScroller().setOnDragHandlerListener(this);
mAdapter = new FavoritesAdapter(inflater, resources, mRecyclerView, Settings.getListMode());
mAdapter.register();
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setDrawSelectorOnTop(true);
mRecyclerView.hasFixedSize();
@@ -395,10 +394,6 @@ public class FavoritesScene extends BaseScene implements
mShowcaseView = null;
}
if (null != mAdapter) {
mAdapter.unregister();
mAdapter = null;
}
if (null != mHelper) {
if (1 == mHelper.getShownViewIndex()) {
mHasFirstRefresh = false;
@@ -410,6 +405,8 @@ public class FavoritesScene extends BaseScene implements
mRecyclerView = null;
}
mAdapter = null;
mSearchBar = null;
mFabLayout = null;
@@ -32,9 +32,7 @@ import android.widget.TextView;
import com.hippo.drawable.TriangleDrawable;
import com.hippo.easyrecyclerview.MarginItemDecoration;
import com.hippo.ehviewer.Constants;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
@@ -42,12 +40,11 @@ import com.hippo.ehviewer.widget.TileThumb;
import com.hippo.util.ApiHelper;
import com.hippo.widget.recyclerview.AutoGridLayoutManager;
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager;
import com.hippo.yorozuya.Messenger;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implements Messenger.Receiver {
abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> {
@IntDef({TYPE_LIST, TYPE_GRID})
@Retention(RetentionPolicy.SOURCE)
@@ -188,17 +185,4 @@ abstract class GalleryAdapter extends RecyclerView.Adapter<GalleryHolder> implem
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
}
}
public void register() {
Messenger.getInstance().register(Constants.MESSAGE_ID_LIST_MODE, this);
}
public void unregister() {
Messenger.getInstance().unregister(Constants.MESSAGE_ID_LIST_MODE, this);
}
@Override
public void onReceive(int id, Object obj) {
setType(Settings.getListMode());
}
}
@@ -263,6 +263,7 @@ public final class GalleryListScene extends BaseScene
Resources resources = context.getResources();
Drawable searchImage = DrawableManager.getDrawable(context, R.drawable.v_magnify_x24);
SpannableStringBuilder ssb = new SpannableStringBuilder(" ");
// TODO hint for e-hentai
ssb.append(resources.getString(R.string.gallery_list_search_bar_hint));
int textSize = (int) (searchBar.getEditTextTextSize() * 1.25);
if (searchImage != null) {
@@ -365,7 +366,6 @@ public final class GalleryListScene extends BaseScene
mAdapter = new GalleryListAdapter(inflater, resources,
mRecyclerView, Settings.getListMode());
mAdapter.register();
mRecyclerView.setSelector(RippleSalon.generateRippleDrawable(false));
mRecyclerView.setDrawSelectorOnTop(true);
mRecyclerView.hasFixedSize();
@@ -457,10 +457,6 @@ public final class GalleryListScene extends BaseScene
mSearchBarMover.cancelAnimation();
mSearchBarMover = null;
}
if (null != mAdapter) {
mAdapter.unregister();
mAdapter = null;
}
if (null != mHelper) {
if (1 == mHelper.getShownViewIndex()) {
mHasFirstRefresh = false;
@@ -472,6 +468,7 @@ public final class GalleryListScene extends BaseScene
mRecyclerView = null;
}
mAdapter = null;
mSearchLayout = null;
mSearchBar = null;
mFab = null;
@@ -309,7 +309,7 @@ public abstract class StageActivity extends EhActivity {
}
// Commit
transaction.commit();
transaction.commitAllowingStateLoss();
// New arguments
if (args != null && fragment instanceof SceneFragment) {
@@ -382,7 +382,7 @@ public abstract class StageActivity extends EhActivity {
transaction.add(getContainerViewId(), newScene, newTag);
// Commit
transaction.commit();
transaction.commitAllowingStateLoss();
// Check request
if (announcer.requestFrom != null) {
@@ -458,7 +458,7 @@ public abstract class StageActivity extends EhActivity {
}
// Commit
transaction.commit();
transaction.commitAllowingStateLoss();
if (!createNewScene && args != null) {
// TODO Call onNewArguments when view created ?
@@ -536,7 +536,7 @@ public abstract class StageActivity extends EhActivity {
transaction.attach(next);
}
transaction.remove(scene);
transaction.commit();
transaction.commitAllowingStateLoss();
// Remove tag
mSceneTagList.remove(index);
@@ -547,6 +547,22 @@ public abstract class StageActivity extends EhActivity {
}
}
public void refreshTopScene() {
int index = mSceneTagList.size() - 1;
if (index < 0) {
return;
}
String tag = mSceneTagList.get(index);
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment fragment = fragmentManager.findFragmentByTag(tag);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.detach(fragment);
transaction.attach(fragment);
transaction.commitAllowingStateLoss();
}
@Override
public void onBackPressed() {
int size = mSceneTagList.size();