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

Add Dagger 2 support #220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ build/
**/.idea/caches

# layout inspector view captures
captures
captures
.idea/
64 changes: 0 additions & 64 deletions .idea/codeStyles/Project.xml

This file was deleted.

5 changes: 0 additions & 5 deletions .idea/codeStyles/codeStyleConfig.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

90 changes: 45 additions & 45 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
buildscript {
ext.kotlinVersion = '1.2.31'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
ext.kotlinVersion = '1.2.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}

allprojects {
repositories {
google()
jcenter()
}
repositories {
google()
jcenter()
}
}

subprojects { project ->
group = GROUP
version = VERSION_NAME
group = GROUP
version = VERSION_NAME

apply plugin: 'checkstyle'
apply plugin: 'checkstyle'

task checkstyle(type: Checkstyle) {
configFile rootProject.file('checkstyle.xml')
source 'src/main/java'
ignoreFailures false
showViolations true
include '**/*.java'
task checkstyle(type: Checkstyle) {
configFile rootProject.file('checkstyle.xml')
source 'src/main/java'
ignoreFailures false
showViolations true
include '**/*.java'

classpath = files()
}
classpath = files()
}

afterEvaluate {
if (project.tasks.findByName('check')) {
check.dependsOn('checkstyle')
afterEvaluate {
if (project.tasks.findByName('check')) {
check.dependsOn('checkstyle')
}
}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
delete rootProject.buildDir
}

ext {
minSdkVersion = 15
targetSdkVersion = 27
compileSdkVersion = 27
buildToolsVersion = '27.0.3'
sourceCompatibilityVersion = JavaVersion.VERSION_1_7
targetCompatibilityVersion = JavaVersion.VERSION_1_7
minSdkVersion = 15
targetSdkVersion = 27
compileSdkVersion = 27
buildToolsVersion = '27.0.3'
sourceCompatibilityVersion = JavaVersion.VERSION_1_7
targetCompatibilityVersion = JavaVersion.VERSION_1_7
}

ext.deps = [
gson : 'com.google.code.gson:gson:2.8.2',
conceal : 'com.facebook.conceal:conceal:1.1.3@aar',
gson : 'com.google.code.gson:gson:2.8.2',
conceal : 'com.facebook.conceal:conceal:1.1.3@aar',

// Test dependencies
junit : 'junit:junit:4.12',
truth : 'com.google.truth:truth:0.28',
robolectric : 'org.robolectric:robolectric:3.3',
mockito : 'org.mockito:mockito-core:2.8.9',
espressoRunner: 'com.android.support.test:runner:0.5',
espressoRules : 'com.android.support.test:rules:0.5',
kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
// Test dependencies
junit : 'junit:junit:4.12',
truth : 'com.google.truth:truth:0.28',
robolectric : 'org.robolectric:robolectric:3.3',
mockito : 'org.mockito:mockito-core:2.8.9',
espressoRunner: 'com.android.support.test:runner:0.5',
espressoRules : 'com.android.support.test:rules:0.5',
kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

]
41 changes: 41 additions & 0 deletions dagger-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 27

defaultConfig {
applicationId "com.orhanobut.hawk.dagger.sample"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.dagger:dagger:2.16'
implementation('com.google.dagger:dagger-android:2.16') {
exclude group: "com.android.support"
}
implementation('com.google.dagger:dagger-android-support:2.16') {
exclude group: "com.android.support"
}
kapt "com.google.dagger:dagger-compiler:2.16"
kapt("com.google.dagger:dagger-android-processor:2.16") {
exclude group: "com.android.support"
}
implementation project(':hawk')
implementation project(':hawk-dagger')
}
21 changes: 21 additions & 0 deletions dagger-sample/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
22 changes: 22 additions & 0 deletions dagger-sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.orhanobut.hawk.dagger.sample">

<application
android:name=".MainApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.orhanobut.hawk.dagger.sample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.orhanobut.hawk.dagger.sample

import android.os.Bundle
import android.support.annotation.VisibleForTesting
import android.support.v4.app.Fragment
import android.support.v7.app.AppCompatActivity
import com.orhanobut.hawk.dagger.Hawker
import dagger.android.DispatchingAndroidInjector
import dagger.android.support.HasSupportFragmentInjector
import javax.inject.Inject

@VisibleForTesting
class MainActivity : AppCompatActivity(), HasSupportFragmentInjector {

@Inject
lateinit var hawker: Hawker

@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>

override fun supportFragmentInjector() = dispatchingAndroidInjector

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

save()
load()
}

private fun save() {
hawker.put("name", "Hawker")
hawker.put("description", "Hawk with Dagger 2 support")
}

private fun load() {
val name: String? = hawker.get("name")
val description: String? = hawker.get("description")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.orhanobut.hawk.dagger.sample

import android.app.Activity
import android.app.Application
import com.orhanobut.hawk.dagger.sample.di.AppInjector
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import javax.inject.Inject

class MainApplication : Application(), HasActivityInjector {
@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>

override fun activityInjector(): AndroidInjector<Activity> {
return dispatchingAndroidInjector
}

override fun onCreate() {
super.onCreate()
AppInjector.init(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.orhanobut.hawk.dagger.sample.di

import com.orhanobut.hawk.dagger.sample.MainActivity
import dagger.Module
import dagger.android.ContributesAndroidInjector

@Suppress("unused")
@Module
abstract class ActivityModule {
@ContributesAndroidInjector()
abstract fun contributeMainActivity(): MainActivity
}
Loading