Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark as Read on Open and Scroll #1025

Merged
merged 27 commits into from
Aug 3, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
beb6fba
Mark as read on open and scroll option
IzakJoubert Jul 12, 2023
897a447
Mark as read on open and scroll option
IzakJoubert Jul 12, 2023
a62f335
Merge branch 'main' into issue/403
ZJouba Jul 12, 2023
286175b
Fixing mark all
IzakJoubert Jul 12, 2023
d1df954
Merge branch 'issue/403' of https://github.com/ZJouba/jerboa into iss…
IzakJoubert Jul 12, 2023
cdb4ee1
Merge branch 'main' into issue/403
IzakJoubert Jul 12, 2023
1a9860f
Update Http.kt
ZJouba Jul 12, 2023
8a23a7e
Merge branch 'main' into issue/403
ZJouba Jul 13, 2023
96f35c3
Update Home in PostActivity
IzakJoubert Jul 13, 2023
37b251c
Merge branch 'main' into issue/403
ZJouba Jul 13, 2023
6dab5b6
Updates and merge conflict fixes
IzakJoubert Jul 20, 2023
f297596
Merged main
IzakJoubert Jul 20, 2023
c6aa4a9
Merge remote-tracking branch 'upstream/main' into issue/403
IzakJoubert Jul 24, 2023
4d4375f
Merge branch 'main' into issue/403
ZJouba Jul 27, 2023
ccd7f46
Check if read first and use appState to launch coroutine
IzakJoubert Jul 27, 2023
7d6c6d8
Adding back migration
IzakJoubert Jul 27, 2023
1083197
Removing dev
IzakJoubert Jul 27, 2023
29dd480
Removing unused functions
IzakJoubert Jul 28, 2023
e7987ee
Merge branch 'main' into issue/403
ZJouba Jul 28, 2023
94190d1
Merge remote-tracking branch 'upstream/main' into issue/403
IzakJoubert Aug 3, 2023
2d964eb
Fixing merge conflicts
IzakJoubert Aug 3, 2023
b5de940
Fixing migration
IzakJoubert Aug 3, 2023
74300ac
New account check
IzakJoubert Aug 3, 2023
942b810
Merging ifs
IzakJoubert Aug 3, 2023
92d3a96
Removed manual mark as read
IzakJoubert Aug 3, 2023
0e2576c
Only for Accounts
IzakJoubert Aug 3, 2023
690f4b5
Trigger woodpecker
IzakJoubert Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merged main
IzakJoubert committed Jul 20, 2023
commit f2975969b7b251cd59d495409df30b84e2db4db6
218 changes: 0 additions & 218 deletions app/schemas/com.jerboa.db.AppDB/21.json

This file was deleted.

24 changes: 6 additions & 18 deletions app/src/main/java/com/jerboa/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -105,8 +105,7 @@ class MainActivity : AppCompatActivity() {
val ctx = LocalContext.current
val accountViewModel: AccountViewModel = viewModel(factory = AccountViewModelFactory.Factory)
val appSettingsViewModel: AppSettingsViewModel = viewModel(factory = AppSettingsViewModelFactory.Factory)
val accountSettingsViewModel: AccountSettingsViewModel =
viewModel(factory = AccountSettingsViewModelFactory.Factory)
val accountSettingsViewModel: AccountSettingsViewModel = viewModel(factory = AccountSettingsViewModelFactory.Factory)

API.errorHandler = {
Log.e("jerboa", it.toString())
@@ -151,13 +150,9 @@ class MainActivity : AppCompatActivity() {
BackConfirmationMode.Toast -> {
this@MainActivity.addConfirmationToast(appState.navController, ctx)
}

BackConfirmationMode.Dialog -> {
this@MainActivity.addConfirmationDialog(navController) {
showConfirmationDialog.value = true
}
this@MainActivity.addConfirmationDialog(appState.navController) { showConfirmationDialog.value = true }
}

BackConfirmationMode.None -> {}
}

@@ -179,18 +174,13 @@ 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, MINIMUM_API_VERSION) < 0 && !serverVersionOutdatedViewed.value) {
ShowOutdatedServerDialog(
siteVersion = siteVersion,
onConfirm = { serverVersionOutdatedViewed.value = true },
)
}
}

