Skip to content

Commit

Permalink
updated some libs and some refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Oct 5, 2024
1 parent 5a222b4 commit f60fd52
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 85 deletions.
7 changes: 0 additions & 7 deletions app/src/main/java/io/github/yamin8000/owl/core/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@
package io.github.yamin8000.owl.core

import android.app.Application
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import dagger.hilt.android.HiltAndroidApp

internal val Context.historyDataStore: DataStore<Preferences> by preferencesDataStore(name = "history")
internal val Context.favouritesDataStore: DataStore<Preferences> by preferencesDataStore(name = "favourites")

@HiltAndroidApp
internal class App : Application()
4 changes: 1 addition & 3 deletions common/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
<manifest />
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.twotone.ArrowBack
import androidx.compose.material.icons.twotone.Delete
import androidx.compose.material.ripple.rememberRipple
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TTS(
fun createEngine(tag: String = languageTag) {
tts = TextToSpeech(context) {
if (it == TextToSpeech.SUCCESS) {
tts?.setLanguage(Locale.forLanguageTag(tag))
tts?.language = Locale.forLanguageTag(tag)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class SettingsDatastoreRepository(
}

override suspend fun getIsVibrating(): Boolean {
return getBool(SettingsKeys.IS_VIBRATING) ?: true
return getBool(SettingsKeys.IS_VIBRATING) != false
}

override suspend fun setIsVibrating(value: Boolean) {
setBool(SettingsKeys.IS_VIBRATING, value)
}

override suspend fun getIsStartingBlank(): Boolean {
return getBool(SettingsKeys.IS_STARTING_BLANK) ?: true
return getBool(SettingsKeys.IS_STARTING_BLANK) != false
}

override suspend fun setIsStartingBlank(value: Boolean) {
Expand Down
4 changes: 1 addition & 3 deletions feature_favourites/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
<manifest />
4 changes: 1 addition & 3 deletions feature_history/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
<manifest />
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class TermSuggesterRepositoryImpl(
private val dao: DAOs.TermDao,
private val app: Application
) : TermSuggesterRepository {
private val DEFAULT_N_GRAM_SIZE = 3
private val NOT_WORD_CHARS_REGEX = Regex("\\W+")
private val defaultNGramSize = 3
private val notWordsRegex = Regex("\\W+")

override suspend fun suggestTerms(searchTerm: String): List<String> {
items = items.plus(getOldSearchData())

val term = searchTerm.lowercase().replace(NOT_WORD_CHARS_REGEX, "")
val term = searchTerm.lowercase().replace(notWordsRegex, "")
val nGramSize = nGramSizeProvider(term)
if (items.contains(term)) return listOf(term)
val searchTermGrams = term.windowed(nGramSize)
Expand All @@ -68,7 +68,7 @@ class TermSuggesterRepositoryImpl(
.bufferedReader()
.use { it.readText() }
.split(',')
.map { it.replace(NOT_WORD_CHARS_REGEX, "") }
.map { it.replace(notWordsRegex, "") }
} catch (e: NotFoundException) {
listOf()
}
Expand Down Expand Up @@ -108,11 +108,11 @@ class TermSuggesterRepositoryImpl(

private fun nGramSizeProvider(
searchTerm: String
) = if (searchTerm.length > DEFAULT_N_GRAM_SIZE) {
val size = ceil(searchTerm.length.toFloat() / DEFAULT_N_GRAM_SIZE).roundToInt()
if (size < DEFAULT_N_GRAM_SIZE) DEFAULT_N_GRAM_SIZE
) = if (searchTerm.length > defaultNGramSize) {
val size = ceil(searchTerm.length.toFloat() / defaultNGramSize).roundToInt()
if (size < defaultNGramSize) defaultNGramSize
else size
} else DEFAULT_N_GRAM_SIZE
} else defaultNGramSize

private suspend fun getOldSearchData() = dao.all().map { it.word }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package io.github.yamin8000.owl.feature_settings.ui

import android.content.Context
import android.os.Build
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -48,6 +49,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.style.TextAlign
Expand Down Expand Up @@ -262,11 +264,12 @@ private fun ThemeSetting(
SettingsItem(
onClick = onShowDialog,
content = {
val context = LocalContext.current
Icon(
imageVector = Icons.TwoTone.DisplaySettings,
contentDescription = stringResource(R.string.theme)
)
PersianText(text = theme.toString())
PersianText(text = theme.toStringResource(context))
}
)
if (theme == ThemeType.System && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
Expand Down Expand Up @@ -316,16 +319,16 @@ private fun ThemeChangerDialog(
onClick = onThemeClick
),
content = {
val context = LocalContext.current
RadioButton(
selected = theme == currentTheme,
onClick = null,
modifier = Modifier.padding(start = 8.dp)
)
PersianText(
text = theme.toString(),
text = theme.toStringResource(context),
modifier = Modifier.padding(vertical = 16.dp)
)

}
)
}
Expand All @@ -344,4 +347,13 @@ private fun DynamicThemeNotice(
text = stringResource(R.string.dynamic_theme_notice),
textAlign = TextAlign.Justify
)
}

private fun ThemeType.toStringResource(
context: Context
) = when (this) {
ThemeType.Dark -> context.getString(R.string.theme_dark)
ThemeType.Darker -> context.getString(R.string.theme_oled)
ThemeType.Light -> context.getString(R.string.theme_light)
ThemeType.System -> context.getString(R.string.theme_system)
}
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
activityCompose = "1.9.2"
composeLibs = "1.7.2"
composeLibs = "1.7.3"
coreKtx = "1.13.1"
coreSplashscreen = "1.0.1"
datastorePreferences = "1.1.1"
Expand All @@ -11,9 +11,9 @@ lifecycleViewmodelCompose = "2.8.6"
lottieCompose = "6.5.2"
material3 = "1.3.0"
moshi = "1.15.1"
navigationCompose = "2.8.1"
navigationCompose = "2.8.2"
kotlin = "2.0.20"
android-application = "8.6.1"
android-application = "8.7.0"
ksp = "2.0.20-1.0.24"
retrofit = "2.11.0"
room = "2.6.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ package io.github.yamin8000.owl.search.data.datasource.local.entity
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey

import androidx.room.PrimaryKey

@Entity(
Expand Down

0 comments on commit f60fd52

Please sign in to comment.