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
5 changes: 5 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ android {

debug {
applicationIdSuffix = ".debug"
signingConfig = signingConfigs.getByName("nightly")
}
}

Expand Down Expand Up @@ -166,6 +167,10 @@ dependencies {
implementation(libs.room.ktx)
annotationProcessor(libs.room.compiler)
ksp(libs.room.compiler)
implementation(libs.sqlite)
implementation(libs.paging)
implementation(libs.paging.compose)
implementation(libs.room.paging)

// Compose Navigation
implementation(libs.reimagined.navigation)
Expand Down
112 changes: 112 additions & 0 deletions app/schemas/io.github.wiiznokes.gitnote.data.room.RepoDatabase/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "629876da98854b1836f711fc3d20c0a0",
"entities": [
{
"tableName": "NoteFolders",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`relativePath` TEXT NOT NULL, `id` INTEGER NOT NULL, PRIMARY KEY(`relativePath`))",
"fields": [
{
"fieldPath": "relativePath",
"columnName": "relativePath",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"relativePath"
]
}
},
{
"tableName": "Notes",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`relativePath` TEXT NOT NULL, `content` TEXT NOT NULL, `lastModifiedTimeMillis` INTEGER NOT NULL, `id` INTEGER NOT NULL, PRIMARY KEY(`relativePath`))",
"fields": [
{
"fieldPath": "relativePath",
"columnName": "relativePath",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "lastModifiedTimeMillis",
"columnName": "lastModifiedTimeMillis",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"relativePath"
]
}
},
{
"tableName": "NotesFts",
"createSql": "CREATE VIRTUAL TABLE IF NOT EXISTS `${TABLE_NAME}` USING FTS4(`relativePath` TEXT NOT NULL, `content` TEXT NOT NULL, content=`Notes`)",
"fields": [
{
"fieldPath": "relativePath",
"columnName": "relativePath",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "content",
"columnName": "content",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": []
},
"ftsVersion": "FTS4",
"ftsOptions": {
"tokenizer": "simple",
"tokenizerArgs": [],
"contentTable": "Notes",
"languageIdColumnName": "",
"matchInfo": "FTS4",
"notIndexedColumns": [],
"prefixSizes": [],
"preferredOrder": "ASC"
},
"contentSyncTriggers": [
"CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_NotesFts_BEFORE_UPDATE BEFORE UPDATE ON `Notes` BEGIN DELETE FROM `NotesFts` WHERE `docid`=OLD.`rowid`; END",
"CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_NotesFts_BEFORE_DELETE BEFORE DELETE ON `Notes` BEGIN DELETE FROM `NotesFts` WHERE `docid`=OLD.`rowid`; END",
"CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_NotesFts_AFTER_UPDATE AFTER UPDATE ON `Notes` BEGIN INSERT INTO `NotesFts`(`docid`, `relativePath`, `content`) VALUES (NEW.`rowid`, NEW.`relativePath`, NEW.`content`); END",
"CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_NotesFts_AFTER_INSERT AFTER INSERT ON `Notes` BEGIN INSERT INTO `NotesFts`(`docid`, `relativePath`, `content`) VALUES (NEW.`rowid`, NEW.`relativePath`, NEW.`content`); END"
]
}
],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '629876da98854b1836f711fc3d20c0a0')"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.github.wiiznokes.gitnote

import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.github.wiiznokes.gitnote.data.room.Note
import io.github.wiiznokes.gitnote.data.room.NoteFolder
import io.github.wiiznokes.gitnote.data.room.RepoDatabase
import io.github.wiiznokes.gitnote.data.room.RepoDatabase.Companion.buildFactory
import io.github.wiiznokes.gitnote.data.room.RepoDatabaseDao
import io.requery.android.database.sqlite.SQLiteDatabaseConfiguration.MEMORY_DB_PATH
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

private const val TAG = "RepoDatabaseTest"

