diff --git a/app/src/main/java/com/aiosman/riderpro/exp/ViewModel.kt b/app/src/main/java/com/aiosman/riderpro/exp/ViewModel.kt new file mode 100644 index 0000000..1ef7ce9 --- /dev/null +++ b/app/src/main/java/com/aiosman/riderpro/exp/ViewModel.kt @@ -0,0 +1,9 @@ +package com.aiosman.riderpro.exp + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider + +inline fun viewModelFactory(crossinline f: () -> VM) = + object : ViewModelProvider.Factory { + override fun create(aClass: Class):T = f() as T + } \ No newline at end of file diff --git a/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfile.kt b/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfile.kt index 4c68510..9b6911a 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfile.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfile.kt @@ -8,7 +8,6 @@ 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.lazy.LazyColumn import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.pullrefresh.PullRefreshIndicator @@ -24,8 +23,10 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp +import androidx.lifecycle.viewmodel.compose.viewModel import androidx.paging.compose.collectAsLazyPagingItems import com.aiosman.riderpro.R +import com.aiosman.riderpro.exp.viewModelFactory import com.aiosman.riderpro.ui.composables.CustomAsyncImage import com.aiosman.riderpro.ui.index.tabs.profile.MomentPostUnit import com.aiosman.riderpro.ui.index.tabs.profile.UserInformation @@ -34,23 +35,26 @@ import kotlinx.coroutines.launch @OptIn(ExperimentalMaterialApi::class) @Composable fun AccountProfile(id: String) { - val model = AccountProfileViewModel + val model: AccountProfileViewModel = viewModel(factory = viewModelFactory { + AccountProfileViewModel() + }, key = "viewModel_${id}") val scope = rememberCoroutineScope() val items = model.momentsFlow.collectAsLazyPagingItems() val state = rememberPullRefreshState(model.refreshing, onRefresh = { - model.loadProfile(id,pullRefresh = true) + model.loadProfile(id, pullRefresh = true) }) LaunchedEffect(Unit) { model.loadProfile(id) } Box( modifier = Modifier - .fillMaxSize().background(Color.White).pullRefresh(state) + .fillMaxSize() + .pullRefresh(state) + .background(Color(0xFFF5F5F5)) ) { LazyColumn( modifier = Modifier - .fillMaxSize() - .padding(bottom = 16.dp), + .fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Top, ) { @@ -60,27 +64,32 @@ fun AccountProfile(id: String) { .fillMaxWidth() ) { - val banner = model.profile?.banner - if (banner != null) { - CustomAsyncImage( - LocalContext.current, - banner, - modifier = Modifier - .fillMaxWidth() - .height(400.dp), - contentDescription = "", - contentScale = ContentScale.Crop - ) + if (model.profile == null) { + Spacer(modifier = Modifier.height(400.dp)) } else { - Image( - painter = painterResource(id = R.drawable.rider_pro_moment_demo_2), - modifier = Modifier - .fillMaxWidth() - .height(400.dp), - contentDescription = "", - contentScale = ContentScale.Crop - ) + val banner = model.profile?.banner + if (banner != null) { + CustomAsyncImage( + LocalContext.current, + banner, + modifier = Modifier + .fillMaxWidth() + .height(400.dp), + contentDescription = "", + contentScale = ContentScale.Crop + ) + } else { + Image( + painter = painterResource(id = R.drawable.rider_pro_moment_demo_2), + modifier = Modifier + .fillMaxWidth() + .height(400.dp), + contentDescription = "", + contentScale = ContentScale.Crop + ) + } } + } Spacer(modifier = Modifier.height(32.dp)) model.profile?.let { @@ -105,6 +114,9 @@ fun AccountProfile(id: String) { val momentItem = items[idx] ?: return@items MomentPostUnit(momentItem) } + item { + Spacer(modifier = Modifier.height(32.dp)) + } } PullRefreshIndicator(model.refreshing, state, Modifier.align(Alignment.TopCenter)) diff --git a/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfileViewModel.kt b/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfileViewModel.kt index fe7ae9b..c01d3f8 100644 --- a/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfileViewModel.kt +++ b/app/src/main/java/com/aiosman/riderpro/ui/profile/AccountProfileViewModel.kt @@ -23,7 +23,7 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch -object AccountProfileViewModel : ViewModel() { +class AccountProfileViewModel : ViewModel() { var profileId by mutableStateOf(0) val accountService: AccountService = AccountServiceImpl() val momentService: MomentService = MomentServiceImpl() diff --git a/app/src/main/res/mipmap-hdpi/rider_pro_follow_grey.png b/app/src/main/res/mipmap-hdpi/rider_pro_follow_grey.png new file mode 100644 index 0000000..389055e Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/rider_pro_follow_grey.png differ diff --git a/app/src/main/res/mipmap-hdpi/rider_pro_follow_red.png b/app/src/main/res/mipmap-hdpi/rider_pro_follow_red.png new file mode 100644 index 0000000..fa8e520 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/rider_pro_follow_red.png differ diff --git a/app/src/main/res/mipmap-mdpi/rider_pro_follow_grey.png b/app/src/main/res/mipmap-mdpi/rider_pro_follow_grey.png new file mode 100644 index 0000000..d93789f Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/rider_pro_follow_grey.png differ diff --git a/app/src/main/res/mipmap-mdpi/rider_pro_follow_red.png b/app/src/main/res/mipmap-mdpi/rider_pro_follow_red.png new file mode 100644 index 0000000..0f13f89 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/rider_pro_follow_red.png differ diff --git a/app/src/main/res/mipmap-xhdpi/rider_pro_follow_grey.png b/app/src/main/res/mipmap-xhdpi/rider_pro_follow_grey.png new file mode 100644 index 0000000..daeb87a Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/rider_pro_follow_grey.png differ diff --git a/app/src/main/res/mipmap-xhdpi/rider_pro_follow_red.png b/app/src/main/res/mipmap-xhdpi/rider_pro_follow_red.png new file mode 100644 index 0000000..f821178 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/rider_pro_follow_red.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/rider_pro_follow_grey.png b/app/src/main/res/mipmap-xxhdpi/rider_pro_follow_grey.png new file mode 100644 index 0000000..ebc1d9a Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/rider_pro_follow_grey.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/rider_pro_follow_red.png b/app/src/main/res/mipmap-xxhdpi/rider_pro_follow_red.png new file mode 100644 index 0000000..dcf50de Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/rider_pro_follow_red.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_grey.png b/app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_grey.png new file mode 100644 index 0000000..09eb245 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_grey.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_red.png b/app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_red.png new file mode 100644 index 0000000..6d0972f Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_red.png differ