Add favorites info
This commit is contained in:
1 parent
d2553b39a6
commit
d7e2adaef4
4 files changed
+106
-11
No files matched your search
@@ -89,6 +89,7 @@ import com.hippo.yorozuya.ViewUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// TODO Bug for FavoritesScene and GalleryListScene, if list view of SearchBar expand first, RecyclerView padding top will be wrong
|
||||
// TODO Get favorite, modify favorite, add favorite, what a mess!
|
||||
public class FavoritesScene extends BaseScene implements
|
||||
EasyRecyclerView.OnItemClickListener, EasyRecyclerView.OnItemLongClickListener,
|
||||
@@ -98,6 +99,11 @@ public class FavoritesScene extends BaseScene implements
|
||||
private static final long ANIMATE_TIME = 300L;
|
||||
|
||||
private static final String KEY_URL_BUILDER = "url_builder";
|
||||
private static final String KEY_SEARCH_MODE = "search_mode";
|
||||
private static final String KEY_HAS_FIRST_REFRESH = "has_first_refresh";
|
||||
private static final String KEY_FAV_COUNT_ARRAY = "fav_count_array";
|
||||
private static final String KEY_ALL_COUNT = "all_count";
|
||||
private static final String KEY_ALL_LIMIT = "all_limit";
|
||||
|
||||
@Nullable
|
||||
@ViewLifeCircle
|
||||
@@ -134,11 +140,20 @@ public class FavoritesScene extends BaseScene implements
|
||||
private EhClient mClient;
|
||||
@Nullable
|
||||
@WholeLifeCircle
|
||||
private String[] mFavCat;
|
||||
private String[] mFavCatArray;
|
||||
@Nullable
|
||||
@WholeLifeCircle
|
||||
private FavListUrlBuilder mUrlBuilder;
|
||||
|
||||
public int[] countArray; // Size 10
|
||||
public int current; // -1 for error
|
||||
public int limit; // -1 for error
|
||||
|
||||
@Nullable
|
||||
private int[] mFavCountArray;
|
||||
private int mAllCount = -1;
|
||||
private int mAllLimit = -1;
|
||||
|
||||
private boolean mHasFirstRefresh;
|
||||
private boolean mSearchMode;
|
||||
// Avoid unnecessary search bar update
|
||||
@@ -168,7 +183,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mClient = EhApplication.getEhClient(getContext());
|
||||
mFavCat = Settings.getFavCat();
|
||||
mFavCatArray = Settings.getFavCat();
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
onInit();
|
||||
@@ -180,6 +195,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
private void onInit() {
|
||||
mUrlBuilder = new FavListUrlBuilder();
|
||||
mUrlBuilder.setFavCat(Settings.getRecentFavCat());
|
||||
mSearchMode = false;
|
||||
}
|
||||
|
||||
private void onRestore(Bundle savedInstanceState) {
|
||||
@@ -187,12 +203,22 @@ public class FavoritesScene extends BaseScene implements
|
||||
if (mUrlBuilder == null) {
|
||||
mUrlBuilder = new FavListUrlBuilder();
|
||||
}
|
||||
mSearchMode = savedInstanceState.getBoolean(KEY_SEARCH_MODE);
|
||||
mHasFirstRefresh = savedInstanceState.getBoolean(KEY_HAS_FIRST_REFRESH);
|
||||
mFavCountArray = savedInstanceState.getIntArray(KEY_FAV_COUNT_ARRAY);
|
||||
mAllCount = savedInstanceState.getInt(KEY_ALL_COUNT);
|
||||
mAllLimit = savedInstanceState.getInt(KEY_ALL_LIMIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelable(KEY_URL_BUILDER, mUrlBuilder);
|
||||
outState.putBoolean(KEY_SEARCH_MODE, mSearchMode);
|
||||
outState.putBoolean(KEY_HAS_FIRST_REFRESH, mHasFirstRefresh);
|
||||
outState.putIntArray(KEY_FAV_COUNT_ARRAY, mFavCountArray);
|
||||
outState.putInt(KEY_ALL_COUNT, mAllCount);
|
||||
outState.putInt(KEY_ALL_LIMIT, mAllLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -200,7 +226,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
super.onDestroy();
|
||||
|
||||
mClient = null;
|
||||
mFavCat = null;
|
||||
mFavCatArray = null;
|
||||
mUrlBuilder = null;
|
||||
}
|
||||
|
||||
@@ -251,6 +277,12 @@ public class FavoritesScene extends BaseScene implements
|
||||
mFabLayout.setHidePrimaryFab(true);
|
||||
mFabLayout.setOnClickFabListener(this);
|
||||
|
||||
// Restore search mode
|
||||
if (mSearchMode) {
|
||||
mSearchMode = false;
|
||||
enterSearchMode(false);
|
||||
}
|
||||
|
||||
// Only refresh for the first time
|
||||
if (!mHasFirstRefresh) {
|
||||
mHasFirstRefresh = true;
|
||||
@@ -260,10 +292,10 @@ public class FavoritesScene extends BaseScene implements
|
||||
return view;
|
||||
}
|
||||
|
||||
// keyword of mUrlBuilder, fav cat of mUrlBuilder, mFavCat.
|
||||
// keyword of mUrlBuilder, fav cat of mUrlBuilder, mFavCatArray.
|
||||
// They changed, call it
|
||||
private void updateSearchBar() {
|
||||
if (mUrlBuilder == null || mSearchBar == null || mFavCat == null) {
|
||||
if (mUrlBuilder == null || mSearchBar == null || mFavCatArray == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -271,7 +303,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
int favCat = mUrlBuilder.getFavCat();
|
||||
String favCatName;
|
||||
if (favCat >= 0 && favCat < 10) {
|
||||
favCatName = mFavCat[favCat];
|
||||
favCatName = mFavCatArray[favCat];
|
||||
} else if (favCat == FavListUrlBuilder.FAV_CAT_LOCAL) {
|
||||
favCatName = getString(R.string.local_favorites);
|
||||
} else {
|
||||
@@ -331,6 +363,22 @@ public class FavoritesScene extends BaseScene implements
|
||||
mOldKeyword = null;
|
||||
}
|
||||
|
||||
private void showFavoritesInfoDialog() {
|
||||
if (mFavCatArray == null || mFavCountArray == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(mAllCount).append("/").append(mAllLimit).append("\n");
|
||||
for (int i = 0, n = 10; i < n; i++) {
|
||||
sb.append(mFavCatArray[i]).append(": ").append(mFavCountArray[i]).append("\n");
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.favorites_info)
|
||||
.setMessage(sb.toString())
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateDrawerView(LayoutInflater inflater,
|
||||
@@ -345,6 +393,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_info:
|
||||
showFavoritesInfoDialog();
|
||||
return true;
|
||||
case R.id.action_default_favorites_slot:
|
||||
String[] items = new String[12];
|
||||
items[0] = getString(R.string.let_me_select);
|
||||
@@ -368,8 +419,8 @@ public class FavoritesScene extends BaseScene implements
|
||||
mDrawerList = new ArrayList<>(12);
|
||||
mDrawerList.add(getString(R.string.local_favorites));
|
||||
mDrawerList.add(getString(R.string.cloud_favorites));
|
||||
if (mFavCat != null) {
|
||||
for (String favCat: mFavCat) {
|
||||
if (mFavCatArray != null) {
|
||||
for (String favCat: mFavCatArray) {
|
||||
mDrawerList.add(favCat);
|
||||
}
|
||||
}
|
||||
@@ -686,9 +737,9 @@ public class FavoritesScene extends BaseScene implements
|
||||
if (mHelper != null && mSearchBarMover != null &&
|
||||
mHelper.isCurrentTask(taskId)) {
|
||||
|
||||
if (mFavCat != null && mDrawerList != null) {
|
||||
if (mFavCatArray != null && mDrawerList != null) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
mFavCat[i] = result.catArray[i];
|
||||
mFavCatArray[i] = result.catArray[i];
|
||||
mDrawerList.set(i + 2, result.catArray[i]);
|
||||
}
|
||||
|
||||
@@ -697,6 +748,14 @@ public class FavoritesScene extends BaseScene implements
|
||||
}
|
||||
}
|
||||
|
||||
mFavCountArray = result.countArray;
|
||||
if (result.current != -1) {
|
||||
mAllCount = result.current;
|
||||
}
|
||||
if (result.limit != -1) {
|
||||
mAllLimit = result.limit;
|
||||
}
|
||||
|
||||
updateSearchBar();
|
||||
mHelper.setPages(taskId, result.pages);
|
||||
mHelper.onGetPageData(taskId, result.galleryInfoList);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:height="24dp"
|
||||
android:width="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@color/primary_drawable_dark"
|
||||
android:pathData="@string/pd_info"/>
|
||||
|
||||
</vector>
|
||||
@@ -19,10 +19,16 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_info"
|
||||
android:icon="@drawable/v_info_dark_x24"
|
||||
android:title="@string/favorites_info"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_default_favorites_slot"
|
||||
android:icon="@drawable/v_heart_box_dark_x24"
|
||||
android:title="@string/default_favorites_slot"
|
||||
app:showAsAction="always"/>
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
</menu>
|
||||
@@ -328,6 +328,7 @@
|
||||
<string name="move_favorites_dialog_title">Move favorites</string>
|
||||
<string name="default_favorites_slot">Default favorites slot</string>
|
||||
<string name="let_me_select">Let me select</string>
|
||||
<string name="favorites_info">Favorites info</string>
|
||||
|
||||
<!-- Progress Scene -->
|
||||
<string name="error_something_wrong_happened">Something wrong happened</string>
|
||||
|
||||
Reference in new issue
Block a user