diff options
author | Allan Wang <me@allanwang.ca> | 2017-07-23 23:26:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-23 23:26:34 -0700 |
commit | 50ad7f0ae89fc52ce57fe03328f4221fb57f2eac (patch) | |
tree | 69ead8807bb7371428953a0363519343f03f9b5b /core/src/main | |
parent | 4706b8f6a8d08a6961da6ab34d15881b63356d79 (diff) | |
download | kau-50ad7f0ae89fc52ce57fe03328f4221fb57f2eac.tar.gz kau-50ad7f0ae89fc52ce57fe03328f4221fb57f2eac.tar.bz2 kau-50ad7f0ae89fc52ce57fe03328f4221fb57f2eac.zip |
Fully implement imagepicker and create play store showcase (#12)3.1.1
* Update changelog
* Add uri to imagemodel
* Revamp image pickers
* Prepare play store showcase
* Add encrypted files
* Test showcase
* Clean elastic recycler activity
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 25 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 10 |
2 files changed, 31 insertions, 4 deletions
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 @@ -20,6 +20,27 @@ import org.jetbrains.anko.contentView */ /** + * 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<out Activity>, + 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<out Activity>, @@ -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() } |