else -> {}
}

@@ -278,6 +268,7 @@ class MainActivity : AppCompatActivity() {
useCustomTabs = appSettings.useCustomTabs,
usePrivateTabs = appSettings.usePrivateTabs,
blurNSFW = appSettings.blurNSFW,
showPostLinkPreviews = appSettings.showPostLinkPreviews,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
)
}
@@ -311,6 +302,7 @@ class MainActivity : AppCompatActivity() {
useCustomTabs = appSettings.useCustomTabs,
usePrivateTabs = appSettings.usePrivateTabs,
blurNSFW = appSettings.blurNSFW,
showPostLinkPreviews = appSettings.showPostLinkPreviews,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
)
}
@@ -382,7 +374,6 @@ class MainActivity : AppCompatActivity() {
blurNSFW = appSettings.blurNSFW,
showPostLinkPreviews = appSettings.showPostLinkPreviews,
drawerState = drawerState,
openImageViewer = navController::toView,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
)
}
@@ -417,7 +408,6 @@ class MainActivity : AppCompatActivity() {
blurNSFW = appSettings.blurNSFW,
showPostLinkPreviews = appSettings.showPostLinkPreviews,
drawerState = drawerState,
openImageViewer = navController::toView,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
)
}
@@ -531,9 +521,7 @@ 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) {
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/api/Http.kt
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion app/src/main/java/com/jerboa/db/AppDB.kt
Original file line number Diff line number Diff line change
@@ -35,10 +35,11 @@ val APP_SETTINGS_DEFAULT = AppSettings(
showTextDescriptionsInNavbar = true,
backConfirmationMode = 1,
markAsReadOnScroll = false,
showPostLinkPreviews = true,
)

@Database(
version = 21,
version = 22,
entities = [Account::class, AppSettings::class],
exportSchema = true,
)
10 changes: 10 additions & 0 deletions app/src/main/java/com/jerboa/db/AppDBMigrations.kt
Original file line number Diff line number Diff line change
@@ -262,6 +262,15 @@ val MIGRATION_19_20 = 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(
"ALTER TABLE AppSettings ADD COLUMN show_post_link_previews INTEGER NOT NULL DEFAULT 1",
)
}
}

val MIGRATION_21_22 = object : Migration(21, 22) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(UPDATE_APP_CHANGELOG_UNVIEWED)
database.execSQL(
@@ -292,4 +301,5 @@ val MIGRATIONS_LIST = arrayOf(
MIGRATION_18_19,
MIGRATION_19_20,
MIGRATION_20_21,
MIGRATION_21_22,
)
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@ fun CommunityActivity(
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
blurNSFW: Boolean,
showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
) {
Log.d("jerboa", "got to community activity")
@@ -103,7 +104,7 @@ fun CommunityActivity(
if (communityViewModel.initialized) communityViewModel.updatePost(pv)
}

navController.ConsumeReturn<PostView>(PostViewReturn.POST_VIEW) { pv ->
appState.ConsumeReturn<PostView>(PostViewReturn.POST_VIEW) { pv ->
if (communityViewModel.initialized) communityViewModel.updatePost(pv)
}

@@ -220,7 +221,6 @@ fun CommunityActivity(
onClickBack = appState::navigateUp,
)
}

else -> {}
}
}
@@ -399,7 +399,9 @@ fun CommunityActivity(
useCustomTabs = useCustomTabs,
usePrivateTabs = usePrivateTabs,
blurNSFW = blurNSFW,
openImageViewer = navController::toView,
showPostLinkPreviews = showPostLinkPreviews,
openImageViewer = appState::toView,
openLink = appState::openLink,
markAsReadOnScroll = markAsReadOnScroll,
onMarkAsRead = { postView ->
account?.also { acct ->
@@ -412,10 +414,8 @@ fun CommunityActivity(
)
}
},
navController = navController,
)
}

