Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
AkosPaha01 committed Aug 9, 2022
1 parent 0e3c1c9 commit c3fd6eb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ class MainActivity : AppCompatActivity() {
if (!themes.isNullOrEmpty()) {
openShareThemeDialog { dialog, name, author ->
val files = arrayListOf<File>()
File(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){cacheDir}else{
externalCacheDir
}, "pack.meta").apply {
File(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
cacheDir
} else {
externalCacheDir
}, "pack.meta"
).apply {
files.add(this)
writeText("name=$name\nauthor=$author\n")
}
Expand All @@ -288,9 +292,13 @@ class MainActivity : AppCompatActivity() {
files.add(File(it.path))
if (image.exists()) files.add(image)
}
val zip = File(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){cacheDir}else{
externalCacheDir
}, "themes.pack")
val zip = File(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
cacheDir
} else {
externalCacheDir
}, "themes.pack"
)
zip.delete()
ZipHelper().zip(files.map { it.absolutePath }, zip.absolutePath)
files.forEach { it.delete() }
Expand Down Expand Up @@ -471,7 +479,11 @@ class MainActivity : AppCompatActivity() {
R.string.patch,
Build.VERSION.SDK_INT > Build.VERSION_CODES.N
) {
if (PackageUtils.isPackageInstalled(PATCHER_PACKAGE, packageManager)) {
if (PackageUtils.isPackageInstalled(
PATCHER_PACKAGE,
packageManager
)
) {
val themeFile = File(theme.path)
val imageFile = theme.image?.let {
File(
Expand All @@ -482,12 +494,23 @@ class MainActivity : AppCompatActivity() {
val files = arrayListOf(themeFile)
if (imageFile != null) files.add(imageFile)

val pack = File(cacheDir, "export.pack")
val pack = File(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
cacheDir
} else {
externalCacheDir
}, "export.pack"
)
ZipHelper().zip(
files.map { it.absolutePath },
pack.absolutePath
)
ThemeUtils.shareTheme(this, pack, true, PATCHER_PACKAGE)
ThemeUtils.shareTheme(
this,
pack,
true,
PATCHER_PACKAGE
)
} else openUrl(PLAY_URL(PATCHER_PACKAGE))
}
)
Expand Down Expand Up @@ -737,6 +760,7 @@ class MainActivity : AppCompatActivity() {
}
}.start()
}

override fun onDestroy() {
callbacks.forEach { it.remove() }
super.onDestroy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.view.View
import android.view.ViewTreeObserver
Expand Down Expand Up @@ -234,7 +235,13 @@ class AppStartUp(private val activity: AppCompatActivity) {
initialized && scheme != "content" && data != null -> {
if (data.scheme == "file") {
val file = SuFile(data.path).let {
File(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){filesDir}else{getExternalFilesDir("")}, "theme.pack").apply {
File(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
filesDir
} else {
getExternalFilesDir("")
}, "theme.pack"
).apply {
ProcessBuilder().su(
"rm \"$absolutePath\"",
"cp \"${it.absolutePath}\" \"$absolutePath\"",
Expand Down Expand Up @@ -290,7 +297,13 @@ class AppStartUp(private val activity: AppCompatActivity) {
}
finishAndRemoveTask()
}
val file = File(cacheDir, "flags.rboard").apply {
val file = File(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
cacheDir
} else {
externalCacheDir
}, "flags.rboard"
).apply {
delete()
data.writeToFile(activity, this)
}
Expand Down Expand Up @@ -324,13 +337,25 @@ class AppStartUp(private val activity: AppCompatActivity) {
isReady = true
openLoadingDialog(R.string.unpacking_themes)
doAsync({
val zip = File(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){cacheDir}else{externalCacheDir},"themes.pack").apply {
val zip = File(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
cacheDir
} else {
externalCacheDir
}, "themes.pack"
).apply {
delete()
data.writeToFile(activity, this)
}
if (!zip.exists()) listOf()
else {
val destination = File(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P){cacheDir}else{externalCacheDir}, zip.nameWithoutExtension)
val destination = File(
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
cacheDir
} else {
externalCacheDir
}, zip.nameWithoutExtension
)
SuFile(destination.absolutePath).deleteRecursive()
if (ZipHelper().unpackZip(
destination.absolutePath,
Expand Down

0 comments on commit c3fd6eb

Please sign in to comment.