Merge branch 'feed_fixes' into 'master'

Feed fixes

See merge request pixeldroid/PixelDroid!400
This commit is contained in:
Matthieu 2021-11-28 18:56:40 +00:00
commit 1186491d71
9 changed files with 54 additions and 70 deletions

View File

@ -57,10 +57,10 @@ fun parseHTMLText(
context: Context,
lifecycleScope: LifecycleCoroutineScope,
) : Spanned {
//Convert text to spannable
// Convert text to spannable
val content = fromHtml(text)
//Retrive all links that should be made clickable
// Retrieve all links that should be made clickable
val builder = SpannableStringBuilder(content)
val urlSpans = content.getSpans(0, content.length, URLSpan::class.java)
@ -71,52 +71,55 @@ fun parseHTMLText(
val text = builder.subSequence(start, end)
var customSpan: ClickableSpan? = null
//Handle hashtags
// Handle hashtags
if (text[0] == '#') {
val tag = text.subSequence(1, text.length).toString()
customSpan = object : ClickableSpanNoUnderline() {
override fun onClick(widget: View) {
openTag(context, tag)
}
}
builder.removeSpan(span)
}
//Handle mentions
if(text[0] == '@' && !mentions.isNullOrEmpty()) {
val accountUsername = text.subSequence(1, text.length).toString()
var id: String? = null
// Handle mentions
else if(text[0] == '@') {
if (!mentions.isNullOrEmpty()){
val accountUsername = text.subSequence(1, text.length).toString()
var id: String? = null
//Go through all mentions stored in the status
for (mention in mentions) {
if (mention.username.equals(accountUsername, ignoreCase = true)
) {
id = mention.id
// Go through all mentions stored in the status
for (mention in mentions) {
if (mention.username.equals(accountUsername, ignoreCase = true)
) {
id = mention.id
//Mentions can be of users in other domains
if (mention.url.contains(getDomain(span.url))) {
break
//Mentions can be of users in other domains
if (mention.url.contains(getDomain(span.url))) {
break
}
}
}
}
//Check that we found a user for the given mention
if (id != null) {
val accountId: String = id
customSpan = object : ClickableSpanNoUnderline() {
override fun onClick(widget: View) {
Log.e("MENTION", "CLICKED")
//Retrieve the account for the given profile
lifecycleScope.launchWhenCreated {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
openAccountFromId(accountId, api, context)
// Check that we found a user for the given mention
if (id != null) {
val accountId: String = id
customSpan = object : ClickableSpanNoUnderline() {
override fun onClick(widget: View) {
// Retrieve the account for the given profile
lifecycleScope.launchWhenCreated {
val api: PixelfedAPI = apiHolder.api ?: apiHolder.setToCurrentUser()
openAccountFromId(accountId, api, context)
}
}
}
}
}
builder.removeSpan(span)
}
builder.removeSpan(span)
builder.setSpan(customSpan, start, end, flags)
// Add zero-width space after links in end of line to fix its too large hitbox.

View File

@ -48,8 +48,7 @@ class FeedContentRepository<T: FeedContentDatabase> @ExperimentalPagingApi
return Pager(
config = PagingConfig(initialLoadSize = NETWORK_PAGE_SIZE,
pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false,
prefetchDistance = 50
prefetchDistance = 20
),
remoteMediator = mediator,
pagingSourceFactory = pagingSourceFactory

View File

@ -41,18 +41,14 @@ class NotificationsRemoteMediator @Inject constructor(
override suspend fun load(loadType: LoadType, state: PagingState<Int, Notification>): MediatorResult {
val (max_id, min_id) = when (loadType) {
LoadType.REFRESH -> {
Pair<String?, String?>(null, null)
}
val maxId = when (loadType) {
LoadType.REFRESH -> null
LoadType.PREPEND -> {
//No prepend for the moment, might be nice to add later
return MediatorResult.Success(endOfPaginationReached = true)
}
LoadType.APPEND -> {
Pair<String?, String?>(state.lastItemOrNull()?.id, null)
}
LoadType.APPEND -> state.lastItemOrNull()?.id
?: return MediatorResult.Success(endOfPaginationReached = true)
}
try {
@ -61,10 +57,9 @@ class NotificationsRemoteMediator @Inject constructor(
val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val apiResponse = api.notifications(
max_id = max_id,
min_id = min_id,
limit = state.config.pageSize.toString(),
)
max_id = maxId,
limit = state.config.pageSize.toString()
)
apiResponse.forEach{it.user_id = user.user_id; it.instance_uri = user.instance_uri}

View File

@ -26,18 +26,14 @@ class HomeFeedRemoteMediator @Inject constructor(
override suspend fun load(loadType: LoadType, state: PagingState<Int, HomeStatusDatabaseEntity>): MediatorResult {
val (max_id, min_id) = when (loadType) {
LoadType.REFRESH -> {
Pair<String?, String?>(null, null)
}
val maxId = when (loadType) {
LoadType.REFRESH -> null
LoadType.PREPEND -> {
//No prepend for the moment, might be nice to add later
return MediatorResult.Success(endOfPaginationReached = true)
}
LoadType.APPEND -> {
Pair<String?, String?>(state.lastItemOrNull()?.id, null)
}
LoadType.APPEND -> state.lastItemOrNull()?.id
?: return MediatorResult.Success(endOfPaginationReached = true)
}
try {
@ -46,8 +42,7 @@ class HomeFeedRemoteMediator @Inject constructor(
val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val apiResponse = api.timelineHome(
max_id= max_id,
min_id = min_id, limit = state.config.pageSize.toString()
max_id= maxId, limit = state.config.pageSize.toString()
)
val dbObjects = apiResponse.map{

View File

@ -41,18 +41,14 @@ class PublicFeedRemoteMediator @Inject constructor(
override suspend fun load(loadType: LoadType, state: PagingState<Int, PublicFeedStatusDatabaseEntity>): MediatorResult {
val (max_id, min_id) = when (loadType) {
LoadType.REFRESH -> {
Pair<String?, String?>(null, null)
}
val maxId = when (loadType) {
LoadType.REFRESH -> null
LoadType.PREPEND -> {
//No prepend for the moment, might be nice to add later
return MediatorResult.Success(endOfPaginationReached = true)
}
LoadType.APPEND -> {
Pair<String?, String?>(state.lastItemOrNull()?.id, null)
}
LoadType.APPEND -> state.lastItemOrNull()?.id
?: return MediatorResult.Success(endOfPaginationReached = true)
}
try {
@ -61,8 +57,7 @@ class PublicFeedRemoteMediator @Inject constructor(
val api = apiHolder.api ?: apiHolder.setToCurrentUser()
val apiResponse = api.timelinePublic(
max_id = max_id,
min_id = min_id,
max_id = maxId,
limit = state.config.pageSize.toString(),
)

View File

@ -21,8 +21,7 @@ class FollowersContentRepository @ExperimentalPagingApi
return Pager(
config = PagingConfig(
initialLoadSize = NETWORK_PAGE_SIZE,
pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false),
pageSize = NETWORK_PAGE_SIZE),
pagingSourceFactory = {
FollowersPagingSource(api, accountId, following)
}

View File

@ -24,8 +24,8 @@ class HashTagContentRepository @ExperimentalPagingApi
return Pager(
config = PagingConfig(
initialLoadSize = NETWORK_PAGE_SIZE,
pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false),
pageSize = NETWORK_PAGE_SIZE
),
pagingSourceFactory = {
HashTagPagingSource(api, hashtag)
}

View File

@ -19,8 +19,7 @@ class ProfileContentRepository @ExperimentalPagingApi
return Pager(
config = PagingConfig(
initialLoadSize = NETWORK_PAGE_SIZE,
pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false),
pageSize = NETWORK_PAGE_SIZE),
pagingSourceFactory = {
ProfilePagingSource(api, accountId)
}

View File

@ -28,8 +28,7 @@ class SearchContentRepository<T: FeedContent> @ExperimentalPagingApi
return Pager(
config = PagingConfig(
initialLoadSize = NETWORK_PAGE_SIZE,
pageSize = NETWORK_PAGE_SIZE,
enablePlaceholders = false),
pageSize = NETWORK_PAGE_SIZE),
pagingSourceFactory = {
SearchPagingSource<T>(api, query, type)
}