Skip to content

Commit

Permalink
Merge pull request #49 from wiiznokes/update-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes authored Aug 29, 2024
2 parents c737ecf + 43960f3 commit e05afdf
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 103 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [24.08]

- delete folder (#42)
- remove fuzzy for searching. Use substring instead

### Changed

- kotlin 2.0

### Fixed

- provider dd
23 changes: 6 additions & 17 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.time.format.DateTimeFormatter
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.about.libraries)
// for room
alias(libs.plugins.ksp)
Expand Down Expand Up @@ -60,7 +61,6 @@ android {
}
}


signingConfigs {
create("release") {

Expand Down Expand Up @@ -97,7 +97,6 @@ android {
arg("room.schemaLocation", "$projectDir/schemas")
}


kotlinOptions {
jvmTarget = "21"
}
Expand All @@ -111,27 +110,16 @@ android {
checkReleaseBuilds = false
}

composeOptions.kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()

packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}

externalNativeBuild {
cmake {
path = file("src/main/cpp/CMakeLists.txt")
version = "3.22.1"
}
}


ndkVersion = "26.1.10909125"
}



kotlin {
jvmToolchain(21)
}
Expand All @@ -147,8 +135,11 @@ dependencies {
//implementation(libs.work.runtime.ktx)
//implementation(libs.splash.screen)


val composeBom = platform(libs.compose.bom)

// Compose
implementation(platform(libs.compose.bom.alpha))
implementation(composeBom)
implementation(libs.compose.ui)
implementation(libs.compose.material)
implementation(libs.compose.material3)
Expand Down Expand Up @@ -178,13 +169,11 @@ dependencies {
// Markdown to HTML
//implementation(libs.markdown)

// Fuzzy search
implementation(libs.fuzzywuzzy)

// unit test
testImplementation(libs.test.junit.ktx)

// integration test
androidTestImplementation(composeBom)
androidTestImplementation(libs.test.junit.ktx)
androidTestImplementation(libs.kotlinx.coroutines.test)
androidTestImplementation(libs.androidx.runner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ data class NoteFolder(
if (other == null || this::class != other::class) return false
return id == (other as NoteFolder).id
}

override fun hashCode(): Int = id
}

Expand Down Expand Up @@ -135,5 +136,6 @@ data class Note(
if (other == null || this::class != other::class) return false
return id == (other as Note).id
}

override fun hashCode(): Int = id
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ enum class Provider : ProviderLink {
GitLab {
override val mainPage: String = "https://gitlab.com/"
override val createRepo: String = "https://gitlab.com/projects/new#blank_project"
override val createToken: String = "https://gitlab.com/-/user_settings/personal_access_tokens"
override val createToken: String =
"https://gitlab.com/-/user_settings/personal_access_tokens"
override val listRepo: String = "https://gitlab.com/dashboard/projects"
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ private fun GridView(
gridNote.note, EditType.Update
)
} else {
vm.selectNote(gridNote.note, add = !gridNote.selected
vm.selectNote(
gridNote.note, add = !gridNote.selected
)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import io.github.wiiznokes.gitnote.R
import io.github.wiiznokes.gitnote.data.room.Note
import io.github.wiiznokes.gitnote.ui.component.CustomDropDown
import io.github.wiiznokes.gitnote.ui.component.CustomDropDownModel
import io.github.wiiznokes.gitnote.ui.component.SimpleIcon
Expand Down
81 changes: 30 additions & 51 deletions app/src/main/java/io/github/wiiznokes/gitnote/ui/util/Fuzzy.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package io.github.wiiznokes.gitnote.ui.util

import io.github.wiiznokes.gitnote.data.room.Note
import me.xdrop.fuzzywuzzy.FuzzySearch
import me.xdrop.fuzzywuzzy.model.ExtractedResult
import java.util.Vector

// todo: maybe replace with a Kotlin impl (https://github.com/solo-studios/kt-fuzzy)

private const val MIN_SCORE = 50
private const val TAG = "Fuzzy"

// todo: highlight matching part (maybe by return List<Note, FuzzyMatch>> to avoid wrapping the note struct
fun fuzzySort(
Expand All @@ -17,67 +14,49 @@ fun fuzzySort(
val names = notes.map { it.nameWithoutExtension() }
val contents = notes.map { it.content }

val namesRes = FuzzySearch.extractSorted(query, names)

val contentsRes = FuzzySearch.extractSorted(query, contents)

assert(notes.size >= namesRes.size && notes.size >= contentsRes.size)

return mergeSortedLists(
notes = notes,
sortedList1 = namesRes,
sortedList2 = contentsRes,
)
}
val v1 = Vector<Int>()
val v2 = Vector<Int>()

val done = BooleanArray(notes.size) { false }

// todo: maybe use iterator instead
private fun mergeSortedLists(
notes: List<Note>,
sortedList1: List<ExtractedResult>,
sortedList2: List<ExtractedResult>
): List<Note> {

val alreadyAddedNotes = BooleanArray(notes.size) { false }
val mergedList = mutableListOf<Note>()
for ((pos, name) in names.withIndex()) {

var index1 = 0
var index2 = 0
if (name.contains(query, ignoreCase = true)) {
done[pos] = true

fun maybeAdd(fuzzyResult: ExtractedResult) {
if (alreadyAddedNotes[fuzzyResult.index] || fuzzyResult.score < MIN_SCORE) {
return
if (name.startsWith(query)) {
v1.add(pos)
} else {
v2.add(pos)
}
}
alreadyAddedNotes[fuzzyResult.index] = true
mergedList.add(notes[fuzzyResult.index])
return
}

while (index1 < sortedList1.size && index2 < sortedList2.size) {
val fuzzyResult1 = sortedList1[index1]
val fuzzyResul2 = sortedList2[index2]
}

if (fuzzyResult1.score >= fuzzyResul2.score) {
maybeAdd(fuzzyResult1)
index1++
for ((pos, name) in contents.withIndex()) {
if (done[pos]) {
continue
}
if (name.contains(query, ignoreCase = true)) {

} else {
maybeAdd(fuzzyResul2)
index2++
v2.add(pos)
}

}

// Add remaining elements from list1, if any
while (index1 < sortedList1.size) {
maybeAdd(sortedList1[index1])
index1++
val v1n = v1.map { pos ->
notes[pos]
}

// Add remaining elements from list2, if any
while (index2 < sortedList2.size) {
maybeAdd(sortedList2[index2])
index2++
val v2n = v2.map { pos ->
notes[pos]
}

return mergedList
val res = v1n + v2n

return res
}


Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.github.wiiznokes.gitnote.ui.model.SortType.Modification
import io.github.wiiznokes.gitnote.ui.screen.app.DrawerFolderModel
import io.github.wiiznokes.gitnote.ui.util.fuzzySort
import io.github.wiiznokes.gitnote.ui.util.mapAndCombine
import io.github.wiiznokes.gitnote.util.contains
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -167,8 +166,7 @@ class GridViewModel : ViewModel() {
storageManager.deleteNotes(currentSelectedNotes)
uiHelper.makeToast(
uiHelper.getQuantityString(
R.plurals.success_notes_delete,
currentSelectedNotes.size
R.plurals.success_notes_delete, currentSelectedNotes.size
)
)
}
Expand Down Expand Up @@ -219,9 +217,7 @@ class GridViewModel : ViewModel() {
}
}.let { filteredNotesFlow ->
combine(
filteredNotesFlow,
prefs.sortType.getFlow(),
prefs.sortOrder.getFlow()
filteredNotesFlow, prefs.sortType.getFlow(), prefs.sortOrder.getFlow()
) { filteredNotes, sortType, sortOrder ->

when (sortType) {
Expand Down Expand Up @@ -255,9 +251,7 @@ class GridViewModel : ViewModel() {
note.relativePath
} else {
name
},
selected = selectedNotes.contains(note),
note = note
}, selected = selectedNotes.contains(note), note = note
)
}
}.stateIn(
Expand All @@ -266,8 +260,7 @@ class GridViewModel : ViewModel() {


val drawerFolders = combine(
dao.allNoteFolders(),
currentNoteFolderRelativePath
dao.allNoteFolders(), currentNoteFolderRelativePath
) { notesFolders, path ->
notesFolders.filter {
it.parentPath() == path
Expand All @@ -277,8 +270,7 @@ class GridViewModel : ViewModel() {
DrawerFolderModel(
noteCount = notes.count {
it.parentPath().startsWith(folder.relativePath)
},
noteFolder = folder
}, noteFolder = folder
)
}
}.stateIn(
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.about.libraries) apply false
}
30 changes: 11 additions & 19 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
[versions]
agp = "8.5.0"

# https://developer.android.com/jetpack/androidx/releases/compose-kotlin?hl=fr
kotlin = "1.9.24"
compose-compiler = "1.5.14"
agp = "8.5.2"
kotlin = "2.0.20"

# https://github.com/google/ksp/releases
# sync with the kotlin version
ksp = "1.9.24-1.0.20"

ktx-core = "1.13.1"
ktx-lifecycle = "2.8.2"

# https://developer.android.com/develop/ui/compose/bom/bom-mapping
compose-bom = "2024.06.00"
ksp = "2.0.20-1.0.24"

ktx-lifecycle = "2.8.4"
room = "2.6.1"
about-libraries = "11.2.1"

[libraries]
# AndroidX Core
androidx-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "ktx-core" }
androidx-ktx = { group = "androidx.core", name = "core-ktx", version = "1.13.1" }
runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "ktx-lifecycle" }
runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "ktx-lifecycle" }
compose-activity = { group = "androidx.activity", name = "activity-compose", version = "1.9.0" }
compose-activity = { group = "androidx.activity", name = "activity-compose", version = "1.9.1" }
datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version = "1.1.1" }

# Compose
# https://central.sonatype.com/artifact/dev.chrisbanes.compose/compose-bom/versions
compose-bom-alpha = { group = "dev.chrisbanes.compose", name = "compose-bom", version = "2024.05.00-alpha03" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "compose-bom" }
# compose-bom-alpha = { group = "dev.chrisbanes.compose", name = "compose-bom", version = "2024.05.00-alpha03" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version = "2024.08.00" }
compose-ui = { group = "androidx.compose.ui", name = "ui" }
compose-ui-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
Expand All @@ -52,15 +44,15 @@ markdown = { group = "org.jetbrains", name = "markdown", version = "0.6.1" }
# 3-party
about-libraries = { group = "com.mikepenz", name = "aboutlibraries-compose-m3", version.ref = "about-libraries" }
reimagined-navigation = { group = "dev.olshevski.navigation", name = "reimagined", version = "1.5.0" }
fuzzywuzzy = { module = "me.xdrop:fuzzywuzzy", version = "1.4.0" }

# Test
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version = "1.8.1" }
test-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version = "1.1.5" }
androidx-runner = { group = "androidx.test", name = "runner", version = "1.5.2" }
test-junit-ktx = { group = "androidx.test.ext", name = "junit-ktx", version = "1.2.1" }
androidx-runner = { group = "androidx.test", name = "runner", version = "1.6.2" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
about-libraries = { id = "com.mikepenz.aboutlibraries.plugin", version.ref = "about-libraries" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }

0 comments on commit e05afdf

Please sign in to comment.