RoadReport / RoadReport_AndroidClient

「看路!」的 Android 專案,架構很亂btw
https://play.google.com/store/apps/details?id=com.txwstudio.app.roadreport
Apache License 2.0
0 stars 0 forks source link

在 LiveCamSelectCardAdapter 與 LiveCamViewModel 間新增 Repository #6

Closed MrNegativeTW closed 4 years ago

MrNegativeTW commented 4 years ago

Details

Context

在 LiveCamFragment 中,使用 RecyclerView 列出可用相機列表,並於 onClick 後更新 UI 上元件

The Problem

  1. 似乎缺少 Repository 作為橋梁,ViewModel 與 Adapter 間資料無法互通
  2. 若使用 companion object 放 MutableLiveData ,就算 ViewModel onDestory 後,資料仍繼續存在,下次進入時將會讀取上次資訊。

Solution For Now

  1. 於 LiveCamSelectCardAdapter 使用 companion object 放 MutableLiveData,並在 onClick 時更新
  2. LiveCamFragment 設定 observe 並更新相對應 UI

What I want

新增 Repository ?

Problem Code Location

LiveCamFragment.kt:56 LiveCamSelectCardAdapter.kt:16

Reference

How can I refresh viewModel livedata from another activity

MrNegativeTW commented 4 years ago

Seems solved by adding inner in front of that ViewHolder