Skip to content

Commit

Permalink
Refactor for saving volume as well
Browse files Browse the repository at this point in the history
  • Loading branch information
legendsayantan committed Jun 14, 2024
1 parent 4c132b1 commit 5916c2b
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 88 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
18 changes: 7 additions & 11 deletions app/src/main/java/com/legendsayantan/adbtools/DebloatActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.legendsayantan.adbtools

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
Expand All @@ -26,16 +25,13 @@ import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.reflect.TypeToken
import com.legendsayantan.adbtools.adapters.DebloatAdapter
import com.legendsayantan.adbtools.adapters.AudioStateAdapter
import com.legendsayantan.adbtools.adapters.SimpleAdapter
import com.legendsayantan.adbtools.data.AppData
import com.legendsayantan.adbtools.lib.ShizukuRunner
import com.legendsayantan.adbtools.lib.Utils.Companion.extractUrls
import com.legendsayantan.adbtools.lib.Utils.Companion.getAllInstalledApps
import com.legendsayantan.adbtools.lib.Utils.Companion.initialiseStatusBar
import com.legendsayantan.adbtools.lib.Utils.Companion.loadApps
import com.legendsayantan.adbtools.services.SoundMasterService
import com.legendsayantan.adbtools.services.SoundMasterService.Companion.prepareGetAudioDevices
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -72,11 +68,11 @@ class DebloatActivity : AppCompatActivity() {
lateinit var list: ListView
var filterMode = false
lateinit var cachedApps: HashMap<String, AppData>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_debloat)
initialiseStatusBar()
prepareGetAudioDevices()
list = findViewById(R.id.apps_list)
ShizukuRunner.runAdbCommand("pm grant $packageName android.permission.QUERY_ALL_PACKAGES",
object : ShizukuRunner.CommandResultListener {
Expand All @@ -89,17 +85,17 @@ class DebloatActivity : AppCompatActivity() {
val app = apps.values.toList()[position]
//show dialog
val links = MaterialTextView(this)
links.text = "Links :"
links.text = getString(R.string.links)
val listOfLinks = app.description.extractUrls()
val linkView = ListView(this)
linkView.adapter =
ArrayAdapter(this, android.R.layout.simple_list_item_1, listOfLinks)
linkView.setOnItemClickListener { _, _, position, _ ->
linkView.setOnItemClickListener { _, _, linkPosition, _ ->
//open link
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(listOfLinks[position])))
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(listOfLinks[linkPosition])))
}
val uninstallBtn = MaterialButton(this)
uninstallBtn.text = "Confirm to uninstall"
uninstallBtn.text = getString(R.string.confirm_to_uninstall)
uninstallBtn.setOnClickListener {
//uninstall app
Toast.makeText(this, "Uninstalling ${app.name}", Toast.LENGTH_SHORT).show()
Expand Down Expand Up @@ -134,7 +130,7 @@ class DebloatActivity : AppCompatActivity() {
val btnContainer = LinearLayout(this)
btnContainer.addView(uninstallBtn)
btnContainer.setPadding(20, 20, 20, 20)
btnContainer.gravity = Gravity.RIGHT
btnContainer.gravity = Gravity.END
val dialogView = LinearLayout(this)
dialogView.orientation = LinearLayout.VERTICAL
dialogView.setPadding(20, 0, 20, 20)
Expand Down Expand Up @@ -307,7 +303,7 @@ class DebloatActivity : AppCompatActivity() {
object : ShizukuRunner.CommandResultListener {
override fun onCommandResult(output: String, done: Boolean) {
if (done) {
val allApps = output.replace("package:", "").split("\n");
val allApps = output.replace("package:", "").split("\n")
loadApps { installed ->
val uninstalled = allApps.filter { !installed.contains(it) }
println(uninstalled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.legendsayantan.adbtools.dialog.OutputSelectionDialog
import com.legendsayantan.adbtools.lib.ShizukuRunner
import com.legendsayantan.adbtools.lib.Utils.Companion.initialiseStatusBar
import com.legendsayantan.adbtools.services.SoundMasterService
import com.legendsayantan.adbtools.services.SoundMasterService.Companion.prepareGetAudioDevices
import java.io.File
import java.io.FileNotFoundException
import java.util.Timer
Expand All @@ -37,21 +38,22 @@ import kotlin.concurrent.timerTask

class SoundMasterActivity : AppCompatActivity() {
private lateinit var mediaProjectionManager: MediaProjectionManager
private var packageSliders: MutableList<AudioOutputKey>
private var packageSliders: MutableList<AudioOutputBase>
get() = try {
File(applicationContext.filesDir, FILENAME_SOUNDMASTER).let { file ->
file.readText().split("\n").let { text ->
if (!text.any { it.isBlank() }) text.map { line ->
val splits = line.split("/")
AudioOutputKey(splits[0], splits[splits.size - 1].toInt())
AudioOutputBase(splits[0], splits[1].toInt(), splits[2].toFloatOrNull()?:100f)
}.toMutableList()
else {
file.delete()
mutableListOf()
}
}
}
} catch (f: FileNotFoundException) {
} catch (e: Exception) {
File(applicationContext.filesDir, FILENAME_SOUNDMASTER).delete()
mutableListOf()
}
set(value) {
Expand All @@ -60,7 +62,7 @@ class SoundMasterActivity : AppCompatActivity() {
file.parentFile?.mkdirs()
file.createNewFile()
}
file.writeText(value.joinToString("\n") { it.pkg + "/" + it.output })
file.writeText(value.joinToString("\n") { it.pkg + "/" + it.output + "/" + it.volume})
}

val volumeBarView by lazy { findViewById<RecyclerView>(R.id.volumeBars) }
Expand All @@ -71,13 +73,14 @@ class SoundMasterActivity : AppCompatActivity() {
showing = true
setContentView(R.layout.activity_sound_master)
initialiseStatusBar()
prepareGetAudioDevices()
interacted()
//new slider
findViewById<MaterialCardView>(R.id.newSlider).setOnClickListener {
lastInteractionAt = -1
AppSelectionDialog(this@SoundMasterActivity) { pkg ->
OutputSelectionDialog(this@SoundMasterActivity) { device ->
val key = AudioOutputKey(pkg, device?.id ?: -1)
OutputSelectionDialog(this@SoundMasterActivity,SoundMasterService.getAudioDevices()) { device ->
val key = AudioOutputBase(pkg, device?.id ?: -1, 100f)
if (
if (SoundMasterService.running) SoundMasterService.isAttachable(key)
else (packageSliders.find { it.pkg == key.pkg && it.output == key.output }==null)
Expand Down Expand Up @@ -200,6 +203,7 @@ class SoundMasterActivity : AppCompatActivity() {
startService(Intent(this, SoundMasterService::class.java).apply {
putExtra("packages", packageSliders.map { it.pkg }.toTypedArray())
putExtra("devices", packageSliders.map { it.output }.toIntArray())
putExtra("volumes",packageSliders.map { it.volume }.toFloatArray())
})
interacted()
} else {
Expand All @@ -222,42 +226,36 @@ class SoundMasterActivity : AppCompatActivity() {
findViewById<TextView>(R.id.none).visibility =
if (packageSliders.size > 0) View.GONE else View.VISIBLE
Thread {
val sliders = mutableListOf<AudioOutputBase>()
for (pkg in packageSliders) {
val volume = SoundMasterService.getVolumeOf(pkg)
sliders.add(
AudioOutputBase(
pkg.pkg, pkg.output, volume
)
)
}
val adapter =
VolumeBarAdapter(this@SoundMasterActivity, sliders, { app, vol ->
VolumeBarAdapter(this@SoundMasterActivity, packageSliders, { app, vol ->
interacted()
SoundMasterService.setVolumeOf(sliders[app], vol)
val newPackages = packageSliders
newPackages[app] = AudioOutputBase(packageSliders[app].pkg, packageSliders[app].output, vol)
packageSliders = newPackages
SoundMasterService.setVolumeOf(packageSliders[app], vol)
}, {
interacted()
val newPackages = packageSliders
newPackages.removeAt(it)
packageSliders = newPackages
updateSliders()
SoundMasterService.onDynamicDetach(sliders[it])
SoundMasterService.onDynamicDetach(packageSliders[it])
}, { app, sliderIndex ->
interacted()
if (sliderIndex == 0) SoundMasterService.getBalanceOf(sliders[app])
else SoundMasterService.getBandValueOf(sliders[app], sliderIndex - 1)
if (sliderIndex == 0) SoundMasterService.getBalanceOf(packageSliders[app])
else SoundMasterService.getBandValueOf(packageSliders[app], sliderIndex - 1)
}, { app, slider, value ->
interacted()
if (slider == 0) SoundMasterService.setBalanceOf(sliders[app], value)
else SoundMasterService.setBandValueOf(sliders[app], slider - 1, value)
if (slider == 0) SoundMasterService.setBalanceOf(packageSliders[app], value)
else SoundMasterService.setBandValueOf(packageSliders[app], slider - 1, value)
}, {
interacted()
SoundMasterService.getAudioDevices()
}, { pkg, device ->
interacted()
if(SoundMasterService.switchDeviceFor(sliders[pkg], device)){
if(SoundMasterService.switchDeviceFor(packageSliders[pkg], device)){
val newPackages = packageSliders
newPackages[pkg] = AudioOutputKey(sliders[pkg].pkg, device?.id?:-1)
newPackages[pkg] = AudioOutputBase(packageSliders[pkg].pkg, device?.id?:-1, packageSliders[pkg].volume)
packageSliders = newPackages
updateSliders()
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ import kotlin.concurrent.schedule
* @author legendsayantan
*/
class ThemePatcherActivity : AppCompatActivity() {
val zeroByDefault = listOf(
private val zeroByDefault = listOf(
"persist.sys.trial.theme",
"persist.sys.trial_theme",
"persist.sys.trial.font",
"persist.sys.trial.live_wp",
)
val negativeOneByDefault = listOf(
private val negativeOneByDefault = listOf(
"persist.sys.oplus.theme_uuid",
"persist.sys.oppo.theme.uuid",
"persist.sys.oppo.theme.uuid",
"persist.sys.oppo.theme_uuid"
)
val otherDefaults = hashMapOf(
private val otherDefaults = hashMapOf(
Pair("persist.sys.oplus.live_wp_uuid", "default_live_wp_package_name"),
Pair("persist.sys.oppo.live_wp_uuid", "default_live_wp_package_name")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class DebloatAdapter(private val activity: Activity, private val dataList: HashM
val background = view.findViewById<MaterialCardView>(R.id.background)

val desc = if(data.second.description.isNotEmpty()){
var copy = data.second.description
copy.replace("\n\n","\n").removeUrls()
data.second.description.replace("\n\n","\n").removeUrls()
}else{
data.first
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import android.app.Dialog
import android.content.Context
import android.media.AudioDeviceInfo
import android.view.Gravity
import android.view.WindowManager
import androidx.recyclerview.widget.RecyclerView
import com.legendsayantan.adbtools.R
import com.legendsayantan.adbtools.adapters.SimpleAdapter
import com.legendsayantan.adbtools.adapters.VolumeBarAdapter
import com.legendsayantan.adbtools.services.SoundMasterService

/**
* @author legendsayantan
*/
class OutputSelectionDialog(c:Context,val onDeviceSelected:(AudioDeviceInfo?)->Unit) : Dialog(c) {
class OutputSelectionDialog(
c: Context,
private val devices: List<AudioDeviceInfo?>, val onDeviceSelected: (AudioDeviceInfo?) -> Unit
) : Dialog(c) {
init {
setContentView(R.layout.dialog_outputs)
window?.setBackgroundDrawableResource(android.R.color.transparent)
Expand All @@ -24,9 +25,8 @@ class OutputSelectionDialog(c:Context,val onDeviceSelected:(AudioDeviceInfo?)->U
override fun show() {
super.show()
val list = findViewById<RecyclerView>(R.id.outputs)
val devices = SoundMasterService.getAudioDevices()
val data = devices.map{ VolumeBarAdapter.formatDevice(it) }
val adapter = SimpleAdapter(data){
val data = devices.map { VolumeBarAdapter.formatDevice(it) }
val adapter = SimpleAdapter(data) {
dismiss()
onDeviceSelected(devices[it])
}
Expand Down
23 changes: 7 additions & 16 deletions app/src/main/java/com/legendsayantan/adbtools/lib/GradleUpdate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,21 @@ class GradleUpdate(val context: Context,val gradleFileUrl: String,val checkInter
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val intent = Intent(Intent.ACTION_VIEW,android.net.Uri.parse(apkUrl))
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)
val notification = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannel(
NotificationChannel(
"${context.packageName}.update",
"Updates",
NotificationManager.IMPORTANCE_HIGH
)
notificationManager.createNotificationChannel(
NotificationChannel(
"${context.packageName}.update",
"Updates",
NotificationManager.IMPORTANCE_HIGH
)
)
val notification =
Notification.Builder(context, "${context.packageName}.update")
.setContentTitle("Update available")
.setContentText("New version $version available, click to download.")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setSmallIcon(smallIcon)
.build()
} else {
Notification.Builder(context)
.setContentTitle("Update available")
.setContentText("New version $version available")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setSmallIcon(smallIcon)
.build()
}
notificationManager.notify(1, notification)
}, {})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import com.legendsayantan.adbtools.data.AudioOutputKey
import com.legendsayantan.adbtools.services.SoundMasterService.Companion.notiUpdateTime
import com.legendsayantan.adbtools.services.SoundMasterService.Companion.updateInterval

/**
* @author legendsayantan
Expand All @@ -28,7 +28,6 @@ class PlayBackThread(
private val mediaProjection: MediaProjection
) : Thread("$LOG_TAG : $pkg") {
var playback = true
var targetVolume: Float = 100f
val dataBuffer = ByteArray(BUF_SIZE)
var loadedCycles = 0

Expand Down Expand Up @@ -111,7 +110,7 @@ class PlayBackThread(
fun createOutput(
device: AudioDeviceInfo? = null,
outputKey:Int=device?.id?:-1,
startVolume: Float = targetVolume, bal: Float? = null,
startVolume: Float, bal: Float? = null,
bands: Array<Float> = arrayOf()
) {
val plyr = AudioPlayer(
Expand All @@ -126,8 +125,7 @@ class PlayBackThread(
plyr.play()
try {
plyr.equalizer.enabled = true
} catch (_: Exception) {
}
} catch (_: Exception) { }
bal?.let { plyr.setBalance(bal) }
bands.forEachIndexed { index, fl -> plyr.setBand(index, fl) }
mPlayers[outputKey] = plyr
Expand All @@ -151,7 +149,7 @@ class PlayBackThread(
}

fun getLatency(): Float {
return notiUpdateTime.toFloat() / loadedCycles.coerceAtLeast(1).also { loadedCycles = 0 }
return updateInterval.toFloat() / loadedCycles.coerceAtLeast(1).also { loadedCycles = 0 }
}

override fun interrupt() {
Expand Down
Loading

0 comments on commit 5916c2b

Please sign in to comment.