Skip to content

Commit

Permalink
refactor classes
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Aug 13, 2023
1 parent d3f7574 commit 75f3998
Show file tree
Hide file tree
Showing 61 changed files with 293 additions and 620 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.6.1")
implementation("androidx.activity:activity-compose:1.7.2")

val composeBom = platform("androidx.compose:compose-bom:2023.08.00")
Expand Down
31 changes: 2 additions & 29 deletions app/src/main/java/com/xinto/mauth/Mauth.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
package com.xinto.mauth

import android.app.Application
import com.xinto.mauth.di.core.CoreOtpModule
import com.xinto.mauth.di.db.DbAccountModule
import com.xinto.mauth.di.db.DbModule
import com.xinto.mauth.di.db.DbRtdataModule
import com.xinto.mauth.di.domain.DomainAccountModule
import com.xinto.mauth.di.domain.DomainOtpModule
import com.xinto.mauth.di.domain.DomainQrModule
import com.xinto.mauth.di.domain.DomainSettingsModule
import com.xinto.mauth.di.ui.UiAccountModule
import com.xinto.mauth.di.ui.UiHomeModule
import com.xinto.mauth.di.ui.UiQrscanModule
import com.xinto.mauth.di.ui.UiSettingsModule
import com.xinto.mauth.di.MauthDI
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

