aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-21 02:16:34 -0500
committerGitHub <noreply@github.com>2017-12-21 02:16:34 -0500
commitd683cae6ffe644a9f63eea6cf3b7e59d2bde617b (patch)
tree517fe1d44c27084ccd87507d9804ba28f15c1647 /app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
parent82f9aca96493316bc62008f2b3167d34a6029b38 (diff)
downloadfrost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.gz
frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.tar.bz2
frost-d683cae6ffe644a9f63eea6cf3b7e59d2bde617b.zip
Enhancement/fragment interface (#564)
* Begin fragment interfaces and themable contracts * Prepare swiperefresh interface * Snapshot * Add compilable version * Revamp once more * Finalize layouts * Cleanup
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt140
1 files changed, 140 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
new file mode 100644
index 00000000..681636c4
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt
@@ -0,0 +1,140 @@
+package com.pitchedapps.frost.contracts
+
+import android.view.View
+import com.pitchedapps.frost.facebook.FbItem
+import io.reactivex.subjects.BehaviorSubject
+import io.reactivex.subjects.PublishSubject
+
+/**
+ * Created by Allan Wang on 20/12/17.
+ */
+
+/**
+ * Contract for the underlying parent,
+ * binds to activities & fragments
+ */
+interface FrostContentContainer {
+
+ val baseUrl: String
+
+ val baseEnum: FbItem?
+
+ /**
+ * Update toolbar title
+ */
+ fun setTitle(title: String)
+
+}
+
+/**
+ * Contract for components shared among
+ * all content providers
+ */
+interface FrostContentParent : DynamicUiContract {
+
+ val core: FrostContentCore
+
+ /**
+ * Observable to get data on whether view is refreshing or not
+ */
+ val refreshObservable: PublishSubject<Boolean>
+
+ /**
+ * Observable to get data on refresh progress, with range [0, 100]
+ */
+ val progressObservable: PublishSubject<Int>
+
+ /**
+ * Observable to get new title data (unique values only)
+ */
+ val titleObservable: BehaviorSubject<String>
+
+ var baseUrl: String
+
+ var baseEnum: FbItem?
+
+ /**
+ * Binds the container to self
+ * this will also handle all future bindings
+ * Must be called by container!
+ */
+ fun bind(container: FrostContentContainer)
+
+ /**
+ * Signal that the contract will not be used again
+ * Clean up resources where applicable
+ */
+ fun destroy()
+
+ /**
+ * Hook onto the refresh observable for one cycle
+ * Animate toggles between the fancy ripple and the basic fade
+ * The cycle only starts on the first load since
+ * there may have been another process when this is registered
+ */
+ fun registerTransition(animate: Boolean)
+
+}
+
+/**
+ * Underlying contract for the content itself
+ */
+interface FrostContentCore : DynamicUiContract {
+
+ /**
+ * Reference to parent
+ * Bound through calling [FrostContentParent.bind]
+ */
+ var parent: FrostContentParent
+
+ /**
+ * Initializes view through given [container]
+ *
+ * The content may be free to extract other data from
+ * the container if necessary
+ *
+ * [parent] must be bounded before calling this!
+ */
+ fun bind(container: FrostContentContainer): View
+
+ /**
+ * Call to reload wrapped data
+ */
+ fun reload(animate: Boolean)
+
+ /**
+ * Call to reload base data
+ */
+ fun reloadBase(animate: Boolean)
+
+ /**
+ * If possible, remove anything in the view stack
+ * Applies namely to webviews
+ */
+ fun clearHistory()
+
+ /**
+ * Should be called when a back press is triggered
+ * Return [true] if consumed, [false] otherwise
+ */
+ fun onBackPressed(): Boolean
+
+ val currentUrl: String
+
+ /**
+ * Condition to help pause certain background resources
+ */
+ var active: Boolean
+
+ /**
+ * Triggered when view is within viewpager
+ * and tab is clicked
+ */
+ fun onTabClicked()
+
+ /**
+ * Signal destruction to release some content manually
+ */
+ fun destroy()
+
+} \ No newline at end of file