Skip to content

Commit

Permalink
Merge pull request #125 from TeamAmaze/feature
Browse files Browse the repository at this point in the history
Trash bin fixes and bump version
  • Loading branch information
VishalNehra authored Aug 29, 2023
2 parents 28c2127 + 22fd6d6 commit 18bfc26
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 84 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ android {
minSdk 21
targetSdk 32

Integer sudoVersionCode = 27
String versionNameText = "1.87"
Integer sudoVersionCode = 28
String versionNameText = "1.88"

String[] abiFilterList = property("abiFilters").toString().split(';')
Integer minorVersion = 0
Expand Down Expand Up @@ -194,7 +194,7 @@ android {
// track.set("internal")
track.set("production")
userFraction.set(1.0d)
updatePriority.set(3)
updatePriority.set(4)
releaseStatus.set(com.github.triplet.gradle.androidpublisher.ReleaseStatus.COMPLETED)
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ dependencies {
implementation 'org.zwobble.mammoth:mammoth:1.4.2'
implementation 'me.zhanghai.android.fastscroll:library:1.1.8'
implementation "ch.acra:acra-core:5.7.0"
implementation 'com.github.TeamAmaze:AmazeTrashBin:1.0.5'
implementation 'com.github.TeamAmaze:AmazeTrashBin:1.0.7'

// https://mvnrepository.com/artifact/com.drewnoakes/metadata-extractor
implementation group: 'com.drewnoakes', name: 'metadata-extractor', version: '2.16.0'
Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
-keep class com.google.** { *; }
-keep class org.opencv.** { *; }
-keep class com.artifex.mupdf.** { *;}
-keep class com.amaze.trashbin.** { *; }

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class MainActivity :
override fun onPause() {
super.onPause()
UpdateChecker.unregisterListener()
getFilesModel().resetTrashBinConfig()
}

override fun getTransferFragment(): TransferFragment? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
setupDeletePermanentlyButton(toDelete) {
// reset interal storage stats so that we recalculate storage remaining
filesViewModel.internalStorageStatsLiveData = null
filesViewModel.trashBinFilesLiveData = null
filesViewModel.resetTrashBinConfig()
deletedCallback.invoke()

// deletion complete, no need to check analysis data to remove
Expand All @@ -715,7 +715,7 @@ class AnalyseFragment : AbstractMediaFileInfoOperationsFragment() {
setupDeleteButton(toDelete) {
// reset interal storage stats so that we recalculate storage remaining
filesViewModel.internalStorageStatsLiveData = null
filesViewModel.trashBinFilesLiveData = null
filesViewModel.resetTrashBinConfig()
deletedCallback.invoke()

// deletion complete, no need to check analysis data to remove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ import com.amaze.fileutilities.utilis.log
import com.amaze.fileutilities.utilis.share.ShareAdapter
import com.amaze.fileutilities.utilis.share.getShareIntents
import com.amaze.trashbin.DeletePermanentlyCallback
import com.amaze.trashbin.ListTrashBinFilesCallback
import com.amaze.trashbin.MoveFilesCallback
import com.amaze.trashbin.TrashBin
import com.amaze.trashbin.TrashBinConfig
import com.amaze.trashbin.TrashBinFile
import id.zelory.compressor.Compressor
import id.zelory.compressor.constraint.destination
import id.zelory.compressor.constraint.format
Expand Down Expand Up @@ -174,7 +172,7 @@ class FilesViewModel(val applicationContext: Application) :
PackageInfo?>>?> = AtomicReference()

var internalStorageStatsLiveData: MutableLiveData<StorageSummary?>? = null
var trashBin: TrashBin? = null
private var trashBin: TrashBin? = null

fun internalStorageStats(): LiveData<StorageSummary?> {
if (internalStorageStatsLiveData == null) {
Expand Down Expand Up @@ -1029,18 +1027,18 @@ class FilesViewModel(val applicationContext: Application) :
)
}
}

fun deleteMediaFiles(mediaFileInfoList: List<MediaFileInfo>): LiveData<Pair<Int, Int>> {
return liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) {
val deleteMediaFilesLiveData: MutableLiveData<Pair<Int, Int>> = MutableLiveData()
var successProcessedPair = Pair(0, 0)
deleteMediaFilesLiveData.value = successProcessedPair
viewModelScope.launch(Dispatchers.IO) {
log.info("Deleting media files $mediaFileInfoList")
var successProcessedPair = Pair(0, 0)

val trashBinFilesList = mediaFileInfoList.map { it.toTrashBinFile() }

getTrashBinInstance().deletePermanently(
trashBinFilesList,
object : DeletePermanentlyCallback {
override suspend fun invoke(deletePath: String): Boolean {
override fun invoke(deletePath: String): Boolean {
val mediaFileInfo = mediaFileInfoList.find {
it.path == deletePath
}
Expand Down Expand Up @@ -1079,13 +1077,14 @@ class FilesViewModel(val applicationContext: Application) :
mediaFileInfoList.size
)
}
emit(successProcessedPair)
deleteMediaFilesLiveData.postValue(successProcessedPair)
return true
}
},
true
)
}
return deleteMediaFilesLiveData
}

/**
Expand Down Expand Up @@ -1185,7 +1184,7 @@ class FilesViewModel(val applicationContext: Application) :
onCompleteCallback: (Triple<Int, Long, MediaFileInfo?>) -> (Unit)
) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
log.warn("compressing video failes not supported in version lower than N")
log.warn("compressing video failed not supported in version lower than N")
return
}
var successProcessedPair = Triple<Int, Long, MediaFileInfo?>(0, 0L, null)
Expand Down Expand Up @@ -1296,14 +1295,16 @@ class FilesViewModel(val applicationContext: Application) :
}

fun moveToTrashBin(mediaFileInfoList: List<MediaFileInfo>): LiveData<Pair<Int, Int>> {
return liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) {
val moveToTrashLiveData: MutableLiveData<Pair<Int, Int>> = MutableLiveData()
var successProcessedPair = Pair(0, 0)
moveToTrashLiveData.value = successProcessedPair
viewModelScope.launch(Dispatchers.IO) {
log.info("Moving media files to bin $mediaFileInfoList")
var successProcessedPair = Pair(0, 0)
val trashBinFilesList = mediaFileInfoList.map { it.toTrashBinFile() }
getTrashBinInstance().moveToBin(
trashBinFilesList, true,
object : MoveFilesCallback {
override suspend fun invoke(
override fun invoke(
originalFilePath: String,
trashBinDestination: String
): Boolean {
Expand All @@ -1314,7 +1315,7 @@ class FilesViewModel(val applicationContext: Application) :
successProcessedPair.first,
successProcessedPair.second + 1
)
emit(successProcessedPair)
moveToTrashLiveData.postValue(successProcessedPair)
return false
} else {
successProcessedPair = successProcessedPair.copy(
Expand All @@ -1329,22 +1330,23 @@ class FilesViewModel(val applicationContext: Application) :
uri,
applicationContext
)
emit(successProcessedPair)
moveToTrashLiveData.postValue(successProcessedPair)
// return@moveToBin true
return true
}
}
}
)
}
return moveToTrashLiveData
}

private suspend fun moveToBinLightWeight(mediaFileInfoList: List<MediaFileInfo>) {
private fun moveToBinLightWeight(mediaFileInfoList: List<MediaFileInfo>) {
val trashBinFilesList = mediaFileInfoList.map { it.toTrashBinFile() }
getTrashBinInstance().moveToBin(
trashBinFilesList, true,
object : MoveFilesCallback {
override suspend fun invoke(
override fun invoke(
originalFilePath: String,
trashBinDestination: String
): Boolean {
Expand All @@ -1368,22 +1370,24 @@ class FilesViewModel(val applicationContext: Application) :
}

fun restoreFromBin(mediaFileInfoList: List<MediaFileInfo>): LiveData<Pair<Int, Int>> {
return liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) {
val restoreFromTrashLiveData: MutableLiveData<Pair<Int, Int>> = MutableLiveData()
var successProcessedPair = Pair(0, 0)
restoreFromTrashLiveData.value = successProcessedPair
viewModelScope.launch(Dispatchers.IO) {
log.info("Moving media files to bin $mediaFileInfoList")
var successProcessedPair = Pair(0, 0)
val trashBinFilesList = mediaFileInfoList.map { it.toTrashBinFile() }
getTrashBinInstance().restore(
trashBinFilesList, true,
object : MoveFilesCallback {
override suspend fun invoke(source: String, dest: String): Boolean {
override fun invoke(source: String, dest: String): Boolean {
val sourceFile = File(source)
val destFile = File(dest)
if (!sourceFile.renameTo(destFile)) {
successProcessedPair = successProcessedPair.copy(
successProcessedPair.first,
successProcessedPair.second + 1
)
emit(successProcessedPair)
restoreFromTrashLiveData.postValue(successProcessedPair)
return false
} else {
successProcessedPair = successProcessedPair.copy(
Expand All @@ -1398,13 +1402,14 @@ class FilesViewModel(val applicationContext: Application) :
uri,
applicationContext
)
emit(successProcessedPair)
restoreFromTrashLiveData.postValue(successProcessedPair)
return true
}
}
}
)
}
return restoreFromTrashLiveData
}

fun getMediaFileListSize(mediaFileInfoList: List<MediaFileInfo>): LiveData<Long> {
Expand Down Expand Up @@ -1647,6 +1652,12 @@ class FilesViewModel(val applicationContext: Application) :
return networkIntensiveAppsLiveData!!
}

fun resetTrashBinConfig() {
trashBinConfig = null
trashBin = null
trashBinFilesLiveData = null
}

private fun processNetworkIntensiveApps(packageManager: PackageManager) {
viewModelScope.launch(Dispatchers.IO) {
loadAllInstalledApps(packageManager)
Expand Down Expand Up @@ -2015,7 +2026,7 @@ class FilesViewModel(val applicationContext: Application) :
}
allMediaFilesPair?.filter {
it.title.startsWith(".")
}?.sortedBy { -1 * it.longSize }?.map {
}?.sortedByDescending { it.longSize }?.map {
it.extraInfo?.mediaType = MediaFileInfo.MEDIA_TYPE_UNKNOWN
it
}?.let {
Expand Down Expand Up @@ -2189,17 +2200,14 @@ class FilesViewModel(val applicationContext: Application) :
trashBin = TrashBin(
getTrashbinConfig(),
object : DeletePermanentlyCallback {
override suspend fun invoke(deletePath: String): Boolean {
FileUtils.deleteFileByPath(applicationContext, deletePath)
override fun invoke(deletePath: String): Boolean {
viewModelScope.launch(Dispatchers.IO) {
FileUtils.deleteFileByPath(applicationContext, deletePath)
}
return true
}
},
object : ListTrashBinFilesCallback {
override suspend fun invoke(parentTrashBinPath: String): List<TrashBinFile> {
// do nothing
return emptyList()
}
}
null
)
}
return trashBin!!
Expand Down Expand Up @@ -2306,54 +2314,61 @@ class FilesViewModel(val applicationContext: Application) :

private fun loadAllInstalledApps(packageManager: PackageManager) {
if (allApps.get() == null) {
val apps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
allApps.set(
apps.map {
val info: PackageInfo? = try {
packageManager.getPackageInfo(
it.packageName,
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
PackageManager.GET_SIGNATURES
else PackageManager.GET_SIGNING_CERTIFICATES
)
} catch (e: PackageManager.NameNotFoundException) {
log.warn(
"failed to find package name {} while loading apps list",
it.packageName,
e
)
null
}
Pair(it, info)
}.filter {
val androidInfo: PackageInfo?
try {
androidInfo =
try {
packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
} catch (e: Exception) {
log.warn("failed to load all installed applications", e)
null
}?.let {
apps ->
allApps.set(
apps.map {
val info: PackageInfo? = try {
packageManager.getPackageInfo(
"android",
it.packageName,
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
PackageManager.GET_SIGNATURES
else PackageManager.GET_SIGNING_CERTIFICATES
)
!Utils.isAppInSystemPartition(it.first) && (
it.second == null ||
(
!Utils.isSignedBySystem(it.second, androidInfo) &&
!it.second!!.packageName
.equals(applicationContext.packageName)
)
} catch (e: PackageManager.NameNotFoundException) {
log.warn(
"failed to find package name {} while loading apps list",
it.packageName,
e
)
} catch (e: PackageManager.NameNotFoundException) {
log.warn(
"failed to find package name {} while loading apps list",
it.first.packageName,
e
)
true
null
}
Pair(it, info)
}.filter {
val androidInfo: PackageInfo?
try {
androidInfo =
packageManager.getPackageInfo(
"android",
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
PackageManager.GET_SIGNATURES
else PackageManager.GET_SIGNING_CERTIFICATES
)
!Utils.isAppInSystemPartition(it.first) && (
it.second == null ||
(
!Utils.isSignedBySystem(it.second, androidInfo) &&
!it.second!!.packageName
.equals(applicationContext.packageName)
)
)
} catch (e: PackageManager.NameNotFoundException) {
log.warn(
"failed to find package name {} while loading apps list",
it.first.packageName,
e
)
true
}
}
}
)
insertInstalledApps()
)
insertInstalledApps()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class ImageViewerFragment : AbstractMediaFragment() {

// reset interal storage stats so that we recalculate storage remaining
filesViewModel.internalStorageStatsLiveData = null
filesViewModel.trashBinFilesLiveData = null
filesViewModel.resetTrashBinConfig()

// deletion complete, no need to check analysis data to remove
// as it will get deleted lazily while loading analysis lists
Expand Down
1 change: 1 addition & 0 deletions app/src/main/play/release-notes/en-US/production.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Changelog:
- Minor fixes in trash bin
- Add support for trash bin (recycle bin)
- Add support for images and videos compression
- Improve performance
Expand Down
Loading

0 comments on commit 18bfc26

Please sign in to comment.