|
@@ -3,6 +3,8 @@ package me.vadik.knigopis
|
|
|
import android.os.Bundle
|
|
import android.os.Bundle
|
|
|
import android.support.design.widget.BottomNavigationView
|
|
import android.support.design.widget.BottomNavigationView
|
|
|
import android.support.v7.app.AppCompatActivity
|
|
import android.support.v7.app.AppCompatActivity
|
|
|
|
|
+import android.support.v7.widget.LinearLayoutManager
|
|
|
|
|
+import android.support.v7.widget.RecyclerView
|
|
|
import android.view.MenuItem
|
|
import android.view.MenuItem
|
|
|
import retrofit2.Call
|
|
import retrofit2.Call
|
|
|
import retrofit2.Callback
|
|
import retrofit2.Callback
|
|
@@ -11,6 +13,8 @@ import retrofit2.Response
|
|
|
class MainActivity : AppCompatActivity() {
|
|
class MainActivity : AppCompatActivity() {
|
|
|
|
|
|
|
|
private val api by lazy { app().retrofit.create(Endpoint::class.java) }
|
|
private val api by lazy { app().retrofit.create(Endpoint::class.java) }
|
|
|
|
|
+ private val recyclerView by lazy { findViewById(R.id.recycler_view) as RecyclerView }
|
|
|
|
|
+ private val users = mutableListOf<User>()
|
|
|
|
|
|
|
|
private val onNavigationItemSelectedListener = { item: MenuItem ->
|
|
private val onNavigationItemSelectedListener = { item: MenuItem ->
|
|
|
supportActionBar!!.setTitle(when (item.itemId) {
|
|
supportActionBar!!.setTitle(when (item.itemId) {
|
|
@@ -27,10 +31,15 @@ class MainActivity : AppCompatActivity() {
|
|
|
setContentView(R.layout.activity_main)
|
|
setContentView(R.layout.activity_main)
|
|
|
val navigation = findViewById(R.id.navigation) as BottomNavigationView
|
|
val navigation = findViewById(R.id.navigation) as BottomNavigationView
|
|
|
navigation.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener)
|
|
navigation.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener)
|
|
|
|
|
+ val adapter = UsersAdapter(users)
|
|
|
|
|
+ recyclerView.adapter = adapter
|
|
|
|
|
+ recyclerView.layoutManager = LinearLayoutManager(this)
|
|
|
api.latestUsers().enqueue(object : Callback<Map<String, User>> {
|
|
api.latestUsers().enqueue(object : Callback<Map<String, User>> {
|
|
|
override fun onResponse(call: Call<Map<String, User>>?, response: Response<Map<String, User>>?) {
|
|
override fun onResponse(call: Call<Map<String, User>>?, response: Response<Map<String, User>>?) {
|
|
|
- response?.body()?.forEach { (_, user) ->
|
|
|
|
|
- logw(user.nickname)
|
|
|
|
|
|
|
+ users.clear()
|
|
|
|
|
+ response?.body()?.values?.forEach { user ->
|
|
|
|
|
+ users.add(user)
|
|
|
|
|
+ adapter.notifyItemInserted(0)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|