Merge remote-tracking branch 'refs/remotes/origin/main'

This commit is contained in:
2024-09-17 16:08:34 +08:00
7 changed files with 33 additions and 10 deletions

View File

@@ -41,9 +41,14 @@
android:theme="@style/Theme.RiderPro">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<service
android:name=".MyFirebaseMessagingService"

View File

@@ -4,7 +4,9 @@ import android.Manifest
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Log
@@ -25,6 +27,7 @@ import com.aiosman.riderpro.data.AccountService
import com.aiosman.riderpro.data.AccountServiceImpl
import com.aiosman.riderpro.ui.Navigation
import com.aiosman.riderpro.ui.NavigationRoute
import com.aiosman.riderpro.ui.post.NewPostViewModel
import com.aiosman.riderpro.ui.post.PostViewModel
import com.google.android.libraries.places.api.Places
import com.google.firebase.analytics.FirebaseAnalytics
@@ -108,6 +111,17 @@ class MainActivity : ComponentActivity() {
)
)
}
// 处理分享过来的图片
if (intent?.action == Intent.ACTION_SEND || intent?.action == Intent.ACTION_SEND_MULTIPLE) {
val imageUris: List<Uri>? = if (intent.action == Intent.ACTION_SEND) {
listOf(intent.getParcelableExtra(Intent.EXTRA_STREAM)!!)
} else {
intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)
}
NewPostViewModel.asNewPostWithImageUris(imageUris!!.map { it.toString() })
navController.navigate(NavigationRoute.NewPost.route)
}
}
}

View File

@@ -9,6 +9,7 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.aiosman.riderpro.AppState
import com.aiosman.riderpro.data.MomentService
import com.aiosman.riderpro.entity.MomentEntity
import com.aiosman.riderpro.entity.MomentPagingSource
@@ -34,14 +35,13 @@ object FavouriteListViewModel:ViewModel() {
if (force) {
isLoading = true
}
val profile = accountService.getMyAccountProfile()
isLoading = false
Pager(
config = PagingConfig(pageSize = 5, enablePlaceholders = false),
pagingSourceFactory = {
MomentPagingSource(
MomentRemoteDataSource(momentService),
favoriteUserId = profile.id
favoriteUserId = AppState.UserId
)
}
).flow.cachedIn(viewModelScope).collectLatest {

View File

@@ -11,6 +11,7 @@ import androidx.paging.PagingData
import androidx.paging.cachedIn
import androidx.paging.filter
import androidx.paging.map
import com.aiosman.riderpro.AppState
import com.aiosman.riderpro.data.AccountService
import com.aiosman.riderpro.entity.MomentPagingSource
import com.aiosman.riderpro.entity.MomentRemoteDataSource
@@ -40,9 +41,8 @@ object MomentViewModel : ViewModel() {
if (pullRefresh) {
refreshing = true
}
val profile = accountService.getMyAccountProfile()
// 检查是否有动态
val existMoments = momentService.getMoments(timelineId = profile.id, pageNumber = 1)
val existMoments = momentService.getMoments(timelineId = AppState.UserId, pageNumber = 1)
if (existMoments.list.isEmpty()) {
existsMoment.value = true
}
@@ -55,7 +55,7 @@ object MomentViewModel : ViewModel() {
MomentPagingSource(
MomentRemoteDataSource(momentService),
// 如果没有动态,则显示热门动态
timelineId = if (existMoments.list.isEmpty()) null else profile.id,
timelineId = if (existMoments.list.isEmpty()) null else AppState.UserId,
trend = if (existMoments.list.isEmpty()) true else null
)
}

View File

@@ -47,8 +47,8 @@ object MyProfileViewModel : ViewModel() {
refreshing = true
}
firstLoad = false
profile = accountService.getMyAccountProfile()
val profile = accountService.getMyAccountProfile()
this@MyProfileViewModel.profile = profile
refreshing = false
try {
Pager(
@@ -71,13 +71,11 @@ object MyProfileViewModel : ViewModel() {
}
suspend fun logout() {
accountService.getMyAccountProfile()
AppStore.apply {
token = null
rememberMe = false
saveData()
}
}
fun updateUserProfileBanner(bannerImageUrl: Uri?, context: Context) {

View File

@@ -39,7 +39,6 @@ object DiscoverViewModel:ViewModel() {
}
fun refreshPager() {
viewModelScope.launch {
val profile = accountService.getMyAccountProfile()
Pager(
config = PagingConfig(pageSize = 5, enablePlaceholders = false),
pagingSourceFactory = {

View File

@@ -37,6 +37,13 @@ object NewPostViewModel : ViewModel() {
imageUriList = listOf()
relPostId = null
}
fun asNewPostWithImageUris(imageUris: List<String>) {
textContent = ""
searchPlaceAddressResult = null
modificationList = listOf()
imageUriList = imageUris
relPostId = null
}
suspend fun uriToFile(context: Context, uri: Uri): File {
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)