-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added delete functionality and basic filters to trip history
- Loading branch information
Showing
3 changed files
with
138 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
automotive/src/carapp/java/com/ixam97/carStatsViewer/carApp/TripHistoryFilterScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.ixam97.carStatsViewer.carApp | ||
|
||
import androidx.car.app.CarContext | ||
import androidx.car.app.Screen | ||
import androidx.car.app.model.Action | ||
import androidx.car.app.model.Header | ||
import androidx.car.app.model.Pane | ||
import androidx.car.app.model.PaneTemplate | ||
import androidx.car.app.model.Row | ||
import androidx.car.app.model.Template | ||
import androidx.car.app.model.Toggle | ||
import androidx.lifecycle.DefaultLifecycleObserver | ||
import com.ixam97.carStatsViewer.CarStatsViewer | ||
import com.ixam97.carStatsViewer.R | ||
|
||
class TripHistoryFilterScreen(carContext: CarContext): Screen(carContext), DefaultLifecycleObserver { | ||
|
||
private var showManualTrips: Boolean = CarStatsViewer.appPreferences.tripFilterManual | ||
private var showSinceChargeTrips: Boolean = CarStatsViewer.appPreferences.tripFilterCharge | ||
private var showAutomaticTrips: Boolean = CarStatsViewer.appPreferences.tripFilterAuto | ||
private var showMonthlyTrips: Boolean = CarStatsViewer.appPreferences.tripFilterMonth | ||
|
||
init { | ||
lifecycle.addObserver(this) | ||
} | ||
|
||
override fun onGetTemplate(): Template { | ||
return tripHistoryFilterTemplate() | ||
} | ||
|
||
private fun tripHistoryFilterTemplate() = PaneTemplate.Builder(Pane.Builder().apply { | ||
addRow(Row.Builder().apply { | ||
setToggle(Toggle.Builder { | ||
showManualTrips = it | ||
}.setChecked(showManualTrips).build()) | ||
setTitle(carContext.getString(R.string.history_dialog_filters_manual)) | ||
}.build()) | ||
addRow(Row.Builder().apply { | ||
setToggle(Toggle.Builder { | ||
showSinceChargeTrips = it | ||
}.setChecked(showSinceChargeTrips).build()) | ||
setTitle(carContext.getString(R.string.history_dialog_filters_charge)) | ||
}.build()) | ||
addRow(Row.Builder().apply { | ||
setToggle(Toggle.Builder { | ||
showAutomaticTrips = it | ||
}.setChecked(showAutomaticTrips).build()) | ||
setTitle(carContext.getString(R.string.history_dialog_filters_auto)) | ||
}.build()) | ||
addRow(Row.Builder().apply { | ||
setToggle(Toggle.Builder { | ||
showMonthlyTrips = it | ||
}.setChecked(showMonthlyTrips).build()) | ||
setTitle(carContext.getString(R.string.history_dialog_filters_month)) | ||
}.build()) | ||
addAction(Action.Builder().apply { | ||
setTitle(carContext.getString(R.string.dialog_apply)) | ||
setFlags(Action.FLAG_PRIMARY) | ||
setOnClickListener { | ||
CarStatsViewer.appPreferences.tripFilterManual = showManualTrips | ||
CarStatsViewer.appPreferences.tripFilterCharge = showSinceChargeTrips | ||
CarStatsViewer.appPreferences.tripFilterAuto = showAutomaticTrips | ||
CarStatsViewer.appPreferences.tripFilterMonth = showMonthlyTrips | ||
screenManager.pop() | ||
} | ||
}.build()) | ||
}.build()).apply { | ||
setHeader(Header.Builder().apply { | ||
setTitle(carContext.getString(R.string.history_dialog_filters_title)) | ||
setStartHeaderAction(Action.BACK) | ||
}.build()) | ||
}.build() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters