From fbf2f60f5c846eefa1e2d86058e155a2a81af2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Mon, 9 Sep 2024 17:11:05 +0200 Subject: [PATCH] Use Glide to load images in `NoteAdapter` --- app/build.gradle | 1 + app/lint.xml | 5 +++++ .../privacyfriendlynotes/ui/RecycleActivity.kt | 4 ++-- .../ui/adapter/NoteAdapter.kt | 15 +++++++++------ .../privacyfriendlynotes/ui/main/MainActivity.kt | 1 + 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e631ad5..ae8e3c3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -86,6 +86,7 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation "androidx.constraintlayout:constraintlayout:2.1.4" implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1' + implementation 'com.github.bumptech.glide:glide:4.11.0' def work_version = "2.8.1" implementation "androidx.work:work-runtime:$work_version" diff --git a/app/lint.xml b/app/lint.xml index 9dc3b53..1b66a25 100644 --- a/app/lint.xml +++ b/app/lint.xml @@ -1,5 +1,10 @@ + + + + + diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/RecycleActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/RecycleActivity.kt index 823ff7b..5174d80 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/RecycleActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/RecycleActivity.kt @@ -14,7 +14,6 @@ package org.secuso.privacyfriendlynotes.ui import android.os.Bundle -import androidx.preference.PreferenceManager import android.view.ContextThemeWrapper import android.view.Menu import android.view.MenuItem @@ -24,6 +23,7 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -43,7 +43,7 @@ import org.secuso.privacyfriendlynotes.ui.main.MainActivityViewModel class RecycleActivity : AppCompatActivity() { private val mainActivityViewModel: MainActivityViewModel by lazy { ViewModelProvider(this)[MainActivityViewModel::class.java] } private val searchView: SearchView by lazy { findViewById(R.id.searchViewFilterRecycle) } - private val adapter: NoteAdapter by lazy { NoteAdapter(mainActivityViewModel, true) } + private val adapter: NoteAdapter by lazy { NoteAdapter(this, mainActivityViewModel, true) } private val trashedNotes by lazy { mainActivityViewModel.trashedNotes.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED).stateIn(lifecycleScope, SharingStarted.Lazily, listOf()) } diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/adapter/NoteAdapter.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/adapter/NoteAdapter.kt index de0a76f..3e97606 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/adapter/NoteAdapter.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/adapter/NoteAdapter.kt @@ -13,6 +13,7 @@ */ package org.secuso.privacyfriendlynotes.ui.adapter +import android.app.Activity import android.graphics.Color import android.preference.PreferenceManager import android.text.Html @@ -22,12 +23,15 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView +import androidx.appcompat.content.res.AppCompatResources import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide import org.secuso.privacyfriendlynotes.R import org.secuso.privacyfriendlynotes.room.DbContract import org.secuso.privacyfriendlynotes.room.model.Note import org.secuso.privacyfriendlynotes.ui.main.MainActivityViewModel import org.secuso.privacyfriendlynotes.ui.util.DarkModeUtil +import java.io.File /** * Adapter that provides a binding for notes @@ -36,6 +40,7 @@ import org.secuso.privacyfriendlynotes.ui.util.DarkModeUtil * @see org.secuso.privacyfriendlynotes.ui.RecycleActivity */ class NoteAdapter( + private val activity: Activity, private val mainActivityViewModel: MainActivityViewModel, var colorCategory: Boolean, ) : RecyclerView.Adapter() { @@ -113,12 +118,10 @@ class NoteAdapter( value.data }) if (pref.getBoolean("settings_show_preview", true)) { - val bitmap = mainActivityViewModel.sketchPreview(currentNote, 200) - if (bitmap != null) { - holder.imageViewcategory.setImageBitmap(mainActivityViewModel.sketchPreview(currentNote, 200)) - } else { - holder.imageViewcategory.setImageResource(R.drawable.ic_photo_icon_24dp) - } + holder.imageViewcategory.minimumHeight = 200; holder.imageViewcategory.minimumWidth = 200 + Glide.with(activity).load(File("${activity.application.filesDir.path}/sketches${currentNote.content}")) + .placeholder(AppCompatResources.getDrawable(activity, R.drawable.ic_photo_icon_24dp)) + .into(holder.imageViewcategory) } else { holder.imageViewcategory.setImageResource(R.drawable.ic_photo_icon_24dp) } diff --git a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt index a072d2b..493f666 100644 --- a/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlynotes/ui/main/MainActivity.kt @@ -139,6 +139,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte recyclerView.layoutManager = LinearLayoutManager(this) recyclerView.setHasFixedSize(true) adapter = NoteAdapter( + this, mainActivityViewModel, PreferenceManager.getDefaultSharedPreferences(this).getBoolean("settings_color_category", true) && mainActivityViewModel.getCategory() == CAT_ALL