-
Notifications
You must be signed in to change notification settings - Fork 14
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
54 changed files
with
2,123 additions
and
205 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
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
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
21 changes: 21 additions & 0 deletions
21
app/src/main/java/ua/polodarb/gmsflags/data/databases/local/AppDatabase.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,21 @@ | ||
package ua.polodarb.gmsflags.data.databases.local | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import ua.polodarb.gmsflags.data.databases.local.dao.FlagsDAO | ||
import ua.polodarb.gmsflags.data.databases.local.dao.PackagesDAO | ||
import ua.polodarb.gmsflags.data.databases.local.enities.SavedFlags | ||
import ua.polodarb.gmsflags.data.databases.local.enities.SavedPackages | ||
|
||
|
||
@Database( | ||
entities = [SavedPackages::class, SavedFlags::class], | ||
version = 1 | ||
) | ||
abstract class AppDatabase : RoomDatabase() { | ||
|
||
abstract fun packagesDao(): PackagesDAO | ||
|
||
abstract fun flagsDao(): FlagsDAO | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/ua/polodarb/gmsflags/data/databases/local/dao/FlagsDAO.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,26 @@ | ||
package ua.polodarb.gmsflags.data.databases.local.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import kotlinx.coroutines.flow.Flow | ||
import ua.polodarb.gmsflags.data.databases.local.enities.SavedFlags | ||
import ua.polodarb.gmsflags.data.databases.local.enities.SavedPackages | ||
|
||
@Dao | ||
interface FlagsDAO { | ||
|
||
@Query("SELECT * FROM saved_flags") | ||
fun getSavedFlags(): Flow<List<SavedFlags>> | ||
|
||
@Insert(entity = SavedFlags::class, onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun saveFlag(flagName: SavedFlags) | ||
|
||
@Query("DELETE FROM saved_flags WHERE flag_name = :flagName AND pkg_name = :pkgName") | ||
suspend fun deleteSavedFlag(flagName: String, pkgName: String) | ||
|
||
@Query("DELETE FROM saved_flags") | ||
fun deleteAllSavedFlags() | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/ua/polodarb/gmsflags/data/databases/local/dao/PackagesDAO.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,25 @@ | ||
package ua.polodarb.gmsflags.data.databases.local.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import kotlinx.coroutines.flow.Flow | ||
import ua.polodarb.gmsflags.data.databases.local.enities.SavedPackages | ||
|
||
@Dao | ||
interface PackagesDAO { | ||
|
||
@Query("SELECT * FROM saved_packages") | ||
fun getSavedPackages(): Flow<List<String>> | ||
|
||
@Insert(entity = SavedPackages::class, onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun savePackage(pkgName: SavedPackages) | ||
|
||
@Query("DELETE FROM saved_packages WHERE pkg_name = :pkgName") | ||
suspend fun deleteSavedPackage(pkgName: String) | ||
|
||
@Query("DELETE FROM saved_packages") | ||
fun deleteAllSavedPackages() | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/ua/polodarb/gmsflags/data/databases/local/enities/SavedFlags.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,13 @@ | ||
package ua.polodarb.gmsflags.data.databases.local.enities | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "saved_flags") | ||
data class SavedFlags( | ||
@ColumnInfo(name = "pkg_name") val pkgName: String, | ||
@ColumnInfo(name = "flag_name") val flagName: String, | ||
@ColumnInfo(name = "flag_type") val type: String, | ||
@PrimaryKey(autoGenerate = true) val id: Int = 0 | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/ua/polodarb/gmsflags/data/databases/local/enities/SavedPackages.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 ua.polodarb.gmsflags.data.databases.local.enities | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "saved_packages") | ||
data class SavedPackages( | ||
@PrimaryKey @ColumnInfo(name = "pkg_name") val pkgName: String | ||
) |
3 changes: 1 addition & 2 deletions
3
.../gmsflags/data/repo/DatabaseRepository.kt → ...arb/gmsflags/data/repo/GmsDBRepository.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
43 changes: 43 additions & 0 deletions
43
app/src/main/java/ua/polodarb/gmsflags/data/repo/RoomDBRepository.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,43 @@ | ||
package ua.polodarb.gmsflags.data.repo | ||
|
||
import android.util.Log | ||
import kotlinx.coroutines.flow.flow | ||
import ua.polodarb.gmsflags.data.databases.local.dao.FlagsDAO | ||
import ua.polodarb.gmsflags.data.databases.local.dao.PackagesDAO | ||
import ua.polodarb.gmsflags.data.databases.local.enities.SavedFlags | ||
import ua.polodarb.gmsflags.data.databases.local.enities.SavedPackages | ||
|
||
class RoomDBRepository( | ||
private val savedPackagesDao: PackagesDAO, | ||
private val savedFlagsDao: FlagsDAO | ||
) { | ||
|
||
suspend fun getSavedPackages() = flow<List<String>> { | ||
savedPackagesDao.getSavedPackages().collect { | ||
emit(it) | ||
} | ||
} | ||
|
||
suspend fun deleteSavedPackage(pkgName: String) { | ||
savedPackagesDao.deleteSavedPackage(pkgName) | ||
} | ||
|
||
suspend fun savePackage(pkgName: String) { | ||
savedPackagesDao.savePackage(SavedPackages(pkgName)) | ||
} | ||
|
||
suspend fun getSavedFlags() = flow { | ||
savedFlagsDao.getSavedFlags().collect { | ||
emit(it) | ||
} | ||
} | ||
|
||
suspend fun deleteSavedFlag(flagName: String, pkgName: String) { | ||
savedFlagsDao.deleteSavedFlag(flagName, pkgName) | ||
} | ||
|
||
suspend fun saveFlag(flagName: String, pkgName: String, flagType: String) { | ||
savedFlagsDao.saveFlag(SavedFlags(pkgName, flagName, flagType)) | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/ua/polodarb/gmsflags/data/repo/SettingsRepository.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,34 @@ | ||
package ua.polodarb.gmsflags.data.repo | ||
|
||
import android.content.Context | ||
import ua.polodarb.gmsflags.GMSApplication | ||
import ua.polodarb.gmsflags.data.databases.local.dao.FlagsDAO | ||
import ua.polodarb.gmsflags.data.databases.local.dao.PackagesDAO | ||
|
||
class SettingsRepository( | ||
private val context: Context, | ||
private val flagsDao: FlagsDAO, | ||
private val packagesDAO: PackagesDAO | ||
) { | ||
|
||
private val gmsApplication = context as GMSApplication | ||
|
||
// GMS Database | ||
fun deleteAllOverriddenFlagsFromGMS() { | ||
gmsApplication.getRootDatabase().deleteAllOverriddenFlagsFromGMS() | ||
} | ||
|
||
fun deleteAllOverriddenFlagsFromPlayStore() { | ||
gmsApplication.getRootDatabase().deleteAllOverriddenFlagsFromPlayStore() | ||
} | ||
|
||
// Local Database | ||
suspend fun deleteAllSavedFlags() { | ||
flagsDao.deleteAllSavedFlags() | ||
} | ||
|
||
suspend fun deleteAllSavedPackages() { | ||
packagesDAO.deleteAllSavedPackages() | ||
} | ||
|
||
} |
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
app/src/main/java/ua/polodarb/gmsflags/di/DatabaseModule.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 ua.polodarb.gmsflags.di | ||
|
||
import androidx.room.Room | ||
import org.koin.android.ext.koin.androidApplication | ||
import org.koin.dsl.module | ||
import ua.polodarb.gmsflags.data.databases.local.AppDatabase | ||
import ua.polodarb.gmsflags.data.databases.local.dao.FlagsDAO | ||
import ua.polodarb.gmsflags.data.databases.local.dao.PackagesDAO | ||
|
||
val databaseModule = module { | ||
|
||
single<AppDatabase> { | ||
Room.databaseBuilder( | ||
androidApplication().applicationContext, | ||
AppDatabase::class.java, | ||
"gms_flags_database" | ||
).build() | ||
} | ||
|
||
single<PackagesDAO> { | ||
val database = get<AppDatabase>() | ||
database.packagesDao() | ||
} | ||
|
||
single<FlagsDAO> { | ||
val database = get<AppDatabase>() | ||
database.flagsDao() | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/ua/polodarb/gmsflags/di/RepositoryModule.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,38 @@ | ||
package ua.polodarb.gmsflags.di | ||
|
||
import org.koin.dsl.module | ||
import ua.polodarb.gmsflags.data.repo.AppsListRepository | ||
import ua.polodarb.gmsflags.data.repo.GmsDBRepository | ||
import ua.polodarb.gmsflags.data.repo.RoomDBRepository | ||
import ua.polodarb.gmsflags.data.repo.SettingsRepository | ||
|
||
val repositoryModule = module { | ||
|
||
single { | ||
GmsDBRepository( | ||
context = get() | ||
) | ||
} | ||
|
||
single { | ||
AppsListRepository( | ||
context = get() | ||
) | ||
} | ||
|
||
single { | ||
RoomDBRepository( | ||
savedPackagesDao = get(), | ||
savedFlagsDao = get() | ||
) | ||
} | ||
|
||
single { | ||
SettingsRepository( | ||
context = get(), | ||
flagsDao = get(), | ||
packagesDAO = get() | ||
) | ||
} | ||
|
||
} |
Oops, something went wrong.