Skip to content

Commit

Permalink
refactor: settings module (#2649)
Browse files Browse the repository at this point in the history
  • Loading branch information
AvneetSingh2001 committed Jul 6, 2024
1 parent 48607cc commit 6f0eaac
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 234 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ dependencies {
implementation(projects.feature.notification)
implementation(projects.feature.location)
implementation(projects.feature.about)
implementation(projects.feature.settings)


implementation("androidx.legacy:legacy-support-v4:1.0.0")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/mifos/mobile/MifosSelfServiceApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.raizlabs.android.dbflow.config.FlowConfig
import com.raizlabs.android.dbflow.config.FlowManager
import dagger.hilt.android.HiltAndroidApp
import org.mifos.mobile.core.datastore.PreferencesHelper
import org.mifos.mobile.ui.settings.applySavedTheme
import org.mifos.mobile.core.common.utils.LanguageHelper.onAttach
import org.mifos.mobile.feature.settings.applySavedTheme

/**
* @author ishan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import dagger.hilt.android.AndroidEntryPoint
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.component.mifosComposeView
import org.mifos.mobile.core.ui.theme.MifosMobileTheme
import org.mifos.mobile.feature.settings.SettingsScreen
import org.mifos.mobile.ui.activities.HomeActivity
import org.mifos.mobile.ui.activities.PassCodeActivity
import org.mifos.mobile.ui.activities.base.BaseActivity
Expand Down
196 changes: 0 additions & 196 deletions app/src/main/java/org/mifos/mobile/ui/settings/SettingsFragment.kt

This file was deleted.

1 change: 1 addition & 0 deletions feature/settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
20 changes: 20 additions & 0 deletions feature/settings/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
alias(libs.plugins.mifos.android.feature)
alias(libs.plugins.mifos.android.library.compose)
}

android {
namespace = "org.mifos.mobile.feature.settings"
}

dependencies {
implementation(projects.ui)
implementation(projects.core.common)
implementation(projects.core.model)
implementation(projects.core.data)
implementation(libs.androidx.appcompat)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
}
Empty file.
21 changes: 21 additions & 0 deletions feature/settings/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.mifos.mobile.feature.settings

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.mifos.mobile.feature.settings.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions feature/settings/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.settings
package org.mifos.mobile.feature.settings

import android.content.Context
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -33,7 +33,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.component.MFScaffold
import org.mifos.mobile.core.ui.component.MifosRadioButtonDialog
import org.mifos.mobile.core.ui.component.MifosTopBarTitle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.settings
package org.mifos.mobile.feature.settings


import android.os.Build
Expand All @@ -11,7 +11,6 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.stateIn
import org.mifos.mobile.R
import org.mifos.mobile.core.datastore.PreferencesHelper
import org.mifos.mobile.core.model.enums.AppTheme
import org.mifos.mobile.core.model.enums.MifosAppLanguage
Expand Down Expand Up @@ -72,7 +71,7 @@ class SettingsViewModel @Inject constructor(
}
)
preferencesHelper.appTheme = theme.ordinal
preferencesHelper.applySavedTheme()
preferencesHelper.applyTheme(theme)
}
}

Expand Down Expand Up @@ -119,4 +118,28 @@ enum class SettingsCardItem(
)
}

fun PreferencesHelper.applySavedTheme() {
val applicationTheme = AppTheme.entries.find { it.ordinal == this.appTheme }
AppCompatDelegate.setDefaultNightMode(
when {
applicationTheme == AppTheme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
applicationTheme == AppTheme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
Build.VERSION.SDK_INT > Build.VERSION_CODES.P -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
else -> AppCompatDelegate.MODE_NIGHT_NO
},
)
}


fun PreferencesHelper.applyTheme(applicationTheme: AppTheme) {
this.appTheme = applicationTheme.ordinal
AppCompatDelegate.setDefaultNightMode(
when {
applicationTheme == AppTheme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
applicationTheme == AppTheme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
Build.VERSION.SDK_INT > Build.VERSION_CODES.P -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
else -> AppCompatDelegate.MODE_NIGHT_NO
},
)
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.mifos.mobile.ui.settings
package org.mifos.mobile.feature.settings

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -21,7 +21,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import org.mifos.mobile.R
import org.mifos.mobile.core.ui.theme.MifosMobileTheme

@Composable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M12,3c-4.97,0 -9,4.03 -9,9s4.03,9 9,9s9,-4.03 9,-9c0,-0.46 -0.04,-0.92 -0.1,-1.36c-0.98,1.37 -2.58,2.26 -4.4,2.26c-2.98,0 -5.4,-2.42 -5.4,-5.4c0,-1.81 0.89,-3.42 2.26,-4.4C12.92,3.04 12.46,3 12,3L12,3z" />
</vector>
Loading

0 comments on commit 6f0eaac

Please sign in to comment.