Skip to content

Commit

Permalink
[bug] note content is only accessed if preview enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderPaddyS committed Sep 20, 2024
1 parent 9257354 commit b22491e
Showing 1 changed file with 42 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package org.secuso.privacyfriendlynotes.ui.adapter

import android.app.Activity
import android.graphics.Color
import android.preference.PreferenceManager
import android.text.Html
import android.util.TypedValue
import android.view.LayoutInflater
Expand All @@ -24,6 +23,7 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import org.secuso.privacyfriendlynotes.R
Expand Down Expand Up @@ -67,7 +67,8 @@ class NoteAdapter(
holder.textViewTitle.text = currentNote.name
holder.textViewDescription.text = ""
val pref = PreferenceManager.getDefaultSharedPreferences(holder.itemView.context)
holder.textViewDescription.visibility = if (pref.getBoolean("settings_show_preview", true)) View.VISIBLE else View.GONE
val showPreview = pref.getBoolean("settings_show_preview", true)
holder.textViewDescription.visibility = if (showPreview) View.VISIBLE else View.GONE
holder.textViewExtraText.visibility = View.GONE
holder.textViewExtraText.text = null
holder.imageViewcategory.visibility = View.GONE
Expand Down Expand Up @@ -99,43 +100,50 @@ class NoteAdapter(
}
}

when (currentNote.type) {
DbContract.NoteEntry.TYPE_TEXT -> {
holder.textViewDescription.text = Html.fromHtml(currentNote.content)
holder.textViewDescription.maxLines = 3
}
when (currentNote.type) {
DbContract.NoteEntry.TYPE_TEXT -> {
if (showPreview) {
holder.textViewDescription.text = Html.fromHtml(currentNote.content)
holder.textViewDescription.maxLines = 3
}
}

DbContract.NoteEntry.TYPE_AUDIO -> {
holder.imageViewcategory.visibility = View.VISIBLE
holder.imageViewcategory.setImageResource(R.drawable.ic_mic_icon_24dp)
}
DbContract.NoteEntry.TYPE_AUDIO -> {
holder.imageViewcategory.visibility = View.VISIBLE
holder.imageViewcategory.setImageResource(R.drawable.ic_mic_icon_24dp)
}

DbContract.NoteEntry.TYPE_SKETCH -> {
holder.imageViewcategory.visibility = View.VISIBLE
holder.imageViewcategory.setBackgroundColor(run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorSurfaceVariantLight, value, true)
value.data
})
if (pref.getBoolean("settings_show_preview", true)) {
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)
DbContract.NoteEntry.TYPE_SKETCH -> {
holder.imageViewcategory.visibility = View.VISIBLE
if (showPreview) {
holder.imageViewcategory.setBackgroundColor(run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorSurfaceVariantLight, value, true)
value.data
})
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)
}
}
}

DbContract.NoteEntry.TYPE_CHECKLIST -> {
val preview = mainActivityViewModel.checklistPreview(currentNote)
holder.textViewExtraText.text = "${preview.filter { it.first }.count()}/${preview.size}"
holder.textViewExtraText.visibility = View.VISIBLE
holder.imageViewcategory.visibility = View.GONE
holder.textViewDescription.text = preview.take(3).joinToString(System.lineSeparator()) { it.second }
holder.textViewDescription.maxLines = 3
DbContract.NoteEntry.TYPE_CHECKLIST -> {
holder.imageViewcategory.visibility = View.GONE
holder.textViewExtraText.visibility = View.VISIBLE

if (showPreview) {
val preview = mainActivityViewModel.checklistPreview(currentNote)
holder.textViewExtraText.text = "${preview.filter { it.first }.count()}/${preview.size}"
holder.textViewDescription.text = preview.take(3).joinToString(System.lineSeparator()) { it.second }
holder.textViewDescription.maxLines = 3
} else {
holder.textViewExtraText.text = "-/-"
}
}
}
}

// if the Description is empty, don't show it
if (holder.textViewDescription.text.toString().isEmpty()) {
Expand Down

0 comments on commit b22491e

Please sign in to comment.