Commit 5733b3f1 authored by Joey's avatar Joey

app, core: remove unused code

Signed-off-by: Joey's avatarJoey <bevilacquajoey@gmail.com>
Change-Id: Ib2cd8c28e459755e73bf97669e502b88c7b8244b
parent b2247e7f
Pipeline #59742843 passed with stages
in 18 minutes and 11 seconds
......@@ -19,9 +19,9 @@ import androidx.lifecycle.MutableLiveData
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import it.diab.R
import it.diab.data.entities.Glucose
import it.diab.core.util.PreferencesUtil
import it.diab.core.util.event.Event
import it.diab.data.entities.Glucose
import it.diab.holders.GlucoseHolder
import it.diab.holders.GlucoseHolderCallbacks
import it.diab.util.UIUtils
......@@ -46,10 +46,6 @@ class GlucoseListAdapter(
private val lowThreshold by lazy { PreferencesUtil.getGlucoseLowThreshold(context) }
private val hourFormat = SimpleDateFormat("HH:mm", Locale.getDefault())
private val dateFormat = SimpleDateFormat(
context.getString(R.string.glucose_header_month),
Locale.getDefault()
)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
GlucoseHolder(
......@@ -66,10 +62,6 @@ class GlucoseListAdapter(
}
}
override fun fetchHeaderText(date: Date, onFetch: (String, CoroutineScope) -> Unit) {
viewModel.setHeader(date, dateFormat, onFetch)
}
override fun fetchHourText(date: Date, onFetch: (String, CoroutineScope) -> Unit) {
val text = hourFormat.format(date)
onFetch(text, viewModel.viewModelScope)
......
......@@ -8,7 +8,6 @@
*/
package it.diab.fragments
import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
......@@ -21,11 +20,11 @@ import androidx.paging.PagedList
import androidx.recyclerview.widget.RecyclerView
import it.diab.R
import it.diab.adapters.GlucoseListAdapter
import it.diab.core.util.event.Event
import it.diab.core.util.event.EventObserver
import it.diab.data.entities.Glucose
import it.diab.data.repositories.GlucoseRepository
import it.diab.data.repositories.InsulinRepository
import it.diab.core.util.event.Event
import it.diab.core.util.event.EventObserver
import it.diab.ui.TimeHeaderDecoration
import it.diab.util.extensions.doOnNextLayout
import it.diab.util.extensions.removeAllItemDecorators
......@@ -71,8 +70,6 @@ class GlucoseListFragment : BaseFragment() {
val activity = activity ?: return
viewModel.prepare {
setViewModelStrings()
adapter = GlucoseListAdapter(activity, viewModel)
recyclerView.adapter = adapter
......@@ -83,13 +80,6 @@ class GlucoseListFragment : BaseFragment() {
}
}
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
// Update strings in case Locale changed
setViewModelStrings()
}
private fun update(data: PagedList<Glucose>?) {
adapter.submitList(data)
}
......@@ -98,14 +88,6 @@ class GlucoseListFragment : BaseFragment() {
_openGlucose.value = Event(uid)
}
private fun setViewModelStrings() {
viewModel.setDateStrings(
resources.getString(R.string.time_today),
resources.getString(R.string.time_yesterday),
resources.getString(R.string.glucose_header_last)
)
}
private fun updateHeaders(list: List<Glucose>) {
if (list.isEmpty()) {
return
......
......@@ -14,17 +14,6 @@ import java.util.Date
interface GlucoseHolderCallbacks {
/**
* Fetch a String that for the header
*
* @param date date to be put in the string
* @param onFetch callback for fetch completion
*/
fun fetchHeaderText(
date: Date,
onFetch: (String, CoroutineScope) -> Unit
)
/**
* Fetch a String that represents hours of a given [Date]
*
......
......@@ -10,17 +10,12 @@ package it.diab.viewmodels.glucose
import androidx.annotation.VisibleForTesting
import androidx.paging.LivePagedListBuilder
import it.diab.core.viewmodels.ScopedViewModel
import it.diab.data.entities.Insulin
import it.diab.data.repositories.GlucoseRepository
import it.diab.data.repositories.InsulinRepository
import it.diab.core.viewmodels.ScopedViewModel
import it.diab.util.extensions.diff
import it.diab.util.extensions.getWeekDay
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.text.SimpleDateFormat
import java.util.Date
class GlucoseListViewModel internal constructor(
glucoseRepository: GlucoseRepository,
......@@ -31,10 +26,6 @@ class GlucoseListViewModel internal constructor(
private lateinit var insulins: List<Insulin>
private var yesterday = ""
private var today = ""
private var lastX = "%1\$s"
fun prepare(block: () -> Unit) {
viewModelScope.launch {
runPrepare()
......@@ -44,40 +35,8 @@ class GlucoseListViewModel internal constructor(
fun getInsulin(uid: Long) = insulins.firstOrNull { it.uid == uid } ?: Insulin()
fun setHeader(
date: Date,
format: SimpleDateFormat,
block: (String, CoroutineScope) -> Unit
) {
viewModelScope.launch {
val text = runSetHeader(date, format)
block(text, viewModelScope)
}
}
fun setDateStrings(
today: String,
yesterday: String,
lastX: String
) {
this.yesterday = yesterday
this.today = today
this.lastX = lastX
}
@VisibleForTesting
fun runPrepare() {
insulins = insulinRepository.getInsulins()
}
@VisibleForTesting
fun runSetHeader(date: Date, format: SimpleDateFormat): String {
val diff = date.diff(Date())
return when {
diff == 0 -> today
diff == -1 -> yesterday
diff > -7 -> lastX.format(date.getWeekDay())
else -> format.format(date)
}
}
}
\ No newline at end of file
......@@ -12,8 +12,4 @@
<string name="fit_name">फिट एकीकरण</string>
<string name="settings_name">सेटिंग्स</string>
<!-- Time -->
<string name="time_today">आज</string>
<string name="time_yesterday">कल</string>
</resources>
......@@ -11,8 +11,4 @@
<string name="fit_name">Integrazione Fit</string>
<string name="settings_name">Impostazioni</string>
<!-- Time -->
<string name="time_today">Oggi</string>
<string name="time_yesterday">Ieri</string>
</resources>
\ No newline at end of file
......@@ -11,8 +11,4 @@
<string name="fit_name">Fit integration</string>
<string name="settings_name">Settings</string>
<!-- Time -->
<string name="time_today">Today</string>
<string name="time_yesterday">Yesterday</string>
</resources>
......@@ -33,4 +33,8 @@
<string name="check_again_notification_title">Check glucose again</string>
<string name="check_again_notification_content">Glucose value was low not so long ago, would you mind checking it again?</string>
<string name="check_again_notification_channel">Reminders</string>
<!-- Time -->
<string name="time_today">आज</string>
<string name="time_yesterday">कल</string>
</resources>
......@@ -33,4 +33,8 @@
<string name="check_again_notification_title">Controlla glicemia</string>
<string name="check_again_notification_content">I valori glicemici erano bassi poco fa, desideri controllarli nuovamente?</string>
<string name="check_again_notification_channel">Promemoria</string>
<!-- Time -->
<string name="time_today">Oggi</string>
<string name="time_yesterday">Ieri</string>
</resources>
\ No newline at end of file
......@@ -33,4 +33,8 @@
<string name="check_again_notification_title">Check glucose again</string>
<string name="check_again_notification_content">Glucose value was low not so long ago, would you mind checking it again?</string>
<string name="check_again_notification_channel">Reminders</string>
<!-- Time -->
<string name="time_today">Today</string>
<string name="time_yesterday">Yesterday</string>
</resources>
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