else -> {}
}
}
Original file line number Diff line number Diff line change
@@ -196,6 +196,7 @@ fun BottomNavActivity(
usePrivateTabs = appSettings.usePrivateTabs,
drawerState = drawerState,
blurNSFW = appSettings.blurNSFW,
showPostLinkPreviews = appSettings.showPostLinkPreviews,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
)
}
@@ -235,7 +236,6 @@ fun BottomNavActivity(
blurNSFW = appSettings.blurNSFW,
showPostLinkPreviews = appSettings.showPostLinkPreviews,
drawerState = drawerState,
openImageViewer = navController::toView,
markAsReadOnScroll = appSettings.markAsReadOnScroll,
)
}
Original file line number Diff line number Diff line change
@@ -91,6 +91,7 @@ fun HomeActivity(
usePrivateTabs: Boolean,
drawerState: DrawerState,
blurNSFW: Boolean,
showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
) {
Log.d("jerboa", "got to home activity")
@@ -107,7 +108,7 @@ fun HomeActivity(
if (homeViewModel.initialized) homeViewModel.updatePost(pv)
}

navController.ConsumeReturn<Int>(PostViewReturn.POST_VIEW) { id ->
appState.ConsumeReturn<Int>(PostViewReturn.POST_VIEW) { id ->
if (homeViewModel.initialized) account?.also { homeViewModel.refreshSinglePost(id, account) }
}

@@ -147,6 +148,7 @@ fun HomeActivity(
useCustomTabs = useCustomTabs,
usePrivateTabs = usePrivateTabs,
blurNSFW = blurNSFW,
showPostLinkPreviews = showPostLinkPreviews,
markAsReadOnScroll = markAsReadOnScroll,
)
},
@@ -188,6 +190,7 @@ fun MainPostListingsContent(
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
blurNSFW: Boolean,
showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
) {
val transferPostEditDepsViaRoot = appState.rootChannel<PostEditDeps>()
@@ -200,7 +203,6 @@ fun MainPostListingsContent(
is ApiState.Success -> {
taglines = siteRes.data.taglines
}

else -> {}
}

@@ -234,7 +236,6 @@ fun MainPostListingsContent(
ApiErrorToast(postsRes.msg)
persistentListOf()
}

is ApiState.Holder -> postsRes.data.posts.toImmutableList()
else -> persistentListOf()
}
@@ -350,8 +351,9 @@ fun MainPostListingsContent(
useCustomTabs = useCustomTabs,
usePrivateTabs = usePrivateTabs,
blurNSFW = blurNSFW,
navController = navController,
openImageViewer = navController::toView,
showPostLinkPreviews = showPostLinkPreviews,
openImageViewer = appState::toView,
openLink = appState::openLink,
markAsReadOnScroll = markAsReadOnScroll,
onMarkAsRead = { postView ->
account?.also { acct ->
Original file line number Diff line number Diff line change
@@ -3,7 +3,11 @@ package com.jerboa.ui.components.person
import android.content.Context
import android.util.Log
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
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
@@ -14,8 +18,25 @@ import androidx.compose.material.ExperimentalMaterialApi
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.*
import androidx.compose.material3.DrawerState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.TabRowDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
@@ -125,7 +146,6 @@ fun PersonProfileActivity(
personProfileViewModel.insertComment(cv)
}
}

else -> {}
}
}
@@ -173,7 +193,6 @@ fun PersonProfileActivity(
openDrawer = ::openDrawer,
)
}