@RunWith(AndroidJUnit4::class)
class RepoDatabaseTest {

private lateinit var db: RepoDatabase
private lateinit var dao: RepoDatabaseDao

@Before
fun setup() {
val context = ApplicationProvider.getApplicationContext<Context>()

// https://issuetracker.google.com/issues/454083281
db = Room.databaseBuilder(
context = context,
klass = RepoDatabase::class.java,
name = TAG
)
.allowMainThreadQueries()
.openHelperFactory(buildFactory(MEMORY_DB_PATH))
.build()


dao = db.repoDatabaseDao
}

@After
fun tearDown() {
db.close()
}

@Test
fun testDrawerFoldersQuery() = runTest {

dao.insertNoteFolder(NoteFolder.new(""))
dao.insertNoteFolder(NoteFolder.new("test1"))
dao.insertNoteFolder(NoteFolder.new("test2"))
dao.insertNoteFolder(NoteFolder.new("test1/test1.2"))


dao.insertNote(Note.new("test1/1-1.md"))
dao.insertNote(Note.new("test1/1-2.md"))
dao.insertNote(Note.new("test1/test1.2/1.2-1.md"))
dao.insertNote(Note.new("test2/2-1.md"))
dao.insertNote(Note.new("test1/1-3.md"))

dao.testing()


println(dao.isNoteExist("test1/1-1.md"))
println(dao.isNoteExist("test1/1-1.md2"))

}
}
17 changes: 9 additions & 8 deletions app/src/main/java/io/github/wiiznokes/gitnote/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@ class MainActivity : ComponentActivity() {
} else {
Log.d(TAG, "launch as EDIT_IS_UNSAVED")
Destination.App(
AppDestination.Edit(EditParams.Saved(
note = saveInfo.previousNote,
editType = saveInfo.editType,
name = saveInfo.name,
content = saveInfo.content
))
AppDestination.Edit(
EditParams.Saved(
note = saveInfo.previousNote,
editType = saveInfo.editType,
name = saveInfo.name,
content = saveInfo.content
)
)
)
}

} else Destination.App(AppDestination.Grid)
}
else Destination.Setup(SetupDestination.Main)
} else Destination.Setup(SetupDestination.Main)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import io.github.wiiznokes.gitnote.ui.model.Cred
import io.github.wiiznokes.gitnote.ui.model.CredType
import io.github.wiiznokes.gitnote.ui.model.NoteMinWidth
import io.github.wiiznokes.gitnote.ui.model.SortOrder
import io.github.wiiznokes.gitnote.ui.model.SortType
import io.github.wiiznokes.gitnote.ui.model.StorageConfiguration
import io.github.wiiznokes.gitnote.ui.theme.Theme
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -79,6 +78,7 @@ class AppPreferences(
password = userPassPassword.get()
)
}

CredType.Ssh -> Cred.Ssh(
username = this.sshUsername.get(),
publicKey = this.publicKey.get(),
Expand All @@ -95,20 +95,22 @@ class AppPreferences(
publicKey.update(cred.publicKey)
privateKey.update(cred.privateKey)
}

is Cred.UserPassPlainText -> {
credType.update(CredType.UserPassPlainText)
userPassUsername.update(cred.username)
userPassPassword.update(cred.password)
}

null -> credType.update(CredType.None)
}
}

val provider = enumPreference("provider", ProviderType.GitHub)

val sortType = enumPreference("sortType", SortType.Modification)

val sortOrder = enumPreference("sortOrder", SortOrder.Ascending)
val sortOrder = enumPreference("sortOrder", SortOrder.MostRecent)
val sortOrderFolder = enumPreference("sortOrderFolder", SortOrder.AZ)

val noteMinWidth = enumPreference("noteMinWidth", NoteMinWidth.Default)
val showFullNoteHeight = booleanPreference("showFullNoteHeight", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlin.io.path.deleteExisting
import kotlin.io.path.deleteRecursively
import kotlin.io.path.exists
import kotlin.io.path.extension
import kotlin.io.path.fileSize
import kotlin.io.path.forEachDirectoryEntry
import kotlin.io.path.getLastModifiedTime
import kotlin.io.path.isDirectory
Expand All @@ -44,6 +45,10 @@ sealed class NodeFs(
protected val pathFs: Path = Paths.get(path)
) {

fun fileSize(): Long {
return pathFs.fileSize()
}

fun lastModifiedTime(): FileTime {
return pathFs.getLastModifiedTime()
}
Expand Down
Loading