store media parent paths too

This commit is contained in:
tibbi 2018-04-20 11:46:50 +02:00
parent ce4ee915bb
commit 73000aa611
10 changed files with 18 additions and 14 deletions

View File

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

View File

@ -90,7 +90,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
else -> TYPE_GIF else -> TYPE_GIF
} }
mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), 0, 0, file.length(), type) mMedium = Medium(null, getFilenameFromUri(mUri!!), mUri.toString(), mUri!!.path.getParentPath(), 0, 0, file.length(), type)
supportActionBar?.title = mMedium!!.name supportActionBar?.title = mMedium!!.name
bundle.putSerializable(MEDIUM, mMedium) bundle.putSerializable(MEDIUM, mMedium)

View File

@ -197,7 +197,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
showSystemUI() showSystemUI()
mDirectory = mPath.getParentPath().trimEnd('/') mDirectory = mPath.getParentPath()
if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) { if (mDirectory.startsWith(OTG_PATH.trimEnd('/'))) {
mDirectory += "/" mDirectory += "/"
} }

View File

@ -250,7 +250,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Medium>,
private fun updateStoredFolderItems() { private fun updateStoredFolderItems() {
Thread { Thread {
if (media.isNotEmpty()) { if (media.isNotEmpty()) {
activity.applicationContext.storeFolderItems(media.first().path.getParentPath().trimEnd('/'), media as ArrayList<Medium>) activity.applicationContext.storeFolderItems(media.first().parentPath, media as ArrayList<Medium>)
} }
}.start() }.start()
} }

View File

@ -39,7 +39,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
val firstItem = curMedia.first() val firstItem = curMedia.first()
val lastItem = curMedia.last() val lastItem = curMedia.last()
val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) { val parentDir = if (hasOTG && firstItem.path.startsWith(OTG_PATH)) {
firstItem.path.getParentPath() firstItem.parentPath
} else { } else {
File(firstItem.path).parent File(firstItem.path).parent
} ?: continue } ?: continue

View File

@ -12,7 +12,7 @@ import java.io.File
class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) { class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) {
init { init {
var realPath = path.getParentPath().trimEnd('/') var realPath = path.getParentPath()
val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply { val view = activity.layoutInflater.inflate(R.layout.dialog_save_as, null).apply {
save_as_path.text = activity.humanizePath(realPath) save_as_path.text = activity.humanizePath(realPath)

View File

@ -172,8 +172,7 @@ class MediaFetcher(val context: Context) {
break break
} }
val parentDir = (if (hasOTG && medium.path.startsWith(OTG_PATH)) medium.path.getParentPath().toLowerCase() else File(medium.path).parent?.toLowerCase()) val parentDir = medium.parentPath.toLowerCase()
?: continue
if (directories.containsKey(parentDir)) { if (directories.containsKey(parentDir)) {
directories[parentDir]!!.add(medium) directories[parentDir]!!.add(medium)
} else { } else {
@ -247,7 +246,8 @@ class MediaFetcher(val context: Context) {
else -> TYPE_GIF else -> TYPE_GIF
} }
val medium = Medium(null, filename, file.absolutePath, dateModified, dateTaken, size, type) val parentPath = file.absolutePath.removeSuffix("/")
val medium = Medium(null, filename, file.absolutePath, folder, dateModified, dateTaken, size, type)
curMedia.add(medium) curMedia.add(medium)
} }
} }
@ -296,7 +296,7 @@ class MediaFetcher(val context: Context) {
} }
val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH)) val path = Uri.decode(file.uri.toString().replaceFirst("${context.config.OTGBasePath}%3A", OTG_PATH))
val medium = Medium(null, filename, path, dateModified, dateTaken, size, type) val medium = Medium(null, filename, path, folder, dateModified, dateTaken, size, type)
curMedia.add(medium) curMedia.add(medium)
} }
} }

View File

@ -8,7 +8,7 @@ import com.simplemobiletools.gallery.models.Directory
@Dao @Dao
interface DirectoryDao { interface DirectoryDao {
@Query("SELECT * from directories") @Query("SELECT * FROM directories")
fun getAll(): List<Directory> fun getAll(): List<Directory>
@Insert(onConflict = REPLACE) @Insert(onConflict = REPLACE)

View File

@ -8,9 +8,12 @@ import com.simplemobiletools.gallery.models.Medium
@Dao @Dao
interface MediumDao { interface MediumDao {
@Query("SELECT * from media") @Query("SELECT * FROM media")
fun getAll(): List<Medium> fun getAll(): List<Medium>
@Query("SELECT * FROM media WHERE parent_path = :path")
fun getMediaFromPath(path: String): List<Medium>
@Insert(onConflict = REPLACE) @Insert(onConflict = REPLACE)
fun insert(medium: Medium) fun insert(medium: Medium)

View File

@ -13,11 +13,12 @@ import com.simplemobiletools.gallery.helpers.TYPE_IMAGE
import com.simplemobiletools.gallery.helpers.TYPE_VIDEO import com.simplemobiletools.gallery.helpers.TYPE_VIDEO
import java.io.Serializable import java.io.Serializable
@Entity(tableName = "media", indices = [(Index(value = "path", unique = true))]) @Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))])
data class Medium( data class Medium(
@PrimaryKey(autoGenerate = true) var id: Long?, @PrimaryKey(autoGenerate = true) var id: Long?,
@ColumnInfo(name = "filename") var name: String, @ColumnInfo(name = "filename") var name: String,
@ColumnInfo(name = "path") var path: String, @ColumnInfo(name = "full_path") var path: String,
@ColumnInfo(name = "parent_path") var parentPath: String,
@ColumnInfo(name = "last_modified") val modified: Long, @ColumnInfo(name = "last_modified") val modified: Long,
@ColumnInfo(name = "date_taken") val taken: Long, @ColumnInfo(name = "date_taken") val taken: Long,
@ColumnInfo(name = "size") val size: Long, @ColumnInfo(name = "size") val size: Long,