Changeset View
Changeset View
Standalone View
Standalone View
app/src/main/java/it/reyboz/bustorino/fragments/AlertsFragment.kt
| Show All 24 Lines | |||||
| import android.widget.TextView | import android.widget.TextView | ||||
| import androidx.cardview.widget.CardView | import androidx.cardview.widget.CardView | ||||
| import androidx.fragment.app.Fragment | import androidx.fragment.app.Fragment | ||||
| import androidx.fragment.app.activityViewModels | import androidx.fragment.app.activityViewModels | ||||
| import androidx.fragment.app.viewModels | import androidx.fragment.app.viewModels | ||||
| import androidx.recyclerview.widget.RecyclerView | import androidx.recyclerview.widget.RecyclerView | ||||
| import com.google.transit.realtime.GtfsRealtime | import com.google.transit.realtime.GtfsRealtime | ||||
| import it.reyboz.bustorino.R | import it.reyboz.bustorino.R | ||||
| import it.reyboz.bustorino.backend.Palina | |||||
| import it.reyboz.bustorino.viewmodels.ServiceAlertsViewModel | import it.reyboz.bustorino.viewmodels.ServiceAlertsViewModel | ||||
| import java.text.SimpleDateFormat | import java.text.SimpleDateFormat | ||||
| import java.util.Date | import java.util.Date | ||||
| import java.util.Locale | import java.util.Locale | ||||
| import java.util.TimeZone | import java.util.TimeZone | ||||
| /** | /** | ||||
| * A simple [Fragment] subclass. | * A simple [Fragment] subclass. | ||||
| * Use the [AlertsFragment.newInstance] factory method to | * Use the [AlertsFragment.newInstance] factory method to | ||||
| * create an instance of this fragment. | * create an instance of this fragment. | ||||
| */ | */ | ||||
| class AlertsFragment : ScreenBaseFragment() { | class AlertsFragment : ScreenBaseFragment() { | ||||
| private val alertsViewModel: ServiceAlertsViewModel by activityViewModels() | private val alertsViewModel: ServiceAlertsViewModel by activityViewModels() | ||||
| private lateinit var textView: TextView | private lateinit var textView: TextView | ||||
| private lateinit var statusTextView: TextView | |||||
| override fun onCreate(savedInstanceState: Bundle?) { | override fun onCreate(savedInstanceState: Bundle?) { | ||||
| super.onCreate(savedInstanceState) | super.onCreate(savedInstanceState) | ||||
| arguments?.let { | arguments?.let { | ||||
| //param1 = it.getString(ARG_PARAM1) | //param1 = it.getString(ARG_PARAM1) | ||||
| //param2 = it.getString(ARG_PARAM2) | //param2 = it.getString(ARG_PARAM2) | ||||
| } | } | ||||
| } | } | ||||
| override fun onCreateView( | override fun onCreateView( | ||||
| inflater: LayoutInflater, container: ViewGroup?, | inflater: LayoutInflater, container: ViewGroup?, | ||||
| savedInstanceState: Bundle? | savedInstanceState: Bundle? | ||||
| ): View? { | ): View? { | ||||
| // Inflate the layout for this fragment | // Inflate the layout for this fragment | ||||
| val root = inflater.inflate(R.layout.fragment_alerts, container, false) | val root = inflater.inflate(R.layout.fragment_alerts, container, false) | ||||
| textView = root.findViewById(R.id.simpleTextView) | textView = root.findViewById(R.id.simpleTextView) | ||||
| statusTextView = root.findViewById(R.id.statusTextView) | |||||
| alertsViewModel.allAlertsLiveData.observe(viewLifecycleOwner, { alerts -> | alertsViewModel.allAlertsLiveData.observe(viewLifecycleOwner, { alerts -> | ||||
| if(alerts==null){ | |||||
| return@observe | |||||
| } | |||||
| if(alerts.isEmpty()){ | |||||
| textView.text = "No Alerts to show" | |||||
| } else { | |||||
| val sb = StringBuilder() | val sb = StringBuilder() | ||||
| val unixTimestamp = (System.currentTimeMillis() / 1000) | val unixTimestamp = (System.currentTimeMillis() / 1000) | ||||
| for (x in alerts) { | for (x in alerts) { | ||||
| sb.append(x.longPrint()) | sb.append(x.longPrint()) | ||||
| sb.append("----- Alert active: ").append(x.isActive(unixTimestamp)).append("\n\n") | sb.append("----- Alert active: ").append(x.isActive(unixTimestamp)).append("\n\n") | ||||
| } | } | ||||
| textView.text = sb.toString() | textView.text = sb.toString() | ||||
| } | |||||
| }) | }) | ||||
| alertsViewModel.getDownloadStatusLiveData(requireContext()).observe(viewLifecycleOwner, { workinfos -> | |||||
| val sb = StringBuilder() | |||||
| var c = 1 | |||||
| if(workinfos!=null && workinfos.isNotEmpty()){ | |||||
| for (worki in workinfos){ | |||||
| sb.append("$c - state: ${worki.state}, attempt ${worki.runAttemptCount}").append("\n") | |||||
| c++ | |||||
| } | |||||
| } | |||||
| statusTextView.text = sb.toString() | |||||
| }) | |||||
| alertsViewModel.setStopFilter("472") | //alertsViewModel.setStopFilter(Palina("472") | ||||
| /*alertsViewModel.alertsForStop.observe(viewLifecycleOwner){ | /*alertsViewModel.alertsForStop.observe(viewLifecycleOwner){ | ||||
| Log.d(DEBUG_TAG, "Got ${it.size} alerts") | Log.d(DEBUG_TAG, "Got ${it.size} alerts") | ||||
| it?.let { | it?.let { | ||||
| showAlerts(it) | showAlerts(it) | ||||
| } | } | ||||
| } | } | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | companion object { | ||||
| sdf.timeZone = TimeZone.getTimeZone("Europe/Rome") | sdf.timeZone = TimeZone.getTimeZone("Europe/Rome") | ||||
| return sdf.format(date) | return sdf.format(date) | ||||
| } | } | ||||
| private const val DEBUG_TAG = "BusTO-AlertsFragment" | private const val DEBUG_TAG = "BusTO-AlertsFragment" | ||||
| } | } | ||||
| } | } | ||||
| No newline at end of file | No newline at end of file | ||||
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register