-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
658 additions
and
407 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
37 changes: 0 additions & 37 deletions
37
core/domain/src/main/kotlin/com/core/domain/usecase/AppSettingsUseCase.kt
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
core/domain/src/main/kotlin/com/core/domain/usecase/ApplyAppSettingsUseCase.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,57 @@ | ||
package com.core.domain.usecase | ||
|
||
import com.core.domain.repository.AppSettingsRepository | ||
import com.core.domain.repository.SecureSettingsRepository | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class ApplyAppSettingsUseCase @Inject constructor( | ||
private val appSettingsRepository: AppSettingsRepository, | ||
private val secureSettingsRepository: SecureSettingsRepository | ||
) { | ||
|
||
suspend operator fun invoke( | ||
packageName: String, | ||
onEmptyAppSettingsList: (String) -> Unit, | ||
onAppSettingsDisabled: (String) -> Unit, | ||
onAppSettingsNotSafeToWrite: (String) -> Unit, | ||
onApplied: (String) -> Unit, | ||
onSecurityException: (String) -> Unit, | ||
onFailure: (String?) -> Unit | ||
) { | ||
|
||
val appSettingsList = appSettingsRepository.getAppSettingsList(packageName).first() | ||
|
||
if (appSettingsList.isEmpty()) { | ||
|
||
onEmptyAppSettingsList("No settings found") | ||
|
||
return | ||
} | ||
|
||
if (appSettingsList.any { !it.enabled }) { | ||
|
||
onAppSettingsDisabled("Please enable atleast one setting") | ||
|
||
return | ||
} | ||
|
||
if (appSettingsList.any { !it.safeToWrite }) { | ||
|
||
onAppSettingsNotSafeToWrite("Applying settings that don't exist is not allowed. Please remove items highlighted as red") | ||
|
||
return | ||
} | ||
|
||
secureSettingsRepository.applySecureSettings(appSettingsList).onSuccess { applied -> | ||
if (applied) onApplied("Settings applied") | ||
else onFailure("Database failure") | ||
}.onFailure { t -> | ||
if (t is SecurityException) { | ||
onSecurityException("Permission not granted") | ||
} else { | ||
onFailure(t.localizedMessage) | ||
} | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
core/domain/src/main/kotlin/com/core/domain/usecase/RevertAppSettingsUseCase.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,57 @@ | ||
package com.core.domain.usecase | ||
|
||
import com.core.domain.repository.AppSettingsRepository | ||
import com.core.domain.repository.SecureSettingsRepository | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class RevertAppSettingsUseCase @Inject constructor( | ||
private val appSettingsRepository: AppSettingsRepository, | ||
private val secureSettingsRepository: SecureSettingsRepository | ||
) { | ||
|
||
suspend operator fun invoke( | ||
packageName: String, | ||
onEmptyAppSettingsList: (String) -> Unit, | ||
onAppSettingsDisabled: (String) -> Unit, | ||
onAppSettingsNotSafeToWrite: (String) -> Unit, | ||
onReverted: (String) -> Unit, | ||
onSecurityException: (String) -> Unit, | ||
onFailure: (String?) -> Unit | ||
) { | ||
|
||
val appSettingsList = appSettingsRepository.getAppSettingsList(packageName).first() | ||
|
||
if (appSettingsList.isEmpty()) { | ||
|
||
onEmptyAppSettingsList("No settings found") | ||
|
||
return | ||
} | ||
|
||
if (appSettingsList.any { !it.enabled }) { | ||
|
||
onAppSettingsDisabled("Please enable atleast one setting") | ||
|
||
return | ||
} | ||
|
||
if (appSettingsList.any { !it.safeToWrite }) { | ||
|
||
onAppSettingsNotSafeToWrite("Reverting settings that don't exist is not allowed. Please remove items highlighted as red") | ||
|
||
return | ||
} | ||
|
||
secureSettingsRepository.revertSecureSettings(appSettingsList).onSuccess { applied -> | ||
if (applied) onReverted("Settings reverted") | ||
else onFailure("Database failure") | ||
}.onFailure { t -> | ||
if (t is SecurityException) { | ||
onSecurityException("Permission not granted") | ||
} else { | ||
onFailure(t.localizedMessage) | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
core/domain/src/main/kotlin/com/core/domain/wrapper/BuildVersionWrapper.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.core.domain.wrapper | ||
|
||
interface BuildVersionWrapper { | ||
fun isAtLeastApi31(): Boolean | ||
fun isApi31Higher(): Boolean | ||
} |
Oops, something went wrong.