aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.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/fragments/FragmentContract.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/fragments/FragmentContract.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt92
1 files changed, 92 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt
new file mode 100644
index 00000000..62b1de33
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt
@@ -0,0 +1,92 @@
+package com.pitchedapps.frost.fragments
+
+import android.content.Context
+import com.pitchedapps.frost.contracts.FrostContentContainer
+import com.pitchedapps.frost.contracts.FrostContentCore
+import com.pitchedapps.frost.contracts.FrostContentParent
+import com.pitchedapps.frost.contracts.MainActivityContract
+import com.pitchedapps.frost.views.FrostRecyclerView
+import io.reactivex.disposables.Disposable
+
+/**
+ * Created by Allan Wang on 2017-11-07.
+ */
+
+interface FragmentContract : FrostContentContainer {
+
+ val content: FrostContentParent?
+
+ /**
+ * Helper to retrieve the core from [content]
+ */
+ val core: FrostContentCore?
+ get() = content?.core
+
+ /**
+ * Specifies position in Activity's viewpager
+ */
+ val position: Int
+
+ /**
+ * Specifies whether if current load
+ * will be fragment's first load
+ *
+ * Defaults to true
+ */
+ var firstLoad: Boolean
+
+ /**
+ * Called when the fragment is first visible
+ * Typically, if [firstLoad] is true,
+ * the fragment should call [reload] and make [firstLoad] false
+ */
+ fun firstLoadRequest()
+
+ /**
+ * Single callable action to be executed upon creation
+ * Note that this call is not guaranteed
+ */
+ fun post(action: (fragment: FragmentContract) -> Unit)
+
+ /**
+ * Call whenever a fragment is attached so that it may listen
+ * to activity emissions
+ */
+ fun attachMainObservable(contract: MainActivityContract): Disposable
+
+ /**
+ * Load custom layout to container
+ */
+ fun innerView(context: Context): FrostContentCore
+
+ /**
+ * Call when fragment is detached so that any existing
+ * observable is disposed
+ */
+ fun detachMainObservable()
+
+ /*
+ * -----------------------------------------
+ * Delegates
+ * -----------------------------------------
+ */
+
+ fun onBackPressed(): Boolean
+
+ fun onTabClick()
+
+
+}
+
+interface RecyclerContentContract {
+
+ fun bind(recyclerView: FrostRecyclerView)
+
+ /**
+ * Completely handle data reloading
+ * Optional progress emission update
+ * Callback returns [true] for success, [false] otherwise
+ */
+ fun reload(progress: (Int) -> Unit, callback: (Boolean) -> Unit)
+
+} \ No newline at end of file