Skip to content

Commit

Permalink
refactor: migrate login from xml to compose and multi module with cle…
Browse files Browse the repository at this point in the history
…an arch
  • Loading branch information
Aditya-gupta99 authored and therajanmaurya committed Feb 13, 2024
1 parent 7dc2735 commit 5b412a2
Show file tree
Hide file tree
Showing 44 changed files with 984 additions and 239 deletions.
6 changes: 3 additions & 3 deletions core/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/common/src/main/AndroidManifest.xml
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 core/common/src/main/java/com/mifos/core/common/utils/BaseUrl.kt
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 core/common/src/main/java/com/mifos/core/common/utils/Network.kt
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 core/common/src/main/java/com/mifos/core/common/utils/Resource.kt
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)
}
1 change: 1 addition & 0 deletions core/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
43 changes: 43 additions & 0 deletions core/data/build.gradle.kts
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 added core/data/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions core/data/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 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)
}
}
4 changes: 4 additions & 0 deletions core/data/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>
16 changes: 16 additions & 0 deletions core/data/src/main/java/com/mifos/core/data/model/Role.kt
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
)
23 changes: 23 additions & 0 deletions core/data/src/main/java/com/mifos/core/data/model/User.kt
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 core/data/src/test/java/com/mifos/core/data/ExampleUnitTest.kt
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)
}
}
16 changes: 16 additions & 0 deletions core/datastore/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
}

android {
Expand Down Expand Up @@ -34,10 +36,24 @@ android {

dependencies {

implementation(project(":core:data"))

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")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")

// Hilt dependency
implementation("com.google.dagger:hilt-android:2.50")
kapt("com.google.dagger:hilt-android-compiler:2.50")


// fineract sdk dependencies
implementation("com.github.openMF:mifos-android-sdk-arch:1.06")

// sdk client
implementation("com.github.openMF:fineract-client:2.0.3")
}
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)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.mifos.core.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
Expand All @@ -18,6 +14,6 @@ fun MifosAndroidClientIcon(id: Int) {
painter = painterResource(id = id),
contentDescription = null,
modifier = Modifier
.size(200.dp,100.dp)
.size(200.dp, 100.dp)
)
}
Loading

0 comments on commit 5b412a2

Please sign in to comment.