-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
Bump 1(1.0.0)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
gradle.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## Kotlin MVVM Architecture | ||
|
||
A sample app that display list of New York Times news. The purpose of this project to illustrate the usage of MVVM architecture design pattern that follow the best practices of Object Oriented Design Patterns using the following technology stack. | ||
|
||
1. Architecture Design Pattern | ||
2. MVVM | ||
2. Hilt (Dependency Injection) | ||
3. Live Data | ||
4. Coroutines | ||
5. Retrofit | ||
6. Unit Testing | ||
7. Repository Pattern | ||
8. AndroidX | ||
9. Glide | ||
11. NYT News API | ||
12. JetPack Libraries | ||
|
||
### Demo | ||
<img height="400px" src="https://github.com/WaheedNazir/NewYorkTimesMvvmSample/blob/master/sample/nyt_sample.gif" /> | ||
|
||
### Other samples of MVVM using Kotlin | ||
|
||
* [Todo-App-Kotlin-MVVM-Hilt] - Todos app developed using Kotlin,MVVM, Hilt, Network Bound Resources etc. | ||
* [Android-MVVM-RxJava-Movies] - Movies app developed using Kotlin,MVVM, Koin and RxJava etc. | ||
|
||
[Todo-App-Kotlin-MVVM-Hilt]: <https://github.com/WaheedNazir/TodoKotlinMVVMHilt> | ||
[Android-MVVM-RxJava-Movies]: <https://github.com/WaheedNazir/Android-MVVM-RxJava-Movies> | ||
|
||
|
||
|
||
## Author | ||
[Waheed Nazir](https://github.com/WaheedNazir "Waheed Nazir (WaveTechStudio)") | ||
|
||
|
||
## API Sources | ||
1. [New York Times, Developer API](https://https://developer.nytimes.com/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
apply plugin: "androidx.navigation.safeargs.kotlin" | ||
apply plugin: 'dagger.hilt.android.plugin' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.waheed.nytimes" | ||
minSdkVersion 21 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
buildConfigField("String", "BASE_URL", "\"https://api.nytimes.com/svc/\"") | ||
buildConfigField("String", "API_KEY", "\"q3bzP5tg6ZGtRJoVn0kyGamEUE1vkOdk\"") | ||
|
||
testInstrumentationRunner "com.androiddevs.shoppinglisttestingyt.HiltTestRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_1_8.toString() | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: "libs", include: ["*.jar"]) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.5.0' | ||
implementation 'androidx.appcompat:appcompat:1.3.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | ||
|
||
// Material Design | ||
implementation 'com.google.android.material:material:1.4.0-rc01' | ||
|
||
// Architectural Components | ||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" | ||
|
||
// Lifecycle | ||
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" | ||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1" | ||
implementation "androidx.lifecycle:lifecycle-runtime:2.3.1" | ||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" | ||
|
||
// Room | ||
implementation "androidx.room:room-runtime:2.3.0" | ||
kapt "androidx.room:room-compiler:2.3.0" | ||
|
||
// Kotlin Extensions and Coroutines support for Room | ||
implementation "androidx.room:room-ktx:2.3.0" | ||
|
||
// Retrofit | ||
implementation 'com.squareup.retrofit2:retrofit:2.9.0' | ||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0' | ||
|
||
// Coroutines | ||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3' | ||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.3' | ||
|
||
// Coroutine Lifecycle Scopes | ||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" | ||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" | ||
|
||
// Navigation Components | ||
implementation "androidx.navigation:navigation-fragment-ktx:2.3.5" | ||
implementation "androidx.navigation:navigation-ui-ktx:2.3.5" | ||
|
||
// Glide | ||
implementation 'com.github.bumptech.glide:glide:4.12.0' | ||
kapt 'com.github.bumptech.glide:compiler:4.12.0' | ||
|
||
// Activity KTX for viewModels() | ||
implementation "androidx.activity:activity-ktx:1.2.3" | ||
|
||
//Dagger - Hilt | ||
implementation "com.google.dagger:hilt-android:2.35" | ||
kapt "com.google.dagger:hilt-android-compiler:2.35" | ||
|
||
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03" | ||
kapt "androidx.hilt:hilt-compiler:1.0.0" | ||
|
||
// Timber | ||
implementation 'com.jakewharton.timber:timber:4.7.1' | ||
|
||
// Local Unit Tests | ||
implementation "androidx.test:core:1.2.0" | ||
testImplementation "junit:junit:4.13" | ||
testImplementation "org.hamcrest:hamcrest-all:1.3" | ||
testImplementation "androidx.arch.core:core-testing:2.1.0" | ||
testImplementation "org.robolectric:robolectric:4.3.1" | ||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.1" | ||
testImplementation "com.google.truth:truth:1.0.1" | ||
testImplementation "org.mockito:mockito-core:2.21.0" | ||
|
||
// Instrumented Unit Tests | ||
androidTestImplementation "junit:junit:4.13" | ||
androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:2.12.1" | ||
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.2.1" | ||
androidTestImplementation "androidx.arch.core:core-testing:2.1.0" | ||
androidTestImplementation "com.google.truth:truth:1.0.1" | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
androidTestImplementation "org.mockito:mockito-core:2.21.0" | ||
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.28-alpha' | ||
kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.28-alpha' | ||
debugImplementation "androidx.fragment:fragment-testing:1.3.0-alpha08" | ||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0' | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.waheed.nytimes | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.androiddevs.shoppinglisttestingyt", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.waheed.nytimes | ||
|
||
import android.content.ComponentName | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.core.util.Preconditions | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentFactory | ||
import androidx.fragment.app.testing.FragmentScenario | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.core.app.ApplicationProvider | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
|
||
@ExperimentalCoroutinesApi | ||
inline fun <reified T : Fragment> launchFragmentInHiltContainer( | ||
fragmentArgs: Bundle? = null, | ||
themeResId: Int = R.style.FragmentScenarioEmptyFragmentActivityTheme, | ||
fragmentFactory: FragmentFactory? = null, | ||
crossinline action: T.() -> Unit = {} | ||
) { | ||
val mainActivityIntent = Intent.makeMainActivity( | ||
ComponentName( | ||
ApplicationProvider.getApplicationContext(), | ||
HiltTestActivity::class.java | ||
) | ||
).putExtra(FragmentScenario.EmptyFragmentActivity.THEME_EXTRAS_BUNDLE_KEY, themeResId) | ||
|
||
ActivityScenario.launch<HiltTestActivity>(mainActivityIntent).onActivity { activity -> | ||
fragmentFactory?.let { | ||
activity.supportFragmentManager.fragmentFactory = it | ||
} | ||
val fragment = activity.supportFragmentManager.fragmentFactory.instantiate( | ||
Preconditions.checkNotNull(T::class.java.classLoader), | ||
T::class.java.name | ||
) | ||
fragment.arguments = fragmentArgs | ||
|
||
activity.supportFragmentManager.beginTransaction() | ||
.add(android.R.id.content, fragment, "") | ||
.commitNow() | ||
|
||
(fragment as T).action() | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|