Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Dec 25, 2024
1 parent 225c87f commit 40e2e8c
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .run/iosApp.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="iosApp" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="00008120-000A61801440C01E" XCODE_PROJECT="$PROJECT_DIR$/iosApp/iosApp.xcodeproj" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosApp">
<configuration default="false" name="iosApp" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="0B2971F4-719E-4A66-993F-88A4B3A469FC" XCODE_PROJECT="$PROJECT_DIR$/iosApp/iosApp.xcodeproj" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosApp">
<method v="2">
<option name="com.jetbrains.kmm.ios.BuildIOSAppTask" enabled="true" />
</method>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@file:OptIn(ExperimentalForeignApi::class)

package org.michaelbel.movies.persistence.datastore.di

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import okio.Path.Companion.toPath
import kotlinx.cinterop.ExperimentalForeignApi
import org.koin.dsl.module
import org.michaelbel.movies.persistence.datastore.DATA_STORE_NAME
import platform.Foundation.NSDocumentDirectory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@file:OptIn(ExperimentalForeignApi::class)

package org.michaelbel.movies.persistence.datastore.di

import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
import androidx.datastore.preferences.core.Preferences
import okio.Path.Companion.toPath
import kotlinx.cinterop.ExperimentalForeignApi
import org.koin.dsl.module
import org.michaelbel.movies.persistence.datastore.DATA_STORE_NAME
import platform.Foundation.NSDocumentDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package org.michaelbel.movies.ui.ktx

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.provider.Settings
import android.speech.RecognizerIntent
Expand All @@ -15,6 +17,26 @@ import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import androidx.core.net.toUri

fun Context.navigateToShareText(text: String, title: String) {
Intent().apply {
type = "text/plain"
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, text)
}.also { intent: Intent ->
startActivity(Intent.createChooser(intent, title))
}
}

fun Context.navigateToImageUri(uri: Uri) {
Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "image/jpg")
flags = Intent.FLAG_ACTIVITY_NEW_TASK
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}.also { intent ->
startActivity(intent)
}
}

