Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonn-y2j committed Mar 10, 2021
0 parents commit 8a25688
Show file tree
Hide file tree
Showing 55 changed files with 1,275 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
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
local.properties
17 changes: 17 additions & 0 deletions .idea/$CACHE_FILE$

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

3 changes: 3 additions & 0 deletions .idea/.gitignore

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

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

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

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

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

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

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

9 changes: 9 additions & 0 deletions .idea/misc.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
68 changes: 68 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.project.retoandroid"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildFeatures.dataBinding true

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 = '1.8'
}
}

dependencies {

def retrofit_version = '2.9.0'
def ok_http3_version = '4.5.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.1.0'

implementation "com.squareup.okhttp3:logging-interceptor:$ok_http3_version"
implementation "com.squareup.okhttp3:okhttp:$ok_http3_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0'

implementation 'io.coil-kt:coil:0.11.0'

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
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 com.project.retoandroid

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.getInstrumentation().targetContext
assertEquals("com.project.retoandroid", appContext.packageName)
}
}
26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project.retoandroid">

<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/Theme.RetoAndroid">
<activity android:name=".app.user.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<activity android:name=".app.userDetail.UserDetailActivity" />

</application>

</manifest>
11 changes: 11 additions & 0 deletions app/src/main/java/com/project/retoandroid/app/Injection.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.project.retoandroid.app

import com.project.retoandroid.data.repository.UserRepository

object Injection {

fun provideUserRepository(): UserRepository {
return UserRepository.getInstance()
}

}
51 changes: 51 additions & 0 deletions app/src/main/java/com/project/retoandroid/app/user/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.project.retoandroid.app.user

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.project.retoandroid.R
import com.project.retoandroid.app.userDetail.UserDetailActivity
import com.project.retoandroid.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
private lateinit var viewModel: UserViewModel

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val factory = UserViewModel.Factory(application)
viewModel = ViewModelProvider(viewModelStore, factory).get(UserViewModel::class.java)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)

binding.viewModel = viewModel
binding.lifecycleOwner = this

binding.rviUsers.adapter = UserAdapter(viewModel)

initViewModel()

}

private fun initViewModel() {

viewModel.apply {

userSelected.observe(this@MainActivity, Observer {

it?.let {

UserDetailActivity.startActivity(it, this@MainActivity)

}

})

}

}

}
43 changes: 43 additions & 0 deletions app/src/main/java/com/project/retoandroid/app/user/UserAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.project.retoandroid.app.user

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.project.retoandroid.data.entity.User
import com.project.retoandroid.databinding.RowUserBinding

class UserAdapter(
private val userViewModel: UserViewModel
) : ListAdapter<User, UserAdapter.ViewHolder>(User.DIFF_CALLBACK) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder.from(parent)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val user = getItem(position)
holder.bind(userViewModel, user)
}

class ViewHolder private constructor(val binding: RowUserBinding) : RecyclerView.ViewHolder(binding.root) {

fun bind(userViewModel: UserViewModel, user: User) {
binding.user = user
binding.viewModel = userViewModel

binding.executePendingBindings()
}

companion object {

fun from(parent: ViewGroup): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val binding = RowUserBinding.inflate(layoutInflater, parent, false)
return ViewHolder(binding)
}

}

}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/project/retoandroid/app/user/UserBinding.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.project.retoandroid.app.user

import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView
import com.project.retoandroid.data.entity.User

@BindingAdapter("users")
fun bindUser(recyclerView: RecyclerView, users: List<User>? = emptyList()) {
users ?: return
(recyclerView.adapter as UserAdapter).apply {
submitList(users)
}
}
Loading

0 comments on commit 8a25688

Please sign in to comment.