From 7b482e5bcfec8dbcbf475dac4d26d5133396cc8c Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 12 Jun 2023 16:16:33 +0300 Subject: [PATCH] Fix shortcuts icons size --- ...daterTest.kt => AppShortcutManagerTest.kt} | 6 ++--- .../org/koitharu/kotatsu/core/AppModule.kt | 6 ++--- ...rtcutsUpdater.kt => AppShortcutManager.kt} | 6 ++--- .../core/ui/image/ThumbnailTransformation.kt | 24 +++++++++++++++++++ .../kotatsu/details/ui/DetailsActivity.kt | 6 ++--- .../kotatsu/details/ui/DetailsMenuProvider.kt | 6 ++--- .../kotatsu/reader/ui/ReaderViewModel.kt | 6 ++--- .../settings/UserDataSettingsFragment.kt | 6 ++--- 8 files changed, 45 insertions(+), 21 deletions(-) rename app/src/androidTest/java/org/koitharu/kotatsu/core/os/{ShortcutsUpdaterTest.kt => AppShortcutManagerTest.kt} (94%) rename app/src/main/kotlin/org/koitharu/kotatsu/core/os/{ShortcutsUpdater.kt => AppShortcutManager.kt} (97%) create mode 100644 app/src/main/kotlin/org/koitharu/kotatsu/core/ui/image/ThumbnailTransformation.kt diff --git a/app/src/androidTest/java/org/koitharu/kotatsu/core/os/ShortcutsUpdaterTest.kt b/app/src/androidTest/java/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt similarity index 94% rename from app/src/androidTest/java/org/koitharu/kotatsu/core/os/ShortcutsUpdaterTest.kt rename to app/src/androidTest/java/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt index 6b9de214f..d7fad17d9 100644 --- a/app/src/androidTest/java/org/koitharu/kotatsu/core/os/ShortcutsUpdaterTest.kt +++ b/app/src/androidTest/java/org/koitharu/kotatsu/core/os/AppShortcutManagerTest.kt @@ -23,7 +23,7 @@ import javax.inject.Inject @HiltAndroidTest @RunWith(AndroidJUnit4::class) -class ShortcutsUpdaterTest { +class AppShortcutManagerTest { @get:Rule var hiltRule = HiltAndroidRule(this) @@ -32,7 +32,7 @@ class ShortcutsUpdaterTest { lateinit var historyRepository: HistoryRepository @Inject - lateinit var shortcutsUpdater: ShortcutsUpdater + lateinit var appShortcutManager: AppShortcutManager @Inject lateinit var database: MangaDatabase @@ -72,6 +72,6 @@ class ShortcutsUpdaterTest { private suspend fun awaitUpdate() { val instrumentation = InstrumentationRegistry.getInstrumentation() instrumentation.awaitForIdle() - shortcutsUpdater.await() + appShortcutManager.await() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/AppModule.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/AppModule.kt index 25332e92e..291118eec 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/AppModule.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/AppModule.kt @@ -30,7 +30,7 @@ import org.koitharu.kotatsu.core.cache.StubContentCache import org.koitharu.kotatsu.core.db.MangaDatabase import org.koitharu.kotatsu.core.network.* import org.koitharu.kotatsu.core.os.NetworkState -import org.koitharu.kotatsu.core.os.ShortcutsUpdater +import org.koitharu.kotatsu.core.os.AppShortcutManager import org.koitharu.kotatsu.core.parser.MangaLoaderContextImpl import org.koitharu.kotatsu.core.parser.MangaRepository import org.koitharu.kotatsu.core.parser.favicon.FaviconFetcher @@ -125,12 +125,12 @@ interface AppModule { @ElementsIntoSet fun provideDatabaseObservers( widgetUpdater: WidgetUpdater, - shortcutsUpdater: ShortcutsUpdater, + appShortcutManager: AppShortcutManager, backupObserver: BackupObserver, syncController: SyncController, ): Set<@JvmSuppressWildcards InvalidationTracker.Observer> = arraySetOf( widgetUpdater, - shortcutsUpdater, + appShortcutManager, backupObserver, syncController, ) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/os/ShortcutsUpdater.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManager.kt similarity index 97% rename from app/src/main/kotlin/org/koitharu/kotatsu/core/os/ShortcutsUpdater.kt rename to app/src/main/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManager.kt index 62d431639..c1db43782 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/os/ShortcutsUpdater.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/os/AppShortcutManager.kt @@ -15,7 +15,6 @@ import androidx.core.graphics.drawable.toBitmap import androidx.room.InvalidationTracker import coil.ImageLoader import coil.request.ImageRequest -import coil.size.Precision import coil.size.Scale import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.Dispatchers @@ -25,6 +24,7 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.db.TABLE_HISTORY import org.koitharu.kotatsu.core.parser.MangaDataRepository import org.koitharu.kotatsu.core.prefs.AppSettings +import org.koitharu.kotatsu.core.ui.image.ThumbnailTransformation import org.koitharu.kotatsu.core.util.ext.getDrawableOrThrow import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.processLifecycleScope @@ -36,7 +36,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class ShortcutsUpdater @Inject constructor( +class AppShortcutManager @Inject constructor( @ApplicationContext private val context: Context, private val coil: ImageLoader, private val historyRepository: HistoryRepository, @@ -128,8 +128,8 @@ class ShortcutsUpdater @Inject constructor( .data(manga.coverUrl) .size(iconSize.width, iconSize.height) .tag(manga.source) - .precision(Precision.EXACT) .scale(Scale.FILL) + .transformations(ThumbnailTransformation()) .build(), ).getDrawableOrThrow().toBitmap() }.fold( diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/image/ThumbnailTransformation.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/image/ThumbnailTransformation.kt new file mode 100644 index 000000000..c0ca38662 --- /dev/null +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/image/ThumbnailTransformation.kt @@ -0,0 +1,24 @@ +package org.koitharu.kotatsu.core.ui.image + +import android.graphics.Bitmap +import android.media.ThumbnailUtils +import coil.size.Size +import coil.size.pxOrElse +import coil.transform.Transformation + +class ThumbnailTransformation : Transformation { + + override val cacheKey: String = javaClass.name + + override suspend fun transform(input: Bitmap, size: Size): Bitmap { + return ThumbnailUtils.extractThumbnail( + input, + size.width.pxOrElse { input.width }, + size.height.pxOrElse { input.height }, + ) + } + + override fun equals(other: Any?) = other is ThumbnailTransformation + + override fun hashCode() = javaClass.hashCode() +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 1de67398f..323a0d797 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -30,7 +30,7 @@ import kotlinx.coroutines.flow.filterNotNull import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.resolve.SnackbarErrorObserver import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga -import org.koitharu.kotatsu.core.os.ShortcutsUpdater +import org.koitharu.kotatsu.core.os.AppShortcutManager import org.koitharu.kotatsu.core.parser.MangaIntent import org.koitharu.kotatsu.core.ui.BaseActivity import org.koitharu.kotatsu.core.ui.dialog.RecyclerViewAlertDialog @@ -68,7 +68,7 @@ class DetailsActivity : PopupMenu.OnMenuItemClickListener { @Inject - lateinit var shortcutsUpdater: ShortcutsUpdater + lateinit var appShortcutManager: AppShortcutManager private lateinit var viewBadge: ViewBadge private var buttonTip: WeakReference? = null @@ -147,7 +147,7 @@ class DetailsActivity : activity = this, viewModel = viewModel, snackbarHost = viewBinding.containerChapters, - shortcutsUpdater = shortcutsUpdater, + appShortcutManager = appShortcutManager, ), ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt index 4d333c345..a289f55c2 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsMenuProvider.kt @@ -15,7 +15,7 @@ import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.launch import org.koitharu.kotatsu.R import org.koitharu.kotatsu.browser.BrowserActivity -import org.koitharu.kotatsu.core.os.ShortcutsUpdater +import org.koitharu.kotatsu.core.os.AppShortcutManager import org.koitharu.kotatsu.core.util.ShareHelper import org.koitharu.kotatsu.details.ui.model.MangaBranch import org.koitharu.kotatsu.favourites.ui.categories.select.FavouriteCategoriesSheet @@ -29,7 +29,7 @@ class DetailsMenuProvider( private val activity: FragmentActivity, private val viewModel: DetailsViewModel, private val snackbarHost: View, - private val shortcutsUpdater: ShortcutsUpdater, + private val appShortcutManager: AppShortcutManager, ) : MenuProvider { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { @@ -112,7 +112,7 @@ class DetailsMenuProvider( R.id.action_shortcut -> { viewModel.manga.value?.let { activity.lifecycleScope.launch { - if (!shortcutsUpdater.requestPinShortcut(it)) { + if (!appShortcutManager.requestPinShortcut(it)) { Snackbar.make(snackbarHost, R.string.operation_not_supported, Snackbar.LENGTH_SHORT) .show() } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt index 3a260db4f..0bae31cc5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt @@ -30,7 +30,7 @@ import kotlinx.coroutines.plus import org.koitharu.kotatsu.R import org.koitharu.kotatsu.bookmarks.domain.Bookmark import org.koitharu.kotatsu.bookmarks.domain.BookmarksRepository -import org.koitharu.kotatsu.core.os.ShortcutsUpdater +import org.koitharu.kotatsu.core.os.AppShortcutManager import org.koitharu.kotatsu.core.parser.MangaDataRepository import org.koitharu.kotatsu.core.parser.MangaIntent import org.koitharu.kotatsu.core.prefs.AppSettings @@ -73,7 +73,7 @@ class ReaderViewModel @Inject constructor( private val pageSaveHelper: PageSaveHelper, private val pageLoader: PageLoader, private val chaptersLoader: ChaptersLoader, - private val shortcutsUpdater: ShortcutsUpdater, + private val appShortcutManager: AppShortcutManager, private val doubleMangaLoadUseCase: DoubleMangaLoadUseCase, private val historyUpdateUseCase: HistoryUpdateUseCase, private val detectReaderModeUseCase: DetectReaderModeUseCase, @@ -155,7 +155,7 @@ class ReaderViewModel @Inject constructor( }.launchIn(viewModelScope + Dispatchers.Default) launchJob(Dispatchers.Default) { val mangaId = mangaFlow.filterNotNull().first().id - shortcutsUpdater.notifyMangaOpened(mangaId) + appShortcutManager.notifyMangaOpened(mangaId) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/UserDataSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/UserDataSettingsFragment.kt index 2972d126d..d280e2bd0 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/UserDataSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/UserDataSettingsFragment.kt @@ -21,7 +21,7 @@ import kotlinx.coroutines.runInterruptible import okhttp3.Cache import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.network.cookies.MutableCookieJar -import org.koitharu.kotatsu.core.os.ShortcutsUpdater +import org.koitharu.kotatsu.core.os.AppShortcutManager import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.ui.BasePreferenceFragment import org.koitharu.kotatsu.core.util.FileSize @@ -59,7 +59,7 @@ class UserDataSettingsFragment : BasePreferenceFragment(R.string.data_and_privac lateinit var cache: Cache @Inject - lateinit var shortcutsUpdater: ShortcutsUpdater + lateinit var appShortcutManager: AppShortcutManager private val backupSelectCall = registerForActivityResult( ActivityResultContracts.OpenDocument(), @@ -69,7 +69,7 @@ class UserDataSettingsFragment : BasePreferenceFragment(R.string.data_and_privac override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_user_data) findPreference(AppSettings.KEY_SHORTCUTS)?.isVisible = - shortcutsUpdater.isDynamicShortcutsAvailable() + appShortcutManager.isDynamicShortcutsAvailable() findPreference(AppSettings.KEY_PROTECT_APP) ?.isChecked = !settings.appPassword.isNullOrEmpty() }