Skip to content

Commit

Permalink
setup base source code
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-nhatvm committed May 20, 2021
1 parent 5c24ecf commit 3cb6a86
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 9 deletions.
108 changes: 105 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}

def apikeyPropertiesFile = rootProject.file("apikey.properties")
def apikeyProperties = new Properties()
apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))

android {
buildFeatures{
dataBinding = true
}

compileSdkVersion 30

defaultConfig {
Expand All @@ -29,6 +39,27 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}

flavorDimensions "default"
productFlavors {

dev {
buildConfigField("String", "BASE_URL", apikeyProperties['BASE_URL_DEV'])
buildConfigField("String", "ACCESS_TOKEN", apikeyProperties['ACCESS_TOKEN_DEV'])
}

staging {
buildConfigField("String", "BASE_URL", apikeyProperties['BASE_URL_STAGING'])
buildConfigField("String", "ACCESS_TOKEN", apikeyProperties['ACCESS_TOKEN_STAGING'])
}

live {
buildConfigField("String", "BASE_URL", apikeyProperties['BASE_URL_LIVE'])
buildConfigField("String", "ACCESS_TOKEN", apikeyProperties['ACCESS_TOKEN_LIVE'])
}

}

}

dependencies {
Expand All @@ -37,7 +68,78 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'


implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
implementation 'androidx.navigation:navigation-fragment:2.3.2'
implementation 'androidx.navigation:navigation-ui:2.3.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'

// testing JUnit 4 framework
testImplementation 'junit:junit:4.13.1'

// testing Mockito
testImplementation 'org.mockito:mockito-core:2.25.0'
testImplementation 'org.mockito:mockito-android:2.24.5'
testImplementation 'org.mockito:mockito-inline:2.25.0'

// testing Power Mock for mock final class and method
testImplementation 'org.powermock:powermock-api-mockito2:2.0.9'
testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
testImplementation 'org.powermock:powermock-core:1.7.4'


// testing mock web server
testImplementation "com.squareup.okhttp3:mockwebserver:$mockwebserver"

// testing AndroidX Test - JVM testing
testImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"

// testing robolectric
testImplementation "org.robolectric:robolectric:$robolectric_version"

// testing arch
testImplementation "androidx.arch.core:core-testing:$archTestingVersion"

// constraint layout
implementation "androidx.constraintlayout:constraintlayout:$constraintlayout_version"

// view model scope
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'

// retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"

// moshi
implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"

// okhttpclient
implementation "com.squareup.okhttp3:okhttp:$ok_httpclient_version"
implementation "com.squareup.okhttp3:logging-interceptor:$ok_httpclient_version"

// glide library
implementation "com.github.bumptech.glide:glide:$glide_version"

// dagger
implementation "com.google.dagger:dagger:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
kapt "com.google.dagger:dagger-android-processor:$dagger_version"

// coroutine
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

// viewpager 2
implementation "androidx.viewpager2:viewpager2:1.0.0"

implementation "androidx.activity:activity-ktx:1.2.0"

// flexbox
implementation 'com.google.android:flexbox:2.0.1'

//circle image
implementation 'de.hdodenhof:circleimageview:3.1.0'
}
16 changes: 15 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FatherOfApps" />
android:theme="@style/Theme.FatherOfApps"
>
<activity
android:screenOrientation="portrait"
android:name=".activities.MainActivity" />
<activity
android:screenOrientation="portrait"
android:name=".activities.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
42 changes: 42 additions & 0 deletions app/src/test/java/com/fatherofapps/androidbase/LiveDataTestUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.fatherofapps.androidbase

import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException


@VisibleForTesting(otherwise = VisibleForTesting.NONE)
fun <T> LiveData<T>.getOrAwaitValue(
time: Long = 2,
timeUnit: TimeUnit = TimeUnit.SECONDS,
afterObserve: () -> Unit = {}
): T {
var data: T? = null
val latch = CountDownLatch(1)
val observer = object : Observer<T> {
override fun onChanged(o: T?) {
data = o
latch.countDown()
this@getOrAwaitValue.removeObserver(this)
}
}
this.observeForever(observer)

try {
afterObserve.invoke()

// Don't wait indefinitely if the LiveData is not set.
if (!latch.await(time, timeUnit)) {
throw TimeoutException("LiveData value was never set.")
}

} finally {
this.removeObserver(observer)
}

@Suppress("UNCHECKED_CAST")
return data as T
}
23 changes: 19 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.0"
ext.kotlin_version = "1.4.30"
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
classpath 'com.android.tools.build:gradle:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5"
}
}

Expand All @@ -22,6 +22,21 @@ allprojects {
}
}

ext {
retrofit_version = '2.9.0'
dagger_version = '2.30.1'
moshi_version ='1.11.0'
ok_httpclient_version = '4.9.0'
glide_version = '4.11.0'
coroutines_version = '1.3.9'
constraintlayout_version = '2.0.4'
mockwebserver = '4.9.0'
robolectric_version = '4.4'
androidXTestCoreVersion = '1.1.0'
androidXTestExtKotlinRunnerVersion = '1.1.1'
archTestingVersion = '2.1.0'
}

task clean(type: Delete) {
delete rootProject.buildDir
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4608m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand All @@ -15,5 +15,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# Android operating system, and which are packaged with your app"s APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

0 comments on commit 3cb6a86

Please sign in to comment.