diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 63ce63306..5a982c81e 100755 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -14,7 +14,8 @@ ~ limitations under the License. --> - + + android:theme="@style/AppTheme" + tools:targetApi="tiramisu"> @@ -157,6 +159,15 @@ android:taskAffinity="" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> + + + + .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 { diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.java b/app/src/main/java/com/hippo/ehviewer/Settings.java index 7f0d9fad6..6b76bfbad 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.java +++ b/app/src/main/java/com/hippo/ehviewer/Settings.java @@ -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); } diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt b/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt index f43edd923..8b6c72300 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhTagDatabase.kt @@ -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? { diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java b/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java index a218bb0ab..38713f1be 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/AdvancedFragment.java @@ -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)); } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt b/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt index fcd05f561..d600d7f48 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/fragment/EhFragment.kt @@ -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!!) } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java index 92d7aa44c..bbbcd94ae 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.java @@ -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[] 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; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt index 339c788b5..0101482a2 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/SearchBarScene.kt @@ -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)) }