fix #12 修正删除动态后,移除我的页面中的item
This commit is contained in:
@@ -12,12 +12,10 @@ import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.paging.PagingData
|
||||
import androidx.paging.cachedIn
|
||||
import cn.jpush.android.api.JPushInterface
|
||||
import androidx.paging.filter
|
||||
import com.aiosman.riderpro.AppState
|
||||
import com.aiosman.riderpro.AppStore
|
||||
import com.aiosman.riderpro.JpushService
|
||||
import com.aiosman.riderpro.Messaging
|
||||
import com.aiosman.riderpro.data.AccountProfile
|
||||
import com.aiosman.riderpro.data.AccountService
|
||||
import com.aiosman.riderpro.data.AccountServiceImpl
|
||||
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 nickName get() = profile?.nickName ?: ""
|
||||
val avatar get() = profile?.avatar
|
||||
|
||||
@@ -167,7 +167,6 @@ fun ProfileV3(
|
||||
.height(miniToolbarHeight.dp)
|
||||
// 保持在最低高度和当前高度之间
|
||||
.background(AppColors.decentBackground)
|
||||
|
||||
) {
|
||||
}
|
||||
// header
|
||||
|
||||
@@ -131,21 +131,6 @@ object NewPostViewModel : ViewModel() {
|
||||
val uploadImageList = emptyList<UploadImage>().toMutableList()
|
||||
var index = 0
|
||||
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())
|
||||
?.let { savedImageUri ->
|
||||
@@ -162,7 +147,6 @@ object NewPostViewModel : ViewModel() {
|
||||
// 刷新个人动态
|
||||
MyProfileViewModel.loadProfile(pullRefresh = true)
|
||||
TimelineMomentViewModel.refreshPager()
|
||||
|
||||
}
|
||||
|
||||
suspend fun init() {
|
||||
|
||||
@@ -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.tabs.timeline.TimelineMomentViewModel
|
||||
import com.aiosman.riderpro.ui.index.tabs.moment.tabs.timeline.TimelineMomentsList
|
||||
import com.aiosman.riderpro.ui.index.tabs.profile.MyProfileViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@@ -162,6 +163,7 @@ class PostViewModel(
|
||||
moment?.let {
|
||||
service.deleteMoment(it.id)
|
||||
TimelineMomentViewModel.deleteMoment(it.id)
|
||||
MyProfileViewModel.deleteMoment(it.id)
|
||||
}
|
||||
callback()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user