show an icon at the folder for OTG devices too

This commit is contained in:
tibbi 2018-04-24 13:15:41 +02:00
parent db2e0dc776
commit 85a0a69599
10 changed files with 30 additions and 15 deletions

View file

@ -47,7 +47,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.19.10'
implementation 'com.simplemobiletools:commons:3.19.11'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'it.sephiroth.android.exif:library:1.0.1'

View file

@ -676,7 +676,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified)
val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken)
val size = curMedia.sumByLong { it.size }
return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, isPathOnSD(path), mediaTypes)
return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes)
}
private fun setupAdapter(dirs: ArrayList<Directory>) {

View file

@ -19,10 +19,7 @@ import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
import com.simplemobiletools.gallery.dialogs.PickMediumDialog
import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.helpers.TYPE_GIFS
import com.simplemobiletools.gallery.helpers.TYPE_IMAGES
import com.simplemobiletools.gallery.helpers.TYPE_VIDEOS
import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST
import com.simplemobiletools.gallery.helpers.*
import com.simplemobiletools.gallery.models.AlbumCover
import com.simplemobiletools.gallery.models.Directory
import kotlinx.android.synthetic.main.directory_item_list.view.*
@ -420,7 +417,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
dir_pin.beVisibleIf(pinnedFolders.contains(directory.path))
dir_sd_card.beVisibleIf(directory.isOnSDCard)
dir_location.beVisibleIf(directory.location != LOCAITON_INTERNAL)
if (dir_location.isVisible()) {
dir_location.setImageResource(if (directory.location == LOCATION_SD) R.drawable.ic_sd_card else R.drawable.ic_usb)
}
photo_cnt.beVisibleIf(showMediaCount)
if (isListViewType) {
@ -428,7 +429,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
dir_path.setTextColor(textColor)
photo_cnt.setTextColor(textColor)
dir_pin.applyColorFilter(textColor)
dir_sd_card.applyColorFilter(textColor)
dir_location.applyColorFilter(textColor)
}
}
}

View file

@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.interfaces.MediumDao
import com.simplemobiletools.gallery.models.Directory
import com.simplemobiletools.gallery.models.Medium
@Database(entities = [(Directory::class), (Medium::class)], version = 1)
@Database(entities = [(Directory::class), (Medium::class)], version = 2)
abstract class GalleryDataBase : RoomDatabase() {
abstract fun DirectoryDao(): DirectoryDao
@ -22,7 +22,9 @@ abstract class GalleryDataBase : RoomDatabase() {
fun getInstance(context: Context): GalleryDataBase {
if (INSTANCE == null) {
synchronized(GalleryDataBase::class) {
INSTANCE = Room.databaseBuilder(context.applicationContext, GalleryDataBase::class.java, "gallery.db").build()
INSTANCE = Room.databaseBuilder(context.applicationContext, GalleryDataBase::class.java, "gallery.db")
.fallbackToDestructiveMigration()
.build()
}
}
return INSTANCE!!

View file

@ -215,13 +215,21 @@ fun Context.addTempFolderIfNeeded(dirs: ArrayList<Directory>): ArrayList<Directo
val directories = ArrayList<Directory>()
val tempFolderPath = config.tempFolderPath
if (tempFolderPath.isNotEmpty()) {
val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, isPathOnSD(tempFolderPath), 0)
val newFolder = Directory(null, tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L, getPathLocation(tempFolderPath), 0)
directories.add(newFolder)
}
directories.addAll(dirs)
return directories
}
fun Context.getPathLocation(path: String): Int {
return when {
isPathOnSD(path) -> LOCATION_SD
path.startsWith(OTG_PATH) -> LOCATION_OTG
else -> LOCAITON_INTERNAL
}
}
fun Context.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) {
val options = RequestOptions()
.signature(path.getFileSignature())

View file

@ -102,3 +102,7 @@ const val EXT_ALBUM = 1024
const val TYPE_IMAGES = 1
const val TYPE_VIDEOS = 2
const val TYPE_GIFS = 4
const val LOCAITON_INTERNAL = 1
const val LOCATION_SD = 2
const val LOCATION_OTG = 3

View file

@ -9,7 +9,7 @@ import com.simplemobiletools.gallery.models.Directory
@Dao
interface DirectoryDao {
@Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, is_on_sd_card, media_types FROM directories")
@Query("SELECT path, thumbnail, filename, media_count, last_modified, date_taken, size, location, media_types FROM directories")
fun getAll(): List<Directory>
@Insert(onConflict = REPLACE)

View file

@ -19,7 +19,7 @@ data class Directory(
@ColumnInfo(name = "last_modified") var modified: Long,
@ColumnInfo(name = "date_taken") var taken: Long,
@ColumnInfo(name = "size") var size: Long,
@ColumnInfo(name = "is_on_sd_card") val isOnSDCard: Boolean,
@ColumnInfo(name = "location") val location: Int,
@ColumnInfo(name = "media_types") var types: Int) : Serializable, Comparable<Directory> {
companion object {

View file

@ -82,7 +82,7 @@
</LinearLayout>
<ImageView
android:id="@+id/dir_sd_card"
android:id="@+id/dir_location"
android:layout_width="@dimen/sd_card_icon_size"
android:layout_height="@dimen/sd_card_icon_size"
android:layout_alignParentBottom="true"

View file

@ -76,7 +76,7 @@
android:paddingBottom="@dimen/tiny_margin">
<ImageView
android:id="@+id/dir_sd_card"
android:id="@+id/dir_location"
android:layout_width="@dimen/sd_card_icon_size"
android:layout_height="@dimen/sd_card_icon_size"
android:paddingBottom="@dimen/small_margin"