-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- 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 | ||
local.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.
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,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' | ||
} |
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) | ||
} | ||
} |
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> |
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() | ||
} | ||
|
||
} |
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) | ||
|
||
} | ||
|
||
}) | ||
|
||
} | ||
|
||
} | ||
|
||
} |
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) | ||
} | ||
|
||
} | ||
|
||
} | ||
} |
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) | ||
} | ||
} |