Skip to content

Commit 65f7d4b

Browse files
Init, First commit
0 parents  commit 65f7d4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1031
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-android-extensions'
4+
apply plugin: 'kotlin-kapt'
5+
6+
7+
8+
android {
9+
compileSdkVersion 26
10+
defaultConfig {
11+
applicationId "com.gajraj.android.sharedprefssample"
12+
minSdkVersion 15
13+
targetSdkVersion 26
14+
versionCode 1
15+
versionName "1.0"
16+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
def presentationDependencies = rootProject.ext.presentationDependencies
28+
annotationProcessor presentationDependencies.daggerCompiler
29+
kapt presentationDependencies.daggerCompiler
30+
compile presentationDependencies.dagger
31+
provided presentationDependencies.javaxAnnotation
32+
33+
implementation fileTree(dir: 'libs', include: ['*.jar'])
34+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
35+
implementation 'com.android.support:appcompat-v7:26.1.0'
36+
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
37+
38+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.gajraj.android.sharedprefssample
2+
3+
import android.support.test.InstrumentationRegistry
4+
import android.support.test.runner.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getTargetContext()
22+
assertEquals("com.gajraj.android.sharedprefssample", appContext.packageName)
23+
}
24+
}

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.gajraj.android.sharedprefssample">
4+
5+
<application
6+
android:name=".MyApplication"
7+
android:allowBackup="true"
8+
android:icon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:roundIcon="@mipmap/ic_launcher_round"
11+
android:supportsRtl="true"
12+
android:theme="@style/AppTheme">
13+
<activity android:name=".MainActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
17+
<category android:name="android.intent.category.LAUNCHER" />
18+
</intent-filter>
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.gajraj.android.sharedprefssample
2+
3+
import android.os.Bundle
4+
import android.support.v7.app.AppCompatActivity
5+
import android.util.Log
6+
import com.gajraj.android.sharedprefssample.prefs.PreferencesHelperImpl
7+
import javax.inject.Inject
8+
9+
class MainActivity : AppCompatActivity() {
10+
11+
@Inject
12+
lateinit var preferencesHelperImpl: PreferencesHelperImpl
13+
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
setContentView(R.layout.activity_main)
17+
inject()
18+
prefsTest()
19+
}
20+
21+
private fun prefsTest() {
22+
preferencesHelperImpl.setUserDetails("1001", "gajraj")
23+
val userId: String? = preferencesHelperImpl.getUserId()
24+
Log.i("SampleApp", "userId:" + userId)
25+
}
26+
27+
fun inject() {
28+
MyApplication.getComponent().inject(this)
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.gajraj.android.sharedprefssample
2+
3+
import android.app.Application
4+
import com.smit.android.realestate.di.component.ApplicationComponent
5+
import com.smit.android.realestate.di.component.DaggerApplicationComponent
6+
import com.smit.android.realestate.di.module.ApplicationModule
7+
8+
/**
9+
* Created by Gajraj on 5/24/2018.
10+
*/
11+
class MyApplication : Application() {
12+
13+
override fun onCreate() {
14+
super.onCreate()
15+
component = buildComponent()
16+
}
17+
18+
19+
protected fun buildComponent(): ApplicationComponent {
20+
return DaggerApplicationComponent.builder()
21+
.applicationModule(ApplicationModule(this))
22+
.build()
23+
}
24+
25+
companion object {
26+
private lateinit var component: ApplicationComponent
27+
fun getComponent(): ApplicationComponent {
28+
return component
29+
}
30+
}
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.smit.android.realestate.di.component
2+
3+
import android.content.Context
4+
import com.gajraj.android.sharedprefssample.MainActivity
5+
import com.smit.android.realestate.di.module.ApplicationModule
6+
import dagger.Component
7+
import javax.inject.Singleton
8+
9+
/**
10+
* Created by Gajraj on 4/25/2018.
11+
*/
12+
@Singleton
13+
@Component(modules = arrayOf(ApplicationModule::class))
14+
interface ApplicationComponent {
15+
fun inject(mainActivity: MainActivity)
16+
fun context(): Context
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.smit.android.realestate.di.module
2+
3+
import android.content.Context
4+
import com.gajraj.android.sharedprefssample.MyApplication
5+
import com.gajraj.android.sharedprefssample.prefs.PreferencesHelperImpl
6+
7+
import dagger.Module
8+
import dagger.Provides
9+
import javax.inject.Singleton
10+
11+
12+
/**
13+
* Created by Gajraj on 4/25/2018.
14+
*/
15+
16+
@Module
17+
class ApplicationModule(private val application: MyApplication) {
18+
19+
@Provides
20+
@Singleton
21+
fun application(): MyApplication {
22+
return application
23+
}
24+
25+
@Provides
26+
@Singleton
27+
fun provideApplicationContext(): Context {
28+
return application
29+
}
30+
31+
@Provides
32+
@Singleton
33+
fun providePreferencesHelper(context: Context): PreferencesHelperImpl {
34+
return PreferencesHelperImpl(context)
35+
}
36+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.smit.android.realestate.di.scope
2+
3+
import javax.inject.Scope
4+
5+
/**
6+
* Created by Gajraj on 4/26/2018.
7+
*/
8+
9+
@Scope
10+
@Retention(AnnotationRetention.RUNTIME)
11+
annotation class AppScope {
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.smit.android.realestate.di.scope
2+
3+
import javax.inject.Scope
4+
5+
/**
6+
* Created by Gajraj on 4/26/2018.
7+
*/
8+
9+
@Scope
10+
@Retention(AnnotationRetention.RUNTIME)
11+
annotation class LoginScope {
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.gajraj.android.sharedprefssample.model
2+
3+
/**
4+
* Created by Gajraj on 5/21/2018.
5+
*/
6+
data class AccessToken(val token: String?, val tokenExpiry: String?, val refreshToken: String?)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.gajraj.android.sharedprefssample.model
2+
3+
data class LoginResponseVO(
4+
var refreshToken: String? = null,
5+
var userId: Int? = null,
6+
var tokenExpiry: Int? = null,
7+
var username: String? = null,
8+
var token: String? = null
9+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.gajraj.android.sharedprefssample.prefs
2+
3+
import com.gajraj.android.sharedprefssample.model.AccessToken
4+
import com.gajraj.android.sharedprefssample.model.LoginResponseVO
5+
6+
/**
7+
* Created by Gajraj
8+
*/
9+
interface PreferencesHelper {
10+
fun setAccessToken(accessToken: AccessToken)
11+
fun setUserDetails(userId: String?, userName: String?)
12+
fun getAccessToken(): AccessToken
13+
fun saveUserDetails(response: LoginResponseVO)
14+
fun setRefreshToken(refreshToken: String?)
15+
}

0 commit comments

Comments
 (0)