From b30c3bbc2aebdaae1877646f50259fae370bce53 Mon Sep 17 00:00:00 2001 From: jacobrein Date: Fri, 13 Dec 2024 07:28:42 -0700 Subject: [PATCH] Update librariesThis commit updates various libraries and dependencies, including:- `reorderable`: v2.4.0 -> v2.4.2 - `accompanist`: v0.36.0 -> v0.37.0 - `zoomimageComposeGlide`: v1.0.2 -> v1.1.0It also includes code refactoring and adjustments, such as:- Removing unnecessary imports. - Improving permission requests. - Adding awaitAll for source population in GlobalSearchViewModel. - Improving Glide async image loading in ReaderComposeImage. - Replacing deprecated api in ImageLoaderSettings. - Adding stacktrace to error output in DownloadViewerFragment. --- .../uiviews/BaseMainActivity.kt | 11 ++-- .../globalsearch/GlobalSearchViewModel.kt | 32 +++++++----- .../uiviews/utils/components/Permissions.kt | 50 +++++++++++-------- .../animeworld/videos/ViewVideosFragment.kt | 2 - gradle/libs.versions.toml | 11 ++-- .../programmersbox/mangaworld/GenericManga.kt | 3 +- .../downloads/DownloadViewerFragment.kt | 3 +- .../reader/compose/ReaderComposeImage.kt | 7 +-- .../settings/ImageLoaderSettings.kt | 2 +- 9 files changed, 65 insertions(+), 56 deletions(-) diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt index 3122904c4..585e57e64 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/BaseMainActivity.kt @@ -6,8 +6,10 @@ import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle +import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.ExperimentalSharedTransitionApi @@ -113,8 +115,6 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.google.accompanist.drawablepainter.rememberDrawablePainter -import com.google.accompanist.permissions.ExperimentalPermissionsApi -import com.google.accompanist.permissions.rememberPermissionState import com.programmersbox.extensionloader.SourceRepository import com.programmersbox.favoritesdatabase.ItemDatabase import com.programmersbox.favoritesdatabase.SourceOrder @@ -387,7 +387,7 @@ abstract class BaseMainActivity : AppCompatActivity() { Modifier.draggable( orientation = Orientation.Vertical, state = - rememberDraggableState { delta -> scrollBehavior.state.heightOffset -= delta }, + rememberDraggableState { delta -> scrollBehavior.state.heightOffset -= delta }, onDragStopped = { velocity -> settleAppBarBottom( scrollBehavior.state, @@ -713,12 +713,11 @@ abstract class BaseMainActivity : AppCompatActivity() { ) } - @OptIn(ExperimentalPermissionsApi::class) @Composable fun AskForNotificationPermissions() { if (Build.VERSION.SDK_INT >= 33) { - val permissions = rememberPermissionState(permission = Manifest.permission.POST_NOTIFICATIONS) - LaunchedEffect(Unit) { permissions.launchPermissionRequest() } + val permissionRequest = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {} + LaunchedEffect(Unit) { permissionRequest.launch(Manifest.permission.POST_NOTIFICATIONS) } } } diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/globalsearch/GlobalSearchViewModel.kt b/UIViews/src/main/java/com/programmersbox/uiviews/globalsearch/GlobalSearchViewModel.kt index 40e0f64d8..e7adbfe8f 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/globalsearch/GlobalSearchViewModel.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/globalsearch/GlobalSearchViewModel.kt @@ -48,6 +48,7 @@ class GlobalSearchViewModel( isRefreshing = true isSearching = true searchListPublisher = emptyList() + //TODO: Add option to have live population or all at once async { sourceRepository.list .apmap { a -> @@ -61,21 +62,26 @@ class GlobalSearchViewModel( .onCompletion { isRefreshing = false } } .forEach { launch { it.collect() } } + // this populates after it all finishes - /*combine( - info.searchList() - .apmap { a -> - a - .searchSourceList(searchText, list = emptyList()) - .dispatchIoAndCatchList() - .map { SearchModel(a.serviceName, it) } + /*val d = awaitAll( + *sourceRepository + .list + .mapNotNull { a -> + async { + a + .apiService + .searchSourceList(searchText, list = emptyList()) + .dispatchIoAndCatchList() + .map { SearchModel(a.apiService.serviceName, it) } + .filter { it.data.isNotEmpty() } + .firstOrNull() + } } - ) { it.toList().filter { s -> s.data.isNotEmpty() } } - .onStart { isRefreshing = true } - .onCompletion { isRefreshing = false } - .onEach { searchListPublisher = it } - .collect() - */ + .toTypedArray() + ).filterNotNull() + searchListPublisher = d + isRefreshing = false*/ }.await() isSearching = false } diff --git a/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/Permissions.kt b/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/Permissions.kt index b81a59cc7..e4cb4b9f0 100644 --- a/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/Permissions.kt +++ b/UIViews/src/main/java/com/programmersbox/uiviews/utils/components/Permissions.kt @@ -3,42 +3,50 @@ package com.programmersbox.uiviews.utils.components import android.content.Intent import android.net.Uri import android.provider.Settings -import androidx.compose.foundation.layout.* +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.* +import androidx.compose.material3.Button +import androidx.compose.material3.Card +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import androidx.compose.ui.util.fastAll -import com.google.accompanist.permissions.ExperimentalPermissionsApi -import com.google.accompanist.permissions.rememberMultiplePermissionsState -import com.google.accompanist.permissions.shouldShowRationale import com.programmersbox.uiviews.R -@ExperimentalPermissionsApi @Composable fun PermissionRequest(permissionsList: List, content: @Composable () -> Unit) { - val storagePermissions = rememberMultiplePermissionsState(permissionsList) + var hasStoragePermission by remember { mutableStateOf(false) } + val storage = rememberLauncherForActivityResult( + ActivityResultContracts.RequestMultiplePermissions() + ) { hasStoragePermission = it.all { it.value } } val context = LocalContext.current - SideEffect { storagePermissions.launchMultiplePermissionRequest() } - if (storagePermissions.allPermissionsGranted) { + SideEffect { storage.launch(permissionsList.toTypedArray()) } + if (hasStoragePermission) { content() } else { - if (storagePermissions.permissions.fastAll { it.status.shouldShowRationale }) { - NeedsPermissions { storagePermissions.launchMultiplePermissionRequest() } - } else { - NeedsPermissions { - context.startActivity( - Intent().apply { - action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS - data = Uri.fromParts("package", context.packageName, null) - } - ) - } + NeedsPermissions { + context.startActivity( + Intent().apply { + action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS + data = Uri.fromParts("package", context.packageName, null) + } + ) } } } diff --git a/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt b/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt index 0ccce4844..ee754350f 100644 --- a/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt +++ b/animeworld/src/main/java/com/programmersbox/animeworld/videos/ViewVideosFragment.kt @@ -69,7 +69,6 @@ import coil.compose.rememberAsyncImagePainter import coil.decode.VideoFrameDecoder import coil.request.ImageRequest import coil.request.videoFramePercent -import com.google.accompanist.permissions.ExperimentalPermissionsApi import com.programmersbox.animeworld.MainActivity import com.programmersbox.animeworld.R import com.programmersbox.animeworld.SlideToDeleteDialog @@ -97,7 +96,6 @@ import java.util.concurrent.TimeUnit @OptIn( ExperimentalMaterial3Api::class, ExperimentalAnimationApi::class, - ExperimentalPermissionsApi::class ) @Composable fun ViewVideoScreen() { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 8dfe3b4e7..21986b8a8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,7 @@ glideVersion = "4.16.0" pagecurl = "1.5.1" pagingVersion = "3.3.5" protobufGradlePlugin = "0.9.4" -reorderable = "2.4.0" +reorderable = "2.4.2" roomVersion = "2.7.0-alpha12" navVersion = "2.9.0-alpha04" koin-bom = "4.0.0" @@ -30,7 +30,7 @@ lifecycle = "2.9.0-alpha08" jetpack = "1.6.0-alpha03" jetpackCompiler = "1.5.11" jetbrainsCompiler = "1.5.1" -accompanist = "0.36.0" +accompanist = "0.37.0" okhttpVersion = "4.12.0" ktorVersion = "3.0.2" workVersion = "2.10.0" @@ -61,7 +61,7 @@ benchmark-macro-junit4 = "1.3.0" androidx-baselineprofile = "1.3.0" profileinstaller = "1.3.1" zoomableImageGlide = "0.14.0" -zoomimageComposeGlide = "1.0.2" +zoomimageComposeGlide = "1.1.0" googleAndroidLibrariesMapsplatformSecretsGradlePlugin = "2.0.1" @@ -139,7 +139,6 @@ material-kolor = { module = "com.materialkolor:material-kolor", version.ref = "m #Accompanist drawablePainter = { module = "com.google.accompanist:accompanist-drawablepainter", version.ref = "accompanist" } -permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" } adaptive = { module = "com.google.accompanist:accompanist-adaptive", version.ref = "accompanist" } okhttpLib = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttpVersion" } okhttpDns = { module = "com.squareup.okhttp3:okhttp-dnsoverhttps", version.ref = "okhttpVersion" } @@ -340,7 +339,7 @@ compose = [ "composeRuntimeLivedata", "landscapist-bom", "landscapistGlide", "landscapistPalette", "landscapistPlaceholder", "coilCompose", - "composeConstraintLayout", "permissions", + "composeConstraintLayout", "drawablePainter", "uiUtil", "materialYou", "materialYou-common", "materialWindow", @@ -354,7 +353,7 @@ composeTv = [ "composeRuntimeLivedata", "landscapist-bom", "landscapistGlide", "landscapistPalette", "landscapistPlaceholder", "coilCompose", - "composeConstraintLayout", "permissions", + "composeConstraintLayout", "drawablePainter", "uiUtil", "navCompose" ] diff --git a/mangaworld/src/main/java/com/programmersbox/mangaworld/GenericManga.kt b/mangaworld/src/main/java/com/programmersbox/mangaworld/GenericManga.kt index e755374f6..15b5c55b6 100644 --- a/mangaworld/src/main/java/com/programmersbox/mangaworld/GenericManga.kt +++ b/mangaworld/src/main/java/com/programmersbox/mangaworld/GenericManga.kt @@ -46,7 +46,6 @@ import androidx.navigation.NavController import androidx.navigation.NavGraphBuilder import androidx.navigation.compose.composable import androidx.navigation.toRoute -import com.google.accompanist.permissions.ExperimentalPermissionsApi import com.programmersbox.favoritesdatabase.DbModel import com.programmersbox.gsonutils.toJson import com.programmersbox.helpfulutils.downloadManager @@ -262,7 +261,7 @@ class GenericManga( } } - @OptIn(ExperimentalPermissionsApi::class, ExperimentalAnimationApi::class) + @OptIn(ExperimentalAnimationApi::class) override fun composeCustomPreferences(): ComposeSettingsDsl.() -> Unit = { viewSettings { diff --git a/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt b/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt index 16422b2ea..6e892e381 100644 --- a/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt +++ b/mangaworld/src/main/java/com/programmersbox/mangaworld/downloads/DownloadViewerFragment.kt @@ -59,7 +59,6 @@ import androidx.compose.ui.util.fastForEach import androidx.core.net.toUri import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.viewmodel.compose.viewModel -import com.google.accompanist.permissions.ExperimentalPermissionsApi import com.programmersbox.mangaworld.ChaptersGet import com.programmersbox.mangaworld.DOWNLOAD_FILE_PATH import com.programmersbox.mangaworld.MangaSettingsHandling @@ -83,7 +82,6 @@ import androidx.compose.material3.MaterialTheme as M3MaterialTheme @OptIn( ExperimentalMaterial3Api::class, - ExperimentalPermissionsApi::class, ExperimentalFoundationApi::class, ExperimentalAnimationApi::class, ) @@ -263,6 +261,7 @@ private fun ChapterItem( } emit(true) } catch (e: Exception) { + e.printStackTrace() emit(false) } } diff --git a/mangaworld/src/main/java/com/programmersbox/mangaworld/reader/compose/ReaderComposeImage.kt b/mangaworld/src/main/java/com/programmersbox/mangaworld/reader/compose/ReaderComposeImage.kt index f16ca183b..0540bc1b1 100644 --- a/mangaworld/src/main/java/com/programmersbox/mangaworld/reader/compose/ReaderComposeImage.kt +++ b/mangaworld/src/main/java/com/programmersbox/mangaworld/reader/compose/ReaderComposeImage.kt @@ -31,7 +31,8 @@ import coil.request.ImageRequest import coil.size.Size import com.bumptech.glide.load.model.GlideUrl import com.github.panpf.zoomimage.GlideZoomAsyncImage -import com.github.panpf.zoomimage.compose.glide.internal.ExperimentalGlideComposeApi +import com.github.panpf.zoomimage.compose.glide.ExperimentalGlideComposeApi +import com.github.panpf.zoomimage.rememberGlideZoomState import com.github.panpf.zoomimage.zoom.ReadMode import com.programmersbox.mangasettings.ImageLoaderType import com.programmersbox.mangaworld.R @@ -182,14 +183,14 @@ internal fun Panpf( .fillMaxWidth() .clip(RectangleShape) ) { - val state = com.github.panpf.zoomimage.compose.rememberZoomState() + val state = rememberGlideZoomState() LaunchedEffect(Unit) { state.zoomable.readMode = ReadMode(ReadMode.SIZE_TYPE_VERTICAL, ReadMode.Decider.Default) } GlideZoomAsyncImage( model = remember(painter) { GlideUrl(painter) { headers } }, - state = state, + zoomState = state, contentDescription = null, contentScale = contentScale, scrollBar = null, diff --git a/mangaworld/src/main/java/com/programmersbox/mangaworld/settings/ImageLoaderSettings.kt b/mangaworld/src/main/java/com/programmersbox/mangaworld/settings/ImageLoaderSettings.kt index 7c3d939fa..28d44aa97 100644 --- a/mangaworld/src/main/java/com/programmersbox/mangaworld/settings/ImageLoaderSettings.kt +++ b/mangaworld/src/main/java/com/programmersbox/mangaworld/settings/ImageLoaderSettings.kt @@ -190,7 +190,7 @@ private fun Coil( ) } -@OptIn(com.github.panpf.zoomimage.compose.glide.internal.ExperimentalGlideComposeApi::class) +@OptIn(com.github.panpf.zoomimage.compose.glide.ExperimentalGlideComposeApi::class) @Composable private fun Panpf( url: String,