-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #424 from firemaples/refactor/restructure
Refactor basics, MainBar and ResultView
- Loading branch information
Showing
55 changed files
with
4,656 additions
and
1,309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# From https://mrmans0n.github.io/compose-rules/detekt/ | ||
Compose: | ||
ComposableAnnotationNaming: | ||
active: true | ||
ComposableNaming: | ||
active: true | ||
# -- You can optionally disable the checks in this rule for regex matches against the composable name (e.g. molecule presenters) | ||
# allowedComposableFunctionNames: .*Presenter,.*MoleculePresenter | ||
ComposableParamOrder: | ||
active: true | ||
# -- You can optionally have a list of types to be treated as lambdas (e.g. typedefs or fun interfaces not picked up automatically) | ||
# treatAsLambda: MyLambdaType | ||
CompositionLocalAllowlist: | ||
active: true | ||
# -- You can optionally define a list of CompositionLocals that are allowed here | ||
# allowedCompositionLocals: LocalSomething,LocalSomethingElse | ||
CompositionLocalNaming: | ||
active: true | ||
ContentEmitterReturningValues: | ||
active: true | ||
# -- You can optionally add your own composables here | ||
# contentEmitters: MyComposable,MyOtherComposable | ||
DefaultsVisibility: | ||
active: true | ||
ModifierClickableOrder: | ||
active: true | ||
# -- You can optionally add your own Modifier types | ||
# customModifiers: BananaModifier,PotatoModifier | ||
ModifierComposable: | ||
active: true | ||
# -- You can optionally add your own Modifier types | ||
# customModifiers: BananaModifier,PotatoModifier | ||
ModifierMissing: | ||
active: true | ||
# -- You can optionally control the visibility of which composables to check for here | ||
# -- Possible values are: `only_public`, `public_and_internal` and `all` (default is `only_public`) | ||
# checkModifiersForVisibility: only_public | ||
# -- You can optionally add your own Modifier types | ||
# customModifiers: BananaModifier,PotatoModifier | ||
ModifierNaming: | ||
active: true | ||
# -- You can optionally add your own Modifier types | ||
# customModifiers: BananaModifier,PotatoModifier | ||
ModifierNotUsedAtRoot: | ||
active: true | ||
# -- You can optionally add your own composables here | ||
# contentEmitters: MyComposable,MyOtherComposable | ||
# -- You can optionally add your own Modifier types | ||
# customModifiers: BananaModifier,PotatoModifier | ||
ModifierReused: | ||
active: true | ||
# -- You can optionally add your own Modifier types | ||
# customModifiers: BananaModifier,PotatoModifier | ||
ModifierWithoutDefault: | ||
active: true | ||
MultipleEmitters: | ||
active: true | ||
# -- You can optionally add your own composables here that will count as content emitters | ||
# contentEmitters: MyComposable,MyOtherComposable | ||
# -- You can add composables here that you don't want to count as content emitters (e.g. custom dialogs or modals) | ||
# contentEmittersDenylist: MyNonEmitterComposable | ||
MutableParams: | ||
active: true | ||
MutableStateParam: | ||
active: true | ||
PreviewAnnotationNaming: | ||
active: true | ||
PreviewPublic: | ||
active: true | ||
RememberMissing: | ||
active: true | ||
RememberContentMissing: | ||
active: true | ||
UnstableCollections: | ||
active: true | ||
ViewModelForwarding: | ||
active: true | ||
# -- You can optionally use this rule on things other than types ending in "ViewModel" or "Presenter" (which are the defaults). You can add your own via a regex here: | ||
# allowedStateHolderNames: .*ViewModel,.*Presenter | ||
# -- You can optionally add an allowlist for Composable names that won't be affected by this rule | ||
# allowedForwarding: .*Content,.*FancyStuff | ||
ViewModelInjection: | ||
active: true | ||
# -- You can optionally add your own ViewModel factories here | ||
# viewModelFactories: hiltViewModel,potatoViewModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
main/src/main/java/tw/firemaples/onscreenocr/CoreApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
main/src/main/java/tw/firemaples/onscreenocr/data/repo/PreferenceRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package tw.firemaples.onscreenocr.data.repo | ||
|
||
import android.graphics.Point | ||
import androidx.lifecycle.asFlow | ||
import com.chibatching.kotpref.livedata.asLiveData | ||
import tw.firemaples.onscreenocr.pref.AppPref | ||
import javax.inject.Inject | ||
|
||
class PreferenceRepository @Inject constructor() { | ||
fun saveLastMainBarPosition(x: Int, y: Int) { | ||
AppPref.lastMainBarPosition = Point(x, y) | ||
} | ||
|
||
fun getLastMainBarPosition(): Point = | ||
AppPref.lastMainBarPosition | ||
|
||
fun getShowTextSelectionOnResultView() = | ||
AppPref.asLiveData(AppPref::displaySelectedTextOnResultWindow).asFlow() | ||
|
||
fun setShowTextSelectionOnResultView(show: Boolean) { | ||
AppPref.displaySelectedTextOnResultWindow = show | ||
} | ||
|
||
fun getResultViewFontSize() = | ||
AppPref.asLiveData(AppPref::resultWindowFontSize).asFlow() | ||
|
||
fun setResultViewFontSize(fontSize: Float) { | ||
AppPref.resultWindowFontSize = fontSize | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
main/src/main/java/tw/firemaples/onscreenocr/data/repo/RecognitionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tw.firemaples.onscreenocr.data.repo | ||
|
||
import androidx.lifecycle.asFlow | ||
import com.chibatching.kotpref.livedata.asLiveData | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import tw.firemaples.onscreenocr.pref.AppPref | ||
import tw.firemaples.onscreenocr.recognition.TextRecognitionProviderType | ||
import tw.firemaples.onscreenocr.utils.Constants | ||
import javax.inject.Inject | ||
|
||
class RecognitionRepository @Inject constructor() { | ||
val ocrLanguage: Flow<String> | ||
get() = AppPref.asLiveData(AppPref::selectedOCRLang).asFlow() | ||
|
||
val ocrProvider: Flow<TextRecognitionProviderType> | ||
get() = AppPref.asLiveData(AppPref::selectedOCRProviderKey).asFlow() | ||
.map { key -> | ||
TextRecognitionProviderType.entries.firstOrNull { it.key == key } | ||
?: Constants.DEFAULT_OCR_PROVIDER | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
main/src/main/java/tw/firemaples/onscreenocr/data/repo/SettingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tw.firemaples.onscreenocr.data.repo | ||
|
||
import tw.firemaples.onscreenocr.pages.setting.SettingManager | ||
import javax.inject.Inject | ||
|
||
class SettingRepository @Inject constructor() { | ||
fun shouldRestoreMainBarPosition(): Boolean = | ||
SettingManager.restoreMainBarPosition | ||
|
||
fun hideOCRAreaAfterTranslated(): Boolean = | ||
SettingManager.hideRecognizedResultAfterTranslated | ||
} |
17 changes: 17 additions & 0 deletions
17
main/src/main/java/tw/firemaples/onscreenocr/data/repo/TranslatorRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package tw.firemaples.onscreenocr.data.repo | ||
|
||
import androidx.lifecycle.asFlow | ||
import com.chibatching.kotpref.livedata.asLiveData | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
import tw.firemaples.onscreenocr.pref.AppPref | ||
import tw.firemaples.onscreenocr.translator.TranslationProviderType | ||
import javax.inject.Inject | ||
|
||
class TranslatorRepository @Inject constructor() { | ||
val currentProviderType: Flow<TranslationProviderType> | ||
get() = AppPref.asLiveData(AppPref::selectedTranslationProvider).asFlow() | ||
.map { TranslationProviderType.fromKey(it) } | ||
val currentTranslationLang: Flow<String> | ||
get() = AppPref.asLiveData(AppPref::selectedTranslationLang).asFlow() | ||
} |
16 changes: 16 additions & 0 deletions
16
...c/main/java/tw/firemaples/onscreenocr/data/usecase/GetCurrentOCRDisplayLangCodeUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import kotlinx.coroutines.flow.combine | ||
import tw.firemaples.onscreenocr.data.repo.RecognitionRepository | ||
import tw.firemaples.onscreenocr.recognition.TextRecognizer | ||
import javax.inject.Inject | ||
|
||
class GetCurrentOCRDisplayLangCodeUseCase @Inject constructor( | ||
private val recognitionRepository: RecognitionRepository, | ||
) { | ||
operator fun invoke() = | ||
recognitionRepository.ocrProvider | ||
.combine(recognitionRepository.ocrLanguage) { provider, lang -> | ||
TextRecognizer.getRecognizer(provider).parseToDisplayLangCode(lang) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
main/src/main/java/tw/firemaples/onscreenocr/data/usecase/GetCurrentOCRLangUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import kotlinx.coroutines.flow.combine | ||
import tw.firemaples.onscreenocr.data.repo.RecognitionRepository | ||
import javax.inject.Inject | ||
|
||
class GetCurrentOCRLangUseCase @Inject constructor( | ||
private val recognitionRepository: RecognitionRepository, | ||
) { | ||
operator fun invoke() = | ||
combine( | ||
recognitionRepository.ocrProvider, | ||
recognitionRepository.ocrLanguage, | ||
) { provider, lang -> provider to lang } | ||
} |
10 changes: 10 additions & 0 deletions
10
.../src/main/java/tw/firemaples/onscreenocr/data/usecase/GetCurrentTranslationLangUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import tw.firemaples.onscreenocr.data.repo.TranslatorRepository | ||
import javax.inject.Inject | ||
|
||
class GetCurrentTranslationLangUseCase @Inject constructor( | ||
private val translatorRepository: TranslatorRepository, | ||
) { | ||
operator fun invoke() = translatorRepository.currentTranslationLang | ||
} |
10 changes: 10 additions & 0 deletions
10
main/src/main/java/tw/firemaples/onscreenocr/data/usecase/GetCurrentTranslatorTypeUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import tw.firemaples.onscreenocr.data.repo.TranslatorRepository | ||
import javax.inject.Inject | ||
|
||
class GetCurrentTranslatorTypeUseCase @Inject constructor( | ||
private val translatorRepository: TranslatorRepository, | ||
) { | ||
operator fun invoke() = translatorRepository.currentProviderType | ||
} |
10 changes: 10 additions & 0 deletions
10
...ain/java/tw/firemaples/onscreenocr/data/usecase/GetHidingOCRAreaAfterTranslatedUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import tw.firemaples.onscreenocr.data.repo.SettingRepository | ||
import javax.inject.Inject | ||
|
||
class GetHidingOCRAreaAfterTranslatedUseCase @Inject constructor( | ||
private val settingRepository: SettingRepository, | ||
) { | ||
operator fun invoke() = settingRepository.hideOCRAreaAfterTranslated() | ||
} |
16 changes: 16 additions & 0 deletions
16
.../src/main/java/tw/firemaples/onscreenocr/data/usecase/GetMainBarInitialPositionUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import android.graphics.Point | ||
import tw.firemaples.onscreenocr.data.repo.PreferenceRepository | ||
import tw.firemaples.onscreenocr.data.repo.SettingRepository | ||
import javax.inject.Inject | ||
|
||
class GetMainBarInitialPositionUseCase @Inject constructor( | ||
private val settingRepository: SettingRepository, | ||
private val preferenceRepository: PreferenceRepository, | ||
) { | ||
operator fun invoke() = | ||
if (settingRepository.shouldRestoreMainBarPosition()) | ||
preferenceRepository.getLastMainBarPosition() | ||
else Point(0, 0) | ||
} |
10 changes: 10 additions & 0 deletions
10
main/src/main/java/tw/firemaples/onscreenocr/data/usecase/GetResultViewFontSizeUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import tw.firemaples.onscreenocr.data.repo.PreferenceRepository | ||
import javax.inject.Inject | ||
|
||
class GetResultViewFontSizeUseCase @Inject constructor( | ||
private val preferenceRepository: PreferenceRepository, | ||
) { | ||
operator fun invoke() = preferenceRepository.getResultViewFontSize() | ||
} |
10 changes: 10 additions & 0 deletions
10
...ain/java/tw/firemaples/onscreenocr/data/usecase/GetShowTextSelectorOnResultViewUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package tw.firemaples.onscreenocr.data.usecase | ||
|
||
import tw.firemaples.onscreenocr.data.repo.PreferenceRepository | ||
import javax.inject.Inject | ||
|
||
class GetShowTextSelectorOnResultViewUseCase @Inject constructor( | ||
private val preferenceRepository: PreferenceRepository, | ||
) { | ||
operator fun invoke() = preferenceRepository.getShowTextSelectionOnResultView() | ||
} |
Oops, something went wrong.