From d683cae6ffe644a9f63eea6cf3b7e59d2bde617b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 21 Dec 2017 02:16:34 -0500 Subject: Enhancement/fragment interface (#564) * Begin fragment interfaces and themable contracts * Prepare swiperefresh interface * Snapshot * Add compilable version * Revamp once more * Finalize layouts * Cleanup --- .../frost/contracts/ActivityContract.kt | 14 +++ .../frost/contracts/DynamicUiContract.kt | 30 +++++ .../frost/contracts/FrostContentContract.kt | 140 +++++++++++++++++++++ .../frost/contracts/FrostObservables.kt | 31 +++++ .../pitchedapps/frost/contracts/FrostThemable.kt | 29 +++++ .../pitchedapps/frost/contracts/FrostUrlData.kt | 25 ++++ .../com/pitchedapps/frost/contracts/WebContract.kt | 8 -- 7 files changed, 269 insertions(+), 8 deletions(-) create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostContentContract.kt create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt create mode 100644 app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostUrlData.kt delete mode 100644 app/src/main/kotlin/com/pitchedapps/frost/contracts/WebContract.kt (limited to 'app/src/main/kotlin/com/pitchedapps/frost/contracts') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt new file mode 100644 index 00000000..f51c4e53 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/ActivityContract.kt @@ -0,0 +1,14 @@ +package com.pitchedapps.frost.contracts + +import io.reactivex.subjects.PublishSubject + +/** + * All the contracts for [MainActivity] + */ +interface ActivityContract : FileChooserActivityContract + +interface MainActivityContract : ActivityContract { + val fragmentSubject: PublishSubject + fun setTitle(res: Int) + fun setTitle(text: CharSequence) +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt new file mode 100644 index 00000000..303c64b3 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/DynamicUiContract.kt @@ -0,0 +1,30 @@ +package com.pitchedapps.frost.contracts + +/** + * Functions that will modify the current ui + */ +interface DynamicUiContract { + + /** + * Change all necessary view components to the new theme + * Also propagate where applicable + */ + fun reloadTheme() + + /** + * Change theme without propagation + */ + fun reloadThemeSelf() + + /** + * Change text size & propagate + */ + fun reloadTextSize() + + + /** + * Change text size without propagation + */ + fun reloadTextSizeSelf() + +} \ No newline at end of file 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 + + /** + * Observable to get data on refresh progress, with range [0, 100] + */ + val progressObservable: PublishSubject + + /** + * Observable to get new title data (unique values only) + */ + val titleObservable: BehaviorSubject + + 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 diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt new file mode 100644 index 00000000..882b67a0 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostObservables.kt @@ -0,0 +1,31 @@ +package com.pitchedapps.frost.contracts + +import io.reactivex.subjects.BehaviorSubject +import io.reactivex.subjects.PublishSubject + +/** + * Created by Allan Wang on 2017-11-07. + */ +interface FrostObservables { + /** + * Observable to get data on whether view is refreshing or not + */ + var refreshObservable: PublishSubject + + /** + * Observable to get data on refresh progress, with range [0, 100] + */ + var progressObservable: PublishSubject + + /** + * Observable to get new title data (unique values only) + */ + var titleObservable: BehaviorSubject + + fun passObservablesTo(other: FrostObservables) { + other.refreshObservable = refreshObservable + other.progressObservable = progressObservable + other.titleObservable = titleObservable + } + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt new file mode 100644 index 00000000..3322f62e --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostThemable.kt @@ -0,0 +1,29 @@ +package com.pitchedapps.frost.contracts + +import android.view.View +import android.widget.TextView + +/** + * Created by Allan Wang on 2017-11-07. + * + * Should be implemented by all views in [com.pitchedapps.frost.activities.MainActivity] + * to allow for instant view reloading + */ +interface FrostThemable { + + /** + * Change all necessary view components to the new theme + * and call whatever other children that also implement [FrostThemable] + */ + fun reloadTheme() + + fun setTextColors(color: Int, vararg textViews: TextView?) = + themeViews(color, *textViews) { setTextColor(it) } + + fun setBackgrounds(color: Int, vararg views: View?) = + themeViews(color, *views) { setBackgroundColor(it) } + + fun themeViews(color: Int, vararg views: T?, action: T.(Int) -> Unit) = + views.filterNotNull().forEach { it.action(color) } + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostUrlData.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostUrlData.kt new file mode 100644 index 00000000..18467fa4 --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/contracts/FrostUrlData.kt @@ -0,0 +1,25 @@ +package com.pitchedapps.frost.contracts + +import com.pitchedapps.frost.facebook.FbItem + +/** + * Created by Allan Wang on 19/12/17. + */ +interface FrostUrlData { + + /** + * The main (and fallback) url + */ + var baseUrl: String + + /** + * Only base viewpager should pass an enum + */ + var baseEnum: FbItem? + + fun passUrlDataTo(other: FrostUrlData) { + other.baseUrl = baseUrl + other.baseEnum = baseEnum + } + +} \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/contracts/WebContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/contracts/WebContract.kt deleted file mode 100644 index 2485a468..00000000 --- a/app/src/main/kotlin/com/pitchedapps/frost/contracts/WebContract.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.pitchedapps.frost.contracts - -/** - * Created by Allan Wang on 2017-07-04. - * - * Combination of all the core functions implemented by the Activity - */ -interface ActivityWebContract : FileChooserActivityContract \ No newline at end of file -- cgit v1.2.3