Skip to content

Commit

Permalink
Migration from dagger2 to hilt (#2019)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 authored Aug 5, 2023
1 parent 909c83a commit 49da775
Show file tree
Hide file tree
Showing 99 changed files with 249 additions and 679 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@ ext {

//navigation components version
navigationComponentsVersion = '2.6.0'

// hiltVersion
hiltVersion = '2.44'
}
11 changes: 6 additions & 5 deletions mifosng-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.14"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.6.0"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.44'
}
}

Expand All @@ -41,6 +42,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'com.google.dagger.hilt.android'

android {
compileSdkVersion rootProject.ext.compileSdkVersion
Expand Down Expand Up @@ -190,11 +192,6 @@ dependencies {
implementation "com.google.maps.android:android-maps-utils:$rootProject.mapUtilsServicesVersion"
implementation "androidx.test.espresso:espresso-idling-resource:$rootProject.espressoidlingVersion"

//Dagger dependencies
implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
compileOnly "javax.annotation:jsr250-api:$rootProject.jsrVersion" //Required by Dagger2
kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"

//LifeCycle
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$rootProject.lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycleExtensionsVersion"
Expand Down Expand Up @@ -279,6 +276,10 @@ dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:$rootProject.navigationComponentsVersion"
implementation "androidx.navigation:navigation-ui-ktx:$rootProject.navigationComponentsVersion"

// Hilt dependency
implementation "com.google.dagger:hilt-android:$rootProject.hiltVersion"
kapt "com.google.dagger:hilt-android-compiler:$rootProject.hiltVersion"

}
/*
All direct/transitive dependencies shared between your test and production APKs need to be
Expand Down
8 changes: 0 additions & 8 deletions mifosng-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".HomeActivity" />
</activity>
<activity
android:name=".ClientListActivity"
android:label="@string/clients"
android:screenOrientation="portrait" />
<activity
android:name=".GroupListActivity"
android:label="@string/groups"
android:screenOrientation="portrait" />
<activity
android:name=".activity.pinpointclient.PinpointClientActivity"
android:label="@string/pinpoint"
Expand Down
18 changes: 2 additions & 16 deletions mifosng-android/src/main/java/com/mifos/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ import com.evernote.android.job.JobManager
import com.facebook.stetho.Stetho
import com.joanzapata.iconify.Iconify
import com.joanzapata.iconify.fonts.MaterialModule
import com.mifos.mifosxdroid.injection.component.ApplicationComponent
import com.mifos.mifosxdroid.injection.component.DaggerApplicationComponent
import com.mifos.mifosxdroid.injection.module.ApplicationModule
import com.mifos.mifosxdroid.offlinejobs.OfflineJobCreator
import com.mifos.mobile.passcode.utils.ForegroundChecker
import com.mifos.utils.LanguageHelper.onAttach
import com.mifos.utils.ThemeHelper
import com.raizlabs.android.dbflow.config.FlowConfig
import com.raizlabs.android.dbflow.config.FlowManager
import dagger.hilt.android.HiltAndroidApp
import io.fabric.sdk.android.Fabric

/**
* Created by ishankhanna on 13/03/15.
*/
@HiltAndroidApp
class App : MultiDexApplication() {
var mApplicationComponent: ApplicationComponent? = null
override fun onCreate() {
super.onCreate()
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
Expand All @@ -53,19 +52,6 @@ class App : MultiDexApplication() {
ForegroundChecker.init(this)
}

// Needed to replace the component with a test specific one
var component: ApplicationComponent?
get() {
if (mApplicationComponent == null) {
mApplicationComponent = DaggerApplicationComponent.builder()
.applicationModule(ApplicationModule(this))
.build()
}
return mApplicationComponent
}
set(applicationComponent) {
mApplicationComponent = applicationComponent
}

override fun attachBaseContext(base: Context) {
super.attachBaseContext(onAttach(base))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import android.net.Uri
import android.os.Bundle
import com.mifos.mifosxdroid.core.MifosBaseActivity
import com.mifos.mifosxdroid.databinding.ActivityAboutBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class AboutActivity : MifosBaseActivity() {

private lateinit var binding: ActivityAboutBinding
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ import com.mifos.mifosxdroid.databinding.ViewNavDrawerHeaderBinding
import com.mifos.utils.Constants
import com.mifos.utils.EspressoIdlingResource
import com.mifos.utils.PrefManager
import dagger.hilt.android.AndroidEntryPoint

/**
* Created by shashankpriyadarshi on 19/06/20.
*/
@AndroidEntryPoint
open class HomeActivity : MifosBaseActivity(), NavigationView.OnNavigationItemSelectedListener {

private lateinit var binding: ActivityHomeBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ import com.mifos.utils.Constants
import com.mifos.utils.PrefManager.getBoolean
import com.mifos.utils.PrefManager.putBoolean
import com.mifos.utils.PrefManager.userId
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

/**
* @author fomenkoo
*/
@AndroidEntryPoint
class PathTrackingActivity : MifosBaseActivity(), PathTrackingMvpView, OnRefreshListener {

private lateinit var binding: ActivityPathTrackerBinding
Expand All @@ -53,7 +55,6 @@ class PathTrackingActivity : MifosBaseActivity(), PathTrackingMvpView, OnRefresh
super.onCreate(savedInstanceState)
binding = ActivityPathTrackerBinding.inflate(layoutInflater)
setContentView(binding.root)
activityComponent?.inject(this)
pathTrackingPresenter?.attachView(this)
showBackButton()
intentLocationService = Intent(this, PathTrackingService::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListe
import com.google.android.gms.location.LocationListener
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationServices
import com.mifos.App
import com.mifos.api.GenericResponse
import com.mifos.api.datamanager.DataManagerDataTable
import com.mifos.mifosxdroid.R
Expand Down Expand Up @@ -67,7 +66,6 @@ class PathTrackingService : Service(), ConnectionCallbacks, OnConnectionFailedLi
private var subscription: Subscription? = null
override fun onCreate() {
super.onCreate()
App[this].component!!.inject(this)
buildGoogleApiClient()
}

Expand Down Expand Up @@ -211,7 +209,7 @@ class PathTrackingService : Service(), ConnectionCallbacks, OnConnectionFailedLi

override fun onLocationChanged(location: Location) {
currentLocation = location
latLngs!!.add(UserLatLng(currentLocation!!.latitude, currentLocation!!.longitude))
latLngs!!.add(UserLatLng(currentLocation.latitude, currentLocation.longitude))
}

override fun onConnectionFailed(connectionResult: ConnectionResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ import com.mifos.objects.client.ClientAddressResponse
import com.mifos.utils.CheckSelfPermissionAndRequest.checkSelfPermission
import com.mifos.utils.CheckSelfPermissionAndRequest.requestPermission
import com.mifos.utils.Constants
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

/**
* @author fomenkoo
*/
@AndroidEntryPoint
class PinpointClientActivity : MifosBaseActivity(), PinPointClientMvpView, OnRefreshListener,
PinpointClientAdapter.OnItemClick {

private lateinit var binding: ActivityPinpointLocationBinding
private val arg : PinpointClientActivityArgs by navArgs()
private val arg: PinpointClientActivityArgs by navArgs()

@Inject
lateinit var pinpointClientAdapter: PinpointClientAdapter
Expand All @@ -46,8 +48,8 @@ class PinpointClientActivity : MifosBaseActivity(), PinPointClientMvpView, OnRef
@Inject
var pinPointClientPresenter: PinPointClientPresenter? = null
private var clientId = 0
private var apptableId : Int? = 0
private var dataTableId : Int? = 0
private var apptableId: Int? = 0
private var dataTableId: Int? = 0
private var addresses: List<ClientAddressResponse> = ArrayList()
override fun onItemLongClick(position: Int) {
apptableId = addresses[position].clientId
Expand Down Expand Up @@ -84,7 +86,6 @@ class PinpointClientActivity : MifosBaseActivity(), PinPointClientMvpView, OnRef

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent?.inject(this)
binding = ActivityPinpointLocationBinding.inflate(layoutInflater)
setContentView(binding.root)
pinPointClientPresenter?.attachView(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import androidx.recyclerview.widget.RecyclerView
import com.mifos.api.model.BulkRepaymentTransactions
import com.mifos.mifosxdroid.R
import com.mifos.mifosxdroid.databinding.ItemIndividualCollectionSheetBinding
import com.mifos.mifosxdroid.injection.ActivityContext
import com.mifos.mifosxdroid.online.collectionsheetindividualdetails.OnRetrieveSheetItemData
import com.mifos.objects.accounts.loan.PaymentTypeOptions
import com.mifos.objects.collectionsheet.LoanAndClientName
import com.mifos.utils.ImageLoaderUtils
import dagger.hilt.android.qualifiers.ActivityContext
import java.util.Locale
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import androidx.fragment.app.FragmentManager
import com.mifos.App
import com.mifos.mifosxdroid.R
import com.mifos.mifosxdroid.SplashScreenActivity
import com.mifos.mifosxdroid.injection.component.ActivityComponent
import com.mifos.mifosxdroid.injection.component.DaggerActivityComponent
import com.mifos.mifosxdroid.injection.module.ActivityModule
import com.mifos.mifosxdroid.passcode.PassCodeActivity
import com.mifos.mobile.passcode.BasePassCodeActivity
import com.mifos.utils.Constants
Expand All @@ -33,7 +30,6 @@ import com.mifos.utils.PrefManager.clearPrefs
*/
open class MifosBaseActivity : BasePassCodeActivity(), BaseActivityCallback {
var toolbar: Toolbar? = null
private var mActivityComponent: ActivityComponent? = null
private var progress: ProgressDialog? = null
override fun setContentView(layoutResID: Int) {
super.setContentView(layoutResID)
Expand All @@ -51,17 +47,6 @@ open class MifosBaseActivity : BasePassCodeActivity(), BaseActivityCallback {
}
}

val activityComponent: ActivityComponent?
get() {
if (mActivityComponent == null) {
mActivityComponent = DaggerActivityComponent.builder()
.activityModule(ActivityModule(this))
.applicationComponent(App.get(this).component)
.build()
}
return mActivityComponent
}

private fun setActionBarTitle(title: String?) {
if (supportActionBar != null && getTitle() != null) {
setTitle(title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import androidx.fragment.app.DialogFragment
import com.mifos.mifosxdroid.R
import com.mifos.mifosxdroid.core.MifosBaseActivity
import com.mifos.mifosxdroid.core.ProgressableDialogFragment
import com.mifos.mifosxdroid.core.util.Toaster.show
import com.mifos.mifosxdroid.databinding.DialogFragmentChargeBinding
Expand All @@ -28,6 +27,7 @@ import com.mifos.services.data.ChargesPayload
import com.mifos.utils.Constants
import com.mifos.utils.DateHelper
import com.mifos.utils.FragmentConstants
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

/**
Expand All @@ -36,6 +36,7 @@ import javax.inject.Inject
*
* Use this Dialog Fragment to Create and/or Update charges
*/
@AndroidEntryPoint
class ChargeDialogFragment : ProgressableDialogFragment(), OnDatePickListener, ChargeDialogMvpView,
OnItemSelectedListener {
val LOG_TAG = javaClass.simpleName
Expand All @@ -58,7 +59,6 @@ class ChargeDialogFragment : ProgressableDialogFragment(), OnDatePickListener, C
private var createdCharge: Charges? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activity as MifosBaseActivity).activityComponent?.inject(this)
if (arguments != null) clientId = requireArguments().getInt(Constants.CLIENT_ID)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.mifos.mifosxdroid.dialogfragments.checkertaskfilterdialog

import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import com.mifos.mifosxdroid.R
import com.mifos.mifosxdroid.core.MifosBaseActivity
import com.mifos.mifosxdroid.databinding.DialogFragmentCheckerTaskFilterBinding
import com.mifos.mifosxdroid.online.checkerinbox.CheckerInboxViewModel
import com.mifos.mifosxdroid.online.checkerinbox.CheckerInboxViewModelFactory
import com.mifos.mifosxdroid.uihelpers.MFDatePicker
import com.mifos.utils.FragmentConstants
import java.lang.ClassCastException
import dagger.hilt.android.AndroidEntryPoint
import java.sql.Timestamp
import java.text.SimpleDateFormat
import javax.inject.Inject

@AndroidEntryPoint
class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePickListener,
AdapterView.OnItemSelectedListener {

Expand Down Expand Up @@ -61,14 +62,12 @@ class CheckerTaskFilterDialogFragment : DialogFragment(), MFDatePicker.OnDatePic
selectedEntity = ALL
datePickerFromDate = MFDatePicker.newInsance(this)
datePickerToDate = MFDatePicker.newInsance(this)

(activity as MifosBaseActivity).activityComponent?.inject(this)
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
binding = DialogFragmentCheckerTaskFilterBinding.inflate(inflater,container,false)
binding = DialogFragmentCheckerTaskFilterBinding.inflate(inflater, container, false)
return binding.root
}

Expand Down
Loading

0 comments on commit 49da775

Please sign in to comment.