Add toplist
This commit is contained in:
9 files changed
+150
-14
No files matched your search
@@ -47,6 +47,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
public static final int MODE_WHATS_HOT = 0x3;
|
||||
public static final int MODE_IMAGE_SEARCH = 0x4;
|
||||
public static final int MODE_SUBSCRIPTION = 0x5;
|
||||
public static final int MODE_TOPLIST = 0x6;
|
||||
public static final int DEFAULT_ADVANCE = AdvanceSearchTable.SNAME | AdvanceSearchTable.STAGS;
|
||||
public static final int DEFAULT_MIN_RATING = 2;
|
||||
public static final Creator<ListUrlBuilder> CREATOR = new Creator<ListUrlBuilder>() {
|
||||
@@ -582,6 +583,18 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
return EhUrl.getPopularUrl();
|
||||
case MODE_IMAGE_SEARCH:
|
||||
return EhUrl.getImageSearchUrl();
|
||||
case MODE_TOPLIST:
|
||||
StringBuilder sb = new StringBuilder(EhUrl.getHost());
|
||||
sb.append("toplist.php?tl=");
|
||||
try {
|
||||
sb.append(URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// Empty
|
||||
}
|
||||
if (mPageIndex != 0) {
|
||||
sb.append('/').append(mPageIndex);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,7 +619,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
dest.writeByte(mShowExpunged ? (byte) 1 : (byte) 0);
|
||||
}
|
||||
|
||||
@IntDef({MODE_NORMAL, MODE_UPLOADER, MODE_TAG, MODE_WHATS_HOT, MODE_IMAGE_SEARCH, MODE_SUBSCRIPTION})
|
||||
@IntDef({MODE_NORMAL, MODE_UPLOADER, MODE_TAG, MODE_WHATS_HOT, MODE_IMAGE_SEARCH, MODE_SUBSCRIPTION, MODE_TOPLIST})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
private @interface Mode {
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
@@ -34,6 +35,7 @@ public final class GalleryListUrlParser {
|
||||
private static final String PATH_NORMAL = "/";
|
||||
private static final String PATH_UPLOADER = "/uploader/";
|
||||
private static final String PATH_TAG = "/tag/";
|
||||
private static final String PATH_TOPLIST = "/toplist.php";
|
||||
|
||||
public static ListUrlBuilder parse(String urlStr) {
|
||||
URL url;
|
||||
@@ -59,6 +61,8 @@ public final class GalleryListUrlParser {
|
||||
return parseUploader(path);
|
||||
} else if (path.startsWith(PATH_TAG)) {
|
||||
return parseTag(path);
|
||||
} else if (path.startsWith(PATH_TOPLIST)) {
|
||||
return parseToplist(urlStr);
|
||||
} else if (path.startsWith("/")) {
|
||||
int category;
|
||||
try {
|
||||
@@ -131,4 +135,25 @@ public final class GalleryListUrlParser {
|
||||
builder.setKeyword(tag);
|
||||
return builder;
|
||||
}
|
||||
|
||||
// TODO get page
|
||||
private static ListUrlBuilder parseToplist(String path) {
|
||||
Uri uri = Uri.parse(path);
|
||||
|
||||
if (uri == null || TextUtils.isEmpty(uri.getQueryParameter("tl"))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int tl = Integer.parseInt(uri.getQueryParameter("tl"));
|
||||
|
||||
if (tl > 15 || tl < 11) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ListUrlBuilder builder = new ListUrlBuilder();
|
||||
builder.setMode(ListUrlBuilder.MODE_TOPLIST);
|
||||
builder.setKeyword(String.valueOf(tl));
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -487,6 +487,21 @@ public final class MainActivity extends StageActivity
|
||||
}
|
||||
}
|
||||
|
||||
public void recreateDrawerView(SceneFragment scene) {
|
||||
if (scene instanceof BaseScene && mRightDrawer != null && mDrawerLayout != null) {
|
||||
BaseScene baseScene = (BaseScene) scene;
|
||||
mRightDrawer.removeAllViews();
|
||||
View drawerView = baseScene.createDrawerView(
|
||||
baseScene.getLayoutInflater2(), mRightDrawer, null);
|
||||
if (drawerView != null) {
|
||||
mRightDrawer.addView(drawerView);
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, Gravity.RIGHT);
|
||||
} else {
|
||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.RIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSceneViewDestroyed(SceneFragment scene) {
|
||||
super.onSceneViewDestroyed(scene);
|
||||
@@ -626,6 +641,11 @@ public final class MainActivity extends StageActivity
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_WHATS_HOT);
|
||||
startSceneFirstly(new Announcer(GalleryListScene.class)
|
||||
.setArgs(args));
|
||||
} else if (id == R.id.nav_toplist) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryListScene.KEY_ACTION, GalleryListScene.ACTION_TOP_LIST);
|
||||
startSceneFirstly(new Announcer(GalleryListScene.class)
|
||||
.setArgs(args));
|
||||
} else if (id == R.id.nav_favourite) {
|
||||
startScene(new Announcer(FavoritesScene.class));
|
||||
} else if (id == R.id.nav_history) {
|
||||
|
||||
@@ -151,6 +151,10 @@ public abstract class BaseScene extends SceneFragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void recreateDrawerView() {
|
||||
((MainActivity)requireActivity()).recreateDrawerView(this);
|
||||
}
|
||||
|
||||
public final View createDrawerView(LayoutInflater inflater,
|
||||
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
drawerView = onCreateDrawerView(inflater, container, savedInstanceState);
|
||||
|
||||
@@ -126,6 +126,7 @@ public final class GalleryListScene extends BaseScene
|
||||
public final static String ACTION_HOMEPAGE = "action_homepage";
|
||||
public final static String ACTION_SUBSCRIPTION = "action_subscription";
|
||||
public final static String ACTION_WHATS_HOT = "action_whats_hot";
|
||||
public final static String ACTION_TOP_LIST = "action_top_list";
|
||||
public final static String ACTION_LIST_URL_BUILDER = "action_list_url_builder";
|
||||
public final static String KEY_LIST_URL_BUILDER = "list_url_builder";
|
||||
public final static String KEY_HAS_FIRST_REFRESH = "has_first_refresh";
|
||||
@@ -218,6 +219,7 @@ public final class GalleryListScene extends BaseScene
|
||||
private DownloadManager.DownloadInfoListener mDownloadInfoListener;
|
||||
private FavouriteStatusRouter mFavouriteStatusRouter;
|
||||
private FavouriteStatusRouter.Listener mFavouriteStatusRouterListener;
|
||||
private boolean mIsTopList = false;
|
||||
|
||||
@Nullable
|
||||
private static String getSuitableTitleForUrlBuilder(
|
||||
@@ -243,6 +245,18 @@ public final class GalleryListScene extends BaseScene
|
||||
return resources.getString(R.string.subscription);
|
||||
} else if (ListUrlBuilder.MODE_WHATS_HOT == urlBuilder.getMode()) {
|
||||
return resources.getString(R.string.whats_hot);
|
||||
} else if (ListUrlBuilder.MODE_TOPLIST == urlBuilder.getMode()) {
|
||||
switch (urlBuilder.getKeyword()) {
|
||||
case "11":
|
||||
return resources.getString(R.string.toplist_alltime);
|
||||
case "12":
|
||||
return resources.getString(R.string.toplist_pastyear);
|
||||
case "13":
|
||||
return resources.getString(R.string.toplist_pastmonth);
|
||||
case "15":
|
||||
return resources.getString(R.string.toplist_yesterday);
|
||||
}
|
||||
return null;
|
||||
} else if (!TextUtils.isEmpty(keyword)) {
|
||||
return keyword;
|
||||
} else if (MathUtils.hammingWeight(category) == 1) {
|
||||
@@ -282,6 +296,10 @@ public final class GalleryListScene extends BaseScene
|
||||
} else if (ACTION_WHATS_HOT.equals(action)) {
|
||||
mUrlBuilder.reset();
|
||||
mUrlBuilder.setMode(ListUrlBuilder.MODE_WHATS_HOT);
|
||||
} else if (ACTION_TOP_LIST.equals(action)) {
|
||||
mUrlBuilder.reset();
|
||||
mUrlBuilder.setMode(ListUrlBuilder.MODE_TOPLIST);
|
||||
mUrlBuilder.setKeyword("11");
|
||||
} else if (ACTION_LIST_URL_BUILDER.equals(action)) {
|
||||
ListUrlBuilder builder = args.getParcelable(KEY_LIST_URL_BUILDER);
|
||||
if (builder != null) {
|
||||
@@ -472,13 +490,19 @@ public final class GalleryListScene extends BaseScene
|
||||
String keyword = builder.getKeyword();
|
||||
int category = builder.getCategory();
|
||||
|
||||
boolean isTopList = builder.getMode() == ListUrlBuilder.MODE_TOPLIST;
|
||||
if (isTopList != mIsTopList) {
|
||||
mIsTopList = isTopList;
|
||||
recreateDrawerView();
|
||||
}
|
||||
|
||||
// Update normal search mode
|
||||
mSearchLayout.setNormalSearchMode(builder.getMode() == ListUrlBuilder.MODE_SUBSCRIPTION
|
||||
? R.id.search_subscription_search
|
||||
: R.id.search_normal_search);
|
||||
|
||||
// Update search edit text
|
||||
if (!TextUtils.isEmpty(keyword) && null != mSearchBar) {
|
||||
if (!TextUtils.isEmpty(keyword) && null != mSearchBar && !mIsTopList) {
|
||||
if (builder.getMode() == ListUrlBuilder.MODE_TAG) {
|
||||
keyword = wrapTagKeyword(keyword);
|
||||
}
|
||||
@@ -505,6 +529,8 @@ public final class GalleryListScene extends BaseScene
|
||||
checkedItemId = R.id.nav_subscription;
|
||||
} else if (ListUrlBuilder.MODE_WHATS_HOT == builder.getMode()) {
|
||||
checkedItemId = R.id.nav_whats_hot;
|
||||
} else if (ListUrlBuilder.MODE_TOPLIST == builder.getMode()) {
|
||||
checkedItemId = R.id.nav_toplist;
|
||||
} else {
|
||||
checkedItemId = 0;
|
||||
}
|
||||
@@ -777,8 +803,12 @@ public final class GalleryListScene extends BaseScene
|
||||
dragDropManager.attachRecyclerView(recyclerView);
|
||||
mQuickSearchList = EhDB.getAllQuickSearch();
|
||||
tip.setText(R.string.quick_search_tip);
|
||||
toolbar.setTitle(R.string.quick_search);
|
||||
toolbar.inflateMenu(R.menu.drawer_gallery_list);
|
||||
if (mIsTopList) {
|
||||
toolbar.setTitle(R.string.toplist);
|
||||
} else {
|
||||
toolbar.setTitle(R.string.quick_search);
|
||||
}
|
||||
if (!mIsTopList) toolbar.inflateMenu(R.menu.drawer_gallery_list);
|
||||
toolbar.setOnMenuItemClickListener(item -> {
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_add) {
|
||||
@@ -791,7 +821,7 @@ public final class GalleryListScene extends BaseScene
|
||||
return true;
|
||||
});
|
||||
|
||||
if (0 == mQuickSearchList.size()) {
|
||||
if (0 == mQuickSearchList.size() && !mIsTopList) {
|
||||
tip.setVisibility(View.VISIBLE);
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
} else {
|
||||
@@ -1526,7 +1556,7 @@ public final class GalleryListScene extends BaseScene
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull QsDrawerHolder holder, int position) {
|
||||
if (mQuickSearchList != null) {
|
||||
if (mQuickSearchList != null && !mIsTopList) {
|
||||
holder.key.setText(mQuickSearchList.get(position).getName());
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (null == mHelper || null == mUrlBuilder) {
|
||||
@@ -1568,22 +1598,39 @@ public final class GalleryListScene extends BaseScene
|
||||
});
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
int[] keywords = {11, 12, 13, 15};
|
||||
int[] toplists = {R.string.toplist_alltime, R.string.toplist_pastyear, R.string.toplist_pastmonth, R.string.toplist_yesterday};
|
||||
holder.key.setText(getString(toplists[position]));
|
||||
holder.option.setVisibility(View.GONE);
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
if (null == mHelper || null == mUrlBuilder) {
|
||||
return;
|
||||
}
|
||||
|
||||
mUrlBuilder.setKeyword(String.valueOf(keywords[position]));
|
||||
mUrlBuilder.setPageIndex(0);
|
||||
onUpdateUrlBuilder();
|
||||
mHelper.refresh();
|
||||
setState(STATE_NORMAL);
|
||||
closeDrawer(Gravity.RIGHT);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return mQuickSearchList != null ? mQuickSearchList.get(position).getId() : 0;
|
||||
return !mIsTopList ? mQuickSearchList != null ? mQuickSearchList.get(position).getId() : 0 : position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mQuickSearchList != null ? mQuickSearchList.size() : 0;
|
||||
return !mIsTopList ? mQuickSearchList != null ? mQuickSearchList.size() : 0 : 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCheckCanStartDrag(@NonNull QsDrawerHolder holder, int position, int x, int y) {
|
||||
return x > holder.option.getX() && y > holder.option.getY();
|
||||
return !mIsTopList && x > holder.option.getX() && y > holder.option.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1652,8 +1699,8 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
|
||||
private class GalleryDetailUrlSuggestion extends UrlSuggestion {
|
||||
private long mGid;
|
||||
private String mToken;
|
||||
private final long mGid;
|
||||
private final String mToken;
|
||||
|
||||
private GalleryDetailUrlSuggestion(long gid, String token) {
|
||||
mGid = gid;
|
||||
@@ -1671,9 +1718,9 @@ public final class GalleryListScene extends BaseScene
|
||||
}
|
||||
|
||||
private class GalleryPageUrlSuggestion extends UrlSuggestion {
|
||||
private long mGid;
|
||||
private String mPToken;
|
||||
private int mPage;
|
||||
private final long mGid;
|
||||
private final String mPToken;
|
||||
private final int mPage;
|
||||
|
||||
private GalleryPageUrlSuggestion(long gid, String pToken, int page) {
|
||||
mGid = gid;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M2,17h2v0.5L3,17.5v1h1v0.5L2,19v1h3v-4L2,16v1zM3,8h1L4,4L2,4v1h1v3zM2,11h1.8L2,13.1v0.9h3v-1L3.2,13L5,10.9L5,10L2,10v1zM7,5v2h14L21,5L7,5zM7,19h14v-2L7,17v2zM7,13h14v-2L7,11v2z"/>
|
||||
</vector>
|
||||
@@ -32,6 +32,11 @@
|
||||
android:icon="@drawable/v_fire_black_x24"
|
||||
android:title="@string/whats_hot" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_toplist"
|
||||
android:icon="@drawable/ic_baseline_format_list_numbered_24"
|
||||
android:title="@string/toplist" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_favourite"
|
||||
android:icon="@drawable/v_heart_black_x24"
|
||||
|
||||
@@ -721,4 +721,11 @@
|
||||
<string name="download_start_all_reversed">全部开始(倒序)</string>
|
||||
<string name="settings_download_download_delay">下载延时</string>
|
||||
<string name="settings_download_download_delay_summary">每次下载延时 %s 毫秒</string>
|
||||
|
||||
<string name="no_browser_installed">请安装一个浏览器。</string>
|
||||
<string name="toplist_alltime">从始至终</string>
|
||||
<string name="toplist_pastyear">过去一年</string>
|
||||
<string name="toplist_pastmonth">过去一个月</string>
|
||||
<string name="toplist_yesterday">昨日</string>
|
||||
<string name="toplist">排行</string>
|
||||
</resources>
|
||||
@@ -787,4 +787,9 @@
|
||||
<string name="download_start_all_reversed">Start all (reversed)</string>
|
||||
|
||||
<string name="no_browser_installed">Just install a browser please.</string>
|
||||
<string name="toplist_alltime">All-Time</string>
|
||||
<string name="toplist_pastyear">Past Year</string>
|
||||
<string name="toplist_pastmonth">Past Month</string>
|
||||
<string name="toplist_yesterday">Yesterday</string>
|
||||
<string name="toplist">Toplist</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user