converted addcharge to Composable
This commit is contained in:
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -3,6 +3,7 @@
|
|||||||
<component name="DesignSurface">
|
<component name="DesignSurface">
|
||||||
<option name="filePathToZoomLevelMap">
|
<option name="filePathToZoomLevelMap">
|
||||||
<map>
|
<map>
|
||||||
|
<entry key="..\:/Users/socke/StudioProjects/batterytracker/app/src/main/res/layout/fragment_add_charge.xml" value="0.12708333333333333" />
|
||||||
<entry key="..\:/Users/socrates/AndroidStudioProjects/BatteryTracker/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.323" />
|
<entry key="..\:/Users/socrates/AndroidStudioProjects/BatteryTracker/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.323" />
|
||||||
<entry key="..\:/Users/socrates/AndroidStudioProjects/BatteryTracker/app/src/main/res/drawable/ic_launcher_background.xml" value="0.323" />
|
<entry key="..\:/Users/socrates/AndroidStudioProjects/BatteryTracker/app/src/main/res/drawable/ic_launcher_background.xml" value="0.323" />
|
||||||
<entry key="..\:/Users/socrates/AndroidStudioProjects/BatteryTracker/app/src/main/res/drawable/ic_menu_camera.xml" value="0.323" />
|
<entry key="..\:/Users/socrates/AndroidStudioProjects/BatteryTracker/app/src/main/res/drawable/ic_menu_camera.xml" value="0.323" />
|
||||||
|
|||||||
@@ -7,9 +7,13 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.AutoCompleteTextView
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.*
|
import androidx.compose.material.*
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.BatteryChargingFull
|
||||||
|
import androidx.compose.material.icons.filled.EditCalendar
|
||||||
|
import androidx.compose.material.icons.filled.Save
|
||||||
import androidx.compose.material.icons.filled.Tag
|
import androidx.compose.material.icons.filled.Tag
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -18,6 +22,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.TextRange
|
import androidx.compose.ui.text.TextRange
|
||||||
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.text.input.TextFieldValue
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.constraintlayout.compose.ConstraintLayout
|
import androidx.constraintlayout.compose.ConstraintLayout
|
||||||
@@ -26,6 +31,7 @@ import com.google.android.material.datepicker.MaterialDatePicker
|
|||||||
import com.sockenklaus.batterytracker.R
|
import com.sockenklaus.batterytracker.R
|
||||||
import com.sockenklaus.batterytracker.databinding.FragmentAddChargeBinding
|
import com.sockenklaus.batterytracker.databinding.FragmentAddChargeBinding
|
||||||
import com.sockenklaus.batterytracker.ui.theme.BatteryTrackerTheme
|
import com.sockenklaus.batterytracker.ui.theme.BatteryTrackerTheme
|
||||||
|
import com.sockenklaus.batterytracker.util.validateDecimal
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.time.format.FormatStyle
|
import java.time.format.FormatStyle
|
||||||
@@ -39,6 +45,7 @@ class AddChargeFragment : Fragment() {
|
|||||||
private var _binding: FragmentAddChargeBinding? = null
|
private var _binding: FragmentAddChargeBinding? = null
|
||||||
|
|
||||||
private lateinit var viewModel: AddChargeViewModel
|
private lateinit var viewModel: AddChargeViewModel
|
||||||
|
|
||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterialApi::class)
|
@OptIn(ExperimentalMaterialApi::class)
|
||||||
@@ -53,12 +60,12 @@ class AddChargeFragment : Fragment() {
|
|||||||
|
|
||||||
// TODO: Add viewModel!!
|
// TODO: Add viewModel!!
|
||||||
val items = listOf("E1", "E2", "E3", "E4", "Bonsai", "Bonai")
|
val items = listOf("E1", "E2", "E3", "E4", "Bonsai", "Bonai")
|
||||||
val adapter = ArrayAdapter(requireContext(), R.layout.list_item, items)
|
val dateFormat: DateTimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(Locale.GERMANY)
|
||||||
|
|
||||||
binding.composeView.setContent{
|
binding.root.setContent{
|
||||||
BatteryTrackerTheme {
|
BatteryTrackerTheme {
|
||||||
ConstraintLayout {
|
ConstraintLayout {
|
||||||
val (textBatteryId, dbgFilterOptions, dbgExp, btnDate, textCharge, fab) = createRefs()
|
val (textBatteryId, ddTextField, dd, btnDate, textCharge, fab) = createRefs()
|
||||||
val outerMargin = 24.dp
|
val outerMargin = 24.dp
|
||||||
val innerMargin = 16.dp
|
val innerMargin = 16.dp
|
||||||
|
|
||||||
@@ -86,13 +93,22 @@ class AddChargeFragment : Fragment() {
|
|||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
ExposedDropdownMenuDefaults.TrailingIcon(expanded = bIdExpanded)
|
ExposedDropdownMenuDefaults.TrailingIcon(expanded = bIdExpanded)
|
||||||
},
|
},
|
||||||
colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors()
|
colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors(),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.constrainAs(ddTextField){
|
||||||
|
top.linkTo(parent.top)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
val filteringOptions = items.filter { it.contains(selectedBatteryId.text, ignoreCase = true)}
|
val filteringOptions = items.filter { it.contains(selectedBatteryId.text, ignoreCase = true)}
|
||||||
|
if(filteringOptions.size > 1 && !selectedBatteryId.text.isNullOrBlank()) bIdExpanded = true
|
||||||
if(filteringOptions.isNotEmpty()) {
|
if(filteringOptions.isNotEmpty()) {
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
expanded = bIdExpanded,
|
expanded = bIdExpanded,
|
||||||
onDismissRequest = { bIdExpanded = false }
|
onDismissRequest = { bIdExpanded = false },
|
||||||
|
modifier = Modifier.constrainAs(dd){
|
||||||
|
top.linkTo(ddTextField.bottom)
|
||||||
|
}
|
||||||
) {
|
) {
|
||||||
for (filteringOption in filteringOptions) {
|
for (filteringOption in filteringOptions) {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
@@ -110,47 +126,57 @@ class AddChargeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*Text(
|
TextButton(
|
||||||
filteringOptions.toString(),
|
onClick = { openDatePicker() },
|
||||||
Modifier.constrainAs(dbgFilterOptions) {
|
modifier = Modifier
|
||||||
top.linkTo(textBatteryId.bottom, margin = 40.dp)
|
.constrainAs(btnDate){
|
||||||
|
top.linkTo(textCharge.bottom, innerMargin)
|
||||||
|
start.linkTo(parent.start, outerMargin)
|
||||||
|
end.linkTo(parent.end, outerMargin)
|
||||||
|
width = Dimension.fillToConstraints
|
||||||
}
|
}
|
||||||
)*/
|
|
||||||
Text(
|
){
|
||||||
"expanded: $bIdExpanded",
|
Icon(
|
||||||
Modifier.constrainAs(dbgExp) {
|
Icons.Default.EditCalendar,
|
||||||
top.linkTo(dbgFilterOptions.bottom, margin = 40.dp)
|
"Edit Calendar Icon",
|
||||||
|
Modifier.size(ButtonDefaults.IconSize),
|
||||||
|
)
|
||||||
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
|
Text("Date: ${date.format(dateFormat)}")
|
||||||
|
}
|
||||||
|
|
||||||
|
OutlinedTextField(
|
||||||
|
value = charge,
|
||||||
|
onValueChange = { charge = validateDecimal(it, charge) },
|
||||||
|
leadingIcon = { Icon(Icons.Default.BatteryChargingFull, "Icon Battery Charging Full") },
|
||||||
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
|
||||||
|
label = { Text(stringResource(R.string.hint_charge)) },
|
||||||
|
modifier = Modifier
|
||||||
|
.constrainAs(textCharge){
|
||||||
|
top.linkTo(textBatteryId.bottom, innerMargin)
|
||||||
|
start.linkTo(parent.start, outerMargin)
|
||||||
|
end.linkTo(parent.end, outerMargin)
|
||||||
|
width = Dimension.fillToConstraints
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ExtendedFloatingActionButton(
|
||||||
|
text = { Text(stringResource(R.string.button_save_charge)) },
|
||||||
|
onClick = { /*TODO*/ },
|
||||||
|
icon = { Icon(Icons.Default.Save, "Icon Save") },
|
||||||
|
modifier = Modifier.constrainAs(fab){
|
||||||
|
top.linkTo(btnDate.bottom, 24.dp)
|
||||||
|
end.linkTo(parent.end, outerMargin)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*(binding.editBatteryId.editText as? AutoCompleteTextView)?.setAdapter(adapter)
|
|
||||||
|
|
||||||
|
|
||||||
val current: LocalDate = LocalDate.now()
|
|
||||||
val formatter: DateTimeFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(Locale.GERMANY)
|
|
||||||
val formatted: String = current.format(formatter) ?: ""
|
|
||||||
|
|
||||||
binding.editDate.text = formatted
|
|
||||||
|
|
||||||
binding.fab.setOnClickListener{
|
|
||||||
buttonClicked()
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.editDate.setOnClickListener {
|
|
||||||
openDatePicker()
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buttonClicked() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
_binding = null
|
_binding = null
|
||||||
|
|||||||
@@ -1,117 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<androidx.compose.ui.platform.ComposeView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".ui.fragments.add_charge.AddChargeFragment">
|
tools:context=".ui.fragments.add_charge.AddChargeFragment"
|
||||||
|
|
||||||
<androidx.compose.ui.platform.ComposeView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
tools:context=".ui.fragments.AddChargeFragment"
|
|
||||||
android:id="@+id/compose_view"
|
android:id="@+id/compose_view"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
<!--<com.google.android.material.textfield.TextInputLayout
|
|
||||||
android:id="@+id/edit_battery_id"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:hint="@string/select_battery_id"
|
|
||||||
android:minHeight="48dp"
|
|
||||||
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/text_battery_id"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/compose_view"
|
|
||||||
|
|
||||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
|
||||||
>
|
|
||||||
|
|
||||||
<AutoCompleteTextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="text"
|
|
||||||
tools:ignore="TextContrastCheck" />
|
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/edit_date"
|
|
||||||
style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
app:icon="@drawable/ic_baseline_edit_calendar_24"
|
|
||||||
app:layout_constraintStart_toStartOf="@+id/edit_battery_id"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/edit_battery_id"
|
|
||||||
tools:ignore="SpeakableTextPresentCheck" />
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
|
||||||
android:id="@+id/edit_charge"
|
|
||||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
|
|
||||||
android:hint="@string/hint_charge"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="@+id/edit_date"
|
|
||||||
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/edit_date">
|
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:inputType="numberDecimal"
|
|
||||||
tools:ignore="TextContrastCheck" />
|
|
||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text_battery_id"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:text="@string/battery_id"
|
|
||||||
app:layout_constraintBaseline_toBaselineOf="@+id/edit_battery_id"
|
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text_date"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/date"
|
|
||||||
app:layout_constraintBaseline_toBaselineOf="@+id/edit_date"
|
|
||||||
app:layout_constraintEnd_toEndOf="@+id/text_battery_id" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text_charge"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/charge"
|
|
||||||
app:layout_constraintBaseline_toBaselineOf="@+id/edit_charge"
|
|
||||||
app:layout_constraintEnd_toEndOf="@+id/text_date" />
|
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
|
||||||
android:id="@+id/fab"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_marginTop="32dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:contentDescription="@string/button_save_charge"
|
|
||||||
android:text="@string/button_save_charge"
|
|
||||||
app:icon="@drawable/ic_baseline_check_24"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/edit_charge" />-->
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
Reference in New Issue
Block a user