-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
1,250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
# Gradle files | ||
/.idea | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# Intellij | ||
*.iml | ||
.idea/workspace.xml | ||
.idea/tasks.xml | ||
.idea/gradle.xml | ||
.idea/dictionaries | ||
.idea/libraries | ||
|
||
# Keystore files | ||
*.jks | ||
|
||
# External native build folder generated in Android Studio 2.2 and later | ||
.externalNativeBuild | ||
|
||
# Google Services (e.g. APIs or Firebase) | ||
google-services.json | ||
|
||
# Freeline | ||
freeline.py | ||
freeline/ | ||
freeline_project_description.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
def getProperty(String filename, String propName) { | ||
def propsFile = rootProject.file(filename) | ||
if (propsFile.exists()) { | ||
def props = new Properties() | ||
props.load(new FileInputStream(propsFile)) | ||
if (props[propName] != null) { | ||
return props[propName] | ||
} else { | ||
print("No such property " + propName + " in file " + filename); | ||
} | ||
} else { | ||
print(filename + " does not exist!") | ||
} | ||
} | ||
|
||
android { | ||
compileSdkVersion rootProject.compileSdkVersion | ||
defaultConfig { | ||
applicationId "com.skydoves.themovies" | ||
minSdkVersion rootProject.minSdkVersion | ||
targetSdkVersion rootProject.targetSdkVersion | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
buildConfigField "String", "TMDB_API_KEY", "\"${getProperty("local.properties", "tmdb_api_key")}\"" | ||
} | ||
kapt { | ||
correctErrorTypes = true | ||
} | ||
dataBinding { | ||
enabled = true | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
// support library | ||
implementation "com.android.support:appcompat-v7:$supportLibraryVersion" | ||
implementation "com.android.support:recyclerview-v7:$supportLibraryVersion" | ||
|
||
// kotlin | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" | ||
|
||
// architecture components | ||
implementation "android.arch.lifecycle:extensions:$archCompomentVersion" | ||
implementation "android.arch.persistence.room:runtime:$archCompomentVersion" | ||
kapt "android.arch.persistence.room:compiler:$archCompomentVersion" | ||
|
||
// dependency injection | ||
implementation "com.google.dagger:dagger:$daggerVersion" | ||
implementation "com.google.dagger:dagger-android:$daggerVersion" | ||
implementation "com.google.dagger:dagger-android-support:$daggerVersion" | ||
kapt "com.google.dagger:dagger-compiler:$daggerVersion" | ||
kapt "com.google.dagger:dagger-android-processor:$daggerVersion" | ||
|
||
// network | ||
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" | ||
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" | ||
implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion" | ||
implementation "com.google.code.gson:gson:$retrofitVersion" | ||
|
||
// glide | ||
implementation "com.github.bumptech.glide:glide:$glideVersion" | ||
kapt "com.github.bumptech.glide:compiler:$glideVersion" | ||
|
||
// debugging | ||
implementation "com.jakewharton.timber:timber:$timberVersion" | ||
implementation "com.facebook.stetho:stetho:$stethoVersion" | ||
implementation "com.facebook.stetho:stetho-okhttp3:$stethoVersion" | ||
|
||
testImplementation 'junit:junit:4.12' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/com/skydoves/themovies/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.skydoves.themovies | ||
|
||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.runner.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.getTargetContext() | ||
assertEquals("com.skydoves.themovies", appContext.packageName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.skydoves.themovies"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:name=".TheMoviesApplication" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".view.ui.main.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/skydoves/themovies/TheMoviesApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.skydoves.themovies | ||
|
||
import com.facebook.stetho.Stetho | ||
import com.skydoves.themovies.di.DaggerAppComponent | ||
import dagger.android.AndroidInjector | ||
import dagger.android.DaggerApplication | ||
import timber.log.Timber | ||
|
||
/** | ||
* Developed by skydoves on 2018-08-07. | ||
* Copyright (c) 2018 skydoves rights reserved. | ||
*/ | ||
|
||
class TheMoviesApplication: DaggerApplication() { | ||
|
||
private val appComponent = DaggerAppComponent.builder() | ||
.application(this) | ||
.build() | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
appComponent.inject(this) | ||
|
||
if (BuildConfig.DEBUG) { | ||
Timber.plant(Timber.DebugTree()) | ||
} | ||
|
||
Stetho.initializeWithDefaults(this) | ||
} | ||
|
||
override fun applicationInjector(): AndroidInjector<out DaggerApplication> { | ||
return appComponent | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/skydoves/themovies/api/ApiResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.skydoves.themovies.api | ||
|
||
import retrofit2.Response | ||
import timber.log.Timber | ||
import java.io.IOException | ||
|
||
/** | ||
* Developed by skydoves on 2018-08-07. | ||
* Copyright (c) 2018 skydoves rights reserved. | ||
*/ | ||
|
||
class ApiResponse<T> { | ||
val code: Int | ||
val body: T? | ||
val message: String? | ||
|
||
val isSuccessful: Boolean | ||
get() = code in 200..300 | ||
|
||
constructor(error: Throwable) { | ||
this.code = 500 | ||
this.body = null | ||
this.message = error.message | ||
} | ||
|
||
constructor(response: Response<T>) { | ||
this.code = response.code() | ||
|
||
if (response.isSuccessful) { | ||
this.body = response.body() | ||
this.message = response.message() | ||
} else { | ||
var errorMessage: String? = null | ||
response.errorBody()?.let { | ||
try { | ||
errorMessage = response.errorBody()!!.string() | ||
} catch (ignored: IOException) { | ||
Timber.e(ignored, "error while parsing response") | ||
} | ||
} | ||
|
||
errorMessage?.apply { | ||
if(isNullOrEmpty() || trim { it <= ' ' }.isEmpty()) { | ||
errorMessage = response.message() | ||
} | ||
} | ||
|
||
this.body = null | ||
this.message = errorMessage | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/skydoves/themovies/api/LiveDataCallAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.skydoves.themovies.api | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
import android.arch.lifecycle.LiveData | ||
import retrofit2.Call | ||
import retrofit2.CallAdapter | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
import java.lang.reflect.Type | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
/** | ||
* A Retrofit adapter that converts the Call into a LiveData of ApiResponse. | ||
* @param <R> | ||
</R> */ | ||
class LiveDataCallAdapter<R>(private val responseType: Type) : CallAdapter<R, LiveData<ApiResponse<R>>> { | ||
|
||
override fun responseType(): Type { | ||
return responseType | ||
} | ||
|
||
override fun adapt(call: Call<R>): LiveData<ApiResponse<R>> { | ||
return object : LiveData<ApiResponse<R>>() { | ||
var started = AtomicBoolean(false) | ||
override fun onActive() { | ||
super.onActive() | ||
if (started.compareAndSet(false, true)) { | ||
call.enqueue(object : Callback<R> { | ||
override fun onResponse(call: Call<R>, response: Response<R>) { | ||
postValue(ApiResponse(response)) | ||
} | ||
|
||
override fun onFailure(call: Call<R>, throwable: Throwable) { | ||
postValue(ApiResponse(throwable)) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.