aboutsummaryrefslogtreecommitdiff
path: root/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-18 20:16:23 -0700
committerGitHub <noreply@github.com>2017-07-18 20:16:23 -0700
commit8f2b5ac043f47cc44f43c3788d1377083fb339a2 (patch)
tree8f91042414de211cbfe67a76298300884f46a765 /core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
parent4eee8d59c21b2061b9f5fd0e805ca60ab84c3585 (diff)
downloadkau-8f2b5ac043f47cc44f43c3788d1377083fb339a2.tar.gz
kau-8f2b5ac043f47cc44f43c3788d1377083fb339a2.tar.bz2
kau-8f2b5ac043f47cc44f43c3788d1377083fb339a2.zip
Dev 2.1 (#8)
* Rewrite animation interfaces * Update changelog * Add scale factor for slide * Remove margins in iitems and replace with decorators * Remove mutable list * Switch cardiitem to use lambdas for click * status * Utils update and imagepicker fixes * Remove stringholder * Add fade in fade out * Increment about version * Rename fromedge to direction in javadocs * More logging * Add logging and docs * Make card icons visible * Update email builder and icon padding * Create elastic recycler activity * Fix card iitem * Add lint check and plurals * Inline all the things * Format and sort xml * Update dependencies and increment version
Diffstat (limited to 'core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt')
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt81
1 files changed, 81 insertions, 0 deletions
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
new file mode 100644
index 0000000..1dcf14b
--- /dev/null
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
@@ -0,0 +1,81 @@
+package ca.allanwang.kau.ui.activities
+
+import android.os.Bundle
+import android.support.design.widget.AppBarLayout
+import android.support.design.widget.CoordinatorLayout
+import android.support.design.widget.FloatingActionButton
+import android.support.v7.app.AppCompatActivity
+import android.support.v7.widget.RecyclerView
+import android.support.v7.widget.Toolbar
+import android.transition.TransitionInflater
+import ca.allanwang.kau.ui.R
+import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout
+import ca.allanwang.kau.utils.bindView
+
+/**
+ * Created by Allan Wang on 2017-07-17.
+ *
+ * A generic activity comprised of an ElasticDragDismissFrameLayout, CoordinatorLayout, Toolbar, RecyclerView, and Fab
+ * [ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout]
+ * [android.support.v7.widget.RecyclerView]
+ *
+ * The recyclerview defaults to a linearlayoutmanager, and the adapter is automatically bounded
+ *
+ * The exit animation is set to slide out, but the entrance must be defined yourself
+ */
+abstract class ElasticRecyclerActivity() : AppCompatActivity() {
+
+ val appBar: AppBarLayout by bindView(R.id.kau_appbar)
+ val toolbar: Toolbar by bindView(R.id.kau_toolbar)
+ val coordinator: CoordinatorLayout by bindView(R.id.kau_coordinator)
+ val draggableFrame: ElasticDragDismissFrameLayout by bindView(R.id.kau_draggable)
+ val recycler: RecyclerView by bindView(R.id.kau_recycler)
+ val fab: FloatingActionButton by bindView(R.id.kau_fab)
+ val configs = Configs()
+
+ class Configs {
+ var exitTransitionBottom = R.transition.kau_exit_slide_bottom
+ var exitTransitionTop = R.transition.kau_exit_slide_top
+ }
+
+ override final fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.kau_elastic_recycler_activity)
+ setSupportActionBar(toolbar)
+ if (!onCreate(savedInstanceState, configs)) return
+ draggableFrame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ override fun onDragDismissed() {
+ window.returnTransition = TransitionInflater.from(this@ElasticRecyclerActivity)
+ .inflateTransition(if (draggableFrame.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop)
+ recycler.stopScroll()
+ finishAfterTransition()
+ }
+ })
+ }
+
+ /**
+ * The replacement method for the original [onCreate]
+ * The configurations are passed and can be customized here
+ * Returns true (default) if we wish to continue with the remaining optional setup
+ * Return false if we wish to skip this (usually if we have more complez requirements)
+ */
+ abstract fun onCreate(savedInstanceState: Bundle?, configs: Configs): Boolean
+
+ /**
+ * Receive actions when the a click event is received outside of the coordinator
+ */
+ fun setOutsideTapListener(listener: () -> Unit) {
+ draggableFrame.setOnClickListener { listener() }
+ }
+
+ fun hideFabOnUpwardsScroll() {
+ recycler.addOnScrollListener(object :RecyclerView.OnScrollListener(){
+ override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
+ if (dy > 0 && fab.isShown) fab.hide()
+ else if (dy < 0 && !fab.isShown) fab.show()
+ }
+ })
+ }
+
+}
+