Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/dark-mode-button-initial-state
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtavis authored Jan 24, 2025
2 parents 5e7a722 + db94d03 commit 780177d
Show file tree
Hide file tree
Showing 89 changed files with 777 additions and 216 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ git remote add upstream https://github.com/scribe-org/Scribe-Android.git
- Press the play button marked "Run App"
- From here code edits that are made will be reflected in the app each time it is ran

> [!IMPORTANT]
> If you're not seeing your changes or are experiencing issues when running the app, consider clearing the Android Studio cache. This can be done via `File` > `Invalidate Caches...` in the menu. You can then select options for which caches to invalidate and then select `Invalidate and Restart` restart Android Studio so the changes are reflected.
>
> Please note that you may also need to remake your emulator device from time to time. The team generally develops on emulators for the latest Pixel phones.
> [!NOTE]
> Currently Scribe-Android does not work as a floating keyboard.
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ git remote add upstream https://github.com/scribe-org/Scribe-Android.git
- Press the play button marked "Run App"
- From here code edits that are made will be reflected in the app each time it is ran.

> [!NOTE]
> Currently Scribe-Android does not work as a floating keyboard.
> [!IMPORTANT]
> If you're not seeing your changes or are experiencing issues when running the app, consider clearing the Android Studio cache. This can be done via `File` > `Invalidate Caches...` in the menu. You can then select options for which caches to invalidate and then select `Invalidate and Restart` restart Android Studio so the changes are reflected.
>
> Please note that you may also need to remake your emulator device from time to time. The team generally develops on emulators for the latest Pixel phones.
After activating your emulator, consider setting up [pre-commit](https://pre-commit.com/) to fix common errors in the codebase before they're committed by running:

Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins {
id("de.mannodermaus.android-junit5") version "1.11.2.0"
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0"
id("jacoco")
kotlin("plugin.serialization") version "1.9.0"
}

jacoco {
Expand Down Expand Up @@ -247,6 +248,7 @@ dependencies {
api("com.google.code.gson:gson:2.10.1")
api("com.github.bumptech.glide:glide:4.14.2")
ksp("com.github.bumptech.glide:ksp:4.14.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
}

tasks.register<Copy>("moveFromi18n") {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/assets/data-contracts/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
},
"3": {
"title": "Perfekt",
"1": { "ich": "" },
"2": { "du": "" },
"3": { "er/sie/es": "" },
"4": { "wir": "" },
"5": { "ihr": "" },
"6": { "sie/Sie": "" }
"1": { "ich": "[auxiliaryVerb] pastParticiple" },
"2": { "du": "[auxiliaryVerb] pastParticiple" },
"3": { "er/sie/es": "[auxiliaryVerb] pastParticiple" },
"4": { "wir": "[auxiliaryVerb] pastParticiple" },
"5": { "ihr": "[auxiliaryVerb] pastParticiple" },
"6": { "sie/Sie": "[auxiliaryVerb] pastParticiple" }
}
}
}
53 changes: 40 additions & 13 deletions app/src/main/assets/data-contracts/en.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
{
"numbers": { "singular": "plural" },
"genders": {
"canonical": [],
"feminines": [],
"masculines": [],
"commons": [],
"neuters": []
"genders": {
"canonical": ["NOT_INCLUDED"],
"feminines": ["NOT_INCLUDED"],
"masculines": ["NOT_INCLUDED"],
"commons": ["NOT_INCLUDED"],
"neuters": ["NOT_INCLUDED"]
},
"conjugations": {
"1": {
"title": "",
"1": "",
"2": "",
"3": "",
"4": "",
"5": "",
"6": ""
"title": "Present",
"1": { "I": "simplePresent" },
"2": { "you": "simplePresent" },
"3": { "he/she/it": "simplePresentThirdPersonSingular" },
"4": { "we": "simplePresent" },
"5": { "you all": "simplePresent" },
"6": { "they": "simplePresent" }
},
"2": {
"title": "Past",
"1": { "I": "simplePast" },
"2": { "you": "simplePast" },
"3": { "he/she/it": "simplePast" },
"4": { "we": "simplePast" },
"5": { "you all": "simplePast" },
"6": { "they": "simplePast" }
},
"3": {
"title": "Perfect",
"1": { "I": "presentParticiple simplePast" },
"2": { "you": "presentParticiple simplePast" },
"3": { "he/she/it": "presentParticiple simplePast" },
"4": { "we": "presentParticiple simplePast" },
"5": { "you all": "presentParticiple simplePast" },
"6": { "they": "presentParticiple simplePast" }
},
"4": {
"title": "Past Perfect",
"1": { "I": "pastParticiple simplePast" },
"2": { "you": "pastParticiple simplePast" },
"3": { "he/she/it": "pastParticiple simplePast" },
"4": { "we": "pastParticiple simplePast" },
"5": { "you all": "pastParticiple simplePast" },
"6": { "they": "pastParticiple simplePast" }
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/App.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Handles application-level initialization and sets the default night mode based on user configuration.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/activities/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Implements the main activity with a custom action bar, ViewPager navigation, and dynamic UI adjustments.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/CommonsContext.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Functions and properties for accessing shared preferences and BaseConfig.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/Context.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Functions for retrieving configuration settings and calculating color based on theme and background preferences.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/ContextStyling.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Functions for determining and retrieving proper text and colors based on user settings.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/Drawable.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Extends the Drawable class to apply a color filter to a drawable using a specified color.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/Int.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Functions for manipulating colors used within the application.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/RecyclerView.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Adds a custom item decoration (divider) to a RecyclerView, using a specified drawable and custom margins.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/View.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Utility functions for managing visibility and haptic feedback in Android views.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* A test class to prepare for application testing.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/helpers/BaseConfig.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* A configuration helper class for managing app settings.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/helpers/CommonsConstants.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Common constants that are used throughout helper classes and objects.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/helpers/Config.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* A class that extends BaseConfig to manage additional app settings.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/helpers/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Constants that are used throughout helper classes and objects.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/helpers/CustomAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* A RecyclerView adapter that supports multiple view types.
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/be/scri/helpers/DatabaseFileManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package be.scri.helpers

import android.content.Context
import android.util.Log
import java.io.FileOutputStream

class DatabaseFileManager(
private val context: Context,
) {
fun loadDatabaseFile(language: String) {
val databaseName = "${language}LanguageData.sqlite"
val dbFile = context.getDatabasePath(databaseName)
Log.i("ALPHA", "Loaded Database")

if (!dbFile.exists()) {
context.assets.open("data/$databaseName").use { inputStream ->
FileOutputStream(dbFile).use { outputStream ->
inputStream.copyTo(outputStream)
outputStream.flush()
}
}
}
}
}
99 changes: 32 additions & 67 deletions app/src/main/java/be/scri/helpers/DatabaseHelper.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* A helper to facilitate database calls for Scribe keyboard commands.
Expand All @@ -7,16 +7,19 @@
package be.scri.helpers

import android.content.Context
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream

class DatabaseHelper(
private val context: Context,
) : SQLiteOpenHelper(context, null, null, DATABASE_VERSION) {
context: Context,
) : SQLiteOpenHelper(
context,
null,
null,
DATABASE_VERSION,
) {
private val dbManagers = DatabaseManagers(context)

companion object {
private const val DATABASE_VERSION = 1
}
Expand All @@ -34,66 +37,28 @@ class DatabaseHelper(
}

fun loadDatabase(language: String) {
val databaseName = "${language}LanguageData.sqlite"
val dbFile = context.getDatabasePath(databaseName)
if (!dbFile.exists()) {
val inputStream: InputStream = context.assets.open("data/$databaseName")
val outputStream: OutputStream = FileOutputStream(dbFile)

inputStream.copyTo(outputStream)

outputStream.flush()
outputStream.close()
inputStream.close()
}
}

fun getEmojiKeywords(language: String): HashMap<String, MutableList<String>> {
val hashMap = HashMap<String, MutableList<String>>()
val dbFile = context.getDatabasePath("${language}LanguageData.sqlite")
val db = SQLiteDatabase.openDatabase(dbFile.path, null, SQLiteDatabase.OPEN_READONLY)
val cursor = db.rawQuery("SELECT * FROM emoji_keywords", null)

cursor.use {
if (cursor.moveToFirst()) {
do {
val key = cursor.getString(0)
hashMap[key] = getEmojiKeyMaps(cursor)
} while (cursor.moveToNext())
}
}
return hashMap
dbManagers.fileManager.loadDatabaseFile(language)
}

fun getEmojiKeyMaps(cursor: Cursor): MutableList<String> {
val values = mutableListOf<String>()

for (i in 1 until cursor.columnCount) {
values.add(cursor.getString(i))
}
return values
}

fun getNounKeywords(language: String): HashMap<String, MutableList<String>> {
val hashMap = HashMap<String, MutableList<String>>()
val dbFile = context.getDatabasePath("${language}LanguageData.sqlite")
val db = SQLiteDatabase.openDatabase(dbFile.path, null, SQLiteDatabase.OPEN_READONLY)
val cursor = db.rawQuery("SELECT * FROM nouns", null)

cursor.use {
if (cursor.moveToFirst()) {
do {
val key = cursor.getString(0).lowercase()
hashMap[key] = getNounKeyMaps(cursor)
} while (cursor.moveToNext())
}
}
return hashMap
}

fun getNounKeyMaps(cursor: Cursor): MutableList<String> {
val values = mutableListOf<String>()
values.add(cursor.getString(2))
return values
}
fun getRequiredData(language: String): DataContract? =
dbManagers.contractLoader.loadContract(
language,
)

fun getEmojiKeywords(language: String): HashMap<String, MutableList<String>> =
dbManagers.emojiManager.getEmojiKeywords(
language,
)

fun findGenderOfWord(language: String): HashMap<String, List<String>> =
dbManagers.genderManager.findGenderOfWord(
language,
getRequiredData(language),
)

fun checkIfWordIsPlural(language: String): List<String>? =
dbManagers.pluralManager.checkIfWordIsPlural(
language,
getRequiredData(language),
)
}
17 changes: 17 additions & 0 deletions app/src/main/java/be/scri/helpers/DatabaseManagers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package be.scri.helpers

import ContractDataLoader
import EmojiDataManager
import GenderDataManager
import PluralFormsManager
import android.content.Context

class DatabaseManagers(
context: Context,
) {
val fileManager = DatabaseFileManager(context)
val contractLoader = ContractDataLoader(context)
val emojiManager = EmojiDataManager(context)
val genderManager = GenderDataManager(context)
val pluralManager = PluralFormsManager(context)
}
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/helpers/HintUtils.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* A helper to facilitate resetting application hints if the user would like to see them again.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/helpers/KeyboardBase.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

/**
* Custom keyboard implementation for handling keyboard layouts, rows and keys with XML-based configuration.
Expand Down
Loading

0 comments on commit 780177d

Please sign in to comment.