chats: implement attachment onClick

main
Alibek Omarov 4 years ago
parent f7a3c8710f
commit effa7d07c4
  1. 16
      app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt
  2. 36
      app/src/main/java/com/keylesspalace/tusky/components/chat/ChatActivity.kt
  3. 4
      app/src/main/java/com/keylesspalace/tusky/viewdata/AttachmentViewData.kt

@ -79,7 +79,16 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
return intent return intent
} }
fun newAvatarIntent(context: Context, url: String): Intent { @JvmStatic
fun newIntent(context: Context?, attachment: Attachment): Intent {
val intent = Intent(context, ViewMediaActivity::class.java)
intent.putParcelableArrayListExtra(EXTRA_ATTACHMENTS,
arrayListOf(AttachmentViewData(attachment, null, null)))
intent.putExtra(EXTRA_ATTACHMENT_INDEX, 0)
return intent
}
fun newAvatarIntent(context: Context?, url: String): Intent {
val intent = Intent(context, ViewMediaActivity::class.java) val intent = Intent(context, ViewMediaActivity::class.java)
intent.putExtra(EXTRA_AVATAR_URL, url) intent.putExtra(EXTRA_AVATAR_URL, url)
return intent return intent
@ -171,6 +180,11 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
override fun onPrepareOptionsMenu(menu: Menu?): Boolean { override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
menu?.findItem(R.id.action_share_media)?.isEnabled = !isCreating menu?.findItem(R.id.action_share_media)?.isEnabled = !isCreating
if(attachments != null) {
val isStatus = attachments!!.any { it.statusId != null && it.statusUrl != null }
menu?.findItem(R.id.action_open_status)?.isVisible = isStatus
}
return true return true
} }

@ -20,10 +20,6 @@ import android.widget.Toast
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.annotation.VisibleForTesting import androidx.annotation.VisibleForTesting
import com.keylesspalace.tusky.BottomSheetActivity
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.BuildConfig
import com.keylesspalace.tusky.ViewTagActivity
import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.di.ViewModelFactory import com.keylesspalace.tusky.di.ViewModelFactory
import com.keylesspalace.tusky.entity.Chat import com.keylesspalace.tusky.entity.Chat
@ -35,9 +31,11 @@ import com.keylesspalace.tusky.repository.ChatRepository
import com.keylesspalace.tusky.viewdata.ChatMessageViewData import com.keylesspalace.tusky.viewdata.ChatMessageViewData
import androidx.arch.core.util.Function import androidx.arch.core.util.Function
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityOptionsCompat
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.view.ViewCompat
import androidx.core.view.inputmethod.InputConnectionCompat import androidx.core.view.inputmethod.InputConnectionCompat
import androidx.core.view.inputmethod.InputContentInfoCompat import androidx.core.view.inputmethod.InputContentInfoCompat
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
@ -49,11 +47,13 @@ import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition import com.bumptech.glide.request.transition.Transition
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.keylesspalace.tusky.*
import com.keylesspalace.tusky.adapter.* import com.keylesspalace.tusky.adapter.*
import com.keylesspalace.tusky.appstore.* import com.keylesspalace.tusky.appstore.*
import com.keylesspalace.tusky.components.common.* import com.keylesspalace.tusky.components.common.*
import com.keylesspalace.tusky.components.compose.ComposeActivity import com.keylesspalace.tusky.components.compose.ComposeActivity
import com.keylesspalace.tusky.components.compose.dialog.makeCaptionDialog import com.keylesspalace.tusky.components.compose.dialog.makeCaptionDialog
import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.repository.Placeholder import com.keylesspalace.tusky.repository.Placeholder
import com.keylesspalace.tusky.repository.TimelineRequestMode import com.keylesspalace.tusky.repository.TimelineRequestMode
import com.keylesspalace.tusky.service.MessageToSend import com.keylesspalace.tusky.service.MessageToSend
@ -862,13 +862,13 @@ class ChatActivity: BottomSheetActivity(),
FetchEnd.TOP -> { FetchEnd.TOP -> {
updateMessages(msgs, fullFetch) updateMessages(msgs, fullFetch)
val pos = msgs.indexOfFirst { it.isRight() } val last = msgs.indexOfFirst { it.isRight() }
mastodonApi.markChatAsRead(chatId, msgs[pos].asRight().id) mastodonApi.markChatAsRead(chatId, msgs[last].asRight().id)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.autoDispose(this, Lifecycle.Event.ON_DESTROY) .autoDispose(this, Lifecycle.Event.ON_DESTROY)
.subscribe({ .subscribe({
Log.d(TAG, "Marked new messages as read up to ${msgs[pos].asRight().id}") Log.d(TAG, "Marked new messages as read up to ${msgs[last].asRight().id}")
}, { }, {
Log.d(TAG, "Failed to mark messages as read", it) Log.d(TAG, "Failed to mark messages as read", it)
}) })
@ -1039,6 +1039,28 @@ class ChatActivity: BottomSheetActivity(),
startActivity(intent) startActivity(intent)
} }
override fun onViewMedia(position: Int, view: View?) {
val attachment = msgs[position].asRight().attachment!!
when(attachment.type) {
Attachment.Type.GIFV, Attachment.Type.VIDEO, Attachment.Type.AUDIO, Attachment.Type.IMAGE -> {
val intent = ViewMediaActivity.newIntent(this, attachment)
if(view != null) {
val url = attachment.url
ViewCompat.setTransitionName(view, url)
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, view, url)
startActivity(intent, options.toBundle())
} else {
startActivity(intent)
}
}
Attachment.Type.UNKNOWN -> {
viewUrl(attachment.url)
}
}
}
companion object { companion object {
private const val MEDIA_PICK_RESULT = 1 private const val MEDIA_PICK_RESULT = 1
private const val MEDIA_TAKE_PHOTO_RESULT = 2 private const val MEDIA_TAKE_PHOTO_RESULT = 2

@ -8,8 +8,8 @@ import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
data class AttachmentViewData( data class AttachmentViewData(
val attachment: Attachment, val attachment: Attachment,
val statusId: String, val statusId: String?,
val statusUrl: String val statusUrl: String?
) : Parcelable { ) : Parcelable {
companion object { companion object {
@JvmStatic @JvmStatic

Loading…
Cancel
Save