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 {
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.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

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

View File

@ -92,8 +92,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mLastMediaHandler.removeCallbacksAndMessages(null)
}
override fun onStop() {
super.onStop()
override fun onDestroy() {
super.onDestroy()
config.temporarilyShowHidden = false
}
@ -399,9 +399,11 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
private fun storeFolder() {
val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size))
val json = Gson().toJson(subList)
config.saveFolderMedia(mPath, json)
if (!config.temporarilyShowHidden) {
val subList = mMedia.subList(0, Math.min(SAVE_MEDIA_CNT, mMedia.size))
val json = Gson().toJson(subList)
config.saveFolderMedia(mPath, json)
}
}
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) {
var hiddenCnt = 0
var unhiddenCnt = 0
selectedPositions.map { dirs[it].path }.forEach {
selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach {
if (File(it).containsNoMedia())
hiddenCnt++
else
@ -160,7 +160,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
val pinnedFolders = config.pinnedFolders
var pinnedCnt = 0
var unpinnedCnt = 0
selectedPositions.map { dirs[it].path }.forEach {
selectedPositions.map { dirs.getOrNull(it)?.path }.filterNotNull().forEach {
if (pinnedFolders.contains(it))
pinnedCnt++
else

View File

@ -140,7 +140,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0
var unhiddenCnt = 0
selectedPositions.map { media[it] }.forEach {
selectedPositions.map { media.getOrNull(it) }.filterNotNull().forEach {
if (it.name.startsWith('.'))
hiddenCnt++
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 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> {
@ -69,78 +67,80 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
val showMedia = config.showMedia
val showHidden = config.shouldShowHidden
if (cur.moveToFirst()) {
var filename: String
var path: String
var dateTaken: Long
var dateModified: Long
var size: Long
var isImage: Boolean
var isVideo: Boolean
val excludedFolders = config.excludedFolders
val noMediaFolders = context.getNoMediaFolders()
cur.use { cur ->
if (cur.moveToFirst()) {
var filename: String
var path: String
var dateTaken: Long
var dateModified: Long
var size: Long
var isImage: Boolean
var isVideo: Boolean
val excludedFolders = config.excludedFolders
val noMediaFolders = context.getNoMediaFolders()
do {
try {
path = cur.getStringValue(MediaStore.Images.Media.DATA)
size = cur.getLongValue(MediaStore.Images.Media.SIZE)
if (size == 0L) {
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
do {
try {
path = cur.getStringValue(MediaStore.Images.Media.DATA)
size = cur.getLongValue(MediaStore.Images.Media.SIZE)
if (size == 0L) {
size = File(path).length()
}
}
if (!isExcluded && !showHidden) {
noMediaFolders.forEach {
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 && path.contains("/.")) {
isExcluded = true
}
if (!isExcluded && !showHidden) {
noMediaFolders.forEach {
if (path.startsWith(it)) {
isExcluded = true
}
}
}
if (!isExcluded) {
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
if (!isExcluded && !showHidden && path.contains("/.")) {
isExcluded = true
}
val medium = Medium(filename, path, isVideo, dateModified, dateTaken, size)
curMedia.add(medium)
if (!isExcluded) {
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) {
continue
}
} while (cur.moveToNext())
} while (cur.moveToNext())
}
}
Medium.sorting = config.getFileSorting(curPath)

View File

@ -306,8 +306,10 @@ class VideoFragment : ViewPagerFragment(), SurfaceHolder.Callback, SeekBar.OnSee
return
initMediaPlayer()
if (mMediaPlayer == null)
if (mMediaPlayer == null) {
activity.toast(R.string.unknown_error_occurred)
return
}
val videoProportion = mMediaPlayer!!.videoWidth.toFloat() / mMediaPlayer!!.videoHeight.toFloat()
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="wallpaper_set_successfully">Fundo definido com sucesso</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 -->
<string name="show_hidden_media">Mostrar pastas ocultas</string>
@ -83,8 +83,8 @@
<string name="show_media">Mostrar multimédia</string>
<string name="images">Apenas imagens</string>
<string name="videos">Apenas vídeos</string>
<string name="gifs">Gifs only</string>
<string name="images_videos_gifs">Images, videos, gifs</string>
<string name="gifs">Apenas 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="loop_videos">Vídeos em ciclo</string>
<string name="animate_gifs">Animação de gifs nas miniaturas</string>