-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate login from xml to compose and multi module with cle…
…an arch
- Loading branch information
1 parent
7dc2735
commit 5b412a2
Showing
44 changed files
with
984 additions
and
239 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
</manifest> |
16 changes: 16 additions & 0 deletions
16
core/common/src/main/java/com/mifos/core/common/utils/BaseUrl.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,16 @@ | ||
package com.mifos.core.common.utils | ||
|
||
object BaseUrl { | ||
|
||
// "/" in the last of the base url always | ||
|
||
const val PROTOCOL_HTTPS = "https://" | ||
|
||
const val API_ENDPOINT = "gsoc.mifos.community" | ||
|
||
const val API_PATH = "/fineract-provider/api/v1/" | ||
|
||
const val PORT = "80" | ||
|
||
const val TENANT = "default" | ||
} |
33 changes: 33 additions & 0 deletions
33
core/common/src/main/java/com/mifos/core/common/utils/Network.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,33 @@ | ||
/* | ||
* This project is licensed under the open source MPL V2. | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.common.utils | ||
|
||
import android.content.Context | ||
import android.net.ConnectivityManager | ||
import android.net.NetworkCapabilities | ||
|
||
/** | ||
* Created by Aditya Gupta on 11/02/24. | ||
*/ | ||
|
||
object Network { | ||
|
||
fun isOnline(context: Context): Boolean { | ||
val connectivityManager = | ||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
val capabilities = | ||
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork) | ||
if (capabilities != null) { | ||
if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) { | ||
return true | ||
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) { | ||
return true | ||
} else if (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
core/common/src/main/java/com/mifos/core/common/utils/Resource.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,14 @@ | ||
package com.mifos.core.common.utils | ||
|
||
/** | ||
* Created by Aditya Gupta on 11/02/24. | ||
*/ | ||
|
||
sealed class Resource<T>(val data: T? = null, val message: String? = null) { | ||
|
||
class Success<T>(data: T?) : Resource<T>(data) | ||
|
||
class Error<T>(message: String, data: T? = null) : Resource<T>(data, message) | ||
|
||
class Loading<T>(data: T? = null) : Resource<T>(data) | ||
} |
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 @@ | ||
/build |
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 @@ | ||
plugins { | ||
id("com.android.library") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
android { | ||
namespace = "com.mifos.core.data" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 26 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation("androidx.core:core-ktx:1.12.0") | ||
implementation("androidx.appcompat:appcompat:1.6.1") | ||
implementation("com.google.android.material:material:1.11.0") | ||
testImplementation("junit:junit:4.13.2") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
} |
Empty file.
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 @@ | ||
# 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 |
24 changes: 24 additions & 0 deletions
24
core/data/src/androidTest/java/com/mifos/core/data/ExampleInstrumentedTest.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,24 @@ | ||
package com.mifos.core.data | ||
|
||
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("com.mifos.core.data.test", appContext.packageName) | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
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,16 @@ | ||
/* | ||
* This project is licensed under the open source MPL V2. | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.data.model | ||
|
||
/** | ||
* Created by ishankhanna on 09/02/14. | ||
*/ | ||
data class Role( | ||
var id: Int = 0, | ||
|
||
var name: String? = null, | ||
|
||
var description: String? = null | ||
) |
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,23 @@ | ||
/* | ||
* This project is licensed under the open source MPL V2. | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.data.model | ||
|
||
class User { | ||
var username: String? = null | ||
|
||
var userId = 0 | ||
|
||
var base64EncodedAuthenticationKey: String? = null | ||
|
||
var isAuthenticated = false | ||
|
||
var officeId = 0 | ||
|
||
var officeName: String? = null | ||
|
||
var roles: List<Role> = ArrayList() | ||
|
||
var permissions: List<String> = ArrayList() | ||
} |
17 changes: 17 additions & 0 deletions
17
core/data/src/test/java/com/mifos/core/data/ExampleUnitTest.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,17 @@ | ||
package com.mifos.core.data | ||
|
||
import org.junit.Test | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.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,54 @@ | ||
package com.mifos.core.datastore | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.preference.PreferenceManager | ||
import com.mifos.core.data.model.User | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import org.apache.fineract.client.models.PostAuthenticationResponse | ||
import org.mifos.core.sharedpreference.Key | ||
import org.mifos.core.sharedpreference.UserPreferences | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Created by Aditya Gupta on 19/08/23. | ||
*/ | ||
|
||
class PrefManager @Inject constructor(@ApplicationContext context: Context) : | ||
UserPreferences<User>() { | ||
|
||
private val USER_DETAILS = "user_details" | ||
private val AUTH_USERNAME = "auth_username" | ||
private val AUTH_PASSWORD = "auth_password" | ||
|
||
override val preference: SharedPreferences = | ||
PreferenceManager.getDefaultSharedPreferences(context) | ||
|
||
override fun getUser(): User { | ||
return get(Key.Custom(USER_DETAILS)) | ||
} | ||
|
||
override fun saveUser(user: User) { | ||
put(Key.Custom(USER_DETAILS), user) | ||
} | ||
|
||
// Created this to store userDetails | ||
fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { | ||
put(Key.Custom(USER_DETAILS), user) | ||
} | ||
|
||
fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { | ||
put(Key.Custom(permissionDeniedStatus), status) | ||
} | ||
|
||
fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { | ||
return get(Key.Custom(permissionDeniedStatus), true) | ||
} | ||
|
||
var usernamePassword: Pair<String, String> | ||
get() = Pair(get(Key.Custom(AUTH_USERNAME)), get(Key.Custom(AUTH_PASSWORD))) | ||
set(value) { | ||
put(Key.Custom(AUTH_USERNAME), value.first) | ||
put(Key.Custom(AUTH_PASSWORD), value.second) | ||
} | ||
} |
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
Oops, something went wrong.