Skip to content

Commit

Permalink
Merge pull request #326 from hemker/feature/compare_version_name
Browse files Browse the repository at this point in the history
Implement optional version name comparison
  • Loading branch information
rumboalla authored Dec 31, 2020
2 parents c31fc01 + 4d6febd commit e991e3e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ dependencies {
implementation 'ch.acra:acra-http:5.4.0'
implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.1'
implementation 'com.g00fy2:versioncompare:1.3.7'

testImplementation 'junit:junit:4.12'

Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/apkupdater/repository/UpdatesRepository.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.apkupdater.repository

import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import com.apkupdater.model.ui.AppUpdate
import com.apkupdater.repository.apkmirror.ApkMirrorUpdater
Expand All @@ -8,6 +9,7 @@ import com.apkupdater.repository.fdroid.FdroidRepository
import com.apkupdater.repository.googleplay.GooglePlayRepository
import com.apkupdater.util.app.AppPrefs
import com.apkupdater.util.ioScope
import com.g00fy2.versioncompare.Version
import kotlinx.coroutines.async
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
Expand Down Expand Up @@ -43,7 +45,15 @@ class UpdatesRepository: KoinComponent {
)
}

if (prefs.settings.compareVersionName) filterUpdates(updates, apps)

if (errors.isEmpty()) Result.success(updates.sortedBy { it.name }) else Result.failure(errors.first())
}

}
private fun filterUpdates(updates: MutableList<AppUpdate>, apps: Sequence<PackageInfo>) {
updates.retainAll { update ->
Version(update.version).isHigherThan(apps.find { apk -> apk.packageName == update.packageName }?.versionName)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class PreferenceFragmentPrefs(private val context: Context, private val prefs: S
get() = prefs.getBoolean(context.getString(R.string.settings_exclude_experimental_key), true)
set(value) = prefs.edit().putBoolean(context.getString(R.string.settings_exclude_experimental_key), value).apply()

var compareVersionName
get() = prefs.getBoolean("compareVersionName", true)
set(value) = prefs.edit().putBoolean("compareVersionName", value).apply()

var checkForUpdates
get() = prefs.getString(context.getString(R.string.settings_check_for_updates_key), "0")
set(value) = prefs.edit().putString(context.getString(R.string.settings_check_for_updates_key), value).apply()
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<string translatable="false" name="settings_exclude_experimental_key">excludeExperimental</string>
<string name="settings_exclude_experimental_title">Exclude Experimental Apps</string>

<string translatable="false" name="settings_compare_version_name_key">compareVersionName</string>
<string name="settings_compare_version_name_title">Compare Version Name</string>

<string translatable="false" name="settings_root_install_key">rootInstall</string>
<string name="settings_root_install_title">Root Install</string>

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@
app:defaultValue="true"
app:iconSpaceReserved="false"
/>
<SwitchPreferenceCompat
app:key="@string/settings_compare_version_name_key"
app:title="@string/settings_compare_version_name_title"
app:summary=""
app:defaultValue="true"
app:iconSpaceReserved="false"
/>
</PreferenceCategory>

<PreferenceCategory app:title="@string/settings_root_options_title" app:iconSpaceReserved="false">
Expand Down

0 comments on commit e991e3e

Please sign in to comment.