mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 01:03:49 +00:00
refactor: remove unused KThumbnailView functions, extract intent creation to MediaPreviewActivity
This commit is contained in:
parent
9cccbd7aae
commit
f59b3a3b61
@ -64,10 +64,12 @@ import org.session.libsignal.utilities.Log;
|
|||||||
import org.thoughtcrime.securesms.components.MediaView;
|
import org.thoughtcrime.securesms.components.MediaView;
|
||||||
import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord;
|
import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord;
|
||||||
import org.thoughtcrime.securesms.database.loaders.PagingMediaLoader;
|
import org.thoughtcrime.securesms.database.loaders.PagingMediaLoader;
|
||||||
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
||||||
import org.thoughtcrime.securesms.mediapreview.MediaPreviewViewModel;
|
import org.thoughtcrime.securesms.mediapreview.MediaPreviewViewModel;
|
||||||
import org.thoughtcrime.securesms.mediapreview.MediaRailAdapter;
|
import org.thoughtcrime.securesms.mediapreview.MediaRailAdapter;
|
||||||
import org.thoughtcrime.securesms.mms.GlideApp;
|
import org.thoughtcrime.securesms.mms.GlideApp;
|
||||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||||
|
import org.thoughtcrime.securesms.mms.Slide;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||||
import org.thoughtcrime.securesms.util.AttachmentUtil;
|
import org.thoughtcrime.securesms.util.AttachmentUtil;
|
||||||
import org.thoughtcrime.securesms.util.DateUtils;
|
import org.thoughtcrime.securesms.util.DateUtils;
|
||||||
@ -116,6 +118,22 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
|
|||||||
|
|
||||||
private int restartItem = -1;
|
private int restartItem = -1;
|
||||||
|
|
||||||
|
public static Intent getPreviewIntent(Context context, Slide slide, MmsMessageRecord mms) {
|
||||||
|
Intent previewIntent = null;
|
||||||
|
if (MediaPreviewActivity.isContentTypeSupported(slide.getContentType()) && slide.getUri() != null) {
|
||||||
|
previewIntent = new Intent(context, MediaPreviewActivity.class);
|
||||||
|
previewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
.setDataAndType(slide.getUri(), slide.getContentType())
|
||||||
|
.putExtra(ADDRESS_EXTRA, mms.getRecipient().getAddress())
|
||||||
|
.putExtra(OUTGOING_EXTRA, mms.isOutgoing())
|
||||||
|
.putExtra(DATE_EXTRA, mms.getTimestamp())
|
||||||
|
.putExtra(SIZE_EXTRA, slide.asAttachment().getSize())
|
||||||
|
.putExtra(CAPTION_EXTRA, slide.getCaption().orNull())
|
||||||
|
.putExtra(LEFT_IS_RECENT_EXTRA, false);
|
||||||
|
}
|
||||||
|
return previewIntent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,6 +38,7 @@ class AlbumThumbnailView : FrameLayout {
|
|||||||
|
|
||||||
private val cornerMask by lazy { CornerMask(this) }
|
private val cornerMask by lazy { CornerMask(this) }
|
||||||
private var slides: List<Slide> = listOf()
|
private var slides: List<Slide> = listOf()
|
||||||
|
private var slideSize: Int = 0
|
||||||
|
|
||||||
private fun initialize() {
|
private fun initialize() {
|
||||||
LayoutInflater.from(context).inflate(R.layout.album_thumbnail_view, this)
|
LayoutInflater.from(context).inflate(R.layout.album_thumbnail_view, this)
|
||||||
@ -69,22 +70,9 @@ class AlbumThumbnailView : FrameLayout {
|
|||||||
child.getGlobalVisibleRect(testRect)
|
child.getGlobalVisibleRect(testRect)
|
||||||
if (Rect.intersects(rawRect, testRect)) {
|
if (Rect.intersects(rawRect, testRect)) {
|
||||||
// hit intersects with this particular child
|
// hit intersects with this particular child
|
||||||
slides.getOrNull(index)?.let { slide ->
|
val slide = slides.getOrNull(index) ?: return
|
||||||
// dispatch to view image
|
ActivityDispatcher.get(context)?.dispatchIntent { context ->
|
||||||
if (MediaPreviewActivity.isContentTypeSupported(slide.contentType) && slide.uri != null) {
|
MediaPreviewActivity.getPreviewIntent(context, slide, mms)
|
||||||
ActivityDispatcher.get(context)?.dispatchIntent { context ->
|
|
||||||
Intent(context, MediaPreviewActivity::class.java).apply {
|
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
||||||
setDataAndType(slide.uri, slide.contentType)
|
|
||||||
putExtra(MediaPreviewActivity.ADDRESS_EXTRA, mms.recipient.address)
|
|
||||||
putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mms.isOutgoing)
|
|
||||||
putExtra(MediaPreviewActivity.DATE_EXTRA, mms.timestamp)
|
|
||||||
putExtra(MediaPreviewActivity.SIZE_EXTRA, slide.asAttachment().size)
|
|
||||||
putExtra(MediaPreviewActivity.CAPTION_EXTRA, slide.caption.orNull())
|
|
||||||
putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,16 +80,20 @@ class AlbumThumbnailView : FrameLayout {
|
|||||||
|
|
||||||
fun bind(glideRequests: GlideRequests, message: MmsMessageRecord,
|
fun bind(glideRequests: GlideRequests, message: MmsMessageRecord,
|
||||||
isStart: Boolean, isEnd: Boolean) {
|
isStart: Boolean, isEnd: Boolean) {
|
||||||
// TODO: optimize for same size
|
|
||||||
slides = message.slideDeck.thumbnailSlides
|
slides = message.slideDeck.thumbnailSlides
|
||||||
if (slides.isEmpty()) {
|
if (slides.isEmpty()) {
|
||||||
// this should never be encountered because it's checked by parent
|
// this should never be encountered because it's checked by parent
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
calculateRadius(isStart, isEnd, message.isOutgoing)
|
calculateRadius(isStart, isEnd, message.isOutgoing)
|
||||||
albumCellContainer.removeAllViews()
|
|
||||||
LayoutInflater.from(context).inflate(layoutRes(slides.size), albumCellContainer)
|
// recreate cell views if different size to what we have already (for recycling)
|
||||||
// iterate
|
if (slides.size != this.slideSize) {
|
||||||
|
albumCellContainer.removeAllViews()
|
||||||
|
LayoutInflater.from(context).inflate(layoutRes(slides.size), albumCellContainer)
|
||||||
|
this.slideSize = slides.size
|
||||||
|
}
|
||||||
|
// iterate binding
|
||||||
slides.take(5).forEachIndexed { position, slide ->
|
slides.take(5).forEachIndexed { position, slide ->
|
||||||
val thumbnailView = getThumbnailView(position)
|
val thumbnailView = getThumbnailView(position)
|
||||||
thumbnailView.setImageResource(glideRequests, slide, showControls = false, isPreview = false)
|
thumbnailView.setImageResource(glideRequests, slide, showControls = false, isPreview = false)
|
||||||
|
@ -151,8 +151,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
return super.getSystemService(name)
|
return super.getSystemService(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispatchIntent(body: (Context) -> Intent) {
|
override fun dispatchIntent(body: (Context) -> Intent?) {
|
||||||
val intent = body(this)
|
val intent = body(this) ?: return
|
||||||
push(intent, false)
|
push(intent, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,10 +186,6 @@ open class KThumbnailView: FrameLayout {
|
|||||||
slide = null
|
slide = null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showProgressSpinner() {
|
|
||||||
transferControls.showProgressSpinner()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setImageResource(glideRequests: GlideRequests, uri: Uri): ListenableFuture<Boolean> {
|
fun setImageResource(glideRequests: GlideRequests, uri: Uri): ListenableFuture<Boolean> {
|
||||||
val future = SettableFuture<Boolean>()
|
val future = SettableFuture<Boolean>()
|
||||||
|
|
||||||
@ -210,18 +206,6 @@ open class KThumbnailView: FrameLayout {
|
|||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showDownloadText(showDownloadText: Boolean) {
|
|
||||||
transferControls.setShowDownloadText(showDownloadText)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setDownloadClickListener(listener: SlidesClickedListener) {
|
|
||||||
transferControls.setDownloadClickListener {
|
|
||||||
slide?.let { slide ->
|
|
||||||
listener.onClick(it, listOf(slide))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
}
|
}
|
@ -64,5 +64,5 @@ interface ActivityDispatcher {
|
|||||||
@SuppressLint("WrongConstant")
|
@SuppressLint("WrongConstant")
|
||||||
fun get(context: Context) = context.getSystemService(SERVICE) as? ActivityDispatcher
|
fun get(context: Context) = context.getSystemService(SERVICE) as? ActivityDispatcher
|
||||||
}
|
}
|
||||||
fun dispatchIntent(body: (Context)->Intent)
|
fun dispatchIntent(body: (Context)->Intent?)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user