Skip to content

Commit

Permalink
Merge pull request #100 from TeamAmaze/feature
Browse files Browse the repository at this point in the history
Add analysis to clear background processes; Fix uri file sharing issue; fix home screen fab
  • Loading branch information
VishalNehra committed Jan 9, 2023
2 parents 59355dc + 6439421 commit 0ad0f79
Show file tree
Hide file tree
Showing 51 changed files with 1,539 additions and 201 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ android {
applicationId "com.amaze.fileutilities"
minSdk 19
targetSdk 31
versionCode 75
versionName "1.75"
versionCode 76
versionName "1.76"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

<uses-feature
android:name="android.software.leanback"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class AudioPlayerDialogActivity : PermissionsActivity(), IAudioPlayerInterfaceHa
dialog.show()
} else {
dialog.dismiss()
audioUri.getFileFromUri()?.length()?.also {
audioUri.getFileFromUri(this)?.length()?.also {
if (it > AudioPlayerInterfaceHandlerViewModel.WAVEFORM_THRESHOLD_BYTES) {
viewModel.forceShowSeekbar = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ interface IAudioPlayerInterfaceHandler : OnPlaybackInfoUpdate, LifecycleOwner {
getContextWeakRef().get()?.let {
context ->
val file = progressHandler.audioPlaybackInfo
.audioModel.getUri().getFileFromUri()
.audioModel.getUri().getFileFromUri(context)
if (file != null) {
lifecycleScope.launch {
try {
Expand Down Expand Up @@ -502,7 +502,7 @@ interface IAudioPlayerInterfaceHandler : OnPlaybackInfoUpdate, LifecycleOwner {
context ->
if (context != null) {
val file = audioService?.getAudioProgressHandlerCallback()?.audioPlaybackInfo
?.audioModel?.getUri()?.getFileFromUri()
?.audioModel?.getUri()?.getFileFromUri(context)
if (file != null) {
lifecycleScope.launch {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data class LocalDocxModel(
}

override fun getName(context: Context): String {
uri.getFileFromUri()?.run {
uri.getFileFromUri(context)?.run {
return this.name
}
uri.path?.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class EpubViewerActivity : PermissionsActivity() {
"and mimetype $mimeType"
)
epubModel = LocalEpubModel(uri = epubUri, mimeType = mimeType)
val filePathFromUri = epubUri.getFileFromUri()
val filePathFromUri = epubUri.getFileFromUri(this)
if (filePathFromUri != null) {
val config: Config = Config()
.setAllowedDirection(Config.AllowedDirection.ONLY_HORIZONTAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.content.Intent
import android.content.SharedPreferences
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.provider.Settings
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -248,8 +249,12 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
junkFilesPreview.invalidateProgress(true, null)
junkFiles?.let {
junkFilesPreview.invalidateProgress(false, null)
junkFilesPreview.loadPreviews(junkFiles) {
cleanButtonClick(it) {
junkFilesPreview.loadSummaryTextPreview(
if (it.first.isEmpty())
null else it.second,
null
) {
cleanButtonClick(it.first) {
filesViewModel.junkFilesLiveData = null
thread {
installedAppsDao.deleteAll()
Expand Down Expand Up @@ -279,7 +284,10 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
analyseViewModel.getClutteredVideos(mediaFilePair.second)
.observe(viewLifecycleOwner) { clutteredVideosInfo ->
clutteredVideosInfo?.let {
clutteredVideoPreview.invalidateProgress(false, null)
clutteredVideoPreview.invalidateProgress(
false,
null
)
clutteredVideoPreview.loadPreviews(clutteredVideosInfo) {
cleanButtonClick(it) {
analyseViewModel.clutteredVideosLiveData = null
Expand All @@ -291,7 +299,10 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
.observe(viewLifecycleOwner) {
largeVideosList ->
largeVideosList?.let {
largeVideoPreview.invalidateProgress(false, null)
largeVideoPreview.invalidateProgress(
false,
null
)
largeVideoPreview.loadPreviews(largeVideosList) {
cleanButtonClick(it) {
analyseViewModel.largeVideosLiveData = null
Expand All @@ -308,7 +319,10 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
largeDownloads ->
largeDownloadPreview.invalidateProgress(true, null)
largeDownloads?.let {
largeDownloadPreview.invalidateProgress(false, null)
largeDownloadPreview.invalidateProgress(
false,
null
)
largeDownloadPreview.loadPreviews(largeDownloads) {
cleanButtonClick(it) {
filesViewModel.largeDownloadsLiveData = null
Expand Down Expand Up @@ -388,6 +402,32 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
}
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
memoryUsagePreview.visibility = View.VISIBLE
filesViewModel.getMemoryInfo().observe(viewLifecycleOwner) {
memoryUsage ->
memoryUsagePreview.invalidateProgress(true, null)
memoryUsage?.let {
memoryUsagePreview.invalidateProgress(false, null)
memoryUsagePreview.loadSummaryTextPreview(it, {
filesViewModel.memoryInfoLiveData = null
reloadFragment()
}, {
filesViewModel.killBackgroundProcesses(
requireContext()
.packageManager
) {
requireActivity().runOnUiThread {
requireContext()
.showToastOnBottom(getString(R.string.ram_usage_clear))
filesViewModel.memoryInfoLiveData = null
reloadFragment()
}
}
})
}
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
unusedAppsPreview.visibility = View.VISIBLE
if (!isUsageStatsPermissionGranted()) {
Expand Down Expand Up @@ -434,7 +474,10 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
mediaFileInfoList ->
mostUsedAppsPreview.invalidateProgress(true, null)
mediaFileInfoList?.let {
mostUsedAppsPreview.invalidateProgress(false, null)
mostUsedAppsPreview.invalidateProgress(
false,
null
)
mostUsedAppsPreview.loadPreviews(mediaFileInfoList) {
cleanButtonClick(it) {
filesViewModel.mostUsedAppsLiveData = null
Expand All @@ -446,7 +489,10 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
mediaFileInfoList ->
leastUsedAppsPreview.invalidateProgress(true, null)
mediaFileInfoList?.let {
leastUsedAppsPreview.invalidateProgress(false, null)
leastUsedAppsPreview.invalidateProgress(
false,
null
)
leastUsedAppsPreview.loadPreviews(mediaFileInfoList) {
cleanButtonClick(it) {
filesViewModel.leastUsedAppsLiveData = null
Expand Down Expand Up @@ -521,6 +567,12 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
}
}
}
if (analyseViewModel.fragmentScrollPosition != null) {
Handler().postDelayed({
analyseScrollView.scrollY = analyseViewModel.fragmentScrollPosition!!
analyseViewModel.fragmentScrollPosition = null
}, 1000)
}
}
return root
}
Expand Down Expand Up @@ -579,6 +631,7 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
}

private fun reloadFragment() {
analyseViewModel.fragmentScrollPosition = binding.analyseScrollView.scrollY
val navController = NavHostFragment.findNavController(this)
navController.popBackStack()
navController.navigate(R.id.navigation_analyse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AnalyseViewModel : ViewModel() {
var distractedImagesLiveData: MutableLiveData<ArrayList<MediaFileInfo>?>? = null
var selfieImagesLiveData: MutableLiveData<ArrayList<MediaFileInfo>?>? = null
var groupPicImagesLiveData: MutableLiveData<ArrayList<MediaFileInfo>?>? = null
var fragmentScrollPosition: Int? = null

fun getBlurImages(dao: BlurAnalysisDao): LiveData<ArrayList<MediaFileInfo>?> {
if (blurImagesLiveData == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.FrameLayout
import android.widget.HorizontalScrollView
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar
Expand Down Expand Up @@ -56,9 +57,14 @@ class AnalysisTypeView(context: Context, attrs: AttributeSet?) : LinearLayout(co
private val loadingHorizontalScroll: ProgressBar
private val cancelLoadingView: ImageView
private val requirePermissionsParent: LinearLayout
private val requirePermissionsTitle: TextView
private val refreshParent: LinearLayout
private val grantPermissionButton: Button
private val refreshButton: Button
private val requirePermissionScroll: HorizontalScrollView
private val summaryViewParent: LinearLayout
private val summaryTextView: TextView
private val summaryViewButton: Button
private var showPreview = false

companion object {
Expand All @@ -81,8 +87,14 @@ class AnalysisTypeView(context: Context, attrs: AttributeSet?) : LinearLayout(co
cancelLoadingView = loadingProgressParent.findViewById(R.id.cancel_loading_button)
loadingHorizontalScroll = imagesListScroll.findViewById(R.id.scroll_progress)
requirePermissionsParent = imagesListParent.findViewById(R.id.require_permission_parent)
requirePermissionsTitle = requirePermissionsParent
.findViewById(R.id.require_permission_title)
refreshParent = imagesListParent.findViewById(R.id.refresh_parent)
grantPermissionButton = requirePermissionsParent.findViewById(R.id.grant_button)
requirePermissionScroll = imagesListScroll.findViewById(R.id.require_permission_scroll)
summaryViewParent = imagesListScroll.findViewById(R.id.summary_view_parent)
summaryTextView = imagesListScroll.findViewById(R.id.summary_view_title)
summaryViewButton = imagesListScroll.findViewById(R.id.summary_view_button)
refreshButton = refreshParent.findViewById(R.id.refresh_button)

val a = context.obtainStyledAttributes(
Expand Down Expand Up @@ -179,6 +191,31 @@ class AnalysisTypeView(context: Context, attrs: AttributeSet?) : LinearLayout(co
}
}

fun loadSummaryTextPreview(
text: String?,
refreshCallback: (() -> Unit)?,
cleanButtonClick: () -> Unit
) {
if (text.isNullOrEmpty()) {
hideFade(300)
}
loadingHorizontalScroll.visibility = View.GONE
requirePermissionScroll.visibility = View.GONE
if (showPreview) {
summaryViewParent.visibility = View.VISIBLE
summaryTextView.text = text
if (refreshCallback != null) {
summaryViewButton.visibility = View.VISIBLE
summaryViewButton.setOnClickListener {
refreshCallback.invoke()
}
}
}
cleanButton.setOnClickListener {
cleanButtonClick.invoke()
}
}

private fun getImageView(mediaFileInfo: MediaFileInfo): ImageView {
val imageView = ImageView(context)
imageView.setOnClickListener {
Expand Down
Loading

0 comments on commit 0ad0f79

Please sign in to comment.