Skip to content

Commit

Permalink
remove zoomable async image
Browse files Browse the repository at this point in the history
  • Loading branch information
Tlaster committed Feb 6, 2024
1 parent 46e99d7 commit 7d49a7f
Show file tree
Hide file tree
Showing 23 changed files with 673 additions and 194 deletions.
40 changes: 0 additions & 40 deletions app/src/main/java/dev/dimension/flare/ui/common/OnNewIntent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@ import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.util.DisplayMetrics
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.core.util.Consumer

private fun Context.getActivity(): Activity {
Expand All @@ -41,35 +33,3 @@ fun OnNewIntent(
onDispose { activity.removeOnNewIntentListener(listener) }
}
}

@Composable
fun FullScreenBox(
modifier: Modifier = Modifier,
content: @Composable BoxScope.() -> Unit,
) {
val context = LocalContext.current
val windowManager =
remember { context.getSystemService(Context.WINDOW_SERVICE) as WindowManager }

val (widthPx, heightPx) =
remember(windowManager) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
windowManager.currentWindowMetrics.bounds.width() to
windowManager.currentWindowMetrics.bounds.height()
} else {
DisplayMetrics().apply {
@Suppress("DEPRECATION")
windowManager.defaultDisplay.getRealMetrics(this)
}.let {
it.widthPixels to it.heightPixels
}
}
}
val (width, height) =
with(LocalDensity.current) {
remember(widthPx, heightPx) {
Pair(widthPx.toDp(), heightPx.toDp())
}
}
Box(modifier = Modifier.requiredSize(width, height).then(modifier), content = content)
}
14 changes: 12 additions & 2 deletions app/src/main/java/dev/dimension/flare/ui/component/NetworkImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ fun NetworkImage(
filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
) {
SubcomposeAsyncImage(
model = model,
model =
ImageRequest.Builder(LocalContext.current)
.data(model)
.let {
if (model is String) {
it.memoryCacheKey(model)
} else {
it
}
}
.build(),
contentDescription = contentDescription,
alignment = alignment,
contentScale = contentScale,
Expand All @@ -60,7 +70,7 @@ fun NetworkImage(

@Composable
fun EmojiImage(
uri: Any?,
uri: String,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
Expand Down
25 changes: 20 additions & 5 deletions app/src/main/java/dev/dimension/flare/ui/component/VideoPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.AspectRatioFrameLayout.RESIZE_MODE_ZOOM
import androidx.media3.ui.PlayerView

@OptIn(UnstableApi::class)
Expand All @@ -33,6 +33,8 @@ fun VideoPlayer(
showControls: Boolean = false,
keepScreenOn: Boolean = false,
aspectRatio: Float? = null,
onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
) {
var isLoaded by remember { mutableStateOf(false) }
Box(modifier = modifier) {
Expand All @@ -57,19 +59,31 @@ fun VideoPlayer(
}
},
)
if (aspectRatio == null) {
this.videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
}
}
PlayerView(context).apply {
controllerShowTimeoutMs = -1
useController = showControls
player = exoPlayer
layoutParams =
ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
if (aspectRatio == null) {
this.resizeMode = RESIZE_MODE_ZOOM
}
this.keepScreenOn = keepScreenOn
if (onClick != null) {
setOnClickListener {
onClick()
}
}
if (onLongClick != null) {
setOnLongClickListener {
onLongClick()
true
}
}
}
},
onRelease = {
Expand Down Expand Up @@ -97,7 +111,8 @@ fun VideoPlayer(
} else {
it
}
},
}
.fillMaxSize(),
)
}
LinearProgressIndicator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun CommonStatusComponent(
user: UiUser,
medias: ImmutableList<UiMedia>,
humanizedTime: String,
onMediaClick: (statusKey: MicroBlogKey, index: Int) -> Unit,
onMediaClick: (statusKey: MicroBlogKey, index: Int, preview: String?) -> Unit,
onUserClick: (MicroBlogKey) -> Unit,
modifier: Modifier = Modifier,
sensitive: Boolean = false,
Expand Down Expand Up @@ -192,6 +192,12 @@ fun CommonStatusComponent(
onMediaClick.invoke(
statusKey,
medias.indexOf(it),
when (it) {
is UiMedia.Image -> it.previewUrl
is UiMedia.Video -> it.thumbnailUrl
is UiMedia.Gif -> it.previewUrl
else -> null
},
)
},
sensitive = sensitive,
Expand Down Expand Up @@ -241,6 +247,12 @@ fun CommonStatusComponent(
onMediaClick.invoke(
quotedStatus.statusKey,
quotedStatus.medias.indexOf(it),
when (it) {
is UiMedia.Image -> it.previewUrl
is UiMedia.Video -> it.thumbnailUrl
is UiMedia.Gif -> it.previewUrl
else -> null
},
)
},
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,35 +363,10 @@ internal class DefaultStatusEvent(
override fun onMediaClick(
statusKey: MicroBlogKey,
index: Int,
preview: String?,
uriHandler: UriHandler,
) {
uriHandler.openUri(StatusMediaRouteDestination(statusKey, index).deeplink())
// when (media) {
// is UiMedia.Image -> {
// uriHandler.openUri(MediaRouteDestination(media.url).deeplink())
// }
//
// is UiMedia.Audio -> Unit
// is UiMedia.Gif -> {
// uriHandler.openUri(
// VideoRouteDestination(
// media.url,
// previewUri = media.previewUrl,
// contentDescription = media.description,
// ).deeplink(),
// )
// }
//
// is UiMedia.Video -> {
// uriHandler.openUri(
// VideoRouteDestination(
// media.url,
// previewUri = media.thumbnailUrl,
// contentDescription = media.description,
// ).deeplink(),
// )
// }
// }
uriHandler.openUri(StatusMediaRouteDestination(statusKey, index, preview).deeplink())
}

override fun onDeleteClick(
Expand Down Expand Up @@ -702,6 +677,7 @@ internal data object EmptyStatusEvent : StatusEvent {
override fun onMediaClick(
statusKey: MicroBlogKey,
index: Int,
preview: String?,
uriHandler: UriHandler,
) = Unit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Card
import androidx.compose.material3.CardColors
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -29,6 +31,7 @@ internal fun UiStatusQuoted(
status: UiStatus,
onMediaClick: (UiMedia) -> Unit,
modifier: Modifier = Modifier,
colors: CardColors = CardDefaults.cardColors(),
onClick: () -> Unit = {},
showMedia: Boolean = true,
) {
Expand All @@ -47,6 +50,7 @@ internal fun UiStatusQuoted(
onClick = onClick,
sensitive = status.sensitive,
showMedia = showMedia,
colors = colors,
)
}
is UiStatus.MastodonNotification -> Unit
Expand All @@ -64,6 +68,7 @@ internal fun UiStatusQuoted(
onClick = onClick,
sensitive = status.sensitive,
showMedia = showMedia,
colors = colors,
)

is UiStatus.MisskeyNotification -> Unit
Expand All @@ -81,6 +86,7 @@ internal fun UiStatusQuoted(
onClick = onClick,
sensitive = false,
showMedia = showMedia,
colors = colors,
)
is UiStatus.BlueskyNotification -> Unit
is UiStatus.XQT ->
Expand All @@ -97,6 +103,7 @@ internal fun UiStatusQuoted(
onClick = onClick,
sensitive = status.sensitive,
showMedia = showMedia,
colors = colors,
)
}
}
Expand All @@ -114,10 +121,12 @@ private fun QuotedStatus(
onMediaClick: (UiMedia) -> Unit,
showMedia: Boolean,
modifier: Modifier = Modifier,
colors: CardColors = CardDefaults.cardColors(),
onClick: () -> Unit = {},
) {
Card(
modifier = modifier,
colors = colors,
onClick = onClick,
) {
Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fun MediaItem(
when (media) {
is UiMedia.Image -> {
NetworkImage(
model = media.url,
model = media.previewUrl,
contentDescription = media.description,
modifier =
Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ internal fun BlueskyStatusComponent(
}
.then(modifier),
statusKey = data.statusKey,
onMediaClick = { statusKey, index ->
onMediaClick = { statusKey, index, preview ->
event.onMediaClick(
statusKey = statusKey,
index = index,
preview = preview,
uriHandler = uriHandler,
)
},
Expand Down Expand Up @@ -256,6 +257,7 @@ internal interface BlueskyStatusEvent {
fun onMediaClick(
statusKey: MicroBlogKey,
index: Int,
preview: String?,
uriHandler: UriHandler,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ internal fun MastodonStatusComponent(
}
.then(modifier),
statusKey = actualData.statusKey,
onMediaClick = { statusKey, index ->
onMediaClick = { statusKey, index, preview ->
event.onMediaClick(
statusKey = statusKey,
index = index,
preview = preview,
uriHandler = uriHandler,
)
},
Expand Down Expand Up @@ -368,6 +369,7 @@ internal interface MastodonStatusEvent {
fun onMediaClick(
statusKey: MicroBlogKey,
index: Int,
preview: String?,
uriHandler: UriHandler,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ internal fun MisskeyStatusComponent(
}
.then(modifier),
statusKey = actualData.statusKey,
onMediaClick = { statusKey, index ->
onMediaClick = { statusKey, index, preview ->
event.onMediaClick(
statusKey = statusKey,
index = index,
preview = preview,
uriHandler = uriHandler,
)
},
Expand Down Expand Up @@ -364,6 +365,7 @@ internal interface MisskeyStatusEvent {
fun onMediaClick(
statusKey: MicroBlogKey,
index: Int,
preview: String?,
uriHandler: UriHandler,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ internal fun XQTStatusComponent(
}
.then(modifier),
statusKey = actualData.statusKey,
onMediaClick = { statusKey, index ->
onMediaClick = { statusKey, index, preview ->
event.onMediaClick(
statusKey = statusKey,
index = index,
preview = preview,
uriHandler = uriHandler,
)
},
Expand Down Expand Up @@ -271,6 +272,7 @@ internal interface XQTStatusEvent {
fun onMediaClick(
statusKey: MicroBlogKey,
index: Int,
preview: String?,
uriHandler: UriHandler,
)

Expand Down
Loading

0 comments on commit 7d49a7f

Please sign in to comment.