Commit 09b4c46a authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Fix updates screen

parent 1a8224d3
......@@ -79,11 +79,10 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
showFragment(searchFragment)
return true
}
// TODO Enable once updates screen is implemented
/*R.id.menu_updates -> {
R.id.menu_updates -> {
showFragment(updatesFragment)
return true
}*/
}
R.id.menu_settings -> {
showFragment(SettingsFragment())
return true
......
......@@ -9,12 +9,12 @@ import io.eelo.appinstaller.application.model.State
import io.eelo.appinstaller.utils.Execute
import java.util.concurrent.atomic.AtomicInteger
class UnUpdatedAppsFinder(private val packageManager: PackageManager, private val callback: UpdatesModelInterface, private val applicationManager: ApplicationManager) : AsyncTask<Context, Any, Any>() {
class OutdatedApplicationsFinder(private val packageManager: PackageManager, private val callback: UpdatesModelInterface, private val applicationManager: ApplicationManager) : AsyncTask<Context, Any, Any>() {
private var result: ArrayList<Application>? = null
override fun doInBackground(vararg params: Context): Any? {
result = getNotUpdatedApplications(params[0])
result = getOutdatedApplications(params[0])
return null
}
......@@ -22,7 +22,7 @@ class UnUpdatedAppsFinder(private val packageManager: PackageManager, private va
callback.onAppsFound(this.result!!)
}
private fun getNotUpdatedApplications(context: Context): ArrayList<Application> {
private fun getOutdatedApplications(context: Context): ArrayList<Application> {
val result = ArrayList<Application>()
val installedApplications = getInstalledApplications()
......@@ -58,9 +58,31 @@ class UnUpdatedAppsFinder(private val packageManager: PackageManager, private va
private fun getInstalledApplications(): ArrayList<String> {
val result = ArrayList<String>()
packageManager.getInstalledApplications(0).forEach { app ->
result.add(app.packageName)
if (!isSystemApp(app.packageName)) {
result.add(app.packageName)
}
}
return result
}
private fun isSystemApp(packageName: String): Boolean {
try {
// Get package information for the app
val appPackageInfo = packageManager.getPackageInfo(
packageName, PackageManager.GET_SIGNATURES)
// Get package information for the Android system
val systemPackageInfo = packageManager.getPackageInfo(
"android", PackageManager.GET_SIGNATURES)
// Compare app and Android system signatures
if (appPackageInfo.signatures.isNotEmpty() &&
systemPackageInfo.signatures.isNotEmpty() &&
appPackageInfo.signatures[0] == systemPackageInfo.signatures[0]) {
return true
}
} catch (exception: Exception) {
exception.printStackTrace()
}
return false
}
}
......@@ -21,7 +21,7 @@ class UpdatesModel : UpdatesModelInterface {
override fun loadApplicationList(context: Context) {
if (Common.isNetworkAvailable(context)) {
UnUpdatedAppsFinder(context.packageManager, this, applicationManager!!).execute(context)
OutdatedApplicationsFinder(context.packageManager, this, applicationManager!!).execute(context)
} else {
screenError.value = Error.NO_INTERNET
}
......
......@@ -19,12 +19,11 @@
android:icon="@drawable/ic_menu_search"
android:orderInCategory="1"/>
<!-- TODO Enable once updates screen is implemented -->
<!--<item
<item
android:title="@string/menu_updates"
android:id="@+id/menu_updates"
android:icon="@drawable/ic_menu_updates"
android:orderInCategory="1"/>-->
android:orderInCategory="1"/>
<item
android:title="@string/menu_settings"
......
......@@ -13,8 +13,7 @@
</PreferenceCategory>
<!-- TODO Enable once updates screen is implemented -->
<!--<PreferenceCategory android:title="@string/preference_updates_title">
<PreferenceCategory android:title="@string/preference_updates_title">
<ListPreference
android:defaultValue="@string/preference_update_interval_default"
......@@ -43,5 +42,5 @@
android:summary="@string/preference_update_notify_available_description"
android:title="@string/preference_update_notify_available_title" />
</PreferenceCategory>-->
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment