Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger #10

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
24 changes: 21 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ buildscript {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-kapt'

repositories {
jcenter()
Expand All @@ -20,7 +21,7 @@ repositories {
}

android {
compileSdkVersion 24
compileSdkVersion 27

defaultConfig {
applicationId "com.manoj.dlt"
Expand Down Expand Up @@ -50,12 +51,22 @@ android {
maxProcessCount 4
threadCount 16
}
configurations.all {
resolutionStrategy.force 'com.android.support:appcompat-v7:27.0.1'
resolutionStrategy.force 'com.android.support:cardview-v7:27.0.1'
resolutionStrategy.force 'com.android.support:annotations:27.0.1'
resolutionStrategy.force 'com.android.support:support-compat:27.0.1'
resolutionStrategy.force 'com.android.support:support-fragment:27.0.1'
resolutionStrategy.force 'com.android.support:animated-vector-drawable:27.0.1'
resolutionStrategy.force 'com.android.support:support-v4:27.0.1'
resolutionStrategy.force 'com.android.support:cardview-v7:27.0.1'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:appcompat-v7:27.0.1'
compile 'com.android.support:cardview-v7:27.0.1'
compile 'com.pnikosis:materialish-progress:1.7'
compile 'com.github.hotchemi:android-rate:1.0.1'
compile 'com.google.firebase:firebase-database:9.0.2'
Expand All @@ -66,5 +77,12 @@ dependencies {
}
compile 'com.getkeepsafe.taptargetview:taptargetview:1.5.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.google.dagger:dagger-android:2.17"
compile ('com.google.dagger:dagger-android-support:2.17')
annotationProcessor "com.google.dagger:dagger-compiler:2.17"
annotationProcessor 'com.google.dagger:dagger-android-processor:2.17'

kapt "com.google.dagger:dagger-compiler:2.17"
kapt 'com.google.dagger:dagger-android-processor:2.17'
}
apply plugin: 'com.google.gms.google-services'
34 changes: 27 additions & 7 deletions app/src/main/java/com/manoj/dlt/DeepLinkTestApplication.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
package com.manoj.dlt

import android.app.Activity
import android.app.Application
import android.widget.Toast
import com.crashlytics.android.Crashlytics
import com.google.firebase.database.FirebaseDatabase
import com.manoj.dlt.di.AppComponent
import com.manoj.dlt.di.ContextModule
import com.manoj.dlt.di.DaggerAppComponent
import com.manoj.dlt.features.DeepLinkHistoryFeature
import com.manoj.dlt.features.LinkQueueHandler
import com.manoj.dlt.features.ProfileFeature
import com.manoj.dlt.utils.Utilities
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import dagger.android.support.DaggerApplication
import dagger.internal.DaggerCollections
import io.fabric.sdk.android.Fabric
import javax.inject.Inject

class DeepLinkTestApplication: Application {
constructor()
class DeepLinkTestApplication: DaggerApplication() {

@Inject
lateinit var _profileFeature: ProfileFeature
@Inject
lateinit var _linkQueueHandler: LinkQueueHandler

override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerAppComponent.builder()
.contextModule(ContextModule(this))
.build()
}

override fun onCreate() {
FirebaseDatabase.getInstance().setPersistenceEnabled(true)
super.onCreate()

if(Constants.ENVIRONMENT.equals(Constants.CONFIG.PRODUCTION)) {
Fabric.with(this, Crashlytics())
Crashlytics.setUserIdentifier(ProfileFeature.getInstance(this).getUserId())
Crashlytics.setString("user id", ProfileFeature.getInstance(this).getUserId())
Crashlytics.setUserIdentifier(_profileFeature.getUserId())
Crashlytics.setString("user id", _profileFeature.getUserId())
} else
{
Toast.makeText(applicationContext, "In Testing mode", Toast.LENGTH_LONG).show()
}
if(Constants.isFirebaseAvailable(this))
{
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
LinkQueueHandler.getInstance(this).runQueueListener()
_linkQueueHandler.runQueueListener()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this

DeepLinkHistoryFeature.getInstance(applicationContext)
Utilities.initializeAppRateDialog(applicationContext)
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/manoj/dlt/di/ActivityModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.manoj.dlt.di

import com.manoj.dlt.ui.activities.DeepLinkHistoryActivity
import dagger.Module
import dagger.android.ContributesAndroidInjector

@Module
abstract class ActivityModule {

@ContributesAndroidInjector
abstract fun annotateAndroidInjectionMappingForDeepLinkHistoryActivity(): DeepLinkHistoryActivity
}
38 changes: 38 additions & 0 deletions app/src/main/java/com/manoj/dlt/di/AppComponent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.manoj.dlt.di

import android.app.Activity
import android.app.Application
import android.content.Context
import com.manoj.dlt.DeepLinkTestApplication
import com.manoj.dlt.features.ProfileFeature
import com.manoj.dlt.interfaces.IDeepLinkHistory
import com.manoj.dlt.interfaces.IProfileFeature
import com.manoj.dlt.ui.activities.DeepLinkHistoryActivity
import dagger.BindsInstance
import dagger.Component
import dagger.android.AndroidInjectionModule
import dagger.android.AndroidInjector
import dagger.android.support.AndroidSupportInjectionModule
import javax.inject.Singleton

@Singleton
@Component(modules = [FeaturesModule::class,
AndroidInjectionModule::class, AndroidSupportInjectionModule::class,
ActivityModule::class])
public interface AppComponent: AndroidInjector<DeepLinkTestApplication> {

fun getContext(): Context

fun getProfileFeature(): IProfileFeature

fun getDeepLinkHistoryFeature(): IDeepLinkHistory

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove accessor functions


// @Component.Builder
// interface Builder {
//
// @BindsInstance
// fun application(application: Application): Builder
//
// fun build(): AppComponent
// }
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/manoj/dlt/di/ContextModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.manoj.dlt.di

import android.content.Context
import dagger.Module
import dagger.Provides
import javax.inject.Singleton

@Module
class ContextModule constructor(val context: Context) {

@Provides
@Singleton
fun getAppContext(): Context {
return context.applicationContext
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/manoj/dlt/di/FeaturesModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.manoj.dlt.di

import com.manoj.dlt.features.DeepLinkHistoryFeature
import com.manoj.dlt.features.ProfileFeature
import com.manoj.dlt.interfaces.IDeepLinkHistory
import com.manoj.dlt.interfaces.IProfileFeature
import dagger.Binds
import dagger.Module
import dagger.Provides
import javax.inject.Singleton

@Module(includes = [UtilsModule::class])
abstract class FeaturesModule {

@Singleton
@Binds
abstract fun getHistoryFeature(feature: DeepLinkHistoryFeature): IDeepLinkHistory

@Singleton
@Binds
abstract fun getProfileFeature(feature: ProfileFeature): IProfileFeature
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/manoj/dlt/di/UtilsModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.manoj.dlt.di

import android.content.Context
import com.manoj.dlt.Constants
import com.manoj.dlt.features.FileSystem
import com.manoj.dlt.interfaces.IFileSystem
import dagger.Module
import dagger.Provides
import javax.inject.Named

@Module(includes = [ContextModule::class])
class UtilsModule {

@Provides
@Named(Constants.GLOBAL_PREF_KEY)
fun getGlobalPrefStore(context: Context): IFileSystem {
return FileSystem(context, Constants.GLOBAL_PREF_KEY)
}


@Provides
@Named(Constants.DEEP_LINK_HISTORY_KEY)
fun getHistoryPrefStore(context: Context): IFileSystem {
return FileSystem(context, Constants.DEEP_LINK_HISTORY_KEY)
}

}
20 changes: 9 additions & 11 deletions app/src/main/java/com/manoj/dlt/features/DeepLinkHistoryFeature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@ import com.manoj.dlt.Constants
import com.manoj.dlt.DbConstants
import com.manoj.dlt.events.DeepLinkFireEvent
import com.manoj.dlt.interfaces.IDeepLinkHistory
import com.manoj.dlt.interfaces.IFileSystem
import com.manoj.dlt.interfaces.IProfileFeature
import com.manoj.dlt.models.DeepLinkInfo
import com.manoj.dlt.models.ResultType
import com.manoj.dlt.utils.SingletonHolder
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import java.util.*
import javax.inject.Inject
import javax.inject.Named

class DeepLinkHistoryFeature private constructor(contextIn: Context): IDeepLinkHistory{
class DeepLinkHistoryFeature @Inject constructor(contextIn: Context, val profileFeature: IProfileFeature,
@Named(Constants.DEEP_LINK_HISTORY_KEY) val _fileSystem: IFileSystem): IDeepLinkHistory{

val _fileSystem: FileSystem
val _context: Context = contextIn

init {
_fileSystem = FileSystem(_context, Constants.DEEP_LINK_HISTORY_KEY)
EventBus.getDefault().register(this)
}

companion object: SingletonHolder<DeepLinkHistoryFeature, Context> (::DeepLinkHistoryFeature) {

}

override fun addLinkToHistory(deepLinkInfo: DeepLinkInfo) {
if (Constants.isFirebaseAvailable(_context)) {
addLinkToFirebaseHistory(deepLinkInfo)
Expand Down Expand Up @@ -74,7 +72,7 @@ class DeepLinkHistoryFeature private constructor(contextIn: Context): IDeepLinkH
}

private fun addLinkToFirebaseHistory(deepLinkInfo: DeepLinkInfo) {
val baseUserReference = ProfileFeature.getInstance(_context).getCurrentUserFirebaseBaseRef()
val baseUserReference = profileFeature.getCurrentUserFirebaseBaseRef()
val linkReference = baseUserReference.child(DbConstants.USER_HISTORY).child(deepLinkInfo.id)
val infoMap = object : HashMap<String, Any?>() {
init {
Expand All @@ -92,7 +90,7 @@ class DeepLinkHistoryFeature private constructor(contextIn: Context): IDeepLinkH
}

private fun clearFirebaseHistory() {
val baseUserReference = ProfileFeature.getInstance(_context).getCurrentUserFirebaseBaseRef()
val baseUserReference = profileFeature.getCurrentUserFirebaseBaseRef()
val historyRef = baseUserReference.child(DbConstants.USER_HISTORY)
historyRef.setValue(null)
}
Expand All @@ -102,7 +100,7 @@ class DeepLinkHistoryFeature private constructor(contextIn: Context): IDeepLinkH
}

private fun removeLinkFromFirebaseHistory(deepLinkId: String) {
val baseUserReference = ProfileFeature.getInstance(_context).getCurrentUserFirebaseBaseRef()
val baseUserReference = profileFeature.getCurrentUserFirebaseBaseRef()
val linkReference = baseUserReference.child(DbConstants.USER_HISTORY).child(deepLinkId)
linkReference.setValue(null)
}
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/com/manoj/dlt/features/LinkQueueHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@ import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseReference
import com.manoj.dlt.Constants
import com.manoj.dlt.DbConstants
import com.manoj.dlt.DeepLinkTestApplication
import com.manoj.dlt.interfaces.IProfileFeature
import com.manoj.dlt.utils.FirebaseChildAddedListener
import com.manoj.dlt.utils.SingletonHolder
import com.manoj.dlt.utils.Utilities
import javax.inject.Inject

class LinkQueueHandler private constructor(context: Context) {
class LinkQueueHandler @Inject constructor(context: Context, val profileFeature: IProfileFeature) {

private var _isProcessing: Boolean = false
private val context: Context = context
private val _queueListener: ChildEventListener
private val _queueReference: DatabaseReference

init {
_queueReference = ProfileFeature.getInstance(context).getCurrentUserFirebaseBaseRef().child(DbConstants.LINK_QUEUE)
_queueReference = profileFeature.getCurrentUserFirebaseBaseRef().child(DbConstants.LINK_QUEUE)
_queueListener = getQueueListener()
}

companion object : SingletonHolder<LinkQueueHandler, Context>(::LinkQueueHandler){

}

fun runQueueListener() {
if (_isProcessing) {
//Already attached listener on queue. do nothing
Expand All @@ -49,7 +48,7 @@ class LinkQueueHandler private constructor(context: Context) {
val qId = dataSnapshot.key
val deepLink = dataSnapshot.value.toString()
Utilities.checkAndFireDeepLink(deepLink, context)
Utilities.logLinkViaWeb(deepLink, ProfileFeature.getInstance(context).getUserId(), context)
Utilities.logLinkViaWeb(deepLink, profileFeature.getUserId(), context)
_queueReference.child(qId).setValue(null)
}
}
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/com/manoj/dlt/features/ProfileFeature.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import com.manoj.dlt.interfaces.IProfileFeature
import com.manoj.dlt.utils.SingletonHolder
import com.manoj.dlt.utils.Utilities
import java.util.*
import javax.inject.Inject

class ProfileFeature private constructor(context: Context): IProfileFeature
class ProfileFeature @Inject constructor(context: Context): IProfileFeature
{
private val _fileSystem: FileSystem
private var _userId: String?
Expand All @@ -26,10 +27,6 @@ class ProfileFeature private constructor(context: Context): IProfileFeature
Log.d("profile", "user id = " + _userId)
}

companion object: SingletonHolder<ProfileFeature, Context>(::ProfileFeature) {

}

override fun getUserId(): String {
return _userId!!
}
Expand Down
Loading