Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SettingsRepo, refactoring & setting for battery limit #28

Merged
merged 34 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9cdc836
Standardize formatting and color values of icons
miguelguzmanr Feb 14, 2024
2ca10a8
Merge remote-tracking branch 'upstream/main' into charging-separation
miguelguzmanr Feb 14, 2024
8474896
Rename face buttons
miguelguzmanr Feb 15, 2024
36f4b41
Allow title in CheckBoxDialogPreference
miguelguzmanr Feb 15, 2024
890cf4f
Attempt consistency in titles & descriptions
miguelguzmanr Feb 15, 2024
b8e7196
Add SettingsRepo & refactoring
miguelguzmanr Feb 15, 2024
dec5050
Add padding in RemapButtonDialog
miguelguzmanr Feb 15, 2024
390b5c6
Add setting to bypass charge after 80%
miguelguzmanr Feb 15, 2024
e048cb7
Merge pull request #1 from miguelguzmanr/charging-separation
miguelguzmanr Feb 15, 2024
c00bd51
Rename function getDeviceCodename
miguelguzmanr Feb 20, 2024
0e8b1b7
Remove debug println
miguelguzmanr Feb 20, 2024
37ef775
Add explicit function for Settings initialization
miguelguzmanr Feb 20, 2024
18bc583
Add constant for accessibility services setting
miguelguzmanr Feb 20, 2024
ad7bc88
Refactor saturation property to a function
miguelguzmanr Feb 20, 2024
8150976
Remove unused properties
miguelguzmanr Feb 20, 2024
75a492d
Merge branch 'main' into main
miguelguzmanr Apr 18, 2024
9c4521c
Optimize imports
miguelguzmanr Apr 21, 2024
f465920
Update gradle.properties
miguelguzmanr Apr 21, 2024
1860873
Update dependencies
miguelguzmanr Apr 21, 2024
f13a20a
Add setting for charging separation
miguelguzmanr Apr 21, 2024
d7f98ea
Fix typo in preference key
miguelguzmanr Apr 21, 2024
4c35532
Create .gitattributes
miguelguzmanr Apr 21, 2024
26094cb
Add battery level broadcast receiver
miguelguzmanr Apr 21, 2024
9844999
Remove unused preference
miguelguzmanr Apr 21, 2024
cc32a96
Enable Aggregating Task
miguelguzmanr Apr 27, 2024
a980356
Make context private in SharedPrefsRepo
miguelguzmanr Apr 27, 2024
d91acac
Make deviceUtils private in MainViewModel
miguelguzmanr Apr 27, 2024
d9a5af6
Add setting to dump a log file
miguelguzmanr Apr 28, 2024
3a3548d
Fix incorrect setting restrictCharge
miguelguzmanr Apr 28, 2024
46a6c57
Add battery level monitor service
miguelguzmanr Apr 28, 2024
884c8dc
Remove debug requirement for dump log to file
miguelguzmanr May 15, 2024
9b1e42f
Add Debug settings header
miguelguzmanr May 15, 2024
b62e33c
Add get & set float values in ShellExecutor
miguelguzmanr May 15, 2024
8d99eea
Migrate battery level monitor to accessibility service
miguelguzmanr May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ android {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
hilt {
enableAggregatingTask = true
}
}

