Skip to content

Commit

Permalink
Glimpse: Add zoom support for images
Browse files Browse the repository at this point in the history
Change-Id: Ia140942af6bb17f62dbfeda9b2403cf72ca6875d
  • Loading branch information
SebaUbuntu committed Feb 1, 2024
1 parent 8b9d279 commit 6f3c304
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ android_app {
"Glimpse_io.coil-kt_coil",
"Glimpse_io.coil-kt_coil-gif",
"Glimpse_io.coil-kt_coil-video",
"Glimpse_com.davemorrissey.labs_subsampling-scale-image-view-androidx",
],

optimize: {
Expand Down
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ dependencies {
implementation("io.coil-kt:coil:2.5.0")
implementation("io.coil-kt:coil-gif:2.5.0")
implementation("io.coil-kt:coil-video:2.5.0")

// subsampling-scale-image-view
implementation("com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0")
}

configure<GenerateBpPluginExtension> {
Expand Down
32 changes: 32 additions & 0 deletions app/libs/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,38 @@ android_library {
java_version: "1.7",
}

android_library_import {
name: "Glimpse_com.davemorrissey.labs_subsampling-scale-image-view-androidx-nodeps",
aars: ["com/davemorrissey/labs/subsampling-scale-image-view-androidx/3.10.0/subsampling-scale-image-view-androidx-3.10.0.aar"],
sdk_version: "34",
min_sdk_version: "14",
apex_available: [
"//apex_available:platform",
"//apex_available:anyapex",
],
static_libs: [
"androidx.appcompat_appcompat",
"androidx.exifinterface_exifinterface",
],
}

android_library {
name: "Glimpse_com.davemorrissey.labs_subsampling-scale-image-view-androidx",
sdk_version: "34",
min_sdk_version: "14",
apex_available: [
"//apex_available:platform",
"//apex_available:anyapex",
],
manifest: "com/davemorrissey/labs/subsampling-scale-image-view-androidx/3.10.0/AndroidManifest.xml",
static_libs: [
"Glimpse_com.davemorrissey.labs_subsampling-scale-image-view-androidx-nodeps",
"androidx.appcompat_appcompat",
"androidx.exifinterface_exifinterface",
],
java_version: "1.7",
}

android_library_import {
name: "Glimpse_com.google.android.material_material-nodeps",
aars: ["com/google/android/material/material/1.9.0/material-1.9.0.aar"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.davemorrissey.labs.subscaleview"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="29" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Dave Morrissey

SPDX-License-Identifier: Apache-2.0
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Dave Morrissey

SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package org.lineageos.glimpse.recyclerview
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.lifecycle.findViewTreeLifecycleOwner
Expand All @@ -18,15 +17,15 @@ import androidx.media3.ui.PlayerView
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import coil.load
import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import org.lineageos.glimpse.R
import org.lineageos.glimpse.ext.fade
import org.lineageos.glimpse.models.Media
import org.lineageos.glimpse.models.MediaStoreMedia
import org.lineageos.glimpse.models.MediaType
import org.lineageos.glimpse.viewmodels.MediaViewerUIViewModel
import org.lineageos.glimpse.viewmodels.MediaViewerViewModel
import kotlin.reflect.safeCast

class MediaViewerAdapter(
private val exoPlayer: Lazy<ExoPlayer>,
Expand Down Expand Up @@ -63,7 +62,7 @@ class MediaViewerAdapter(
private val mediaViewerUIViewModel: MediaViewerUIViewModel,
) : RecyclerView.ViewHolder(view) {
// Views
private val imageView = view.findViewById<ImageView>(R.id.imageView)
private val imageView = view.findViewById<SubsamplingScaleImageView>(R.id.imageView)

@androidx.media3.common.util.UnstableApi
private val playerControlView = view.findViewById<PlayerControlView>(R.id.exo_controller)
Expand Down Expand Up @@ -127,11 +126,9 @@ class MediaViewerAdapter(
fun bind(media: Media, position: Int) {
this.media = media
this.position = position
imageView.load(media.uri) {
MediaStoreMedia::class.safeCast(media)?.let {
memoryCacheKey("full_${it.id}")
placeholderMemoryCacheKey("thumbnail_${it.id}")
}

if (media.mediaType == MediaType.IMAGE) {
imageView.setImage(ImageSource.uri(media.uri))
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/media_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:layout_height="match_parent">

<!-- Images -->
<ImageView
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
Expand Down

0 comments on commit 6f3c304

Please sign in to comment.