diff --git a/app/build.gradle b/app/build.gradle index 326cf1a0..02c2ca2f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -263,7 +263,7 @@ dependencies { implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'com.google.android.exoplayer:exoplayer:2.16.0' implementation 'com.google.android.exoplayer:extension-mediasession:2.16.0' - implementation 'com.ramijemli.percentagechartview:percentagechartview:0.3.1' + implementation 'com.github.DroidsOnRoids:PercentageChartView:5a6836bd0d' implementation 'com.github.massoudss:waveformSeekBar:5.0.1' implementation 'com.github.lincollincol:amplituda:2.1.6' //Simple library show diff --git a/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt b/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt index 4f362cd3..582bea3f 100644 --- a/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt +++ b/app/src/main/java/com/amaze/fileutilities/PermissionsActivity.kt @@ -209,7 +209,12 @@ open class PermissionsActivity : .setPositiveButton( resources.getString(R.string.yes) ) { dialog, _ -> - startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) + try { + startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) + } catch (anfe: ActivityNotFoundException) { + log.warn("failed to find location settings activity", anfe) + this.showToastInCenter(getString(R.string.grantfailed)) + } dialog.cancel() } .setNegativeButton( diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt b/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt index 2f926b34..a23dadb7 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/WelcomePermissionScreen.kt @@ -195,7 +195,12 @@ abstract class WelcomePermissionScreen : .setPositiveButton( resources.getString(R.string.yes) ) { dialog, _ -> - startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) + try { + startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)) + } catch (anfe: ActivityNotFoundException) { + log.warn("failed to find location settings activity", anfe) + this.showToastInCenter(getString(R.string.grantfailed)) + } dialog.cancel() } .setNegativeButton( diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/AnalyseFragment.kt b/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/AnalyseFragment.kt index ff29e7af..b1c91b80 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/AnalyseFragment.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/AnalyseFragment.kt @@ -20,6 +20,7 @@ package com.amaze.fileutilities.home_page.ui.analyse +import android.content.ActivityNotFoundException import android.content.Intent import android.content.SharedPreferences import android.net.Uri @@ -40,6 +41,7 @@ import androidx.work.ExistingPeriodicWorkPolicy import com.amaze.fileutilities.BuildConfig import com.amaze.fileutilities.R import com.amaze.fileutilities.databinding.FragmentAnalyseBinding +import com.amaze.fileutilities.home_page.WelcomePermissionScreen import com.amaze.fileutilities.home_page.database.AppDatabase import com.amaze.fileutilities.home_page.database.PathPreferences import com.amaze.fileutilities.home_page.ui.files.FilesViewModel @@ -48,11 +50,16 @@ import com.amaze.fileutilities.utilis.AbstractMediaFileInfoOperationsFragment import com.amaze.fileutilities.utilis.PreferencesConstants import com.amaze.fileutilities.utilis.Utils import com.amaze.fileutilities.utilis.getAppCommonSharedPreferences +import com.amaze.fileutilities.utilis.showToastInCenter import com.amaze.fileutilities.utilis.showToastOnBottom import kotlin.concurrent.thread +import org.slf4j.Logger +import org.slf4j.LoggerFactory class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() { + private var log: Logger = LoggerFactory.getLogger(AnalyseFragment::class.java) + private lateinit var analyseViewModel: AnalyseViewModel private val filesViewModel: FilesViewModel by activityViewModels() @@ -483,9 +490,7 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() { unusedAppsPreview.visibility = View.VISIBLE if (!isUsageStatsPermissionGranted()) { unusedAppsPreview.loadRequireElevatedPermission({ - val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) - intent.data = Uri.parse("package:${requireActivity().packageName}") - startActivity(intent) + launchUsageAccessScreen() }, ::usageStatsPermissionReload) } else { filesViewModel.getUnusedApps().observe(viewLifecycleOwner) { @@ -508,14 +513,10 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() { leastUsedAppsPreview.visibility = View.VISIBLE if (!isUsageStatsPermissionGranted()) { mostUsedAppsPreview.loadRequireElevatedPermission({ - val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) - intent.data = Uri.parse("package:${requireActivity().packageName}") - startActivity(intent) + launchUsageAccessScreen() }, ::usageStatsPermissionReload) leastUsedAppsPreview.loadRequireElevatedPermission({ - val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) - intent.data = Uri.parse("package:${requireActivity().packageName}") - startActivity(intent) + launchUsageAccessScreen() }, ::usageStatsPermissionReload) } else { filesViewModel.getMostUsedApps().observe(viewLifecycleOwner) { @@ -554,9 +555,7 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() { !isUsageStatsPermissionGranted() ) { networkIntensiveAppsPreview.loadRequireElevatedPermission({ - val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) - intent.data = Uri.parse("package:${requireActivity().packageName}") - startActivity(intent) + launchUsageAccessScreen() }, ::usageStatsPermissionReload) } else { filesViewModel.getNetworkIntensiveApps().observe(viewLifecycleOwner) { @@ -617,8 +616,7 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() { // Starting with version O, the PACKAGE_USAGE_STATS permission is necessary to query // the size of other apps largeSizeDiffAppsPreview.loadRequireElevatedPermission({ - val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) - startActivity(intent) + launchUsageAccessScreen() }, ::usageStatsPermissionReload) } else { filesViewModel.getLargeSizeDiffApps() @@ -1084,4 +1082,16 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() { } } } + + private fun launchUsageAccessScreen() { + try { + val intent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) + intent.data = Uri.parse("package:${requireActivity().packageName}") + startActivity(intent) + } catch (anfe: ActivityNotFoundException) { + log.warn("usage access activity not found", anfe) + requireContext().showToastInCenter(getString(R.string.grantfailed)) + } + + } } diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/AudiosListFragment.kt b/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/AudiosListFragment.kt index 1bdd8f5c..b2b397db 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/AudiosListFragment.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/AudiosListFragment.kt @@ -579,14 +579,16 @@ class AudiosListFragment : AbstractMediaInfoListFragment(), IAudioPlayerInterfac val selectedSongList = getMediaFileAdapter()?.checkItemsList if (selectedSongList?.size == 1) { selectedSongList[0].mediaFileInfo?.getContentUri(requireContext())?.let { it1 -> - audioPlaybackServiceConnection - .getAudioServiceInstance()?.insertPlayNextSong( - it1 - ) - Toast.makeText( - requireContext(), R.string.play_next_success, - Toast.LENGTH_LONG - ).show() + if (::audioPlaybackServiceConnection.isInitialized) { + audioPlaybackServiceConnection + .getAudioServiceInstance()?.insertPlayNextSong( + it1 + ) + Toast.makeText( + requireContext(), R.string.play_next_success, + Toast.LENGTH_LONG + ).show() + } } } hideActionBar() diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/ui/transfer/TransferFragment.kt b/app/src/main/java/com/amaze/fileutilities/home_page/ui/transfer/TransferFragment.kt index 5008c177..7df9c3dd 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/ui/transfer/TransferFragment.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/ui/transfer/TransferFragment.kt @@ -20,6 +20,7 @@ package com.amaze.fileutilities.home_page.ui.transfer +import android.content.ActivityNotFoundException import android.content.Intent import android.net.wifi.WifiManager import android.net.wifi.WpsInfo @@ -100,8 +101,13 @@ class TransferFragment : Fragment(), WifiP2pManager.ConnectionInfoListener, Peer ) if (!wifiManager.isWifiEnabled) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - val intent = Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY) - mainActivity!!.startActivity(intent) + try { + val intent = Intent(Settings.Panel.ACTION_INTERNET_CONNECTIVITY) + mainActivity!!.startActivity(intent) + } catch (anfe: ActivityNotFoundException) { + log.warn("failed to find internet connectivity panel", anfe) + requireContext().showToastInCenter(getString(R.string.grantfailed)) + } } else { wifiManager.isWifiEnabled = true } diff --git a/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt b/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt index d09d2197..65512e4d 100644 --- a/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt +++ b/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt @@ -1347,9 +1347,15 @@ class Utils { val pwrm = context.applicationContext.getSystemService(POWER_SERVICE) as PowerManager val name = context.applicationContext.packageName if (!pwrm.isIgnoringBatteryOptimizations(name)) { - intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS - intent.data = Uri.parse("package:$name") - context.startActivity(intent) + try { + intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS + intent.data = Uri.parse("package:$name") + context.startActivity(intent) + } catch (anfe: ActivityNotFoundException) { + log.warn("failed to find ignore battery optimizations screen", anfe) + context.showToastInCenter(context.getString(R.string.grantfailed)) + } + } }