diff options
| author | Tyler Nijmeh <tylernij@gmail.com> | 2021-03-31 00:03:08 -0700 |
|---|---|---|
| committer | Tyler Nijmeh <tylernij@gmail.com> | 2021-03-31 00:03:08 -0700 |
| commit | 27017af52ec758ef549f466821b6530cacbcb557 (patch) | |
| tree | a93a5cdf3c6ec334bc43a2556b1092125ef6a124 /app | |
| parent | fcb3d95806543ea2088dd75c3863f71b3eeb1d88 (diff) | |
Initial, barebones recycler
Signed-off-by: Tyler Nijmeh <tylernij@gmail.com>
Diffstat (limited to 'app')
5 files changed, 124 insertions, 1 deletions
diff --git a/app/src/main/java/com/draco/buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt b/app/src/main/java/com/draco/buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt new file mode 100644 index 0000000..3e4669b --- /dev/null +++ b/app/src/main/java/com/draco/buoy/recyclers/BatterySaverProfileRecyclerAdapter.kt @@ -0,0 +1,80 @@ +package com.draco.buoy.recyclers + +import android.content.ContentResolver +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.draco.buoy.R +import com.draco.buoy.repositories.BatterySaverConstantsConfigProfiles +import com.draco.buoy.utils.BatterySaverManager + +class BatterySaverProfileRecyclerAdapter( + contentResolver: ContentResolver +) : RecyclerView.Adapter<BatterySaverProfileRecyclerAdapter.ViewHolder>() { + private val batterySaverProfiles = arrayOf( + BatterySaverConstantsConfigProfiles.DEFAULT, + BatterySaverConstantsConfigProfiles.LIGHT, + BatterySaverConstantsConfigProfiles.MODERATE, + BatterySaverConstantsConfigProfiles.HIGH, + BatterySaverConstantsConfigProfiles.EXTREME, + ) + + private val batterySaverManager = BatterySaverManager(contentResolver) + + class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { + val title = itemView.findViewById<TextView>(R.id.title) + val description = itemView.findViewById<TextView>(R.id.description) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.recycler_item_profile, parent, false) + return ViewHolder(view) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val profile = batterySaverProfiles[position] + + val isDefaultProfile = (profile == BatterySaverConstantsConfigProfiles.DEFAULT) + + when (profile) { + BatterySaverConstantsConfigProfiles.DEFAULT -> { + holder.title.setText(R.string.profile_title_default) + holder.description.setText(R.string.profile_description_default) + } + + BatterySaverConstantsConfigProfiles.LIGHT -> { + holder.title.setText(R.string.profile_title_light) + holder.description.setText(R.string.profile_description_light) + } + + BatterySaverConstantsConfigProfiles.MODERATE -> { + holder.title.setText(R.string.profile_title_moderate) + holder.description.setText(R.string.profile_description_moderate) + } + + BatterySaverConstantsConfigProfiles.HIGH -> { + holder.title.setText(R.string.profile_title_high) + holder.description.setText(R.string.profile_description_high) + } + + BatterySaverConstantsConfigProfiles.EXTREME -> { + holder.title.setText(R.string.profile_title_extreme) + holder.description.setText(R.string.profile_description_extreme) + } + } + + holder.itemView.setOnClickListener { + /* Apply profile */ + batterySaverManager.setConstantsConfig(profile) + /* Enable low power mode */ + batterySaverManager.setLowPower(true) + /* If this is not the default config, set sticky and don't auto disable */ + batterySaverManager.setLowPowerSticky(!isDefaultProfile) + batterySaverManager.setLowPowerStickyAutoDisableEnabled(isDefaultProfile) + } + } + + override fun getItemCount(): Int = batterySaverProfiles.size +}
\ No newline at end of file diff --git a/app/src/main/java/com/draco/buoy/views/MainActivity.kt b/app/src/main/java/com/draco/buoy/views/MainActivity.kt index 224d851..b8f1fc2 100644 --- a/app/src/main/java/com/draco/buoy/views/MainActivity.kt +++ b/app/src/main/java/com/draco/buoy/views/MainActivity.kt @@ -4,17 +4,28 @@ import android.content.Intent import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.activity.viewModels +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import com.draco.buoy.R +import com.draco.buoy.recyclers.BatterySaverProfileRecyclerAdapter import com.draco.buoy.utils.PermissionUtils import com.draco.buoy.viewmodels.MainActivityViewModel class MainActivity : AppCompatActivity() { private val viewModel: MainActivityViewModel by viewModels() + private lateinit var recycler: RecyclerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + recycler = findViewById(R.id.recycler_profile) + + recycler.apply { + adapter = BatterySaverProfileRecyclerAdapter(contentResolver) + layoutManager = LinearLayoutManager(this@MainActivity) + } + if (!PermissionUtils.isPermissionsGranted(this, android.Manifest.permission.WRITE_SECURE_SETTINGS)) goToPermissionActivity() } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 24f3d6b..640773b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -2,5 +2,8 @@ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> - + <androidx.recyclerview.widget.RecyclerView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/recycler_profile" /> </RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/recycler_item_profile.xml b/app/src/main/res/layout/recycler_item_profile.xml new file mode 100644 index 0000000..25b0cde --- /dev/null +++ b/app/src/main/res/layout/recycler_item_profile.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="200dp" + android:orientation="vertical"> + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/title" /> + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/description" /> +</LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 619b965..c2acd83 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,4 +11,19 @@ <string name="copied">Copied to clipboard</string> <string name="snackbar_intent_failed">Could not handle this action</string> + + <string name="profile_title_default">Default</string> + <string name="profile_description_default">The default configuration provided by the system</string> + + <string name="profile_title_light">Light</string> + <string name="profile_description_light">The default configuration provided by the system</string> + + <string name="profile_title_moderate">Moderate</string> + <string name="profile_description_moderate">The default configuration provided by the system</string> + + <string name="profile_title_high">High</string> + <string name="profile_description_high">The default configuration provided by the system</string> + + <string name="profile_title_extreme">Extreme</string> + <string name="profile_description_extreme">The default configuration provided by the system</string> </resources>
\ No newline at end of file |