is ApiState.Holder -> {
val person = profileRes.data.person_view.person
PersonProfileHeader(
@@ -223,7 +242,6 @@ fun PersonProfileActivity(
openDrawer = ::openDrawer,
)
}

else -> {}
}
},
@@ -244,7 +262,7 @@ fun PersonProfileActivity(
useCustomTabs = useCustomTabs,
usePrivateTabs = usePrivateTabs,
blurNSFW = blurNSFW,
openImageViewer = openImageViewer,
showPostLinkPreviews = showPostLinkPreviews,
markAsReadOnScroll = markAsReadOnScroll,
)
},
@@ -275,7 +293,7 @@ fun UserTabs(
useCustomTabs: Boolean,
usePrivateTabs: Boolean,
blurNSFW: Boolean,
openImageViewer: (url: String) -> Unit,
showPostLinkPreviews: Boolean,
markAsReadOnScroll: Boolean,
) {
val transferCommentEditDepsViaRoot = appState.rootChannel<CommentEditDeps>()
@@ -294,7 +312,7 @@ fun UserTabs(

val loading = personProfileViewModel.personDetailsRes.isLoading()

navController.ConsumeReturn<Int>(PostViewReturn.POST_VIEW) { id ->
appState.ConsumeReturn<Int>(PostViewReturn.POST_VIEW) { id ->
if (personProfileViewModel.initialized) account?.also { personProfileViewModel.refreshSinglePost(id, account) }
}

@@ -315,7 +333,6 @@ fun UserTabs(
ApiState.Refreshing,
)
}

else -> {}
}
},
@@ -407,7 +424,6 @@ fun UserTabs(
}
}
}

