Skip to content

Commit

Permalink
Fix usage access permissions issues; fix audio list fragment crash; f…
Browse files Browse the repository at this point in the history
…ix percentage chart view crash
  • Loading branch information
VishalNehra committed Jul 14, 2024
1 parent 9e8746a commit f5d5d76
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}
}

Expand Down

0 comments on commit f5d5d76

Please sign in to comment.