Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Changed

- Improve timestamp algorithme. O(n \* m) to O(n)
- Improve timestamp algorithm. O(n \* m) to O(n)
- Improve performance of the database creation. Use transaction and batch insert

## [26.08]

Expand Down
63 changes: 49 additions & 14 deletions app/src/main/java/io/github/wiiznokes/gitnote/data/room/Dao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.util.Log
import androidx.paging.PagingSource
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.RawQuery
import androidx.room.Transaction
import androidx.room.Upsert
import androidx.sqlite.db.SimpleSQLiteQuery
import androidx.sqlite.db.SupportSQLiteQuery
Expand All @@ -28,8 +30,7 @@ private const val LIMIT_FILE_SIZE_DB = 2 * 1024 * 1024
@Dao
interface RepoDatabaseDao {

// todo: use @Transaction
// todo: don't clear the all database each time
@Transaction
suspend fun clearAndInit(
rootPath: String,
timestamps: HashMap<String, Long>,
Expand All @@ -42,11 +43,21 @@ interface RepoDatabaseDao {
val rootFolder = NoteFolder.new(
relativePath = "",
)
insertNoteFolder(rootFolder)

val notes = mutableListOf<Note>()
val folders = mutableListOf<NoteFolder>()

folders.add(rootFolder)

val rootLength = rootFs.path.length + 1

suspend fun initRec(folder: NodeFs.Folder) {
var folderCount = 0

val stack = ArrayDeque<NodeFs.Folder>()
stack.add(rootFs)

while (stack.isNotEmpty()) {
val folder = stack.removeLast()

folder.forEachNodeFs { nodeFs ->

Expand All @@ -69,11 +80,16 @@ interface RepoDatabaseDao {
val relativePath = nodeFs.path.substring(startIndex = rootLength)
val note = Note.new(
relativePath = relativePath,
lastModifiedTimeMillis = timestamps.get(relativePath)
lastModifiedTimeMillis = timestamps[relativePath]
?: nodeFs.lastModifiedTime().toMillis(),
content = nodeFs.readText(),
)
insertNote(note)

notes.add(note)
if (notes.size >= 1000) {
insertNotes(notes)
notes.clear()
}
//Log.d(TAG, "add note: $note")
}

Expand All @@ -85,15 +101,26 @@ interface RepoDatabaseDao {
relativePath = nodeFs.path.substring(startIndex = rootLength),
)
//Log.d(TAG, "add noteFolder: $noteFolder")
insertNoteFolder(noteFolder)
progressCb?.invoke(Progress.GeneratingDatabase(noteFolder.relativePath))
initRec(nodeFs)
folders.add(noteFolder)

if (folders.size >= 1000) {
insertFolders(folders)
folders.clear()
}

if (folderCount % 20 == 0) {
progressCb?.invoke(Progress.GeneratingDatabase(noteFolder.relativePath))
}
folderCount += 1

stack.addLast(nodeFs)
}
}
}
}

initRec(rootFs)
insertNotes(notes)
insertFolders(folders)
}


Expand Down Expand Up @@ -270,9 +297,13 @@ interface RepoDatabaseDao {
}


@Upsert
@Insert
suspend fun insertNoteFolder(noteFolder: NoteFolder)


@Insert
suspend fun insertFolders(folders: List<NoteFolder>)

/**
* Delete all notes inside the note folder, and the note folder
*/
Expand All @@ -297,18 +328,22 @@ interface RepoDatabaseDao {
@Upsert
suspend fun insertNote(note: Note)

@Upsert
suspend fun insertNotes(notes: List<Note>)

@Delete
suspend fun removeNote(note: Note)

@Query("DELETE FROM NoteFolders")
fun removeAllNoteFolder()
suspend fun removeAllNoteFolder()

@Query("DELETE FROM Notes")
fun removeAllNote()
suspend fun removeAllNote()

fun clearDatabase() {
suspend fun clearDatabase() {
removeAllNoteFolder()
removeAllNote()

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,18 @@ abstract class RepoDatabase : RoomDatabase() {
}

fun buildFactory(path: String): SupportSQLiteOpenHelper.Factory {
return object : SupportSQLiteOpenHelper.Factory {
override fun create(configuration: SupportSQLiteOpenHelper.Configuration): SupportSQLiteOpenHelper {
val config = SQLiteDatabaseConfiguration(
path,
SQLiteDatabase.OPEN_CREATE or SQLiteDatabase.OPEN_READWRITE
)

config.functions.add(SQLiteFunction("rank", 1, Rank))
config.functions.add(SQLiteFunction("parentPath", 1, ParentPath))
config.functions.add(SQLiteFunction("fullName", 1, FullName))
return SupportSQLiteOpenHelper.Factory { configuration ->
val config = SQLiteDatabaseConfiguration(
path,
SQLiteDatabase.OPEN_CREATE or SQLiteDatabase.OPEN_READWRITE
)

val options = RequerySQLiteOpenHelperFactory.ConfigurationOptions { config }
return RequerySQLiteOpenHelperFactory(listOf(options)).create(configuration)
}
config.functions.add(SQLiteFunction("rank", 1, Rank))
config.functions.add(SQLiteFunction("parentPath", 1, ParentPath))
config.functions.add(SQLiteFunction("fullName", 1, FullName))

val options = RequerySQLiteOpenHelperFactory.ConfigurationOptions { config }
RequerySQLiteOpenHelperFactory(listOf(options)).create(configuration)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GithubProvider : Provider {
private val clientId = "Ov23li8EPatIAsWPt9QT"

// storing this secret in the repo is "ok"
// the only risk is github app reputation and quotas
// the only risk is GitHub app reputation and quotas
// it would require a server to not store it here
private val clientSecret = "12f3f4742855deaafb45e798bcc635608b9d6fe6"

Expand Down Expand Up @@ -111,7 +111,7 @@ class GithubProvider : Provider {

if (responseCode !in 200..299) {
val error = connection.errorStream?.bufferedReader()?.use { it.readText() }
Exception("Failed to create repo: HTTP $responseCode $error")
throw Exception("Failed to create repo: HTTP $responseCode $error")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.dp


private val TAG = "CustomDropDown"
private const val TAG = "CustomDropDown"

data class CustomDropDownModel(
val text: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ private fun DialogPreview() {
expanded = remember {
mutableStateOf(true)
},
text = "Do you wanna have sex ? kvfeznfezlzelfnklze" +
"geg g ggre gegljerngljerngljrnljrengljneglnerlgnelrnglerngenrgne lnglng lenrgln elgrne lgn lgknergner ngegn lekgner nengk enrgl e"
text = "I am a description"
) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import io.github.wiiznokes.gitnote.ui.model.NoteViewType
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
import kotlin.time.Duration.Companion.milliseconds


private const val TAG = "TopGridScreen"
Expand Down Expand Up @@ -445,7 +446,7 @@ private fun SyncStateIcon(

if (state is Ok) {
LaunchedEffect(visible) {
delay(1000)
delay(1000.milliseconds)
visible = false
onConsumeOkSyncState()
tooltipState.dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.viewmodel.compose.viewModel
import dev.olshevski.navigation.reimagined.AnimatedNavHost
import dev.olshevski.navigation.reimagined.NavAction
Expand All @@ -15,6 +16,7 @@ import dev.olshevski.navigation.reimagined.navigate
import dev.olshevski.navigation.reimagined.pop
import dev.olshevski.navigation.reimagined.popUpTo
import dev.olshevski.navigation.reimagined.rememberNavController
import io.github.wiiznokes.gitnote.R
import io.github.wiiznokes.gitnote.ui.component.RequestConfirmationDialog
import io.github.wiiznokes.gitnote.ui.destination.NewRepoMethod
import io.github.wiiznokes.gitnote.ui.destination.SetupDestination
Expand Down Expand Up @@ -96,7 +98,7 @@ fun SetupNav(

RequestConfirmationDialog(
expanded = requestConfirmationDialogExpanded,
text = "WARNING: Are you sure you want to continue? The directory will be deleted.",
text = stringResource(R.string.warning_folder_deletion),
onConfirmation = {
pendingStorageConfig?.let { storageConfig ->
when (setupDestination.newRepoMethod) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.wiiznokes.gitnote.ui.screen.setup.remote

import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -134,7 +135,7 @@ fun EnterUrlScreen(
onClick = {
val urlText = url.value.text
scope.launch {
if (NetworkPermissionHelper.requiresLocalNetworkPermission(urlText) && !NetworkPermissionHelper.isPermissionGranted(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CINNAMON_BUN && NetworkPermissionHelper.requiresLocalNetworkPermission(urlText) && !NetworkPermissionHelper.isPermissionGranted(
context
)
) {
Expand Down
62 changes: 0 additions & 62 deletions app/src/main/java/io/github/wiiznokes/gitnote/ui/utils/Fuzzy.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
package io.github.wiiznokes.gitnote.ui.utils

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

@Composable
fun rememberWindowInfo(): WindowInfo {
val configuration = LocalConfiguration.current
val windowInfo = LocalWindowInfo.current
val size = windowInfo.containerSize

val widthDp = with(LocalDensity.current) { size.width.toDp() }
val heightDp = with(LocalDensity.current) { size.height.toDp() }

return WindowInfo(
screenWidthInfo = when {
configuration.screenWidthDp < 600 -> WindowInfo.WindowType.Compact
configuration.screenWidthDp < 840 -> WindowInfo.WindowType.Medium
widthDp < 600.dp -> WindowInfo.WindowType.Compact
widthDp < 840.dp -> WindowInfo.WindowType.Medium
else -> WindowInfo.WindowType.Expanded
},
screenHeightInfo = when {
configuration.screenHeightDp < 480 -> WindowInfo.WindowType.Compact
configuration.screenHeightDp < 900 -> WindowInfo.WindowType.Medium
heightDp < 480.dp -> WindowInfo.WindowType.Compact
heightDp < 900.dp -> WindowInfo.WindowType.Medium
else -> WindowInfo.WindowType.Expanded
},
screenWidth = configuration.screenWidthDp.dp,
screenHeight = configuration.screenHeightDp.dp
screenWidth = widthDp,
screenHeight = heightDp
)
}


data class WindowInfo(
val screenWidthInfo: WindowType,
val screenHeightInfo: WindowType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ fun onLink(v: TextFieldValue): TextFieldValue {
fun Int.max(b: Int): Int = max(this, b)

/**
* @param f1: this callback will be called on each line selected. Return true if you want to short circuit.
* @param f2: this callback is also called on each line selected, after f1. Return the modified line
* @param f1 this callback will be called on each line selected. Return true if you want to short circuit.
* @param f2 this callback is also called on each line selected, after f1. Return the modified line
*/
private fun multiLinePrefixModifier(
v: TextFieldValue,
Expand Down
Loading