Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
hoanganhtuan95ptit committed Aug 18, 2024
1 parent 80fc326 commit a9fb907
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 31 deletions.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
32 changes: 16 additions & 16 deletions constant/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,26 @@ project.ext {

hoanganhtuan95Dependencies = [

base : "com.github.hoanganhtuan95ptit.core:base:1.1.15",
android : "com.github.hoanganhtuan95ptit.core:android:1.1.15",
base : "com.github.hoanganhtuan95ptit.core:base:1.1.16",
android : "com.github.hoanganhtuan95ptit.core:android:1.1.16",

task : "com.github.hoanganhtuan95ptit.core:task:1.1.15",
state : "com.github.hoanganhtuan95ptit.core:state:1.1.15",
image : "com.github.hoanganhtuan95ptit.core:image:1.1.15",
adapter : "com.github.hoanganhtuan95ptit.core:adapter:1.1.15",
task : "com.github.hoanganhtuan95ptit.core:task:1.1.16",
state : "com.github.hoanganhtuan95ptit.core:state:1.1.16",
image : "com.github.hoanganhtuan95ptit.core:image:1.1.16",
adapter : "com.github.hoanganhtuan95ptit.core:adapter:1.1.16",

analytics : "com.github.hoanganhtuan95ptit.core:analytics:1.1.15",
analytics_log : "com.github.hoanganhtuan95ptit.core:analytics-log:1.1.15",
// analytics_firebase : "com.github.hoanganhtuan95ptit.core:analytics-firebase:1.1.15",
analytics : "com.github.hoanganhtuan95ptit.core:analytics:1.1.16",
analytics_log : "com.github.hoanganhtuan95ptit.core:analytics-log:1.1.16",
analytics_firebase : "com.github.hoanganhtuan95ptit.core:analytics-firebase:1.1.16",

crashlytics : "com.github.hoanganhtuan95ptit.core:crashlytics:1.1.15",
// crashlytics_log : "com.github.hoanganhtuan95ptit.core:crashlytics-log:1.1.15",
// crashlytics_firebase: "com.github.hoanganhtuan95ptit.core:crashlytics-firebase:1.1.15",
crashlytics : "com.github.hoanganhtuan95ptit.core:crashlytics:1.1.16",
crashlytics_log : "com.github.hoanganhtuan95ptit.core:crashlytics-log:1.1.16",
crashlytics_firebase: "com.github.hoanganhtuan95ptit.core:crashlytics-firebase:1.1.16",

detect : "com.github.hoanganhtuan95ptit.core:detect:1.1.15",
// detect_mlkit : "com.github.hoanganhtuan95ptit.core:detect-mlkit:1.1.15",
detect : "com.github.hoanganhtuan95ptit.core:detect:1.1.16",
detect_mlkit : "com.github.hoanganhtuan95ptit.core:detect-mlkit:1.1.16",

translate : "com.github.hoanganhtuan95ptit.core:translate:1.1.15",
// translate_mlkit : "com.github.hoanganhtuan95ptit.core:translate-mlkit:1.1.15"
translate : "com.github.hoanganhtuan95ptit.core:translate:1.1.16",
translate_mlkit : "com.github.hoanganhtuan95ptit.core:translate-mlkit:1.1.16"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.simple.detect.mlkit.data.tasks

import com.simple.detect.data.tasks.DetectStateTask
import com.simple.detect.entities.DetectProvider
import com.simple.detect.entities.DetectState
import com.simple.detect.mlkit.data.tasks.lanugage.LanguageDetectStateTask
import com.simple.state.toSuccess
import com.simple.task.LowException
Expand All @@ -11,12 +12,10 @@ class MlkitDetectStateTask(
val list: List<LanguageDetectStateTask>
) : DetectStateTask {

override suspend fun executeTask(param: DetectStateTask.Param): Pair<String, Int> {

val provider = DetectProvider.OFFLINE.value
override suspend fun executeTask(param: DetectStateTask.Param): Pair<DetectProvider, DetectState> {

val state = list.executeAsyncByFast(LanguageDetectStateTask.Param(param.languageCode)).toSuccess()?.data ?: throw LowException("")

return provider to state
return DetectProvider.OFFLINE to state
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.simple.detect.mlkit.data.tasks.lanugage

import com.simple.detect.entities.DetectState
import com.simple.task.LowException
import com.simple.task.Task

abstract class LanguageDetectStateTask : Task<LanguageDetectStateTask.Param, Int>, LanguageSupportTask {
abstract class LanguageDetectStateTask : Task<LanguageDetectStateTask.Param, DetectState>, LanguageSupportTask {

override suspend fun executeTask(param: Param): Int {
override suspend fun executeTask(param: Param): DetectState {

return if (!checkSupport(param.languageCode)) {
throw LowException("")
} else {
1
DetectState.READY
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.simple.detect.data.tasks

import com.simple.detect.entities.DetectProvider
import com.simple.detect.entities.DetectState
import com.simple.task.Task

interface DetectStateTask : Task<DetectStateTask.Param, Pair<String, Int>> {
interface DetectStateTask : Task<DetectStateTask.Param, Pair<DetectProvider, DetectState>> {

data class Param(val languageCode: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@ import com.google.mlkit.nl.translate.TranslateLanguage
import com.google.mlkit.nl.translate.TranslateRemoteModel
import com.simple.state.ResultState
import com.simple.translate.data.tasks.TranslateStateTask
import com.simple.translate.entities.TranslateProvider
import com.simple.translate.entities.TranslateState
import com.simple.translate.mlkit.utils.exts.checkModelDownloaded

class MlkitTranslateStateTask : TranslateStateTask {

override suspend fun executeTask(param: TranslateStateTask.Param): Int {
override suspend fun executeTask(param: TranslateStateTask.Param): Pair<TranslateProvider, TranslateState> {

return if (param.languageCode !in TranslateLanguage.getAllLanguages()) {
val state = if (param.languageCode !in TranslateLanguage.getAllLanguages()) {

-1
TranslateState.NO_SUPPORT
} else {

checkDownloadModel(param.languageCode)
}

return TranslateProvider.OFFLINE to state
}

private suspend fun checkDownloadModel(languageCode: String): Int {
private suspend fun checkDownloadModel(languageCode: String): TranslateState {

val state = TranslateRemoteModel.Builder(languageCode).build().checkModelDownloaded()

return if (state is ResultState.Success) {

if (state.data) 1 else 0
if (state.data) TranslateState.READY else TranslateState.NOT_READY
} else {

-1
TranslateState.NO_SUPPORT
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.simple.translate.data.tasks

import com.simple.task.Task
import com.simple.translate.entities.TranslateProvider
import com.simple.translate.entities.TranslateState

interface TranslateStateTask : Task<TranslateStateTask.Param, Int> {
interface TranslateStateTask : Task<TranslateStateTask.Param, Pair<TranslateProvider, TranslateState>> {

data class Param(val languageCode: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.simple.translate.entities

enum class TranslateState(val value: Int) {

READY(1),
NOT_READY(0),
NO_SUPPORT(-1)
}

enum class TranslateProvider(val value: String) {

ONLINE("ONLINE"),
OFFLINE("OFFLINE");
}

0 comments on commit a9fb907

Please sign in to comment.