Download torrent from ehtracker.org

This commit is contained in:
NekoInverter committed 2021-01-01 17:40:56 +08:00
1 parent ad2ecf54cd
commit 8513a78c01
1 file changed
+16 -25
@@ -458,7 +458,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
}
@Override
public void onSaveInstanceState(Bundle outState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
if (mAction != null) {
@@ -923,7 +923,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
bindPreviews(gd);
}
@SuppressWarnings("deprecation")
private void bindTags(GalleryTagGroup[] tagGroups) {
Context context = getContext2();
LayoutInflater inflater = getLayoutInflater2();
@@ -1367,7 +1366,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, galleryInfo);
intent.putExtra(GalleryActivity.KEY_PAGE, index);
startActivity(intent);
return;
}
}
}
@@ -1451,19 +1449,14 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
return;
}
int id = menuId.get(which);
switch (id) {
case R.id.vote_up:
voteTag(tag, 1);
break;
case R.id.vote_down:
voteTag(tag, -1);
break;
case R.id.show_definition:
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false);
break;
case R.id.add_filter:
showFilterTagDialog(tag);
break;
if (id == R.id.vote_up) {
voteTag(tag, 1);
} else if (id == R.id.vote_down) {
voteTag(tag, -1);
} else if (id == R.id.show_definition) {
UrlOpener.openUrl(context, EhUrl.getTagDefinitionUrl(tag2), false);
} else if (id == R.id.add_filter) {
showFilterTagDialog(tag);
}
}).show();
}
@@ -1479,7 +1472,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
.setMethod(EhClient.METHOD_VOTE_TAG)
.setArgs(mGalleryDetail.apiUid, mGalleryDetail.apiKey, mGalleryDetail.gid, mGalleryDetail.token, tag, vote)
.setCallback(new VoteTagListener(context,
activity.getStageId(), getTag(), mGid));
activity.getStageId(), getTag()));
EhApplication.getEhClient(context).execute(request);
}
@@ -1770,11 +1763,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
private static class VoteTagListener extends EhCallback<GalleryDetailScene, VoteTagParser.Result> {
private final long mGid;
public VoteTagListener(Context context, int stageId, String sceneTag, long gid) {
public VoteTagListener(Context context, int stageId, String sceneTag) {
super(context, stageId, sceneTag);
mGid = gid;
}
@Override
@@ -1843,7 +1833,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
}
}
private class ModifyFavoritesListener extends EhCallback<GalleryDetailScene, Void> {
private static class ModifyFavoritesListener extends EhCallback<GalleryDetailScene, Void> {
private final boolean mAddOrRemove;
@@ -1889,7 +1879,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
}
}
private class DownloadArchiveListener extends EhCallback<GalleryDetailScene, Void> {
private static class DownloadArchiveListener extends EhCallback<GalleryDetailScene, Void> {
public DownloadArchiveListener(Context context, int stageId, String sceneTag) {
super(context, stageId, sceneTag);
@@ -2100,8 +2090,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
if (null != context && null != mTorrentList && position < mTorrentList.length) {
String url = mTorrentList[position].first;
String name = mTorrentList[position].second;
// Use system download service
DownloadManager.Request r = new DownloadManager.Request(Uri.parse(url));
// TODO: Don't use buggy system download service
DownloadManager.Request r = new DownloadManager.Request(Uri.parse(url.replace("exhentai.org", "ehtracker.org")));
r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
FileUtils.sanitizeFilename(name + ".torrent"));
r.allowScanningByMediaScanner();
@@ -2112,6 +2102,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
try {
dm.enqueue(r);
} catch (Throwable e) {
e.printStackTrace();
ExceptionUtils.throwIfFatal(e);
}
}