mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
fix #194, check for storage permission even if opening third party image
This commit is contained in:
parent
b8ee70f7ed
commit
858d66e728
1 changed files with 27 additions and 0 deletions
|
@ -1,14 +1,19 @@
|
||||||
package com.simplemobiletools.gallery.activities
|
package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
|
import android.support.v4.app.ActivityCompat
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import com.simplemobiletools.commons.extensions.hasWriteStoragePermission
|
||||||
import com.simplemobiletools.commons.extensions.scanPath
|
import com.simplemobiletools.commons.extensions.scanPath
|
||||||
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.*
|
import com.simplemobiletools.gallery.extensions.*
|
||||||
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
import com.simplemobiletools.gallery.fragments.PhotoFragment
|
||||||
|
@ -19,6 +24,7 @@ import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentListener {
|
open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentListener {
|
||||||
|
private val STORAGE_PERMISSION = 1
|
||||||
private var mMedium: Medium? = null
|
private var mMedium: Medium? = null
|
||||||
private var mIsFullScreen = false
|
private var mIsFullScreen = false
|
||||||
|
|
||||||
|
@ -33,6 +39,14 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.fragment_holder)
|
setContentView(R.layout.fragment_holder)
|
||||||
|
|
||||||
|
if (hasWriteStoragePermission()) {
|
||||||
|
checkIntent(savedInstanceState)
|
||||||
|
} else {
|
||||||
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_PERMISSION)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkIntent(savedInstanceState: Bundle? = null) {
|
||||||
mUri = intent.data ?: return
|
mUri = intent.data ?: return
|
||||||
|
|
||||||
if (mUri.scheme == "file") {
|
if (mUri.scheme == "file") {
|
||||||
|
@ -84,6 +98,19 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
|
||||||
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
|
supportActionBar?.setBackgroundDrawable(resources.getDrawable(R.drawable.actionbar_gradient_background))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
|
||||||
|
if (requestCode == STORAGE_PERMISSION) {
|
||||||
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
checkIntent()
|
||||||
|
} else {
|
||||||
|
toast(R.string.no_storage_permissions)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun sendViewPagerIntent(path: String) {
|
private fun sendViewPagerIntent(path: String) {
|
||||||
Intent(this, ViewPagerActivity::class.java).apply {
|
Intent(this, ViewPagerActivity::class.java).apply {
|
||||||
putExtra(MEDIUM, path)
|
putExtra(MEDIUM, path)
|
||||||
|
|
Loading…
Reference in a new issue