-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit b4c536d
Showing
84 changed files
with
1,867 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,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,55 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
defaultConfig { | ||
applicationId "io.indrian16.getrestapi" | ||
minSdkVersion 16 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" | ||
|
||
// Android Support | ||
implementation 'com.android.support:appcompat-v7:27.1.1' | ||
implementation 'com.android.support:design:27.1.1' | ||
implementation 'com.android.support:cardview-v7:27.1.1' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
|
||
//Retrofit 2 | ||
implementation "com.squareup.retrofit2:retrofit:2.4.0" | ||
implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0" | ||
implementation "com.squareup.retrofit2:converter-moshi:2.4.0" | ||
|
||
// Okhttp3 + Interceptor | ||
implementation 'com.squareup.okhttp3:okhttp:3.11.0' | ||
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0' | ||
|
||
// Rx | ||
implementation "io.reactivex.rxjava2:rxjava:2.2.0" | ||
implementation "io.reactivex.rxjava2:rxandroid:2.1.0" | ||
implementation 'com.github.pwittchen:reactivenetwork-rx2:2.1.0' | ||
|
||
// Picasso | ||
implementation 'com.squareup.picasso:picasso:2.71828' | ||
|
||
// Test | ||
implementation 'com.android.support:support-v4:27.1.1' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
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/io/indrian16/getrestapi/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 io.indrian16.getrestapi | ||
|
||
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("io.indrian16.getrestapi", 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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="io.indrian16.getrestapi"> | ||
|
||
<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:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".base.BaseActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
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,6 @@ | ||
package io.indrian16.getrestapi | ||
|
||
interface BasePresenter { | ||
|
||
fun start() | ||
} |
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,6 @@ | ||
package io.indrian16.getrestapi | ||
|
||
interface BaseView<T> { | ||
|
||
val presenter: T | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/io/indrian16/getrestapi/base/BaseActivity.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,27 @@ | ||
package io.indrian16.getrestapi.base | ||
|
||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import io.indrian16.getrestapi.R | ||
import io.indrian16.getrestapi.util.setupActionBar | ||
import io.indrian16.getrestapi.util.setupViewPager | ||
|
||
class BaseActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_base) | ||
|
||
initView() | ||
} | ||
|
||
private fun initView() { | ||
|
||
setupActionBar(R.id.toolbar) { | ||
|
||
supportActionBar?.title = resources.getString(R.string.app_name) | ||
} | ||
setupViewPager(R.id.view_pager, R.id.tab_layout) | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/io/indrian16/getrestapi/base/adapter/ViewPagerAdapter.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,41 @@ | ||
package io.indrian16.getrestapi.base.adapter | ||
|
||
import android.support.v4.app.Fragment | ||
import android.support.v4.app.FragmentManager | ||
import android.support.v4.app.FragmentPagerAdapter | ||
import io.indrian16.getrestapi.ui.post.PostFragment | ||
import io.indrian16.getrestapi.ui.todo.TodoFragment | ||
import io.indrian16.getrestapi.ui.user.UserFragment | ||
import io.indrian16.getrestapi.util.Fragment_TITLE_0 | ||
import io.indrian16.getrestapi.util.Fragment_TITLE_1 | ||
import io.indrian16.getrestapi.util.Fragment_TITLE_2 | ||
import io.indrian16.getrestapi.util.NUM_PAGE | ||
|
||
class ViewPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) { | ||
|
||
override fun getItem(position: Int): Fragment { | ||
|
||
return when (position) { | ||
|
||
0 -> PostFragment() | ||
1 -> TodoFragment() | ||
2 -> UserFragment() | ||
|
||
else -> PostFragment() | ||
} | ||
} | ||
|
||
override fun getCount(): Int = NUM_PAGE | ||
|
||
override fun getPageTitle(position: Int): CharSequence? { | ||
|
||
return when(position) { | ||
|
||
0 -> Fragment_TITLE_0 | ||
1 -> Fragment_TITLE_1 | ||
2 -> Fragment_TITLE_2 | ||
|
||
else -> Fragment_TITLE_0 | ||
} | ||
} | ||
} |
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,6 @@ | ||
package io.indrian16.getrestapi.model | ||
|
||
data class Post(val userId: Int, | ||
val id: Int, | ||
val title: String, | ||
val body: String) |
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,6 @@ | ||
package io.indrian16.getrestapi.model | ||
|
||
data class Todo(val userId: Int, | ||
val id: Int, | ||
val title: String, | ||
val completed: Boolean) |
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,5 @@ | ||
package io.indrian16.getrestapi.model | ||
|
||
data class User(val id: Int, | ||
val name: String, | ||
val email: String) |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/io/indrian16/getrestapi/network/ApiService.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,37 @@ | ||
package io.indrian16.getrestapi.network | ||
|
||
import io.indrian16.getrestapi.model.Post | ||
import io.indrian16.getrestapi.model.Todo | ||
import io.indrian16.getrestapi.model.User | ||
import io.indrian16.getrestapi.util.BASE_URL | ||
import io.reactivex.Observable | ||
import retrofit2.Retrofit | ||
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory | ||
import retrofit2.converter.moshi.MoshiConverterFactory | ||
import retrofit2.http.GET | ||
|
||
interface ApiService { | ||
|
||
@GET("/posts") | ||
fun getPosts(): Observable<List<Post>> | ||
|
||
@GET("/todos") | ||
fun getTodos(): Observable<List<Todo>> | ||
|
||
@GET("/users") | ||
fun getUsers(): Observable<List<User>> | ||
|
||
companion object { | ||
|
||
fun create(): ApiService { | ||
|
||
val retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | ||
.addConverterFactory(MoshiConverterFactory.create()) | ||
.build() | ||
|
||
return retrofit.create(ApiService::class.java) | ||
} | ||
} | ||
} |
Oops, something went wrong.