fix #12 修正删除动态后,移除我的页面中的item

This commit is contained in:
2024-11-03 16:51:23 +08:00
parent 7152bfd9c1
commit 34ce648102
4 changed files with 11 additions and 20 deletions

View File

@@ -12,12 +12,10 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig import androidx.paging.PagingConfig
import androidx.paging.PagingData import androidx.paging.PagingData
import androidx.paging.cachedIn import androidx.paging.cachedIn
import cn.jpush.android.api.JPushInterface import androidx.paging.filter
import com.aiosman.riderpro.AppState import com.aiosman.riderpro.AppState
import com.aiosman.riderpro.AppStore import com.aiosman.riderpro.AppStore
import com.aiosman.riderpro.JpushService
import com.aiosman.riderpro.Messaging import com.aiosman.riderpro.Messaging
import com.aiosman.riderpro.data.AccountProfile
import com.aiosman.riderpro.data.AccountService import com.aiosman.riderpro.data.AccountService
import com.aiosman.riderpro.data.AccountServiceImpl import com.aiosman.riderpro.data.AccountServiceImpl
import com.aiosman.riderpro.data.MomentService import com.aiosman.riderpro.data.MomentService
@@ -119,6 +117,14 @@ object MyProfileViewModel : ViewModel() {
} }
} }
fun deleteMoment(id: Int) {
val currentPagingData = _sharedFlow.value
val updatedPagingData = currentPagingData.filter { momentItem ->
momentItem.id != id
}
_sharedFlow.value = updatedPagingData
}
val bio get() = profile?.bio ?: "" val bio get() = profile?.bio ?: ""
val nickName get() = profile?.nickName ?: "" val nickName get() = profile?.nickName ?: ""
val avatar get() = profile?.avatar val avatar get() = profile?.avatar

View File

@@ -167,7 +167,6 @@ fun ProfileV3(
.height(miniToolbarHeight.dp) .height(miniToolbarHeight.dp)
// 保持在最低高度和当前高度之间 // 保持在最低高度和当前高度之间
.background(AppColors.decentBackground) .background(AppColors.decentBackground)
) { ) {
} }
// header // header

View File

@@ -131,21 +131,6 @@ object NewPostViewModel : ViewModel() {
val uploadImageList = emptyList<UploadImage>().toMutableList() val uploadImageList = emptyList<UploadImage>().toMutableList()
var index = 0 var index = 0
for (item in imageList) { for (item in imageList) {
val cursor = context.contentResolver.query(Uri.parse(item.uri), null, null, null, null)
// cursor?.use {
// if (it.moveToFirst()) {
// val columnIndex = it.getColumnIndex("_display_name")
// if (columnIndex != -1) {
// val displayName = it.getString(columnIndex)
// val extension = displayName.substringAfterLast(".")
// Log.d("NewPost", "File name: $displayName, extension: $extension")
// // read as file
// val file = uriToFile(context, Uri.parse(item.uri))
// Log.d("NewPost", "File size: ${file.length()}")
// uploadImageList += UploadImage(file, displayName, item.uri, extension)
// }
// }
// }
// 保存图片到本地 // 保存图片到本地
FileUtil.bitmapToJPG(context, item.bitmap, UUID.randomUUID().toString()) FileUtil.bitmapToJPG(context, item.bitmap, UUID.randomUUID().toString())
?.let { savedImageUri -> ?.let { savedImageUri ->
@@ -162,7 +147,6 @@ object NewPostViewModel : ViewModel() {
// 刷新个人动态 // 刷新个人动态
MyProfileViewModel.loadProfile(pullRefresh = true) MyProfileViewModel.loadProfile(pullRefresh = true)
TimelineMomentViewModel.refreshPager() TimelineMomentViewModel.refreshPager()
} }
suspend fun init() { suspend fun init() {

View File

@@ -16,6 +16,7 @@ import com.aiosman.riderpro.entity.MomentServiceImpl
import com.aiosman.riderpro.ui.index.tabs.moment.MomentViewModel import com.aiosman.riderpro.ui.index.tabs.moment.MomentViewModel
import com.aiosman.riderpro.ui.index.tabs.moment.tabs.timeline.TimelineMomentViewModel import com.aiosman.riderpro.ui.index.tabs.moment.tabs.timeline.TimelineMomentViewModel
import com.aiosman.riderpro.ui.index.tabs.moment.tabs.timeline.TimelineMomentsList import com.aiosman.riderpro.ui.index.tabs.moment.tabs.timeline.TimelineMomentsList
import com.aiosman.riderpro.ui.index.tabs.profile.MyProfileViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -162,6 +163,7 @@ class PostViewModel(
moment?.let { moment?.let {
service.deleteMoment(it.id) service.deleteMoment(it.id)
TimelineMomentViewModel.deleteMoment(it.id) TimelineMomentViewModel.deleteMoment(it.id)
MyProfileViewModel.deleteMoment(it.id)
} }
callback() callback()
} }