更新个人主页
- 使用ViewModel重构个人主页 - 优化个人主页UI细节 - 新增关注功能图片资源
9
app/src/main/java/com/aiosman/riderpro/exp/ViewModel.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.aiosman.riderpro.exp
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
|
||||
inline fun <VM : ViewModel> viewModelFactory(crossinline f: () -> VM) =
|
||||
object : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(aClass: Class<T>):T = f() as T
|
||||
}
|
||||
@@ -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,6 +64,9 @@ fun AccountProfile(id: String) {
|
||||
.fillMaxWidth()
|
||||
|
||||
) {
|
||||
if (model.profile == null) {
|
||||
Spacer(modifier = Modifier.height(400.dp))
|
||||
} else {
|
||||
val banner = model.profile?.banner
|
||||
if (banner != null) {
|
||||
CustomAsyncImage(
|
||||
@@ -82,6 +89,8 @@ fun AccountProfile(id: String) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Spacer(modifier = Modifier.height(32.dp))
|
||||
model.profile?.let {
|
||||
UserInformation(
|
||||
@@ -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))
|
||||
|
||||
@@ -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()
|
||||
|
||||
BIN
app/src/main/res/mipmap-hdpi/rider_pro_follow_grey.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
app/src/main/res/mipmap-hdpi/rider_pro_follow_red.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
app/src/main/res/mipmap-mdpi/rider_pro_follow_grey.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-mdpi/rider_pro_follow_red.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/rider_pro_follow_grey.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
app/src/main/res/mipmap-xhdpi/rider_pro_follow_red.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/rider_pro_follow_grey.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/rider_pro_follow_red.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_grey.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/rider_pro_follow_red.png
Normal file
|
After Width: | Height: | Size: 16 KiB |