Skip to content

Commit

Permalink
ReVancedUpdater: Fixup threads stuff
Browse files Browse the repository at this point in the history
* Move the whole compareHashes() function to a separate thread, but keep the code that updates UI stuff on the UI thread

Signed-off-by: Leonardo Ledda <leonardoledda@gmail.com>
  • Loading branch information
LeddaZ committed Feb 10, 2024
1 parent e03ca59 commit 4ab9ebf
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/it/leddaz/revancedupdater/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.apache.commons.codec.binary.Hex
import org.apache.commons.codec.digest.DigestUtils
import java.io.File
import java.io.FileInputStream
import kotlin.concurrent.thread


private var installedReVancedVersion = Version("99.99")
Expand Down Expand Up @@ -438,7 +439,9 @@ class MainActivity : AppCompatActivity() {
var latestHash = getLatestReVancedHash()
if (packageName == MUSIC_PACKAGE)
latestHash = getLatestReVancedMusicHash()
compareHashes(latestHash, updateStatusTextView, packageName, button)
thread {
compareHashes(latestHash, updateStatusTextView, packageName, button)
}
} else {
updateStatusTextView.text = getString(R.string.no_update_available)
button.isEnabled = false
Expand All @@ -463,12 +466,14 @@ class MainActivity : AppCompatActivity() {
) {
val pInfo: PackageInfo = packageManager.getPackageInfo(packageName, 0)
val file = File(pInfo.applicationInfo.sourceDir)
runOnUiThread {
val installedAppHash = String(Hex.encodeHex(DigestUtils.sha256(FileInputStream(file))))
if (installedAppHash == latestHash) {
val installedAppHash = String(Hex.encodeHex(DigestUtils.sha256(FileInputStream(file))))
if (installedAppHash == latestHash) {
runOnUiThread {
updateStatusTextView.text = getString(R.string.no_update_available)
button.isEnabled = false
} else {
}
} else {
runOnUiThread {
updateStatusTextView.text = getString(R.string.update_available)
button.isEnabled = true
}
Expand Down

0 comments on commit 4ab9ebf

Please sign in to comment.