@Composable
fun rememberSpeechRecognitionLauncher(onInputText: (String) -> Unit): () -> Unit {
val speechRecognizeContract = rememberLauncherForActivityResult(
Expand Down Expand Up @@ -64,6 +86,12 @@ fun rememberNavigateToAppSettings(): () -> Unit {
return remember { { appSettingsContract.launch(intent) } }
}

@Composable
fun rememberNavigateToDeveloperSettings(): () -> Unit {
val appSettingsContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
return remember { { appSettingsContract.launch(Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)) } }
}

@Composable
fun rememberRequestNotificationPermission(
onGranted: () -> Unit = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AccountViewModel(
.stateIn(
scope = scope,
started = SharingStarted.Lazily,
initialValue = AccountPojo.Empty
initialValue = null
)

override fun handleError(throwable: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ internal fun AccountScreenContent(
strokeWidth = 2.dp
)
} else {
Text(text = stringResource(MoviesStrings.account_logout))
Text(
text = stringResource(MoviesStrings.account_logout)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
package org.michaelbel.movies.debug.ui

import android.app.Activity
import android.content.Intent
import android.provider.Settings
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
Expand All @@ -29,11 +25,12 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import org.koin.androidx.compose.koinViewModel
import org.michaelbel.movies.common.ktx.appSettingsIntent
import org.michaelbel.movies.debug.DebugViewModel
import org.michaelbel.movies.debug_impl.R
import org.michaelbel.movies.ui.icons.MoviesAndroidIcons
import org.michaelbel.movies.ui.ktx.collectAsStateCommon
import org.michaelbel.movies.ui.ktx.rememberNavigateToAppSettings
import org.michaelbel.movies.ui.ktx.rememberNavigateToDeveloperSettings
import org.michaelbel.movies.ui.theme.MoviesTheme

@Composable
Expand All @@ -46,7 +43,8 @@ internal fun DebugActivityContent(

val context = LocalContext.current
val clipboardManager = LocalClipboardManager.current
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
val navigateToAppSettings = rememberNavigateToAppSettings()
val navigateToDeveloperSettings = rememberNavigateToDeveloperSettings()
val topAppBarScrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
state = rememberTopAppBarState(),
canScroll = { true }
Expand All @@ -60,9 +58,9 @@ internal fun DebugActivityContent(
modifier = Modifier.nestedScroll(topAppBarScrollBehavior.nestedScrollConnection),
topBar = {
DebugToolbar(
onNavigationIconClick = { (context as Activity).finish() },
modifier = Modifier.fillMaxWidth(),
topAppBarScrollBehavior = topAppBarScrollBehavior,
onNavigationIconClick = { (context as Activity).finish() }
topAppBarScrollBehavior = topAppBarScrollBehavior
)
},
containerColor = MaterialTheme.colorScheme.primaryContainer
Expand All @@ -77,7 +75,7 @@ internal fun DebugActivityContent(
title = stringResource(R.string.debug_app_settings),
description = "",
icon = painterResource(MoviesAndroidIcons.SettingsCinematicBlur24),
onClick = { resultContract.launch(context.appSettingsIntent) }
onClick = navigateToAppSettings
)
}
item {
Expand All @@ -92,7 +90,7 @@ internal fun DebugActivityContent(
title = stringResource(R.string.debug_developer_settings),
description = "",
icon = painterResource(MoviesAndroidIcons.SettingsAccountBox24),
onClick = { resultContract.launch(Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS)) }
onClick = navigateToDeveloperSettings
)
}
if (viewModel.isFirebaseTokenFeatureEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import org.michaelbel.movies.ui.ktx.displayCutoutWindowInsets

@Composable
internal fun DebugToolbar(
onNavigationIconClick: () -> Unit,
modifier: Modifier = Modifier,
topAppBarScrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(),
onNavigationIconClick: () -> Unit
topAppBarScrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
) {
LargeTopAppBar(
title = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ internal fun SettingItem(
Row(
modifier = modifier
.fillMaxWidth()
.clickable { onClick() }
.clickable(onClick = onClick)
.padding(horizontal = 8.dp, vertical = 20.dp),
verticalAlignment = Alignment.CenterVertically,
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painter = icon,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.michaelbel.movies.details.ui

import android.content.Intent
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import org.jetbrains.compose.resources.stringResource
import org.michaelbel.movies.common.theme.AppTheme
import org.michaelbel.movies.details.DetailsViewModel
import org.michaelbel.movies.ui.ktx.collectAsStateCommon
import org.michaelbel.movies.ui.ktx.navigateToShareText
import org.michaelbel.movies.ui.strings.MoviesStrings

@Composable
Expand All @@ -23,22 +22,12 @@ actual fun DetailsRoute(
val networkStatus by viewModel.networkStatus.collectAsStateCommon()
val currentTheme by viewModel.currentTheme.collectAsStateCommon()

val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}
val context = LocalContext.current
val shareTitle = stringResource(MoviesStrings.share_via)

val onShareUrl: (String) -> Unit = { url ->
Intent().apply {
type = "text/plain"
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, url)
}.also { intent: Intent ->
resultContract.launch(Intent.createChooser(intent, shareTitle))
}
}

DetailsScreenContent(
onBackClick = onBackClick,
onShareClick = onShareUrl,
onShareClick = { context.navigateToShareText(it, shareTitle) },
onNavigateToGallery = onNavigateToGallery,
onGenerateColors = viewModel::onGenerateColors,
detailsState = detailsState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal fun DetailsToolbar(
actions = {
AnimatedVisibility(
visible = movieUrl != null,
modifier = Modifier.then(modifierDisplayCutoutWindowInsets),
modifier = modifierDisplayCutoutWindowInsets,
enter = fadeIn()
) {
if (movieUrl != null) {
Expand All @@ -62,7 +62,7 @@ internal fun DetailsToolbar(
navigationIcon = {
BackIcon(
onClick = onNavigationIconClick,
modifier = Modifier.then(modifierDisplayCutoutWindowInsets),
modifier = modifierDisplayCutoutWindowInsets,
onContainerColor = onContainerColor
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ internal fun FeedScreenContent(
pagingItems = pagingItems,
onMovieClick = onNavigateToDetails,
contentPadding = innerPadding,
modifier = Modifier.windowInsetsPadding(displayCutoutWindowInsets),
modifier = Modifier.windowInsetsPadding(displayCutoutWindowInsets)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ internal fun FeedToolbar(
{
SearchIcon(
onClick = onSearchIconClick,
modifier = Modifier.then(modifierDisplayCutoutWindowInsets)
modifier = modifierDisplayCutoutWindowInsets
)
}
} else {
{}
},
actions = {
Row(
modifier = Modifier.then(modifierDisplayCutoutWindowInsets)
modifier = modifierDisplayCutoutWindowInsets
) {
if (isSettingsIconVisible) {
SettingsIcon(
Expand Down Expand Up @@ -115,7 +115,9 @@ internal fun FeedToolbar(

if (isTmdbApiKeyEmpty) {
ApiKeyBox(
modifier = Modifier.fillMaxWidth().padding(vertical = 16.dp)
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.michaelbel.movies.gallery.ui

import android.content.Intent
import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -57,6 +54,7 @@ import org.michaelbel.movies.ui.accessibility.MoviesContentDescription
import org.michaelbel.movies.ui.compose.iconbutton.BackIcon
import org.michaelbel.movies.ui.compose.iconbutton.DownloadIcon
import org.michaelbel.movies.ui.ktx.displayCutoutWindowInsets
import org.michaelbel.movies.ui.ktx.navigateToImageUri
import org.michaelbel.movies.ui.theme.MoviesTheme
import org.michaelbel.movies.work.DownloadImageWorker
import org.michaelbel.movies.work.WorkInfoState
Expand All @@ -73,7 +71,6 @@ internal fun GalleryScreenContent(
val hapticFeedback = LocalHapticFeedback.current
val coroutineScope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {}

val pagerState = rememberPagerState(pageCount = { movieImages.size })
var currentPage by remember { mutableIntStateOf(0) }
Expand All @@ -92,13 +89,7 @@ internal fun GalleryScreenContent(
duration = SnackbarDuration.Long
)
if (result == SnackbarResult.ActionPerformed) {
Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "image/jpg")
flags = Intent.FLAG_ACTIVITY_NEW_TASK
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}.also { intent ->
resultContract.launch(intent)
}
context.navigateToImageUri(uri)
}
}
}
Expand Down Expand Up @@ -130,7 +121,9 @@ internal fun GalleryScreenContent(
Scaffold(
modifier = modifier.fillMaxSize(),
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
SnackbarHost(
hostState = snackbarHostState
)
},
containerColor = MaterialTheme.colorScheme.primaryContainer
) { innerPadding ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ internal fun LoopHorizontalPager(
pagerState: PagerState,
modifier: Modifier = Modifier,
contentPadding: PaddingValues = PaddingValues(0.dp),
content: @Composable PagerScope.(page: Int) -> Unit,
content: @Composable PagerScope.(page: Int) -> Unit
) {
HorizontalPager(
state = pagerState,
modifier = modifier,
contentPadding = contentPadding,
pageSpacing = 8.dp,
flingBehavior = PagerDefaults.flingBehavior(state = pagerState),
pageContent = { index ->
content(index)
}
pageContent = { index -> content(index) }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ actual fun GalleryRoute(
) {
Text(
text = "Gallery",
modifier = Modifier.clickable { onBackClick() }
modifier = Modifier.clickable(onClick = onBackClick)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ actual fun GalleryRoute(
) {
Text(
text = "Gallery",
modifier = Modifier.clickable { onBackClick() }
modifier = Modifier.clickable(onClick = onBackClick)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ actual fun SearchRoute(
) {
Text(
text = "Feed",
modifier = Modifier.clickable { onBackClick() }
modifier = Modifier.clickable(onClick = onBackClick)
)
}
Loading

0 comments on commit 40e2e8c

Please sign in to comment.