Food xml cleanup

This commit is contained in:
Milos Kozak 2022-04-25 14:55:30 +02:00
parent d357698a6a
commit 2a3341b5be
3 changed files with 97 additions and 166 deletions

View file

@ -17,7 +17,6 @@ import info.nightscout.androidaps.database.AppRepository
import info.nightscout.androidaps.database.entities.Food import info.nightscout.androidaps.database.entities.Food
import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.database.entities.UserEntry.Action
import info.nightscout.androidaps.database.entities.UserEntry.Sources import info.nightscout.androidaps.database.entities.UserEntry.Sources
import info.nightscout.androidaps.database.entities.ValueWithUnit
import info.nightscout.androidaps.database.transactions.InvalidateFoodTransaction import info.nightscout.androidaps.database.transactions.InvalidateFoodTransaction
import info.nightscout.androidaps.databinding.FoodFragmentBinding import info.nightscout.androidaps.databinding.FoodFragmentBinding
import info.nightscout.androidaps.databinding.FoodItemBinding import info.nightscout.androidaps.databinding.FoodItemBinding
@ -26,7 +25,6 @@ import info.nightscout.androidaps.events.EventFoodDatabaseChanged
import info.nightscout.androidaps.extensions.toVisibility import info.nightscout.androidaps.extensions.toVisibility
import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.logging.UserEntryLogger
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.protection.ProtectionCheck
@ -35,10 +33,8 @@ import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.androidaps.utils.ui.UIRunnable import info.nightscout.androidaps.utils.ui.UIRunnable
import info.nightscout.shared.logging.AAPSLogger import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag import info.nightscout.shared.logging.LTag
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import io.reactivex.rxjava3.kotlin.subscribeBy
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
@ -73,27 +69,7 @@ class FoodFragment : DaggerFragment() {
binding.recyclerview.setHasFixedSize(true) binding.recyclerview.setHasFixedSize(true)
binding.recyclerview.layoutManager = LinearLayoutManager(view.context) binding.recyclerview.layoutManager = LinearLayoutManager(view.context)
binding.refreshFromNightscout.setOnClickListener { binding.filterInputLayout.setEndIconOnClickListener {
context?.let { context ->
OKDialog.showConfirmation(context, rh.gs(R.string.refresheventsfromnightscout) + " ?", {
uel.log(
Action.FOOD, Sources.Food, rh.gs(R.string.refresheventsfromnightscout),
ValueWithUnit.SimpleString(rh.gsNotLocalised(R.string.refresheventsfromnightscout))
)
disposable += Completable.fromAction { repository.deleteAllFoods() }
.subscribeOn(aapsSchedulers.io)
.observeOn(aapsSchedulers.main)
.subscribeBy(
onError = { aapsLogger.error("Error removing foods", it) },
onComplete = { rxBus.send(EventFoodDatabaseChanged()) }
)
rxBus.send(EventNSClientRestart())
})
}
}
binding.filterinputLayout.setEndIconOnClickListener {
binding.filter.setText("") binding.filter.setText("")
binding.categoryList.setText(rh.gs(R.string.none), false) binding.categoryList.setText(rh.gs(R.string.none), false)
binding.subcategoryList.setText(rh.gs(R.string.none), false) binding.subcategoryList.setText(rh.gs(R.string.none), false)
@ -220,7 +196,6 @@ class FoodFragment : DaggerFragment() {
holder.binding.energy.text = rh.gs(R.string.shortenergy) + ": " + food.energy + rh.gs(R.string.shortkilojoul) holder.binding.energy.text = rh.gs(R.string.shortenergy) + ": " + food.energy + rh.gs(R.string.shortkilojoul)
holder.binding.energy.visibility = food.energy.isNotZero().toVisibility() holder.binding.energy.visibility = food.energy.isNotZero().toVisibility()
holder.binding.icRemove.tag = food holder.binding.icRemove.tag = food
holder.binding.foodItem.tag = food
holder.binding.icCalculator.tag = food holder.binding.icCalculator.tag = food
} }

View file

@ -6,37 +6,27 @@
android:orientation="vertical" android:orientation="vertical"
tools:context="info.nightscout.androidaps.plugins.general.food.FoodFragment"> tools:context="info.nightscout.androidaps.plugins.general.food.FoodFragment">
<info.nightscout.androidaps.utils.ui.SingleClickButton
android:id="@+id/refresh_from_nightscout"
style="@style/GrayButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableStart="@drawable/ic_refresh"
android:text="@string/refresheventsfromnightscout"
tools:visibility="visible" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/filterinputLayout" android:id="@+id/filter_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/filter" android:hint="@string/filter"
app:startIconDrawable="@android:drawable/ic_menu_search" app:endIconMode="clear_text"
app:endIconMode="clear_text"> app:startIconDrawable="@android:drawable/ic_menu_search">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/filter" android:id="@+id/filter"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp" android:layout_marginStart="5dp"
android:layout_marginEnd="5dp" android:layout_marginEnd="5dp"
android:layout_gravity="center_vertical"
android:layout_weight="1" android:layout_weight="1"
android:autofillHints="@string/notes_label" android:autofillHints="@string/notes_label"
android:gravity="start" android:gravity="start"
android:textStyle="bold" android:inputType="text|textCapSentences"
android:inputType="text|textCapSentences" /> android:textStyle="bold" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View file

@ -1,71 +1,48 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
style="@style/Widget.MaterialComponents.CardView"
android:id="@+id/food_card" android:id="@+id/food_card"
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp" android:layout_gravity="center"
android:layout_marginEnd="4dp"
android:layout_marginTop="4dp"
app:strokeWidth="1dp"
app:cardCornerRadius="4dp" app:cardCornerRadius="4dp"
app:contentPadding="2dp"
app:cardElevation="4dp" app:cardElevation="4dp"
app:cardUseCompatPadding="true" app:cardUseCompatPadding="true"
android:layout_gravity="center"> app:contentPadding="2dp"
app:strokeWidth="1dp">
<LinearLayout <LinearLayout
android:id="@+id/food_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/left_right_split"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingStart="3dp" android:paddingStart="3dp"
android:paddingEnd="3dp"> android:paddingEnd="3dp">
<LinearLayout <LinearLayout
android:id="@+id/name_and_info_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="start">
<LinearLayout
android:id="@+id/name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:text="Name" android:gravity="start"
android:textStyle="bold" android:orientation="vertical">
android:textSize="@dimen/twenty_four_dp"
tools:ignore="HardcodedText" />
</LinearLayout> <TextView
android:id="@+id/name"
<LinearLayout
android:id="@+id/info_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:text="Name"
android:textSize="@dimen/twenty_four_dp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:gravity="start" android:gravity="start"
android:orientation="horizontal" android:orientation="horizontal">
android:layout_marginStart="5dp">
<TextView <TextView
android:id="@+id/carbs" android:id="@+id/carbs"
@ -107,43 +84,32 @@
android:text="Energy" android:text="Energy"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
</LinearLayout> </LinearLayout>
</LinearLayout>
<LinearLayout </LinearLayout>
android:id="@+id/buttons_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="end">
<ImageView <ImageView
android:id="@+id/ic_calculator" android:id="@+id/ic_calculator"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:padding="2dp" android:contentDescription="@string/overview_calculator_label"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="-5dp"
android:paddingTop="-5dp"
android:scaleX=".5"
android:scaleY=".5"
android:src="@drawable/ic_calculator" /> android:src="@drawable/ic_calculator" />
<ImageView <ImageView
android:id="@+id/ic_remove" android:id="@+id/ic_remove"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:padding="2dp" android:contentDescription="@string/remove_label"
android:orientation="horizontal" android:orientation="horizontal"
android:padding="2dp"
android:src="@drawable/ic_trash_outline" /> android:src="@drawable/ic_trash_outline" />
</LinearLayout> </LinearLayout>
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="?android:attr/dividerHorizontal" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>