Refactored code to be more readable
This commit is contained in:
1 parent
c219aa2b30
commit
343d358d22
3 files changed
+25
-23
No files matched your search
@@ -1,4 +1,5 @@
|
||||
package com.anthonyla.paperize.core
|
||||
import android.app.WallpaperManager
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
@@ -239,3 +240,11 @@ fun isValidUri(context: Context, uriString: String?): Boolean {
|
||||
} catch (e: Exception) { false }
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if device uses a live wallpaper
|
||||
*/
|
||||
fun isLiveWallpaperSet(context: Context): Boolean {
|
||||
val wallpaperManager = WallpaperManager.getInstance(context)
|
||||
return wallpaperManager.wallpaperInfo != null
|
||||
}
|
||||
|
||||
+14
-22
@@ -68,15 +68,22 @@ fun HomeScreen(
|
||||
blurPercentage: Int,
|
||||
firstSet: Boolean
|
||||
) {
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
|
||||
val tabItems = getTabItems()
|
||||
val pagerState = rememberPagerState { tabItems.size }
|
||||
val pagerState = rememberPagerState(0) { tabItems.size }
|
||||
var tabIndex by rememberSaveable { mutableIntStateOf(pagerState.currentPage) }
|
||||
var addAlbumDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (addAlbumDialog) AddAlbumDialog(
|
||||
onDismissRequest = { addAlbumDialog = false },
|
||||
onConfirmation = { navigateToAddWallpaperScreen(it) }
|
||||
)
|
||||
|
||||
LaunchedEffect(tabIndex) {
|
||||
pagerState.animateScrollToPage(tabIndex)
|
||||
}
|
||||
LaunchedEffect(pagerState.currentPage) {
|
||||
tabIndex = pagerState.currentPage
|
||||
}
|
||||
|
||||
Scaffold (
|
||||
topBar = {
|
||||
HomeTopBar(
|
||||
@@ -85,20 +92,8 @@ fun HomeScreen(
|
||||
onSettingsClick = onSettingsClick,
|
||||
)
|
||||
}
|
||||
) { padding ->
|
||||
LaunchedEffect(tabIndex) {
|
||||
if (tabIndex in tabItems.indices) {
|
||||
pagerState.animateScrollToPage(tabIndex)
|
||||
}
|
||||
}
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.currentPage }.collect { page ->
|
||||
if (page in tabItems.indices) {
|
||||
tabIndex = page
|
||||
}
|
||||
}
|
||||
}
|
||||
Column(modifier = Modifier.padding(padding)) {
|
||||
) {
|
||||
Column(modifier = Modifier.padding(it)) {
|
||||
TabRow(
|
||||
selectedTabIndex = tabIndex,
|
||||
indicator = { tabPositions ->
|
||||
@@ -124,10 +119,8 @@ fun HomeScreen(
|
||||
icon = {
|
||||
Icon(
|
||||
imageVector =
|
||||
if (index == tabIndex)
|
||||
item.filledIcon
|
||||
else
|
||||
item.unfilledIcon,
|
||||
if (index == tabIndex) item.filledIcon
|
||||
else item.unfilledIcon,
|
||||
contentDescription = item.title
|
||||
)
|
||||
}
|
||||
@@ -136,8 +129,7 @@ fun HomeScreen(
|
||||
}
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
beyondViewportPageCount = 1,
|
||||
userScrollEnabled = true,
|
||||
beyondViewportPageCount = 1
|
||||
) { index ->
|
||||
when(index) {
|
||||
0 -> WallpaperScreen(
|
||||
|
||||
+2
-1
@@ -95,6 +95,8 @@ fun WallpaperScreen(
|
||||
val openLiveDialog = rememberSaveable { mutableStateOf(false) }
|
||||
val openNoticeDialog = rememberSaveable { mutableStateOf(false) }
|
||||
val showInterval = rememberSaveable { mutableStateOf(false) }
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
if (openLiveDialog.value) {
|
||||
ShowLiveWallpaperEnabledDialog(
|
||||
onDismissRequest = { openLiveDialog.value = false }
|
||||
@@ -108,7 +110,6 @@ fun WallpaperScreen(
|
||||
}
|
||||
)
|
||||
}
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = {
|
||||
|
||||
Reference in new issue
Block a user