Skip to content

Commit

Permalink
DI setup complete
Browse files Browse the repository at this point in the history
  • Loading branch information
aveek committed Jun 19, 2022
1 parent 18db010 commit a20e9d9
Show file tree
Hide file tree
Showing 58 changed files with 412 additions and 27 deletions.
26 changes: 21 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'androidx.navigation.safeargs.kotlin'
}

Expand Down Expand Up @@ -36,18 +37,33 @@ android {
buildFeatures {
dataBinding true
}
hilt {
enableAggregatingTask = true
}
kapt {
correctErrorTypes = true
}
}

dependencies {
implementation project(':libraries:uiComponents')
implementation project(':feature:login')
implementation project(':feature:products')
implementation project(':network')
implementation project(':storage')
implementation project(':libraries:uiComponents')

// // HILT - Needs to be present in each modules individually
//
implementation Deps.androidx_hilt
implementation Deps.androidx_hilt_navigation
kapt Deps.androidx_hilt_kapt

// implementation Deps.androidx_core
// implementation Deps.androidx_retrofit
// implementation Deps.androidx_retrofit_gson_conv
// implementation Deps.gson_version


implementation Deps.androidx_core
implementation Deps.androidx_retrofit
implementation Deps.androidx_retrofit_gson_conv
implementation Deps.gson_version
// implementation 'com.squareup.okhttp3:okhttp:4.9.3'
// implementation 'androidx.appcompat:appcompat:1.4.1'
}
8 changes: 6 additions & 2 deletions app/src/main/java/com/moneybox/minimb/data/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package com.moneybox.minimb.data

import android.content.Intent
import android.content.SharedPreferences


import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.moneybox.minimb.data.utility.ConstantsClass
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

