Skip to content

Commit

Permalink
Improves preview of notes.
Browse files Browse the repository at this point in the history
Adds preview of sketch note.
Adds done ration to preview of checklist note.
  • Loading branch information
coderPaddyS committed Nov 2, 2023
1 parent e263ec0 commit e1ee89c
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface NoteDao {
fun activeNotesFilteredAlphabetical(thisFilterText: String): Flow<List<Note?>?>

@Query("SELECT * FROM notes WHERE ((LOWER(name) LIKE '%'|| LOWER(:thisFilterText) || '%') OR (LOWER(content) LIKE '%'|| LOWER(:thisFilterText) || '%' AND type = 3) OR type = 1) AND in_trash='1' ORDER BY name DESC")
fun trashedNotesFiltered(thisFilterText: String): Flow<List<Note?>?>
fun trashedNotesFiltered(thisFilterText: String): Flow<List<Note>>

@Query("SELECT * FROM notes WHERE (category=:thisCategory) AND (in_trash='0') AND ((LOWER(name) LIKE '%'|| LOWER(:thisFilterText) || '%') OR (LOWER(content) LIKE '%'|| LOWER(:thisFilterText) || '%' AND type = 3) OR type = 1) ORDER BY name DESC")
fun activeNotesFilteredFromCategory(thisFilterText: String, thisCategory: Integer): Flow<List<Note?>?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.secuso.privacyfriendlynotes.R
import org.secuso.privacyfriendlynotes.room.model.Note
import org.secuso.privacyfriendlynotes.ui.adapter.NoteAdapter
import org.secuso.privacyfriendlynotes.ui.main.MainActivityViewModel

Expand All @@ -35,7 +36,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 var adapter: NoteAdapter = NoteAdapter()
private var adapter: NoteAdapter = NoteAdapter(mainActivityViewModel)
private var filter: MutableLiveData<String> = MutableLiveData("")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -61,10 +62,12 @@ class RecycleActivity : AppCompatActivity() {
})
filter.observe(this) { it ->
mainActivityViewModel.getTrashedNotesFiltered(it).observe(this) { notes ->
adapter.setNotes(notes)
if (notes != null) {
adapter.setNotes(notes)
}
}
}
adapter.setOnItemClickListener { note ->
adapter.setOnItemClickListener { note: Note ->
AlertDialog.Builder(this@RecycleActivity)
.setTitle(String.format(getString(R.string.dialog_restore_title), note.name))
.setMessage(String.format(getString(R.string.dialog_restore_message), note.name))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
This file is part of the application Privacy Friendly Notes.
Privacy Friendly Notes is free software:
you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or any later version.
Privacy Friendly Notes is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Privacy Friendly Notes. If not, see <http://www.gnu.org/licenses/>.
*/
package org.secuso.privacyfriendlynotes.ui.adapter

import android.opengl.Visibility
import android.preference.PreferenceManager
import android.text.Html
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
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

/**
* Adapter that provides a binding for notes
* @see org.secuso.privacyfriendlynotes.ui.main.MainActivity
*
* @see org.secuso.privacyfriendlynotes.ui.RecycleActivity
*/
class NoteAdapter(private val mainActivityViewModel: MainActivityViewModel) : RecyclerView.Adapter<NoteAdapter.NoteHolder>() {
private var notes: List<Note> = ArrayList()
private val notesFilteredList: List<Note> = ArrayList()
private var listener: ((Note) -> Unit)? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoteHolder {
val itemView = LayoutInflater.from(parent.context)
.inflate(R.layout.note_item, parent, false)
return NoteHolder(itemView)
}

/**
* Defines how notes are presented in the RecyclerView.
* @see org.secuso.privacyfriendlynotes.ui.main.MainActivity
*
* @param holder
* @param position
*/
override fun onBindViewHolder(holder: NoteHolder, position: Int) {
val currentNote = notes[position]
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
when (currentNote.type) {
DbContract.NoteEntry.TYPE_TEXT -> {
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_SKETCH -> {
holder.imageViewcategory.visibility = View.VISIBLE
holder.imageViewcategory.setImageBitmap(mainActivityViewModel.sketchPreview(currentNote, 360))
}

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

// if the Description is empty, don't show it
if (holder.textViewDescription.text.toString().isEmpty()) {
holder.textViewDescription.visibility = View.GONE
}
}

override fun getItemCount(): Int {
return notes.size
}

fun setNotes(notes: List<Note>) {
this.notes = notes
notifyDataSetChanged()
}

inner class NoteHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val textViewTitle: TextView
val textViewDescription: TextView
val imageViewcategory: ImageView
val textViewExtraText: TextView

init {
textViewTitle = itemView.findViewById(R.id.text_view_title)
textViewDescription = itemView.findViewById(R.id.text_view_description)
imageViewcategory = itemView.findViewById(R.id.imageView_category)
textViewExtraText = itemView.findViewById(R.id.note_text_extra)
itemView.setOnClickListener {
val position = adapterPosition
if (listener != null && position != RecyclerView.NO_POSITION) {
listener!!(notes[position])
}
}
}
}

fun setOnItemClickListener(listener: (Note) -> Unit) {
this.listener = listener
}

fun getNoteAt(pos: Int): Note {
return notes[pos]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@

import java.util.List;

import kotlin.Unit;

/**
* The MainActivity includes the functionality of the primary screen.
* It provides the possibility to access existing notes and add new ones.
Expand Down Expand Up @@ -131,15 +133,15 @@ protected void onCreate(Bundle savedInstanceState) {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

//Fill from Room database
mainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);

//Fill from Room database
RecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
adapter = new NoteAdapter();
adapter = new NoteAdapter(mainActivityViewModel);
recyclerView.setAdapter(adapter);

mainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
mainActivityViewModel.getActiveNotes().observe(this, new Observer<List<Note>>() {
@Override
public void onChanged(@Nullable List<Note> notes) {
Expand Down Expand Up @@ -193,7 +195,7 @@ public boolean onQueryTextSubmit(String query) {



/**
/*
* Handels when a note is clicked.
*/
adapter.setOnItemClickListener(note -> {
Expand All @@ -208,19 +210,12 @@ public boolean onQueryTextSubmit(String query) {
return null;
};
switch (note.getType()) {
case DbContract.NoteEntry.TYPE_TEXT:
launchActivity.apply(TextNoteActivity.class);
break;
case DbContract.NoteEntry.TYPE_AUDIO:
launchActivity.apply(AudioNoteActivity.class);
break;
case DbContract.NoteEntry.TYPE_SKETCH:
launchActivity.apply(SketchActivity.class);
break;
case DbContract.NoteEntry.TYPE_CHECKLIST:
launchActivity.apply(ChecklistNoteActivity.class);
break;
case DbContract.NoteEntry.TYPE_TEXT -> launchActivity.apply(TextNoteActivity.class);
case DbContract.NoteEntry.TYPE_AUDIO -> launchActivity.apply(AudioNoteActivity.class);
case DbContract.NoteEntry.TYPE_SKETCH -> launchActivity.apply(SketchActivity.class);
case DbContract.NoteEntry.TYPE_CHECKLIST -> launchActivity.apply(ChecklistNoteActivity.class);
}
return Unit.INSTANCE;
});

PreferenceManager.setDefaultValues(this, R.xml.pref_settings, false);
Expand Down
Loading

0 comments on commit e1ee89c

Please sign in to comment.