Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit 3a3b1a9

Browse files
authored
Merge pull request #14 from amardeshbd/feature/12_setup_barebone_layout_preview_screen
Feature/12 setup barebone layout preview screen
2 parents 2deaa6f + 9a4a4b8 commit 3a3b1a9

20 files changed

+820
-6
lines changed

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dependencies {
5757
// ========================================================
5858
// 3rd party libraries
5959
// ========================================================
60+
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
6061
debugImplementation "com.squareup.leakcanary:leakcanary-android:$rootProject.leakcanaryLibraryVersion"
6162
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$rootProject.leakcanaryLibraryVersion"
6263

@@ -71,6 +72,9 @@ dependencies {
7172
//implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
7273
kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
7374

75+
// A highly customizable, powerful and easy-to-use alerting library for Android.
76+
// https://github.com/aritraroy/Flashbar
77+
implementation "com.andrognito.flashbar:flashbar:$rootProject.flashBarVersion"
7478

7579
// ----------------------------------------------------------------
7680
// Android Unit and Instrumentation test

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<category android:name="android.intent.category.LAUNCHER" />
1818
</intent-filter>
1919
</activity>
20+
<activity android:name=".layoutpositioning.LayoutPositioningDemoActivity"></activity>
2021
</application>
2122

2223
</manifest>

app/src/main/java/com/hossainkhan/android/demo/MainActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package com.hossainkhan.android.demo
22

33
import android.support.v7.app.AppCompatActivity
44
import android.os.Bundle
5+
import android.view.View
56
import com.hossainkhan.android.demo.data.AppDataStore
7+
import com.hossainkhan.android.demo.layoutpositioning.LayoutPositioningDemoActivity
68
import dagger.android.AndroidInjection
79
import timber.log.Timber
810
import javax.inject.Inject
@@ -19,4 +21,11 @@ class MainActivity : AppCompatActivity() {
1921
Timber.d("Got data: ${appDataStore.isFirstTime()}")
2022
appDataStore.updateFirstTimeUser(false)
2123
}
24+
25+
// FIXME - Test code
26+
fun goSomewhere(view: View?) {
27+
startActivity(LayoutPositioningDemoActivity
28+
.createStartIntent(this, R.layout.activity_positioning_top_left))
29+
30+
}
2231
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2018 Hossain Khan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hossainkhan.android.demo.base
18+
19+
/**
20+
* Application configurations.
21+
*/
22+
object AppConfig {
23+
const val GITHUB_BASE_URL = "https://github.com/amardeshbd/android-constraint-layout-cheatsheet"
24+
}

app/src/main/java/com/hossainkhan/android/demo/dagger/ActivityBindingModule.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package com.hossainkhan.android.demo.dagger
1818

19+
import com.hossainkhan.android.demo.layoutpositioning.LayoutPositioningDemoActivity
1920
import dagger.Module
21+
import dagger.android.ContributesAndroidInjector
2022

2123
/**
2224
* We want Dagger.Android to create a Subcomponent which has a parent Component of whichever
@@ -31,7 +33,7 @@ import dagger.Module
3133
* When Dagger.Android annotation processor runs it will create subcomponents for us.
3234
*/
3335
@Module
34-
public abstract class ActivityBindingModule {
36+
abstract class ActivityBindingModule {
3537
/*
3638
* https://google.github.io/dagger/android.html
3739
* Pro-tip: If your subcomponent and its builder have no other methods or supertypes than
@@ -42,8 +44,7 @@ public abstract class ActivityBindingModule {
4244
* into the subcomponent. If the subcomponent needs scopes, apply the scope annotations to
4345
* the method as well.
4446
*/
45-
// Example
46-
//@ActivityScoped
47-
//@ContributesAndroidInjector(modules = arrayOf(ModuleNameWhichHasActivityInjection::class))
48-
//abstract fun someActivity(): SomeActivity
47+
@ActivityScope
48+
@ContributesAndroidInjector
49+
abstract fun layoutPositioningActivity(): LayoutPositioningDemoActivity
4950
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2018 Hossain Khan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hossainkhan.android.demo.dagger
18+
19+
import javax.inject.Scope
20+
21+
@Scope
22+
@Retention(AnnotationRetention.RUNTIME)
23+
annotation class ActivityScope
24+

app/src/main/java/com/hossainkhan/android/demo/dagger/DataStoreModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.hossainkhan.android.demo.dagger
1818

1919
import android.content.Context
2020
import android.content.SharedPreferences
21+
import android.content.res.Resources
2122
import dagger.Module
2223
import dagger.Provides
2324

@@ -27,4 +28,9 @@ class DataStoreModule {
2728
internal fun provideSharedPreferences(context: Context): SharedPreferences {
2829
return context.getSharedPreferences("app_preferences", Context.MODE_PRIVATE)
2930
}
31+
32+
@Provides
33+
internal fun provideAndroidResoures(context: Context): Resources {
34+
return context.resources
35+
}
3036
}

app/src/main/java/com/hossainkhan/android/demo/dagger/DemoApplicationComponent.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import android.app.Application
2020
import com.hossainkhan.android.demo.base.DemoApplication
2121
import dagger.BindsInstance
2222
import dagger.Component
23+
import javax.inject.Singleton
2324

25+
@Singleton
2426
@Component(modules = arrayOf(
2527
ApplicationModule::class,
28+
ActivityBindingModule::class,
2629
DataStoreModule::class,
2730
MainActivityModule::class))
2831
interface DemoApplicationComponent {

app/src/main/java/com/hossainkhan/android/demo/data/AppDataStore.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import javax.inject.Inject
2323
* Application wide data storage and preferences backed by [SharedPreferences].
2424
*/
2525
class AppDataStore @Inject constructor(
26-
private val preferences: SharedPreferences) {
26+
private val preferences: SharedPreferences,
27+
val layoutStore: LayoutDataStore) {
2728

2829
private companion object {
2930
private const val PREF_KEY_IS_FIRST_TIME_USER = "KEY_IS_FIRST_TIME_USER"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2018 Hossain Khan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hossainkhan.android.demo.data
18+
19+
import android.content.res.Resources
20+
import android.support.annotation.LayoutRes
21+
import com.hossainkhan.android.demo.R
22+
import javax.inject.Inject
23+
import javax.inject.Singleton
24+
25+
@Singleton
26+
class LayoutDataStore @Inject constructor(
27+
private val resources: Resources) {
28+
private val supportedLayoutInfos = listOf(
29+
LayoutInformation(
30+
layoutResourceId = R.layout.activity_positioning_top_left,
31+
title = "Positioning: Top Left",
32+
description = "Top left using constraints."),
33+
LayoutInformation(
34+
layoutResourceId = R.layout.activity_positioning_centered,
35+
title = "Positioning: Centered",
36+
description = "Centered view using constraints on top-bottom and left-right.")
37+
)
38+
39+
/**
40+
* A map of layout information by layout resource ID.
41+
*/
42+
val layoutsInfos: Map<Int, LayoutInformation> by lazy {
43+
supportedLayoutInfos.associateBy { it.layoutResourceId }
44+
}
45+
46+
/**
47+
* Returns Github URL for layout resource file for this project.
48+
*/
49+
fun getLayoutUrl(@LayoutRes layoutResourceId: Int): String {
50+
return resources.getResourceName(layoutResourceId)
51+
}
52+
}

0 commit comments

Comments
 (0)