-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
191 additions
and
22 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
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
20 changes: 0 additions & 20 deletions
20
energy_settings/src/main/kotlin/de/cyface/energy_settings/CustomPreferences.kt
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
energy_settings/src/main/kotlin/de/cyface/energy_settings/EnergySettings.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,52 @@ | ||
/* | ||
* Copyright 2023 Cyface GmbH | ||
* | ||
* This file is part of the Cyface Energy Settings for Android. | ||
* | ||
* The Cyface Energy Settings for Android is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Cyface Energy Settings for Android is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with the Cyface Energy Settings for Android. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.cyface.energy_settings | ||
|
||
import android.content.Context | ||
import androidx.core.content.edit | ||
import de.cyface.energy_settings.Constants.PREFERENCES_MANUFACTURER_WARNING_SHOWN_KEY | ||
|
||
/** | ||
* Custom settings used by this library. | ||
* | ||
* Attention: | ||
* - Never mix SingleProcessDataStore with MultiProcessDataStore for the same file. | ||
* - We use SingleProcessDataStore, so don't access preferences from multiple processes. | ||
* - Only create one instance of `DataStore` per file in the same process. | ||
* - We use ProtoBuf to ensure type safety. Rebuild after changing the .proto file. | ||
* | ||
* @author Armin Schnabel | ||
* @version 2.0.0 | ||
* @since 3.4.0 | ||
*/ | ||
class CustomPreferences(context: Context) { | ||
|
||
fun saveWarningShown(warningShown: Boolean) { | ||
//FIXME | ||
/*preferences.edit { | ||
putBoolean(PREFERENCES_MANUFACTURER_WARNING_SHOWN_KEY, warningShown) | ||
apply() | ||
}*/ | ||
} | ||
|
||
fun getWarningShown(): Boolean { | ||
return true // FIXME | ||
//return preferences.getBoolean(PREFERENCES_MANUFACTURER_WARNING_SHOWN_KEY, false) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
energy_settings/src/main/kotlin/de/cyface/energy_settings/SettingsSerializer.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,51 @@ | ||
/* | ||
* Copyright 2023 Cyface GmbH | ||
* | ||
* This file is part of the Cyface App for Android. | ||
* | ||
* The Cyface App for Android is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Cyface App for Android is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with the Cyface App for Android. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package de.cyface.energy_settings | ||
|
||
import androidx.datastore.core.CorruptionException | ||
import androidx.datastore.core.Serializer | ||
import com.google.protobuf.InvalidProtocolBufferException | ||
import java.io.InputStream | ||
import java.io.OutputStream | ||
|
||
/** | ||
* The serializer for the Proto DataStore of the preferences stored in the [Settings] file. | ||
* | ||
* For details: https://developer.android.com/topic/libraries/architecture/datastore#proto-datastore | ||
* | ||
* @author Armin Schnabel | ||
* @since 3.7.0 | ||
* @version 1.0.0 | ||
*/ | ||
object SettingsSerializer : Serializer<Settings> { | ||
override val defaultValue: Settings = Settings.getDefaultInstance() | ||
|
||
override suspend fun readFrom(input: InputStream): Settings { | ||
try { | ||
return Settings.parseFrom(input) | ||
} catch (exception: InvalidProtocolBufferException) { | ||
throw CorruptionException("Cannot read proto.", exception) | ||
} | ||
} | ||
|
||
override suspend fun writeTo( | ||
t: Settings, | ||
output: OutputStream | ||
) = t.writeTo(output) | ||
} |
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,53 @@ | ||
/* | ||
* Copyright 2023 Cyface GmbH | ||
* | ||
* This file is part of the Cyface Utils for Android. | ||
* | ||
* The Cyface Utils for Android is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The Cyface Utils for Android is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with the Cyface Utils for Android. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
syntax = "proto3"; | ||
|
||
option java_package = "de.cyface.utils"; | ||
option java_multiple_files = true; | ||
|
||
/** | ||
* The data types for the values stored in the `AppPreferences`. | ||
* | ||
* See https://protobuf.dev/programming-guides/proto3/ | ||
* | ||
* Attention: The classes are generated from the file at compile time. Don't forget to rebuild. | ||
* | ||
* @author: Armin Schnabel | ||
* @since: 4.0.0 | ||
* @version: 1.0.0 | ||
*/ | ||
message Settings { | ||
// Whether the map should be automatically centered while moving | ||
bool center_map = 1; | ||
|
||
// Whether the app should be able to upload measurementsA. | ||
bool upload_enabled = 2; | ||
|
||
// The maximum frequency with which the IMU sensors should collect data, e.g. 100 Hz. | ||
int32 sensor_frequency = 3; | ||
|
||
// Whether the app should report to the error monitoring service. | ||
bool report_errors = 4; | ||
|
||
// The currently selected modality, e.g. 'CAR'. | ||
string modality = 5; | ||
|
||
// The API version of the terms accepted by the user, e.g. 5. | ||
int32 accepted_terms = 6; | ||
} |