From 50ad7f0ae89fc52ce57fe03328f4221fb57f2eac Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 23 Jul 2017 23:26:34 -0700 Subject: Fully implement imagepicker and create play store showcase (#12) * Update changelog * Add uri to imagemodel * Revamp image pickers * Prepare play store showcase * Add encrypted files * Test showcase * Clean elastic recycler activity --- .../kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 25 ++++++++++++++++++++-- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 10 +++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'core/src/main/kotlin/ca') diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index 54aeaff..5631e70 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -2,11 +2,11 @@ package ca.allanwang.kau.utils import android.annotation.SuppressLint import android.app.Activity +import android.app.ActivityOptions import android.content.Intent import android.graphics.Color -import android.os.Build +import android.os.Bundle import android.support.annotation.ColorInt -import android.support.annotation.RequiresApi import android.support.annotation.StringRes import android.support.design.widget.Snackbar import android.view.Menu @@ -19,6 +19,27 @@ import org.jetbrains.anko.contentView * Created by Allan Wang on 2017-06-21. */ +/** + * Helper class to launch an activity for result + * Counterpart of [Activity.startActivityForResult] + * For starting activities without result, see [startActivity] + */ +@SuppressLint("NewApi") +fun Activity.startActivityForResult( + clazz: Class, + requestCode: Int, + transition: Boolean = false, + bundle: Bundle? = null, + intentBuilder: Intent.() -> Unit = {}) { + val intent = Intent(this, clazz) + val fullBundle = if (transition && buildIsLollipopAndUp) + ActivityOptions.makeSceneTransitionAnimation(this).toBundle() + else Bundle() + if (bundle != null) fullBundle.putAll(bundle) + intent.intentBuilder() + startActivityForResult(intent, requestCode, if (fullBundle.isEmpty) null else fullBundle) +} + /** * Restarts an activity from itself with a fade animation * Keeps its existing extra bundles and has a builder to accept other parameters diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index 7a92665..2219b5d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -26,6 +26,12 @@ import com.afollestad.materialdialogs.MaterialDialog /** * Created by Allan Wang on 2017-06-03. */ + +/** + * Helper class to launch an activity from a context + * Counterpart of [ContextCompat.startActivity] + * For starting activities for results, see [startActivityForResult] + */ @SuppressLint("NewApi") fun Context.startActivity( clazz: Class, @@ -33,14 +39,14 @@ fun Context.startActivity( transition: Boolean = false, bundle: Bundle? = null, intentBuilder: Intent.() -> Unit = {}) { - val intent = (Intent(this, clazz)) + val intent = Intent(this, clazz) if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) - intent.intentBuilder() val fullBundle = if (transition && this is Activity && buildIsLollipopAndUp) ActivityOptions.makeSceneTransitionAnimation(this).toBundle() else Bundle() if (transition && this !is Activity) KL.d("Cannot make scene transition when context is not an instance of an Activity") if (bundle != null) fullBundle.putAll(bundle) + intent.intentBuilder() ContextCompat.startActivity(this, intent, if (fullBundle.isEmpty) null else fullBundle) if (this is Activity && clearStack) finish() } -- cgit v1.2.3