From b47b5dcd76c0998b086cb1eb327c0a0a457753ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9luchu?= Date: Mon, 23 Oct 2023 11:18:27 +0200 Subject: [PATCH] Fixed add WhatsApp Stickers in new design --- app/build.gradle.kts | 3 +- app/src/main/AndroidManifest.xml | 14 -- .../core/extensions/ActivityExtensions.kt | 26 +++- .../navigation/NavGraphBuilderExtensions.kt | 2 +- .../wastickersonline/core/utils/Constants.kt | 9 ++ .../details/view/StickerDetailsActivity.kt | 134 ------------------ .../details/view/StickerDetailsView.kt | 133 ++++++++++++----- .../details/viewmodel/DetailsViewModel.kt | 55 +++++++ .../provider/StickerContentProvider.kt | 4 +- .../sticker/repository/StickersRepository.kt | 1 + .../features/sticker/view/DashboardView.kt | 29 ++-- 11 files changed, 213 insertions(+), 197 deletions(-) delete mode 100644 app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsActivity.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e11fad5..e100739 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -18,7 +18,7 @@ android { minSdk = 22 targetSdk = 34 versionCode = 1 - versionName = "2.0.1" + versionName = "3.0.0" vectorDrawables.useSupportLibrary = true contentProviderAuthority = "$applicationId.provider.StickerContentProvider" manifestPlaceholders["contentProviderAuthority"] = contentProviderAuthority @@ -80,6 +80,7 @@ dependencies { implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1") implementation("androidx.browser:browser:1.6.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") + implementation("com.google.accompanist:accompanist-permissions:0.32.0") implementation(libs.bundles.hilt) implementation(libs.bundles.coil) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 21fab89..1e441db 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,8 +5,6 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/jeluchu/wastickersonline/core/extensions/ActivityExtensions.kt b/app/src/main/java/com/jeluchu/wastickersonline/core/extensions/ActivityExtensions.kt index 7876f74..9996ecf 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/core/extensions/ActivityExtensions.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/core/extensions/ActivityExtensions.kt @@ -2,8 +2,14 @@ package com.jeluchu.wastickersonline.core.extensions import android.Manifest import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent import android.content.pm.PackageManager +import android.widget.Toast import androidx.core.app.ActivityCompat +import com.jeluchu.wastickersonline.BuildConfig +import com.jeluchu.wastickersonline.core.utils.Stickers +import com.jeluchu.wastickersonline.features.sticker.models.StickerPack val Activity.permissionStorage: Unit get() { @@ -19,4 +25,22 @@ val Activity.permissionStorage: Unit 1 ) } - } \ No newline at end of file + } + +fun Activity.addStickers(stickerPack: StickerPack) { + val intent = Intent().apply { + action = "com.whatsapp.intent.action.ENABLE_STICKER_PACK" + putExtra(Stickers.packId, stickerPack.identifier.toString()) + putExtra(Stickers.authority, BuildConfig.CONTENT_PROVIDER_AUTHORITY) + putExtra(Stickers.packName, stickerPack.name) + } + try { + startActivityForResult(intent, 200) + } catch (e: ActivityNotFoundException) { + Toast.makeText( + this, + "No se añadió el paquete de stickers. Si deseas añadirlo, instala o actualiza WhatsApp.", + Toast.LENGTH_LONG + ).show() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/jeluchu/wastickersonline/core/ui/navigation/NavGraphBuilderExtensions.kt b/app/src/main/java/com/jeluchu/wastickersonline/core/ui/navigation/NavGraphBuilderExtensions.kt index 1105317..5fe5d9f 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/core/ui/navigation/NavGraphBuilderExtensions.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/core/ui/navigation/NavGraphBuilderExtensions.kt @@ -30,7 +30,7 @@ fun NavGraphBuilder.detailsNav(nav: Destinations) { arguments = listOf(navArgument(NavArgs.Sticker.key) { type = StickerPackType }) ) { StickersDetailsView( - //onBackClick = { nav.goBack(it) }, + onBackClick = { nav.goBack(it) }, //onItemClick = {} //onSearchClick = { /*openActivityFromRight(SearchActivity::class.java)*/ }, //onCategoryClick = { /*showDialogFragment(CategoryDialogFragment())*/ } diff --git a/app/src/main/java/com/jeluchu/wastickersonline/core/utils/Constants.kt b/app/src/main/java/com/jeluchu/wastickersonline/core/utils/Constants.kt index c174e44..01cba8f 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/core/utils/Constants.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/core/utils/Constants.kt @@ -4,6 +4,7 @@ object LocalShared { object Stickers { const val stickers = "stickers" + const val stickerPacks = "sticker_packs" } } @@ -11,4 +12,12 @@ object LocalShared { object Database { const val cache = "WaStickersOnlineCache-db" const val favourites = "WaStickersOnlineFavourites-db" +} + +object Stickers { + const val packId = "sticker_pack_id" + const val authority = "sticker_pack_authority" + const val packName = "sticker_pack_name" + const val stickerpack = "stickerpack" + } \ No newline at end of file diff --git a/app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsActivity.kt b/app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsActivity.kt deleted file mode 100644 index 1b6a078..0000000 --- a/app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsActivity.kt +++ /dev/null @@ -1,134 +0,0 @@ -package com.jeluchu.wastickersonline.features.details.view - -import android.graphics.Bitmap -import android.os.Bundle -import androidx.activity.compose.setContent -import androidx.appcompat.app.AppCompatActivity -import androidx.core.graphics.drawable.toBitmap -import androidx.lifecycle.lifecycleScope -import coil.ImageLoader -import coil.request.ImageRequest -import com.jeluchu.jchucomponents.ktx.coroutines.noCrash -import com.jeluchu.jchucomponents.ktx.strings.getLastBitFromUrl -import com.jeluchu.jchucomponents.ktx.strings.saveImage -import com.jeluchu.wastickersonline.core.utils.ConstantsMeth.Companion.getApiEndpointStickers -import com.jeluchu.wastickersonline.features.sticker.models.StickerPack -import com.jeluchu.wastickersonline.features.sticker.view.MainActivity -import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.launch -import java.io.File -import java.io.FileOutputStream - -@AndroidEntryPoint -class StickerDetailsActivity : AppCompatActivity() { - - //private val binding by viewBinding(ActivityStickerDetailsBinding::inflate) - - //private val adapterStickers: StickersDetailsAdapter by inject() - - private var stickerPackView: StickerPack? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - //setContentView(binding.root) - //initUI() - //initListeners() - //if (intent.extras != null) { - // stickerPackView = intent.serializable("stickerpack") as StickerPack? - //} - - getStickerPack() - setContent { - StickersDetailsView() - } - } - - /* - private fun initUI() = with(binding) { - if (intent.extras != null) { - stickerPackView = intent.serializable("stickerpack") as StickerPack? - } - - ivTrayImage.load(stickerPackView!!.trayImageFile) - tvPackName.simpleText(stickerPackView!!.name) - tvAuthor.simpleText(stickerPackView!!.publisher) - - adapterStickers.supportFragmentManager = supportFragmentManager - adapterStickers.submitList(stickerPackView?.stickers.orEmpty()) - rvStickers.apply { - setHasFixedSize(true) - setItemViewCacheSize(30) - adapter = adapterStickers - scheduleLayoutAnimation() - } - - } - - private fun initListeners() = with(binding) { - ivBack.setOnClickListener { exitActivityLeft() } - mcvAddToWhatsApp.setOnClickListener { - val intent = Intent().apply { - action = "com.whatsapp.intent.action.ENABLE_STICKER_PACK" - putExtra(EXTRA_STICKER_PACK_ID, stickerPackView!!.identifier.toString()) - putExtra(EXTRA_STICKER_PACK_AUTHORITY, BuildConfig.CONTENT_PROVIDER_AUTHORITY) - putExtra(EXTRA_STICKER_PACK_NAME, stickerPackView!!.name) - } - try { - startActivityForResult(intent, 200) - } catch (e: ActivityNotFoundException) { - Toast.makeText( - this@StickerDetailsActivity, - "No se añadió el paquete de stickers. Si deseas añadirlo, instala o actualiza WhatsApp.", - Toast.LENGTH_LONG - ).show() - } - } - mcvAddToTelegram.setOnClickListener { openInCustomTab(stickerPackView!!.publisherWebsite) } - onBackPressedDispatcher.addCallback( - this@StickerDetailsActivity, - object : OnBackPressedCallback(true) { - override fun handleOnBackPressed() = exitActivityLeft() - } - ) - } - */ - private fun getStickerPack() { - noCrash { - - val trayImageFile = stickerPackView!!.trayImageFile.getLastBitFromUrl() - - val req = ImageRequest.Builder(this@StickerDetailsActivity) - .data(getApiEndpointStickers() + stickerPackView!!.identifier + "/" + trayImageFile) - .target { - val myDir = - File("${MainActivity.path}/${stickerPackView!!.identifier}/try") - myDir.mkdirs() - val imageName = trayImageFile.replace(".png", "").replace(" ", "_") + ".png" - val file = File(myDir, imageName) - if (file.exists()) file.delete() - try { - val out = FileOutputStream(file) - it.toBitmap().compress(Bitmap.CompressFormat.PNG, 40, out) - out.close() - } catch (e: Exception) { - e.printStackTrace() - } - }.build() - - lifecycleScope.launch { ImageLoader(this@StickerDetailsActivity).execute(req) } - - for (s in stickerPackView!!.stickers) { - val imageFile = s.imageFile.getLastBitFromUrl() - - val myDir = File("${MainActivity.path}/${stickerPackView!!.identifier}") - myDir.mkdirs() - val file = File(myDir, imageFile) - if (file.exists()) file.delete() - - (getApiEndpointStickers() + stickerPackView!!.identifier + "/" + imageFile).saveImage( - File("${MainActivity.path}/${stickerPackView!!.identifier}", imageFile) - ) - } - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsView.kt b/app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsView.kt index d229471..212f520 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsView.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/features/details/view/StickerDetailsView.kt @@ -3,28 +3,45 @@ package com.jeluchu.wastickersonline.features.details.view import android.app.Activity import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel +import com.jeluchu.jchucomponents.ktx.compose.toImageVector +import com.jeluchu.jchucomponents.ktx.compose.toStringRes +import com.jeluchu.jchucomponents.ktx.numbers.height import com.jeluchu.jchucomponents.ui.accompanist.systemui.SystemStatusBarColors import com.jeluchu.jchucomponents.ui.composables.images.NetworkImage import com.jeluchu.jchucomponents.ui.extensions.modifier.cornerRadius +import com.jeluchu.jchucomponents.ui.foundation.icon.IconLink import com.jeluchu.jchucomponents.ui.foundation.lists.ColumnContentAlignment import com.jeluchu.jchucomponents.ui.foundation.lists.LazyStaticGrid import com.jeluchu.jchucomponents.ui.foundation.lists.ListColumn import com.jeluchu.jchucomponents.ui.foundation.lists.RowContentAlignment +import com.jeluchu.wastickersonline.R +import com.jeluchu.wastickersonline.core.extensions.addStickers +import com.jeluchu.wastickersonline.core.ui.theme.darkGreen import com.jeluchu.wastickersonline.core.ui.theme.darkness +import com.jeluchu.wastickersonline.core.ui.theme.milky import com.jeluchu.wastickersonline.core.ui.theme.primary import com.jeluchu.wastickersonline.core.ui.theme.secondary import com.jeluchu.wastickersonline.features.details.viewmodel.DetailViewModel @@ -32,6 +49,7 @@ import com.jeluchu.wastickersonline.features.sticker.models.StickerPack @Composable fun StickersDetailsView( + onBackClick: () -> Unit, vm: DetailViewModel = hiltViewModel(), act: Activity = LocalContext.current as Activity ) { @@ -40,49 +58,94 @@ fun StickersDetailsView( systemBarsColor = primary ) - StickersDetails(vm.state!!) + StickersDetails( + activity = act, + onBackClick = onBackClick, + stickerPack = vm.state!!, + ) } @OptIn(ExperimentalMaterial3Api::class) @Composable private fun StickersDetails( + activity: Activity, + onBackClick: () -> Unit, stickerPack: StickerPack -) = Scaffold( - topBar = { - CenterAlignedTopAppBar( - title = { Text(text = stickerPack.name) }, - colors = TopAppBarDefaults.centerAlignedTopAppBarColors( - containerColor = primary, - titleContentColor = darkness - ) - ) - }, - containerColor = primary -) { paddingValues -> - ListColumn( - modifier = Modifier.padding(paddingValues), - contentPadding = PaddingValues(15.dp) - ) { - item { - LazyStaticGrid( - columns = 4, - items = stickerPack.stickers, - rowContentAlignment = RowContentAlignment( - horizontalArrangement = Arrangement.spacedBy(10.dp) - ), - columnContentAlignment = ColumnContentAlignment( - verticalArrangement = Arrangement.spacedBy(10.dp) - ) - ) { sticker -> - NetworkImage( - modifier = Modifier - .weight(1f) - .aspectRatio(1f) - .clip(10.cornerRadius()) - .background(secondary), - url = sticker.imageFile +) = Box { + Scaffold( + topBar = { + CenterAlignedTopAppBar( + title = { Text(text = stickerPack.name) }, + navigationIcon = { + IconLink( + imageVector = R.drawable.ic_arrow_left.toImageVector(), + onClick = onBackClick, + contentDescription = "" + ) + }, + colors = TopAppBarDefaults.centerAlignedTopAppBarColors( + containerColor = primary, + titleContentColor = darkness ) + ) + }, + containerColor = primary + ) { paddingValues -> + ListColumn( + modifier = Modifier.padding(paddingValues), + contentPadding = PaddingValues(15.dp) + ) { + item { + LazyStaticGrid( + columns = 4, + items = stickerPack.stickers, + rowContentAlignment = RowContentAlignment( + horizontalArrangement = Arrangement.spacedBy(10.dp) + ), + columnContentAlignment = ColumnContentAlignment( + verticalArrangement = Arrangement.spacedBy(10.dp) + ) + ) { sticker -> + NetworkImage( + modifier = Modifier + .weight(1f) + .aspectRatio(1f) + .clip(10.cornerRadius()) + .background(secondary), + url = sticker.imageFile + ) + } } + item { 100.height() } + } + } + + Column( + modifier = Modifier + .fillMaxWidth() + .align(Alignment.BottomCenter) + .clip(RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp)) + .background(darkGreen) + .padding(15.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(5.dp) + ) { + Button( + modifier = Modifier.fillMaxWidth(), + shape = 15.cornerRadius(), + colors = ButtonDefaults.buttonColors( + containerColor = secondary + ), + onClick = { activity.addStickers(stickerPack) }, + contentPadding = ButtonDefaults.ButtonWithIconContentPadding + ) { + Text( + modifier = Modifier.padding(5.dp), + text = R.string.add_to_whatsapp.toStringRes(), + textAlign = TextAlign.Center, + fontSize = 18.sp, + color = milky + ) } } } \ No newline at end of file diff --git a/app/src/main/java/com/jeluchu/wastickersonline/features/details/viewmodel/DetailsViewModel.kt b/app/src/main/java/com/jeluchu/wastickersonline/features/details/viewmodel/DetailsViewModel.kt index 9d4672e..fc65837 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/features/details/viewmodel/DetailsViewModel.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/features/details/viewmodel/DetailsViewModel.kt @@ -1,12 +1,26 @@ package com.jeluchu.wastickersonline.features.details.viewmodel +import android.graphics.Bitmap import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue +import androidx.core.graphics.drawable.toBitmap import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import coil.ImageLoader +import coil.request.ImageRequest +import com.jeluchu.jchucomponents.ktx.coroutines.noCrash +import com.jeluchu.jchucomponents.ktx.strings.getLastBitFromUrl +import com.jeluchu.jchucomponents.ktx.strings.saveImage +import com.jeluchu.wastickersonline.WaStickersOnline import com.jeluchu.wastickersonline.core.ui.navigation.NavArgs +import com.jeluchu.wastickersonline.core.utils.ConstantsMeth import com.jeluchu.wastickersonline.features.sticker.models.StickerPack +import com.jeluchu.wastickersonline.features.sticker.view.MainActivity +import kotlinx.coroutines.launch +import java.io.File +import java.io.FileOutputStream class DetailViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { @@ -17,5 +31,46 @@ class DetailViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { init { state = item + getStickerPack() + } + + private fun getStickerPack() = with(WaStickersOnline.getContext()) { + noCrash { + + val trayImageFile = item.trayImageFile.getLastBitFromUrl() + + val req = ImageRequest.Builder(this) + .data(ConstantsMeth.getApiEndpointStickers() + item.identifier + "/" + trayImageFile) + .target { + val myDir = + File("${MainActivity.path}/${item.identifier}/try") + myDir.mkdirs() + val imageName = trayImageFile.replace(".png", "").replace(" ", "_") + ".png" + val file = File(myDir, imageName) + if (file.exists()) file.delete() + try { + val out = FileOutputStream(file) + it.toBitmap().compress(Bitmap.CompressFormat.PNG, 40, out) + out.close() + } catch (e: Exception) { + e.printStackTrace() + } + }.build() + + viewModelScope.launch { ImageLoader(this@with).execute(req) } + + for (s in item.stickers) { + val imageFile = s.imageFile.getLastBitFromUrl() + + val myDir = File("${MainActivity.path}/${item.identifier}") + myDir.mkdirs() + val file = File(myDir, imageFile) + if (file.exists()) file.delete() + + (ConstantsMeth.getApiEndpointStickers() + item.identifier + "/" + imageFile).saveImage( + File("${MainActivity.path}/${item.identifier}", imageFile) + ) + } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/provider/StickerContentProvider.kt b/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/provider/StickerContentProvider.kt index d54f016..d27ad9d 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/provider/StickerContentProvider.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/provider/StickerContentProvider.kt @@ -53,7 +53,7 @@ class StickerContentProvider : ContentProvider() { override fun query( uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String? - ): Cursor? = + ): Cursor = when (MATCHER.match(uri)) { METADATA_CODE -> getPackForAllStickerPacks(uri) METADATA_CODE_FOR_SINGLE_PACK -> getCursorForSingleStickerPack(uri) @@ -134,7 +134,7 @@ class StickerContentProvider : ContentProvider() { } } - override fun getType(uri: Uri): String? = + override fun getType(uri: Uri): String = when (MATCHER.match(uri)) { METADATA_CODE -> "vnd.android.cursor.dir/vnd." + BuildConfig.CONTENT_PROVIDER_AUTHORITY + "." + METADATA METADATA_CODE_FOR_SINGLE_PACK -> "vnd.android.cursor.item/vnd." + BuildConfig.CONTENT_PROVIDER_AUTHORITY + "." + METADATA diff --git a/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/repository/StickersRepository.kt b/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/repository/StickersRepository.kt index 5be05c3..3d14154 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/repository/StickersRepository.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/repository/StickersRepository.kt @@ -31,6 +31,7 @@ interface StickersRepository { saveFetchResult = { data -> local.deleteAll() preferences.saveLong(LocalShared.Stickers.stickers, System.currentTimeMillis()) + preferences.saveObjectsList(LocalShared.Stickers.stickerPacks, data) data.forEach { local.insertStickers(it.toStickerPackEntity()) } }, shouldFetch = { diff --git a/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/view/DashboardView.kt b/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/view/DashboardView.kt index 24062bd..23cb2e7 100644 --- a/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/view/DashboardView.kt +++ b/app/src/main/java/com/jeluchu/wastickersonline/features/sticker/view/DashboardView.kt @@ -1,6 +1,5 @@ package com.jeluchu.wastickersonline.features.sticker.view -import android.app.Activity import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -9,8 +8,11 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.items +import androidx.compose.material3.Button import androidx.compose.material3.CenterAlignedTopAppBar import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -20,11 +22,16 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle +import com.google.accompanist.permissions.ExperimentalPermissionsApi +import com.google.accompanist.permissions.isGranted +import com.google.accompanist.permissions.rememberPermissionState +import com.google.accompanist.permissions.shouldShowRationale import com.jeluchu.jchucomponents.core.states.ListStates +import com.jeluchu.jchucomponents.ktx.compose.toPainter +import com.jeluchu.jchucomponents.ktx.packageutils.buildIsTiramisuAndUp import com.jeluchu.jchucomponents.ui.accompanist.systemui.SystemStatusBarColors import com.jeluchu.jchucomponents.ui.composables.column.ScrollableColumn import com.jeluchu.jchucomponents.ui.composables.images.NetworkImage @@ -60,12 +67,18 @@ fun DashboardView( @Composable private fun DashboardView( state: ListStates, - act: Activity = LocalContext.current as Activity, onStickerClick: (StickerPack) -> Unit ) = Scaffold( topBar = { CenterAlignedTopAppBar( title = { Text(text = "Stickers") }, + navigationIcon = { + Icon( + modifier = Modifier.size(30.dp), + painter = com.jeluchu.jchucomponents.ui.R.drawable.ic_deco_jeluchu.toPainter(), + contentDescription = "" + ) + }, colors = TopAppBarDefaults.centerAlignedTopAppBarColors( containerColor = primary, titleContentColor = darkness @@ -73,15 +86,13 @@ private fun DashboardView( ) }, containerColor = primary -) { +) { paddingValues -> ScrollableColumn( - modifier = Modifier.padding(it) + modifier = Modifier.padding(paddingValues) ) { state.data.forEach { Column( - modifier = Modifier.clickable { - onStickerClick(it) - } + modifier = Modifier.clickable { onStickerClick(it) } ) { Surface( modifier = Modifier.padding(horizontal = 15.dp), @@ -99,7 +110,7 @@ private fun DashboardView( contentPadding = PaddingValues(15.dp), horizontalArrangement = Arrangement.spacedBy(5.dp), ) { - items(it.stickers) { sticker -> + items(it.stickers, key = { it }) { sticker -> NetworkImage( modifier = Modifier .size(90.dp)