Expand All @@ -24,23 +13,7 @@ class Mauth : Application() {
startKoin {
androidContext(this@Mauth)

modules(
CoreOtpModule,

DbModule,
DbAccountModule,
DbRtdataModule,

DomainAccountModule,
DomainOtpModule,
DomainSettingsModule,
DomainQrModule,

UiAccountModule,
UiHomeModule,
UiSettingsModule,
UiQrscanModule,
)
modules(MauthDI.all)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.xinto.mauth.domain.settings
package com.xinto.mauth.core.settings

import android.content.Context
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.xinto.mauth.domain.settings.model.SortSetting
import com.xinto.mauth.core.settings.model.SortSetting
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class DefaultSettingsRepository(context: Context) : SettingsRepository {
class DefaultSettings(context: Context) : Settings {

private val Context.preferences by preferencesDataStore("preferences")
private val preferences = context.preferences
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.xinto.mauth.domain.settings
package com.xinto.mauth.core.settings

import com.xinto.mauth.domain.settings.model.SortSetting
import com.xinto.mauth.core.settings.model.SortSetting
import kotlinx.coroutines.flow.Flow

interface SettingsRepository {

interface Settings {
fun getSecureMode(): Flow<Boolean>
fun getSortMode(): Flow<SortSetting>

suspend fun setSecureMode(value: Boolean)
suspend fun setSortMode(value: SortSetting)

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.xinto.mauth.domain.settings.model
package com.xinto.mauth.core.settings.model

enum class SortSetting {
DateAsc,
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/xinto/mauth/db/AccountDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.xinto.mauth.db.converter.OtpConverter
import com.xinto.mauth.db.converter.UriConverter
import com.xinto.mauth.db.converter.UuidConverter
Expand Down Expand Up @@ -38,4 +39,24 @@ abstract class AccountDatabase : RoomDatabase() {

abstract fun rtdataDao(): RtdataDao

companion object Migrations {

val Migrate3to4 = object : Migration(3, 4) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE countdata (account_id BLOB NOT NULL, count INTEGER NOT NULL, PRIMARY KEY(account_id))")
database.execSQL("INSERT INTO countdata (account_id, count) SELECT id, counter FROM accounts")
database.execSQL("CREATE TABLE accounts_temp (id BLOB NOT NULL, icon TEXT, secret TEXT NOT NULL, label TEXT NOT NULL, issuer TEXT NOT NULL, algorithm INTEGER NOT NULL DEFAULT 0, type INTEGER NOT NULL DEFAULT 0, digits INTEGER NOT NULL DEFAULT 6, period INTEGER NOT NULL DEFAULT 30, PRIMARY KEY(id))")
database.execSQL("INSERT INTO accounts_temp (id, icon, secret, label, issuer, algorithm, type, digits, period) SELECT id, icon, secret, label, issuer, algorithm, type, digits, period FROM accounts")
database.execSQL("DROP TABLE accounts")
database.execSQL("ALTER TABLE accounts_temp RENAME TO accounts")
}
}

val Migrate4To5 = object : Migration(4, 5) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE accounts ADD COLUMN create_date INTEGER NOT NULL DEFAULT 0")
database.execSQL("UPDATE accounts SET create_date = strftime('%s','now') + ROWID")
}
}
}
}
74 changes: 74 additions & 0 deletions app/src/main/java/com/xinto/mauth/di/MauthDI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.xinto.mauth.di

import androidx.room.Room
import com.xinto.mauth.core.otp.generator.DefaultOtpGenerator
import com.xinto.mauth.core.otp.generator.OtpGenerator
import com.xinto.mauth.core.otp.parser.DefaultOtpUriParser
import com.xinto.mauth.core.otp.parser.OtpUriParser
import com.xinto.mauth.core.otp.transformer.DefaultKeyTransformer
import com.xinto.mauth.core.otp.transformer.KeyTransformer
import com.xinto.mauth.db.AccountDatabase
import com.xinto.mauth.domain.AccountRepository
import com.xinto.mauth.domain.OtpRepository
import com.xinto.mauth.domain.QrRepository
import com.xinto.mauth.domain.SettingsRepository
import com.xinto.mauth.core.settings.DefaultSettings
import com.xinto.mauth.core.settings.Settings
import com.xinto.mauth.ui.screen.account.AccountViewModel
import com.xinto.mauth.ui.screen.home.HomeViewModel
import com.xinto.mauth.ui.screen.qrscan.QrScanViewModel
import com.xinto.mauth.ui.screen.settings.SettingsViewModel
import org.apache.commons.codec.binary.Base32
import org.koin.android.ext.koin.androidContext
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
import org.koin.dsl.module

object MauthDI {

val CoreModule = module {
singleOf(::DefaultOtpGenerator) bind OtpGenerator::class
singleOf(::DefaultOtpUriParser) bind OtpUriParser::class
single {
DefaultKeyTransformer(Base32())
} bind KeyTransformer::class
singleOf(::DefaultSettings) bind Settings::class
}

val DbModule = module {
single {
Room.databaseBuilder(androidContext(), AccountDatabase::class.java, "accounts")
.addMigrations(AccountDatabase.Migrate3to4)
.addMigrations(AccountDatabase.Migrate4To5)
.build()
}

single {
val db: AccountDatabase = get()
db.accountsDao()
}

single {
val db: AccountDatabase = get()
db.rtdataDao()
}
}

val DomainModule = module {
singleOf(::AccountRepository)
singleOf(::OtpRepository)
singleOf(::QrRepository)
singleOf(::SettingsRepository)
}

val UiModule = module {
viewModelOf(::AccountViewModel)
viewModelOf(::SettingsViewModel)
viewModelOf(::QrScanViewModel)
viewModelOf(::HomeViewModel)
}

val all = listOf(CoreModule, DbModule, DomainModule, UiModule)

}
20 changes: 0 additions & 20 deletions app/src/main/java/com/xinto/mauth/di/core/CoreOtpModule.kt

This file was deleted.

11 changes: 0 additions & 11 deletions app/src/main/java/com/xinto/mauth/di/db/DbAccountModule.kt

This file was deleted.

35 changes: 0 additions & 35 deletions app/src/main/java/com/xinto/mauth/di/db/DbModule.kt

This file was deleted.

11 changes: 0 additions & 11 deletions app/src/main/java/com/xinto/mauth/di/db/DbRtdataModule.kt

This file was deleted.

17 changes: 0 additions & 17 deletions app/src/main/java/com/xinto/mauth/di/domain/DomainAccountModule.kt

This file was deleted.

15 changes: 0 additions & 15 deletions app/src/main/java/com/xinto/mauth/di/domain/DomainOtpModule.kt

This file was deleted.

13 changes: 0 additions & 13 deletions app/src/main/java/com/xinto/mauth/di/domain/DomainQrModule.kt

This file was deleted.

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/java/com/xinto/mauth/di/ui/UiAccountModule.kt

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/java/com/xinto/mauth/di/ui/UiHomeModule.kt

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/java/com/xinto/mauth/di/ui/UiQrscanModule.kt

This file was deleted.

Loading

0 comments on commit 75f3998

Please sign in to comment.