rescan path from third party intent if not in mediastore
This commit is contained in:
parent
318664fca1
commit
9529173e0a
1 changed files with 67 additions and 36 deletions
|
@ -6,6 +6,7 @@ import android.graphics.Color
|
|||
import android.graphics.drawable.ColorDrawable
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
|
@ -68,6 +69,39 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.photo_video_menu, menu)
|
||||
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
||||
|
||||
menu.apply {
|
||||
findItem(R.id.menu_set_as).isVisible = mMedium?.isImage() == true && visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
||||
findItem(R.id.menu_edit).isVisible = mMedium?.isImage() == true && mUri?.scheme == "file" && visibleBottomActions and BOTTOM_ACTION_EDIT == 0
|
||||
findItem(R.id.menu_properties).isVisible = mUri?.scheme == "file" && visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
||||
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
|
||||
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
||||
}
|
||||
|
||||
updateMenuItemColors(menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (mMedium == null || mUri == null) {
|
||||
return true
|
||||
}
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.menu_set_as -> setAs(mUri!!.toString())
|
||||
R.id.menu_open_with -> openPath(mUri!!.toString(), true)
|
||||
R.id.menu_share -> sharePath(mUri!!.toString())
|
||||
R.id.menu_edit -> openEditor(mUri!!.toString())
|
||||
R.id.menu_properties -> showProperties()
|
||||
R.id.menu_show_on_map -> showFileOnMap(mUri!!.toString())
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun checkIntent(savedInstanceState: Bundle? = null) {
|
||||
if (intent.data == null && intent.action == Intent.ACTION_VIEW) {
|
||||
hideKeyboard()
|
||||
|
@ -230,7 +264,20 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
|||
}
|
||||
|
||||
private fun sendViewPagerIntent(path: String) {
|
||||
ensureBackgroundThread {
|
||||
if (isPathPresentInMediaStore(path)) {
|
||||
openViewPager(path)
|
||||
} else {
|
||||
rescanPath(path) {
|
||||
openViewPager(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun openViewPager(path: String) {
|
||||
MediaActivity.mMedia.clear()
|
||||
runOnUiThread {
|
||||
hideKeyboard()
|
||||
Intent(this, ViewPagerActivity::class.java).apply {
|
||||
putExtra(SKIP_AUTHENTICATION, intent.getBooleanExtra(SKIP_AUTHENTICATION, false))
|
||||
|
@ -241,38 +288,22 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
|||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.photo_video_menu, menu)
|
||||
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
||||
|
||||
menu.apply {
|
||||
findItem(R.id.menu_set_as).isVisible = mMedium?.isImage() == true && visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
||||
findItem(R.id.menu_edit).isVisible = mMedium?.isImage() == true && mUri?.scheme == "file" && visibleBottomActions and BOTTOM_ACTION_EDIT == 0
|
||||
findItem(R.id.menu_properties).isVisible = mUri?.scheme == "file" && visibleBottomActions and BOTTOM_ACTION_PROPERTIES == 0
|
||||
findItem(R.id.menu_share).isVisible = visibleBottomActions and BOTTOM_ACTION_SHARE == 0
|
||||
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
||||
}
|
||||
|
||||
updateMenuItemColors(menu)
|
||||
return true
|
||||
private fun isPathPresentInMediaStore(path: String): Boolean {
|
||||
val uri = MediaStore.Files.getContentUri("external")
|
||||
val selection = "${MediaStore.Images.Media.DATA} = ?"
|
||||
val selectionArgs = arrayOf(path)
|
||||
|
||||
try {
|
||||
val cursor = contentResolver.query(uri, null, selection, selectionArgs, null)
|
||||
cursor?.use {
|
||||
return cursor.moveToFirst()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (mMedium == null || mUri == null) {
|
||||
return true
|
||||
}
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.menu_set_as -> setAs(mUri!!.toString())
|
||||
R.id.menu_open_with -> openPath(mUri!!.toString(), true)
|
||||
R.id.menu_share -> sharePath(mUri!!.toString())
|
||||
R.id.menu_edit -> openEditor(mUri!!.toString())
|
||||
R.id.menu_properties -> showProperties()
|
||||
R.id.menu_show_on_map -> showFileOnMap(mUri!!.toString())
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
private fun showProperties() {
|
||||
|
|
Loading…
Reference in a new issue