handle open_documet_tree activityresult in shared simpleactivity
This commit is contained in:
parent
fb59224405
commit
c71f94d9ec
3 changed files with 11 additions and 21 deletions
|
@ -1,7 +1,5 @@
|
|||
package com.simplemobiletools.gallery.activities;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
|
@ -238,21 +236,10 @@ public class ViewPagerActivity extends SimpleActivity
|
|||
if (resultCode == RESULT_OK) {
|
||||
Utils.Companion.showToast(getApplicationContext(), R.string.wallpaper_set_successfully);
|
||||
}
|
||||
} else if (requestCode == Constants.OPEN_DOCUMENT_TREE && resultCode == Activity.RESULT_OK && data != null) {
|
||||
saveTreeUri(data);
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
private void saveTreeUri(Intent resultData) {
|
||||
Uri treeUri = resultData.getData();
|
||||
getConfig().setTreeUri(resultData.getData().toString());
|
||||
|
||||
int takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
|
||||
getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
|
||||
}
|
||||
|
||||
private void shareMedium() {
|
||||
final Medium medium = getCurrentMedium();
|
||||
Utils.Companion.shareMedium(medium, this);
|
||||
|
|
|
@ -137,13 +137,6 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
|||
})
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == Constants.OPEN_DOCUMENT_TREE && resultCode == Activity.RESULT_OK && resultData != null) {
|
||||
Utils.saveTreeUri(this, resultData)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCompressionFormat(file: File): Bitmap.CompressFormat {
|
||||
return when (file.extension.toLowerCase()) {
|
||||
"png" -> Bitmap.CompressFormat.PNG
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package com.simplemobiletools.gallery.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.MenuItem
|
||||
|
||||
import com.simplemobiletools.gallery.Config
|
||||
import com.simplemobiletools.gallery.Constants
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.Utils
|
||||
|
||||
open class SimpleActivity : AppCompatActivity() {
|
||||
lateinit var config: Config
|
||||
|
@ -29,4 +32,11 @@ open class SimpleActivity : AppCompatActivity() {
|
|||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == Constants.OPEN_DOCUMENT_TREE && resultCode == Activity.RESULT_OK && resultData != null) {
|
||||
Utils.saveTreeUri(this, resultData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue