Actually display the data

parent c0771d06
Pipeline #4786 passed with stages
in 3 minutes and 39 seconds
......@@ -8,13 +8,16 @@ import android.view.Menu
import android.view.MenuItem
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.flexbox.FlexboxLayoutManager
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import srct.whatsopen.util.MainViewAdapter
import srct.whatsopen.util.WhatsOpenService
class MainActivity : AppCompatActivity() {
......@@ -59,19 +62,16 @@ class MainActivity : AppCompatActivity() {
refreshLayout!!.isRefreshing = true
service!!.getData()
.subscribeOn(Schedulers.io())
.doOnError { err ->
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ facilities ->
refreshLayout!!.isRefreshing = false
recycle_view.adapter = MainViewAdapter(facilities)
}, { err ->
Toast.makeText(
applicationContext,
"Network Error: $err",
Toast.LENGTH_SHORT
).show()
}
.observeOn(AndroidSchedulers.mainThread())
.subscribe { facilities ->
run {
// findViewById<TextView>(R.id.main_text).text = facilities.toString()
refreshLayout!!.isRefreshing = false
}
}
})
}
}
package srct.whatsopen.util
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import srct.whatsopen.R
import srct.whatsopen.model.Facility
class MainViewAdapter(var facilities: List<Facility>) : RecyclerView.Adapter<Holder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
// return Holder(View.inflate(parent.context, R.layout.item_facility, null))
return Holder(
LayoutInflater.from(parent.context).inflate(
R.layout.item_facility,
parent,
false
)
)
}
override fun getItemCount(): Int {
return facilities.size
}
override fun onBindViewHolder(holder: Holder, position: Int) {
val facility = facilities[position]
holder.itemView.findViewById<TextView>(R.id.facility_title).text = facility.name
holder.itemView.findViewById<TextView>(R.id.change_text).text =
"24hr: ${facility.currentSchedule().isOpen24Hours}"
}
}
class Holder(view: View) : RecyclerView.ViewHolder(view)
......@@ -37,6 +37,7 @@
android:id="@+id/recycle_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_facility" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
\ No newline at end of file
......@@ -5,29 +5,33 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
app:cardElevation="4dp"
app:cardUseCompatPadding="false"
app:contentPadding="10dp">
<com.google.android.flexbox.FlexboxLayout
app:alignItems="stretch"
app:flexDirection="row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:alignItems="stretch"
app:flexDirection="row"
app:justifyContent="space_between">
<com.google.android.flexbox.FlexboxLayout
app:flexDirection="column"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
app:flexDirection="column">
<TextView
android:id="@+id/textView2"
android:id="@+id/facility_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Facility Name" />
<TextView
android:id="@+id/textView3"
android:id="@+id/change_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Open Status" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment