Show gallery page instead of gallery detail for page links
This commit is contained in:
1 parent
dca1c6ccbd
commit
77a3cfcece
3 files changed
+76
-48
No files matched your search
@@ -29,6 +29,9 @@ import androidx.browser.customtabs.CustomTabColorSchemeParams;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrlOpener;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.client.parser.GalleryPageUrlParser;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.StageActivity;
|
||||
@@ -41,6 +44,10 @@ public final class UrlOpener {
|
||||
}
|
||||
|
||||
public static void openUrl(@NonNull Context context, String url, boolean ehUrl) {
|
||||
openUrl(context, url, ehUrl, null);
|
||||
}
|
||||
|
||||
public static void openUrl(@NonNull Context context, String url, boolean ehUrl, GalleryDetail galleryDetail) {
|
||||
if (TextUtils.isEmpty(url)) {
|
||||
return;
|
||||
}
|
||||
@@ -49,6 +56,30 @@ public final class UrlOpener {
|
||||
Uri uri = Uri.parse(url);
|
||||
|
||||
if (ehUrl) {
|
||||
if (galleryDetail != null) {
|
||||
GalleryPageUrlParser.Result result = GalleryPageUrlParser.parse(url);
|
||||
if (result != null) {
|
||||
if (result.gid == galleryDetail.gid) {
|
||||
intent = new Intent(context, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryDetail);
|
||||
intent.putExtra(GalleryActivity.KEY_PAGE, result.page);
|
||||
context.startActivity(intent);
|
||||
return;
|
||||
}
|
||||
} else if (url.startsWith("#c")) {
|
||||
try {
|
||||
intent = new Intent(context, GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryDetail);
|
||||
intent.putExtra(GalleryActivity.KEY_PAGE, Integer.parseInt(url.replace("#c", "")) - 1);
|
||||
context.startActivity(intent);
|
||||
return;
|
||||
} catch (NumberFormatException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
Announcer announcer = EhUrlOpener.parseUrl(url);
|
||||
if (null != announcer) {
|
||||
intent = new Intent(context, MainActivity.class);
|
||||
|
||||
@@ -34,7 +34,6 @@ import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.text.style.URLSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -50,7 +49,6 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.text.util.LinkifyCompat;
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -108,15 +106,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
public static final String KEY_GID = "gid";
|
||||
public static final String KEY_TOKEN = "token";
|
||||
public static final String KEY_COMMENT_LIST = "comment_list";
|
||||
public static final String KEY_GALLERY_DETAIL = "gallery_detail";
|
||||
private static final int TYPE_COMMENT = 0;
|
||||
private static final int TYPE_MORE = 1;
|
||||
private static final int TYPE_PROGRESS = 2;
|
||||
private long mApiUid;
|
||||
private String mApiKey;
|
||||
private long mGid;
|
||||
private String mToken;
|
||||
@Nullable
|
||||
private GalleryCommentList mCommentList;
|
||||
private GalleryDetail mGalleryDetail;
|
||||
@Nullable
|
||||
private EasyRecyclerView mRecyclerView;
|
||||
@Nullable
|
||||
@@ -157,12 +151,8 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
mApiUid = args.getLong(KEY_API_UID, -1L);
|
||||
mApiKey = args.getString(KEY_API_KEY);
|
||||
mGid = args.getLong(KEY_GID, -1L);
|
||||
mToken = args.getString(KEY_TOKEN, null);
|
||||
mCommentList = args.getParcelable(KEY_COMMENT_LIST);
|
||||
mShowAllComments = mCommentList != null && !mCommentList.hasMore;
|
||||
mGalleryDetail = args.getParcelable(KEY_GALLERY_DETAIL);
|
||||
mShowAllComments = mGalleryDetail != null && mGalleryDetail.comments != null && !mGalleryDetail.comments.hasMore;
|
||||
}
|
||||
|
||||
private void onInit() {
|
||||
@@ -170,22 +160,14 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onRestore(@NonNull Bundle savedInstanceState) {
|
||||
mApiUid = savedInstanceState.getLong(KEY_API_UID, -1L);
|
||||
mApiKey = savedInstanceState.getString(KEY_API_KEY);
|
||||
mGid = savedInstanceState.getLong(KEY_GID, -1L);
|
||||
mToken = savedInstanceState.getString(KEY_TOKEN, null);
|
||||
mCommentList = savedInstanceState.getParcelable(KEY_COMMENT_LIST);
|
||||
mShowAllComments = mCommentList != null && !mCommentList.hasMore;
|
||||
mGalleryDetail = savedInstanceState.getParcelable(KEY_GALLERY_DETAIL);
|
||||
mShowAllComments = mGalleryDetail != null && mGalleryDetail.comments != null && !mGalleryDetail.comments.hasMore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putLong(KEY_API_UID, mApiUid);
|
||||
outState.putString(KEY_API_KEY, mApiKey);
|
||||
outState.putLong(KEY_GID, mGid);
|
||||
outState.putString(KEY_TOKEN, mToken);
|
||||
outState.putParcelable(KEY_COMMENT_LIST, mCommentList);
|
||||
outState.putParcelable(KEY_GALLERY_DETAIL, mGalleryDetail);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -364,7 +346,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
EhRequest request = new EhRequest()
|
||||
.setMethod(EhClient.METHOD_VOTE_COMMENT)
|
||||
.setArgs(mApiUid, mApiKey, mGid, mToken, id, vote)
|
||||
.setArgs(mGalleryDetail.apiUid, mGalleryDetail.apiKey, mGalleryDetail.gid, mGalleryDetail.token, id, vote)
|
||||
.setCallback(new VoteCommentListener(context,
|
||||
activity.getStageId(), getTag()));
|
||||
EhApplication.getEhClient(context).execute(request);
|
||||
@@ -423,11 +405,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
private void showCommentDialog(int position) {
|
||||
final Context context = getContext();
|
||||
if (context == null || mCommentList == null || mCommentList.comments == null || position >= mCommentList.comments.length || position < 0) {
|
||||
if (context == null || mGalleryDetail == null || mGalleryDetail.comments == null || mGalleryDetail.comments.comments == null || position >= mGalleryDetail.comments.comments.length || position < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
final GalleryComment comment = mCommentList.comments[position];
|
||||
final GalleryComment comment = mGalleryDetail.comments.comments[position];
|
||||
List<String> menu = new ArrayList<>();
|
||||
final IntList menuId = new IntList();
|
||||
Resources resources = context.getResources();
|
||||
@@ -488,7 +470,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
commentHolder.comment.clearCurrentSpan();
|
||||
|
||||
if (span instanceof URLSpan) {
|
||||
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true);
|
||||
UrlOpener.openUrl(activity, ((URLSpan) span).getURL(), true, mGalleryDetail);
|
||||
} else {
|
||||
showCommentDialog(position);
|
||||
}
|
||||
@@ -516,7 +498,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCommentList == null || mCommentList.comments == null || mCommentList.comments.length <= 0) {
|
||||
if (mGalleryDetail == null || mGalleryDetail.comments == null || mGalleryDetail.comments.comments == null || mGalleryDetail.comments.comments.length <= 0) {
|
||||
mViewTransition.showView(1, animation);
|
||||
} else {
|
||||
mViewTransition.showView(0, animation);
|
||||
@@ -650,8 +632,8 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
@Nullable
|
||||
private String getGalleryDetailUrl() {
|
||||
if (mGid != -1 && mToken != null) {
|
||||
return EhUrl.getGalleryDetailUrl(mGid, mToken, 0, mShowAllComments);
|
||||
if (mGalleryDetail != null && mGalleryDetail.gid != -1 && mGalleryDetail.token != null) {
|
||||
return EhUrl.getGalleryDetailUrl(mGalleryDetail.gid, mGalleryDetail.token, 0, mShowAllComments);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -707,13 +689,13 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onRefreshGallerySuccess(GalleryCommentList result) {
|
||||
if (mAdapter == null) {
|
||||
if (mGalleryDetail == null || mAdapter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mRefreshLayout.setRefreshing(false);
|
||||
mRefreshingComments = false;
|
||||
mCommentList = result;
|
||||
mGalleryDetail.comments = result;
|
||||
mAdapter.notifyDataSetChanged();
|
||||
|
||||
updateView(true);
|
||||
@@ -737,11 +719,11 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onCommentGallerySuccess(GalleryCommentList result) {
|
||||
if (mAdapter == null) {
|
||||
if (mGalleryDetail == null || mAdapter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mCommentList = result;
|
||||
mGalleryDetail.comments = result;
|
||||
mAdapter.notifyDataSetChanged();
|
||||
Bundle re = new Bundle();
|
||||
re.putParcelable(KEY_COMMENT_LIST, result);
|
||||
@@ -756,13 +738,13 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onVoteCommentSuccess(VoteCommentParser.Result result) {
|
||||
if (mAdapter == null || mCommentList == null || mCommentList.comments == null) {
|
||||
if (mAdapter == null || mGalleryDetail.comments == null || mGalleryDetail.comments.comments == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int position = -1;
|
||||
for (int i = 0, n = mCommentList.comments.length; i < n; i++) {
|
||||
GalleryComment comment = mCommentList.comments[i];
|
||||
for (int i = 0, n = mGalleryDetail.comments.comments.length; i < n; i++) {
|
||||
GalleryComment comment = mGalleryDetail.comments.comments[i];
|
||||
if (comment.id == result.id) {
|
||||
position = i;
|
||||
break;
|
||||
@@ -775,7 +757,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
// Update comment
|
||||
GalleryComment comment = mCommentList.comments[position];
|
||||
GalleryComment comment = mGalleryDetail.comments.comments[position];
|
||||
comment.score = result.score;
|
||||
if (result.expectVote > 0) {
|
||||
comment.voteUpEd = 0 != result.vote;
|
||||
@@ -788,7 +770,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
mAdapter.notifyItemChanged(position);
|
||||
|
||||
Bundle re = new Bundle();
|
||||
re.putParcelable(KEY_COMMENT_LIST, mCommentList);
|
||||
re.putParcelable(KEY_COMMENT_LIST, mGalleryDetail.comments);
|
||||
setResult(SceneFragment.RESULT_OK, re);
|
||||
}
|
||||
|
||||
@@ -1021,7 +1003,7 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CommentHolder holder, int position) {
|
||||
Context context = getContext();
|
||||
if (context == null || mCommentList == null) {
|
||||
if (context == null || mGalleryDetail == null || mGalleryDetail.comments == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1031,24 +1013,24 @@ public final class GalleryCommentsScene extends ToolbarScene
|
||||
|
||||
|
||||
if (holder instanceof ActualCommentHolder) {
|
||||
((ActualCommentHolder) holder).bind(mCommentList.comments[position]);
|
||||
((ActualCommentHolder) holder).bind(mGalleryDetail.comments.comments[position]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mCommentList == null || mCommentList.comments == null) {
|
||||
if (mGalleryDetail == null || mGalleryDetail.comments == null || mGalleryDetail.comments.comments == null) {
|
||||
return 0;
|
||||
} else if (mCommentList.hasMore) {
|
||||
return mCommentList.comments.length + 1;
|
||||
} else if (mGalleryDetail.comments.hasMore) {
|
||||
return mGalleryDetail.comments.comments.length + 1;
|
||||
} else {
|
||||
return mCommentList.comments.length;
|
||||
return mGalleryDetail.comments.comments.length;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (position >= mCommentList.comments.length) {
|
||||
if (position >= mGalleryDetail.comments.comments.length) {
|
||||
return mRefreshingComments ? TYPE_PROGRESS : TYPE_MORE;
|
||||
} else {
|
||||
return TYPE_COMMENT;
|
||||
|
||||
@@ -66,6 +66,7 @@ import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.transition.TransitionInflater;
|
||||
|
||||
import com.google.android.material.progressindicator.CircularProgressIndicator;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.hippo.app.EditTextDialogBuilder;
|
||||
import com.hippo.beerbelly.BeerBelly;
|
||||
import com.hippo.ehviewer.AppConfig;
|
||||
@@ -256,6 +257,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
private GalleryInfo mGalleryInfo;
|
||||
private long mGid;
|
||||
private String mToken;
|
||||
private int mPage;
|
||||
@Nullable
|
||||
private GalleryDetail mGalleryDetail;
|
||||
private int mRequestId = IntIdGenerator.INVALID_ID;
|
||||
@@ -354,6 +356,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
} else if (ACTION_GID_TOKEN.equals(action)) {
|
||||
mGid = args.getLong(KEY_GID);
|
||||
mToken = args.getString(KEY_TOKEN);
|
||||
mPage = args.getInt(KEY_PAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -881,6 +884,17 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
if (gd == null) {
|
||||
return;
|
||||
}
|
||||
if (mPage != 0) {
|
||||
Snackbar.make(requireActivity().findViewById(R.id.snackbar), getString(R.string.read_from, mPage), Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.read, v -> {
|
||||
Intent intent = new Intent(requireContext(), GalleryActivity.class);
|
||||
intent.setAction(GalleryActivity.ACTION_EH);
|
||||
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, mGalleryDetail);
|
||||
intent.putExtra(GalleryActivity.KEY_PAGE, mPage);
|
||||
startActivity(intent);
|
||||
})
|
||||
.show();
|
||||
}
|
||||
if (mThumb == null || mTitle == null || mUploader == null || mCategory == null ||
|
||||
mLanguage == null || mPages == null || mSize == null || mPosted == null ||
|
||||
mFavoredTimes == null || mRatingText == null || mRating == null || mTorrent == null || mNewerVersion == null) {
|
||||
@@ -1338,6 +1352,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
args.putLong(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
|
||||
args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token);
|
||||
args.putParcelable(GalleryCommentsScene.KEY_COMMENT_LIST, mGalleryDetail.comments);
|
||||
args.putParcelable(GalleryCommentsScene.KEY_GALLERY_DETAIL, mGalleryDetail);
|
||||
startScene(new Announcer(GalleryCommentsScene.class)
|
||||
.setArgs(args)
|
||||
.setRequestCode(this, REQUEST_CODE_COMMENT_GALLERY));
|
||||
|
||||
Reference in new issue
Block a user