|
|
@@ -1,7 +1,12 @@
|
|
|
package com.sduduzog.slimlauncher.ui.main
|
|
|
|
|
|
import android.app.Activity
|
|
|
-import android.content.*
|
|
|
+import android.content.ActivityNotFoundException
|
|
|
+import android.content.BroadcastReceiver
|
|
|
+import android.content.ComponentName
|
|
|
+import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
+import android.content.IntentFilter
|
|
|
import android.content.pm.LauncherApps
|
|
|
import android.net.Uri
|
|
|
import android.os.Bundle
|
|
|
@@ -18,6 +23,8 @@ import android.view.inputmethod.EditorInfo
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
import android.widget.PopupMenu
|
|
|
import android.widget.Toast
|
|
|
+import androidx.activity.result.ActivityResultLauncher
|
|
|
+import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
|
|
|
import androidx.constraintlayout.motion.widget.MotionLayout
|
|
|
import androidx.constraintlayout.motion.widget.MotionLayout.TransitionListener
|
|
|
import androidx.fragment.app.viewModels
|
|
|
@@ -43,7 +50,8 @@ import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.launch
|
|
|
import java.text.DateFormat
|
|
|
import java.text.SimpleDateFormat
|
|
|
-import java.util.*
|
|
|
+import java.util.Date
|
|
|
+import java.util.Locale
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
@AndroidEntryPoint
|
|
|
@@ -55,6 +63,12 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
|
|
|
private lateinit var receiver: BroadcastReceiver
|
|
|
private lateinit var appDrawerAdapter: AppDrawerAdapter
|
|
|
+ private lateinit var uninstallAppLauncher: ActivityResultLauncher<Intent>
|
|
|
+
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+ uninstallAppLauncher = registerForActivityResult(StartActivityForResult()) { refreshApps() }
|
|
|
+ }
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
|
|
val coreRepository = unlauncherDataSource.corePreferencesRepo
|
|
|
@@ -124,9 +138,7 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
super.onResume()
|
|
|
updateClock()
|
|
|
|
|
|
- lifecycleScope.launch(Dispatchers.IO) {
|
|
|
- unlauncherDataSource.unlauncherAppsRepo.setApps(getInstalledApps())
|
|
|
- }
|
|
|
+ refreshApps()
|
|
|
if (!::appDrawerAdapter.isInitialized) {
|
|
|
appDrawerAdapter.setAppFilter()
|
|
|
}
|
|
|
@@ -138,6 +150,14 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun refreshApps() {
|
|
|
+ val installedApps = getInstalledApps()
|
|
|
+ lifecycleScope.launch(Dispatchers.IO) {
|
|
|
+ unlauncherDataSource.unlauncherAppsRepo.setApps(installedApps)
|
|
|
+ viewModel.filterHomeApps(installedApps)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
override fun onStop() {
|
|
|
super.onStop()
|
|
|
activity?.unregisterReceiver(receiver)
|
|
|
@@ -353,7 +373,7 @@ class HomeFragment : BaseFragment(), OnLaunchAppListener {
|
|
|
R.id.uninstall -> {
|
|
|
val intent = Intent(Intent.ACTION_DELETE)
|
|
|
intent.data = Uri.parse("package:" + app.packageName)
|
|
|
- startActivity(intent)
|
|
|
+ uninstallAppLauncher.launch(intent)
|
|
|
//appDrawerAdapter.notifyDataSetChanged()
|
|
|
// TODO: Handle the case when this is done for system apps
|
|
|
}
|