App: Update object with installation status
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -180,7 +180,6 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
|||||||
private var isExternal = false
|
private var isExternal = false
|
||||||
private var isNone = false
|
private var isNone = false
|
||||||
private var status = Status.NONE
|
private var status = Status.NONE
|
||||||
private var isInstalled: Boolean = false
|
|
||||||
private var isUpdatable: Boolean = false
|
private var isUpdatable: Boolean = false
|
||||||
private var autoDownload: Boolean = false
|
private var autoDownload: Boolean = false
|
||||||
private var downloadOnly: Boolean = false
|
private var downloadOnly: Boolean = false
|
||||||
@@ -255,14 +254,15 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
|||||||
|
|
||||||
if (args.app != null) {
|
if (args.app != null) {
|
||||||
app = args.app!!
|
app = args.app!!
|
||||||
isInstalled = PackageUtil.isInstalled(requireContext(), app.packageName)
|
|
||||||
|
|
||||||
inflatePartialApp()
|
inflatePartialApp()
|
||||||
} else {
|
} else {
|
||||||
isExternal = true
|
isExternal = true
|
||||||
app = App(args.packageName)
|
app = App(args.packageName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check whether app is installed or not
|
||||||
|
app.isInstalled = PackageUtil.isInstalled(requireContext(), app.packageName)
|
||||||
|
|
||||||
// App Details
|
// App Details
|
||||||
viewModel.fetchAppDetails(view.context, app.packageName)
|
viewModel.fetchAppDetails(view.context, app.packageName)
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
@@ -421,10 +421,11 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (::app.isInitialized) {
|
if (::app.isInitialized) {
|
||||||
val installed = PackageUtil.isInstalled(requireContext(), app.packageName)
|
app.isInstalled = PackageUtil.isInstalled(requireContext(), app.packageName)
|
||||||
menu?.findItem(R.id.action_uninstall)?.isVisible = installed
|
|
||||||
menu?.findItem(R.id.menu_app_settings)?.isVisible = installed
|
menu?.findItem(R.id.action_uninstall)?.isVisible = app.isInstalled
|
||||||
uninstallActionEnabled = installed
|
menu?.findItem(R.id.menu_app_settings)?.isVisible = app.isInstalled
|
||||||
|
uninstallActionEnabled = app.isInstalled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -706,11 +707,11 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAndSetupInstall() {
|
private fun checkAndSetupInstall() {
|
||||||
runOnUiThread {
|
app.isInstalled = PackageUtil.isInstalled(requireContext(), app.packageName)
|
||||||
isInstalled = PackageUtil.isInstalled(requireContext(), app.packageName)
|
|
||||||
|
|
||||||
|
runOnUiThread {
|
||||||
binding.layoutDetailsInstall.btnDownload.let { btn ->
|
binding.layoutDetailsInstall.btnDownload.let { btn ->
|
||||||
if (isInstalled) {
|
if (app.isInstalled) {
|
||||||
isUpdatable = PackageUtil.isUpdatable(
|
isUpdatable = PackageUtil.isUpdatable(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
app.packageName,
|
app.packageName,
|
||||||
|
|||||||
@@ -61,6 +61,10 @@ abstract class BaseAppsViewModel(application: Application) : BaseAndroidViewMode
|
|||||||
return appDetailsHelper
|
return appDetailsHelper
|
||||||
.getAppByPackageName(filtersPackages)
|
.getAppByPackageName(filtersPackages)
|
||||||
.filter { it.displayName.isNotEmpty() }
|
.filter { it.displayName.isNotEmpty() }
|
||||||
|
.map {
|
||||||
|
it.isInstalled = true
|
||||||
|
it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user