From c71f94d9ec1f5015637d3ad9e0b2ee0d874e6759 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 6 Nov 2016 19:53:02 +0100 Subject: [PATCH] handle open_documet_tree activityresult in shared simpleactivity --- .../gallery/activities/ViewPagerActivity.java | 13 ------------- .../gallery/activities/EditActivity.kt | 7 ------- .../gallery/activities/SimpleActivity.kt | 12 +++++++++++- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index 057c2a9c3..b4e655821 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -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); diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 40a9a7b8e..cf3c0f1ba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt index 3d3251653..284f44e27 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt @@ -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) + } + } }