Skip to content

Commit

Permalink
Task ticking, GSON, other improvements and bug fixes
Browse files Browse the repository at this point in the history
* Add option to tick tasks
  * Add checkboxes
  * Update serializers
  * Change all UI occurrences of Note to Task
* Implement GSON serializer
  * Add GSON option to serializer preference
* Minor improvements/bug fixes
  * Dependency updates
  * Change overdue icon
  * Change Date/Time picker color
  * Fix off-by-one error in date picker
  * Find new bugs
  • Loading branch information
profiluefter committed Mar 20, 2021
1 parent 86e2206 commit 6d1200b
Show file tree
Hide file tree
Showing 43 changed files with 131 additions and 43 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Bugs

* file name provider only executed on app launch
* overflow menu settings icon white on white
* file name provider only executed on app launch (sometimes it works???)
* overflow menu settings icon white on white when light theme
* checking note in details activity doesn't work
* "couldn't find view with id 2131296670" when tapping on edittexts in editor view

# Features

Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation "com.google.dagger:hilt-android:$hilt_version"
implementation 'com.google.code.gson:gson:2.8.6'

implementation project(":data-lib")

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/me/profiluefter/profinote/HiltModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ object PreferenceBasedModule {
fun serializerBinding(
@ApplicationContext context: Context,
binary: Provider<BinarySerializer>,
csv: Provider<CSVSerializer>
csv: Provider<CSVSerializer>,
gson: Provider<GSONSerializer>
): Serializer = when (PreferenceManager.getDefaultSharedPreferences(context)
.getString("storageFormat", "binary")) {
"binary" -> binary.get()
"CSV" -> csv.get()
"GSON" -> gson.get()
else -> null!!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ class CSVSerializer @Inject constructor(private val storage: Storage) : Serializ
}

private fun fromCSV(line: String): Note {
val (title, minute, hour, day, month, year, description) = line.split(";")
val (title, done, minute, hour, day, month, year, description) = line.split(";")
Log.v(TAG, "Parsed note \"$title\".")
return Note(
URLDecoder.decode(title, "UTF-8"),
done.toBoolean(),
minute.toInt(),
hour.toInt(),
day.toInt(),
Expand All @@ -42,10 +43,11 @@ class CSVSerializer @Inject constructor(private val storage: Storage) : Serializ
private fun toCSV(note: Note): String = note.run {
Log.v(TAG, "Serializing note \"$title\".")
fun encode(string: String) = URLEncoder.encode(string, "UTF-8")
"${encode(title)};$minute;$hour;$day;$month;$year;${encode(description)}"
"${encode(title)};$done;$minute;$hour;$day;$month;$year;${encode(description)}"
}
}

// Helper for object destructuring in CSVDataLoader#fromCSV(String)
private operator fun <T> List<T>.component6(): T = get(5)
private operator fun <T> List<T>.component7(): T = get(6)
private operator fun <T> List<T>.component8(): T = get(7)
22 changes: 22 additions & 0 deletions app/src/main/java/me/profiluefter/profinote/data/GSONSerializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.profiluefter.profinote.data

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import javax.inject.Inject

private val gson = Gson()

class GSONSerializer @Inject constructor(private val storage: Storage) : Serializer {
override suspend fun load(): List<Note> {
val bytes = storage.get() ?: return emptyList()
val json = bytes.toString(Charsets.UTF_8)

val listType = object : TypeToken<List<Note>>() {}.type
return gson.fromJson(json, listType)
}

override suspend fun save(notes: List<Note>) {
val json = gson.toJson(notes)
storage.store(json.toByteArray(Charsets.UTF_8))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SampleSerializer @Inject constructor() : Serializer {
override suspend fun load(): List<Note> = Array(20) {
Note(
"Sleep $it ${"is important for your health because it helps your body to regain energy!".substring(0, min(it/2, 72))}",
false,
23, 2, 28, Random.nextInt(1..12), 2021,
"Sleep $it is good for your health!".repeat(it*2)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NoteEditorActivityViewModel(note: Note?, position: Int) : ViewModel() {
}

val title: MutableLiveData<String> = MutableLiveData(note?.title ?: "")
val done: MutableLiveData<Boolean> = MutableLiveData(note?.done ?: false)
val date: MutableLiveData<String> = MutableLiveData(note?.date ?: currentDate)
val time: MutableLiveData<String> = MutableLiveData(note?.time ?: currentTime)
val description: MutableLiveData<String> = MutableLiveData(note?.description ?: "")
Expand All @@ -37,7 +38,7 @@ class NoteEditorActivityViewModel(note: Note?, position: Int) : ViewModel() {
get() {
val (day, month, year) = date.value!!.split(".").map { it.toInt() }
val (hour, minute) = time.value!!.split(":").map { it.toInt() }
return Note(title.value!!, minute, hour, day, month, year, description.value!!)
return Note(title.value!!, done.value!!, minute, hour, day, month, year, description.value!!)
}
val notePosition: Int = position

Expand All @@ -46,7 +47,7 @@ class NoteEditorActivityViewModel(note: Note?, position: Int) : ViewModel() {
val calendar = Calendar.getInstance()
return formatDate(
calendar.get(Calendar.DAY_OF_MONTH),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.MONTH) + 1,
calendar.get(Calendar.YEAR)
)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/baseline_notification_important_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2zM13,16h-2v-2h2v2zM13,12h-2L11,8h2v4zM12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2z"/>
</vector>
36 changes: 25 additions & 11 deletions app/src/main/res/layout/activity_note_details.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<import type="me.profiluefter.profinote.data.NoteKt" />
<import type="me.profiluefter.profinote.data.NoteKt"/>

<variable
name="note"
type="me.profiluefter.profinote.data.Note" />
type="me.profiluefter.profinote.data.Note"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<CheckBox
android:id="@+id/note_details_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:checked="@{note.done}"
android:minHeight="0dp"
android:minWidth="0dp"
app:layout_constraintBottom_toBottomOf="@id/note_details_date"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/note_details_title"/>

<TextView
android:id="@+id/note_details_title"
android:layout_width="0dp"
Expand All @@ -27,9 +41,9 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/note_details_done"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/full_names" />
tools:text="@tools:sample/full_names"/>

<TextView
android:id="@+id/note_details_date"
Expand All @@ -38,9 +52,9 @@
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@{NoteKt.getDate(note)}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/note_details_title"
tools:text="@tools:sample/date/ddmmyy[0]" />
app:layout_constraintStart_toEndOf="@id/note_details_done"
app:layout_constraintTop_toBottomOf="@id/note_details_title"
tools:text="@tools:sample/date/ddmmyy[0]"/>

<TextView
android:id="@+id/note_details_time"
Expand All @@ -51,7 +65,7 @@
app:layout_constraintBottom_toBottomOf="@+id/note_details_date"
app:layout_constraintStart_toEndOf="@+id/note_details_date"
app:layout_constraintTop_toTopOf="@+id/note_details_date"
tools:text="@tools:sample/date/hhmm" />
tools:text="@tools:sample/date/hhmm"/>

<TextView
android:id="@+id/note_details_description"
Expand All @@ -68,7 +82,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/note_details_date"
tools:text="@tools:sample/lorem/random[0]" />
tools:text="@tools:sample/lorem/random[0]"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
14 changes: 13 additions & 1 deletion app/src/main/res/layout/activity_note_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
android:layout_height="match_parent"
tools:context=".activities.NoteEditorActivity">

<CheckBox
android:id="@+id/noteEditorDone"
android:checked="@={viewModel.done}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:minHeight="0dp"
android:minWidth="0dp"
app:layout_constraintBottom_toBottomOf="@+id/noteEditorTitleContainer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/noteEditorTitleContainer"/>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/noteEditorTitleContainer"
android:layout_width="0dp"
Expand All @@ -23,7 +35,7 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/noteEditorDone"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.textfield.TextInputEditText
Expand Down
38 changes: 26 additions & 12 deletions app/src/main/res/layout/recycler_view_item.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<import type="me.profiluefter.profinote.data.NoteKt" />
<import type="me.profiluefter.profinote.data.NoteKt"/>
<import type="me.profiluefter.profinote.activities.MainActivity"/>

<variable
name="note"
type="me.profiluefter.profinote.data.Note" />
type="me.profiluefter.profinote.data.Note"/>

<variable
name="position"
type="int" />
type="int"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand All @@ -23,9 +23,23 @@
android:longClickable="true"
android:onClick="@{view -> ((MainActivity) view.context).onShowNoteDetails(position)}">

<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/itemDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:checked="@={note.done}"
android:minHeight="0dp"
android:minWidth="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/itemTitle"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
Expand All @@ -35,11 +49,11 @@
android:text="@{note.title}"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="20sp"
app:drawableEndCompat="@{NoteKt.isOverdue(note) ? @drawable/outline_error_outline_24 : null}"
app:drawableEndCompat="@{NoteKt.isOverdue(note) ? @drawable/baseline_notification_important_24 : null}"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toStartOf="@+id/itemDate"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@id/itemDone"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/full_names" />

Expand All @@ -52,7 +66,7 @@
android:text="@{NoteKt.getDate(note)}"
app:layout_constraintEnd_toStartOf="@+id/itemTime"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/date/ddmmyy[0]" />
tools:text="@tools:sample/date/ddmmyy[0]"/>

<TextView
android:id="@+id/itemTime"
Expand All @@ -63,7 +77,7 @@
android:text="@{NoteKt.getTime(note)}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="@tools:sample/date/hhmm" />
tools:text="@tools:sample/date/hhmm"/>

<TextView
android:id="@+id/itemDescription"
Expand All @@ -77,9 +91,9 @@
android:text="@{note.description}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toEndOf="@+id/itemDone"
app:layout_constraintTop_toBottomOf="@+id/itemTitle"
tools:text="@tools:sample/lorem[4:10]" />
tools:text="@tools:sample/lorem[4:10]"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
6 changes: 3 additions & 3 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<item name="colorSecondary">?attr/colorPrimary</item>
<item name="colorSecondaryVariant">?attr/colorPrimaryVariant</item>
<item name="colorOnSecondary">?attr/colorOnPrimary</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
<string-array name="storage_format_name">
<item>@string/storage_format_csv</item>
<item>@string/storage_format_binary</item>
<item>@string/storage_format_gson</item>
</string-array>
<string-array name="storage_format_values">
<item>CSV</item>
<item>binary</item>
<item>GSON</item>
</string-array>
<string-array name="storage_location_name">
<item>@string/storage_location_private_file</item>
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<resources>
<string name="app_name">Notian</string>
<string name="new_note">New Note</string>
<string name="new_note">New Task</string>
<string name="new_note_condensed">New</string>
<string name="due_warning">Warning</string>
<string name="save_notes">Save</string>
<string name="no_notes">There are currently no notes.\nTry creating some with the button on the top!</string>
<string name="no_notes">There are currently no tasks.\nTry creating some with the button on the top!</string>
<string name="note_action_edit">Edit</string>
<string name="note_action_details">Details</string>
<string name="note_action_delete">Delete</string>
Expand All @@ -13,9 +13,9 @@
<string name="note_editor_time">Time</string>
<string name="note_editor_description">Description</string>
<string name="note_editor_save_button">Save button</string>
<string name="note_deleted">Note deleted</string>
<string name="note_deleted">Task deleted</string>
<string name="undo">Undo</string>
<string name="saved_notes">Saved notes</string>
<string name="saved_notes">Saved tasks</string>
<string name="storage_format_csv">CSV</string>
<string name="storage_format_binary">Binary</string>
<string name="storage_format_selection">Storage Format</string>
Expand All @@ -30,4 +30,5 @@
<string name="grant_permission">Grant permission</string>
<string name="no_sd_card">No SD-Card inserted</string>
<string name="storage_location_external_storage">External Storage</string>
<string name="storage_format_gson">GSON</string>
</resources>
Loading

0 comments on commit 6d1200b

Please sign in to comment.