From beb6fba365478f6cdecdb2ac350e0507109d2d73 Mon Sep 17 00:00:00 2001 From: ZJouba Date: Wed, 12 Jul 2023 11:58:31 +0200 Subject: [PATCH 01/17] Mark as read on open and scroll option --- app/src/main/java/com/jerboa/MainActivity.kt | 65 +++-- app/src/main/java/com/jerboa/api/Http.kt | 20 +- app/src/main/java/com/jerboa/db/AppDB.kt | 22 +- app/src/main/java/com/jerboa/db/Migrations.kt | 14 +- .../com/jerboa/model/CommunityViewModel.kt | 60 +++-- .../java/com/jerboa/model/HomeViewModel.kt | 61 +++-- .../jerboa/model/PersonProfileViewModel.kt | 45 ++-- .../java/com/jerboa/model/PostViewModel.kt | 50 ++-- .../components/community/CommunityActivity.kt | 89 +++---- .../ui/components/home/BottomNavActivity.kt | 95 ++++--- .../jerboa/ui/components/home/HomeActivity.kt | 76 +++--- .../person/PersonProfileActivity.kt | 87 ++++--- .../jerboa/ui/components/post/PostActivity.kt | 134 ++++------ .../jerboa/ui/components/post/PostListing.kt | 244 +++++++++++------- .../jerboa/ui/components/post/PostListings.kt | 11 +- .../settings/account/AccountSettings.kt | 5 +- .../lookandfeel/LookAndFeelActivity.kt | 51 ++-- app/src/main/res/values/strings.xml | 1 + 18 files changed, 622 insertions(+), 508 deletions(-) diff --git a/app/src/main/java/com/jerboa/MainActivity.kt b/app/src/main/java/com/jerboa/MainActivity.kt index 18a9ea1f8..21a102b45 100644 --- a/app/src/main/java/com/jerboa/MainActivity.kt +++ b/app/src/main/java/com/jerboa/MainActivity.kt @@ -11,18 +11,11 @@ import android.widget.Toast import androidx.activity.compose.setContent import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity -import androidx.compose.animation.EnterTransition -import androidx.compose.animation.ExitTransition -import androidx.compose.animation.slideInHorizontally -import androidx.compose.animation.slideOutHorizontally +import androidx.compose.animation.* import androidx.compose.material3.DrawerValue import androidx.compose.material3.rememberDrawerState -import androidx.compose.runtime.DisposableEffect -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue +import androidx.compose.runtime.* import androidx.compose.runtime.livedata.observeAsState -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.compose.NavHost @@ -35,32 +28,11 @@ import arrow.core.Either import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.MINIMUM_API_VERSION -import com.jerboa.db.APP_SETTINGS_DEFAULT -import com.jerboa.db.AccountRepository -import com.jerboa.db.AccountViewModel -import com.jerboa.db.AccountViewModelFactory -import com.jerboa.db.AppDB -import com.jerboa.db.AppSettingsRepository -import com.jerboa.db.AppSettingsViewModel -import com.jerboa.db.AppSettingsViewModelFactory -import com.jerboa.model.AccountSettingsViewModel -import com.jerboa.model.AccountSettingsViewModelFactory -import com.jerboa.model.CommunityViewModel -import com.jerboa.model.ReplyItem -import com.jerboa.model.SiteViewModel +import com.jerboa.db.* +import com.jerboa.model.* import com.jerboa.ui.components.comment.edit.CommentEditActivity import com.jerboa.ui.components.comment.reply.CommentReplyActivity -import com.jerboa.ui.components.common.CommentEditDeps -import com.jerboa.ui.components.common.MarkdownHelper -import com.jerboa.ui.components.common.PostEditDeps -import com.jerboa.ui.components.common.PrivateMessageDeps -import com.jerboa.ui.components.common.Route -import com.jerboa.ui.components.common.ShowChangelog -import com.jerboa.ui.components.common.ShowOutdatedServerDialog -import com.jerboa.ui.components.common.SwipeToNavigateBack -import com.jerboa.ui.components.common.getCurrentAccountSync -import com.jerboa.ui.components.common.takeDepsFromRoot -import com.jerboa.ui.components.common.toView +import com.jerboa.ui.components.common.* import com.jerboa.ui.components.community.CommunityActivity import com.jerboa.ui.components.community.list.CommunityListActivity import com.jerboa.ui.components.community.sidebar.CommunitySidebarActivity @@ -146,9 +118,13 @@ class MainActivity : AppCompatActivity() { BackConfirmationMode.Toast -> { this@MainActivity.addConfirmationToast(navController, ctx) } + BackConfirmationMode.Dialog -> { - this@MainActivity.addConfirmationDialog(navController) { showConfirmationDialog.value = true } + this@MainActivity.addConfirmationDialog(navController) { + showConfirmationDialog.value = true + } } + BackConfirmationMode.None -> {} } @@ -170,13 +146,22 @@ class MainActivity : AppCompatActivity() { when (val siteRes = siteViewModel.siteRes) { is ApiState.Success -> { val siteVersion = siteRes.data.version - if (compareVersions(siteVersion, MINIMUM_API_VERSION) < 0 && !serverVersionOutdatedViewed.value) { + if (compareVersions( + siteVersion, +<<<<<<< Updated upstream + MINIMUM_API_VERSION +======= + MINIMUM_API_VERSION, +>>>>>>> Stashed changes + ) < 0 && !serverVersionOutdatedViewed.value + ) { ShowOutdatedServerDialog( siteVersion = siteVersion, onConfirm = { serverVersionOutdatedViewed.value = true }, ) } } + else -> {} } @@ -264,6 +249,7 @@ class MainActivity : AppCompatActivity() { useCustomTabs = appSettings.useCustomTabs, usePrivateTabs = appSettings.usePrivateTabs, blurNSFW = appSettings.blurNSFW, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } @@ -296,6 +282,7 @@ class MainActivity : AppCompatActivity() { useCustomTabs = appSettings.useCustomTabs, usePrivateTabs = appSettings.usePrivateTabs, blurNSFW = appSettings.blurNSFW, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } @@ -364,6 +351,7 @@ class MainActivity : AppCompatActivity() { blurNSFW = appSettings.blurNSFW, drawerState = drawerState, openImageViewer = navController::toView, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } @@ -397,6 +385,7 @@ class MainActivity : AppCompatActivity() { blurNSFW = appSettings.blurNSFW, drawerState = drawerState, openImageViewer = navController::toView, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } @@ -500,6 +489,7 @@ class MainActivity : AppCompatActivity() { usePrivateTabs = appSettings.usePrivateTabs, blurNSFW = appSettings.blurNSFW, openImageViewer = { url -> navController.toView(url) }, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } } @@ -507,7 +497,9 @@ class MainActivity : AppCompatActivity() { composable( route = Route.COMMENT, deepLinks = DEFAULT_LEMMY_INSTANCES.map { instance -> - navDeepLink { uriPattern = "$instance/comment/{${Route.CommentArgs.ID}}" } + navDeepLink { + uriPattern = "$instance/comment/{${Route.CommentArgs.ID}}" + } }, arguments = listOf( navArgument(Route.CommentArgs.ID) { @@ -530,6 +522,7 @@ class MainActivity : AppCompatActivity() { siteViewModel = siteViewModel, blurNSFW = appSettings.blurNSFW, openImageViewer = navController::toView, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } diff --git a/app/src/main/java/com/jerboa/api/Http.kt b/app/src/main/java/com/jerboa/api/Http.kt index 18ac7ea7d..180a8d935 100644 --- a/app/src/main/java/com/jerboa/api/Http.kt +++ b/app/src/main/java/com/jerboa/api/Http.kt @@ -20,7 +20,7 @@ import java.io.InputStream import okhttp3.Response as HttpResponse const val VERSION = "v3" -const val DEFAULT_INSTANCE = "lemmy.ml" +const val DEFAULT_INSTANCE = "voyager.lemmy.ml" const val MINIMUM_API_VERSION: String = "0.18" val REDACTED_QUERY_PARAMS = setOf("auth") val REDACTED_BODY_FIELDS = setOf("jwt", "password") @@ -53,6 +53,12 @@ interface API { @POST("post/like") suspend fun likePost(@Body form: CreatePostLike): Response + /** + * Mark post as read. + */ + @POST("post/mark_as_read") + suspend fun markAsRead(@Body form: MarkPostAsRead): Response + /** * Like / vote on a comment. */ @@ -290,7 +296,17 @@ interface API { .build() } } - .addInterceptor(CustomHttpLoggingInterceptor(REDACTED_QUERY_PARAMS, REDACTED_BODY_FIELDS)) + .addInterceptor( + CustomHttpLoggingInterceptor( + REDACTED_QUERY_PARAMS, +<<<<<<< Updated upstream + REDACTED_BODY_FIELDS + ) +======= + REDACTED_BODY_FIELDS, + ), +>>>>>>> Stashed changes + ) .build() return Retrofit.Builder() diff --git a/app/src/main/java/com/jerboa/db/AppDB.kt b/app/src/main/java/com/jerboa/db/AppDB.kt index b7cd7980f..059a5772e 100644 --- a/app/src/main/java/com/jerboa/db/AppDB.kt +++ b/app/src/main/java/com/jerboa/db/AppDB.kt @@ -5,18 +5,12 @@ import android.content.Context import android.database.sqlite.SQLiteDatabase.CONFLICT_IGNORE import android.util.Log import androidx.annotation.WorkerThread -import androidx.lifecycle.LiveData -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.viewModelScope +import androidx.lifecycle.* import androidx.room.* import androidx.sqlite.db.SupportSQLiteDatabase -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.* import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient import okhttp3.Request @@ -131,6 +125,11 @@ data class AppSettings( defaultValue = "1", ) val backConfirmationMode: Int, + @ColumnInfo( + name = "markAsReadOnScroll", + defaultValue = "0", + ) + val markAsReadOnScroll: Boolean, ) val APP_SETTINGS_DEFAULT = AppSettings( @@ -152,6 +151,11 @@ val APP_SETTINGS_DEFAULT = AppSettings( blurNSFW = true, showTextDescriptionsInNavbar = true, backConfirmationMode = 1, +<<<<<<< Updated upstream + markAsReadOnScroll = false +======= + markAsReadOnScroll = false, +>>>>>>> Stashed changes ) @Dao @@ -283,7 +287,7 @@ class AppSettingsRepository( } @Database( - version = 19, + version = 20, entities = [Account::class, AppSettings::class], exportSchema = true, ) diff --git a/app/src/main/java/com/jerboa/db/Migrations.kt b/app/src/main/java/com/jerboa/db/Migrations.kt index b8bae7ec3..26afbee11 100644 --- a/app/src/main/java/com/jerboa/db/Migrations.kt +++ b/app/src/main/java/com/jerboa/db/Migrations.kt @@ -9,11 +9,11 @@ val MIGRATION_1_2 = object : Migration(1, 2) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL( "alter table account add column default_listing_type INTEGER NOT " + - "NULL default 0", + "NULL default 0", ) database.execSQL( "alter table account add column default_sort_type INTEGER NOT " + - "NULL default 0", + "NULL default 0", ) } } @@ -220,6 +220,15 @@ val MIGRATION_18_19 = object : Migration(18, 19) { } } +val MIGRATION_19_20 = object : Migration(19, 20) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED) + database.execSQL( + "ALTER TABLE AppSettings ADD COLUMN markAsReadOnScroll INTEGER NOT NULL DEFAULT 0", + ) + } +} + // Don't forget to test your migration with `./gradlew app:connectAndroidTest` val MIGRATIONS_LIST = arrayOf( MIGRATION_1_2, @@ -240,4 +249,5 @@ val MIGRATIONS_LIST = arrayOf( MIGRATION_16_17, MIGRATION_17_18, MIGRATION_18_19, + MIGRATION_19_20, ) diff --git a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt index ede0e9a7d..f9b723258 100644 --- a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt +++ b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt @@ -6,31 +6,11 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.jerboa.* import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockCommunityResponse -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.BlockPersonResponse -import com.jerboa.datatypes.types.CommunityId -import com.jerboa.datatypes.types.CommunityResponse -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.FollowCommunity -import com.jerboa.datatypes.types.GetCommunity -import com.jerboa.datatypes.types.GetCommunityResponse -import com.jerboa.datatypes.types.GetPosts -import com.jerboa.datatypes.types.GetPostsResponse -import com.jerboa.datatypes.types.PostResponse -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SavePost -import com.jerboa.datatypes.types.SortType -import com.jerboa.findAndUpdatePost -import com.jerboa.mergePosts -import com.jerboa.serializeToMap -import com.jerboa.showBlockCommunityToast -import com.jerboa.showBlockPersonToast +import com.jerboa.datatypes.types.* import com.jerboa.ui.components.common.Initializable import kotlinx.coroutines.launch @@ -41,7 +21,7 @@ class CommunityViewModel : ViewModel(), Initializable { private set private var followCommunityRes: ApiState by - mutableStateOf(ApiState.Empty) + mutableStateOf(ApiState.Empty) var postsRes: ApiState by mutableStateOf(ApiState.Empty) private set @@ -50,8 +30,9 @@ class CommunityViewModel : ViewModel(), Initializable { private var savePostRes: ApiState by mutableStateOf(ApiState.Empty) private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) private var blockCommunityRes: ApiState by - mutableStateOf(ApiState.Empty) + mutableStateOf(ApiState.Empty) private var blockPersonRes: ApiState by mutableStateOf(ApiState.Empty) + private var markPostRes: ApiState by mutableStateOf(ApiState.Empty) var sortType by mutableStateOf(SortType.Active) private set @@ -117,8 +98,22 @@ class CommunityViewModel : ViewModel(), Initializable { if (newRes.data.posts.isEmpty()) { // Hit the end of the posts prevPage() } - ApiState.Success(GetPostsResponse(mergePosts(oldRes.data.posts, newRes.data.posts))) + ApiState.Success( + GetPostsResponse( + mergePosts( + oldRes.data.posts, +<<<<<<< Updated upstream + newRes.data.posts + ) + ) +======= + newRes.data.posts, + ), + ), +>>>>>>> Stashed changes + ) } + else -> { prevPage() oldRes @@ -246,4 +241,19 @@ class CommunityViewModel : ViewModel(), Initializable { else -> {} } } + + fun markPostAsRead(form: MarkPostAsRead) { + viewModelScope.launch { + markPostRes = ApiState.Loading + markPostRes = apiWrapper(API.getInstance().markAsRead(form)) + + when (val markRes = markPostRes) { + is ApiState.Success -> { + updatePost(markRes.data.post_view) + } + + else -> {} + } + } + } } diff --git a/app/src/main/java/com/jerboa/model/HomeViewModel.kt b/app/src/main/java/com/jerboa/model/HomeViewModel.kt index 15eedc384..1f89308fa 100644 --- a/app/src/main/java/com/jerboa/model/HomeViewModel.kt +++ b/app/src/main/java/com/jerboa/model/HomeViewModel.kt @@ -6,28 +6,12 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.jerboa.* import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockCommunityResponse -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.BlockPersonResponse -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.GetPosts -import com.jerboa.datatypes.types.GetPostsResponse -import com.jerboa.datatypes.types.ListingType -import com.jerboa.datatypes.types.PostResponse -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SavePost -import com.jerboa.datatypes.types.SortType +import com.jerboa.datatypes.types.* import com.jerboa.db.Account -import com.jerboa.findAndUpdatePost -import com.jerboa.mergePosts -import com.jerboa.serializeToMap -import com.jerboa.showBlockCommunityToast -import com.jerboa.showBlockPersonToast import com.jerboa.ui.components.common.Initializable import kotlinx.coroutines.launch @@ -42,6 +26,7 @@ class HomeViewModel : ViewModel(), Initializable { private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) private var blockCommunityRes: ApiState by mutableStateOf(ApiState.Empty) private var blockPersonRes: ApiState by mutableStateOf(ApiState.Empty) + private var markPostRes: ApiState by mutableStateOf(ApiState.Empty) var sortType by mutableStateOf(SortType.Active) private set @@ -96,8 +81,22 @@ class HomeViewModel : ViewModel(), Initializable { if (newRes.data.posts.isEmpty()) { // Hit the end of the posts prevPage() } - ApiState.Success(GetPostsResponse(mergePosts(oldRes.data.posts, newRes.data.posts))) + ApiState.Success( + GetPostsResponse( + mergePosts( + oldRes.data.posts, +<<<<<<< Updated upstream + newRes.data.posts + ) + ) +======= + newRes.data.posts, + ), + ), +>>>>>>> Stashed changes + ) } + else -> { prevPage() oldRes @@ -168,7 +167,13 @@ class HomeViewModel : ViewModel(), Initializable { fun updateFromAccount(account: Account) { updateSortType(SortType.values().getOrElse(account.defaultSortType) { sortType }) - updateListingType(ListingType.values().getOrElse(account.defaultListingType) { listingType }) + updateListingType( +<<<<<<< Updated upstream + ListingType.values().getOrElse(account.defaultListingType) { listingType }) +======= + ListingType.values().getOrElse(account.defaultListingType) { listingType }, + ) +>>>>>>> Stashed changes } fun updatePost(postView: PostView) { @@ -178,6 +183,7 @@ class HomeViewModel : ViewModel(), Initializable { val newRes = ApiState.Success(existing.data.copy(posts = newPosts)) postsRes = newRes } + else -> {} } } @@ -215,4 +221,19 @@ class HomeViewModel : ViewModel(), Initializable { auth = jwt, ) } + + fun markPostAsRead(form: MarkPostAsRead) { + viewModelScope.launch { + markPostRes = ApiState.Loading + markPostRes = apiWrapper(API.getInstance().markAsRead(form)) + + when (val markRes = markPostRes) { + is ApiState.Success -> { + updatePost(markRes.data.post_view) + } + + else -> {} + } + } + } } diff --git a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt index 859d023c3..a301bc5af 100644 --- a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt @@ -6,32 +6,11 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.jerboa.* import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockCommunityResponse -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.BlockPersonResponse -import com.jerboa.datatypes.types.CommentResponse -import com.jerboa.datatypes.types.CommentView -import com.jerboa.datatypes.types.CreateCommentLike -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeleteComment -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.GetPersonDetails -import com.jerboa.datatypes.types.GetPersonDetailsResponse -import com.jerboa.datatypes.types.PersonId -import com.jerboa.datatypes.types.PostResponse -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SaveComment -import com.jerboa.datatypes.types.SavePost -import com.jerboa.datatypes.types.SortType -import com.jerboa.findAndUpdateComment -import com.jerboa.findAndUpdatePost -import com.jerboa.serializeToMap -import com.jerboa.showBlockCommunityToast -import com.jerboa.showBlockPersonToast +import com.jerboa.datatypes.types.* import com.jerboa.ui.components.common.Initializable import kotlinx.coroutines.launch @@ -47,13 +26,15 @@ class PersonProfileViewModel : ViewModel(), Initializable { private var savePostRes: ApiState by mutableStateOf(ApiState.Empty) private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) private var blockCommunityRes: ApiState by - mutableStateOf(ApiState.Empty) + mutableStateOf(ApiState.Empty) private var blockPersonRes: ApiState by mutableStateOf(ApiState.Empty) private var likeCommentRes: ApiState by mutableStateOf(ApiState.Empty) private var saveCommentRes: ApiState by mutableStateOf(ApiState.Empty) private var deleteCommentRes: ApiState by mutableStateOf(ApiState.Empty) + private var markPostRes: ApiState by mutableStateOf(ApiState.Empty) + var sortType by mutableStateOf(SortType.New) private set var page by mutableStateOf(1) @@ -130,6 +111,7 @@ class PersonProfileViewModel : ViewModel(), Initializable { ), ) } + else -> { prevPage() oldRes @@ -286,4 +268,19 @@ class PersonProfileViewModel : ViewModel(), Initializable { else -> {} } } + + fun markPostAsRead(form: MarkPostAsRead) { + viewModelScope.launch { + markPostRes = ApiState.Loading + markPostRes = apiWrapper(API.getInstance().markAsRead(form)) + + when (val markRes = markPostRes) { + is ApiState.Success -> { + updatePost(markRes.data.post_view) + } + + else -> {} + } + } + } } diff --git a/app/src/main/java/com/jerboa/model/PostViewModel.kt b/app/src/main/java/com/jerboa/model/PostViewModel.kt index a2367992c..42a9e1339 100644 --- a/app/src/main/java/com/jerboa/model/PostViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PostViewModel.kt @@ -7,37 +7,12 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import arrow.core.Either +import com.jerboa.* import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper -import com.jerboa.appendData -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockCommunityResponse -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.BlockPersonResponse -import com.jerboa.datatypes.types.CommentId -import com.jerboa.datatypes.types.CommentResponse -import com.jerboa.datatypes.types.CommentSortType -import com.jerboa.datatypes.types.CommentView -import com.jerboa.datatypes.types.CreateCommentLike -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeleteComment -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.GetComments -import com.jerboa.datatypes.types.GetCommentsResponse -import com.jerboa.datatypes.types.GetPost -import com.jerboa.datatypes.types.GetPostResponse -import com.jerboa.datatypes.types.ListingType -import com.jerboa.datatypes.types.PostId -import com.jerboa.datatypes.types.PostResponse -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SaveComment -import com.jerboa.datatypes.types.SavePost +import com.jerboa.datatypes.types.* import com.jerboa.db.Account -import com.jerboa.findAndUpdateComment -import com.jerboa.serializeToMap -import com.jerboa.showBlockCommunityToast -import com.jerboa.showBlockPersonToast import com.jerboa.ui.components.common.Initializable import kotlinx.coroutines.launch @@ -67,6 +42,7 @@ class PostViewModel : ViewModel(), Initializable { private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) private var blockCommunityRes: ApiState by mutableStateOf(ApiState.Empty) private var blockPersonRes: ApiState by mutableStateOf(ApiState.Empty) + private var markPostRes: ApiState by mutableStateOf(ApiState.Empty) fun initialize( id: Either, @@ -155,6 +131,7 @@ class PostViewModel : ViewModel(), Initializable { commentsRes = ApiState.Success(existing.data.copy(comments = appended)) } + else -> {} } } @@ -307,4 +284,23 @@ class PostViewModel : ViewModel(), Initializable { else -> {} } } + +<<<<<<< Updated upstream + +======= +>>>>>>> Stashed changes + fun markPostAsRead(form: MarkPostAsRead) { + viewModelScope.launch { + markPostRes = ApiState.Loading + markPostRes = apiWrapper(API.getInstance().markAsRead(form)) + + when (val markRes = markPostRes) { + is ApiState.Success -> { + updatePost(markRes.data.post_view) + } + + else -> {} + } + } + } } diff --git a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt index b30aee8c1..295b3749c 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt @@ -10,15 +10,7 @@ import androidx.compose.material.icons.outlined.Add import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.FabPosition -import androidx.compose.material3.FloatingActionButton -import androidx.compose.material3.Icon -import androidx.compose.material3.Scaffold -import androidx.compose.material3.SnackbarHost -import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.rememberTopAppBarState +import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -31,48 +23,15 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import androidx.navigation.NavController import arrow.core.Either +import com.jerboa.* import com.jerboa.R -import com.jerboa.VoteType import com.jerboa.api.ApiState -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.CommunityId -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.FollowCommunity -import com.jerboa.datatypes.types.GetCommunity -import com.jerboa.datatypes.types.GetPosts -import com.jerboa.datatypes.types.GetSite -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SavePost -import com.jerboa.datatypes.types.SortType -import com.jerboa.datatypes.types.SubscribedType +import com.jerboa.datatypes.types.* import com.jerboa.db.AccountViewModel import com.jerboa.db.AppSettingsViewModel -import com.jerboa.isLoading -import com.jerboa.isRefreshing import com.jerboa.model.CommunityViewModel import com.jerboa.model.SiteViewModel -import com.jerboa.newVote -import com.jerboa.scrollToTop -import com.jerboa.shareLink -import com.jerboa.ui.components.common.ApiEmptyText -import com.jerboa.ui.components.common.ApiErrorText -import com.jerboa.ui.components.common.ConsumeReturn -import com.jerboa.ui.components.common.CreatePostDeps -import com.jerboa.ui.components.common.InitializeRoute -import com.jerboa.ui.components.common.LoadingBar -import com.jerboa.ui.components.common.PostEditDeps -import com.jerboa.ui.components.common.getCurrentAccount -import com.jerboa.ui.components.common.getPostViewMode -import com.jerboa.ui.components.common.rootChannel -import com.jerboa.ui.components.common.toCommunity -import com.jerboa.ui.components.common.toCreatePost -import com.jerboa.ui.components.common.toPost -import com.jerboa.ui.components.common.toPostEdit -import com.jerboa.ui.components.common.toPostReport -import com.jerboa.ui.components.common.toProfile -import com.jerboa.ui.components.common.toView +import com.jerboa.ui.components.common.* import com.jerboa.ui.components.post.PostListings import com.jerboa.ui.components.post.edit.PostEditReturn import kotlinx.collections.immutable.toImmutableList @@ -90,6 +49,7 @@ fun CommunityActivity( useCustomTabs: Boolean, usePrivateTabs: Boolean, blurNSFW: Boolean, + markAsReadOnScroll: Boolean, ) { Log.d("jerboa", "got to community activity") val transferCreatePostDepsViaRoot = navController.rootChannel() @@ -112,7 +72,13 @@ fun CommunityActivity( communityViewModel.resetPage() account?.let { - communityViewModel.updateSortType(SortType.values().getOrElse(account.defaultSortType) { siteViewModel.sortType }) + communityViewModel.updateSortType( +<<<<<<< Updated upstream + SortType.values().getOrElse(account.defaultSortType) { siteViewModel.sortType }) +======= + SortType.values().getOrElse(account.defaultSortType) { siteViewModel.sortType }, + ) +>>>>>>> Stashed changes } communityViewModel.getCommunity( form = GetCommunity( @@ -216,6 +182,7 @@ fun CommunityActivity( navController = navController, ) } + else -> {} } } @@ -223,7 +190,17 @@ fun CommunityActivity( content = { padding -> Box(modifier = Modifier.pullRefresh(pullRefreshState)) { // zIndex needed bc some elements of a post get drawn above it. - PullRefreshIndicator(communityViewModel.postsRes.isRefreshing(), pullRefreshState, Modifier.align(Alignment.TopCenter).zIndex(100F)) + PullRefreshIndicator( + communityViewModel.postsRes.isRefreshing(), + pullRefreshState, + Modifier + .align(Alignment.TopCenter) +<<<<<<< Updated upstream + .zIndex(100F) +======= + .zIndex(100F), +>>>>>>> Stashed changes + ) // Can't be in ApiState.Loading, because of infinite scrolling if (communityViewModel.postsRes.isLoading()) { LoadingBar(padding = padding) @@ -389,8 +366,26 @@ fun CommunityActivity( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = navController::toView, + markAsReadOnScroll = markAsReadOnScroll, + onMarkAsRead = { postView -> + account?.also { acct -> + communityViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, +<<<<<<< Updated upstream + auth = acct.jwt + ) +======= + auth = acct.jwt, + ), +>>>>>>> Stashed changes + ) + } + }, ) } + else -> {} } } diff --git a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt index 9c701d244..8ecc64bd7 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt @@ -1,30 +1,12 @@ package com.jerboa.ui.components.home -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.WindowInsets -import androidx.compose.foundation.layout.isImeVisible -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Bookmarks -import androidx.compose.material.icons.filled.Email -import androidx.compose.material.icons.filled.Home -import androidx.compose.material.icons.filled.Person -import androidx.compose.material.icons.filled.Search -import androidx.compose.material.icons.outlined.Bookmarks -import androidx.compose.material.icons.outlined.Email -import androidx.compose.material.icons.outlined.Home -import androidx.compose.material.icons.outlined.Person -import androidx.compose.material.icons.outlined.Search -import androidx.compose.material3.DrawerState -import androidx.compose.material3.ModalDrawerSheet -import androidx.compose.material3.ModalNavigationDrawer -import androidx.compose.material3.Scaffold -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.material.icons.filled.* +import androidx.compose.material.icons.outlined.* +import androidx.compose.material3.* +import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector @@ -47,10 +29,7 @@ import com.jerboa.fetchHomePosts import com.jerboa.loginFirstToast import com.jerboa.model.HomeViewModel import com.jerboa.model.SiteViewModel -import com.jerboa.ui.components.common.BottomAppBarAll -import com.jerboa.ui.components.common.InitializeRoute -import com.jerboa.ui.components.common.getCurrentAccount -import com.jerboa.ui.components.common.toView +import com.jerboa.ui.components.common.* import com.jerboa.ui.components.community.list.CommunityListActivity import com.jerboa.ui.components.drawer.MainDrawer import com.jerboa.ui.components.inbox.InboxActivity @@ -62,11 +41,56 @@ enum class NavTab( val iconFilled: ImageVector, val contentDescriptionId: Int, ) { - Home(R.string.bottomBar_label_home, Icons.Outlined.Home, Icons.Filled.Home, R.string.bottomBar_home), - Search(R.string.bottomBar_label_search, Icons.Outlined.Search, Icons.Filled.Search, R.string.bottomBar_search), - Inbox(R.string.bottomBar_label_inbox, Icons.Outlined.Email, Icons.Filled.Email, R.string.bottomBar_inbox), - Saved(R.string.bottomBar_label_bookmarks, Icons.Outlined.Bookmarks, Icons.Filled.Bookmarks, R.string.bottomBar_bookmarks), - Profile(R.string.bottomBar_label_profile, Icons.Outlined.Person, Icons.Filled.Person, R.string.bottomBar_profile), + Home( + R.string.bottomBar_label_home, + Icons.Outlined.Home, + Icons.Filled.Home, +<<<<<<< Updated upstream + R.string.bottomBar_home +======= + R.string.bottomBar_home, +>>>>>>> Stashed changes + ), + Search( + R.string.bottomBar_label_search, + Icons.Outlined.Search, + Icons.Filled.Search, +<<<<<<< Updated upstream + R.string.bottomBar_search +======= + R.string.bottomBar_search, +>>>>>>> Stashed changes + ), + Inbox( + R.string.bottomBar_label_inbox, + Icons.Outlined.Email, + Icons.Filled.Email, +<<<<<<< Updated upstream + R.string.bottomBar_inbox +======= + R.string.bottomBar_inbox, +>>>>>>> Stashed changes + ), + Saved( + R.string.bottomBar_label_bookmarks, + Icons.Outlined.Bookmarks, + Icons.Filled.Bookmarks, +<<<<<<< Updated upstream + R.string.bottomBar_bookmarks +======= + R.string.bottomBar_bookmarks, +>>>>>>> Stashed changes + ), + Profile( + R.string.bottomBar_label_profile, + Icons.Outlined.Person, + Icons.Filled.Person, +<<<<<<< Updated upstream + R.string.bottomBar_profile +======= + R.string.bottomBar_profile, +>>>>>>> Stashed changes + ), ; fun needsLogin() = this == Inbox || this == Saved || this == Profile @@ -170,6 +194,11 @@ fun BottomNavActivity( usePrivateTabs = appSettings.usePrivateTabs, drawerState = drawerState, blurNSFW = appSettings.blurNSFW, +<<<<<<< Updated upstream + markAsReadOnScroll = appSettings.markAsReadOnScroll +======= + markAsReadOnScroll = appSettings.markAsReadOnScroll, +>>>>>>> Stashed changes ) } @@ -208,6 +237,7 @@ fun BottomNavActivity( blurNSFW = appSettings.blurNSFW, drawerState = drawerState, openImageViewer = navController::toView, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } @@ -225,6 +255,7 @@ fun BottomNavActivity( blurNSFW = appSettings.blurNSFW, openImageViewer = navController::toView, drawerState = drawerState, + markAsReadOnScroll = appSettings.markAsReadOnScroll, ) } } diff --git a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt index 329d1eac8..75fb8e383 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt @@ -14,69 +14,28 @@ import androidx.compose.material.icons.outlined.Add import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState -import androidx.compose.material3.DrawerState -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.FabPosition -import androidx.compose.material3.FloatingActionButton -import androidx.compose.material3.Icon -import androidx.compose.material3.Scaffold -import androidx.compose.material3.SnackbarHost -import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.TopAppBarScrollBehavior -import androidx.compose.material3.rememberTopAppBarState +import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.ui.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.Modifier +import androidx.compose.ui.* import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex import androidx.navigation.NavController +import com.jerboa.* import com.jerboa.R -import com.jerboa.VoteType import com.jerboa.api.ApiState -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SavePost -import com.jerboa.datatypes.types.Tagline +import com.jerboa.datatypes.types.* import com.jerboa.db.Account import com.jerboa.db.AccountViewModel import com.jerboa.db.AppSettingsViewModel -import com.jerboa.isLoading -import com.jerboa.isRefreshing -import com.jerboa.loginFirstToast import com.jerboa.model.HomeViewModel import com.jerboa.model.SiteViewModel -import com.jerboa.newVote -import com.jerboa.scrollToTop -import com.jerboa.shareLink -import com.jerboa.ui.components.common.ApiEmptyText -import com.jerboa.ui.components.common.ApiErrorText -import com.jerboa.ui.components.common.ApiErrorToast -import com.jerboa.ui.components.common.ConsumeReturn -import com.jerboa.ui.components.common.CreatePostDeps -import com.jerboa.ui.components.common.LoadingBar -import com.jerboa.ui.components.common.PostEditDeps -import com.jerboa.ui.components.common.getCurrentAccount -import com.jerboa.ui.components.common.getPostViewMode -import com.jerboa.ui.components.common.rootChannel -import com.jerboa.ui.components.common.toCommunity -import com.jerboa.ui.components.common.toCreatePost -import com.jerboa.ui.components.common.toPost -import com.jerboa.ui.components.common.toPostEdit -import com.jerboa.ui.components.common.toPostReport -import com.jerboa.ui.components.common.toProfile -import com.jerboa.ui.components.common.toView +import com.jerboa.ui.components.common.* import com.jerboa.ui.components.post.PostListings import com.jerboa.ui.components.post.edit.PostEditReturn import kotlinx.collections.immutable.persistentListOf @@ -96,6 +55,7 @@ fun HomeActivity( usePrivateTabs: Boolean, drawerState: DrawerState, blurNSFW: Boolean, + markAsReadOnScroll: Boolean, ) { Log.d("jerboa", "got to home activity") val transferCreatePostDepsViaRoot = navController.rootChannel() @@ -147,6 +107,7 @@ fun HomeActivity( useCustomTabs = useCustomTabs, usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, + markAsReadOnScroll = markAsReadOnScroll, ) }, floatingActionButtonPosition = FabPosition.End, @@ -187,6 +148,7 @@ fun MainPostListingsContent( useCustomTabs: Boolean, usePrivateTabs: Boolean, blurNSFW: Boolean, + markAsReadOnScroll: Boolean, ) { val transferPostEditDepsViaRoot = navController.rootChannel() @@ -198,6 +160,7 @@ fun MainPostListingsContent( is ApiState.Success -> { taglines = siteRes.data.taglines } + else -> {} } @@ -231,6 +194,7 @@ fun MainPostListingsContent( ApiErrorToast(postsRes.msg) persistentListOf() } + is ApiState.Holder -> postsRes.data.posts.toImmutableList() else -> persistentListOf() } @@ -347,6 +311,26 @@ fun MainPostListingsContent( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = navController::toView, + markAsReadOnScroll = markAsReadOnScroll, + onMarkAsRead = { postView -> + account?.also { acct -> + homeViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, +<<<<<<< Updated upstream + auth = acct.jwt + ) + ) + } + } +======= + auth = acct.jwt, + ), + ) + } + }, +>>>>>>> Stashed changes ) } } diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index a3586b44c..5e7d75293 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -4,10 +4,7 @@ import android.content.Context import android.util.Log import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.items -import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.lazy.* import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.material.ExperimentalMaterialApi @@ -29,19 +26,7 @@ import com.jerboa.R import com.jerboa.VoteType import com.jerboa.api.ApiState import com.jerboa.commentsToFlatNodes -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.CommentView -import com.jerboa.datatypes.types.CreateCommentLike -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeleteComment -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.GetPersonDetails -import com.jerboa.datatypes.types.PersonId -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SaveComment -import com.jerboa.datatypes.types.SavePost -import com.jerboa.datatypes.types.SortType +import com.jerboa.datatypes.types.* import com.jerboa.db.Account import com.jerboa.db.AccountViewModel import com.jerboa.db.AppSettingsViewModel @@ -59,27 +44,7 @@ import com.jerboa.shareLink import com.jerboa.ui.components.comment.CommentNodes import com.jerboa.ui.components.comment.edit.CommentEditReturn import com.jerboa.ui.components.comment.reply.CommentReplyReturn -import com.jerboa.ui.components.common.ApiEmptyText -import com.jerboa.ui.components.common.ApiErrorText -import com.jerboa.ui.components.common.CommentEditDeps -import com.jerboa.ui.components.common.CommentReplyDeps -import com.jerboa.ui.components.common.ConsumeReturn -import com.jerboa.ui.components.common.InitializeRoute -import com.jerboa.ui.components.common.LoadingBar -import com.jerboa.ui.components.common.PostEditDeps -import com.jerboa.ui.components.common.getCurrentAccount -import com.jerboa.ui.components.common.getPostViewMode -import com.jerboa.ui.components.common.rootChannel -import com.jerboa.ui.components.common.simpleVerticalScrollbar -import com.jerboa.ui.components.common.toComment -import com.jerboa.ui.components.common.toCommentEdit -import com.jerboa.ui.components.common.toCommentReply -import com.jerboa.ui.components.common.toCommentReport -import com.jerboa.ui.components.common.toCommunity -import com.jerboa.ui.components.common.toPost -import com.jerboa.ui.components.common.toPostEdit -import com.jerboa.ui.components.common.toPostReport -import com.jerboa.ui.components.common.toProfile +import com.jerboa.ui.components.common.* import com.jerboa.ui.components.community.CommunityLink import com.jerboa.ui.components.post.PostListings import com.jerboa.ui.components.post.edit.PostEditReturn @@ -103,6 +68,7 @@ fun PersonProfileActivity( blurNSFW: Boolean, openImageViewer: (url: String) -> Unit, drawerState: DrawerState, + markAsReadOnScroll: Boolean, ) { Log.d("jerboa", "got to person activity") @@ -131,6 +97,7 @@ fun PersonProfileActivity( personProfileViewModel.insertComment(cv) } } + else -> {} } } @@ -178,6 +145,7 @@ fun PersonProfileActivity( openDrawer = ::openDrawer, ) } + is ApiState.Holder -> { val person = profileRes.data.person_view.person PersonProfileHeader( @@ -227,6 +195,7 @@ fun PersonProfileActivity( openDrawer = ::openDrawer, ) } + else -> {} } }, @@ -248,6 +217,7 @@ fun PersonProfileActivity( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = openImageViewer, + markAsReadOnScroll = markAsReadOnScroll, ) }, ) @@ -278,6 +248,7 @@ fun UserTabs( usePrivateTabs: Boolean, blurNSFW: Boolean, openImageViewer: (url: String) -> Unit, + markAsReadOnScroll: Boolean, ) { val transferCommentEditDepsViaRoot = navController.rootChannel() val transferCommentReplyDepsViaRoot = navController.rootChannel() @@ -312,6 +283,7 @@ fun UserTabs( ApiState.Refreshing, ) } + else -> {} } }, @@ -402,6 +374,7 @@ fun UserTabs( } } } + else -> {} } } @@ -541,8 +514,25 @@ fun UserTabs( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = openImageViewer, + markAsReadOnScroll = markAsReadOnScroll, + onMarkAsRead = { + account?.also { acct -> + personProfileViewModel.markPostAsRead( + MarkPostAsRead( + post_id = it.post.id, + read = true, +<<<<<<< Updated upstream + auth = acct.jwt +======= + auth = acct.jwt, +>>>>>>> Stashed changes + ), + ) + } + }, ) } + else -> {} } } @@ -568,7 +558,8 @@ fun UserTabs( // Holds the un-expanded comment ids val unExpandedComments = remember { mutableStateListOf() } - val commentsWithToggledActionBar = remember { mutableStateListOf() } + val commentsWithToggledActionBar = + remember { mutableStateListOf() } val toggleExpanded = { commentId: Int -> if (unExpandedComments.contains(commentId)) { @@ -619,7 +610,15 @@ fun UserTabs( increaseLazyListIndexTracker = {}, addToParentIndexes = {}, isFlat = true, - isExpanded = { commentId -> !unExpandedComments.contains(commentId) }, + isExpanded = { commentId -> + !unExpandedComments.contains( +<<<<<<< Updated upstream + commentId +======= + commentId, +>>>>>>> Stashed changes + ) + }, listState = listState, toggleExpanded = { commentId -> toggleExpanded(commentId) }, toggleActionBar = { commentId -> toggleActionBar(commentId) }, @@ -718,7 +717,13 @@ fun UserTabs( showCollapsedCommentContent = true, isCollapsedByParent = false, showActionBar = { commentId -> - showActionBarByDefault xor commentsWithToggledActionBar.contains(commentId) + showActionBarByDefault xor commentsWithToggledActionBar.contains( +<<<<<<< Updated upstream + commentId +======= + commentId, +>>>>>>> Stashed changes + ) }, account = account, moderators = listOf(), diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 55934997f..0a6a74da1 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -2,11 +2,7 @@ package com.jerboa.ui.components.post import android.util.Log import androidx.compose.foundation.focusable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.ExperimentalMaterialApi @@ -16,26 +12,9 @@ import androidx.compose.material.icons.outlined.Sort import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Scaffold -import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults -import androidx.compose.material3.rememberTopAppBarState -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateListOf -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.Modifier +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.* import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.input.key.Key @@ -48,67 +27,22 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavController import arrow.core.Either -import com.jerboa.PostViewMode +import com.jerboa.* import com.jerboa.R -import com.jerboa.VoteType import com.jerboa.api.ApiState -import com.jerboa.buildCommentsTree -import com.jerboa.datatypes.types.BlockCommunity -import com.jerboa.datatypes.types.BlockPerson -import com.jerboa.datatypes.types.CommentId -import com.jerboa.datatypes.types.CommentSortType -import com.jerboa.datatypes.types.CommentView -import com.jerboa.datatypes.types.CreateCommentLike -import com.jerboa.datatypes.types.CreatePostLike -import com.jerboa.datatypes.types.DeleteComment -import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.PostId -import com.jerboa.datatypes.types.PostView -import com.jerboa.datatypes.types.SaveComment -import com.jerboa.datatypes.types.SavePost +import com.jerboa.datatypes.types.* import com.jerboa.db.AccountViewModel -import com.jerboa.getCommentParentId -import com.jerboa.getDepthFromComment -import com.jerboa.getLocalizedCommentSortTypeName -import com.jerboa.isLoading -import com.jerboa.isModerator -import com.jerboa.isRefreshing import com.jerboa.model.PostViewModel import com.jerboa.model.ReplyItem import com.jerboa.model.SiteViewModel -import com.jerboa.newVote -import com.jerboa.scrollToNextParentComment -import com.jerboa.scrollToPreviousParentComment -import com.jerboa.shareLink import com.jerboa.ui.components.comment.ShowCommentContextButtons import com.jerboa.ui.components.comment.commentNodeItems import com.jerboa.ui.components.comment.edit.CommentEditReturn import com.jerboa.ui.components.comment.reply.CommentReplyReturn -import com.jerboa.ui.components.common.ApiErrorText -import com.jerboa.ui.components.common.CommentEditDeps -import com.jerboa.ui.components.common.CommentNavigationBottomAppBar -import com.jerboa.ui.components.common.CommentReplyDeps -import com.jerboa.ui.components.common.CommentSortOptionsDialog -import com.jerboa.ui.components.common.ConsumeReturn -import com.jerboa.ui.components.common.InitializeRoute -import com.jerboa.ui.components.common.LoadingBar -import com.jerboa.ui.components.common.PostEditDeps -import com.jerboa.ui.components.common.getCurrentAccount -import com.jerboa.ui.components.common.rootChannel -import com.jerboa.ui.components.common.simpleVerticalScrollbar -import com.jerboa.ui.components.common.toComment -import com.jerboa.ui.components.common.toCommentEdit -import com.jerboa.ui.components.common.toCommentReply -import com.jerboa.ui.components.common.toCommentReport -import com.jerboa.ui.components.common.toCommunity -import com.jerboa.ui.components.common.toPost -import com.jerboa.ui.components.common.toPostEdit -import com.jerboa.ui.components.common.toPostReport -import com.jerboa.ui.components.common.toProfile +import com.jerboa.ui.components.common.* import com.jerboa.ui.components.post.edit.PostEditReturn @Composable @@ -149,6 +83,7 @@ fun PostActivity( navigateParentCommentsWithVolumeButtons: Boolean, blurNSFW: Boolean, openImageViewer: (url: String) -> Unit, + markAsReadOnScroll: Boolean, ) { Log.d("jerboa", "got to post activity") val transferCommentEditDepsViaRoot = navController.rootChannel() @@ -176,6 +111,20 @@ fun PostActivity( InitializeRoute(postViewModel) { postViewModel.initialize(id = id) postViewModel.getData(account) + id.fold({ + postViewModel.markPostAsRead( + MarkPostAsRead( + post_id = it, + read = true, +<<<<<<< Updated upstream + auth = account!!.jwt + ) +======= + auth = account!!.jwt, + ), +>>>>>>> Stashed changes + ) + }, {}) } val onClickSortType = { commentSortType: CommentSortType -> @@ -306,6 +255,7 @@ fun PostActivity( when (val postRes = postViewModel.postRes) { is ApiState.Loading -> LoadingBar(padding) + is ApiState.Failure -> ApiErrorText(postRes.msg) is ApiState.Success -> { val postView = postRes.data.post_view @@ -351,7 +301,8 @@ fun PostActivity( } }, onReplyClick = { pv -> - val isModerator = isModerator(pv.creator, postRes.data.moderators) + val isModerator = + isModerator(pv.creator, postRes.data.moderators) navController.toCommentReply( channel = transferCommentReplyDepsViaRoot, replyItem = ReplyItem.PostItem(pv), @@ -439,6 +390,26 @@ fun PostActivity( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = openImageViewer, + markAsReadOnScroll = markAsReadOnScroll, + onMarkAsRead = { pv -> + account?.also { acct -> + postViewModel.markPostAsRead( + MarkPostAsRead( + post_id = pv.post.id, + read = true, +<<<<<<< Updated upstream + auth = acct.jwt + ) + ) + } + } +======= + auth = acct.jwt, + ), + ) + } + }, +>>>>>>> Stashed changes ) } @@ -546,7 +517,8 @@ fun PostActivity( } }, onReplyClick = { cv -> - val isModerator = isModerator(cv.creator, postRes.data.moderators) + val isModerator = + isModerator(cv.creator, postRes.data.moderators) navController.toCommentReply( channel = transferCommentReplyDepsViaRoot, replyItem = ReplyItem.CommentItem(cv), @@ -568,7 +540,15 @@ fun PostActivity( navController.toProfile(id = personId) }, onHeaderClick = { commentView -> toggleExpanded(commentView.comment.id) }, - onHeaderLongClick = { commentView -> toggleActionBar(commentView.comment.id) }, + onHeaderLongClick = { commentView -> + toggleActionBar( +<<<<<<< Updated upstream + commentView.comment.id +======= + commentView.comment.id, +>>>>>>> Stashed changes + ) + }, onEditCommentClick = { cv -> navController.toCommentEdit( channel = transferCommentEditDepsViaRoot, @@ -597,7 +577,7 @@ fun PostActivity( commentView = cv, account = account, - ) + ) }, onBlockCreatorClick = { person -> account?.also { acct -> diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt index eefcd80ca..d64429e6d 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt @@ -2,54 +2,15 @@ package com.jerboa.ui.components.post import android.widget.Toast import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxHeight -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.layout.size +import androidx.compose.foundation.layout.* import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.LocalContentAlpha import androidx.compose.material.LocalContentColor import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Bookmark -import androidx.compose.material.icons.outlined.Block -import androidx.compose.material.icons.outlined.BookmarkBorder -import androidx.compose.material.icons.outlined.ChatBubbleOutline -import androidx.compose.material.icons.outlined.CommentsDisabled -import androidx.compose.material.icons.outlined.ContentCopy -import androidx.compose.material.icons.outlined.Delete -import androidx.compose.material.icons.outlined.Description -import androidx.compose.material.icons.outlined.Edit -import androidx.compose.material.icons.outlined.Flag -import androidx.compose.material.icons.outlined.Forum -import androidx.compose.material.icons.outlined.Link -import androidx.compose.material.icons.outlined.MoreVert -import androidx.compose.material.icons.outlined.Person -import androidx.compose.material.icons.outlined.PushPin -import androidx.compose.material.icons.outlined.Restore -import androidx.compose.material.icons.outlined.Share -import androidx.compose.material.icons.outlined.Textsms -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.Card -import androidx.compose.material3.Divider -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.OutlinedCard -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue +import androidx.compose.material.icons.outlined.* +import androidx.compose.material3.* +import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -71,50 +32,20 @@ import com.jerboa.VoteType import com.jerboa.calculateNewInstantScores import com.jerboa.communityNameShown import com.jerboa.copyToClipboard -import com.jerboa.datatypes.sampleImagePostView -import com.jerboa.datatypes.sampleLinkNoThumbnailPostView -import com.jerboa.datatypes.sampleLinkPostView -import com.jerboa.datatypes.sampleMarkdownPostView -import com.jerboa.datatypes.samplePostView -import com.jerboa.datatypes.types.Community -import com.jerboa.datatypes.types.Person -import com.jerboa.datatypes.types.Post -import com.jerboa.datatypes.types.PostView +import com.jerboa.datatypes.* +import com.jerboa.datatypes.types.* import com.jerboa.db.Account import com.jerboa.hostName import com.jerboa.isImage import com.jerboa.isSameInstance import com.jerboa.nsfwCheck import com.jerboa.openLink -import com.jerboa.ui.components.common.ActionBarButton -import com.jerboa.ui.components.common.CircularIcon -import com.jerboa.ui.components.common.CommentOrPostNodeHeader -import com.jerboa.ui.components.common.DotSpacer -import com.jerboa.ui.components.common.IconAndTextDrawerItem +import com.jerboa.ui.components.common.* import com.jerboa.ui.components.common.MarkdownHelper.CreateMarkdownPreview -import com.jerboa.ui.components.common.MyMarkdownText -import com.jerboa.ui.components.common.NsfwBadge -import com.jerboa.ui.components.common.PictrsThumbnailImage -import com.jerboa.ui.components.common.PictrsUrlImage -import com.jerboa.ui.components.common.ScoreAndTime -import com.jerboa.ui.components.common.SimpleTopAppBar -import com.jerboa.ui.components.common.TimeAgo -import com.jerboa.ui.components.common.VoteGeneric -import com.jerboa.ui.components.common.scoreColor import com.jerboa.ui.components.community.CommunityLink import com.jerboa.ui.components.community.CommunityName import com.jerboa.ui.components.person.PersonProfileLink -import com.jerboa.ui.theme.ACTION_BAR_ICON_SIZE -import com.jerboa.ui.theme.CARD_COLORS -import com.jerboa.ui.theme.LARGER_ICON_THUMBNAIL_SIZE -import com.jerboa.ui.theme.LARGE_PADDING -import com.jerboa.ui.theme.LINK_ICON_SIZE -import com.jerboa.ui.theme.MEDIUM_ICON_SIZE -import com.jerboa.ui.theme.MEDIUM_PADDING -import com.jerboa.ui.theme.POST_LINK_PIC_SIZE -import com.jerboa.ui.theme.SMALL_PADDING -import com.jerboa.ui.theme.XXL_PADDING -import com.jerboa.ui.theme.muted +import com.jerboa.ui.theme.* @Composable fun PostHeaderLine( @@ -333,7 +264,7 @@ fun PostTitleAndImageLink( horizontal = MEDIUM_PADDING, ), - ) { + ) { // Title of the post PostName( postView = postView, @@ -457,7 +388,8 @@ fun PostBody( } } } else { - val defaultColor: Color = LocalContentColor.current.copy(alpha = LocalContentAlpha.current) + val defaultColor: Color = + LocalContentColor.current.copy(alpha = LocalContentAlpha.current) CreateMarkdownPreview( markdown = text, @@ -763,6 +695,12 @@ fun PreviewPostListingCard() { showAvatar = true, blurNSFW = true, openImageViewer = {}, + markAsReadOnScroll = false, +<<<<<<< Updated upstream + onMarkAsRead = {} +======= + onMarkAsRead = {}, +>>>>>>> Stashed changes ) } @@ -795,6 +733,12 @@ fun PreviewLinkPostListing() { showAvatar = true, blurNSFW = true, openImageViewer = {}, + markAsReadOnScroll = false, +<<<<<<< Updated upstream + onMarkAsRead = {} +======= + onMarkAsRead = {}, +>>>>>>> Stashed changes ) } @@ -827,6 +771,12 @@ fun PreviewImagePostListingCard() { showAvatar = true, blurNSFW = true, openImageViewer = {}, + markAsReadOnScroll = false, +<<<<<<< Updated upstream + onMarkAsRead = {} +======= + onMarkAsRead = {}, +>>>>>>> Stashed changes ) } @@ -859,6 +809,12 @@ fun PreviewImagePostListingSmallCard() { showAvatar = true, blurNSFW = true, openImageViewer = {}, + markAsReadOnScroll = false, +<<<<<<< Updated upstream + onMarkAsRead = {} +======= + onMarkAsRead = {}, +>>>>>>> Stashed changes ) } @@ -891,6 +847,8 @@ fun PreviewLinkNoThumbnailPostListing() { showAvatar = true, blurNSFW = true, openImageViewer = {}, + markAsReadOnScroll = false, + onMarkAsRead = {}, ) } @@ -923,6 +881,8 @@ fun PostListing( showAvatar: Boolean, blurNSFW: Boolean, openImageViewer: (url: String) -> Unit, + markAsReadOnScroll: Boolean, + onMarkAsRead: (postView: PostView) -> Unit, ) { // This stores vote data val instantScores = remember { @@ -938,6 +898,14 @@ fun PostListing( var viewSource by remember { mutableStateOf(false) } + if (markAsReadOnScroll) { + DisposableEffect(key1 = postView.post.id) { + onDispose { + onMarkAsRead(postView) + } + } + } + when (postViewMode) { PostViewMode.Card -> PostListingCard( postView = postView, @@ -1161,7 +1129,7 @@ fun PostListingList( horizontalArrangement = Arrangement.spacedBy(SMALL_PADDING, Alignment.Start), verticalArrangement = Arrangement.Center, - ) { + ) { if (showCommunityName) { CommunityLink( community = postView.community, @@ -1551,10 +1519,35 @@ fun PostOptionsDialog( text = stringResource(R.string.post_listing_copy_thumbnail_link), icon = Icons.Outlined.Link, onClick = { - if (copyToClipboard(ctx, postView.post.thumbnail_url, "thumbnail link")) { - Toast.makeText(ctx, ctx.getString(R.string.post_listing_thumbnail_link_copied), Toast.LENGTH_SHORT).show() + if (copyToClipboard( + ctx, + postView.post.thumbnail_url, +<<<<<<< Updated upstream + "thumbnail link" +======= + "thumbnail link", +>>>>>>> Stashed changes + ) + ) { + Toast.makeText( + ctx, + ctx.getString(R.string.post_listing_thumbnail_link_copied), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } else { - Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show() + Toast.makeText( + ctx, + ctx.getString(R.string.generic_error), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } onDismissRequest() }, @@ -1565,10 +1558,35 @@ fun PostOptionsDialog( text = stringResource(R.string.post_listing_copy_title), icon = Icons.Outlined.ContentCopy, onClick = { - if (copyToClipboard(ctx, postView.post.embed_description, "post title")) { - Toast.makeText(ctx, ctx.getString(R.string.post_listing_title_copied), Toast.LENGTH_SHORT).show() + if (copyToClipboard( + ctx, + postView.post.embed_description, +<<<<<<< Updated upstream + "post title" +======= + "post title", +>>>>>>> Stashed changes + ) + ) { + Toast.makeText( + ctx, + ctx.getString(R.string.post_listing_title_copied), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } else { - Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show() + Toast.makeText( + ctx, + ctx.getString(R.string.generic_error), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } onDismissRequest() }, @@ -1580,9 +1598,25 @@ fun PostOptionsDialog( icon = Icons.Outlined.ContentCopy, onClick = { if (copyToClipboard(ctx, postView.post.name, "post name")) { - Toast.makeText(ctx, ctx.getString(R.string.post_listing_name_copied), Toast.LENGTH_SHORT).show() + Toast.makeText( + ctx, + ctx.getString(R.string.post_listing_name_copied), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } else { - Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show() + Toast.makeText( + ctx, + ctx.getString(R.string.generic_error), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } onDismissRequest() }, @@ -1594,9 +1628,25 @@ fun PostOptionsDialog( icon = Icons.Outlined.ContentCopy, onClick = { if (copyToClipboard(ctx, postView.post.body, "post text")) { - Toast.makeText(ctx, ctx.getString(R.string.post_listing_text_copied), Toast.LENGTH_SHORT).show() + Toast.makeText( + ctx, + ctx.getString(R.string.post_listing_text_copied), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } else { - Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show() + Toast.makeText( + ctx, + ctx.getString(R.string.generic_error), +<<<<<<< Updated upstream + Toast.LENGTH_SHORT +======= + Toast.LENGTH_SHORT, +>>>>>>> Stashed changes + ).show() } onDismissRequest() }, @@ -1604,7 +1654,19 @@ fun PostOptionsDialog( } postView.post.body?.also { IconAndTextDrawerItem( - text = if (viewSource) stringResource(R.string.post_listing_view_original) else stringResource(R.string.post_listing_view_source), +<<<<<<< Updated upstream + text = if (viewSource) stringResource(R.string.post_listing_view_original) else stringResource( + R.string.post_listing_view_source + ), +======= + text = if (viewSource) { + stringResource(R.string.post_listing_view_original) + } else { + stringResource( + R.string.post_listing_view_source, + ) + }, +>>>>>>> Stashed changes icon = Icons.Outlined.Description, onClick = onViewSourceClick, ) diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt index 51c4bde5e..13b96c1cc 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt @@ -3,10 +3,7 @@ package com.jerboa.ui.components.post import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.items -import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.lazy.* import androidx.compose.material3.Divider import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -59,6 +56,8 @@ fun PostListings( usePrivateTabs: Boolean, blurNSFW: Boolean, openImageViewer: (url: String) -> Unit, + markAsReadOnScroll: Boolean, + onMarkAsRead: (postView: PostView) -> Unit, ) { LazyColumn( state = listState, @@ -105,6 +104,8 @@ fun PostListings( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = openImageViewer, + markAsReadOnScroll = markAsReadOnScroll, + onMarkAsRead = onMarkAsRead, ) Divider(modifier = Modifier.padding(bottom = SMALL_PADDING)) } @@ -153,5 +154,7 @@ fun PreviewPostListings() { usePrivateTabs = false, blurNSFW = true, openImageViewer = {}, + markAsReadOnScroll = false, + onMarkAsRead = {}, ) } diff --git a/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt b/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt index 50f86bf52..68f342c9b 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/account/AccountSettings.kt @@ -5,7 +5,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.* +import androidx.compose.material.icons.outlined.Close import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable @@ -32,7 +32,7 @@ import com.jerboa.imageInputStreamFromUri import com.jerboa.model.AccountSettingsViewModel import com.jerboa.model.SiteViewModel import com.jerboa.ui.components.common.* -import com.jerboa.ui.theme.* +import com.jerboa.ui.theme.MEDIUM_PADDING import kotlinx.coroutines.launch @Composable @@ -262,6 +262,7 @@ fun SettingsForm( Text(text = stringResource(R.string.account_settings_show_read_posts)) }, ) + SettingsCheckbox( state = botAccount, title = { diff --git a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt index 66783c5ec..8d851cac1 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt @@ -7,18 +7,8 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.Colorize -import androidx.compose.material.icons.outlined.ExitToApp -import androidx.compose.material.icons.outlined.FormatSize -import androidx.compose.material.icons.outlined.Language -import androidx.compose.material.icons.outlined.Palette -import androidx.compose.material.icons.outlined.ViewList -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.Scaffold -import androidx.compose.material3.SnackbarHost -import androidx.compose.material3.SnackbarHostState -import androidx.compose.material3.Text +import androidx.compose.material.icons.outlined.* +import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier @@ -30,19 +20,12 @@ import androidx.navigation.NavController import com.alorma.compose.settings.storage.base.rememberBooleanSettingState import com.alorma.compose.settings.storage.base.rememberFloatSettingState import com.alorma.compose.settings.storage.base.rememberIntSettingState -import com.alorma.compose.settings.ui.SettingsCheckbox -import com.alorma.compose.settings.ui.SettingsList -import com.alorma.compose.settings.ui.SettingsListDropdown -import com.alorma.compose.settings.ui.SettingsSlider -import com.jerboa.PostViewMode +import com.alorma.compose.settings.ui.* +import com.jerboa.* import com.jerboa.R -import com.jerboa.ThemeColor -import com.jerboa.ThemeMode import com.jerboa.db.APP_SETTINGS_DEFAULT import com.jerboa.db.AppSettings import com.jerboa.db.AppSettingsViewModel -import com.jerboa.getLangPreferenceDropdownEntries -import com.jerboa.matchLocale import com.jerboa.ui.components.common.SimpleTopAppBar import com.jerboa.util.BackConfirmationMode @@ -71,7 +54,8 @@ fun LookAndFeelActivity( ) val postViewModeState = rememberIntSettingState(settings.postViewMode) val showBottomNavState = rememberBooleanSettingState(settings.showBottomNav) - val showTextDescriptionsInNavbar = rememberBooleanSettingState(settings.showTextDescriptionsInNavbar) + val showTextDescriptionsInNavbar = + rememberBooleanSettingState(settings.showTextDescriptionsInNavbar) val showCollapsedCommentContentState = rememberBooleanSettingState(settings.showCollapsedCommentContent) val showCommentActionBarByDefaultState = rememberBooleanSettingState( @@ -97,6 +81,8 @@ fun LookAndFeelActivity( val scrollState = rememberScrollState() + val markAsReadOnScroll = rememberBooleanSettingState(settings.markAsReadOnScroll) + fun updateAppSettings() { appSettingsViewModel.update( AppSettings( @@ -118,6 +104,11 @@ fun LookAndFeelActivity( showTextDescriptionsInNavbar = showTextDescriptionsInNavbar.value, blurNSFW = blurNSFW.value, backConfirmationMode = backConfirmationMode.value, +<<<<<<< Updated upstream + markAsReadOnScroll = markAsReadOnScroll.value +======= + markAsReadOnScroll = markAsReadOnScroll.value, +>>>>>>> Stashed changes ), ) } @@ -125,7 +116,14 @@ fun LookAndFeelActivity( Scaffold( snackbarHost = { SnackbarHost(snackbarHostState) }, topBar = { - SimpleTopAppBar(text = stringResource(R.string.look_and_feel_look_and_feel), navController = navController) + SimpleTopAppBar( + text = stringResource(R.string.look_and_feel_look_and_feel), +<<<<<<< Updated upstream + navController = navController +======= + navController = navController, +>>>>>>> Stashed changes + ) }, content = { padding -> Column( @@ -317,6 +315,13 @@ fun LookAndFeelActivity( ) }, ) + SettingsCheckbox( + state = markAsReadOnScroll, + title = { + Text(stringResource(id = R.string.mark_as_read_on_scroll)) + }, + onCheckedChange = { updateAppSettings() }, + ) } }, ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index eb5611a0c..0d96231b5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -337,4 +337,5 @@ Show a confirmation dialog on exit Exit Are you sure you want to exit? + Mark as read on scroll From 897a447525d3548bf80c9840548a593a61fae417 Mon Sep 17 00:00:00 2001 From: ZJouba Date: Wed, 12 Jul 2023 12:35:05 +0200 Subject: [PATCH 02/17] Mark as read on open and scroll option --- app/src/main/java/com/jerboa/MainActivity.kt | 4 -- app/src/main/java/com/jerboa/api/Http.kt | 5 -- app/src/main/java/com/jerboa/db/AppDB.kt | 4 -- app/src/main/java/com/jerboa/db/Migrations.kt | 4 +- .../com/jerboa/model/CommunityViewModel.kt | 10 +-- .../java/com/jerboa/model/HomeViewModel.kt | 10 --- .../jerboa/model/PersonProfileViewModel.kt | 2 +- .../java/com/jerboa/model/PostViewModel.kt | 4 -- .../components/community/CommunityActivity.kt | 13 ---- .../ui/components/home/BottomNavActivity.kt | 24 ------- .../jerboa/ui/components/home/HomeActivity.kt | 12 +--- .../person/PersonProfileActivity.kt | 12 ---- .../jerboa/ui/components/post/PostActivity.kt | 19 +----- .../jerboa/ui/components/post/PostListing.kt | 66 +------------------ .../jerboa/ui/components/post/PostListings.kt | 3 +- .../lookandfeel/LookAndFeelActivity.kt | 22 ++----- 16 files changed, 17 insertions(+), 197 deletions(-) diff --git a/app/src/main/java/com/jerboa/MainActivity.kt b/app/src/main/java/com/jerboa/MainActivity.kt index 21a102b45..3b3009d27 100644 --- a/app/src/main/java/com/jerboa/MainActivity.kt +++ b/app/src/main/java/com/jerboa/MainActivity.kt @@ -148,11 +148,7 @@ class MainActivity : AppCompatActivity() { val siteVersion = siteRes.data.version if (compareVersions( siteVersion, -<<<<<<< Updated upstream - MINIMUM_API_VERSION -======= MINIMUM_API_VERSION, ->>>>>>> Stashed changes ) < 0 && !serverVersionOutdatedViewed.value ) { ShowOutdatedServerDialog( diff --git a/app/src/main/java/com/jerboa/api/Http.kt b/app/src/main/java/com/jerboa/api/Http.kt index 180a8d935..9e7c562cb 100644 --- a/app/src/main/java/com/jerboa/api/Http.kt +++ b/app/src/main/java/com/jerboa/api/Http.kt @@ -299,13 +299,8 @@ interface API { .addInterceptor( CustomHttpLoggingInterceptor( REDACTED_QUERY_PARAMS, -<<<<<<< Updated upstream - REDACTED_BODY_FIELDS - ) -======= REDACTED_BODY_FIELDS, ), ->>>>>>> Stashed changes ) .build() diff --git a/app/src/main/java/com/jerboa/db/AppDB.kt b/app/src/main/java/com/jerboa/db/AppDB.kt index 059a5772e..ead201a80 100644 --- a/app/src/main/java/com/jerboa/db/AppDB.kt +++ b/app/src/main/java/com/jerboa/db/AppDB.kt @@ -151,11 +151,7 @@ val APP_SETTINGS_DEFAULT = AppSettings( blurNSFW = true, showTextDescriptionsInNavbar = true, backConfirmationMode = 1, -<<<<<<< Updated upstream - markAsReadOnScroll = false -======= markAsReadOnScroll = false, ->>>>>>> Stashed changes ) @Dao diff --git a/app/src/main/java/com/jerboa/db/Migrations.kt b/app/src/main/java/com/jerboa/db/Migrations.kt index 26afbee11..b8b53154f 100644 --- a/app/src/main/java/com/jerboa/db/Migrations.kt +++ b/app/src/main/java/com/jerboa/db/Migrations.kt @@ -9,11 +9,11 @@ val MIGRATION_1_2 = object : Migration(1, 2) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL( "alter table account add column default_listing_type INTEGER NOT " + - "NULL default 0", + "NULL default 0", ) database.execSQL( "alter table account add column default_sort_type INTEGER NOT " + - "NULL default 0", + "NULL default 0", ) } } diff --git a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt index f9b723258..b57f1e2c2 100644 --- a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt +++ b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt @@ -21,7 +21,7 @@ class CommunityViewModel : ViewModel(), Initializable { private set private var followCommunityRes: ApiState by - mutableStateOf(ApiState.Empty) + mutableStateOf(ApiState.Empty) var postsRes: ApiState by mutableStateOf(ApiState.Empty) private set @@ -30,7 +30,7 @@ class CommunityViewModel : ViewModel(), Initializable { private var savePostRes: ApiState by mutableStateOf(ApiState.Empty) private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) private var blockCommunityRes: ApiState by - mutableStateOf(ApiState.Empty) + mutableStateOf(ApiState.Empty) private var blockPersonRes: ApiState by mutableStateOf(ApiState.Empty) private var markPostRes: ApiState by mutableStateOf(ApiState.Empty) @@ -102,15 +102,9 @@ class CommunityViewModel : ViewModel(), Initializable { GetPostsResponse( mergePosts( oldRes.data.posts, -<<<<<<< Updated upstream - newRes.data.posts - ) - ) -======= newRes.data.posts, ), ), ->>>>>>> Stashed changes ) } diff --git a/app/src/main/java/com/jerboa/model/HomeViewModel.kt b/app/src/main/java/com/jerboa/model/HomeViewModel.kt index 1f89308fa..b47464b79 100644 --- a/app/src/main/java/com/jerboa/model/HomeViewModel.kt +++ b/app/src/main/java/com/jerboa/model/HomeViewModel.kt @@ -85,15 +85,9 @@ class HomeViewModel : ViewModel(), Initializable { GetPostsResponse( mergePosts( oldRes.data.posts, -<<<<<<< Updated upstream - newRes.data.posts - ) - ) -======= newRes.data.posts, ), ), ->>>>>>> Stashed changes ) } @@ -168,12 +162,8 @@ class HomeViewModel : ViewModel(), Initializable { fun updateFromAccount(account: Account) { updateSortType(SortType.values().getOrElse(account.defaultSortType) { sortType }) updateListingType( -<<<<<<< Updated upstream - ListingType.values().getOrElse(account.defaultListingType) { listingType }) -======= ListingType.values().getOrElse(account.defaultListingType) { listingType }, ) ->>>>>>> Stashed changes } fun updatePost(postView: PostView) { diff --git a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt index a301bc5af..dcdb2cb1d 100644 --- a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt @@ -26,7 +26,7 @@ class PersonProfileViewModel : ViewModel(), Initializable { private var savePostRes: ApiState by mutableStateOf(ApiState.Empty) private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) private var blockCommunityRes: ApiState by - mutableStateOf(ApiState.Empty) + mutableStateOf(ApiState.Empty) private var blockPersonRes: ApiState by mutableStateOf(ApiState.Empty) private var likeCommentRes: ApiState by mutableStateOf(ApiState.Empty) diff --git a/app/src/main/java/com/jerboa/model/PostViewModel.kt b/app/src/main/java/com/jerboa/model/PostViewModel.kt index 42a9e1339..4959f85ce 100644 --- a/app/src/main/java/com/jerboa/model/PostViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PostViewModel.kt @@ -285,10 +285,6 @@ class PostViewModel : ViewModel(), Initializable { } } -<<<<<<< Updated upstream - -======= ->>>>>>> Stashed changes fun markPostAsRead(form: MarkPostAsRead) { viewModelScope.launch { markPostRes = ApiState.Loading diff --git a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt index 295b3749c..e918b7821 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt @@ -73,12 +73,8 @@ fun CommunityActivity( communityViewModel.resetPage() account?.let { communityViewModel.updateSortType( -<<<<<<< Updated upstream - SortType.values().getOrElse(account.defaultSortType) { siteViewModel.sortType }) -======= SortType.values().getOrElse(account.defaultSortType) { siteViewModel.sortType }, ) ->>>>>>> Stashed changes } communityViewModel.getCommunity( form = GetCommunity( @@ -195,11 +191,7 @@ fun CommunityActivity( pullRefreshState, Modifier .align(Alignment.TopCenter) -<<<<<<< Updated upstream - .zIndex(100F) -======= .zIndex(100F), ->>>>>>> Stashed changes ) // Can't be in ApiState.Loading, because of infinite scrolling if (communityViewModel.postsRes.isLoading()) { @@ -373,13 +365,8 @@ fun CommunityActivity( MarkPostAsRead( post_id = postView.post.id, read = true, -<<<<<<< Updated upstream - auth = acct.jwt - ) -======= auth = acct.jwt, ), ->>>>>>> Stashed changes ) } }, diff --git a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt index 8ecc64bd7..1e0d43119 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt @@ -45,51 +45,31 @@ enum class NavTab( R.string.bottomBar_label_home, Icons.Outlined.Home, Icons.Filled.Home, -<<<<<<< Updated upstream - R.string.bottomBar_home -======= R.string.bottomBar_home, ->>>>>>> Stashed changes ), Search( R.string.bottomBar_label_search, Icons.Outlined.Search, Icons.Filled.Search, -<<<<<<< Updated upstream - R.string.bottomBar_search -======= R.string.bottomBar_search, ->>>>>>> Stashed changes ), Inbox( R.string.bottomBar_label_inbox, Icons.Outlined.Email, Icons.Filled.Email, -<<<<<<< Updated upstream - R.string.bottomBar_inbox -======= R.string.bottomBar_inbox, ->>>>>>> Stashed changes ), Saved( R.string.bottomBar_label_bookmarks, Icons.Outlined.Bookmarks, Icons.Filled.Bookmarks, -<<<<<<< Updated upstream - R.string.bottomBar_bookmarks -======= R.string.bottomBar_bookmarks, ->>>>>>> Stashed changes ), Profile( R.string.bottomBar_label_profile, Icons.Outlined.Person, Icons.Filled.Person, -<<<<<<< Updated upstream - R.string.bottomBar_profile -======= R.string.bottomBar_profile, ->>>>>>> Stashed changes ), ; @@ -194,11 +174,7 @@ fun BottomNavActivity( usePrivateTabs = appSettings.usePrivateTabs, drawerState = drawerState, blurNSFW = appSettings.blurNSFW, -<<<<<<< Updated upstream - markAsReadOnScroll = appSettings.markAsReadOnScroll -======= markAsReadOnScroll = appSettings.markAsReadOnScroll, ->>>>>>> Stashed changes ) } diff --git a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt index 75fb8e383..a175d04f9 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt @@ -15,9 +15,7 @@ import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState import androidx.compose.material3.* -import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.* import androidx.compose.ui.* import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext @@ -318,19 +316,11 @@ fun MainPostListingsContent( MarkPostAsRead( post_id = postView.post.id, read = true, -<<<<<<< Updated upstream - auth = acct.jwt - ) - ) - } - } -======= auth = acct.jwt, ), ) } }, ->>>>>>> Stashed changes ) } } diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index 5e7d75293..96f259bf1 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -521,11 +521,7 @@ fun UserTabs( MarkPostAsRead( post_id = it.post.id, read = true, -<<<<<<< Updated upstream - auth = acct.jwt -======= auth = acct.jwt, ->>>>>>> Stashed changes ), ) } @@ -612,11 +608,7 @@ fun UserTabs( isFlat = true, isExpanded = { commentId -> !unExpandedComments.contains( -<<<<<<< Updated upstream - commentId -======= commentId, ->>>>>>> Stashed changes ) }, listState = listState, @@ -718,11 +710,7 @@ fun UserTabs( isCollapsedByParent = false, showActionBar = { commentId -> showActionBarByDefault xor commentsWithToggledActionBar.contains( -<<<<<<< Updated upstream - commentId -======= commentId, ->>>>>>> Stashed changes ) }, account = account, diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 0a6a74da1..02d37c852 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -116,13 +116,8 @@ fun PostActivity( MarkPostAsRead( post_id = it, read = true, -<<<<<<< Updated upstream - auth = account!!.jwt - ) -======= auth = account!!.jwt, ), ->>>>>>> Stashed changes ) }, {}) } @@ -397,19 +392,11 @@ fun PostActivity( MarkPostAsRead( post_id = pv.post.id, read = true, -<<<<<<< Updated upstream - auth = acct.jwt - ) - ) - } - } -======= auth = acct.jwt, ), ) } }, ->>>>>>> Stashed changes ) } @@ -542,11 +529,7 @@ fun PostActivity( onHeaderClick = { commentView -> toggleExpanded(commentView.comment.id) }, onHeaderLongClick = { commentView -> toggleActionBar( -<<<<<<< Updated upstream - commentView.comment.id -======= commentView.comment.id, ->>>>>>> Stashed changes ) }, onEditCommentClick = { cv -> @@ -577,7 +560,7 @@ fun PostActivity( commentView = cv, account = account, - ) + ) }, onBlockCreatorClick = { person -> account?.also { acct -> diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt index d64429e6d..78d62d3ad 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt @@ -264,7 +264,7 @@ fun PostTitleAndImageLink( horizontal = MEDIUM_PADDING, ), - ) { + ) { // Title of the post PostName( postView = postView, @@ -696,11 +696,7 @@ fun PreviewPostListingCard() { blurNSFW = true, openImageViewer = {}, markAsReadOnScroll = false, -<<<<<<< Updated upstream - onMarkAsRead = {} -======= onMarkAsRead = {}, ->>>>>>> Stashed changes ) } @@ -734,11 +730,7 @@ fun PreviewLinkPostListing() { blurNSFW = true, openImageViewer = {}, markAsReadOnScroll = false, -<<<<<<< Updated upstream - onMarkAsRead = {} -======= onMarkAsRead = {}, ->>>>>>> Stashed changes ) } @@ -772,11 +764,7 @@ fun PreviewImagePostListingCard() { blurNSFW = true, openImageViewer = {}, markAsReadOnScroll = false, -<<<<<<< Updated upstream - onMarkAsRead = {} -======= onMarkAsRead = {}, ->>>>>>> Stashed changes ) } @@ -810,11 +798,7 @@ fun PreviewImagePostListingSmallCard() { blurNSFW = true, openImageViewer = {}, markAsReadOnScroll = false, -<<<<<<< Updated upstream - onMarkAsRead = {} -======= onMarkAsRead = {}, ->>>>>>> Stashed changes ) } @@ -1129,7 +1113,7 @@ fun PostListingList( horizontalArrangement = Arrangement.spacedBy(SMALL_PADDING, Alignment.Start), verticalArrangement = Arrangement.Center, - ) { + ) { if (showCommunityName) { CommunityLink( community = postView.community, @@ -1522,31 +1506,19 @@ fun PostOptionsDialog( if (copyToClipboard( ctx, postView.post.thumbnail_url, -<<<<<<< Updated upstream - "thumbnail link" -======= "thumbnail link", ->>>>>>> Stashed changes ) ) { Toast.makeText( ctx, ctx.getString(R.string.post_listing_thumbnail_link_copied), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } else { Toast.makeText( ctx, ctx.getString(R.string.generic_error), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } onDismissRequest() @@ -1561,31 +1533,19 @@ fun PostOptionsDialog( if (copyToClipboard( ctx, postView.post.embed_description, -<<<<<<< Updated upstream - "post title" -======= "post title", ->>>>>>> Stashed changes ) ) { Toast.makeText( ctx, ctx.getString(R.string.post_listing_title_copied), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } else { Toast.makeText( ctx, ctx.getString(R.string.generic_error), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } onDismissRequest() @@ -1601,21 +1561,13 @@ fun PostOptionsDialog( Toast.makeText( ctx, ctx.getString(R.string.post_listing_name_copied), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } else { Toast.makeText( ctx, ctx.getString(R.string.generic_error), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } onDismissRequest() @@ -1631,21 +1583,13 @@ fun PostOptionsDialog( Toast.makeText( ctx, ctx.getString(R.string.post_listing_text_copied), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } else { Toast.makeText( ctx, ctx.getString(R.string.generic_error), -<<<<<<< Updated upstream - Toast.LENGTH_SHORT -======= Toast.LENGTH_SHORT, ->>>>>>> Stashed changes ).show() } onDismissRequest() @@ -1654,11 +1598,6 @@ fun PostOptionsDialog( } postView.post.body?.also { IconAndTextDrawerItem( -<<<<<<< Updated upstream - text = if (viewSource) stringResource(R.string.post_listing_view_original) else stringResource( - R.string.post_listing_view_source - ), -======= text = if (viewSource) { stringResource(R.string.post_listing_view_original) } else { @@ -1666,7 +1605,6 @@ fun PostOptionsDialog( R.string.post_listing_view_source, ) }, ->>>>>>> Stashed changes icon = Icons.Outlined.Description, onClick = onViewSourceClick, ) diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt index 13b96c1cc..de022dbc7 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt @@ -24,12 +24,11 @@ import com.jerboa.db.Account import com.jerboa.isScrolledToEnd import com.jerboa.ui.components.common.simpleVerticalScrollbar import com.jerboa.ui.theme.SMALL_PADDING -import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @Composable fun PostListings( - posts: ImmutableList, + posts: List, contentAboveListings: @Composable () -> Unit = {}, onUpvoteClick: (postView: PostView) -> Unit, onDownvoteClick: (postView: PostView) -> Unit, diff --git a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt index 8d851cac1..c9d13d0d0 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt @@ -104,11 +104,7 @@ fun LookAndFeelActivity( showTextDescriptionsInNavbar = showTextDescriptionsInNavbar.value, blurNSFW = blurNSFW.value, backConfirmationMode = backConfirmationMode.value, -<<<<<<< Updated upstream - markAsReadOnScroll = markAsReadOnScroll.value -======= markAsReadOnScroll = markAsReadOnScroll.value, ->>>>>>> Stashed changes ), ) } @@ -118,11 +114,7 @@ fun LookAndFeelActivity( topBar = { SimpleTopAppBar( text = stringResource(R.string.look_and_feel_look_and_feel), -<<<<<<< Updated upstream - navController = navController -======= navController = navController, ->>>>>>> Stashed changes ) }, content = { padding -> @@ -298,6 +290,13 @@ fun LookAndFeelActivity( }, onCheckedChange = { updateAppSettings() }, ) + SettingsCheckbox( + state = markAsReadOnScroll, + title = { + Text(stringResource(id = R.string.mark_as_read_on_scroll)) + }, + onCheckedChange = { updateAppSettings() }, + ) SettingsList( title = { Text(text = stringResource(R.string.confirm_exit)) @@ -315,13 +314,6 @@ fun LookAndFeelActivity( ) }, ) - SettingsCheckbox( - state = markAsReadOnScroll, - title = { - Text(stringResource(id = R.string.mark_as_read_on_scroll)) - }, - onCheckedChange = { updateAppSettings() }, - ) } }, ) From 286175bee5b027263b180d38af7992d39ba7a7cd Mon Sep 17 00:00:00 2001 From: ZJouba Date: Wed, 12 Jul 2023 17:00:50 +0200 Subject: [PATCH 03/17] Fixing mark all --- .../jerboa/ui/components/post/PostActivity.kt | 13 --------- .../jerboa/ui/components/post/PostListing.kt | 20 -------------- .../jerboa/ui/components/post/PostListings.kt | 27 ++++++++++--------- 3 files changed, 14 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 02d37c852..5e3ddc436 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -83,7 +83,6 @@ fun PostActivity( navigateParentCommentsWithVolumeButtons: Boolean, blurNSFW: Boolean, openImageViewer: (url: String) -> Unit, - markAsReadOnScroll: Boolean, ) { Log.d("jerboa", "got to post activity") val transferCommentEditDepsViaRoot = navController.rootChannel() @@ -385,18 +384,6 @@ fun PostActivity( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = openImageViewer, - markAsReadOnScroll = markAsReadOnScroll, - onMarkAsRead = { pv -> - account?.also { acct -> - postViewModel.markPostAsRead( - MarkPostAsRead( - post_id = pv.post.id, - read = true, - auth = acct.jwt, - ), - ) - } - }, ) } diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt index 78d62d3ad..a622dbadf 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListing.kt @@ -695,8 +695,6 @@ fun PreviewPostListingCard() { showAvatar = true, blurNSFW = true, openImageViewer = {}, - markAsReadOnScroll = false, - onMarkAsRead = {}, ) } @@ -729,8 +727,6 @@ fun PreviewLinkPostListing() { showAvatar = true, blurNSFW = true, openImageViewer = {}, - markAsReadOnScroll = false, - onMarkAsRead = {}, ) } @@ -763,8 +759,6 @@ fun PreviewImagePostListingCard() { showAvatar = true, blurNSFW = true, openImageViewer = {}, - markAsReadOnScroll = false, - onMarkAsRead = {}, ) } @@ -797,8 +791,6 @@ fun PreviewImagePostListingSmallCard() { showAvatar = true, blurNSFW = true, openImageViewer = {}, - markAsReadOnScroll = false, - onMarkAsRead = {}, ) } @@ -831,8 +823,6 @@ fun PreviewLinkNoThumbnailPostListing() { showAvatar = true, blurNSFW = true, openImageViewer = {}, - markAsReadOnScroll = false, - onMarkAsRead = {}, ) } @@ -865,8 +855,6 @@ fun PostListing( showAvatar: Boolean, blurNSFW: Boolean, openImageViewer: (url: String) -> Unit, - markAsReadOnScroll: Boolean, - onMarkAsRead: (postView: PostView) -> Unit, ) { // This stores vote data val instantScores = remember { @@ -882,14 +870,6 @@ fun PostListing( var viewSource by remember { mutableStateOf(false) } - if (markAsReadOnScroll) { - DisposableEffect(key1 = postView.post.id) { - onDispose { - onMarkAsRead(postView) - } - } - } - when (postViewMode) { PostViewMode.Card -> PostListingCard( postView = postView, diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt index de022dbc7..fa3056ca3 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt @@ -5,11 +5,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.* import androidx.compose.material3.Divider -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.derivedStateOf -import androidx.compose.runtime.getValue -import androidx.compose.runtime.remember +import androidx.compose.runtime.* import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.tooling.preview.Preview @@ -71,12 +67,9 @@ fun PostListings( contentAboveListings() } // List of items - items( + itemsIndexed( posts, - key = { postView -> - postView.post.id - }, - ) { postView -> + ) { index, postView -> PostListing( postView = postView, onUpvoteClick = onUpvoteClick, @@ -103,9 +96,17 @@ fun PostListings( usePrivateTabs = usePrivateTabs, blurNSFW = blurNSFW, openImageViewer = openImageViewer, - markAsReadOnScroll = markAsReadOnScroll, - onMarkAsRead = onMarkAsRead, - ) + ).let { + if (!postView.read && markAsReadOnScroll) { + DisposableEffect(key1 = postView.post.id) { + onDispose { + if (listState.isScrollInProgress && index < listState.firstVisibleItemIndex) { + onMarkAsRead(postView) + } + } + } + } + } Divider(modifier = Modifier.padding(bottom = SMALL_PADDING)) } } From 1a9860fe517b3b9ee3e19332b372004001638d81 Mon Sep 17 00:00:00 2001 From: Zack <42601911+ZJouba@users.noreply.github.com> Date: Wed, 12 Jul 2023 18:32:26 +0200 Subject: [PATCH 04/17] Update Http.kt --- app/src/main/java/com/jerboa/api/Http.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/jerboa/api/Http.kt b/app/src/main/java/com/jerboa/api/Http.kt index 640b0d75e..80fc3baff 100644 --- a/app/src/main/java/com/jerboa/api/Http.kt +++ b/app/src/main/java/com/jerboa/api/Http.kt @@ -20,7 +20,7 @@ import java.io.InputStream import okhttp3.Response as HttpResponse const val VERSION = "v3" -const val DEFAULT_INSTANCE = "voyager.lemmy.ml" +const val DEFAULT_INSTANCE = "lemmy.ml" const val MINIMUM_API_VERSION: String = "0.18" val REDACTED_QUERY_PARAMS = setOf("auth") val REDACTED_BODY_FIELDS = setOf("jwt", "password") From 96f35c33a1f6c796751c01b426497115bcd5da18 Mon Sep 17 00:00:00 2001 From: ZJouba Date: Thu, 13 Jul 2023 11:55:39 +0200 Subject: [PATCH 05/17] Update Home in PostActivity --- app/src/main/java/com/jerboa/MainActivity.kt | 5 +++ app/src/main/java/com/jerboa/db/AppDB.kt | 2 +- .../java/com/jerboa/model/HomeViewModel.kt | 23 ++++++++++++ .../ui/components/home/BottomNavActivity.kt | 36 ++++++++++++++----- .../jerboa/ui/components/post/PostActivity.kt | 30 +++++++++------- 5 files changed, 75 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/jerboa/MainActivity.kt b/app/src/main/java/com/jerboa/MainActivity.kt index 835886c80..d0e3ed916 100644 --- a/app/src/main/java/com/jerboa/MainActivity.kt +++ b/app/src/main/java/com/jerboa/MainActivity.kt @@ -46,6 +46,7 @@ import com.jerboa.model.AccountViewModelFactory import com.jerboa.model.AppSettingsViewModel import com.jerboa.model.AppSettingsViewModelFactory import com.jerboa.model.CommunityViewModel +import com.jerboa.model.HomeViewModel import com.jerboa.model.ReplyItem import com.jerboa.model.SiteViewModel import com.jerboa.ui.components.comment.edit.CommentEditActivity @@ -114,6 +115,7 @@ class MainActivity : AppCompatActivity() { viewModel(factory = AppSettingsViewModelFactory.Factory) val accountSettingsViewModel: AccountSettingsViewModel = viewModel(factory = AccountSettingsViewModelFactory.Factory) + val homeViewModel: HomeViewModel = viewModel() API.errorHandler = { Log.e("jerboa", it.toString()) @@ -248,6 +250,7 @@ class MainActivity : AppCompatActivity() { appSettingsViewModel = appSettingsViewModel, appSettings = appSettings, drawerState = drawerState, + homeViewModel = homeViewModel, ) } @@ -508,6 +511,7 @@ class MainActivity : AppCompatActivity() { PostActivity( id = Either.Left(args.id), accountViewModel = accountViewModel, + homeViewModel = homeViewModel, navController = navController, showCollapsedCommentContent = appSettings.showCollapsedCommentContent, showActionBarByDefault = appSettings.showCommentActionBarByDefault, @@ -540,6 +544,7 @@ class MainActivity : AppCompatActivity() { PostActivity( id = Either.Right(args.id), accountViewModel = accountViewModel, + homeViewModel = homeViewModel, navController = navController, useCustomTabs = appSettings.useCustomTabs, usePrivateTabs = appSettings.usePrivateTabs, diff --git a/app/src/main/java/com/jerboa/db/AppDB.kt b/app/src/main/java/com/jerboa/db/AppDB.kt index bf11b0b6c..6e42d89b4 100644 --- a/app/src/main/java/com/jerboa/db/AppDB.kt +++ b/app/src/main/java/com/jerboa/db/AppDB.kt @@ -38,7 +38,7 @@ val APP_SETTINGS_DEFAULT = AppSettings( ) @Database( - version = 19, + version = 20, entities = [Account::class, AppSettings::class], exportSchema = true, ) diff --git a/app/src/main/java/com/jerboa/model/HomeViewModel.kt b/app/src/main/java/com/jerboa/model/HomeViewModel.kt index df0cdb37e..6befd78df 100644 --- a/app/src/main/java/com/jerboa/model/HomeViewModel.kt +++ b/app/src/main/java/com/jerboa/model/HomeViewModel.kt @@ -16,6 +16,8 @@ import com.jerboa.datatypes.types.BlockPerson import com.jerboa.datatypes.types.BlockPersonResponse import com.jerboa.datatypes.types.CreatePostLike import com.jerboa.datatypes.types.DeletePost +import com.jerboa.datatypes.types.GetPost +import com.jerboa.datatypes.types.GetPostResponse import com.jerboa.datatypes.types.GetPosts import com.jerboa.datatypes.types.GetPostsResponse import com.jerboa.datatypes.types.ListingType @@ -39,6 +41,8 @@ class HomeViewModel : ViewModel(), Initializable { var postsRes: ApiState by mutableStateOf(ApiState.Empty) private set + private var postRes: ApiState by mutableStateOf(ApiState.Empty) + private var likePostRes: ApiState by mutableStateOf(ApiState.Empty) private var savePostRes: ApiState by mutableStateOf(ApiState.Empty) private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) @@ -184,6 +188,25 @@ class HomeViewModel : ViewModel(), Initializable { ) } + fun refreshSinglePost(id: Int, account: Account) { + viewModelScope.launch { + val postForm = GetPost(id = id, auth = account.jwt) + postRes = apiWrapper(API.getInstance().getPost(postForm.serializeToMap())) + val refreshedPost = postRes + val existing = postsRes + when { + refreshedPost is ApiState.Success && existing is ApiState.Success -> { + val refreshedPosts = + findAndUpdatePost(existing.data.posts, refreshedPost.data.post_view) + val newPosts = ApiState.Success(existing.data.copy(posts = refreshedPosts)) + postsRes = newPosts + } + + else -> {} + } + } + } + fun updatePost(postView: PostView) { when (val existing = postsRes) { is ApiState.Success -> { diff --git a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt index 69c6fd912..ec65ec83e 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt @@ -1,12 +1,30 @@ package com.jerboa.ui.components.home -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.isImeVisible +import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.* -import androidx.compose.material.icons.outlined.* -import androidx.compose.material3.* -import androidx.compose.runtime.* +import androidx.compose.material.icons.filled.Bookmarks +import androidx.compose.material.icons.filled.Email +import androidx.compose.material.icons.filled.Home +import androidx.compose.material.icons.filled.Person +import androidx.compose.material.icons.filled.Search +import androidx.compose.material.icons.outlined.Bookmarks +import androidx.compose.material.icons.outlined.Email +import androidx.compose.material.icons.outlined.Home +import androidx.compose.material.icons.outlined.Person +import androidx.compose.material.icons.outlined.Search +import androidx.compose.material3.DrawerState +import androidx.compose.material3.ModalDrawerSheet +import androidx.compose.material3.ModalNavigationDrawer +import androidx.compose.material3.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector @@ -14,7 +32,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp -import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable @@ -29,7 +46,10 @@ import com.jerboa.model.AccountViewModel import com.jerboa.model.AppSettingsViewModel import com.jerboa.model.HomeViewModel import com.jerboa.model.SiteViewModel -import com.jerboa.ui.components.common.* +import com.jerboa.ui.components.common.BottomAppBarAll +import com.jerboa.ui.components.common.InitializeRoute +import com.jerboa.ui.components.common.getCurrentAccount +import com.jerboa.ui.components.common.toView import com.jerboa.ui.components.community.list.CommunityListActivity import com.jerboa.ui.components.drawer.MainDrawer import com.jerboa.ui.components.inbox.InboxActivity @@ -88,6 +108,7 @@ fun BottomNavActivity( appSettingsViewModel: AppSettingsViewModel, appSettings: AppSettings, drawerState: DrawerState, + homeViewModel: HomeViewModel, ) { val account = getCurrentAccount(accountViewModel) val ctx = LocalContext.current @@ -107,7 +128,6 @@ fun BottomNavActivity( } } - val homeViewModel: HomeViewModel = viewModel() if (siteViewModel.siteRes is ApiState.Success) { InitializeRoute(homeViewModel) { homeViewModel.updateSortType(siteViewModel.sortType) diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 2814b9b78..b5413667e 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -78,6 +78,7 @@ import com.jerboa.isLoading import com.jerboa.isModerator import com.jerboa.isRefreshing import com.jerboa.model.AccountViewModel +import com.jerboa.model.HomeViewModel import com.jerboa.model.PostViewModel import com.jerboa.model.ReplyItem import com.jerboa.model.SiteViewModel @@ -140,6 +141,7 @@ fun PostActivity( id: Either, siteViewModel: SiteViewModel, accountViewModel: AccountViewModel, + homeViewModel: HomeViewModel, navController: NavController, useCustomTabs: Boolean, usePrivateTabs: Boolean, @@ -177,15 +179,18 @@ fun PostActivity( InitializeRoute(postViewModel) { postViewModel.initialize(id = id) postViewModel.getData(account) - id.fold({ - postViewModel.markPostAsRead( - MarkPostAsRead( - post_id = it, - read = true, - auth = account!!.jwt, - ), - ) - }, {}) + account?.also { + id.fold({ + postViewModel.markPostAsRead( + MarkPostAsRead( + post_id = it, + read = true, + auth = account.jwt, + ), + ) + homeViewModel.refreshSinglePost(it, account) + }, {}) + } } val onClickSortType = { commentSortType: CommentSortType -> @@ -343,9 +348,8 @@ fun PostActivity( auth = acct.jwt, ), ) + homeViewModel.refreshSinglePost(pv.post.id, account) } - // TODO will need to pass in postlistingsviewmodel - // for the Home page to also be updated }, onDownvoteClick = { pv -> account?.also { acct -> @@ -359,6 +363,7 @@ fun PostActivity( auth = acct.jwt, ), ) + homeViewModel.refreshSinglePost(pv.post.id, account) } }, onReplyClick = { pv -> @@ -380,6 +385,7 @@ fun PostActivity( auth = acct.jwt, ), ) + homeViewModel.refreshSinglePost(pv.post.id, account) } }, onCommunityClick = { community -> @@ -400,6 +406,7 @@ fun PostActivity( auth = acct.jwt, ), ) + homeViewModel.refreshSinglePost(pv.post.id, account) } }, onReportClick = { pv -> @@ -614,7 +621,6 @@ fun PostActivity( postViewModel.fetchMoreChildren( commentView = cv, account = account, - ) }, onBlockCreatorClick = { person -> From 6dab5b68cf41960486c322a63a88e3d2d458b5c6 Mon Sep 17 00:00:00 2001 From: ZJouba Date: Thu, 20 Jul 2023 12:22:41 +0200 Subject: [PATCH 06/17] Updates and merge conflict fixes --- app/src/main/java/com/jerboa/MainActivity.kt | 11 +--- app/src/main/java/com/jerboa/db/AppDB.kt | 2 +- .../java/com/jerboa/db/AppDBMigrations.kt | 2 +- .../com/jerboa/model/CommunityViewModel.kt | 25 ++++++++- .../java/com/jerboa/model/HomeViewModel.kt | 1 + .../jerboa/model/PersonProfileViewModel.kt | 51 ++++++++++++++++++- .../java/com/jerboa/model/PostViewModel.kt | 4 +- .../components/community/CommunityActivity.kt | 5 ++ .../ui/components/home/BottomNavActivity.kt | 3 +- .../jerboa/ui/components/home/HomeActivity.kt | 5 ++ .../person/PersonProfileActivity.kt | 5 ++ .../jerboa/ui/components/post/PostActivity.kt | 15 +++--- .../jerboa/ui/components/post/PostListings.kt | 15 ++++-- .../lookandfeel/LookAndFeelActivity.kt | 14 ++--- 14 files changed, 121 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/com/jerboa/MainActivity.kt b/app/src/main/java/com/jerboa/MainActivity.kt index 040dfb7b8..b0a2a69d7 100644 --- a/app/src/main/java/com/jerboa/MainActivity.kt +++ b/app/src/main/java/com/jerboa/MainActivity.kt @@ -46,7 +46,6 @@ import com.jerboa.model.AccountViewModelFactory import com.jerboa.model.AppSettingsViewModel import com.jerboa.model.AppSettingsViewModelFactory import com.jerboa.model.CommunityViewModel -import com.jerboa.model.HomeViewModel import com.jerboa.model.ReplyItem import com.jerboa.model.SiteViewModel import com.jerboa.ui.components.comment.edit.CommentEditActivity @@ -109,13 +108,10 @@ class MainActivity : AppCompatActivity() { setContent { val ctx = LocalContext.current - val accountViewModel: AccountViewModel = - viewModel(factory = AccountViewModelFactory.Factory) - val appSettingsViewModel: AppSettingsViewModel = - viewModel(factory = AppSettingsViewModelFactory.Factory) + val accountViewModel: AccountViewModel = viewModel(factory = AccountViewModelFactory.Factory) + val appSettingsViewModel: AppSettingsViewModel = viewModel(factory = AppSettingsViewModelFactory.Factory) val accountSettingsViewModel: AccountSettingsViewModel = viewModel(factory = AccountSettingsViewModelFactory.Factory) - val homeViewModel: HomeViewModel = viewModel() API.errorHandler = { Log.e("jerboa", it.toString()) @@ -255,7 +251,6 @@ class MainActivity : AppCompatActivity() { appSettingsViewModel = appSettingsViewModel, appSettings = appSettings, drawerState = drawerState, - homeViewModel = homeViewModel, ) } @@ -516,7 +511,6 @@ class MainActivity : AppCompatActivity() { PostActivity( id = Either.Left(args.id), accountViewModel = accountViewModel, - homeViewModel = homeViewModel, navController = navController, showCollapsedCommentContent = appSettings.showCollapsedCommentContent, showActionBarByDefault = appSettings.showCommentActionBarByDefault, @@ -549,7 +543,6 @@ class MainActivity : AppCompatActivity() { PostActivity( id = Either.Right(args.id), accountViewModel = accountViewModel, - homeViewModel = homeViewModel, navController = navController, useCustomTabs = appSettings.useCustomTabs, usePrivateTabs = appSettings.usePrivateTabs, diff --git a/app/src/main/java/com/jerboa/db/AppDB.kt b/app/src/main/java/com/jerboa/db/AppDB.kt index 6e42d89b4..331c441a9 100644 --- a/app/src/main/java/com/jerboa/db/AppDB.kt +++ b/app/src/main/java/com/jerboa/db/AppDB.kt @@ -38,7 +38,7 @@ val APP_SETTINGS_DEFAULT = AppSettings( ) @Database( - version = 20, + version = 21, entities = [Account::class, AppSettings::class], exportSchema = true, ) diff --git a/app/src/main/java/com/jerboa/db/AppDBMigrations.kt b/app/src/main/java/com/jerboa/db/AppDBMigrations.kt index 4a882bdf8..9b77d5a8f 100644 --- a/app/src/main/java/com/jerboa/db/AppDBMigrations.kt +++ b/app/src/main/java/com/jerboa/db/AppDBMigrations.kt @@ -261,7 +261,7 @@ val MIGRATION_19_20 = object : Migration(19, 20) { } } -val MIGRATION_20_21 = object : Migration(19, 20) { +val MIGRATION_20_21 = object : Migration(20, 21) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED) database.execSQL( diff --git a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt index 8ace1c02c..ec6fa49f7 100644 --- a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt +++ b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt @@ -7,11 +7,32 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.jerboa.* import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper -import com.jerboa.datatypes.types.* +import com.jerboa.datatypes.types.BlockCommunity +import com.jerboa.datatypes.types.BlockCommunityResponse +import com.jerboa.datatypes.types.BlockPerson +import com.jerboa.datatypes.types.BlockPersonResponse +import com.jerboa.datatypes.types.CommunityId +import com.jerboa.datatypes.types.CommunityResponse +import com.jerboa.datatypes.types.CreatePostLike +import com.jerboa.datatypes.types.DeletePost +import com.jerboa.datatypes.types.FollowCommunity +import com.jerboa.datatypes.types.GetCommunity +import com.jerboa.datatypes.types.GetCommunityResponse +import com.jerboa.datatypes.types.GetPosts +import com.jerboa.datatypes.types.GetPostsResponse +import com.jerboa.datatypes.types.MarkPostAsRead +import com.jerboa.datatypes.types.PostResponse +import com.jerboa.datatypes.types.PostView +import com.jerboa.datatypes.types.SavePost +import com.jerboa.datatypes.types.SortType +import com.jerboa.findAndUpdatePost +import com.jerboa.mergePosts +import com.jerboa.serializeToMap +import com.jerboa.showBlockCommunityToast +import com.jerboa.showBlockPersonToast import com.jerboa.ui.components.common.Initializable import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/jerboa/model/HomeViewModel.kt b/app/src/main/java/com/jerboa/model/HomeViewModel.kt index 6befd78df..c6e08ff14 100644 --- a/app/src/main/java/com/jerboa/model/HomeViewModel.kt +++ b/app/src/main/java/com/jerboa/model/HomeViewModel.kt @@ -196,6 +196,7 @@ class HomeViewModel : ViewModel(), Initializable { val existing = postsRes when { refreshedPost is ApiState.Success && existing is ApiState.Success -> { + postsRes = ApiState.Loading val refreshedPosts = findAndUpdatePost(existing.data.posts, refreshedPost.data.post_view) val newPosts = ApiState.Success(existing.data.copy(posts = refreshedPosts)) diff --git a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt index 75a48deff..c86886f55 100644 --- a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt @@ -7,11 +7,36 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.jerboa.* import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper -import com.jerboa.datatypes.types.* +import com.jerboa.datatypes.types.BlockCommunity +import com.jerboa.datatypes.types.BlockCommunityResponse +import com.jerboa.datatypes.types.BlockPerson +import com.jerboa.datatypes.types.BlockPersonResponse +import com.jerboa.datatypes.types.CommentResponse +import com.jerboa.datatypes.types.CommentView +import com.jerboa.datatypes.types.CreateCommentLike +import com.jerboa.datatypes.types.CreatePostLike +import com.jerboa.datatypes.types.DeleteComment +import com.jerboa.datatypes.types.DeletePost +import com.jerboa.datatypes.types.GetPersonDetails +import com.jerboa.datatypes.types.GetPersonDetailsResponse +import com.jerboa.datatypes.types.GetPost +import com.jerboa.datatypes.types.GetPostResponse +import com.jerboa.datatypes.types.MarkPostAsRead +import com.jerboa.datatypes.types.PersonId +import com.jerboa.datatypes.types.PostResponse +import com.jerboa.datatypes.types.PostView +import com.jerboa.datatypes.types.SaveComment +import com.jerboa.datatypes.types.SavePost +import com.jerboa.datatypes.types.SortType +import com.jerboa.db.entity.Account +import com.jerboa.findAndUpdateComment +import com.jerboa.findAndUpdatePost +import com.jerboa.serializeToMap +import com.jerboa.showBlockCommunityToast +import com.jerboa.showBlockPersonToast import com.jerboa.ui.components.common.Initializable import kotlinx.coroutines.launch @@ -23,6 +48,8 @@ class PersonProfileViewModel : ViewModel(), Initializable { ) private set + private var postRes: ApiState by mutableStateOf(ApiState.Empty) + private var likePostRes: ApiState by mutableStateOf(ApiState.Empty) private var savePostRes: ApiState by mutableStateOf(ApiState.Empty) private var deletePostRes: ApiState by mutableStateOf(ApiState.Empty) @@ -284,4 +311,24 @@ class PersonProfileViewModel : ViewModel(), Initializable { } } } + + fun refreshSinglePost(id: Int, account: Account) { + viewModelScope.launch { + val postForm = GetPost(id = id, auth = account.jwt) + postRes = apiWrapper(API.getInstance().getPost(postForm.serializeToMap())) + val refreshedPost = postRes + val existing = personDetailsRes + when { + refreshedPost is ApiState.Success && existing is ApiState.Success -> { + personDetailsRes = ApiState.Loading + val refreshedPosts = + findAndUpdatePost(existing.data.posts, refreshedPost.data.post_view) + val newPosts = ApiState.Success(existing.data.copy(posts = refreshedPosts)) + personDetailsRes = newPosts + } + + else -> {} + } + } + } } diff --git a/app/src/main/java/com/jerboa/model/PostViewModel.kt b/app/src/main/java/com/jerboa/model/PostViewModel.kt index 4e4b37225..d7db29f8c 100644 --- a/app/src/main/java/com/jerboa/model/PostViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PostViewModel.kt @@ -311,7 +311,9 @@ class PostViewModel : ViewModel(), Initializable { } } - fun markPostAsRead(form: MarkPostAsRead) { + fun markPostAsRead( + form: MarkPostAsRead, + ) { viewModelScope.launch { markPostRes = ApiState.Loading markPostRes = apiWrapper(API.getInstance().markAsRead(form)) diff --git a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt index 413bafde1..d95f68904 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt @@ -75,6 +75,7 @@ import com.jerboa.ui.components.common.toPostReport import com.jerboa.ui.components.common.toProfile import com.jerboa.ui.components.common.toView import com.jerboa.ui.components.post.PostListings +import com.jerboa.ui.components.post.PostViewReturn import com.jerboa.ui.components.post.edit.PostEditReturn import kotlinx.collections.immutable.toImmutableList @@ -108,6 +109,10 @@ fun CommunityActivity( if (communityViewModel.initialized) communityViewModel.updatePost(pv) } + navController.ConsumeReturn(PostViewReturn.POST_VIEW) { pv -> + if (communityViewModel.initialized) communityViewModel.updatePost(pv) + } + InitializeRoute(communityViewModel) { val communityId = communityArg.fold({ it }, { null }) val communityName = communityArg.fold({ null }, { it }) diff --git a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt index ec65ec83e..d494a093e 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/BottomNavActivity.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.unit.dp +import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable @@ -108,7 +109,6 @@ fun BottomNavActivity( appSettingsViewModel: AppSettingsViewModel, appSettings: AppSettings, drawerState: DrawerState, - homeViewModel: HomeViewModel, ) { val account = getCurrentAccount(accountViewModel) val ctx = LocalContext.current @@ -128,6 +128,7 @@ fun BottomNavActivity( } } + val homeViewModel: HomeViewModel = viewModel() if (siteViewModel.siteRes is ApiState.Success) { InitializeRoute(homeViewModel) { homeViewModel.updateSortType(siteViewModel.sortType) diff --git a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt index f40cb278a..cb5de8c63 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt @@ -79,6 +79,7 @@ import com.jerboa.ui.components.common.toPostReport import com.jerboa.ui.components.common.toProfile import com.jerboa.ui.components.common.toView import com.jerboa.ui.components.post.PostListings +import com.jerboa.ui.components.post.PostViewReturn import com.jerboa.ui.components.post.edit.PostEditReturn import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -113,6 +114,10 @@ fun HomeActivity( if (homeViewModel.initialized) homeViewModel.updatePost(pv) } + navController.ConsumeReturn(PostViewReturn.POST_VIEW) { id -> + if (homeViewModel.initialized) account?.also { homeViewModel.refreshSinglePost(id, account) } + } + Scaffold( modifier = Modifier .nestedScroll(scrollBehavior.nestedScrollConnection) diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index 806de968d..a375b2ad6 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -83,6 +83,7 @@ import com.jerboa.ui.components.common.toPostReport import com.jerboa.ui.components.common.toProfile import com.jerboa.ui.components.community.CommunityLink import com.jerboa.ui.components.post.PostListings +import com.jerboa.ui.components.post.PostViewReturn import com.jerboa.ui.components.post.edit.PostEditReturn import com.jerboa.ui.theme.MEDIUM_PADDING import kotlinx.collections.immutable.toImmutableList @@ -302,6 +303,10 @@ fun UserTabs( val loading = personProfileViewModel.personDetailsRes.isLoading() + navController.ConsumeReturn(PostViewReturn.POST_VIEW) { id -> + if (personProfileViewModel.initialized) account?.also { personProfileViewModel.refreshSinglePost(id, account) } + } + val pullRefreshState = rememberPullRefreshState( refreshing = personProfileViewModel.personDetailsRes.isRefreshing(), onRefresh = { diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index b5413667e..7f0094393 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -78,7 +78,6 @@ import com.jerboa.isLoading import com.jerboa.isModerator import com.jerboa.isRefreshing import com.jerboa.model.AccountViewModel -import com.jerboa.model.HomeViewModel import com.jerboa.model.PostViewModel import com.jerboa.model.ReplyItem import com.jerboa.model.SiteViewModel @@ -99,6 +98,7 @@ import com.jerboa.ui.components.common.ConsumeReturn import com.jerboa.ui.components.common.InitializeRoute import com.jerboa.ui.components.common.LoadingBar import com.jerboa.ui.components.common.PostEditDeps +import com.jerboa.ui.components.common.addReturn import com.jerboa.ui.components.common.getCurrentAccount import com.jerboa.ui.components.common.rootChannel import com.jerboa.ui.components.common.simpleVerticalScrollbar @@ -113,6 +113,10 @@ import com.jerboa.ui.components.common.toPostReport import com.jerboa.ui.components.common.toProfile import com.jerboa.ui.components.post.edit.PostEditReturn +object PostViewReturn { + const val POST_VIEW = "post-view::return(post-view)" +} + @Composable fun CommentsHeaderTitle( selectedSortType: CommentSortType, @@ -141,7 +145,6 @@ fun PostActivity( id: Either, siteViewModel: SiteViewModel, accountViewModel: AccountViewModel, - homeViewModel: HomeViewModel, navController: NavController, useCustomTabs: Boolean, usePrivateTabs: Boolean, @@ -188,7 +191,9 @@ fun PostActivity( auth = account.jwt, ), ) - homeViewModel.refreshSinglePost(it, account) + navController.apply { + addReturn(PostViewReturn.POST_VIEW, it) + } }, {}) } } @@ -348,7 +353,6 @@ fun PostActivity( auth = acct.jwt, ), ) - homeViewModel.refreshSinglePost(pv.post.id, account) } }, onDownvoteClick = { pv -> @@ -363,7 +367,6 @@ fun PostActivity( auth = acct.jwt, ), ) - homeViewModel.refreshSinglePost(pv.post.id, account) } }, onReplyClick = { pv -> @@ -385,7 +388,6 @@ fun PostActivity( auth = acct.jwt, ), ) - homeViewModel.refreshSinglePost(pv.post.id, account) } }, onCommunityClick = { community -> @@ -406,7 +408,6 @@ fun PostActivity( auth = acct.jwt, ), ) - homeViewModel.refreshSinglePost(pv.post.id, account) } }, onReportClick = { pv -> diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt index 47c708288..10d7798f0 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostListings.kt @@ -3,9 +3,17 @@ package com.jerboa.ui.components.post import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.lazy.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListState +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.Divider -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.derivedStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.tooling.preview.Preview @@ -22,11 +30,12 @@ import com.jerboa.db.entity.Account import com.jerboa.isScrolledToEnd import com.jerboa.ui.components.common.simpleVerticalScrollbar import com.jerboa.ui.theme.SMALL_PADDING +import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @Composable fun PostListings( - posts: List, + posts: ImmutableList, contentAboveListings: @Composable () -> Unit = {}, onUpvoteClick: (postView: PostView) -> Unit, onDownvoteClick: (postView: PostView) -> Unit, diff --git a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt index 0e3f7e692..042156ec7 100644 --- a/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/settings/lookandfeel/LookAndFeelActivity.kt @@ -71,16 +71,10 @@ fun LookAndFeelActivity( ) val postViewModeState = rememberIntSettingState(settings.postViewMode) val showBottomNavState = rememberBooleanSettingState(settings.showBottomNav) - val showTextDescriptionsInNavbar = - rememberBooleanSettingState(settings.showTextDescriptionsInNavbar) - val showCollapsedCommentContentState = - rememberBooleanSettingState(settings.showCollapsedCommentContent) - val showCommentActionBarByDefaultState = rememberBooleanSettingState( - settings.showCommentActionBarByDefault, - ) - val showVotingArrowsInListViewState = rememberBooleanSettingState( - settings.showVotingArrowsInListView, - ) + val showTextDescriptionsInNavbar = rememberBooleanSettingState(settings.showTextDescriptionsInNavbar) + val showCollapsedCommentContentState = rememberBooleanSettingState(settings.showCollapsedCommentContent) + val showCommentActionBarByDefaultState = rememberBooleanSettingState(settings.showCommentActionBarByDefault) + val showVotingArrowsInListViewState = rememberBooleanSettingState(settings.showVotingArrowsInListView) val showParentCommentNavigationButtonsState = rememberBooleanSettingState( settings.showParentCommentNavigationButtons, ) From ccd7f46916de9aaacb20306664046eb474573b6d Mon Sep 17 00:00:00 2001 From: ZJouba Date: Thu, 27 Jul 2023 10:44:06 +0200 Subject: [PATCH 07/17] Check if read first and use appState to launch coroutine --- app/schemas/com.jerboa.db.AppDB/22.json | 225 ++++++++++++++++++ .../com/jerboa/model/CommunityViewModel.kt | 8 +- .../java/com/jerboa/model/HomeViewModel.kt | 8 +- .../jerboa/model/PersonProfileViewModel.kt | 8 +- .../java/com/jerboa/model/PostViewModel.kt | 4 +- .../components/community/CommunityActivity.kt | 19 +- .../jerboa/ui/components/home/HomeActivity.kt | 23 +- .../person/PersonProfileActivity.kt | 23 +- .../jerboa/ui/components/post/PostActivity.kt | 27 +-- 9 files changed, 296 insertions(+), 49 deletions(-) create mode 100644 app/schemas/com.jerboa.db.AppDB/22.json diff --git a/app/schemas/com.jerboa.db.AppDB/22.json b/app/schemas/com.jerboa.db.AppDB/22.json new file mode 100644 index 000000000..27fe777cc --- /dev/null +++ b/app/schemas/com.jerboa.db.AppDB/22.json @@ -0,0 +1,225 @@ +{ + "formatVersion": 1, + "database": { + "version": 22, + "identityHash": "f3a3575e455688bfe70df71ffcd95522", + "entities": [ + { + "tableName": "Account", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `current` INTEGER NOT NULL, `instance` TEXT NOT NULL, `name` TEXT NOT NULL, `jwt` TEXT NOT NULL, `default_listing_type` INTEGER NOT NULL DEFAULT 0, `default_sort_type` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "current", + "columnName": "current", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "instance", + "columnName": "instance", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "jwt", + "columnName": "jwt", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "defaultListingType", + "columnName": "default_listing_type", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "defaultSortType", + "columnName": "default_sort_type", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "AppSettings", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `font_size` INTEGER NOT NULL DEFAULT 16, `theme` INTEGER NOT NULL DEFAULT 0, `theme_color` INTEGER NOT NULL DEFAULT 0, `viewed_changelog` INTEGER NOT NULL DEFAULT 0, `post_view_mode` INTEGER NOT NULL DEFAULT 0, `show_bottom_nav` INTEGER NOT NULL DEFAULT 1, `show_collapsed_comment_content` INTEGER NOT NULL DEFAULT 0, `show_comment_action_bar_by_default` INTEGER NOT NULL DEFAULT 1, `show_voting_arrows_in_list_view` INTEGER NOT NULL DEFAULT 1, `show_parent_comment_navigation_buttons` INTEGER NOT NULL DEFAULT 0, `navigate_parent_comments_with_volume_buttons` INTEGER NOT NULL DEFAULT 0, `use_custom_tabs` INTEGER NOT NULL DEFAULT 1, `use_private_tabs` INTEGER NOT NULL DEFAULT 0, `secure_window` INTEGER NOT NULL DEFAULT 0, `blur_nsfw` INTEGER NOT NULL DEFAULT 1, `show_text_descriptions_in_navbar` INTEGER NOT NULL DEFAULT 1, `markAsReadOnScroll` INTEGER NOT NULL DEFAULT 0, `backConfirmationMode` INTEGER NOT NULL DEFAULT 1, `show_post_link_previews` INTEGER NOT NULL DEFAULT 1)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "fontSize", + "columnName": "font_size", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "16" + }, + { + "fieldPath": "theme", + "columnName": "theme", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "themeColor", + "columnName": "theme_color", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "viewedChangelog", + "columnName": "viewed_changelog", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "postViewMode", + "columnName": "post_view_mode", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "showBottomNav", + "columnName": "show_bottom_nav", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showCollapsedCommentContent", + "columnName": "show_collapsed_comment_content", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "showCommentActionBarByDefault", + "columnName": "show_comment_action_bar_by_default", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showVotingArrowsInListView", + "columnName": "show_voting_arrows_in_list_view", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showParentCommentNavigationButtons", + "columnName": "show_parent_comment_navigation_buttons", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "navigateParentCommentsWithVolumeButtons", + "columnName": "navigate_parent_comments_with_volume_buttons", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "useCustomTabs", + "columnName": "use_custom_tabs", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "usePrivateTabs", + "columnName": "use_private_tabs", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "secureWindow", + "columnName": "secure_window", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "blurNSFW", + "columnName": "blur_nsfw", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showTextDescriptionsInNavbar", + "columnName": "show_text_descriptions_in_navbar", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "markAsReadOnScroll", + "columnName": "markAsReadOnScroll", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "backConfirmationMode", + "columnName": "backConfirmationMode", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showPostLinkPreviews", + "columnName": "show_post_link_previews", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'f3a3575e455688bfe70df71ffcd95522')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt index a18f5577d..d02b8965c 100644 --- a/app/src/main/java/com/jerboa/model/CommunityViewModel.kt +++ b/app/src/main/java/com/jerboa/model/CommunityViewModel.kt @@ -7,6 +7,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.jerboa.JerboaAppState import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper @@ -258,8 +259,11 @@ class CommunityViewModel : ViewModel(), Initializable { } } - fun markPostAsRead(form: MarkPostAsRead) { - viewModelScope.launch { + fun markPostAsRead( + form: MarkPostAsRead, + appState: JerboaAppState, + ) { + appState.coroutineScope.launch { markPostRes = ApiState.Loading markPostRes = apiWrapper(API.getInstance().markAsRead(form)) diff --git a/app/src/main/java/com/jerboa/model/HomeViewModel.kt b/app/src/main/java/com/jerboa/model/HomeViewModel.kt index 369304f97..1553835cd 100644 --- a/app/src/main/java/com/jerboa/model/HomeViewModel.kt +++ b/app/src/main/java/com/jerboa/model/HomeViewModel.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.jerboa.JerboaAppState import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper @@ -257,8 +258,11 @@ class HomeViewModel : ViewModel(), Initializable { ) } - fun markPostAsRead(form: MarkPostAsRead) { - viewModelScope.launch { + fun markPostAsRead( + form: MarkPostAsRead, + appState: JerboaAppState, + ) { + appState.coroutineScope.launch { markPostRes = ApiState.Loading markPostRes = apiWrapper(API.getInstance().markAsRead(form)) diff --git a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt index dd4085f63..ed440de91 100644 --- a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt @@ -7,6 +7,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.jerboa.JerboaAppState import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper @@ -297,8 +298,11 @@ class PersonProfileViewModel : ViewModel(), Initializable { } } - fun markPostAsRead(form: MarkPostAsRead) { - viewModelScope.launch { + fun markPostAsRead( + form: MarkPostAsRead, + appState: JerboaAppState, + ) { + appState.coroutineScope.launch { markPostRes = ApiState.Loading markPostRes = apiWrapper(API.getInstance().markAsRead(form)) diff --git a/app/src/main/java/com/jerboa/model/PostViewModel.kt b/app/src/main/java/com/jerboa/model/PostViewModel.kt index 5729bffda..8f1a27c9a 100644 --- a/app/src/main/java/com/jerboa/model/PostViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PostViewModel.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import arrow.core.Either +import com.jerboa.JerboaAppState import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper @@ -317,8 +318,9 @@ class PostViewModel : ViewModel(), Initializable { fun markPostAsRead( form: MarkPostAsRead, + appState: JerboaAppState, ) { - viewModelScope.launch { + appState.coroutineScope.launch { markPostRes = ApiState.Loading markPostRes = apiWrapper(API.getInstance().markAsRead(form)) diff --git a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt index 04fa96468..846d3d6b2 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt @@ -404,14 +404,17 @@ fun CommunityActivity( openLink = appState::openLink, markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { postView -> - account?.also { acct -> - communityViewModel.markPostAsRead( - MarkPostAsRead( - post_id = postView.post.id, - read = true, - auth = acct.jwt, - ), - ) + if (!postView.read) { + account?.also { acct -> + communityViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, + auth = acct.jwt, + ), + appState, + ) + } } }, showIfRead = true, diff --git a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt index db7798167..65cce316b 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt @@ -107,8 +107,8 @@ fun HomeActivity( if (homeViewModel.initialized) homeViewModel.updatePost(pv) } - appState.ConsumeReturn(PostViewReturn.POST_VIEW) { id -> - if (homeViewModel.initialized) account?.also { homeViewModel.refreshSinglePost(id, account) } + appState.ConsumeReturn(PostViewReturn.POST_VIEW) { pv -> + if (homeViewModel.initialized) homeViewModel.updatePost(pv) } Scaffold( @@ -355,14 +355,17 @@ fun MainPostListingsContent( openLink = appState::openLink, markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { postView -> - account?.also { acct -> - homeViewModel.markPostAsRead( - MarkPostAsRead( - post_id = postView.post.id, - read = true, - auth = acct.jwt, - ), - ) + if (!postView.read) { + account?.also { acct -> + homeViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, + auth = acct.jwt, + ), + appState, + ) + } } }, showIfRead = true, diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index 9db0b1a5e..d55873c34 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -315,8 +315,8 @@ fun UserTabs( val loading = personProfileViewModel.personDetailsRes.isLoading() - appState.ConsumeReturn(PostViewReturn.POST_VIEW) { id -> - if (personProfileViewModel.initialized) account?.also { personProfileViewModel.refreshSinglePost(id, account) } + appState.ConsumeReturn(PostViewReturn.POST_VIEW) { pv -> + if (personProfileViewModel.initialized) personProfileViewModel.updatePost(pv) } val pullRefreshState = rememberPullRefreshState( @@ -568,14 +568,17 @@ fun UserTabs( showPostLinkPreviews = showPostLinkPreviews, markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { - account?.also { acct -> - personProfileViewModel.markPostAsRead( - MarkPostAsRead( - post_id = it.post.id, - read = true, - auth = acct.jwt, - ), - ) + if (!it.read) { + account?.also { acct -> + personProfileViewModel.markPostAsRead( + MarkPostAsRead( + post_id = it.post.id, + read = true, + auth = acct.jwt, + ), + appState, + ) + } } }, showIfRead = false, diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 3bbaef6bc..c638b1097 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -172,20 +172,6 @@ fun PostActivity( InitializeRoute(postViewModel) { postViewModel.initialize(id = id) postViewModel.getData(account) - account?.also { - id.fold({ - postViewModel.markPostAsRead( - MarkPostAsRead( - post_id = it, - read = true, - auth = account.jwt, - ), - ) - appState.apply { - addReturn(PostViewReturn.POST_VIEW, it) - } - }, {}) - } } val onClickSortType = { commentSortType: CommentSortType -> @@ -319,6 +305,19 @@ fun PostActivity( is ApiState.Failure -> ApiErrorText(postRes.msg) is ApiState.Success -> { val postView = postRes.data.post_view + account?.also { _ -> + if (!postView.read) { + appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) + postViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, + auth = account.jwt, + ), + appState, + ) + } + } LazyColumn( state = listState, From 7d6c6d895b582dd7f3748bd2bd9c46d593135d4d Mon Sep 17 00:00:00 2001 From: ZJouba Date: Thu, 27 Jul 2023 10:51:33 +0200 Subject: [PATCH 08/17] Adding back migration --- app/schemas/com.jerboa.db.AppDB/21.json | 218 ++++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 app/schemas/com.jerboa.db.AppDB/21.json diff --git a/app/schemas/com.jerboa.db.AppDB/21.json b/app/schemas/com.jerboa.db.AppDB/21.json new file mode 100644 index 000000000..796bac568 --- /dev/null +++ b/app/schemas/com.jerboa.db.AppDB/21.json @@ -0,0 +1,218 @@ +{ + "formatVersion": 1, + "database": { + "version": 21, + "identityHash": "57b5a9e25468cc9029f803df34415820", + "entities": [ + { + "tableName": "Account", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `current` INTEGER NOT NULL, `instance` TEXT NOT NULL, `name` TEXT NOT NULL, `jwt` TEXT NOT NULL, `default_listing_type` INTEGER NOT NULL DEFAULT 0, `default_sort_type` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "current", + "columnName": "current", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "instance", + "columnName": "instance", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "jwt", + "columnName": "jwt", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "defaultListingType", + "columnName": "default_listing_type", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "defaultSortType", + "columnName": "default_sort_type", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "AppSettings", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `font_size` INTEGER NOT NULL DEFAULT 16, `theme` INTEGER NOT NULL DEFAULT 0, `theme_color` INTEGER NOT NULL DEFAULT 0, `viewed_changelog` INTEGER NOT NULL DEFAULT 0, `post_view_mode` INTEGER NOT NULL DEFAULT 0, `show_bottom_nav` INTEGER NOT NULL DEFAULT 1, `show_collapsed_comment_content` INTEGER NOT NULL DEFAULT 0, `show_comment_action_bar_by_default` INTEGER NOT NULL DEFAULT 1, `show_voting_arrows_in_list_view` INTEGER NOT NULL DEFAULT 1, `show_parent_comment_navigation_buttons` INTEGER NOT NULL DEFAULT 0, `navigate_parent_comments_with_volume_buttons` INTEGER NOT NULL DEFAULT 0, `use_custom_tabs` INTEGER NOT NULL DEFAULT 1, `use_private_tabs` INTEGER NOT NULL DEFAULT 0, `secure_window` INTEGER NOT NULL DEFAULT 0, `blur_nsfw` INTEGER NOT NULL DEFAULT 1, `show_text_descriptions_in_navbar` INTEGER NOT NULL DEFAULT 1, `backConfirmationMode` INTEGER NOT NULL DEFAULT 1, `show_post_link_previews` INTEGER NOT NULL DEFAULT 1)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "fontSize", + "columnName": "font_size", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "16" + }, + { + "fieldPath": "theme", + "columnName": "theme", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "themeColor", + "columnName": "theme_color", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "viewedChangelog", + "columnName": "viewed_changelog", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "postViewMode", + "columnName": "post_view_mode", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "showBottomNav", + "columnName": "show_bottom_nav", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showCollapsedCommentContent", + "columnName": "show_collapsed_comment_content", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "showCommentActionBarByDefault", + "columnName": "show_comment_action_bar_by_default", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showVotingArrowsInListView", + "columnName": "show_voting_arrows_in_list_view", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showParentCommentNavigationButtons", + "columnName": "show_parent_comment_navigation_buttons", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "navigateParentCommentsWithVolumeButtons", + "columnName": "navigate_parent_comments_with_volume_buttons", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "useCustomTabs", + "columnName": "use_custom_tabs", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "usePrivateTabs", + "columnName": "use_private_tabs", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "secureWindow", + "columnName": "secure_window", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "blurNSFW", + "columnName": "blur_nsfw", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showTextDescriptionsInNavbar", + "columnName": "show_text_descriptions_in_navbar", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "backConfirmationMode", + "columnName": "backConfirmationMode", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showPostLinkPreviews", + "columnName": "show_post_link_previews", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '57b5a9e25468cc9029f803df34415820')" + ] + } +} \ No newline at end of file From 1083197c5c6b49e32f8cb6394c153a83e697b30a Mon Sep 17 00:00:00 2001 From: ZJouba Date: Thu, 27 Jul 2023 10:52:35 +0200 Subject: [PATCH 09/17] Removing dev --- app/src/main/java/com/jerboa/api/Http.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/jerboa/api/Http.kt b/app/src/main/java/com/jerboa/api/Http.kt index ba4b22b2e..e3cd8f890 100644 --- a/app/src/main/java/com/jerboa/api/Http.kt +++ b/app/src/main/java/com/jerboa/api/Http.kt @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit import okhttp3.Response as HttpResponse const val VERSION = "v3" -const val DEFAULT_INSTANCE = "voyager.lemmy.ml" +const val DEFAULT_INSTANCE = "lemmy.ml" const val MINIMUM_API_VERSION: String = "0.18" val REDACTED_QUERY_PARAMS = setOf("auth") val REDACTED_BODY_FIELDS = setOf("jwt", "password", "auth") From 29dd4804ef3fda9f97829a40b33ef8695d994840 Mon Sep 17 00:00:00 2001 From: ZJouba Date: Fri, 28 Jul 2023 10:03:41 +0200 Subject: [PATCH 10/17] Removing unused functions --- .../java/com/jerboa/model/HomeViewModel.kt | 21 ------------------ .../jerboa/model/PersonProfileViewModel.kt | 22 ------------------- 2 files changed, 43 deletions(-) diff --git a/app/src/main/java/com/jerboa/model/HomeViewModel.kt b/app/src/main/java/com/jerboa/model/HomeViewModel.kt index 1553835cd..76708edf4 100644 --- a/app/src/main/java/com/jerboa/model/HomeViewModel.kt +++ b/app/src/main/java/com/jerboa/model/HomeViewModel.kt @@ -18,7 +18,6 @@ import com.jerboa.datatypes.types.BlockPerson import com.jerboa.datatypes.types.BlockPersonResponse import com.jerboa.datatypes.types.CreatePostLike import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.GetPost import com.jerboa.datatypes.types.GetPostResponse import com.jerboa.datatypes.types.GetPosts import com.jerboa.datatypes.types.GetPostsResponse @@ -192,26 +191,6 @@ class HomeViewModel : ViewModel(), Initializable { ) } - fun refreshSinglePost(id: Int, account: Account) { - viewModelScope.launch { - val postForm = GetPost(id = id, auth = account.jwt) - postRes = apiWrapper(API.getInstance().getPost(postForm.serializeToMap())) - val refreshedPost = postRes - val existing = postsRes - when { - refreshedPost is ApiState.Success && existing is ApiState.Success -> { - postsRes = ApiState.Loading - val refreshedPosts = - findAndUpdatePost(existing.data.posts, refreshedPost.data.post_view) - val newPosts = ApiState.Success(existing.data.copy(posts = refreshedPosts)) - postsRes = newPosts - } - - else -> {} - } - } - } - fun updatePost(postView: PostView) { when (val existing = postsRes) { is ApiState.Success -> { diff --git a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt index ed440de91..0a5f7b1f4 100644 --- a/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PersonProfileViewModel.kt @@ -23,7 +23,6 @@ import com.jerboa.datatypes.types.DeleteComment import com.jerboa.datatypes.types.DeletePost import com.jerboa.datatypes.types.GetPersonDetails import com.jerboa.datatypes.types.GetPersonDetailsResponse -import com.jerboa.datatypes.types.GetPost import com.jerboa.datatypes.types.GetPostResponse import com.jerboa.datatypes.types.MarkPostAsRead import com.jerboa.datatypes.types.PersonId @@ -32,7 +31,6 @@ import com.jerboa.datatypes.types.PostView import com.jerboa.datatypes.types.SaveComment import com.jerboa.datatypes.types.SavePost import com.jerboa.datatypes.types.SortType -import com.jerboa.db.entity.Account import com.jerboa.findAndUpdateComment import com.jerboa.findAndUpdatePost import com.jerboa.serializeToMap @@ -315,24 +313,4 @@ class PersonProfileViewModel : ViewModel(), Initializable { } } } - - fun refreshSinglePost(id: Int, account: Account) { - viewModelScope.launch { - val postForm = GetPost(id = id, auth = account.jwt) - postRes = apiWrapper(API.getInstance().getPost(postForm.serializeToMap())) - val refreshedPost = postRes - val existing = personDetailsRes - when { - refreshedPost is ApiState.Success && existing is ApiState.Success -> { - personDetailsRes = ApiState.Loading - val refreshedPosts = - findAndUpdatePost(existing.data.posts, refreshedPost.data.post_view) - val newPosts = ApiState.Success(existing.data.copy(posts = refreshedPosts)) - personDetailsRes = newPosts - } - - else -> {} - } - } - } } From 2d964ebcaecdb9d3acf380fb349152b110bad4fe Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 3 Aug 2023 09:39:45 +0200 Subject: [PATCH 11/17] Fixing merge conflicts --- app/schemas/com.jerboa.db.AppDB/23.json | 232 ++++++++++++++++++ app/src/main/java/com/jerboa/db/AppDB.kt | 2 +- .../java/com/jerboa/db/AppDBMigrations.kt | 4 +- 3 files changed, 235 insertions(+), 3 deletions(-) create mode 100644 app/schemas/com.jerboa.db.AppDB/23.json diff --git a/app/schemas/com.jerboa.db.AppDB/23.json b/app/schemas/com.jerboa.db.AppDB/23.json new file mode 100644 index 000000000..0a5ad6e1f --- /dev/null +++ b/app/schemas/com.jerboa.db.AppDB/23.json @@ -0,0 +1,232 @@ +{ + "formatVersion": 1, + "database": { + "version": 23, + "identityHash": "cb557db7205cb6ae333d14fbcd156c30", + "entities": [ + { + "tableName": "Account", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `current` INTEGER NOT NULL, `instance` TEXT NOT NULL, `name` TEXT NOT NULL, `jwt` TEXT NOT NULL, `default_listing_type` INTEGER NOT NULL DEFAULT 0, `default_sort_type` INTEGER NOT NULL DEFAULT 0, `verification_state` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "current", + "columnName": "current", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "instance", + "columnName": "instance", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "name", + "columnName": "name", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "jwt", + "columnName": "jwt", + "affinity": "TEXT", + "notNull": true + }, + { + "fieldPath": "defaultListingType", + "columnName": "default_listing_type", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "defaultSortType", + "columnName": "default_sort_type", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "verificationState", + "columnName": "verification_state", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + }, + { + "tableName": "AppSettings", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `font_size` INTEGER NOT NULL DEFAULT 16, `theme` INTEGER NOT NULL DEFAULT 0, `theme_color` INTEGER NOT NULL DEFAULT 0, `viewed_changelog` INTEGER NOT NULL DEFAULT 0, `post_view_mode` INTEGER NOT NULL DEFAULT 0, `show_bottom_nav` INTEGER NOT NULL DEFAULT 1, `show_collapsed_comment_content` INTEGER NOT NULL DEFAULT 0, `show_comment_action_bar_by_default` INTEGER NOT NULL DEFAULT 1, `show_voting_arrows_in_list_view` INTEGER NOT NULL DEFAULT 1, `show_parent_comment_navigation_buttons` INTEGER NOT NULL DEFAULT 0, `navigate_parent_comments_with_volume_buttons` INTEGER NOT NULL DEFAULT 0, `use_custom_tabs` INTEGER NOT NULL DEFAULT 1, `use_private_tabs` INTEGER NOT NULL DEFAULT 0, `secure_window` INTEGER NOT NULL DEFAULT 0, `blur_nsfw` INTEGER NOT NULL DEFAULT 1, `show_text_descriptions_in_navbar` INTEGER NOT NULL DEFAULT 1, `markAsReadOnScroll` INTEGER NOT NULL DEFAULT 0, `backConfirmationMode` INTEGER NOT NULL DEFAULT 1, `show_post_link_previews` INTEGER NOT NULL DEFAULT 1)", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, + { + "fieldPath": "fontSize", + "columnName": "font_size", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "16" + }, + { + "fieldPath": "theme", + "columnName": "theme", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "themeColor", + "columnName": "theme_color", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "viewedChangelog", + "columnName": "viewed_changelog", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "postViewMode", + "columnName": "post_view_mode", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "showBottomNav", + "columnName": "show_bottom_nav", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showCollapsedCommentContent", + "columnName": "show_collapsed_comment_content", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "showCommentActionBarByDefault", + "columnName": "show_comment_action_bar_by_default", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showVotingArrowsInListView", + "columnName": "show_voting_arrows_in_list_view", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showParentCommentNavigationButtons", + "columnName": "show_parent_comment_navigation_buttons", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "navigateParentCommentsWithVolumeButtons", + "columnName": "navigate_parent_comments_with_volume_buttons", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "useCustomTabs", + "columnName": "use_custom_tabs", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "usePrivateTabs", + "columnName": "use_private_tabs", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "secureWindow", + "columnName": "secure_window", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "blurNSFW", + "columnName": "blur_nsfw", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showTextDescriptionsInNavbar", + "columnName": "show_text_descriptions_in_navbar", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "markAsReadOnScroll", + "columnName": "markAsReadOnScroll", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "backConfirmationMode", + "columnName": "backConfirmationMode", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "showPostLinkPreviews", + "columnName": "show_post_link_previews", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "1" + } + ], + "primaryKey": { + "autoGenerate": true, + "columnNames": [ + "id" + ] + }, + "indices": [], + "foreignKeys": [] + } + ], + "views": [], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'cb557db7205cb6ae333d14fbcd156c30')" + ] + } +} \ No newline at end of file diff --git a/app/src/main/java/com/jerboa/db/AppDB.kt b/app/src/main/java/com/jerboa/db/AppDB.kt index 648395aa5..1f23eabb6 100644 --- a/app/src/main/java/com/jerboa/db/AppDB.kt +++ b/app/src/main/java/com/jerboa/db/AppDB.kt @@ -39,7 +39,7 @@ val APP_SETTINGS_DEFAULT = AppSettings( ) @Database( - version = 22, + version = 23, entities = [Account::class, AppSettings::class], exportSchema = true, ) diff --git a/app/src/main/java/com/jerboa/db/AppDBMigrations.kt b/app/src/main/java/com/jerboa/db/AppDBMigrations.kt index 8fe6fadc9..9f8b4b493 100644 --- a/app/src/main/java/com/jerboa/db/AppDBMigrations.kt +++ b/app/src/main/java/com/jerboa/db/AppDBMigrations.kt @@ -287,7 +287,7 @@ val MIGRATION_22_21 = object : Migration(22, 21) { } } -val MIGRATION_21_22 = object : Migration(21, 22) { +val MIGRATION_22_23 = object : Migration(21, 22) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED) database.execSQL( @@ -320,5 +320,5 @@ val MIGRATIONS_LIST = arrayOf( MIGRATION_20_21, MIGRATION_21_22, MIGRATION_22_21, - MIGRATION_21_22, + MIGRATION_22_23, ) From b5de940fc247b99e487153efb2fc12a6ea4e2700 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 3 Aug 2023 09:50:41 +0200 Subject: [PATCH 12/17] Fixing migration --- app/src/main/java/com/jerboa/db/AppDBMigrations.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/jerboa/db/AppDBMigrations.kt b/app/src/main/java/com/jerboa/db/AppDBMigrations.kt index 9f8b4b493..2af65d5c2 100644 --- a/app/src/main/java/com/jerboa/db/AppDBMigrations.kt +++ b/app/src/main/java/com/jerboa/db/AppDBMigrations.kt @@ -287,7 +287,7 @@ val MIGRATION_22_21 = object : Migration(22, 21) { } } -val MIGRATION_22_23 = object : Migration(21, 22) { +val MIGRATION_22_23 = object : Migration(22, 23) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED) database.execSQL( From 74300ac9b7680de224f716cfdf1ef85e2b5f4200 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 3 Aug 2023 10:47:29 +0200 Subject: [PATCH 13/17] New account check --- .../com/jerboa/ui/components/community/CommunityActivity.kt | 4 ++-- .../main/java/com/jerboa/ui/components/home/HomeActivity.kt | 4 ++-- .../com/jerboa/ui/components/person/PersonProfileActivity.kt | 4 ++-- .../main/java/com/jerboa/ui/components/post/PostActivity.kt | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt index bf2a4d8d7..ff176e99a 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt @@ -466,12 +466,12 @@ fun CommunityActivity( markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { postView -> if (!postView.read) { - account?.also { acct -> + if (!account.isAnon()) { communityViewModel.markPostAsRead( MarkPostAsRead( post_id = postView.post.id, read = true, - auth = acct.jwt, + auth = account.jwt, ), appState, ) diff --git a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt index a17596320..75a03cf2a 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt @@ -409,12 +409,12 @@ fun MainPostListingsContent( markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { postView -> if (!postView.read) { - account?.also { acct -> + if (!account.isAnon()) { homeViewModel.markPostAsRead( MarkPostAsRead( post_id = postView.post.id, read = true, - auth = acct.jwt, + auth = account.jwt, ), appState, ) diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index 5f1383e45..f151067f3 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -629,12 +629,12 @@ fun UserTabs( markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { if (!it.read) { - account?.also { acct -> + if (!account.isAnon()) { personProfileViewModel.markPostAsRead( MarkPostAsRead( post_id = it.post.id, read = true, - auth = acct.jwt, + auth = account.jwt, ), appState, ) diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 3acd4df59..f59b4f696 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -75,6 +75,7 @@ import com.jerboa.datatypes.types.PostId import com.jerboa.datatypes.types.PostView import com.jerboa.datatypes.types.SaveComment import com.jerboa.datatypes.types.SavePost +import com.jerboa.db.entity.isAnon import com.jerboa.getCommentParentId import com.jerboa.getDepthFromComment import com.jerboa.getLocalizedCommentSortTypeName @@ -310,7 +311,7 @@ fun PostActivity( is ApiState.Failure -> ApiErrorText(postRes.msg) is ApiState.Success -> { val postView = postRes.data.post_view - account?.also { _ -> + if (!account.isAnon()) { if (!postView.read) { appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) postViewModel.markPostAsRead( From 942b81006c3cbc0ae89a3a6a494415f19725a8fc Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 3 Aug 2023 10:57:46 +0200 Subject: [PATCH 14/17] Merging ifs --- .../components/community/CommunityActivity.kt | 20 ++++++++--------- .../jerboa/ui/components/home/HomeActivity.kt | 20 ++++++++--------- .../person/PersonProfileActivity.kt | 20 ++++++++--------- .../jerboa/ui/components/post/PostActivity.kt | 22 +++++++++---------- 4 files changed, 37 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt index ff176e99a..f4dfa4c92 100644 --- a/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/community/CommunityActivity.kt @@ -465,17 +465,15 @@ fun CommunityActivity( openLink = appState::openLink, markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { postView -> - if (!postView.read) { - if (!account.isAnon()) { - communityViewModel.markPostAsRead( - MarkPostAsRead( - post_id = postView.post.id, - read = true, - auth = account.jwt, - ), - appState, - ) - } + if (!account.isAnon() && !postView.read) { + communityViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, + auth = account.jwt, + ), + appState, + ) } }, showIfRead = true, diff --git a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt index 75a03cf2a..70fba2f1d 100644 --- a/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt @@ -408,17 +408,15 @@ fun MainPostListingsContent( openLink = appState::openLink, markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { postView -> - if (!postView.read) { - if (!account.isAnon()) { - homeViewModel.markPostAsRead( - MarkPostAsRead( - post_id = postView.post.id, - read = true, - auth = account.jwt, - ), - appState, - ) - } + if (!account.isAnon() && !postView.read) { + homeViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, + auth = account.jwt, + ), + appState, + ) } }, showIfRead = true, diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index f151067f3..cbd717f03 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -628,17 +628,15 @@ fun UserTabs( showPostLinkPreviews = showPostLinkPreviews, markAsReadOnScroll = markAsReadOnScroll, onMarkAsRead = { - if (!it.read) { - if (!account.isAnon()) { - personProfileViewModel.markPostAsRead( - MarkPostAsRead( - post_id = it.post.id, - read = true, - auth = account.jwt, - ), - appState, - ) - } + if (!account.isAnon() && !it.read) { + personProfileViewModel.markPostAsRead( + MarkPostAsRead( + post_id = it.post.id, + read = true, + auth = account.jwt, + ), + appState, + ) } }, showIfRead = false, diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index f59b4f696..6a4f68618 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -311,18 +311,16 @@ fun PostActivity( is ApiState.Failure -> ApiErrorText(postRes.msg) is ApiState.Success -> { val postView = postRes.data.post_view - if (!account.isAnon()) { - if (!postView.read) { - appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) - postViewModel.markPostAsRead( - MarkPostAsRead( - post_id = postView.post.id, - read = true, - auth = account.jwt, - ), - appState, - ) - } + if (!account.isAnon() && !postView.read) { + appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) + postViewModel.markPostAsRead( + MarkPostAsRead( + post_id = postView.post.id, + read = true, + auth = account.jwt, + ), + appState, + ) } LazyColumn( From 92d3a9614d087d3e753cc8de004aee63a381a795 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 3 Aug 2023 12:09:18 +0200 Subject: [PATCH 15/17] Removed manual mark as read --- .../java/com/jerboa/model/PostViewModel.kt | 20 ------------------- .../jerboa/ui/components/post/PostActivity.kt | 15 +------------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/app/src/main/java/com/jerboa/model/PostViewModel.kt b/app/src/main/java/com/jerboa/model/PostViewModel.kt index 2bdb48495..6fa5834c5 100644 --- a/app/src/main/java/com/jerboa/model/PostViewModel.kt +++ b/app/src/main/java/com/jerboa/model/PostViewModel.kt @@ -8,7 +8,6 @@ import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import arrow.core.Either -import com.jerboa.JerboaAppState import com.jerboa.api.API import com.jerboa.api.ApiState import com.jerboa.api.apiWrapper @@ -30,7 +29,6 @@ import com.jerboa.datatypes.types.GetCommentsResponse import com.jerboa.datatypes.types.GetPost import com.jerboa.datatypes.types.GetPostResponse import com.jerboa.datatypes.types.ListingType -import com.jerboa.datatypes.types.MarkPostAsRead import com.jerboa.datatypes.types.PostId import com.jerboa.datatypes.types.PostResponse import com.jerboa.datatypes.types.PostView @@ -317,22 +315,4 @@ class PostViewModel : ViewModel(), Initializable { else -> {} } } - - fun markPostAsRead( - form: MarkPostAsRead, - appState: JerboaAppState, - ) { - appState.coroutineScope.launch { - markPostRes = ApiState.Loading - markPostRes = apiWrapper(API.getInstance().markAsRead(form)) - - when (val markRes = markPostRes) { - is ApiState.Success -> { - updatePost(markRes.data.post_view) - } - - else -> {} - } - } - } } diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 6a4f68618..3368f5236 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -70,12 +70,10 @@ import com.jerboa.datatypes.types.CreateCommentLike import com.jerboa.datatypes.types.CreatePostLike import com.jerboa.datatypes.types.DeleteComment import com.jerboa.datatypes.types.DeletePost -import com.jerboa.datatypes.types.MarkPostAsRead import com.jerboa.datatypes.types.PostId import com.jerboa.datatypes.types.PostView import com.jerboa.datatypes.types.SaveComment import com.jerboa.datatypes.types.SavePost -import com.jerboa.db.entity.isAnon import com.jerboa.getCommentParentId import com.jerboa.getDepthFromComment import com.jerboa.getLocalizedCommentSortTypeName @@ -311,18 +309,7 @@ fun PostActivity( is ApiState.Failure -> ApiErrorText(postRes.msg) is ApiState.Success -> { val postView = postRes.data.post_view - if (!account.isAnon() && !postView.read) { - appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) - postViewModel.markPostAsRead( - MarkPostAsRead( - post_id = postView.post.id, - read = true, - auth = account.jwt, - ), - appState, - ) - } - + appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) LazyColumn( state = listState, modifier = Modifier From 0e2576cf2561efd4f7be8b169dcc1249bb57d5af Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 3 Aug 2023 12:22:57 +0200 Subject: [PATCH 16/17] Only for Accounts --- .../main/java/com/jerboa/ui/components/post/PostActivity.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt index 3368f5236..1fe592a8e 100644 --- a/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt @@ -74,6 +74,7 @@ import com.jerboa.datatypes.types.PostId import com.jerboa.datatypes.types.PostView import com.jerboa.datatypes.types.SaveComment import com.jerboa.datatypes.types.SavePost +import com.jerboa.db.entity.isAnon import com.jerboa.getCommentParentId import com.jerboa.getDepthFromComment import com.jerboa.getLocalizedCommentSortTypeName @@ -309,7 +310,7 @@ fun PostActivity( is ApiState.Failure -> ApiErrorText(postRes.msg) is ApiState.Success -> { val postView = postRes.data.post_view - appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) + if (!account.isAnon()) appState.addReturn(PostViewReturn.POST_VIEW, postView.copy(read = true)) LazyColumn( state = listState, modifier = Modifier From 690f4b513cc79679d7fb6235b47b7496f6dcacc2 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 3 Aug 2023 12:43:08 +0200 Subject: [PATCH 17/17] Trigger woodpecker