Skip to content

Commit

Permalink
Create All
Browse files Browse the repository at this point in the history
  • Loading branch information
indrian16 committed Sep 27, 2018
0 parents commit b4c536d
Show file tree
Hide file tree
Showing 84 changed files with 1,867 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
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 added .idea/caches/build_file_checksums.ser
Binary file not shown.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
55 changes: 55 additions & 0 deletions app/build.gradle
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'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
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 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)
}
}
23 changes: 23 additions & 0 deletions app/src/main/AndroidManifest.xml
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>
6 changes: 6 additions & 0 deletions app/src/main/java/io/indrian16/getrestapi/BasePresenter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.indrian16.getrestapi

interface BasePresenter {

fun start()
}
6 changes: 6 additions & 0 deletions app/src/main/java/io/indrian16/getrestapi/BaseView.kt
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 app/src/main/java/io/indrian16/getrestapi/base/BaseActivity.kt
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)
}

}
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
}
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/io/indrian16/getrestapi/model/Post.kt
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)
6 changes: 6 additions & 0 deletions app/src/main/java/io/indrian16/getrestapi/model/Todo.kt
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)
5 changes: 5 additions & 0 deletions app/src/main/java/io/indrian16/getrestapi/model/User.kt
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 app/src/main/java/io/indrian16/getrestapi/network/ApiService.kt
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)
}
}
}
Loading

0 comments on commit b4c536d

Please sign in to comment.