Skip to content

Commit

Permalink
Add configurable photo transformations including a "safe center crop"…
Browse files Browse the repository at this point in the history
… with a configurable maximum cutoff percentage
  • Loading branch information
giejay committed Dec 24, 2024
1 parent 789a49d commit 5bc4c49
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ android {
applicationId "nl.giejay.android.tv.immich"
minSdkVersion 24
targetSdkVersion 35
versionCode 73
versionName "2.2.1"
versionCode 74
versionName "2.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testOptions.unitTests.includeAndroidResources = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ abstract class GenericAssetFragment : VerticalCardGridFragment<Asset>() {
toSliderItems,
loadMore,
{ item -> manualUpdatePosition(this.assets.indexOfFirst { item.ids().contains(it.id) }) },
animationSpeedMillis = PreferenceManager.animationSpeedMillis()
animationSpeedMillis = PreferenceManager.animationSpeedMillis(),
maxCutOffHeight = PreferenceManager.maxCutOffHeight(),
maxCutOffWidth = PreferenceManager.maxCutOffWidth(),
transformation = PreferenceManager.glideTransformation()
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ class ScreenSaverService : DreamService() {
PreferenceManager.screensaverVideoSound(),
assets.toSliderItems(keepOrder = false, mergePortrait = PreferenceManager.sliderMergePortraitPhotos()),
loadMore,
animationSpeedMillis = PreferenceManager.animationSpeedMillis()
animationSpeedMillis = PreferenceManager.animationSpeedMillis(),
maxCutOffHeight = PreferenceManager.maxCutOffHeight(),
maxCutOffWidth = PreferenceManager.maxCutOffWidth(),
transformation = PreferenceManager.glideTransformation()
)
)
mediaSliderView.toggleSlideshow(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum class PhotosOrder(val sort: Comparator<Asset>) {

companion object {
fun valueOfSafe(name: String, default: PhotosOrder): PhotosOrder{
return PhotosOrder.values().find { it.toString() == name } ?: default
return entries.find { it.toString() == name } ?: default
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager
import nl.giejay.android.tv.immich.screensaver.ScreenSaverType
import nl.giejay.mediaslider.transformations.GlideTransformations
import okhttp3.HttpUrl

object PreferenceManager {
Expand Down Expand Up @@ -38,6 +39,11 @@ object PreferenceManager {
private val KEY_SLIDER_SHOW_CITY = "slider_show_city"
private val KEY_SLIDER_ONLY_USE_THUMBNAILS = "slider_only_use_thumbnails"
private val KEY_SLIDER_MERGE_PORTRAIT_PHOTOS = "slider_merge_portrait_photos"
private val KEY_MAX_CUT_OFF_WIDTH = "slider_max_cut_off_width"
private val KEY_MAX_CUT_OFF_HEIGHT = "slider_max_cut_off_height"
private val KEY_GLIDE_TRANSFORMATION = "slider_glide_transformation"

// sorting
val KEY_ALBUMS_SORTING = "albums_sorting"
private val KEY_PHOTOS_SORTING = "photos_sorting"
private val KEY_ALL_ASSETS_SORTING = "all_assets_sorting"
Expand Down Expand Up @@ -84,7 +90,9 @@ object PreferenceManager {
KEY_SIMILAR_ASSETS_YEARS_BACK to 10,
KEY_RECENT_ASSETS_MONTHS_BACK to 5,
KEY_SIMILAR_ASSETS_PERIOD_DAYS to 30,
KEY_SLIDER_ANIMATION_SPEED to 0
KEY_SLIDER_ANIMATION_SPEED to 0,
KEY_MAX_CUT_OFF_HEIGHT to 20,
KEY_MAX_CUT_OFF_WIDTH to 20
)

fun init(context: Context) {
Expand Down Expand Up @@ -334,4 +342,19 @@ object PreferenceManager {
fun animationSpeedMillis(): Int {
return liveContext[KEY_SLIDER_ANIMATION_SPEED].toString().toInt()
}

fun maxCutOffWidth(): Int {
return liveContext[KEY_MAX_CUT_OFF_WIDTH].toString().toInt()
}

fun maxCutOffHeight(): Int {
return liveContext[KEY_MAX_CUT_OFF_HEIGHT].toString().toInt()
}

fun glideTransformation(): GlideTransformations {
return GlideTransformations.valueOfSafe(
getString(KEY_GLIDE_TRANSFORMATION, GlideTransformations.CENTER_INSIDE.toString()),
GlideTransformations.CENTER_INSIDE
)
}
}
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
<item>2000</item>
</string-array>

<string-array name="glide_transformation_labels">
<item>Center Inside (keep image width/height)</item>
<item>Center Crop (fit screen)</item>
<item>Safe Center Crop (max crop percentage)</item>
</string-array>

<array name="glide_transformation_keys">
<item>CENTER_INSIDE</item>
<item>CENTER_CROP</item>
<item>SAFE_CENTER_CROP</item>
</array>

<string-array name="albums_order">
<item>Last updated</item>
<item>Alphabetically (A-Z)</item>
Expand Down
28 changes: 26 additions & 2 deletions app/src/main/res/xml/preferences_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

</PreferenceCategory>



<PreferenceCategory
android:title="Slideshow">

Expand Down Expand Up @@ -109,6 +107,32 @@
android:entries="@array/animation_speed_ms"
android:entryValues="@array/animation_speed_ms"
android:dialogTitle="Animation speed (ms)"/>

<ListPreference
android:key="slider_glide_transformation"
android:title="Photo transformation"
app:useSimpleSummaryProvider="true"
android:defaultValue="CENTER_INSIDE"
android:entries="@array/glide_transformation_labels"
android:entryValues="@array/glide_transformation_keys"
android:dialogTitle="Photo transformation"/>

<SeekBarPreference
android:key="slider_max_cut_off_width"
android:title="Safe Center Crop max cutoff width %"
app:useSimpleSummaryProvider="true"
android:defaultValue="20"
android:dialogTitle="Maximum percentage to cut off image width if using SafeCenterCrop"
>
</SeekBarPreference>
<SeekBarPreference
android:key="slider_max_cut_off_height"
android:title="Safe Center Crop max cutoff height %"
app:useSimpleSummaryProvider="true"
android:defaultValue="20"
android:dialogTitle="Maximum percentage to cut off image height if using SafeCenterCrop"
>
</SeekBarPreference>
</PreferenceCategory>

<PreferenceCategory
Expand Down

0 comments on commit 5bc4c49

Please sign in to comment.