Expand All @@ -13,12 +16,13 @@ class MainActivity : AppCompatActivity() {
lateinit var sharedPreferences : SharedPreferences
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// if (!sharedPreferences.getBoolean(ConstantsClass.Constants.IS_LOGGED_IN.name, false)) {
if (!sharedPreferences.getBoolean(ConstantsClass.Constants.IS_LOGGED_IN.name, false)) {
startActivity(
Intent("com.moneybox.minimb.feature.login.open")
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
.setPackage(this@MainActivity.packageName))
/*}else{
}
/*else{
// Go to Products
val intent = Intent()
intent.setClassName(this@MainActivity, "nbl.core.gpsattendance.MainActivity")
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/moneybox/minimb/data/di/MainModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.moneybox.minimb.data.di

import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityRetainedComponent

@InstallIn(ActivityRetainedComponent::class)
@Module
object MainModule {
}
Binary file modified buildSrc/build/classes/kotlin/main/Versions.class
Binary file not shown.
Binary file modified buildSrc/build/kotlin/compileKotlin/build-history.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1
0
2
1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified buildSrc/build/kotlin/compileKotlin/last-build.bin
Binary file not shown.
Binary file modified buildSrc/build/libs/buildSrc.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object Versions {
// </editor-fold>

// <editor-fold desc="hilt">
val hilt_version = "2.40"
val hilt_version = "2.42"
val hilt_nav_compose_version = "1.0.0"
// </editor-fold>

Expand Down
14 changes: 12 additions & 2 deletions feature/login/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

android {

kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
dataBinding true
}
kapt {
correctErrorTypes = true
}
}

dependencies {
implementation project(':network')
implementation project(':libraries:uiComponents')

implementation Deps.androidx_hilt
implementation Deps.androidx_hilt_navigation
kapt Deps.androidx_hilt_kapt
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moneybox.minimb.feature.login.api

import com.moneybox.minimb.feature.login.models.LoginResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST

interface LoginDataService {

@POST("users/login")
suspend fun loginRequest(@Body user : Map<String , String>) : Response<LoginResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.moneybox.minimb.feature.login.data

import com.google.gson.Gson
import com.moneybox.minimb.feature.login.api.LoginDataService
import com.moneybox.minimb.feature.login.models.LoginResponse
import com.moneybox.minimb.network.ApiResponseResult
import com.moneybox.minimb.network.ErrorResponseRemote
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class LoginDataSource @Inject constructor(private val service : LoginDataService) {
suspend fun login(userMap: HashMap<String, String>): Flow<ApiResponseResult<LoginResponse>> {
return flow {
emit(ApiResponseResult.loading())
val result = service.loginRequest(userMap)
if (result.isSuccessful) {
emit(ApiResponseResult.success(data = result.body()))
} else {
val errorResponseRemote: ErrorResponseRemote =
Gson().fromJson(
result.errorBody()?.charStream(),
ErrorResponseRemote::class.java
)
errorResponseRemote?.let {
it.message?.let { msg ->
emit(ApiResponseResult.error(msg, result.code().toString()))
}
}
}
}
}
fun logout(){

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package com.moneybox.minimb.feature.login.data

import com.moneybox.minimb.feature.login.models.LoginResponse
import com.moneybox.minimb.network.ApiResponseResult
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class LoginRepository @Inject constructor() {
class LoginRepository @Inject constructor(private val loginDataSource: LoginDataSource) {
suspend fun login(userMap : HashMap<String, String>): Flow<ApiResponseResult<LoginResponse>> {
return loginDataSource.login(userMap)
}
fun logout() {
// user = null
loginDataSource.logout()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.moneybox.minimb.feature.login.di

import com.moneybox.minimb.feature.login.api.LoginDataService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityRetainedComponent
import dagger.hilt.android.scopes.ActivityRetainedScoped
import retrofit2.Retrofit

@InstallIn(ActivityRetainedComponent::class)
@Module
object LoginModule {

@Provides
@ActivityRetainedScoped
fun appServiceProvider(retrofit: Retrofit) : LoginDataService{
return retrofit.create(LoginDataService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.moneybox.minimb.feature.login.di

import com.moneybox.minimb.feature.login.api.LoginDataService
import com.moneybox.minimb.feature.login.data.LoginDataSource
import com.moneybox.minimb.feature.login.data.LoginRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.android.scopes.ViewModelScoped

@InstallIn(ViewModelComponent::class)
@Module
class LoginRepositoryModule {

@Provides
@ViewModelScoped
fun provideLoginDataSource(
service: LoginDataService
): LoginDataSource {
return LoginDataSource(service)
}

@Provides
@ViewModelScoped
fun provideLoginDataRepository(
dataSource: LoginDataSource
): LoginRepository {
return LoginRepository(dataSource)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.moneybox.minimb.feature.login.models

import com.google.gson.annotations.SerializedName

data class LoginRequest(
@SerializedName("Idfa")
val idfa: String = "",
@SerializedName("DeviceIdentifier")
val deviceIdentifier: String = "",
@SerializedName("UniqueDeviceIdentifier")
val uniqueDeviceId: String = "",
@SerializedName("Email")
val email: String,
@SerializedName("Password")
val password: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.moneybox.minimb.feature.login.models

import com.google.gson.annotations.SerializedName

data class LoginResponse(
@SerializedName("Session")
val session: SessionDataResponse,
@SerializedName("User")
val user: UserResponse
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.moneybox.minimb.feature.login.models

import com.google.gson.annotations.SerializedName

data class SessionDataResponse(
@SerializedName("BearerToken")
val bearerToken: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.moneybox.minimb.feature.login.models

import com.google.gson.annotations.SerializedName

data class UserResponse(
@SerializedName("UserId")
val userId: String,
@SerializedName("FirstName")
val firstName: String,
@SerializedName("LastName")
val lastName: String,
@SerializedName("Email")
val email: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.navigation.ui.AppBarConfiguration
import com.google.android.material.snackbar.Snackbar
import com.moneybox.minimb.feature.login.LoginActivityHandler
import com.moneybox.minimb.feature.login.R
Expand All @@ -19,9 +18,9 @@ import javax.inject.Inject
@AndroidEntryPoint
class LoginActivity : AppCompatActivity() {

private lateinit var appBarConfiguration: AppBarConfiguration
private lateinit var binding: ActivityLoginBinding
// @Inject lateinit var logger : ILogger
@Inject
lateinit var logger : ILogger


private val loginViewModel : LoginViewModel by viewModels()
Expand All @@ -34,7 +33,7 @@ class LoginActivity : AppCompatActivity() {
handler = LoginActivityHandler(this)
}
setContentView(binding.root)
// logger.debug(message = "Log In View Created")
logger.debug(message = "Log In View Created")

observeViewModelResponse()

Expand Down
21 changes: 18 additions & 3 deletions feature/products/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

android {
buildFeatures {
dataBinding true
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
dataBinding true
}
kapt {
correctErrorTypes = true
}
}

dependencies {
implementation project(':libraries:uiComponents')
implementation project(':network')
implementation project(':libraries:uiComponents')

implementation Deps.androidx_hilt
implementation Deps.androidx_hilt_navigation
kapt Deps.androidx_hilt_kapt
}
Loading

0 comments on commit a20e9d9

Please sign in to comment.