Open account from notification

This commit is contained in:
mjaillot 2021-03-27 12:44:55 +01:00
parent 34446fc9de
commit ce9b83fe60
2 changed files with 20 additions and 10 deletions

View File

@ -88,16 +88,20 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
private fun Notification.openActivity() {
val intent: Intent =
when (type) {
Notification.NotificationType.mention, Notification.NotificationType.favourite,
Notification.NotificationType.favourite,
Notification.NotificationType.poll, Notification.NotificationType.reblog -> {
openPostFromNotification()
}
Notification.NotificationType.follow -> {
Intent(itemView.context, ProfileActivity::class.java).apply {
putExtra(Account.ACCOUNT_TAG, account)
openAccountFromNotification()
}
Notification.NotificationType.mention -> {
/*Intent(itemView.context, PostActivity::class.java).apply {
putExtra(Status.POST_TAG, status?.in_reply_to_id)
}*/ // TODO
openPostFromNotification()
}
null -> return //TODO show an error here?
null -> return
}
itemView.context.startActivity(intent)
}
@ -107,6 +111,11 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
putExtra(Status.POST_TAG, status)
}
private fun Notification.openAccountFromNotification(): Intent =
Intent(itemView.context, ProfileActivity::class.java).apply {
putExtra(Account.ACCOUNT_TAG, account)
}
private fun setNotificationType(
type: Notification.NotificationType,
@ -211,6 +220,11 @@ class NotificationsFragment : CachedFeedFragment<Notification>() {
"Bearer $accessToken",
lifecycleScope
)
avatar.setOnClickListener {
val intent = notification?.openAccountFromNotification()
itemView.context.startActivity(intent)
}
}
companion object {

View File

@ -4,17 +4,12 @@ import android.app.DownloadManager
import android.content.Context
import android.content.Intent
import android.database.Cursor
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.net.Uri
import android.os.Environment
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import androidx.core.net.toUri
import com.google.android.material.snackbar.Snackbar
import com.h.pixeldroid.R
import com.h.pixeldroid.databinding.PostFragmentBinding
import com.h.pixeldroid.posts.getDomain
import java.io.File
import java.io.Serializable
@ -64,6 +59,7 @@ open class Status(
{
companion object {
const val POST_TAG = "postTag"
const val POST_ID_TAG = "post_id_tag"
const val VIEW_COMMENTS_TAG = "view_comments_tag"
const val POST_COMMENT_TAG = "post_comment_tag"
}