Merge pull request #1 from SimpleMobileTools/master

merge
This commit is contained in:
fiepi 2017-05-28 20:01:00 -05:00 committed by GitHub
commit 742a17582e
8 changed files with 87 additions and 81 deletions

View file

@ -32,7 +32,7 @@ android {
} }
dependencies { dependencies {
compile 'com.simplemobiletools:commons:2.18.5' compile 'com.simplemobiletools:commons:2.18.8'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View file

@ -127,8 +127,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.removeCallbacksAndMessages(null)
} }
override fun onStop() { override fun onDestroy() {
super.onStop() super.onDestroy()
config.temporarilyShowHidden = false config.temporarilyShowHidden = false
} }
@ -342,8 +342,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
private fun storeDirectories() { private fun storeDirectories() {
val directories = Gson().toJson(mDirs) if (!config.temporarilyShowHidden) {
config.directories = directories val directories = Gson().toJson(mDirs)
config.directories = directories
}
} }
private fun setupAdapter() { private fun setupAdapter() {

View file

@ -92,8 +92,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mLastMediaHandler.removeCallbacksAndMessages(null) mLastMediaHandler.removeCallbacksAndMessages(null)
} }
override fun onStop() { override fun onDestroy() {
super.onStop() super.onDestroy()
config.temporarilyShowHidden = false config.temporarilyShowHidden = false
} }
@ -399,9 +399,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun storeFolder() { private fun storeFolder() {
val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size)) if (!config.temporarilyShowHidden) {
val json = Gson().toJson(subList) val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size))
config.saveFolderMedia(mPath, json) val json = Gson().toJson(subList)
config.saveFolderMedia(mPath, json)
}
} }
override fun deleteFiles(files: ArrayList<File>) { override fun deleteFiles(files: ArrayList<File>) {

View file

@ -145,7 +145,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
fun checkHideBtnVisibility(menu: Menu) { fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0 var hiddenCnt = 0
var unhiddenCnt = 0 var unhiddenCnt = 0
selectedPositions.map { dirs[it].path }.forEach { selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach {
if (File(it).containsNoMedia()) if (File(it).containsNoMedia())
hiddenCnt++ hiddenCnt++
else else
@ -160,7 +160,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
val pinnedFolders = config.pinnedFolders val pinnedFolders = config.pinnedFolders
var pinnedCnt = 0 var pinnedCnt = 0
var unpinnedCnt = 0 var unpinnedCnt = 0
selectedPositions.map { dirs[it].path }.forEach { selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach {
if (pinnedFolders.contains(it)) if (pinnedFolders.contains(it))
pinnedCnt++ pinnedCnt++
else else

View file

@ -140,7 +140,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
fun checkHideBtnVisibility(menu: Menu) { fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0 var hiddenCnt = 0
var unhiddenCnt = 0 var unhiddenCnt = 0
selectedPositions.map { media[it] }.forEach { selectedPositions.map { media.getOrNull(it) }.filterNotNull().forEach {
if (it.name.startsWith('.')) if (it.name.startsWith('.'))
hiddenCnt++ hiddenCnt++
else else

View file

@ -58,9 +58,7 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%") val selectionArgs = if (curPath.isEmpty()) null else arrayOf("$curPath/%", "$curPath/%/%")
val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath)) val cur = contentResolver.query(uri, projection, selection, selectionArgs, getSortingForFolder(curPath))
cur.use { cur -> return parseCursor(this, cur, isPickImage, isPickVideo, curPath)
return parseCursor(this, cur, isPickImage, isPickVideo, curPath)
}
} }
private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isPickVideo: Boolean, curPath: String): ArrayList<Medium> { private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isPickVideo: Boolean, curPath: String): ArrayList<Medium> {
@ -69,78 +67,80 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
val showMedia = config.showMedia val showMedia = config.showMedia
val showHidden = config.shouldShowHidden val showHidden = config.shouldShowHidden
if (cur.moveToFirst()) { cur.use { cur ->
var filename: String if (cur.moveToFirst()) {
var path: String var filename: String
var dateTaken: Long var path: String
var dateModified: Long var dateTaken: Long
var size: Long var dateModified: Long
var isImage: Boolean var size: Long
var isVideo: Boolean var isImage: Boolean
val excludedFolders = config.excludedFolders var isVideo: Boolean
val noMediaFolders = context.getNoMediaFolders() val excludedFolders = config.excludedFolders
val noMediaFolders = context.getNoMediaFolders()
do { do {
try { try {
path = cur.getStringValue(MediaStore.Images.Media.DATA) path = cur.getStringValue(MediaStore.Images.Media.DATA)
size = cur.getLongValue(MediaStore.Images.Media.SIZE) size = cur.getLongValue(MediaStore.Images.Media.SIZE)
if (size == 0L) { if (size == 0L) {
size = File(path).length() size = File(path).length()
}
if (size <= 0L) {
continue
}
filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
if (filename.isEmpty())
filename = path.getFilenameFromPath()
isImage = filename.isImageFast() || filename.isGif()
isVideo = if (isImage) false else filename.isVideoFast()
if (!isImage && !isVideo)
continue
if (isVideo && (isPickImage || showMedia == IMAGES))
continue
if (isImage && (isPickVideo || showMedia == VIDEOS))
continue
if (!showHidden && filename.startsWith('.'))
continue
var isExcluded = false
excludedFolders.forEach {
if (path.startsWith(it)) {
isExcluded = true
} }
}
if (!isExcluded && !showHidden) { if (size <= 0L) {
noMediaFolders.forEach { continue
}
filename = cur.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
if (filename.isEmpty())
filename = path.getFilenameFromPath()
isImage = filename.isImageFast() || filename.isGif()
isVideo = if (isImage) false else filename.isVideoFast()
if (!isImage && !isVideo)
continue
if (isVideo && (isPickImage || showMedia == IMAGES))
continue
if (isImage && (isPickVideo || showMedia == VIDEOS))
continue
if (!showHidden && filename.startsWith('.'))
continue
var isExcluded = false
excludedFolders.forEach {
if (path.startsWith(it)) { if (path.startsWith(it)) {
isExcluded = true isExcluded = true
} }
} }
}
if (!isExcluded && !showHidden && path.contains("/.")) { if (!isExcluded && !showHidden) {
isExcluded = true noMediaFolders.forEach {
} if (path.startsWith(it)) {
isExcluded = true
}
}
}
if (!isExcluded) { if (!isExcluded && !showHidden && path.contains("/.")) {
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) isExcluded = true
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L }
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size) if (!isExcluded) {
curMedia.add(medium) dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
curMedia.add(medium)
}
} catch (e: Exception) {
continue
} }
} catch (e: Exception) { } while (cur.moveToNext())
continue }
}
} while (cur.moveToNext())
} }
Medium.sorting = config.getFileSorting(curPath) Medium.sorting = config.getFileSorting(curPath)

View file

@ -306,8 +306,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
return return
initMediaPlayer() initMediaPlayer()
if (mMediaPlayer == null) if (mMediaPlayer == null) {
activity.toast(R.string.unknown_error_occurred) activity.toast(R.string.unknown_error_occurred)
return
}
val videoProportion = mMediaPlayer!!.videoWidth.toFloat() / mMediaPlayer!!.videoHeight.toFloat() val videoProportion = mMediaPlayer!!.videoWidth.toFloat() / mMediaPlayer!!.videoHeight.toFloat()
val display = activity.windowManager.defaultDisplay val display = activity.windowManager.defaultDisplay

View file

@ -74,7 +74,7 @@
<string name="setting_wallpaper">A definir como fundo de ecrã&#8230;</string> <string name="setting_wallpaper">A definir como fundo de ecrã&#8230;</string>
<string name="wallpaper_set_successfully">Fundo definido com sucesso</string> <string name="wallpaper_set_successfully">Fundo definido com sucesso</string>
<string name="portrait_aspect_ratio">Proporção na vertical</string> <string name="portrait_aspect_ratio">Proporção na vertical</string>
<string name="landscape_aspect_ratio">proporção na horizontal</string> <string name="landscape_aspect_ratio">Proporção na horizontal</string>
<!-- Settings --> <!-- Settings -->
<string name="show_hidden_media">Mostrar pastas ocultas</string> <string name="show_hidden_media">Mostrar pastas ocultas</string>
@ -83,8 +83,8 @@
<string name="show_media">Mostrar multimédia</string> <string name="show_media">Mostrar multimédia</string>
<string name="images">Apenas imagens</string> <string name="images">Apenas imagens</string>
<string name="videos">Apenas vídeos</string> <string name="videos">Apenas vídeos</string>
<string name="gifs">Gifs only</string> <string name="gifs">Apenas gifs</string>
<string name="images_videos_gifs">Images, videos, gifs</string> <string name="images_videos_gifs">Imagens, vídeos e gifs</string>
<string name="images_and_videos">Imagens e vídeos</string> <string name="images_and_videos">Imagens e vídeos</string>
<string name="loop_videos">Vídeos em ciclo</string> <string name="loop_videos">Vídeos em ciclo</string>
<string name="animate_gifs">Animação de gifs nas miniaturas</string> <string name="animate_gifs">Animação de gifs nas miniaturas</string>