Skip to content

Commit

Permalink
Merge pull request #105 from TeamAmaze/feature
Browse files Browse the repository at this point in the history
Fix pdf crash; improve image viewer viewpager
  • Loading branch information
VishalNehra committed Apr 16, 2023
2 parents 5e8fc9b + 5977659 commit 4be9bf0
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 254 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Expand Up @@ -59,8 +59,8 @@ android {
applicationId "com.amaze.fileutilities"
minSdk 21
targetSdk 31
versionCode 78
versionName "1.78"
versionCode 80
versionName "1.80"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion app/proguard-rules.pro
Expand Up @@ -32,8 +32,8 @@
-keep class com.amaze.fileutilities.cast.CastOptionsProvider { *; }
-keep class android.support.** { *; }
-keep class com.google.** { *; }
-keep class com.folioreader.** { *; }
-keep class org.opencv.** { *; }
-keep class com.artifex.mupdf.** { *;}

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.amaze.fileutilities">

<uses-sdk tools:overrideLibrary="com.folioreader, linc.com.amplituda,
me.zhanghai.android.fastscroll, org.opencv, com.mikepenz.aboutlibraries" />
<uses-sdk tools:overrideLibrary="linc.com.amplituda, me.zhanghai.android.fastscroll,
org.opencv, com.mikepenz.aboutlibraries" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
Expand Down
Expand Up @@ -74,10 +74,10 @@ class AudioPlayerInterfaceHandlerViewModel : ViewModel() {
}*/
if (siblingsLiveData.value.isNullOrEmpty()) {
val uriList = ArrayList<Uri>()
uri.getSiblingUriFiles().run {
uri.getSiblingUriFiles { it.isAudioMimeType() }.run {
if (this != null) {
uriList.addAll(
this.filter { it.isAudioMimeType() }.asReversed()
this.asReversed()
)
} else {
uriList.add(uri)
Expand Down
Expand Up @@ -86,7 +86,7 @@ class ImageViewerActivity : PermissionsActivity() {
}
}
}
viewBinding.pager.currentItem = position
viewBinding.pager.setCurrentItem(position, false)
}
}
}
Expand Down
Expand Up @@ -39,12 +39,11 @@ class ImageViewerViewModel : ViewModel() {
}*/
siblingImagesLiveData.postValue(null)
if (siblingImagesLiveData.value.isNullOrEmpty()) {
imageModel.uri.getSiblingUriFiles().run {
imageModel.uri.getSiblingUriFiles { it.isImageMimeType() }.run {
val imageModelList = ArrayList<LocalImageModel>()
if (this != null) {
imageModelList.addAll(
this.filter { it.isImageMimeType() }
.map { LocalImageModel(it, "") }.asReversed()
this.map { LocalImageModel(it, "") }.asReversed()
)
} else {
imageModelList.add(imageModel)
Expand Down
65 changes: 46 additions & 19 deletions app/src/main/java/com/amaze/fileutilities/utilis/Extensions.kt
Expand Up @@ -71,7 +71,7 @@ import java.io.FileOutputStream

var log: Logger = LoggerFactory.getLogger(Utils::class.java)

fun Uri.getSiblingUriFiles(): ArrayList<Uri>? {
fun Uri.getSiblingUriFiles(filter: (File) -> Boolean): ArrayList<Uri>? {
try {
val currentPath = getFileFromUri()
currentPath?.let {
Expand All @@ -81,26 +81,23 @@ fun Uri.getSiblingUriFiles(): ArrayList<Uri>? {
if (parent != null) {
val filesList = parent.listFiles()
if (filesList != null) {
if (filesList.size < 500) {
parent.listFiles()?.sortBy { it.lastModified() }
parent.listFiles()?.run {
if (this.isNotEmpty()) {
siblings = ArrayList()
for (currentSibling in this) {
siblings!!.add(
Uri.parse(
if (!currentSibling.path
.startsWith("/")
)
"/${currentSibling.path}"
else currentSibling.path
)
val filteredFiles = filesList.filter(filter)
if (filteredFiles.size > 1000) {
siblings = arrayListOf(this)
} else {
siblings = ArrayList()
filteredFiles.sortedBy { it.lastModified() }.forEach {
currentSibling ->
siblings!!.add(
Uri.parse(
if (!currentSibling.path
.startsWith("/")
)
}
}
"/${currentSibling.path}"
else currentSibling.path
)
)
}
} else {
siblings = arrayListOf(this)
}
} else {
siblings = arrayListOf(this)
Expand Down Expand Up @@ -254,6 +251,19 @@ fun Uri.isImageMimeType(): Boolean {
this.path?.endsWith("webp")!!
}

fun File.isImageMimeType(): Boolean {
return this.path.endsWith("jpg") ||
this.path.endsWith("jpe") ||
this.path.endsWith("jpeg") ||
this.path.endsWith("jfif") ||
this.path.endsWith("pjpeg") ||
this.path.endsWith("pjp") ||
this.path.endsWith("gif") ||
this.path.endsWith("png") ||
this.path.endsWith("svg") ||
this.path.endsWith("webp")
}

fun Uri.isVideoMimeType(): Boolean {
return this.path?.endsWith("mp4")!! ||
this.path?.endsWith("mkv")!! ||
Expand Down Expand Up @@ -281,6 +291,23 @@ fun Uri.isAudioMimeType(): Boolean {
this.path?.endsWith("opus")!!
}

fun File.isAudioMimeType(): Boolean {
return this.path.endsWith("mp3") ||
this.path.endsWith("wav") ||
this.path.endsWith("ogg") ||
this.path.endsWith("mp4") ||
this.path.endsWith("m4a") ||
this.path.endsWith("fmp4") ||
this.path.endsWith("flv") ||
this.path.endsWith("flac") ||
this.path.endsWith("amr") ||
this.path.endsWith("aac") ||
this.path.endsWith("ac3") ||
this.path.endsWith("eac3") ||
this.path.endsWith("dca") ||
this.path.endsWith("opus")
}

val Int.dp get() = this / (
Resources.getSystem().displayMetrics.densityDpi.toFloat() /
DisplayMetrics.DENSITY_DEFAULT
Expand Down
1 change: 1 addition & 0 deletions app/src/main/play/release-notes/en-US/production.txt
Expand Up @@ -3,4 +3,5 @@ Changelog:
- Add support for .cbz , .fb2 and .mobi
- Add support to search in pdf
- Improve performance
- Update translations
- Other bugfixes

0 comments on commit 4be9bf0

Please sign in to comment.