Skip to content

Commit

Permalink
#18 - US05 - android list improved design
Browse files Browse the repository at this point in the history
  • Loading branch information
Harold Jose committed Apr 15, 2024
1 parent a79c342 commit bbacc9e
Show file tree
Hide file tree
Showing 24 changed files with 344 additions and 29 deletions.
1 change: 1 addition & 0 deletions androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<application
android:name=".app.MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Expand Down
Binary file added androidApp/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.haroldjose.familysharedlist.android.app

import android.app.Application
import android.content.Context
import dev.haroldjose.familysharedlist.android.dependencyInjection.androidModule
import dev.haroldjose.familysharedlist.dataLayer.datasource.local.keyValueStorage.AndroidKeyValueStorageDataSource
import dev.haroldjose.familysharedlist.dependencyInjection.modules.appModule
Expand All @@ -10,6 +11,17 @@ import org.koin.core.context.startKoin

class MainApplication : Application() {

init {
instance = this
}
companion object {
private var instance: MainApplication? = null

fun applicationContext() : Context {
return instance!!.applicationContext
}
}

override fun onCreate() {
super.onCreate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ class FamilyListViewModel(
private val getOrCreateAccountFromLocalUuidUseCase: GetOrCreateAccountFromLocalUuidUseCase,
private val getProductByCodeUseCase: GetProductByCodeUseCase
): ViewModel(), IFamilyListViewModel {
private var familyListModelsFull: List<FamilyListModel> by mutableStateOf(arrayListOf())
override var familyListModelsGrouped: Map<LocalDate, List<FamilyListModel>> by mutableStateOf(mapOf())
override var familyListModels: List<FamilyListModel> by mutableStateOf(arrayListOf())
override var loading:Boolean by mutableStateOf(false)
override var newItemName: String by mutableStateOf("")
override var selectedItemUuid: String = ""
override var quantity: Int by mutableStateOf(1)
override var tabIndex: FamilyListPageTabEnum by mutableStateOf(FamilyListPageTabEnum.PENDING)
override var openImageSelectedItem: FamilyListModel? by mutableStateOf(null)

private lateinit var accountModel: AccountModel
private var familyListModelsFull: List<FamilyListModel> by mutableStateOf(arrayListOf())


override var goToSetting: () -> Unit = {}
override var goToQuickInsert: () -> Unit = {}
Expand Down Expand Up @@ -206,6 +209,10 @@ class FamilyListViewModel(
}
}

override fun openImage(item: FamilyListModel) {
openImageSelectedItem = item
}

private suspend fun update(item: FamilyListModel){
loading = true
updateFamilyListUseCase.execute(item = item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class FamilyListViewModelMocked: ViewModel(), IFamilyListViewModel {
override var selectedItemUuid: String = ""
override var quantity: Int = 1
override var tabIndex: FamilyListPageTabEnum = FamilyListPageTabEnum.PRIORIZED
override var openImageSelectedItem: FamilyListModel? = Samples.FamilyList.nutella

override var goToSetting: () -> Unit = {}
override var goToQuickInsert: () -> Unit = {}
Expand All @@ -43,4 +44,6 @@ class FamilyListViewModelMocked: ViewModel(), IFamilyListViewModel {
override suspend fun updateQuantity(uuid: String, quantity: Int) {}

override suspend fun updatePrice(uuid: String, price: Double) {}

override fun openImage(item: FamilyListModel) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface IFamilyListViewModel {
var selectedItemUuid: String
var quantity: Int
var tabIndex: FamilyListPageTabEnum
var openImageSelectedItem: FamilyListModel?

var goToSetting: () -> Unit
var goToQuickInsert: () -> Unit
Expand All @@ -30,4 +31,5 @@ interface IFamilyListViewModel {
suspend fun updateName(uuid: String, name: String)
suspend fun updateQuantity(uuid: String, quantity: Int)
suspend fun updatePrice(uuid: String, price: Double)
fun openImage(item: FamilyListModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.twotone.List
import androidx.compose.material.icons.twotone.CheckCircle
import androidx.compose.material.icons.twotone.ShoppingCart
import androidx.compose.material3.BottomSheetDefaults
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
Expand All @@ -20,13 +24,15 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import dev.haroldjose.familysharedlist.android.app.MyApplicationTheme
import dev.haroldjose.familysharedlist.android.extensions.toCurrencyFormat
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.viewmodels.FamilyListViewModelMocked
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.viewmodels.IFamilyListViewModel
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.FamilyListBottomSheetContent
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.FamilyListBottomSheetOpenImage
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.FamilyListBottomSheetQrcode
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.FamilyListTabItemCompletedView
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.FamilyListTabItemView
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.FamilyListTopAppBarView
Expand All @@ -37,16 +43,33 @@ import kotlinx.coroutines.launch
fun FamilyListPage(
viewModel: IFamilyListViewModel
) {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState()
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
SheetState(
skipPartiallyExpanded = false,
density = LocalDensity.current,
initialValue = SheetValue.PartiallyExpanded,
confirmValueChange = {
if (it == SheetValue.Hidden || it == SheetValue.PartiallyExpanded) {
viewModel.openImageSelectedItem = null
}
true
},
)
)

val coroutineScope = rememberCoroutineScope()

LaunchedEffect(key1 = "FamilyListPage") {
viewModel.loadData(fromNetwork = true)
}

BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetPeekHeight = 128.dp,
sheetContent = FamilyListBottomSheetContent(bottomSheetScaffoldState, viewModel),
sheetContent = when (viewModel.openImageSelectedItem) {
null -> FamilyListBottomSheetQrcode(bottomSheetScaffoldState, viewModel)
else -> FamilyListBottomSheetOpenImage(bottomSheetScaffoldState, viewModel)
},
content = {
Scaffold(
topBar = FamilyListTopAppBarView(viewModel)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.twotone.List
import androidx.compose.material.icons.filled.AddCircle
import androidx.compose.material.icons.twotone.CheckCircle
import androidx.compose.material.icons.twotone.ShoppingCart
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil.compose.SubcomposeAsyncImage
import dev.haroldjose.familysharedlist.Logger
import dev.haroldjose.familysharedlist.android.R
import dev.haroldjose.familysharedlist.android.app.MyApplicationTheme
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.barcodeScanner.QrScannerScreen
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.viewmodels.FamilyListViewModelMocked
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.viewmodels.IFamilyListViewModel
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.FamilyListPageTabEnum
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.rowItem.ColumnRigthDefault
import dev.haroldjose.familysharedlist.domainLayer.extensions.Samples
import kotlinx.coroutines.launch

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun FamilyListBottomSheetOpenImage(
bottomSheetScaffoldState: BottomSheetScaffoldState,
viewModel: IFamilyListViewModel
): @Composable() (ColumnScope.() -> Unit) {
val imageUrl = viewModel.openImageSelectedItem?.product?.imageUrl ?:
viewModel.openImageSelectedItem?.product?.imageFrontUrl ?:
viewModel.openImageSelectedItem?.product?.imageFrontSmallUrl ?:
"https://gamestation.com.br/wp-content/themes/game-station/images/image-not-found.png"

LaunchedEffect(key1 = "FamilyListBottomSheetOpenImage") {
bottomSheetScaffoldState.bottomSheetState.expand()
}

return {
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
SubcomposeAsyncImage(
model = imageUrl,
loading = {
CircularProgressIndicator(
modifier = Modifier
.requiredSize(100.dp),
color = Color.LightGray
)
},
contentDescription = viewModel.openImageSelectedItem?.product?.productName,
contentScale = ContentScale.Fit,
modifier = Modifier
.fillMaxSize()
.clip(RoundedCornerShape(16.dp))
.background(Color.White)
.border(BorderStroke(1.dp, Color.Gray), RoundedCornerShape(16.dp))
.padding(4.dp)
)
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
fun FamilyListBottomSheetOpenImage_Preview() {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState()
val viewModel = FamilyListViewModelMocked()
MyApplicationTheme {
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetPeekHeight = 128.dp,
sheetContent = FamilyListBottomSheetOpenImage(bottomSheetScaffoldState, viewModel),
content = {
Text("FamilyListBottomSheetOpenImage_Preview")
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,18 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.twotone.List
import androidx.compose.material.icons.filled.AddCircle
import androidx.compose.material.icons.twotone.CheckCircle
import androidx.compose.material.icons.twotone.ShoppingCart
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.BottomSheetScaffoldState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -47,19 +39,19 @@ import dev.haroldjose.familysharedlist.android.app.MyApplicationTheme
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.barcodeScanner.QrScannerScreen
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.viewmodels.FamilyListViewModelMocked
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.viewmodels.IFamilyListViewModel
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.FamilyListPageTabEnum
import dev.haroldjose.familysharedlist.android.presentationLayer.pages.familyList.views.components.rowItem.ColumnRigthDefault
import dev.haroldjose.familysharedlist.domainLayer.extensions.Samples
import kotlinx.coroutines.launch

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun FamilyListBottomSheetContent(
fun FamilyListBottomSheetQrcode(
bottomSheetScaffoldState: BottomSheetScaffoldState,
viewModel: IFamilyListViewModel
): @Composable() (ColumnScope.() -> Unit) {
val coroutineScope = rememberCoroutineScope()
return {
LaunchedEffect(key1 = "FamilyListBottomSheetOpenImage") {
bottomSheetScaffoldState.bottomSheetState.partialExpand()
}
Box(
Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -144,16 +136,16 @@ fun FamilyListBottomSheetContent(
@OptIn(ExperimentalMaterial3Api::class)
@Preview
@Composable
fun FamilyListBottomSheetContent_Preview() {
fun FamilyListBottomSheetQrcode_Preview() {
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState()
val viewModel = FamilyListViewModelMocked()
MyApplicationTheme {
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetPeekHeight = 128.dp,
sheetContent = FamilyListBottomSheetContent(bottomSheetScaffoldState, viewModel),
sheetContent = FamilyListBottomSheetQrcode(bottomSheetScaffoldState, viewModel),
content = {
Text("FamilyListBottomSheetContent_Preview")
Text("FamilyListBottomSheetQrcode_Preview")
}
)
}
Expand Down
Loading

0 comments on commit bbacc9e

Please sign in to comment.