feat: added debug mod on 0x8 and Enter

This commit is contained in:
danilkinkin 2022-07-13 20:37:09 +04:00
parent 2320d8a464
commit 86f4e5967a
7 changed files with 69 additions and 17 deletions

View file

@ -9,11 +9,13 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.fragment.app.activityViewModels
import com.danilkinkin.buckwheat.utils.toSP
import com.danilkinkin.buckwheat.viewmodels.AppViewModel
import com.danilkinkin.buckwheat.viewmodels.DrawsViewModel
import com.google.android.material.button.MaterialButton
class EditorFragment : Fragment() {
private lateinit var model: DrawsViewModel
private lateinit var appModel: AppViewModel
private var budgetFragment: TextWithLabelFragment? = null
private var drawFragment: TextWithLabelFragment? = null
@ -33,8 +35,10 @@ class EditorFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
val model: DrawsViewModel by activityViewModels()
val appModel: AppViewModel by activityViewModels()
this.model = model
this.appModel = appModel
build()
observe()
@ -184,5 +188,13 @@ class EditorFragment : Fragment() {
}
}
}
appModel.isDebug.observeForever {
requireView().findViewById<MaterialButton>(R.id.dev_tool_btn).visibility = if (it) {
View.VISIBLE
} else {
View.GONE
}
}
}
}

View file

@ -8,11 +8,14 @@ import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.danilkinkin.buckwheat.viewmodels.AppViewModel
import com.danilkinkin.buckwheat.viewmodels.DrawsViewModel
import com.google.android.material.button.MaterialButton
import com.google.android.material.snackbar.Snackbar
class KeyboardFragment : Fragment() {
private lateinit var model: DrawsViewModel
private lateinit var appModel: AppViewModel
override fun onCreateView(
inflater: LayoutInflater,
@ -28,8 +31,10 @@ class KeyboardFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
val model: DrawsViewModel by activityViewModels()
val appModel: AppViewModel by activityViewModels()
this.model = model
this.appModel = appModel
build()
}
@ -86,6 +91,18 @@ class KeyboardFragment : Fragment() {
}
root.findViewById<MaterialButton>(R.id.btn_eval).setOnClickListener {
if ("${model.valueLeftDot}.${model.valueRightDot}" == "00000000.") {
model.resetDraw()
appModel.setIsDebug(!appModel.isDebug.value!!)
Snackbar
.make(requireView(), "Debug ${if (appModel.isDebug.value!!) { "ON" } else { "OFF" }}", Snackbar.LENGTH_LONG)
.show()
return@setOnClickListener
}
model.commitDraw()
}
}

View file

@ -21,7 +21,7 @@ class NewDayBottomSheet: BottomSheetDialogFragment() {
val TAG = NewDayBottomSheet::class.simpleName
}
private lateinit var model: AppViewModel
private lateinit var appModel: AppViewModel
private lateinit var drawsModel: DrawsViewModel
private val restBudgetOfDayTextView: MaterialTextView by lazy {
@ -67,10 +67,10 @@ class NewDayBottomSheet: BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val model: AppViewModel by activityViewModels()
val appModel: AppViewModel by activityViewModels()
val drawsModel: DrawsViewModel by activityViewModels()
this.model = model
this.appModel = appModel
this.drawsModel = drawsModel
build()
@ -93,28 +93,34 @@ class NewDayBottomSheet: BottomSheetDialogFragment() {
restBudgetOfDayTextView.text = "$requireDistributeBudget"
debugTextView.text = "Осталось дней = $restDays " +
"\nПрошло дней с последнего пересчета = $spentDays " +
"\nВесь бюджет = ${drawsModel.wholeBudget.value!!}" +
"\nБюджет на сегодня = ${drawsModel.budgetOfCurrentDay.value!!}" +
"\nОставшийся бюджет = ${drawsModel.restBudget.value!!}"
if (appModel.isDebug.value == true) {
debugTextView.visibility = View.VISIBLE
debugTextView.text = "Осталось дней = $restDays " +
"\nПрошло дней с последнего пересчета = $spentDays " +
"\nВесь бюджет = ${drawsModel.wholeBudget.value!!}" +
"\nБюджет на сегодня = ${drawsModel.budgetOfCurrentDay.value!!}" +
"\nОставшийся бюджет = ${drawsModel.restBudget.value!!}"
splitRestDaysDebugTextView.visibility = View.VISIBLE
splitRestDaysDebugTextView.text = "${drawsModel.wholeBudget.value!!} / $restDays = $budgetPerDaySplit"
addCurrentDayDebugTextView.visibility = View.VISIBLE
addCurrentDayDebugTextView.text = "${drawsModel.restBudget.value!!} / $restDays = $budgetPerDayAdd " +
"\n${requireDistributeBudget} + ${budgetPerDayAdd} = ${requireDistributeBudget + budgetPerDayAdd}"
}
splitRestDaysDescriptionTextView.text = context!!.getString(
R.string.split_rest_days_description,
"$budgetPerDaySplit",
)
splitRestDaysDebugTextView.text = "${drawsModel.wholeBudget.value!!} / $restDays = $budgetPerDaySplit"
addCurrentDayDescriptionTextView.text = context!!.getString(
R.string.add_current_day_description,
"${requireDistributeBudget + budgetPerDayAdd}",
"$budgetPerDayAdd",
)
addCurrentDayDebugTextView.text = "${drawsModel.restBudget.value!!} / $restDays = $budgetPerDayAdd " +
"\n${requireDistributeBudget} + ${budgetPerDayAdd} = ${requireDistributeBudget + budgetPerDayAdd}"
splitRestDaysCardView.setOnClickListener {
drawsModel.reCalcBudget(budgetPerDaySplit)

View file

@ -2,13 +2,25 @@ package com.danilkinkin.buckwheat.viewmodels
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import com.danilkinkin.buckwheat.di.DatabaseModule
import com.danilkinkin.buckwheat.entities.Storage
import java.util.*
class AppViewModel(application: Application) : AndroidViewModel(application) {
private val db = DatabaseModule.getInstance(application)
private val storage = db.storageDao()
var isDebug: MutableLiveData<Boolean> = MutableLiveData(try {
storage.get("isDebug").value.toBoolean()
} catch (e: Exception) {
false
})
fun setIsDebug(debug: Boolean) {
storage.set(Storage("isDebug", debug.toString()))
isDebug.value = debug
}
}

View file

@ -1,6 +1,7 @@
package com.danilkinkin.buckwheat.viewmodels
import android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData

View file

@ -55,7 +55,8 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?android:attr/textColorSecondary" />
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/split_rest_days"
@ -104,7 +105,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?android:attr/textColorSecondary" />
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone" />
</LinearLayout>
@ -169,7 +171,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?android:attr/textColorSecondary" />
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone" />
</LinearLayout>

View file

@ -1,6 +1,7 @@
<resources>
<string name="app_name">Buckwheat</string>
<string name="action_settings">Settings</string>
<!-- Main -->
<string name="budget_for_today">Бюджет на сегодня</string>
<string name="rest_budget_for_today">Останется на сегодня</string>