Skip to content

Commit

Permalink
app: v1.3.4
Browse files Browse the repository at this point in the history
- fix reappearing notification after deleting
- fix notification overwrite when adding multiple notes
  • Loading branch information
Yanndroid committed Jul 20, 2022
1 parent 1071354 commit ca877c8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "de.dlyt.yanndroid.notinotes"
minSdk 26
targetSdk 31
versionCode 7
versionName "1.3.3"
versionCode 8
versionName "1.3.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -32,9 +32,7 @@ android {
}

dependencies {

implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.code.gson:gson:2.9.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
Binary file modified app/release/app-release.aab
Binary file not shown.
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 7,
"versionName": "1.3.3",
"versionCode": 8,
"versionName": "1.3.4",
"outputFile": "app-release.apk"
}
],
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/de/dlyt/yanndroid/notinotes/Notes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Notes(val context: Context) {
)
}

class Note(id: Int) :
class Note(id: Int = -1) :
Serializable {
var title: String? = null
var content: String? = null
Expand All @@ -57,17 +57,25 @@ class Notes(val context: Context) {
var list: ArrayList<Note> = ArrayList()

init {
loadNotesFromSP()
for (note in list) showNotification(note)
}

fun loadNotesFromSP() {
list = Gson().fromJson(
context.getSharedPreferences("sp", Context.MODE_PRIVATE).getString("notes", "[]"),
object : TypeToken<ArrayList<Note>>() {}.type
)
for (note in list) showNotification(note)
}

fun saveNotesToSP() = context.getSharedPreferences("sp", Context.MODE_PRIVATE).edit()
.putString("notes", Gson().toJson(list)).apply()
fun saveNotesToSP() {
context.getSharedPreferences("sp", Context.MODE_PRIVATE).edit()
.putString("notes", Gson().toJson(list)).apply()
}

fun saveNote(note: Note) {
loadNotesFromSP()
if (note.id == -1) note.id = generateNewNoteID()
for (i in list.indices) {
if (note.id == list[i].id) {
list[i] = note
Expand All @@ -82,6 +90,7 @@ class Notes(val context: Context) {
}

fun deleteNote(note: Note) {
loadNotesFromSP()
for (i in list.indices) {
if (note.id == list[i].id) {
list.removeAt(i)
Expand All @@ -92,7 +101,7 @@ class Notes(val context: Context) {
}
}

fun generateNewNoteID(): Int {
private fun generateNewNoteID(): Int {
val takenIDs = list.stream().map { note -> note.id }.collect(Collectors.toList())
var newID = 0
while (takenIDs.contains(newID)) newID++
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/de/dlyt/yanndroid/notinotes/QSTile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class QSTile : TileService() {
}
}

override fun onDestroy() {
/*override fun onDestroy() {
super.onDestroy()
notes.saveNotesToSP()
}
}*/

override fun onClick() {
super.onClick()
notes.editNotePopup(Notes.Note(notes.generateNewNoteID()))
notes.editNotePopup(Notes.Note())
}

private fun createNotificationChannel() {
Expand All @@ -70,6 +70,7 @@ class QSTile : TileService() {
val remoteViews = RemoteViews(context.packageName, R.layout.qs_detail_view)
val adapter = LinearLayoutAdapter(remoteViews, R.id.qs_detail_list)

notes.loadNotesFromSP()
for (note in notes.list) {
val noteView = RemoteViews(context.packageName, R.layout.qs_detail_list_item)
noteView.setTextViewText(R.id.qs_list_item_title, note.title)
Expand All @@ -94,7 +95,7 @@ class QSTile : TileService() {
R.id.qs_detail_add,
Utils.getPendingIntent(
context,
Notes.Note(notes.generateNewNoteID()),
Notes.Note(),
ActionReceiver.ACTION_EDIT
)
)
Expand Down

0 comments on commit ca877c8

Please sign in to comment.