Remove redundant context parameter

This commit is contained in:
FooIbar authored and tarsin committed 2022-12-26 16:38:22 +08:00
1 parent 241d9daae9
commit d77e1e6820
7 files changed
+27 -53

No files matched your search

@@ -337,7 +337,7 @@ class EhApplication : SceneApplication(), DefaultLifecycleObserver, ImageLoaderF
}
@JvmStatic
val downloadManager by lazy { DownloadManager(application) }
val downloadManager by lazy { DownloadManager() }
@JvmStatic
val hosts by lazy { Hosts(application, "hosts.db") }
@@ -17,7 +17,6 @@
package com.hippo.ehviewer.download;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
@@ -44,7 +43,6 @@ import com.hippo.yorozuya.collect.SparseJLArray;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
@@ -55,8 +53,7 @@ import java.util.Map;
public class DownloadManager implements SpiderQueen.OnSpiderListener {
private static final String TAG = DownloadManager.class.getSimpleName();
private static final Comparator<DownloadInfo> DATE_DESC_COMPARATOR = (lhs, rhs) -> lhs.time - rhs.time > 0 ? -1 : 1;
private final Context mContext;
private static final Comparator<DownloadInfo> DATE_DESC_COMPARATOR = (lhs, rhs) -> (int) (rhs.time - lhs.time);
// All download info list
private final LinkedList<DownloadInfo> mAllInfoList;
// All download info map
@@ -79,8 +76,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
@Nullable
private SpiderQueen mCurrentSpider;
public DownloadManager(Context context) {
mContext = context;
public DownloadManager() {
// Get all labels
List<DownloadLabel> labels = EhDB.getAllDownloadLabelList();
@@ -206,7 +202,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Get download from wait list
if (!mWaitList.isEmpty()) {
DownloadInfo info = mWaitList.removeFirst();
SpiderQueen spider = SpiderQueen.obtainSpiderQueen(mContext, info, SpiderQueen.MODE_DOWNLOAD);
SpiderQueen spider = SpiderQueen.obtainSpiderQueen(info, SpiderQueen.MODE_DOWNLOAD);
mCurrentTask = info;
mCurrentSpider = spider;
spider.addOnSpiderListener(this);
@@ -387,7 +383,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
list.add(info);
// Sort
Collections.sort(list, DATE_DESC_COMPARATOR);
list.sort(DATE_DESC_COMPARATOR);
// Add to all download list and map
mAllInfoList.add(info);
@@ -398,7 +394,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
// Sort all download list
Collections.sort(mAllInfoList, DATE_DESC_COMPARATOR);
mAllInfoList.sort(DATE_DESC_COMPARATOR);
// Notify
if (notify) {
@@ -730,7 +726,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
srcList.remove(info);
dstList.add(info);
info.label = label;
Collections.sort(dstList, DATE_DESC_COMPARATOR);
dstList.sort(DATE_DESC_COMPARATOR);
// Save to DB
EhDB.putDownloadInfo(info);
@@ -830,7 +826,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
// Sort
Collections.sort(mDefaultInfoList, DATE_DESC_COMPARATOR);
mDefaultInfoList.sort(DATE_DESC_COMPARATOR);
// Notify listener
for (DownloadInfoListener l : mDownloadInfoListeners) {
@@ -1052,7 +1048,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
@Override
public void run() {
switch (mType) {
case TYPE_ON_GET_PAGES: {
case TYPE_ON_GET_PAGES -> {
DownloadInfo info = mCurrentTask;
if (info == null) {
Log.e(TAG, "Current task is null, but it should not be");
@@ -1065,19 +1061,15 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
}
break;
}
case TYPE_ON_GET_509: {
case TYPE_ON_GET_509 -> {
if (mDownloadListener != null) {
mDownloadListener.onGet509();
}
break;
}
case TYPE_ON_PAGE_DOWNLOAD: {
mSpeedReminder.onDownload(mIndex, mContentLength, mReceivedSize, mBytesRead);
break;
}
case TYPE_ON_PAGE_SUCCESS: {
case TYPE_ON_PAGE_DOWNLOAD ->
mSpeedReminder.onDownload(mIndex, mContentLength, mReceivedSize, mBytesRead);
case TYPE_ON_PAGE_SUCCESS -> {
mSpeedReminder.onDone(mIndex);
DownloadInfo info = mCurrentTask;
if (info == null) {
@@ -1096,9 +1088,8 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
}
break;
}
case TYPE_ON_PAGE_FAILURE: {
case TYPE_ON_PAGE_FAILURE -> {
mSpeedReminder.onDone(mIndex);
DownloadInfo info = mCurrentTask;
if (info == null) {
@@ -1114,9 +1105,8 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
}
break;
}
case TYPE_ON_FINISH: {
case TYPE_ON_FINISH -> {
mSpeedReminder.onFinish();
// Download done
DownloadInfo info = mCurrentTask;
@@ -1159,7 +1149,6 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
// Start next download
ensureDownload();
break;
}
}
@@ -16,8 +16,6 @@
package com.hippo.ehviewer.gallery;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -33,19 +31,17 @@ import eu.kanade.tachiyomi.ui.reader.loader.PageLoader;
public class EhPageLoader extends PageLoader2 implements SpiderQueen.OnSpiderListener {
private final Context mContext;
private final GalleryInfo mGalleryInfo;
@Nullable
private SpiderQueen mSpiderQueen;
public EhPageLoader(Context context, GalleryInfo galleryInfo) {
mContext = context;
public EhPageLoader(GalleryInfo galleryInfo) {
mGalleryInfo = galleryInfo;
}
@Override
public void start() {
mSpiderQueen = SpiderQueen.obtainSpiderQueen(mContext, mGalleryInfo, SpiderQueen.MODE_READ);
mSpiderQueen = SpiderQueen.obtainSpiderQueen(mGalleryInfo, SpiderQueen.MODE_READ);
mSpiderQueen.addOnSpiderListener(this);
if (mSpiderQueen.size() > 0)
notifyDataChanged();
@@ -140,14 +140,11 @@ public final class SpiderDen {
}
public boolean isReady() {
switch (mMode) {
case SpiderQueen.MODE_READ:
return sCache != null;
case SpiderQueen.MODE_DOWNLOAD:
return mDownloadDir != null && mDownloadDir.isDirectory();
default:
return false;
}
return switch (mMode) {
case SpiderQueen.MODE_READ -> sCache != null;
case SpiderQueen.MODE_DOWNLOAD -> mDownloadDir != null && mDownloadDir.isDirectory();
default -> false;
};
}
@Nullable
@@ -16,7 +16,6 @@
package com.hippo.ehviewer.spider;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.ImageDecoder;
import android.os.AsyncTask;
@@ -176,13 +175,11 @@ public final class SpiderQueen implements Runnable {
}
@UiThread
public static SpiderQueen obtainSpiderQueen(@NonNull Context context,
@NonNull GalleryInfo galleryInfo, @Mode int mode) {
public static SpiderQueen obtainSpiderQueen(@NonNull GalleryInfo galleryInfo, @Mode int mode) {
OSUtils.checkMainLoop();
SpiderQueen queen = sQueenMap.get(galleryInfo.gid);
if (queen == null) {
context.getApplicationContext();
queen = new SpiderQueen(galleryInfo);
sQueenMap.put(galleryInfo.gid, queen);
// Set mode
@@ -1093,12 +1090,7 @@ public final class SpiderQueen implements Runnable {
private String getPageUrl(long gid, int index, String pToken,
String oldPageUrl, String skipHathKey) {
String pageUrl;
if (oldPageUrl != null) {
pageUrl = oldPageUrl;
} else {
pageUrl = EhUrl.getPageUrl(gid, index, pToken);
}
String pageUrl = oldPageUrl != null ? oldPageUrl : EhUrl.getPageUrl(gid, index, pToken);
// Add skipHathKey
if (skipHathKey != null) {
if (pageUrl.contains("?")) {
@@ -413,7 +413,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
super.onResume();
if (mRead != null) {
try {
PageLoader2 galleryProvider = new EhPageLoader(requireContext(), mGalleryInfo);
PageLoader2 galleryProvider = new EhPageLoader(mGalleryInfo);
galleryProvider.start();
int startPage = galleryProvider.getStartPage();
if (startPage != 0) {
@@ -206,7 +206,7 @@ class ReaderActivity : EhActivity() {
} else if (ACTION_EH == mAction) {
if (mGalleryInfo != null) {
mGalleryProvider =
EhPageLoader(this, mGalleryInfo)
EhPageLoader(mGalleryInfo)
}
} else if (Intent.ACTION_VIEW == mAction) {
if (mUri != null) {
@@ -849,7 +849,7 @@ class ReaderActivity : EhActivity() {
* Moves the viewer to the given page [index]. It does nothing if the viewer is null or the
* page is not found.
*/
fun moveToPageIndex(index: Int) {
private fun moveToPageIndex(index: Int) {
val viewer = viewer ?: return
val page = mGalleryProvider?.mPages?.getOrNull(index) ?: return
viewer.moveToPage(page)