else -> {}
}
}
@@ -544,8 +560,9 @@ fun UserTabs(
useCustomTabs = useCustomTabs,
usePrivateTabs = usePrivateTabs,
blurNSFW = blurNSFW,
navController = navController,
openImageViewer = openImageViewer,
openImageViewer = appState::toView,
openLink = appState::openLink,
showPostLinkPreviews = showPostLinkPreviews,
markAsReadOnScroll = markAsReadOnScroll,
onMarkAsRead = {
account?.also { acct ->
@@ -560,7 +577,6 @@ fun UserTabs(
},
)
}

else -> {}
}
}
@@ -586,8 +602,7 @@ fun UserTabs(

// Holds the un-expanded comment ids
val unExpandedComments = remember { mutableStateListOf<Int>() }
val commentsWithToggledActionBar =
remember { mutableStateListOf<Int>() }
val commentsWithToggledActionBar = remember { mutableStateListOf<Int>() }

val toggleExpanded = { commentId: Int ->
if (unExpandedComments.contains(commentId)) {
@@ -638,11 +653,7 @@ fun UserTabs(
increaseLazyListIndexTracker = {},
addToParentIndexes = {},
isFlat = true,
isExpanded = { commentId ->
!unExpandedComments.contains(
commentId,
)
},
isExpanded = { commentId -> !unExpandedComments.contains(commentId) },
listState = listState,
toggleExpanded = { commentId -> toggleExpanded(commentId) },
toggleActionBar = { commentId -> toggleActionBar(commentId) },
@@ -739,9 +750,7 @@ fun UserTabs(
showCollapsedCommentContent = true,
isCollapsedByParent = false,
showActionBar = { commentId ->
showActionBarByDefault xor commentsWithToggledActionBar.contains(
commentId,
)
showActionBarByDefault xor commentsWithToggledActionBar.contains(commentId)
},
account = account,
moderators = listOf(),
22 changes: 7 additions & 15 deletions app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt
Original file line number Diff line number Diff line change
@@ -97,8 +97,6 @@ import com.jerboa.ui.components.common.ApiErrorToast
import com.jerboa.ui.components.common.CommentNavigationBottomAppBar
import com.jerboa.ui.components.common.CommentSortOptionsDialog
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.isLoading
import com.jerboa.ui.components.common.isRefreshing
@@ -184,7 +182,7 @@ fun PostActivity(
auth = account.jwt,
),
)
navController.apply {
appState.apply {
addReturn(PostViewReturn.POST_VIEW, it)
}
}, {})
@@ -319,7 +317,6 @@ 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
@@ -363,9 +360,8 @@ fun PostActivity(
}
},
onReplyClick = { pv ->
val isModerator =
isModerator(pv.creator, postRes.data.moderators)
navController.toCommentReply(
val isModerator = isModerator(pv.creator, postRes.data.moderators)
appState.toCommentReply(
channel = transferCommentReplyDepsViaRoot,
replyItem = ReplyItem.PostItem(pv),
isModerator = isModerator,
@@ -555,9 +551,8 @@ fun PostActivity(
}
},
onReplyClick = { cv ->
val isModerator =
isModerator(cv.creator, postRes.data.moderators)
navController.toCommentReply(
val isModerator = isModerator(cv.creator, postRes.data.moderators)
appState.toCommentReply(
channel = transferCommentReplyDepsViaRoot,
replyItem = ReplyItem.CommentItem(cv),
isModerator = isModerator,
@@ -576,11 +571,7 @@ fun PostActivity(
},
onPersonClick = appState::toProfile,
onHeaderClick = { commentView -> toggleExpanded(commentView.comment.id) },
onHeaderLongClick = { commentView ->
toggleActionBar(
commentView.comment.id,
)
},
onHeaderLongClick = { commentView -> toggleActionBar(commentView.comment.id) },
onEditCommentClick = { cv ->
appState.toCommentEdit(
channel = transferCommentEditDepsViaRoot,
@@ -608,6 +599,7 @@ fun PostActivity(
postViewModel.fetchMoreChildren(
commentView = cv,
account = account,

)
},
onBlockCreatorClick = { person ->
Original file line number Diff line number Diff line change
@@ -61,9 +61,9 @@ fun PostListings(
blurNSFW: Boolean,
showPostLinkPreviews: Boolean,
openImageViewer: (url: String) -> Unit,
openLink: (String, Boolean, Boolean) -> Unit,
markAsReadOnScroll: Boolean,
onMarkAsRead: (postView: PostView) -> Unit,
navController: NavController,
) {
LazyColumn(
state = listState,
@@ -79,7 +79,8 @@ fun PostListings(
}
// List of items
itemsIndexed(
posts,
items = posts,
contentType = { _, _ -> "Post" },
) { index, postView ->
PostListing(
postView = postView,
@@ -108,7 +109,7 @@ fun PostListings(
blurNSFW = blurNSFW,
showPostLinkPreview = showPostLinkPreviews,
openImageViewer = openImageViewer,
navController = navController,
openLink = openLink,
).let {
if (!postView.read && markAsReadOnScroll) {
DisposableEffect(key1 = postView.post.id) {
@@ -168,8 +169,8 @@ fun PreviewPostListings() {
blurNSFW = true,
showPostLinkPreviews = true,
openImageViewer = {},
openLink = { _: String, _: Boolean, _: Boolean -> },
markAsReadOnScroll = false,
onMarkAsRead = {},
navController = rememberNavController(),
)
}
Original file line number Diff line number Diff line change
@@ -115,6 +115,7 @@ fun LookAndFeelActivity(
showTextDescriptionsInNavbar = showTextDescriptionsInNavbar.value,
blurNSFW = blurNSFW.value,
backConfirmationMode = backConfirmationMode.value,
showPostLinkPreviews = showPostLinkPreviewMode.value,
markAsReadOnScroll = markAsReadOnScroll.value,
),
)
@@ -123,10 +124,7 @@ 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), onClickBack = onBack)
},
content = { padding ->
Column(
@@ -301,6 +299,13 @@ fun LookAndFeelActivity(
},
onCheckedChange = { updateAppSettings() },
)
SettingsCheckbox(
state = showPostLinkPreviewMode,
title = {
Text(stringResource(id = R.string.show_post_link_previews))
},
onCheckedChange = { updateAppSettings() },
)
SettingsCheckbox(
state = markAsReadOnScroll,
title = {
You are viewing a condensed version of this merge commit. You can view the full changes here.