mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Upgrade Compose
Co-authored-by: ivaniskandar <ivaniskandar@users.noreply.github.com>
This commit is contained in:
		| @@ -4,7 +4,7 @@ import androidx.activity.compose.BackHandler | ||||
| import androidx.compose.animation.core.tween | ||||
| import androidx.compose.animation.fadeIn | ||||
| import androidx.compose.animation.fadeOut | ||||
| import androidx.compose.animation.with | ||||
| import androidx.compose.animation.togetherWith | ||||
| import androidx.compose.foundation.layout.PaddingValues | ||||
| import androidx.compose.foundation.layout.WindowInsets | ||||
| import androidx.compose.foundation.layout.WindowInsetsSides | ||||
| @@ -20,7 +20,7 @@ import cafe.adriel.voyager.core.annotation.InternalVoyagerApi | ||||
| import cafe.adriel.voyager.core.lifecycle.DisposableEffectIgnoringConfiguration | ||||
| import cafe.adriel.voyager.core.screen.Screen | ||||
| import cafe.adriel.voyager.navigator.Navigator | ||||
| import cafe.adriel.voyager.transitions.ScreenTransition | ||||
| import eu.kanade.presentation.util.ScreenTransition | ||||
| import eu.kanade.presentation.util.isTabletUi | ||||
| import tachiyomi.presentation.core.components.AdaptiveSheet as AdaptiveSheetImpl | ||||
|  | ||||
| @@ -43,7 +43,7 @@ fun NavigatorAdaptiveSheet( | ||||
|                 ScreenTransition( | ||||
|                     navigator = sheetNavigator, | ||||
|                     transition = { | ||||
|                         fadeIn(animationSpec = tween(220, delayMillis = 90)) with | ||||
|                         fadeIn(animationSpec = tween(220, delayMillis = 90)) togetherWith | ||||
|                             fadeOut(animationSpec = tween(90)) | ||||
|                     }, | ||||
|                 ) | ||||
|   | ||||
| @@ -188,7 +188,7 @@ fun AppBarActions( | ||||
|             IconButton( | ||||
|                 onClick = it.onClick, | ||||
|                 enabled = it.enabled, | ||||
|                 modifier = Modifier.tooltipAnchor(), | ||||
|                 modifier = Modifier.tooltipTrigger(), | ||||
|             ) { | ||||
|                 Icon( | ||||
|                     imageVector = it.icon, | ||||
| @@ -206,7 +206,7 @@ fun AppBarActions( | ||||
|         ) { | ||||
|             IconButton( | ||||
|                 onClick = { showMenu = !showMenu }, | ||||
|                 modifier = Modifier.tooltipAnchor(), | ||||
|                 modifier = Modifier.tooltipTrigger(), | ||||
|             ) { | ||||
|                 Icon( | ||||
|                     Icons.Outlined.MoreVert, | ||||
| @@ -325,7 +325,7 @@ fun SearchToolbar( | ||||
|                     ) { | ||||
|                         IconButton( | ||||
|                             onClick = onClick, | ||||
|                             modifier = Modifier.tooltipAnchor(), | ||||
|                             modifier = Modifier.tooltipTrigger(), | ||||
|                         ) { | ||||
|                             Icon( | ||||
|                                 Icons.Outlined.Search, | ||||
| @@ -342,7 +342,7 @@ fun SearchToolbar( | ||||
|                                 onClick() | ||||
|                                 focusRequester.requestFocus() | ||||
|                             }, | ||||
|                             modifier = Modifier.tooltipAnchor(), | ||||
|                             modifier = Modifier.tooltipTrigger(), | ||||
|                         ) { | ||||
|                             Icon( | ||||
|                                 Icons.Outlined.Close, | ||||
|   | ||||
| @@ -49,7 +49,7 @@ fun TabbedDialog( | ||||
|         onDismissRequest = onDismissRequest, | ||||
|     ) { contentPadding -> | ||||
|         val scope = rememberCoroutineScope() | ||||
|         val pagerState = rememberPagerState() | ||||
|         val pagerState = rememberPagerState { tabTitles.size } | ||||
|  | ||||
|         Column { | ||||
|             Row { | ||||
| @@ -84,7 +84,6 @@ fun TabbedDialog( | ||||
|  | ||||
|             HorizontalPager( | ||||
|                 modifier = Modifier.animateContentSize(), | ||||
|                 pageCount = tabTitles.size, | ||||
|                 state = pagerState, | ||||
|                 verticalAlignment = Alignment.Top, | ||||
|             ) { page -> | ||||
|   | ||||
| @@ -36,7 +36,7 @@ fun TabbedScreen( | ||||
|     onChangeSearchQuery: (String?) -> Unit = {}, | ||||
| ) { | ||||
|     val scope = rememberCoroutineScope() | ||||
|     val state = rememberPagerState() | ||||
|     val state = rememberPagerState { tabs.size } | ||||
|     val snackbarHostState = remember { SnackbarHostState() } | ||||
|  | ||||
|     LaunchedEffect(startIndex) { | ||||
| @@ -82,7 +82,6 @@ fun TabbedScreen( | ||||
|             } | ||||
|  | ||||
|             HorizontalPager( | ||||
|                 pageCount = tabs.size, | ||||
|                 modifier = Modifier.fillMaxSize(), | ||||
|                 state = state, | ||||
|                 verticalAlignment = Alignment.Top, | ||||
|   | ||||
| @@ -54,7 +54,7 @@ fun LibraryContent( | ||||
|         ), | ||||
|     ) { | ||||
|         val coercedCurrentPage = remember { currentPage().coerceAtMost(categories.lastIndex) } | ||||
|         val pagerState = rememberPagerState(coercedCurrentPage) | ||||
|         val pagerState = rememberPagerState(coercedCurrentPage) { categories.size } | ||||
|  | ||||
|         val scope = rememberCoroutineScope() | ||||
|         var isRefreshing by remember(pagerState.currentPage) { mutableStateOf(false) } | ||||
| @@ -98,7 +98,6 @@ fun LibraryContent( | ||||
|             LibraryPager( | ||||
|                 state = pagerState, | ||||
|                 contentPadding = PaddingValues(bottom = contentPadding.calculateBottomPadding()), | ||||
|                 pageCount = categories.size, | ||||
|                 hasActiveFilters = hasActiveFilters, | ||||
|                 selectedManga = selection, | ||||
|                 searchQuery = searchQuery, | ||||
|   | ||||
| @@ -30,7 +30,6 @@ import tachiyomi.presentation.core.util.plus | ||||
| fun LibraryPager( | ||||
|     state: PagerState, | ||||
|     contentPadding: PaddingValues, | ||||
|     pageCount: Int, | ||||
|     hasActiveFilters: Boolean, | ||||
|     selectedManga: List<LibraryManga>, | ||||
|     searchQuery: String?, | ||||
| @@ -43,7 +42,6 @@ fun LibraryPager( | ||||
|     onClickContinueReading: ((LibraryManga) -> Unit)?, | ||||
| ) { | ||||
|     HorizontalPager( | ||||
|         pageCount = pageCount, | ||||
|         modifier = Modifier.fillMaxSize(), | ||||
|         state = state, | ||||
|         verticalAlignment = Alignment.Top, | ||||
|   | ||||
| @@ -18,6 +18,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape | ||||
| import androidx.compose.material3.DatePicker | ||||
| import androidx.compose.material3.MaterialTheme | ||||
| import androidx.compose.material3.RadioButton | ||||
| import androidx.compose.material3.SelectableDates | ||||
| import androidx.compose.material3.Text | ||||
| import androidx.compose.material3.TextButton | ||||
| import androidx.compose.material3.minimumInteractiveComponentSize | ||||
| @@ -136,13 +137,14 @@ fun TrackScoreSelector( | ||||
| fun TrackDateSelector( | ||||
|     title: String, | ||||
|     initialSelectedDateMillis: Long, | ||||
|     dateValidator: (Long) -> Boolean, | ||||
|     selectableDates: SelectableDates, | ||||
|     onConfirm: (Long) -> Unit, | ||||
|     onRemove: (() -> Unit)?, | ||||
|     onDismissRequest: () -> Unit, | ||||
| ) { | ||||
|     val pickerState = rememberDatePickerState( | ||||
|         initialSelectedDateMillis = initialSelectedDateMillis, | ||||
|         selectableDates = selectableDates, | ||||
|     ) | ||||
|     AlertDialogContent( | ||||
|         modifier = Modifier.windowInsetsPadding(WindowInsets.systemBars), | ||||
| @@ -151,7 +153,6 @@ fun TrackDateSelector( | ||||
|             Column { | ||||
|                 DatePicker( | ||||
|                     state = pickerState, | ||||
|                     dateValidator = dateValidator, | ||||
|                     title = null, | ||||
|                     headline = null, | ||||
|                     showModeToggle = false, | ||||
|   | ||||
| @@ -1,8 +1,12 @@ | ||||
| package eu.kanade.presentation.util | ||||
|  | ||||
| import androidx.compose.animation.AnimatedContent | ||||
| import androidx.compose.animation.AnimatedContentTransitionScope | ||||
| import androidx.compose.animation.ContentTransform | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.ProvidableCompositionLocal | ||||
| import androidx.compose.runtime.staticCompositionLocalOf | ||||
| import androidx.compose.ui.Modifier | ||||
| import cafe.adriel.voyager.core.model.ScreenModel | ||||
| import cafe.adriel.voyager.core.model.ScreenModelStore | ||||
| import cafe.adriel.voyager.core.screen.Screen | ||||
| @@ -10,7 +14,7 @@ import cafe.adriel.voyager.core.screen.ScreenKey | ||||
| import cafe.adriel.voyager.core.screen.uniqueScreenKey | ||||
| import cafe.adriel.voyager.core.stack.StackEvent | ||||
| import cafe.adriel.voyager.navigator.Navigator | ||||
| import cafe.adriel.voyager.transitions.ScreenTransition | ||||
| import cafe.adriel.voyager.transitions.ScreenTransitionContent | ||||
| import kotlinx.coroutines.CoroutineName | ||||
| import kotlinx.coroutines.CoroutineScope | ||||
| import kotlinx.coroutines.Dispatchers | ||||
| @@ -63,3 +67,21 @@ fun DefaultNavigatorScreenTransition(navigator: Navigator) { | ||||
|         }, | ||||
|     ) | ||||
| } | ||||
|  | ||||
| @Composable | ||||
| fun ScreenTransition( | ||||
|     navigator: Navigator, | ||||
|     transition: AnimatedContentTransitionScope<Screen>.() -> ContentTransform, | ||||
|     modifier: Modifier = Modifier, | ||||
|     content: ScreenTransitionContent = { it.Content() }, | ||||
| ) { | ||||
|     AnimatedContent( | ||||
|         targetState = navigator.lastItem, | ||||
|         transitionSpec = transition, | ||||
|         modifier = modifier, | ||||
|     ) { screen -> | ||||
|         navigator.saveableState("transition", screen) { | ||||
|             content(screen) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -114,7 +114,7 @@ fun WebViewScreenContent( | ||||
|     ) { contentPadding -> | ||||
|         val webClient = remember { | ||||
|             object : AccompanistWebViewClient() { | ||||
|                 override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { | ||||
|                 override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) { | ||||
|                     super.onPageStarted(view, url, favicon) | ||||
|                     url?.let { onUrlChange(it) } | ||||
|                 } | ||||
|   | ||||
| @@ -26,7 +26,6 @@ import tachiyomi.domain.backup.service.BackupPreferences | ||||
| import tachiyomi.domain.library.service.LibraryPreferences | ||||
| import tachiyomi.domain.library.service.LibraryPreferences.Companion.MANGA_NON_COMPLETED | ||||
| import tachiyomi.domain.manga.model.TriStateFilter | ||||
| import uy.kohesive.injekt.Injekt | ||||
| import uy.kohesive.injekt.api.get | ||||
| import java.io.File | ||||
|  | ||||
| @@ -136,7 +135,6 @@ object Migrations { | ||||
|                 // Force MAL log out due to login flow change | ||||
|                 // v52: switched from scraping to WebView | ||||
|                 // v53: switched from WebView to OAuth | ||||
|                 val trackManager = Injekt.get<TrackManager>() | ||||
|                 if (trackManager.myAnimeList.isLogged) { | ||||
|                     trackManager.myAnimeList.logout() | ||||
|                     context.toast(R.string.myanimelist_relogin) | ||||
|   | ||||
| @@ -5,7 +5,7 @@ import androidx.compose.animation.AnimatedContent | ||||
| import androidx.compose.animation.AnimatedVisibility | ||||
| import androidx.compose.animation.expandVertically | ||||
| import androidx.compose.animation.shrinkVertically | ||||
| import androidx.compose.animation.with | ||||
| import androidx.compose.animation.togetherWith | ||||
| import androidx.compose.foundation.layout.Box | ||||
| import androidx.compose.foundation.layout.RowScope | ||||
| import androidx.compose.foundation.layout.WindowInsets | ||||
| @@ -121,7 +121,7 @@ object HomeScreen : Screen() { | ||||
|                         AnimatedContent( | ||||
|                             targetState = tabNavigator.current, | ||||
|                             transitionSpec = { | ||||
|                                 materialFadeThroughIn(initialScale = 1f, durationMillis = TabFadeDuration) with | ||||
|                                 materialFadeThroughIn(initialScale = 1f, durationMillis = TabFadeDuration) togetherWith | ||||
|                                     materialFadeThroughOut(durationMillis = TabFadeDuration) | ||||
|                             }, | ||||
|                             content = { | ||||
|   | ||||
| @@ -14,6 +14,7 @@ import androidx.compose.material3.ButtonDefaults | ||||
| import androidx.compose.material3.FilledTonalButton | ||||
| import androidx.compose.material3.Icon | ||||
| import androidx.compose.material3.MaterialTheme | ||||
| import androidx.compose.material3.SelectableDates | ||||
| import androidx.compose.material3.Text | ||||
| import androidx.compose.material3.TextButton | ||||
| import androidx.compose.runtime.Composable | ||||
| @@ -423,6 +424,62 @@ private data class TrackDateSelectorScreen( | ||||
|     private val start: Boolean, | ||||
| ) : Screen() { | ||||
|  | ||||
|     private val selectableDates = object : SelectableDates { | ||||
|         override fun isSelectableDate(utcTimeMillis: Long): Boolean { | ||||
|             val dateToCheck = Instant.ofEpochMilli(utcTimeMillis) | ||||
|                 .atZone(ZoneOffset.systemDefault()) | ||||
|                 .toLocalDate() | ||||
|  | ||||
|             if (dateToCheck > LocalDate.now()) { | ||||
|                 // Disallow future dates | ||||
|                 return false | ||||
|             } | ||||
|  | ||||
|             return if (start && track.finishDate > 0) { | ||||
|                 // Disallow start date to be set later than finish date | ||||
|                 val dateFinished = Instant.ofEpochMilli(track.finishDate) | ||||
|                     .atZone(ZoneId.systemDefault()) | ||||
|                     .toLocalDate() | ||||
|                 dateToCheck <= dateFinished | ||||
|             } else if (!start && track.startDate > 0) { | ||||
|                 // Disallow end date to be set earlier than start date | ||||
|                 val dateStarted = Instant.ofEpochMilli(track.startDate) | ||||
|                     .atZone(ZoneId.systemDefault()) | ||||
|                     .toLocalDate() | ||||
|                 dateToCheck >= dateStarted | ||||
|             } else { | ||||
|                 // Nothing set before | ||||
|                 true | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         override fun isSelectableYear(year: Int): Boolean { | ||||
|             if (year > LocalDate.now().year) { | ||||
|                 // Disallow future dates | ||||
|                 return false | ||||
|             } | ||||
|  | ||||
|             return if (start && track.finishDate > 0) { | ||||
|                 // Disallow start date to be set later than finish date | ||||
|                 val dateFinished = Instant.ofEpochMilli(track.finishDate) | ||||
|                     .atZone(ZoneId.systemDefault()) | ||||
|                     .toLocalDate() | ||||
|                     .year | ||||
|                 year <= dateFinished | ||||
|             } else if (!start && track.startDate > 0) { | ||||
|                 // Disallow end date to be set earlier than start date | ||||
|                 val dateStarted = Instant.ofEpochMilli(track.startDate) | ||||
|                     .atZone(ZoneId.systemDefault()) | ||||
|                     .toLocalDate() | ||||
|                     .year | ||||
|                 year >= dateStarted | ||||
|             } else { | ||||
|                 // Nothing set before | ||||
|                 true | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Composable | ||||
|     override fun Content() { | ||||
|         val navigator = LocalNavigator.currentOrThrow | ||||
| @@ -446,33 +503,7 @@ private data class TrackDateSelectorScreen( | ||||
|                 stringResource(R.string.track_finished_reading_date) | ||||
|             }, | ||||
|             initialSelectedDateMillis = sm.initialSelection, | ||||
|             dateValidator = { utcMillis -> | ||||
|                 val dateToCheck = Instant.ofEpochMilli(utcMillis) | ||||
|                     .atZone(ZoneOffset.systemDefault()) | ||||
|                     .toLocalDate() | ||||
|  | ||||
|                 if (dateToCheck > LocalDate.now()) { | ||||
|                     // Disallow future dates | ||||
|                     return@TrackDateSelector false | ||||
|                 } | ||||
|  | ||||
|                 if (start && track.finishDate > 0) { | ||||
|                     // Disallow start date to be set later than finish date | ||||
|                     val dateFinished = Instant.ofEpochMilli(track.finishDate) | ||||
|                         .atZone(ZoneId.systemDefault()) | ||||
|                         .toLocalDate() | ||||
|                     dateToCheck <= dateFinished | ||||
|                 } else if (!start && track.startDate > 0) { | ||||
|                     // Disallow end date to be set earlier than start date | ||||
|                     val dateStarted = Instant.ofEpochMilli(track.startDate) | ||||
|                         .atZone(ZoneId.systemDefault()) | ||||
|                         .toLocalDate() | ||||
|                     dateToCheck >= dateStarted | ||||
|                 } else { | ||||
|                     // Nothing set before | ||||
|                     true | ||||
|                 } | ||||
|             }, | ||||
|             selectableDates = selectableDates, | ||||
|             onConfirm = { sm.setDate(it); navigator.pop() }, | ||||
|             onRemove = { sm.confirmRemoveDate(navigator) }.takeIf { canRemove }, | ||||
|             onDismissRequest = navigator::pop, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user