Compare commits

..
12 Commits
Author SHA1 Message Date
txyyh dd982c6cb9 Release 1.8.5.1
Releases / Build (push) Has been cancelled
2022-12-20 14:01:10 +00:00
tarsin 927a011c9d Upload mapping for release as well 2022-12-20 21:58:50 +08:00
tarsin ad0ad47a40 Support RTL Slider
But Idk whether we really support RTL :(
2022-12-20 21:30:20 +08:00
tarsin 71a424c15d Remove unused fab 2022-12-20 21:20:42 +08:00
FooIbar 145b7049a8 Support jump to last page
Resolve #466
2022-12-20 21:03:43 +08:00
tarsin 323d258bc2 Fix RTL load 2022-12-20 20:57:45 +08:00
tarsin 56ba52d7b9 Do not recycle bitmap in pager, add back lrucache
TODO: use coil instead
2022-12-20 20:43:15 +08:00
tarsin 54bd6f6ed8 Fix memleak for archive 2022-12-20 19:58:40 +08:00
tarsin f06167ba4b Sync with tachiyomi, support load progress 2022-12-20 19:03:57 +08:00
renovate[bot] 60438ae1ed Update dependency gradle to v8.0-milestone-6 (#562)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-12-20 17:23:02 +08:00
FooIbar 1b87750b87 fixup! Fix isTranslatable (#555)
* Use appcompat to auto store locales

* fixup! Fix isTranslatable #553

* Code cleanup
2022-12-20 08:36:55 +08:00
FooIbar 40cdc566c8 Upload mapping files in ci 2022-12-20 08:33:56 +08:00
33 changed files with 314 additions and 449 deletions

No files matched your search

+7
View File
@@ -56,3 +56,10 @@ jobs:
with:
name: x86-${{ github.sha }}
path: app/build/outputs/apk/release/app-x86-release.apk
- name: Update mapping
uses: actions/upload-artifact@v3
with:
name: mapping-${{ github.sha }}
path: app/build/outputs/mapping/release/mapping.txt
retention-days: 5
+1
View File
@@ -49,6 +49,7 @@ jobs:
app/build/outputs/apk/release/EhViewer-x86_64.apk
app/build/outputs/apk/release/EhViewer-x86.apk
app/build/outputs/apk/release/EhViewer-armeabi-v7a.apk
app/build/outputs/mapping/release/mapping.txt
- name: Collect Apks
run: |
+2 -2
View File
@@ -31,8 +31,8 @@ android {
applicationId "moe.tarsin.ehviewer"
minSdkVersion 28
targetSdkVersion 33
versionCode 180028
versionName "1.8.5.0"
versionCode 180029
versionName "1.8.5.1"
resConfigs 'zh', 'zh-rCN', 'zh-rHK', 'zh-rTW', 'es', 'ja', 'ko', 'fr', 'de', 'th'
}
+2 -2
View File
@@ -16,8 +16,8 @@
-keep class androidx.viewpager.widget.ViewPager$LayoutParams { int position; }
-renamesourcefileattribute
-keepattributes LineNumberTable,SourceFile
-renamesourcefileattribute SourceFile
-repackageclasses
-allowaccessmodification
-mergeinterfacesaggressively
-overloadaggressively
+15 -3
View File
@@ -14,7 +14,8 @@
~ limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature
android:name="android.software.leanback"
@@ -41,12 +42,14 @@
android:fullBackupContent="@xml/backup_scheme"
android:hasFragileUserData="true"
android:icon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:label="@string/app_name"
android:largeHeap="true"
android:localeConfig="@xml/locales_config"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:targetApi="tiramisu">
<activity
android:name="com.hippo.ehviewer.ui.MainActivity"
@@ -99,9 +102,9 @@
<activity
android:name="eu.kanade.tachiyomi.ui.reader.ReaderActivity"
android:colorMode="wideColorGamut"
android:configChanges="screenSize"
android:exported="true"
android:colorMode="wideColorGamut"
android:launchMode="singleTask">
<intent-filter>
@@ -157,6 +160,15 @@
android:taskAffinity=""
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<service
android:name="androidx.appcompat.app.AppLocalesMetadataHolderService"
android:enabled="false"
android:exported="false">
<meta-data
android:name="autoStoreLocales"
android:value="true" />
</service>
<service
android:name="com.hippo.ehviewer.download.DownloadService"
android:foregroundServiceType="dataSync"
@@ -20,7 +20,6 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.app.ActivityManager
import android.content.ComponentCallbacks2
import android.os.Build
import android.text.Html
import android.text.method.LinkMovementMethod
import android.view.View
@@ -28,7 +27,6 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatDelegate
import androidx.collection.LruCache
import androidx.core.content.getSystemService
import androidx.core.os.LocaleListCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
@@ -107,7 +105,7 @@ class EhApplication : SceneApplication(), DefaultLifecycleObserver, ImageLoaderF
super<SceneApplication>.onCreate()
Native.initialize()
GetText.initialize(this)
Settings.initialize(this)
Settings.initialize()
ReadableTime.initialize(this)
AppConfig.initialize(this)
SpiderDen.initialize(this)
@@ -116,9 +114,6 @@ class EhApplication : SceneApplication(), DefaultLifecycleObserver, ImageLoaderF
BitmapUtils.initialize(this)
EhTagDatabase.update()
// Locales can be managed by system automatically above Snow Cone v2
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU)
AppCompatDelegate.setApplicationLocales(LocaleListCompat.create(Settings.getLocale()))
AppCompatDelegate.setDefaultNightMode(Settings.getTheme())
GlobalScope.launch {
@@ -16,7 +16,6 @@
package com.hippo.ehviewer;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;
@@ -27,7 +26,6 @@ import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import com.hippo.ehviewer.client.EhConfig;
import com.hippo.ehviewer.client.EhTagDatabase;
import com.hippo.ehviewer.client.data.FavListUrlBuilder;
import com.hippo.ehviewer.ui.CommonOperations;
import com.hippo.ehviewer.ui.scene.GalleryListScene;
@@ -87,7 +85,6 @@ public class Settings {
public static final int DEFAULT_READ_CACHE_SIZE = 320;
public static final String KEY_BUILT_IN_HOSTS = "built_in_hosts_2";
public static final String KEY_DOMAIN_FRONTING = "domain_fronting";
public static final String KEY_APP_LANGUAGE = "app_language";
public static final String KEY_LIST_THUMB_SIZE = "list_tile_size";
private static final String KEY_HIDE_HV_EVENTS = "hide_hv_events";
private static final boolean DEFAULT_HIDE_HV_EVENTS = true;
@@ -125,34 +122,6 @@ public class Settings {
private static final boolean DEFAULT_METERED_NETWORK_WARNING = false;
private static final String KEY_APP_LINK_VERIFY_TIP = "app_link_verify_tip";
private static final boolean DEFAULT_APP_LINK_VERIFY_TIP = false;
/********************
****** Read
********************/
private static final String KEY_SCREEN_ROTATION = "screen_rotation";
private static final int DEFAULT_SCREEN_ROTATION = 0;
private static final String KEY_READING_DIRECTION = "reading_direction";
private static final String KEY_PAGE_SCALING = "page_scaling";
private static final String KEY_START_POSITION = "start_position";
private static final String KEY_KEEP_SCREEN_ON = "keep_screen_on";
private static final boolean DEFAULT_KEEP_SCREEN_ON = false;
private static final String KEY_SHOW_CLOCK = "gallery_show_clock";
private static final boolean DEFAULT_SHOW_CLOCK = true;
private static final String KEY_SHOW_PROGRESS = "gallery_show_progress";
private static final boolean DEFAULT_SHOW_PROGRESS = true;
private static final String KEY_SHOW_BATTERY = "gallery_show_battery";
private static final boolean DEFAULT_SHOW_BATTERY = true;
private static final String KEY_SHOW_PAGE_INTERVAL = "gallery_show_page_interval";
private static final boolean DEFAULT_SHOW_PAGE_INTERVAL = true;
private static final String KEY_VOLUME_PAGE = "volume_page";
private static final boolean DEFAULT_VOLUME_PAGE = false;
private static final String KEY_REVERSE_VOLUME_PAGE = "reserve_volume_page";
private static final boolean DEFAULT_REVERSE_VOLUME_PAGE = false;
private static final String KEY_READING_FULLSCREEN = "reading_fullscreen";
private static final boolean VALUE_READING_FULLSCREEN = true;
private static final String KEY_CUSTOM_SCREEN_LIGHTNESS = "custom_screen_lightness";
private static final boolean DEFAULT_CUSTOM_SCREEN_LIGHTNESS = false;
private static final String KEY_SCREEN_LIGHTNESS = "screen_lightness";
private static final int DEFAULT_SCREEN_LIGHTNESS = 50;
private static final boolean DEFAULT_MEDIA_SCAN = false;
private static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label";
private static final String DEFAULT_RECENT_DOWNLOAD_LABEL = null;
@@ -166,8 +135,6 @@ public class Settings {
private static final int DEFAULT_PRELOAD_IMAGE = 5;
private static final String KEY_DOWNLOAD_ORIGIN_IMAGE = "download_origin_image";
private static final boolean DEFAULT_DOWNLOAD_ORIGIN_IMAGE = false;
private static final String KEY_READ_THEME = "read_theme";
private static final int DEFAULT_READ_THEME = 1;
/********************
****** Favorites
********************/
@@ -214,15 +181,12 @@ public class Settings {
private static final boolean DEFAULT_SAVE_CRASH_LOG = true;
private static final boolean DEFAULT_BUILT_IN_HOSTS = false;
private static final boolean DEFAULT_FRONTING = false;
private static final String DEFAULT_APP_LANGUAGE = "system";
private static final String KEY_PROXY_TYPE = "proxy_type";
private static final int DEFAULT_PROXY_TYPE = EhProxySelector.TYPE_SYSTEM;
private static final String KEY_PROXY_IP = "proxy_ip";
private static final String DEFAULT_PROXY_IP = null;
private static final String KEY_PROXY_PORT = "proxy_port";
private static final int DEFAULT_PROXY_PORT = -1;
private static final String KEY_GUIDE_GALLERY = "guide_gallery";
private static final boolean DEFAULT_GUIDE_GALLERY = true;
private static final String KEY_CLIPBOARD_TEXT_HASH_CODE = "clipboard_text_hash_code";
private static final int DEFAULT_CLIPBOARD_TEXT_HASH_CODE = 0;
private static final String KEY_DOWNLOAD_DELAY = "download_delay";
@@ -233,12 +197,10 @@ public class Settings {
public static boolean LIST_THUMB_SIZE_INITED = false;
public static SharedPreferences sSettingsPre;
private static int LIST_THUMB_SIZE = 40;
private static Context sContext;
private static EhConfig sEhConfig;
public static void initialize(Context context) {
sContext = context.getApplicationContext();
sSettingsPre = PreferenceManager.getDefaultSharedPreferences(sContext);
public static void initialize() {
sSettingsPre = PreferenceManager.getDefaultSharedPreferences(EhApplication.getApplication());
sEhConfig = loadEhConfig();
fixDefaultValue();
}
@@ -260,15 +222,6 @@ public class Settings {
}
}
public static Locale getLocale() {
String language = Settings.getAppLanguage();
if (language != null && !language.equals("system")) {
return Locale.forLanguageTag(language);
} else {
return Locale.getDefault();
}
}
private static EhConfig loadEhConfig() {
EhConfig ehConfig = new EhConfig();
ehConfig.imageSize = getImageResolution();
@@ -432,7 +385,7 @@ public class Settings {
}
public static int dip2px(int dpValue) {
final float scale = sContext.getResources().getDisplayMetrics().density;
final float scale = EhApplication.getApplication().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
@@ -461,7 +414,7 @@ public class Settings {
}
public static boolean getShowTagTranslations() {
return getBoolean(KEY_SHOW_TAG_TRANSLATIONS, DEFAULT_SHOW_TAG_TRANSLATIONS) && EhTagDatabase.INSTANCE.isTranslatable();
return getBoolean(KEY_SHOW_TAG_TRANSLATIONS, DEFAULT_SHOW_TAG_TRANSLATIONS);
}
public static void putShowTagTranslations(boolean value) {
@@ -496,114 +449,6 @@ public class Settings {
putBoolean(KEY_APP_LINK_VERIFY_TIP, value);
}
public static int getScreenRotation() {
return getIntFromStr(KEY_SCREEN_ROTATION, DEFAULT_SCREEN_ROTATION);
}
public static void putScreenRotation(int value) {
putIntToStr(KEY_SCREEN_ROTATION, value);
}
public static void putReadingDirection(int value) {
putIntToStr(KEY_READING_DIRECTION, value);
}
public static void putPageScaling(int value) {
putIntToStr(KEY_PAGE_SCALING, value);
}
public static void putStartPosition(int value) {
putIntToStr(KEY_START_POSITION, value);
}
public static boolean getKeepScreenOn() {
return getBoolean(KEY_KEEP_SCREEN_ON, DEFAULT_KEEP_SCREEN_ON);
}
public static void putKeepScreenOn(boolean value) {
putBoolean(KEY_KEEP_SCREEN_ON, value);
}
public static boolean getShowClock() {
return getBoolean(KEY_SHOW_CLOCK, DEFAULT_SHOW_CLOCK);
}
public static void putShowClock(boolean value) {
putBoolean(KEY_SHOW_CLOCK, value);
}
public static boolean getShowProgress() {
return getBoolean(KEY_SHOW_PROGRESS, DEFAULT_SHOW_PROGRESS);
}
public static void putShowProgress(boolean value) {
putBoolean(KEY_SHOW_PROGRESS, value);
}
public static boolean getShowBattery() {
return getBoolean(KEY_SHOW_BATTERY, DEFAULT_SHOW_BATTERY);
}
public static void putShowBattery(boolean value) {
putBoolean(KEY_SHOW_BATTERY, value);
}
public static boolean getShowPageInterval() {
return getBoolean(KEY_SHOW_PAGE_INTERVAL, DEFAULT_SHOW_PAGE_INTERVAL);
}
public static void putShowPageInterval(boolean value) {
putBoolean(KEY_SHOW_PAGE_INTERVAL, value);
}
public static boolean getVolumePage() {
return getBoolean(KEY_VOLUME_PAGE, DEFAULT_VOLUME_PAGE);
}
public static void putVolumePage(boolean value) {
putBoolean(KEY_VOLUME_PAGE, value);
}
public static boolean getReverseVolumePage() {
return getBoolean(KEY_REVERSE_VOLUME_PAGE, DEFAULT_REVERSE_VOLUME_PAGE);
}
public static void putReverseVolumePage(boolean value) {
putBoolean(KEY_REVERSE_VOLUME_PAGE, value);
}
public static boolean getReadingFullscreen() {
return getBoolean(KEY_READING_FULLSCREEN, VALUE_READING_FULLSCREEN);
}
public static void putReadingFullscreen(boolean value) {
putBoolean(KEY_READING_FULLSCREEN, value);
}
public static boolean getCustomScreenLightness() {
return getBoolean(KEY_CUSTOM_SCREEN_LIGHTNESS, DEFAULT_CUSTOM_SCREEN_LIGHTNESS);
}
public static void putCustomScreenLightness(boolean value) {
putBoolean(KEY_CUSTOM_SCREEN_LIGHTNESS, value);
}
public static int getScreenLightness() {
return getInt(KEY_SCREEN_LIGHTNESS, DEFAULT_SCREEN_LIGHTNESS);
}
public static void putScreenLightness(int value) {
putInt(KEY_SCREEN_LIGHTNESS, value);
}
public static int getReadTheme() {
return getIntFromStr(KEY_READ_THEME, DEFAULT_READ_THEME);
}
public static void putReadTheme(int value) {
putIntToStr(KEY_READ_THEME, value);
}
public static boolean getEnabledSecurity() {
return getBoolean(KEY_SEC_SECURITY, VALUE_SEC_SECURITY);
}
@@ -617,7 +462,7 @@ public class Settings {
builder.encodedPath(getString(KEY_DOWNLOAD_SAVE_PATH, null));
builder.encodedQuery(getString(KEY_DOWNLOAD_SAVE_QUERY, null));
builder.encodedFragment(getString(KEY_DOWNLOAD_SAVE_FRAGMENT, null));
dir = UniFile.fromUri(sContext, builder.build());
dir = UniFile.fromUri(EhApplication.getApplication(), builder.build());
return dir != null ? dir : UniFile.fromFile(AppConfig.getDefaultDownloadDir());
}
@@ -824,10 +669,6 @@ public class Settings {
putBoolean(KEY_DOMAIN_FRONTING, value);
}
public static String getAppLanguage() {
return getString(KEY_APP_LANGUAGE, DEFAULT_APP_LANGUAGE);
}
public static int getProxyType() {
return getInt(KEY_PROXY_TYPE, DEFAULT_PROXY_TYPE);
}
@@ -852,14 +693,6 @@ public class Settings {
putInt(KEY_PROXY_PORT, value);
}
public static boolean getGuideGallery() {
return getBoolean(KEY_GUIDE_GALLERY, DEFAULT_GUIDE_GALLERY);
}
public static void putGuideGallery(boolean value) {
putBoolean(KEY_GUIDE_GALLERY, value);
}
public static int getClipboardTextHashCode() {
return getInt(KEY_CLIPBOARD_TEXT_HASH_CODE, DEFAULT_CLIPBOARD_TEXT_HASH_CODE);
}
@@ -133,8 +133,8 @@ object EhTagDatabase {
.takeIf { it.size == 4 }
}
fun isTranslatable(): Boolean {
return EhApplication.application.resources.getBoolean(R.bool.tag_translatable)
fun isTranslatable(context: Context): Boolean {
return context.resources.getBoolean(R.bool.tag_translatable)
}
private fun getFileContent(file: File): String? {
@@ -91,6 +91,7 @@ public class ArchivePageLoader extends PageLoader2 {
@Override
public void stop() {
super.stop();
if (archiveThread != null) {
archiveThread.interrupt();
archiveThread = null;
@@ -81,6 +81,7 @@ public class DirPageLoader extends PageLoader2 implements Runnable {
@Override
public void stop() {
super.stop();
if (mBgThread != null) {
mBgThread.interrupt();
mBgThread = null;
@@ -53,6 +53,7 @@ public class EhPageLoader extends PageLoader2 implements SpiderQueen.OnSpiderLis
@Override
public void stop() {
super.stop();
if (mSpiderQueen != null) {
mSpiderQueen.removeOnSpiderListener(this);
// Activity recreate may called, so wait 3000s
@@ -372,7 +372,7 @@ public class AdvancedFragment extends BasePreferenceFragment {
String key = preference.getKey();
if (KEY_APP_LANGUAGE.equals(key) && Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
if ("system".equals(newValue)) {
AppCompatDelegate.setApplicationLocales(LocaleListCompat.wrap(Resources.getSystem().getConfiguration().getLocales()));
AppCompatDelegate.setApplicationLocales(LocaleListCompat.getEmptyLocaleList());
} else {
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags((String) newValue));
}
@@ -52,7 +52,7 @@ class EhFragment : BasePreferenceFragment() {
thumbResolution!!.setSummaryProvider {
getString(R.string.settings_eh_thumb_resolution_summary, (it as ListPreference).entry)
}
if (!EhTagDatabase.isTranslatable()) {
if (!EhTagDatabase.isTranslatable(requireActivity())) {
preferenceScreen.removePreference(showTagTranslations)
preferenceScreen.removePreference(tagTranslationsSource!!)
}
@@ -582,17 +582,14 @@ public class FavoritesScene extends SearchBarScene implements
if (!mRecyclerView.isInCustomChoice()) {
switch (position) {
case 0: // Open right
openDrawer(Gravity.RIGHT);
break;
case 1: // Go to
if (mHelper.canGoTo()) {
showGoToDialog();
}
break;
case 2: // Refresh
mHelper.refresh();
break;
// Go to
case 0 -> {
if (mHelper.canGoTo()) showGoToDialog();
}
// Refresh
case 1 -> mHelper.refresh();
// Last page
case 2 -> mHelper.goToPage(Integer.MAX_VALUE - 1);
}
view.setExpanded(false);
return;
@@ -1141,7 +1138,10 @@ public class FavoritesScene extends SearchBarScene implements
SimpleHandler.getInstance().post(() -> onGetFavoritesLocal(keyword, taskId));
} else {
String prev = null, next = null;
if (jumpTo != null) {
if (page == Integer.MAX_VALUE - 1) {
prev = "1-0";
jumpTo = null;
} else if (jumpTo != null) {
next = Integer.toString(minGid);
operation = 0;
} else if (page != 0 && mHelper != null) {
@@ -57,7 +57,6 @@ import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.core.widget.NestedScrollView;
import com.google.android.material.progressindicator.CircularProgressIndicator;
@@ -261,7 +260,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
private Pair<String, String>[] mArchiveList;
@State
private int mState = STATE_INIT;
private boolean mModifingFavorites;
private boolean mModifyingFavorites;
@Nullable
private static String getArtist(GalleryTagGroup[] tagGroups) {
@@ -293,47 +292,21 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
@StringRes
private int getRatingText(float rating) {
int resId;
switch (Math.round(rating * 2)) {
case 0:
resId = R.string.rating0;
break;
case 1:
resId = R.string.rating1;
break;
case 2:
resId = R.string.rating2;
break;
case 3:
resId = R.string.rating3;
break;
case 4:
resId = R.string.rating4;
break;
case 5:
resId = R.string.rating5;
break;
case 6:
resId = R.string.rating6;
break;
case 7:
resId = R.string.rating7;
break;
case 8:
resId = R.string.rating8;
break;
case 9:
resId = R.string.rating9;
break;
case 10:
resId = R.string.rating10;
break;
default:
resId = R.string.rating_none;
break;
}
return resId;
return switch (Math.round(rating * 2)) {
case 0 -> R.string.rating0;
case 1 -> R.string.rating1;
case 2 -> R.string.rating2;
case 3 -> R.string.rating3;
case 4 -> R.string.rating4;
case 5 -> R.string.rating5;
case 6 -> R.string.rating6;
case 7 -> R.string.rating7;
case 8 -> R.string.rating8;
case 9 -> R.string.rating9;
case 10 -> R.string.rating10;
default -> R.string.rating_none;
};
}
private void handleArgs(Bundle args) {
@@ -357,7 +330,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
}
@Nullable
private String getGalleryDetailUrl(boolean allComment) {
private String getGalleryDetailUrl() {
long gid;
String token;
if (mGalleryDetail != null) {
@@ -372,7 +345,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
} else {
return null;
}
return EhUrl.getGalleryDetailUrl(gid, token, 0, allComment);
return EhUrl.getGalleryDetailUrl(gid, token, 0, false);
}
// -1 for error
@@ -388,18 +361,6 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
}
}
private String getToken() {
if (mGalleryDetail != null) {
return mGalleryDetail.token;
} else if (mGalleryInfo != null) {
return mGalleryInfo.token;
} else if (ACTION_GID_TOKEN.equals(mAction)) {
return mToken;
} else {
return null;
}
}
private String getUploader() {
if (mGalleryDetail != null) {
return mGalleryDetail.uploader;
@@ -519,14 +480,14 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
public boolean onMenuItemClick(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.action_open_in_other_app) {
String url = getGalleryDetailUrl(false);
String url = getGalleryDetailUrl();
Activity activity = getMainActivity();
if (null != url && null != activity) {
UrlOpener.openUrl(activity, url, false);
}
} else if (itemId == R.id.action_refresh) {
if (mState != STATE_REFRESH && mState != STATE_REFRESH_HEADER) {
adjustViewVisibility(STATE_REFRESH, true);
adjustViewVisibility(STATE_REFRESH);
request();
}
} else if (itemId == R.id.action_add_tag) {
@@ -550,7 +511,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
return true;
}
@Nullable
@NonNull
@Override
public View onCreateViewWithToolbar(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
@@ -655,16 +616,16 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
if (prepareData()) {
if (mGalleryDetail != null) {
bindViewSecond();
adjustViewVisibility(STATE_NORMAL, false);
adjustViewVisibility(STATE_NORMAL);
} else if (mGalleryInfo != null) {
bindViewFirst();
adjustViewVisibility(STATE_REFRESH_HEADER, false);
adjustViewVisibility(STATE_REFRESH_HEADER);
} else {
adjustViewVisibility(STATE_REFRESH, false);
adjustViewVisibility(STATE_REFRESH);
}
} else {
mTip.setText(R.string.error_cannot_find_gallery);
adjustViewVisibility(STATE_FAILED, false);
adjustViewVisibility(STATE_FAILED);
}
EhApplication.getDownloadManager().addDownloadInfoListener(this);
@@ -759,12 +720,12 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
private boolean request() {
Context context = getContext();
MainActivity activity = getMainActivity();
String url = getGalleryDetailUrl(false);
String url = getGalleryDetailUrl();
if (null == context || null == activity || null == url) {
return false;
}
EhClient.Callback callback = new GetGalleryDetailListener(context,
EhClient.Callback<?> callback = new GetGalleryDetailListener(context,
activity.getStageId(), getTag());
mRequestId = ((EhApplication) context.getApplicationContext()).putGlobalStuff(callback);
EhRequest request = new EhRequest()
@@ -776,7 +737,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
return true;
}
private void adjustViewVisibility(int state, boolean animation) {
private void adjustViewVisibility(int state) {
if (state == mState) {
return;
}
@@ -784,34 +745,29 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
return;
}
int oldState = mState;
mState = state;
animation = !TRANSITION_ANIMATION_DISABLED && animation;
boolean animation = !TRANSITION_ANIMATION_DISABLED && animation;
switch (state) {
case STATE_NORMAL:
case STATE_NORMAL -> {
// Show mMainView
mViewTransition.showView(0, animation);
// Show mBelowHeader
mViewTransition2.showView(0, animation);
break;
case STATE_REFRESH:
}
case STATE_REFRESH ->
// Show mProgressView
mViewTransition.showView(1, animation);
break;
case STATE_REFRESH_HEADER:
mViewTransition.showView(1, animation);
case STATE_REFRESH_HEADER -> {
// Show mMainView
mViewTransition.showView(0, animation);
// Show mProgress
mViewTransition2.showView(1, animation);
break;
default:
case STATE_INIT:
case STATE_FAILED:
}
case STATE_INIT, STATE_FAILED ->
// Show mFailedView
mViewTransition.showView(2, animation);
break;
mViewTransition.showView(2, animation);
}
}
@@ -915,7 +871,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
private void bindTags(GalleryTagGroup[] tagGroups) {
Context context = getContext();
LayoutInflater inflater = getLayoutInflater();
if (null == context || null == inflater || null == mTags || null == mNoTags) {
if (null == context || null == mTags || null == mNoTags) {
return;
}
@@ -927,7 +883,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
mNoTags.setVisibility(View.GONE);
}
EhTagDatabase ehTags = Settings.getShowTagTranslations() ? EhTagDatabase.INSTANCE : null;
EhTagDatabase ehTags = Settings.getShowTagTranslations() && EhTagDatabase.INSTANCE.isTranslatable(context) ? EhTagDatabase.INSTANCE : null;
int colorTag = ResourcesKt.resolveColor(getTheme(), R.attr.tagBackgroundColor);
int colorName = ResourcesKt.resolveColor(getTheme(), R.attr.tagGroupBackgroundColor);
for (GalleryTagGroup tg : tagGroups) {
@@ -971,7 +927,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
private void bindComments(GalleryComment[] comments) {
Context context = getContext();
LayoutInflater inflater = getLayoutInflater();
if (null == context || null == inflater || null == mComments || null == mCommentsText) {
if (null == context || null == mComments || null == mCommentsText) {
return;
}
@@ -1010,7 +966,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
LayoutInflater inflater = getLayoutInflater();
Resources resources = getResourcesOrNull();
int previewNum = Settings.getPreviewNum();
if (null == inflater || null == resources || null == mGridLayout || null == mPreviewText) {
if (null == resources || null == mGridLayout || null == mPreviewText) {
return;
}
@@ -1046,16 +1002,6 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
return getString(R.string.rating_text, getString(getRatingText(rating)), rating, ratingCount);
}
private void setTransitionName() {
long gid = getGid();
if (gid != -1 && mThumb != null && mUploader != null && mCategory != null) {
ViewCompat.setTransitionName(mThumb, TransitionNameFactory.getThumbTransitionName(gid));
ViewCompat.setTransitionName(mUploader, TransitionNameFactory.getUploaderTransitionName(gid));
ViewCompat.setTransitionName(mCategory, TransitionNameFactory.getCategoryTransitionName(gid));
}
}
private void showSimilarGalleryList() {
GalleryDetail gd = mGalleryDetail;
if (null == gd) {
@@ -1117,7 +1063,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
if (mTip == v) {
if (request()) {
adjustViewVisibility(STATE_REFRESH, true);
adjustViewVisibility(STATE_REFRESH);
}
} else if (mUploader == v) {
String uploader = getUploader();
@@ -1188,17 +1134,17 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
var galleryInfoBottomSheet = new GalleryInfoBottomSheet(mGalleryDetail);
galleryInfoBottomSheet.show(requireActivity().getSupportFragmentManager(), GalleryInfoBottomSheet.TAG);
} else if (mHeart == v || mHeartOutline == v) {
if (mGalleryDetail != null && !mModifingFavorites) {
if (mGalleryDetail != null && !mModifyingFavorites) {
boolean remove = false;
if (EhDB.containLocalFavorites(mGalleryDetail.gid) || mGalleryDetail.isFavorited) {
mModifingFavorites = true;
mModifyingFavorites = true;
CommonOperations.removeFromFavorites(activity, mGalleryDetail,
new ModifyFavoritesListener(context,
activity.getStageId(), getTag(), true));
remove = true;
}
if (!remove) {
mModifingFavorites = true;
mModifyingFavorites = true;
CommonOperations.addToFavorites(activity, mGalleryDetail,
new ModifyFavoritesListener(context,
activity.getStageId(), getTag(), false));
@@ -1207,7 +1153,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
updateFavoriteDrawable();
}
} else if (mShare == v) {
String url = getGalleryDetailUrl(false);
String url = getGalleryDetailUrl();
if (url != null) {
AppHelper.share(activity, url);
}
@@ -1437,17 +1383,17 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
}
return true;
} else if (mHeart == v || mHeartOutline == v) {
if (mGalleryDetail != null && !mModifingFavorites) {
if (mGalleryDetail != null && !mModifyingFavorites) {
boolean remove = false;
if (EhDB.containLocalFavorites(mGalleryDetail.gid) || mGalleryDetail.isFavorited) {
mModifingFavorites = true;
mModifyingFavorites = true;
CommonOperations.removeFromFavorites(activity, mGalleryDetail,
new ModifyFavoritesListener(activity,
activity.getStageId(), getTag(), true));
remove = true;
}
if (!remove) {
mModifingFavorites = true;
mModifyingFavorites = true;
CommonOperations.addToFavorites(activity, mGalleryDetail,
new ModifyFavoritesListener(activity,
activity.getStageId(), getTag(), false), true);
@@ -1492,25 +1438,13 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
return;
}
switch (mDownloadState) {
default:
case DownloadInfo.STATE_INVALID:
mDownload.setText(R.string.download);
break;
case DownloadInfo.STATE_NONE:
mDownload.setText(R.string.download_state_none);
break;
case DownloadInfo.STATE_WAIT:
mDownload.setText(R.string.download_state_wait);
break;
case DownloadInfo.STATE_DOWNLOAD:
mDownload.setText(R.string.download_state_downloading);
break;
case DownloadInfo.STATE_FINISH:
mDownload.setText(R.string.download_state_downloaded);
break;
case DownloadInfo.STATE_FAILED:
mDownload.setText(R.string.download_state_failed);
break;
case DownloadInfo.STATE_INVALID -> mDownload.setText(R.string.download);
case DownloadInfo.STATE_NONE -> mDownload.setText(R.string.download_state_none);
case DownloadInfo.STATE_WAIT -> mDownload.setText(R.string.download_state_wait);
case DownloadInfo.STATE_DOWNLOAD ->
mDownload.setText(R.string.download_state_downloading);
case DownloadInfo.STATE_FINISH -> mDownload.setText(R.string.download_state_downloaded);
case DownloadInfo.STATE_FAILED -> mDownload.setText(R.string.download_state_failed);
}
}
@@ -1570,7 +1504,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
private void onGetGalleryDetailSuccess(GalleryDetail result) {
mGalleryDetail = result;
updateDownloadState();
adjustViewVisibility(STATE_NORMAL, true);
adjustViewVisibility(STATE_NORMAL);
bindViewSecond();
}
@@ -1580,7 +1514,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
if (null != context && null != mTip) {
String error = ExceptionUtils.getReadableString(e);
mTip.setText(error);
adjustViewVisibility(STATE_FAILED, true);
adjustViewVisibility(STATE_FAILED);
}
}
@@ -1598,26 +1532,26 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
}
private void onModifyFavoritesSuccess(boolean addOrRemove) {
mModifingFavorites = false;
mModifyingFavorites = false;
if (mGalleryDetail != null) {
mGalleryDetail.isFavorited = !addOrRemove && mGalleryDetail.favoriteName != null;
updateFavoriteDrawable();
}
}
private void onModifyFavoritesFailure(boolean addOrRemove) {
mModifingFavorites = false;
private void onModifyFavoritesFailure() {
mModifyingFavorites = false;
}
private void onModifyFavoritesCancel(boolean addOrRemove) {
mModifingFavorites = false;
private void onModifyFavoritesCancel() {
mModifyingFavorites = false;
}
@Override
public void onProvideAssistContent(AssistContent outContent) {
super.onProvideAssistContent(outContent);
String url = getGalleryDetailUrl(false);
String url = getGalleryDetailUrl();
if (url != null) {
outContent.setWebUri(Uri.parse(url));
}
@@ -1771,7 +1705,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
R.string.add_to_favorite_failure, LENGTH_LONG);
GalleryDetailScene scene = getScene();
if (scene != null) {
scene.onModifyFavoritesFailure(mAddOrRemove);
scene.onModifyFavoritesFailure();
}
}
@@ -1779,7 +1713,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
public void onCancel() {
GalleryDetailScene scene = getScene();
if (scene != null) {
scene.onModifyFavoritesCancel(mAddOrRemove);
scene.onModifyFavoritesCancel();
}
}
@@ -2105,7 +2039,7 @@ public class GalleryDetailScene extends CollapsingToolbarScene implements View.O
}
}
private class DeleteDialogHelper implements DialogInterface.OnClickListener {
private static class DeleteDialogHelper implements DialogInterface.OnClickListener {
private final com.hippo.ehviewer.download.DownloadManager mDownloadManager;
private final GalleryInfo mGalleryInfo;
private final CheckBoxDialogBuilder mBuilder;
@@ -150,7 +150,7 @@ public final class GalleryListScene extends SearchBarScene
private EasyRecyclerView mRecyclerView;
@Nullable
private SearchLayout mSearchLayout;
ActivityResultLauncher<PickVisualMediaRequest> selectImageLauncher = registerForActivityResult(
final ActivityResultLauncher<PickVisualMediaRequest> selectImageLauncher = registerForActivityResult(
new ActivityResultContracts.PickVisualMedia(),
result -> mSearchLayout.setImageUri(result));
@Nullable
@@ -474,23 +474,26 @@ public final class GalleryListScene extends SearchBarScene
String keyword = builder.getKeyword();
int category = builder.getCategory();
boolean isTopList = builder.getMode() == ListUrlBuilder.MODE_TOPLIST;
var mode = builder.getMode();
boolean isPopular = mode == ListUrlBuilder.MODE_WHATS_HOT;
boolean isTopList = mode == ListUrlBuilder.MODE_TOPLIST;
if (isTopList != mIsTopList) {
mIsTopList = isTopList;
recreateDrawerView();
mFabLayout.getSecondaryFabAt(0).setImageResource(isTopList ? R.drawable.ic_baseline_format_list_numbered_24 : R.drawable.v_magnify_x24);
}
mFabLayout.setSecondaryFabVisibilityAt(1, ListUrlBuilder.MODE_WHATS_HOT != builder.getMode());
// Update fab visibility
mFabLayout.setSecondaryFabVisibilityAt(0, !isPopular);
mFabLayout.setSecondaryFabVisibilityAt(2, !isTopList && !isPopular);
// Update normal search mode
mSearchLayout.setNormalSearchMode(builder.getMode() == ListUrlBuilder.MODE_SUBSCRIPTION
mSearchLayout.setNormalSearchMode(mode == ListUrlBuilder.MODE_SUBSCRIPTION
? R.id.search_subscription_search
: R.id.search_normal_search);
// Update search edit text
if (!TextUtils.isEmpty(keyword) && !mIsTopList) {
if (builder.getMode() == ListUrlBuilder.MODE_TAG) {
if (mode == ListUrlBuilder.MODE_TAG) {
keyword = wrapTagKeyword(keyword);
}
setSearchBarText(keyword);
@@ -505,19 +508,16 @@ public final class GalleryListScene extends SearchBarScene
// Update nav checked item
int checkedItemId;
if (ListUrlBuilder.MODE_NORMAL == builder.getMode() &&
EhUtils.NONE == category &&
TextUtils.isEmpty(keyword)) {
checkedItemId = R.id.nav_homepage;
} else if (ListUrlBuilder.MODE_SUBSCRIPTION == builder.getMode()) {
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;
}
checkedItemId = switch (mode) {
case ListUrlBuilder.MODE_NORMAL ->
EhUtils.NONE == category && TextUtils.isEmpty(keyword) ? R.id.nav_homepage : 0;
case ListUrlBuilder.MODE_SUBSCRIPTION -> R.id.nav_subscription;
case ListUrlBuilder.MODE_WHATS_HOT -> R.id.nav_whats_hot;
case ListUrlBuilder.MODE_TOPLIST -> R.id.nav_toplist;
case ListUrlBuilder.MODE_TAG, ListUrlBuilder.MODE_UPLOADER, ListUrlBuilder.MODE_IMAGE_SEARCH ->
0;
default -> throw new IllegalStateException("Unexpected value: " + mode);
};
setNavCheckedItem(checkedItemId);
mNavCheckedId = checkedItemId;
}
@@ -797,14 +797,14 @@ public final class GalleryListScene extends SearchBarScene
}
}
public boolean onItemClick(int position) {
public void onItemClick(int position) {
if (null == mHelper || null == mRecyclerView) {
return false;
return;
}
GalleryInfo gi = mHelper.getDataAtEx(position);
if (gi == null) {
return true;
return;
}
Bundle args = new Bundle();
@@ -812,7 +812,6 @@ public final class GalleryListScene extends SearchBarScene
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, gi);
Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
startScene(announcer);
return true;
}
@Override
@@ -890,17 +889,14 @@ public final class GalleryListScene extends SearchBarScene
}
switch (position) {
case 0: // Open right
openDrawer(Gravity.RIGHT);
break;
case 1: // Go to
if (mHelper.canGoTo()) {
showGoToDialog();
}
break;
case 2: // Refresh
mHelper.refresh();
break;
// Go to
case 0 -> {
if (mHelper.canGoTo()) showGoToDialog();
}
// Refresh
case 1 -> mHelper.refresh();
// Last page
case 2 -> mHelper.goToPage(Integer.MAX_VALUE - 1);
}
view.setExpanded(false);
@@ -1607,6 +1603,9 @@ public final class GalleryListScene extends SearchBarScene
} else {
nextGid = page;
}
} else if (page == Integer.MAX_VALUE - 1) {
prevGid = 1;
jumpTo = null;
} else if (jumpTo != null) {
nextGid = minGid;
} else if (page != 0) {
@@ -311,7 +311,7 @@ abstract class SearchBarScene : ToolbarScene() {
val s = text.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
if (s.isNotEmpty()) {
val keyword = s[s.size - 1]
val translate = Settings.getShowTagTranslations() && isTranslatable()
val translate = Settings.getShowTagTranslations() && isTranslatable(requireContext())
suggestFlow(keyword, translate, true).collect {
emit(TagSuggestion(it.first, it.second))
}
@@ -78,6 +78,9 @@ class Image private constructor(source: Source?, val release: () -> Unit = {}) {
}
}
val isRecycled: Boolean
get() = (mObtainedDrawable as? BitmapDrawable)?.bitmap?.isRecycled ?: (mObtainedDrawable as? AnimatedImageDrawable)?.isRunning?.not() ?: true
companion object {
val screenWidth = EhApplication.application.resources.displayMetrics.widthPixels
val screenHeight = EhApplication.application.resources.displayMetrics.heightPixels
@@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.source.model
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
open class Page(val index: Int) {
@@ -9,7 +10,14 @@ open class Page(val index: Int) {
var status = MutableStateFlow(State.QUEUE)
var progress = MutableStateFlow(0f)
private val _progressFlow = MutableStateFlow(0)
val progressFlow = _progressFlow.asStateFlow()
var progress: Int
get() = _progressFlow.value
set(value) {
_progressFlow.value = value
}
enum class State {
QUEUE,
@@ -305,6 +305,7 @@ class ReaderActivity : EhActivity() {
binding.actionReadingMode.setImageResource(viewerMode.iconRes)
viewer?.destroy()
viewer = ReadingModeType.toViewer(readerPreferences.defaultReadingMode().get(), this)
binding.pageSlider.isRTL = viewer is R2LPagerViewer
updateViewerInset(readerPreferences.fullscreen().get())
binding.viewerContainer.removeAllViews()
setOrientation(readerPreferences.defaultOrientationType().get())
@@ -1,11 +1,17 @@
package eu.kanade.tachiyomi.ui.reader.loader
import androidx.annotation.CallSuper
import androidx.collection.LruCache
import com.hippo.image.Image
import com.hippo.yorozuya.MathUtils
import com.hippo.yorozuya.OSUtils
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
import kotlinx.coroutines.flow.MutableStateFlow
abstract class PageLoader {
private val mImageCache = ImageCache()
val mPages by lazy {
check(size() > 0)
(0 until size()).map { ReaderPage(it) }
@@ -17,12 +23,24 @@ abstract class PageLoader {
abstract fun start()
abstract fun stop()
@CallSuper
open fun stop() {
mImageCache.evictAll()
}
abstract fun size(): Int
fun request(index: Int) {
onRequest(index)
fun request(page: ReaderPage) {
val index = mPages.indexOf(page)
val image = mImageCache[index]
if (image != null)
notifyPageSucceed(index, image)
else
onRequest(index)
}
fun retryPage(page: ReaderPage) {
onForceRequest(mPages.indexOf(page))
}
protected abstract fun onRequest(index: Int)
@@ -48,20 +66,39 @@ abstract class PageLoader {
fun notifyPagePercent(index: Int, percent: Float) {
mPages[index].status.compareAndSet(Page.State.QUEUE, Page.State.DOWNLOAD_IMAGE)
mPages[index].progress.value = percent
mPages[index].progress = (percent * 100).toInt()
}
fun notifyPageSucceed(index: Int, image: Image) {
val priv = mPages[index].image
if (mImageCache[index] != image)
mImageCache.add(index, image)
mPages[index].image = image
mPages[index].status.value = Page.State.READY
priv?.recycle()
}
fun notifyPageFailed(index: Int) {
mPages[index].status.value = Page.State.ERROR
}
private class ImageCache : LruCache<Int, Image>(MathUtils.clamp(OSUtils.getTotalMemory() / 16, MIN_CACHE_SIZE, MAX_CACHE_SIZE).toInt()) {
fun add(key: Int, value: Image) {
put(key, value)
}
override fun sizeOf(key: Int, value: Image): Int {
return value.height * value.width * 4
}
override fun entryRemoved(evicted: Boolean, key: Int, oldValue: Image, newValue: Image?) {
oldValue.recycle()
}
companion object {
private const val MAX_CACHE_SIZE = (512 * 1024 * 1024).toLong()
private const val MIN_CACHE_SIZE = (128 * 1024 * 1024).toLong()
}
}
companion object {
const val STATE_WAIT = -1
const val STATE_ERROR = -2
@@ -278,7 +278,7 @@ open class ReaderPageImageView @JvmOverloads constructor(
when (image) {
is Drawable -> {
val bitmap = (image as BitmapDrawable).bitmap
setImage(ImageSource.bitmap(bitmap))
setImage(ImageSource.cachedBitmap(bitmap))
}
is InputStream -> setImage(ImageSource.inputStream(image))
else -> throw IllegalArgumentException("Not implemented for class ${image::class.simpleName}")
@@ -11,10 +11,9 @@ import androidx.annotation.IntRange
import com.google.android.material.progressindicator.CircularProgressIndicator
/**
* A wrapper for [CircularProgressIndicator] that always rotates while being determinate.
* A wrapper for [CircularProgressIndicator] that always rotates.
*
* By always rotating we give the feedback to the user that the application isn't 'stuck',
* and by making it determinate the user also approximately knows how much the operation will take.
* By always rotating we give the feedback to the user that the application isn't 'stuck'.
*/
class ReaderProgressIndicator @JvmOverloads constructor(
context: Context,
@@ -39,19 +39,18 @@ class PagerPageHolder(
/**
* Loading progress bar to indicate the current progress.
*/
private val progressIndicator: ReaderProgressIndicator =
ReaderProgressIndicator(readerThemedContext).apply {
updateLayoutParams<LayoutParams> {
gravity = Gravity.CENTER
}
private val progressIndicator: ReaderProgressIndicator = ReaderProgressIndicator(readerThemedContext).apply {
updateLayoutParams<LayoutParams> {
gravity = Gravity.CENTER
}
}
/**
* Error layout to show when the image fails to load.
*/
private var errorLayout: ReaderErrorBinding? = null
private var scope = CoroutineScope(Dispatchers.IO)
private val scope = CoroutineScope(Dispatchers.IO)
/**
* Subscription for status changes of the page.
@@ -59,17 +58,12 @@ class PagerPageHolder(
private var statusJob: Job? = null
/**
* Subscription for progress changes of the page.
* Job for progress changes of the page.
*/
private var progressJob: Job? = null
init {
addView(progressIndicator)
progressJob = scope.launch(Dispatchers.Main) {
page.progress.collect {
progressIndicator.setProgress(it.toInt())
}
}
statusJob = scope.launch(Dispatchers.Main) {
page.status.collectLatest {
processStatus(it)
@@ -83,10 +77,17 @@ class PagerPageHolder(
@SuppressLint("ClickableViewAccessibility")
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
unsubscribeProgress()
cancelProgressJob()
unsubscribeStatus()
}
private fun launchProgressJob() {
progressJob?.cancel()
progressJob = scope.launch(Dispatchers.Main) {
page.progressFlow.collectLatest { value -> progressIndicator.setProgress(value) }
}
}
/**
* Called when the status of the page changes.
*
@@ -97,17 +98,16 @@ class PagerPageHolder(
Page.State.QUEUE -> setQueued()
Page.State.LOAD_PAGE -> setLoading()
Page.State.DOWNLOAD_IMAGE -> {
launchProgressJob()
setDownloading()
}
Page.State.READY -> {
page.image?.mObtainedDrawable?.let { setImage(it) }
unsubscribeProgress()
cancelProgressJob()
}
Page.State.ERROR -> {
setError()
unsubscribeProgress()
cancelProgressJob()
}
}
}
@@ -117,13 +117,12 @@ class PagerPageHolder(
*/
private fun unsubscribeStatus() {
statusJob?.cancel()
statusJob = null
}
/**
* Unsubscribes from the progress subscription.
*/
private fun unsubscribeProgress() {
private fun cancelProgressJob() {
progressJob?.cancel()
progressJob = null
}
/**
@@ -203,7 +202,7 @@ class PagerPageHolder(
errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), this, true)
errorLayout?.actionRetry?.viewer = viewer
errorLayout?.actionRetry?.setOnClickListener {
viewer.activity.mGalleryProvider?.request(page.index)
viewer.activity.mGalleryProvider?.retryPage(page)
}
}
errorLayout?.root?.isVisible = true
@@ -54,7 +54,7 @@ class PagerViewerAdapter(private val viewer: PagerViewer) : ViewPagerAdapter() {
* Creates a new view for the item at the given [position].
*/
override fun createView(container: ViewGroup, position: Int): View {
currentChapter?.request(position)
currentChapter?.request(items[position] as ReaderPage)
return when (val item = items[position]) {
is ReaderPage -> PagerPageHolder(readerThemedContext, viewer, item)
else -> throw NotImplementedError("Holder for ${item.javaClass} not implemented")
@@ -74,9 +74,9 @@ class WebtoonAdapter(val viewer: WebtoonViewer) : RecyclerView.Adapter<RecyclerV
*/
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val item = items[position]
currentChapter!!.request(position)
currentChapter!!.request(item as ReaderPage)
when (holder) {
is WebtoonPageHolder -> holder.bind(item as ReaderPage)
is WebtoonPageHolder -> holder.bind(item)
}
}
@@ -63,14 +63,21 @@ class WebtoonPageHolder(
*/
private var page: ReaderPage? = null
private var progressJob: Job? = null
private val scope = CoroutineScope(Dispatchers.IO)
/**
* Subscription for status changes of the page.
*/
private var statusJob: Job? = null
private var scope = CoroutineScope(Dispatchers.IO)
/**
* Job for progress changes of the page.
*/
private var progressJob: Job? = null
init {
refreshLayoutParams()
frame.onImageLoaded = { onImageDecoded() }
frame.onImageLoadError = { onImageDecodeError() }
frame.onScaleChanged = { viewer.activity.hideMenu() }
@@ -81,11 +88,6 @@ class WebtoonPageHolder(
*/
fun bind(page: ReaderPage) {
this.page = page
progressJob = scope.launch(Dispatchers.Main) {
page.progress.collect {
progressIndicator.setProgress(it.toInt())
}
}
statusJob = scope.launch(Dispatchers.Main) {
page.status.collectLatest {
processStatus(it)
@@ -111,13 +113,26 @@ class WebtoonPageHolder(
*/
override fun recycle() {
statusJob?.cancel()
progressJob?.cancel()
cancelProgressJob()
removeErrorLayout()
frame.recycle()
page?.image?.recycle()
progressIndicator.setProgress(0, animated = false)
}
/**
* Observes the progress of the page and updates view.
*/
private fun launchProgressJob() {
cancelProgressJob()
val page = page ?: return
progressJob = scope.launch(Dispatchers.Main) {
page.progressFlow.collectLatest { value -> progressIndicator.setProgress(value) }
}
}
/**
* Called when the status of the page changes.
*
@@ -128,21 +143,28 @@ class WebtoonPageHolder(
Page.State.QUEUE -> setQueued()
Page.State.LOAD_PAGE -> setLoading()
Page.State.DOWNLOAD_IMAGE -> {
launchProgressJob()
setDownloading()
}
Page.State.READY -> {
page?.image?.mObtainedDrawable?.let { setImage(it) }
progressJob?.cancel()
cancelProgressJob()
}
Page.State.ERROR -> {
setError()
progressJob?.cancel()
cancelProgressJob()
}
}
}
/**
* Unsubscribes from the progress subscription.
*/
private fun cancelProgressJob() {
progressJob?.cancel()
progressJob = null
}
/**
* Called when the page is queued.
*/
@@ -232,7 +254,7 @@ class WebtoonPageHolder(
errorLayout = ReaderErrorBinding.inflate(LayoutInflater.from(context), frame, true)
errorLayout?.root?.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, (parentHeight * 0.8).toInt())
errorLayout?.actionRetry?.setOnClickListener {
viewer.activity.mGalleryProvider?.request(page!!.index)
viewer.activity.mGalleryProvider?.retryPage(page!!)
}
}
return errorLayout!!
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="200"
android:fromYDelta="-100%"
android:toYDelta="0%" />
</set>
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:duration="200"
android:fromYDelta="0%"
android:toYDelta="-100%" />
</set>
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2022 Tarsin Norbin
~
~ This file is part of EhViewer
~
~ EhViewer is free software: you can redistribute it and/or modify it
~ under the terms of the GNU GeneralPublic License as published
~ by the Free Software Foundation,either version 3 of the License, or
~ (at your option) any later version.
~
~ EhViewer is distributed in the hope that it will be useful, but WITHOUT
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with EhViewer.
~ If not, see <https://www.gnu.org/licenses/>.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M7,18 L5.6,16.6 10.2,12 5.6,7.4 7,6 13,12ZM16,18V6H18V18Z" />
</vector>
+7 -7
View File
@@ -32,16 +32,10 @@
android:id="@+id/fab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="@dimen/corner_fab_margin"
android:paddingEnd="@dimen/corner_fab_margin"
android:paddingBottom="@dimen/corner_fab_margin"
app:fitsSystemWindowsInsets="top|bottom">
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.Material3.FloatingActionButton.Small.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/v_heart_box_dark_x24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.Material3.FloatingActionButton.Small.Primary"
android:layout_width="wrap_content"
@@ -54,6 +48,12 @@
android:layout_height="wrap_content"
app:srcCompat="@drawable/v_refresh_dark_x24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.Material3.FloatingActionButton.Small.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/v_last_page_x24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.Material3.FloatingActionButton.Small.Primary"
android:layout_width="wrap_content"
@@ -40,16 +40,10 @@
android:id="@+id/fab_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="@dimen/corner_fab_margin"
android:paddingEnd="@dimen/corner_fab_margin"
android:paddingBottom="@dimen/corner_fab_margin"
app:fitsSystemWindowsInsets="top|bottom">
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.Material3.FloatingActionButton.Small.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/v_magnify_x24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.Material3.FloatingActionButton.Small.Primary"
android:layout_width="wrap_content"
@@ -62,6 +56,12 @@
android:layout_height="wrap_content"
app:srcCompat="@drawable/v_refresh_dark_x24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/Widget.Material3.FloatingActionButton.Small.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/v_last_page_x24" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-milestone-5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-milestone-6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists