Tab shows bookmarks
This commit is contained in:
parent
e222a375db
commit
a81808664a
@ -10,6 +10,7 @@ import androidx.lifecycle.LifecycleCoroutineScope
|
||||
import androidx.paging.LoadState
|
||||
import androidx.paging.LoadStateAdapter
|
||||
import androidx.paging.PagingDataAdapter
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.google.gson.Gson
|
||||
@ -21,6 +22,7 @@ import org.pixeldroid.app.databinding.ErrorLayoutBinding
|
||||
import org.pixeldroid.app.databinding.LoadStateFooterViewItemBinding
|
||||
import org.pixeldroid.app.posts.feeds.uncachedFeeds.FeedViewModel
|
||||
import org.pixeldroid.app.utils.api.objects.FeedContent
|
||||
import org.pixeldroid.app.utils.api.objects.Status
|
||||
import retrofit2.HttpException
|
||||
|
||||
/**
|
||||
@ -168,4 +170,13 @@ class ReposLoadStateViewHolder(
|
||||
return ReposLoadStateViewHolder(binding, retry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val UIMODEL_STATUS_COMPARATOR = object : DiffUtil.ItemCallback<Status>() {
|
||||
override fun areItemsTheSame(oldItem: Status, newItem: Status): Boolean {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: Status, newItem: Status): Boolean =
|
||||
oldItem.id == newItem.id
|
||||
}
|
@ -13,7 +13,8 @@ import javax.inject.Inject
|
||||
class ProfileContentRepository @ExperimentalPagingApi
|
||||
@Inject constructor(
|
||||
private val api: PixelfedAPI,
|
||||
private val accountId: String
|
||||
private val accountId: String,
|
||||
private val bookmarks: Boolean
|
||||
) : UncachedContentRepository<Status> {
|
||||
override fun getStream(): Flow<PagingData<Status>> {
|
||||
return Pager(
|
||||
@ -21,7 +22,7 @@ class ProfileContentRepository @ExperimentalPagingApi
|
||||
initialLoadSize = NETWORK_PAGE_SIZE,
|
||||
pageSize = NETWORK_PAGE_SIZE),
|
||||
pagingSourceFactory = {
|
||||
ProfilePagingSource(api, accountId)
|
||||
ProfilePagingSource(api, accountId, bookmarks)
|
||||
}
|
||||
).flow
|
||||
}
|
||||
|
@ -9,16 +9,25 @@ import java.io.IOException
|
||||
|
||||
class ProfilePagingSource(
|
||||
private val api: PixelfedAPI,
|
||||
private val accountId: String
|
||||
private val accountId: String,
|
||||
private val bookmarks: Boolean
|
||||
) : PagingSource<String, Status>() {
|
||||
override suspend fun load(params: LoadParams<String>): LoadResult<String, Status> {
|
||||
val position = params.key
|
||||
return try {
|
||||
val posts = api.accountPosts(
|
||||
account_id = accountId,
|
||||
max_id = position,
|
||||
limit = params.loadSize
|
||||
)
|
||||
val posts =
|
||||
if(bookmarks) {
|
||||
api.bookmarks(
|
||||
limit = params.loadSize,
|
||||
max_id = position
|
||||
)
|
||||
} else {
|
||||
api.accountPosts(
|
||||
account_id = accountId,
|
||||
max_id = position,
|
||||
limit = params.loadSize
|
||||
)
|
||||
}
|
||||
|
||||
val nextKey = posts.lastOrNull()?.id
|
||||
|
||||
|
@ -24,7 +24,6 @@ import org.pixeldroid.app.R
|
||||
import org.pixeldroid.app.databinding.ActivityProfileBinding
|
||||
import org.pixeldroid.app.databinding.FragmentProfilePostsBinding
|
||||
import org.pixeldroid.app.posts.PostActivity
|
||||
import org.pixeldroid.app.posts.feeds.uncachedFeeds.FeedViewModel
|
||||
import org.pixeldroid.app.posts.parseHTMLText
|
||||
import org.pixeldroid.app.utils.*
|
||||
import org.pixeldroid.app.utils.api.PixelfedAPI
|
||||
@ -40,7 +39,6 @@ class ProfileActivity : BaseThemedWithBarActivity() {
|
||||
private lateinit var domain : String
|
||||
private lateinit var accountId : String
|
||||
private lateinit var binding: ActivityProfileBinding
|
||||
private lateinit var viewModel: FeedViewModel<Status>
|
||||
|
||||
private var user: UserDatabaseEntity? = null
|
||||
|
||||
@ -66,24 +64,23 @@ class ProfileActivity : BaseThemedWithBarActivity() {
|
||||
|
||||
private fun createSearchTabs(account: Account?): Array<Fragment>{
|
||||
|
||||
val profileGridFragment = ProfileFeedFragment()
|
||||
val arguments = Bundle().apply {
|
||||
putSerializable(Account.ACCOUNT_TAG, account)
|
||||
putSerializable(ProfileFeedFragment.PROFILE_GRID, false)
|
||||
putSerializable(ProfileFeedFragment.BOOKMARKS, false)
|
||||
}
|
||||
val profileFeedFragment = ProfileFeedFragment()
|
||||
val argumentsGrid = Bundle()
|
||||
val argumentsFeed = Bundle()
|
||||
argumentsGrid.putSerializable(Account.ACCOUNT_TAG, account)
|
||||
argumentsFeed.putSerializable(Account.ACCOUNT_TAG, account)
|
||||
argumentsGrid.putSerializable(ProfileFeedFragment.PROFILE_GRID, true)
|
||||
argumentsFeed.putSerializable(ProfileFeedFragment.PROFILE_GRID, false)
|
||||
profileGridFragment.arguments = argumentsGrid
|
||||
profileFeedFragment.arguments = argumentsFeed
|
||||
profileFeedFragment.arguments = arguments.deepCopy()
|
||||
|
||||
// If we are viewing our own account
|
||||
arguments.putSerializable(ProfileFeedFragment.PROFILE_GRID, true)
|
||||
val profileGridFragment = ProfileFeedFragment()
|
||||
profileGridFragment.arguments = arguments.deepCopy()
|
||||
|
||||
// If we are viewing our own account, show bookmarks
|
||||
if(account == null || account.id == user?.user_id) {
|
||||
val profileBookmarksFragment = ProfileFeedFragment() // TODO: bookmark fragment
|
||||
val arguments = Bundle()
|
||||
arguments.putSerializable(Account.ACCOUNT_TAG, account)
|
||||
argumentsFeed.putSerializable(ProfileFeedFragment.PROFILE_GRID, false)
|
||||
profileBookmarksFragment.arguments = arguments
|
||||
val profileBookmarksFragment = ProfileFeedFragment()
|
||||
arguments.putSerializable(ProfileFeedFragment.BOOKMARKS, true)
|
||||
profileBookmarksFragment.arguments = arguments.deepCopy()
|
||||
return arrayOf(
|
||||
profileGridFragment,
|
||||
profileFeedFragment,
|
||||
|
@ -9,10 +9,10 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.paging.ExperimentalPagingApi
|
||||
import androidx.paging.PagingDataAdapter
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.pixeldroid.app.posts.StatusViewHolder
|
||||
import org.pixeldroid.app.posts.feeds.UIMODEL_STATUS_COMPARATOR
|
||||
import org.pixeldroid.app.posts.feeds.uncachedFeeds.*
|
||||
import org.pixeldroid.app.posts.feeds.uncachedFeeds.profile.ProfileContentRepository
|
||||
import org.pixeldroid.app.utils.api.objects.Account
|
||||
@ -27,17 +27,20 @@ class ProfileFeedFragment : UncachedFeedFragment<Status>() {
|
||||
|
||||
companion object {
|
||||
const val PROFILE_GRID = "ProfileGrid"
|
||||
const val BOOKMARKS = "Bookmarks"
|
||||
}
|
||||
|
||||
private lateinit var accountId : String
|
||||
private var user: UserDatabaseEntity? = null
|
||||
private var grid: Boolean = false
|
||||
private var grid: Boolean = true
|
||||
private var bookmarks: Boolean = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
grid = arguments?.getSerializable(PROFILE_GRID) as Boolean? ?: true
|
||||
adapter = ProfilePostsAdapter(grid)
|
||||
grid = arguments?.getSerializable(PROFILE_GRID) as Boolean
|
||||
bookmarks = arguments?.getSerializable(BOOKMARKS) as Boolean
|
||||
adapter = ProfilePostsAdapter()
|
||||
|
||||
//get the currently active user
|
||||
user = db.userDao().getActiveUser()
|
||||
@ -54,7 +57,7 @@ class ProfileFeedFragment : UncachedFeedFragment<Status>() {
|
||||
|
||||
val view = super.onCreateView(inflater, container, savedInstanceState)
|
||||
|
||||
if(grid) {
|
||||
if(grid || bookmarks) {
|
||||
binding.list.layoutManager = GridLayoutManager(context, 3)
|
||||
}
|
||||
|
||||
@ -63,7 +66,8 @@ class ProfileFeedFragment : UncachedFeedFragment<Status>() {
|
||||
viewModel = ViewModelProvider(requireActivity(), ProfileViewModelFactory(
|
||||
ProfileContentRepository(
|
||||
apiHolder.setToCurrentUser(),
|
||||
accountId
|
||||
accountId,
|
||||
bookmarks
|
||||
)
|
||||
)
|
||||
)["Profile", FeedViewModel::class.java] as FeedViewModel<Status>
|
||||
@ -74,23 +78,12 @@ class ProfileFeedFragment : UncachedFeedFragment<Status>() {
|
||||
return view
|
||||
}
|
||||
|
||||
private val UIMODEL_COMPARATOR = object : DiffUtil.ItemCallback<Status>() {
|
||||
override fun areItemsTheSame(oldItem: Status, newItem: Status): Boolean {
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: Status, newItem: Status): Boolean =
|
||||
oldItem.content == newItem.content
|
||||
}
|
||||
|
||||
inner class ProfilePostsAdapter(
|
||||
private val grid: Boolean
|
||||
) : PagingDataAdapter<Status, RecyclerView.ViewHolder>(
|
||||
UIMODEL_COMPARATOR
|
||||
inner class ProfilePostsAdapter() : PagingDataAdapter<Status, RecyclerView.ViewHolder>(
|
||||
UIMODEL_STATUS_COMPARATOR
|
||||
) {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return if(grid) {
|
||||
return if(grid || bookmarks) {
|
||||
ProfilePostsViewHolder.create(parent)
|
||||
} else {
|
||||
StatusViewHolder.create(parent)
|
||||
@ -101,7 +94,7 @@ class ProfileFeedFragment : UncachedFeedFragment<Status>() {
|
||||
val post = getItem(position)
|
||||
|
||||
post?.let {
|
||||
if(grid) {
|
||||
if(grid || bookmarks) {
|
||||
(holder as ProfilePostsViewHolder).bind(it)
|
||||
} else {
|
||||
(holder as StatusViewHolder).bind(it, apiHolder, db,
|
||||
|
@ -183,6 +183,14 @@ interface PixelfedAPI {
|
||||
@Path("id") statusId: String,
|
||||
) : Status
|
||||
|
||||
@GET("/api/v1/bookmarks")
|
||||
suspend fun bookmarks(
|
||||
@Query("limit") limit: Number? = null,
|
||||
@Query("max_id") max_id: String? = null,
|
||||
@Query("since_id") since_id: String? = null,
|
||||
@Query("min_id") min_id: String? = null
|
||||
) : List<Status>
|
||||
|
||||
@POST("/api/v1/statuses/{id}/bookmark")
|
||||
suspend fun bookmarkStatus(
|
||||
@Path("id") statusId: String
|
||||
|
Loading…
x
Reference in New Issue
Block a user