Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Glide to load images in NoteAdapter #170

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<!-- Disable the NotificationPermission check for glide -->
<issue id="NotificationPermission">
<ignore regexp="com.bumptech.glide.request.target.NotificationTarget" />
</issue>

<!-- Set the severity of missing translations to warning instead of error -->
<issue id="MissingTranslation" severity="warning" />
</lint>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<NoteAdapter.NoteHolder>() {
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading