Skip to content

Commit

Permalink
refactor and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
legendsayantan committed Jun 19, 2024
1 parent 5916c2b commit 00f869c
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 166 deletions.
Binary file modified app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ class DebloatActivity : AppCompatActivity() {
onFailure: () -> Unit
) {
try {
val url =
URL("https://cdn.jsdelivr.net/gh/Universal-Debloater-Alliance/universal-android-debloater-next-generation@main/resources/assets/uad_lists.json")
val url = URL(getString(R.string.url_uad_lists))
GlobalScope.launch(Dispatchers.IO) {
try {
// Read the JSON content from the URL
Expand Down Expand Up @@ -306,7 +305,6 @@ class DebloatActivity : AppCompatActivity() {
val allApps = output.replace("package:", "").split("\n")
loadApps { installed ->
val uninstalled = allApps.filter { !installed.contains(it) }
println(uninstalled)
runOnUiThread {
val appsView = RecyclerView(activityContext)
val dialog = MaterialAlertDialogBuilder(activityContext)
Expand Down Expand Up @@ -350,6 +348,6 @@ class DebloatActivity : AppCompatActivity() {
}

companion object{
val FILENAME_DATABASE: String = "debloat-list.json"
const val FILENAME_DATABASE: String = "debloat-list.json"
}
}
16 changes: 10 additions & 6 deletions app/src/main/java/com/legendsayantan/adbtools/LookbackActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,21 @@ class LookbackActivity : AppCompatActivity() {
"Installed Successfully.",
Toast.LENGTH_SHORT
).show()
} else {
Toast.makeText(
applicationContext,
"Failure: ${output}",
Toast.LENGTH_SHORT
).show()
}
cacheFile.delete()
}
}
}

override fun onCommandError(error: String) {
Handler(mainLooper).post {
Toast.makeText(
applicationContext,
"Failure: $error",
Toast.LENGTH_SHORT
).show()
}
}
})

}
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/com/legendsayantan/adbtools/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import com.legendsayantan.adbtools.lib.ShizukuRunner
import com.legendsayantan.adbtools.lib.Utils
import com.legendsayantan.adbtools.lib.Utils.Companion.initialiseNotiChannel
import com.legendsayantan.adbtools.lib.Utils.Companion.initialiseStatusBar
import com.legendsayantan.adbtools.services.SoundMasterService
import java.util.UUID
Expand Down Expand Up @@ -122,19 +120,20 @@ class MainActivity : AppCompatActivity() {
}
}
}
cardShell.setOnClickListener { openShell() }
cardShell.setOnClickListener { localShell() }
cardIntentShell.setOnClickListener { intentShell() }
}

private fun openShell() {
private fun localShell() {
val dialog = MaterialAlertDialogBuilder(this)
dialog.setTitle("ADB Shell")
dialog.setTitle(getString(R.string.localshell))
val scrollContainer = ScrollView(this)
val layout = LinearLayout(this)
layout.orientation = LinearLayout.VERTICAL
layout.setPadding(30, 25, 30, 15)
val commandOut = TextView(this)
val commandBar = LinearLayout(this)
commandOut.typeface = resources.getFont(R.font.consolas)
commandBar.orientation = LinearLayout.HORIZONTAL
commandBar.gravity = Gravity.CENTER
val editText = EditText(this)
Expand All @@ -158,6 +157,12 @@ class MainActivity : AppCompatActivity() {
btn.isEnabled = done
}
}

override fun onCommandError(error: String) {
runOnUiThread {
commandOut.text = "ERROR:\n$error"
}
}
})
editText.selectAll()
}
Expand All @@ -174,9 +179,9 @@ class MainActivity : AppCompatActivity() {
private fun intentShell(){
val prefs = getSharedPreferences("execution", MODE_PRIVATE)
if(prefs.getString("key",null)==null){
prefs.edit().putString("key",UUID.randomUUID().toString()).apply()
prefs.edit().putString("key",UUID.randomUUID().toString().replace("-","")).apply()
}
val key = prefs.getString("key",null)
val key = prefs.getString("key",null)?.replace("-","")
val layout = LinearLayout(this).apply {
setPadding(60,0,60,0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,13 @@ class MixedAudioActivity : AppCompatActivity() {
reloadApps()
}
}

override fun onCommandError(error: String) {
runOnUiThread {
Toast.makeText(this@MixedAudioActivity, "Error: $error", Toast.LENGTH_SHORT).show()
dialog.dismiss()
}
}
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Intent
import android.media.projection.MediaProjectionManager
import android.os.Bundle
import android.os.Handler
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import android.widget.Space
Expand All @@ -20,15 +21,13 @@ import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.card.MaterialCardView
import com.legendsayantan.adbtools.adapters.VolumeBarAdapter
import com.legendsayantan.adbtools.data.AudioOutputBase
import com.legendsayantan.adbtools.data.AudioOutputKey
import com.legendsayantan.adbtools.dialog.AppSelectionDialog
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
import kotlin.concurrent.timerTask

Expand All @@ -44,7 +43,11 @@ class SoundMasterActivity : AppCompatActivity() {
file.readText().split("\n").let { text ->
if (!text.any { it.isBlank() }) text.map { line ->
val splits = line.split("/")
AudioOutputBase(splits[0], splits[1].toInt(), splits[2].toFloatOrNull()?:100f)
AudioOutputBase(
splits[0],
splits[1].toInt(),
splits[2].toFloatOrNull() ?: 100f
)
}.toMutableList()
else {
file.delete()
Expand All @@ -62,7 +65,7 @@ class SoundMasterActivity : AppCompatActivity() {
file.parentFile?.mkdirs()
file.createNewFile()
}
file.writeText(value.joinToString("\n") { it.pkg + "/" + it.output + "/" + it.volume})
file.writeText(value.joinToString("\n") { it.pkg + "/" + it.output + "/" + it.volume })
}

val volumeBarView by lazy { findViewById<RecyclerView>(R.id.volumeBars) }
Expand All @@ -79,18 +82,24 @@ class SoundMasterActivity : AppCompatActivity() {
findViewById<MaterialCardView>(R.id.newSlider).setOnClickListener {
lastInteractionAt = -1
AppSelectionDialog(this@SoundMasterActivity) { pkg ->
OutputSelectionDialog(this@SoundMasterActivity,SoundMasterService.getAudioDevices()) { device ->
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)
else (packageSliders.find { it.pkg == key.pkg && it.output == key.output } == null)
) {
val newPackages = packageSliders
newPackages.add(key)
packageSliders = newPackages
if (SoundMasterService.running) SoundMasterService.onDynamicAttach(key, device)
if (SoundMasterService.running) SoundMasterService.onDynamicAttach(
key,
device
)
updateSliders()
}else combinationExists()
} else combinationExists()
interacted()
}.show()
}.show()
Expand Down Expand Up @@ -127,7 +136,7 @@ class SoundMasterActivity : AppCompatActivity() {
super.onResume()
}

fun updateBtnState() {
private fun updateBtnState() {
val btnImage = findViewById<ImageView>(R.id.playPauseButton)
btnImage.setImageResource(if (SoundMasterService.running) R.drawable.baseline_stop_24 else R.drawable.baseline_play_arrow_24)
btnImage.setOnClickListener {
Expand All @@ -153,12 +162,24 @@ class SoundMasterActivity : AppCompatActivity() {
done: Boolean
) {
if (done) {
mediaProjectionManager =
applicationContext.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(),
MEDIA_PROJECTION_REQUEST_CODE
)
if (output.isBlank()){
mediaProjectionManager =
applicationContext.getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(),
MEDIA_PROJECTION_REQUEST_CODE
)
}
}
}

override fun onCommandError(error: String) {
Handler(mainLooper).post {
Toast.makeText(
applicationContext,
getString(R.string.permission_error),
Toast.LENGTH_LONG
).show()
}
}
})
Expand All @@ -169,8 +190,8 @@ class SoundMasterActivity : AppCompatActivity() {
Handler(mainLooper).post {
Toast.makeText(
applicationContext,
"Shizuku Error",
Toast.LENGTH_SHORT
getString(R.string.permission_error),
Toast.LENGTH_LONG
).show()
}
}
Expand Down Expand Up @@ -203,16 +224,15 @@ 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())
putExtra("volumes", packageSliders.map { it.volume }.toFloatArray())
})
interacted()
} else {
Toast.makeText(
this, "Request to obtain MediaProjection failed.",
Toast.LENGTH_SHORT
).show()
interacted()
}
interacted()
}
}

Expand All @@ -230,7 +250,8 @@ class SoundMasterActivity : AppCompatActivity() {
VolumeBarAdapter(this@SoundMasterActivity, packageSliders, { app, vol ->
interacted()
val newPackages = packageSliders
newPackages[app] = AudioOutputBase(packageSliders[app].pkg, packageSliders[app].output, vol)
newPackages[app] =
AudioOutputBase(packageSliders[app].pkg, packageSliders[app].output, vol)
packageSliders = newPackages
SoundMasterService.setVolumeOf(packageSliders[app], vol)
}, {
Expand All @@ -253,13 +274,17 @@ class SoundMasterActivity : AppCompatActivity() {
SoundMasterService.getAudioDevices()
}, { pkg, device ->
interacted()
if(SoundMasterService.switchDeviceFor(packageSliders[pkg], device)){
if (SoundMasterService.switchDeviceFor(packageSliders[pkg], device)) {
val newPackages = packageSliders
newPackages[pkg] = AudioOutputBase(packageSliders[pkg].pkg, device?.id?:-1, packageSliders[pkg].volume)
newPackages[pkg] = AudioOutputBase(
packageSliders[pkg].pkg,
device?.id ?: -1,
packageSliders[pkg].volume
)
packageSliders = newPackages
updateSliders()
true
}else {
} else {
combinationExists()
false
}
Expand All @@ -271,8 +296,9 @@ class SoundMasterActivity : AppCompatActivity() {
}.start()
}

private fun combinationExists(){
Toast.makeText(applicationContext,"Combination already exists.",Toast.LENGTH_SHORT).show()
private fun combinationExists() {
Toast.makeText(applicationContext, "Combination already exists.", Toast.LENGTH_SHORT)
.apply { setGravity(Gravity.TOP, 0, 100) }.show()
}

companion object {
Expand Down
Loading

0 comments on commit 00f869c

Please sign in to comment.