Skip to content

Commit

Permalink
Include simplified list activity for comparison of technology
Browse files Browse the repository at this point in the history
  • Loading branch information
ashdavies committed Aug 19, 2019
1 parent 17d4fa0 commit fd5331a
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 4 deletions.
Binary file removed art/device-2018-06-10-191700.png
Binary file not shown.
Binary file removed art/device-2018-06-10-200109.png
Binary file not shown.
Binary file added art/list-activity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:icon="@mipmap/ic_launcher"
android:theme="@style/Theme.DataBinding">

<activity android:name="io.ashdavies.databinding.repos.RepoActivity"
<activity android:name=".repos.RepoActivity"
android:label="@string/application">

<intent-filter>
Expand All @@ -18,6 +18,10 @@

</activity>

<activity android:name=".list.ListActivity"
android:exported="true"
android:label="@string/application" />

</application>

</manifest>
37 changes: 37 additions & 0 deletions src/main/kotlin/io/ashdavies/databinding/list/ListActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.ashdavies.databinding.list

import android.os.Bundle
import android.widget.ArrayAdapter
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import io.ashdavies.databinding.R
import io.ashdavies.databinding.databinding.ActivityListBinding
import io.ashdavies.databinding.extensions.activityBinding
import io.ashdavies.databinding.repos.retrofit
import io.ashdavies.databinding.services.GitHubService
import kotlinx.coroutines.launch
import retrofit2.create

internal class ListActivity : AppCompatActivity() {

private val binding: ActivityListBinding by activityBinding(R.layout.activity_list)

private val service: GitHubService = retrofit.create()

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

setSupportActionBar(binding.toolbar)
binding.lifecycleOwner = this

lifecycleScope.launch {
binding.list.adapter = ArrayAdapter(this@ListActivity, android.R.layout.simple_list_item_1, repos("Kotlin"))
}
}

private suspend fun repos(name: String): Array<String> = service
.repos("$name+in:name,description", 0, 50)
.items
.map { it.name }
.toTypedArray()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class RepoBoundaryCallback(
private val _error: MutableLiveData<Throwable> = MutableLiveData()
val error: LiveData<Throwable> = _error

private var page: Int = 1
private var page: Int = 0

override fun onZeroItemsLoaded() {
requestItems()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ internal class RepoViewModel(repository: RepoRepository) : ViewModel() {
.consumeAsFlow()
.filter { it.length >= MIN_LENGTH }
.debounce(500)
.onEach { println("query $it") }
.collect { query.value = it }
}
}

fun onQuery(value: String) {
println("offered $value")
viewModelScope.launch {
_query.send(value)
}
Expand Down
37 changes: 37 additions & 0 deletions src/main/res/layout/activity_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".repos.RepoActivity">

<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</com.google.android.material.appbar.AppBarLayout>

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingTop="@dimen/vertical_spacing"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@android:layout/simple_list_item_1" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

0 comments on commit fd5331a

Please sign in to comment.