Skip to content

Commit

Permalink
一端終わり
Browse files Browse the repository at this point in the history
  • Loading branch information
175atsu committed Dec 6, 2019
1 parent afc0c05 commit c906e9d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'

def arch_lifecycle_version = '2.0.0'
implementation "androidx.lifecycle:lifecycle-runtime:$arch_lifecycle_version"
implementation "androidx.lifecycle:lifecycle-extensions:$arch_lifecycle_version"
implementation "androidx.lifecycle:lifecycle-reactivestreams:$arch_lifecycle_version"

//Glide
def glide_version = '4.9.0'
implementation "com.github.bumptech.glide:glide:$glide_version"
Expand Down
21 changes: 9 additions & 12 deletions app/src/main/java/com/example/qiitaapiapp/ListFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.fragment_list.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.Call
import retrofit2.Callback
import retrofit2.HttpException
import retrofit2.Response

class ListFragment: Fragment() {

var mContext: Context? = null
val Retrofit = RetrofitInstance()
private val mUser: ViewModel = ViewModel()

//
companion object {
Expand All @@ -49,7 +46,7 @@ class ListFragment: Fragment() {
fun recyclerViewInitialSetting() {
val rv = recyclerView
val adapter = ViewAdapter(searchGitHubRepositoryByCoroutines(), object : ViewAdapter.ListListener {
override fun onClickRow(tappedView: View, userListModel: Model) {
override fun onClickRow(tappedView: View, userListModel: ViewModel) {
toDetail(userListModel)
}
})
Expand All @@ -62,9 +59,9 @@ class ListFragment: Fragment() {
}

//データリストに保存し、そのデータの取得
// fun fetchAllUserData(): List<Model> {
// fun fetchAllUserData(): List<ViewModel> {
//
// val dataList = mutableListOf<Model>()
// val dataList = mutableListOf<ViewModel>()
// //リクエストURl作成してデータとる
// Retrofit.createService().apiDemo(page = 1, perPage = 20).enqueue(object : Callback<List<QiitResponse>> {
//
Expand All @@ -76,7 +73,7 @@ class ListFragment: Fragment() {
// if (response.isSuccessful) {
// response.body()?.let {
// for (item in it) {
// val data: Model = Model().also {
// val data: ViewModel = ViewModel().also {
// it.title = item.title
// it.url = item.url
// it.id = item.user!!.id
Expand Down Expand Up @@ -107,8 +104,8 @@ class ListFragment: Fragment() {
}

val coroutineScope = CoroutineScope(context = Dispatchers.Main)
fun searchGitHubRepositoryByCoroutines(): List<Model> {
val dataList = mutableListOf<Model>()
fun searchGitHubRepositoryByCoroutines(): List<ViewModel> {
val dataList = mutableListOf<ViewModel>()
coroutineScope.launch {
try {
val qiitaRepositoriesData = qiitRepositoriesByCoroutines(
Expand All @@ -117,7 +114,7 @@ class ListFragment: Fragment() {
)
qiitaRepositoriesData.let {
for (item in it) {
val data: Model = Model().also {
val data: ViewModel = ViewModel().also {
it.title = item.title
it.url = item.url
it.id = item.user?.id
Expand All @@ -138,7 +135,7 @@ class ListFragment: Fragment() {


//詳細ページへの遷移
fun toDetail(urlData: Model) {
fun toDetail(urlData: ViewModel) {
val fragment = WebViewFragment()
val bundle = Bundle().apply {
putString("URL", urlData.url)
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/com/example/qiitaapiapp/ViewAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package com.example.qiitaapiapp
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.util.Util

class ViewAdapter(private val list: List<Model>, private val listener: ListListener): RecyclerView.Adapter<ViewHolder>() {
class ViewAdapter(private val list: List<ViewModel>, private val listener: ListListener): RecyclerView.Adapter<ViewHolder>() {
//レイアウト
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
Expand Down Expand Up @@ -42,6 +40,6 @@ class ViewAdapter(private val list: List<Model>, private val listener: ListListe

//質問
interface ListListener {
fun onClickRow(tappedView: View, rowModel: Model)
fun onClickRow(tappedView: View, rowModel: ViewModel)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.qiitaapiapp

class Model {
class ViewModel {
var title: String? = null
var id: String? = null
var url: String? = null
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/layout/row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
<data>
<variable
name="viewmodel"
type="com.example.qiitaapiapp.Model" />
type="com.example.qiitaapiapp.ViewModel" />
</data>


<LinearLayout
android:id="@+id/cell"
android:layout_width="match_parent"
Expand All @@ -22,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_margin="10dp"
android:text="TextView" />
android:text="@{viewmodel.title}" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand All @@ -48,7 +47,7 @@
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="TextView"
android:text="@{viewmodel.id}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down

0 comments on commit c906e9d

Please sign in to comment.