room {
Expand Down
98 changes: 56 additions & 42 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,73 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" tools:ignore="QueryAllPackagesPermission"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />

<application
android:name=".OdinToolsApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName"
android:supportsRtl="true"
android:theme="@style/Theme.OdinTools"
android:dataExtractionRules="@xml/data_extraction_rules">
android:name=".OdinToolsApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName"
android:supportsRtl="true"
android:theme="@style/Theme.OdinTools"
android:dataExtractionRules="@xml/data_extraction_rules">
<activity
android:name=".main.MainActivity"
android:exported="true"
android:theme="@style/Theme.OdinTools"
android:screenOrientation="landscape">
android:name=".main.MainActivity"
android:exported="true"
android:theme="@style/Theme.OdinTools"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".tiles.ControllerTileService"
android:exported="true"
android:icon="@drawable/ic_controllerstyle"
android:label="@string/controllerStyle"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
android:name=".tiles.ControllerTileService"
android:exported="true"
android:icon="@drawable/ic_face_buttons"
android:label="@string/controllerStyle"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>

<meta-data
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true"/>
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true" />
</service>
<service
android:name=".tiles.L2R2TileService"
android:exported="true"
android:icon="@drawable/ic_sliders"
android:label="@string/l2r2mode"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
android:name=".tiles.L2R2TileService"
android:exported="true"
android:icon="@drawable/ic_sliders"
android:label="@string/l2r2mode"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE"/>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>

<meta-data
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true"/>
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true" />
</service>
<service android:name=".service.ForegroundAppWatcherService"
android:exported="false"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<service
android:name=".service.ForegroundAppWatcherService"
android:exported="false"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility_service_config" />
</service>
<service
android:name=".service.BatteryLevelMonitorService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="specialUse">
</service>

<receiver
android:name=".tools.BootReceiver"
android:enabled="true"
android:exported="true">
android:name=".tools.BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ package de.langerhans.odintools.appsettings
import android.graphics.drawable.Drawable
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.*
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import de.langerhans.odintools.data.AppOverrideDao
import de.langerhans.odintools.tools.DeviceUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@ package de.langerhans.odintools.appsettings

import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.material3.Button
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -16,12 +34,21 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import de.langerhans.odintools.R
import de.langerhans.odintools.models.ControllerStyle.*
import de.langerhans.odintools.models.FanMode.*
import de.langerhans.odintools.models.L2R2Style.*
import de.langerhans.odintools.models.ControllerStyle.Disconnect
import de.langerhans.odintools.models.ControllerStyle.Odin
import de.langerhans.odintools.models.ControllerStyle.Xbox
import de.langerhans.odintools.models.FanMode.Off
import de.langerhans.odintools.models.FanMode.Quiet
import de.langerhans.odintools.models.FanMode.Smart
import de.langerhans.odintools.models.FanMode.Sport
import de.langerhans.odintools.models.L2R2Style.Analog
import de.langerhans.odintools.models.L2R2Style.Both
import de.langerhans.odintools.models.L2R2Style.Digital
import de.langerhans.odintools.models.NoChange
import de.langerhans.odintools.models.PerfMode
import de.langerhans.odintools.models.PerfMode.*
import de.langerhans.odintools.models.PerfMode.HighPerformance
import de.langerhans.odintools.models.PerfMode.Performance
import de.langerhans.odintools.models.PerfMode.Standard
import de.langerhans.odintools.ui.composables.DeleteConfirmDialog
import de.langerhans.odintools.ui.composables.LargeDropdownMenu
import de.langerhans.odintools.ui.composables.OdinTopAppBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import de.langerhans.odintools.data.AppOverrideDao
import de.langerhans.odintools.data.AppOverrideEntity
import de.langerhans.odintools.models.*
import de.langerhans.odintools.models.ControllerStyle
import de.langerhans.odintools.models.FanMode
import de.langerhans.odintools.models.FanMode.Companion.getDisabledFanModes
import de.langerhans.odintools.models.L2R2Style
import de.langerhans.odintools.models.NoChange
import de.langerhans.odintools.models.PerfMode
import de.langerhans.odintools.tools.DeviceUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package de.langerhans.odintools.data

import androidx.room.*
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow

@Dao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class SharedPrefsRepo @Inject constructor(
@ApplicationContext context: Context,
@ApplicationContext private val context: Context,
) {

private val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
Expand Down Expand Up @@ -35,6 +35,18 @@ class SharedPrefsRepo @Inject constructor(
get() = prefs.getBoolean(KEY_OVERRIDE_DELAY, false)
set(value) = prefs.edit().putBoolean(KEY_OVERRIDE_DELAY, value).apply()

var chargeLimitEnabled
get() = prefs.getBoolean(KEY_CHARGE_LIMIT_ENABLED, false)
set(value) = prefs.edit().putBoolean(KEY_CHARGE_LIMIT_ENABLED, value).apply()

var minBatteryLevel
get() = prefs.getInt(KEY_MIN_BATTERY_LEVEL, 20)
set(value) = prefs.edit().putInt(KEY_MIN_BATTERY_LEVEL, value).apply()

var maxBatteryLevel
get() = prefs.getInt(KEY_MAX_BATTERY_LEVEL, 80)
set(value) = prefs.edit().putInt(KEY_MAX_BATTERY_LEVEL, value).apply()

private var appOverrideEnabledListener: OnSharedPreferenceChangeListener? = null

fun observeAppOverrideEnabledState(overridesEnabled: (newState: Boolean) -> Unit, overrideDelayEnabled: (newState: Boolean) -> Unit) {
Expand Down Expand Up @@ -62,5 +74,8 @@ class SharedPrefsRepo @Inject constructor(
private const val KEY_VIBRATION_STRENGTH = "vibration_strength"
private const val KEY_APP_OVERRIDE_ENABLED = "app_override_enabled"
private const val KEY_OVERRIDE_DELAY = "override_delay"
private const val KEY_CHARGE_LIMIT_ENABLED = "charge_limit_enabled"
private const val KEY_MIN_BATTERY_LEVEL = "min_battery_level"
private const val KEY_MAX_BATTERY_LEVEL = "max_battery_level"
}
}
Loading
Loading