WIP bookmark buttons
This commit is contained in:
parent
80539851c0
commit
e1f7018b19
|
@ -317,6 +317,48 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun bookmarkPost(api: PixelfedAPI) {
|
||||||
|
//Call the api function
|
||||||
|
status?.id?.let { id ->
|
||||||
|
try {
|
||||||
|
api.bookmarkStatus(id)
|
||||||
|
} catch (exception: HttpException) {
|
||||||
|
Toast.makeText(
|
||||||
|
binding.root.context,
|
||||||
|
binding.root.context.getString(R.string.bookmark_post_failed_error, exception.code()),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
} catch (exception: IOException) {
|
||||||
|
Toast.makeText(
|
||||||
|
binding.root.context,
|
||||||
|
binding.root.context.getString(R.string.bookmark_post_failed_io_except),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun undoBookmarkPost(api: PixelfedAPI) {
|
||||||
|
//Call the api function
|
||||||
|
status?.id?.let { id ->
|
||||||
|
try {
|
||||||
|
api.undoBookmarkStatus(id)
|
||||||
|
} catch (exception: HttpException) {
|
||||||
|
Toast.makeText(
|
||||||
|
binding.root.context,
|
||||||
|
binding.root.context.getString(R.string.undobookmark_post_failed_error, exception.code()),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
} catch (exception: IOException) {
|
||||||
|
Toast.makeText(
|
||||||
|
binding.root.context,
|
||||||
|
binding.root.context.getString(R.string.undobookmark_post_failed_io_except),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun activateMoreButton(apiHolder: PixelfedAPIHolder, db: AppDatabase, lifecycleScope: LifecycleCoroutineScope){
|
private fun activateMoreButton(apiHolder: PixelfedAPIHolder, db: AppDatabase, lifecycleScope: LifecycleCoroutineScope){
|
||||||
binding.statusMore.setOnClickListener {
|
binding.statusMore.setOnClickListener {
|
||||||
PopupMenu(it.context, it).apply {
|
PopupMenu(it.context, it).apply {
|
||||||
|
@ -341,6 +383,18 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
R.id.post_more_menu_bookmark -> {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
bookmarkPost(apiHolder.api ?: apiHolder.setToCurrentUser())
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.post_more_menu_unbookmark -> {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
undoBookmarkPost(apiHolder.api ?: apiHolder.setToCurrentUser())
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
R.id.post_more_menu_save_to_gallery -> {
|
R.id.post_more_menu_save_to_gallery -> {
|
||||||
Dexter.withContext(binding.root.context)
|
Dexter.withContext(binding.root.context)
|
||||||
.withPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
.withPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||||
|
@ -429,6 +483,11 @@ class StatusViewHolder(val binding: PostFragmentBinding) : RecyclerView.ViewHold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inflate(R.menu.post_more_menu)
|
inflate(R.menu.post_more_menu)
|
||||||
|
if(status?.bookmarked == true) {
|
||||||
|
menu.setGroupVisible(R.id.post_more_menu_group_bookmark, false)
|
||||||
|
} else {
|
||||||
|
menu.setGroupVisible(R.id.post_more_menu_group_unbookmark, false)
|
||||||
|
}
|
||||||
if(status?.media_attachments.isNullOrEmpty()) {
|
if(status?.media_attachments.isNullOrEmpty()) {
|
||||||
//make sure to disable image-related things if there aren't any
|
//make sure to disable image-related things if there aren't any
|
||||||
menu.setGroupVisible(R.id.post_more_group_picture, false)
|
menu.setGroupVisible(R.id.post_more_group_picture, false)
|
||||||
|
|
|
@ -183,6 +183,17 @@ interface PixelfedAPI {
|
||||||
@Path("id") statusId: String,
|
@Path("id") statusId: String,
|
||||||
) : Status
|
) : Status
|
||||||
|
|
||||||
|
@POST("/api/v1/statuses/{id}/bookmark")
|
||||||
|
suspend fun bookmarkStatus(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
) : Status
|
||||||
|
|
||||||
|
@POST("/api/v1/statuses/{id}/undobookmark")
|
||||||
|
suspend fun undoBookmarkStatus(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
) : Status
|
||||||
|
|
||||||
|
|
||||||
//Used in our case to retrieve comments for a given status
|
//Used in our case to retrieve comments for a given status
|
||||||
@GET("/api/v1/statuses/{id}/context")
|
@GET("/api/v1/statuses/{id}/context")
|
||||||
suspend fun statusComments(
|
suspend fun statusComments(
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
android:title="@string/unbookmark" />
|
android:title="@string/unbookmark" />
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
|
|
||||||
<!-- Group that should only be shown if there are pictures in the post -->
|
<!-- Group that should only be shown if there are pictures in the post -->
|
||||||
<group android:id="@+id/post_more_group_picture">
|
<group android:id="@+id/post_more_group_picture">
|
||||||
<item android:id="@+id/post_more_menu_share_picture"
|
<item android:id="@+id/post_more_menu_share_picture"
|
||||||
|
|
|
@ -254,6 +254,10 @@ For more info about Pixelfed, you can check here: https://pixelfed.org"</string>
|
||||||
<string name="mascot_description">Image showing a red panda, Pixelfed\'s mascot, using a phone</string>
|
<string name="mascot_description">Image showing a red panda, Pixelfed\'s mascot, using a phone</string>
|
||||||
<string name="delete_post_failed_error">Could not delete the post, error %1$d</string>
|
<string name="delete_post_failed_error">Could not delete the post, error %1$d</string>
|
||||||
<string name="delete_post_failed_io_except">Could not delete the post, check your connection?</string>
|
<string name="delete_post_failed_io_except">Could not delete the post, check your connection?</string>
|
||||||
|
<string name="bookmark_post_failed_error">Could not bookmark the post, error %1$d</string>
|
||||||
|
<string name="bookmark_post_failed_io_except">Could not bookmark the post, check your connection?</string>
|
||||||
|
<string name="undobookmark_post_failed_error">Could not unbookmark the post, error %1$d</string>
|
||||||
|
<string name="undobookmark_post_failed_io_except">Could not unbookmark the post, check your connection?</string>
|
||||||
|
|
||||||
<!-- Error message when a selected file can not be found -->
|
<!-- Error message when a selected file can not be found -->
|
||||||
<string name="file_not_found">File %1$s was not found</string>
|
<string name="file_not_found">File %1$s was not found</string>
|
||||||
|
|
Loading…
Reference in New Issue