diff options
author | Allan Wang <me@allanwang.ca> | 2018-02-02 21:05:26 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-02 21:05:26 -0500 |
commit | d68ea6d7eb8cadf687308fa3204386b79df0556b (patch) | |
tree | 0797c5c53e09b6af5eb996ab42e1f814ee615561 /app/src/main/kotlin/com/pitchedapps/frost/fragments | |
parent | f36e0fff23abb5c892b40d1a9fb70776078976c4 (diff) | |
download | frost-d68ea6d7eb8cadf687308fa3204386b79df0556b.tar.gz frost-d68ea6d7eb8cadf687308fa3204386b79df0556b.tar.bz2 frost-d68ea6d7eb8cadf687308fa3204386b79df0556b.zip |
Feature/post (#696)v1.8.1
* Reorder final override
* Add initial fab bindings
* Update scripts
* Optimize and use js header hider
* Remove old header hider
* Use method for generating clicker
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/fragments')
4 files changed, 51 insertions, 8 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index 0aaeaa6d..b77847de 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -2,14 +2,19 @@ package com.pitchedapps.frost.fragments import android.content.Context import android.os.Bundle +import android.support.design.widget.FloatingActionButton import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import ca.allanwang.kau.utils.fadeScaleTransition +import ca.allanwang.kau.utils.setIcon import ca.allanwang.kau.utils.withArguments +import com.mikepenz.iconics.typeface.IIcon import com.pitchedapps.frost.contracts.DynamicUiContract import com.pitchedapps.frost.contracts.FrostContentParent import com.pitchedapps.frost.contracts.MainActivityContract +import com.pitchedapps.frost.contracts.MainFabContract import com.pitchedapps.frost.enums.FeedSort import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.utils.* @@ -70,7 +75,7 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { throw IllegalArgumentException("${this::class.java.simpleName} is not attached to a context implementing MainActivityContract") } - override final fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + final override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(layoutRes, container, false) val content = view as? FrostContentParent ?: throw IllegalArgumentException("layoutRes for fragment must return view implementing FrostContentParent") @@ -118,6 +123,7 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { } position -> { contract.setTitle(baseEnum.titleId) + updateFab(contract) core?.active = true } -(position + 1) -> { @@ -129,6 +135,22 @@ abstract class BaseFragment : Fragment(), FragmentContract, DynamicUiContract { } } + override fun updateFab(contract: MainFabContract) { + contract.hideFab() // default + } + + protected fun FloatingActionButton.update(iicon: IIcon, click: () -> Unit) { + if (isShown) { + fadeScaleTransition { + setIcon(iicon, Prefs.iconColor) + } + } else { + setIcon(iicon, Prefs.iconColor) + show() + } + setOnClickListener { click() } + } + override fun detachMainObservable() { activityDisposable?.dispose() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt index 98a081e6..e683b056 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentContract.kt @@ -1,9 +1,7 @@ package com.pitchedapps.frost.fragments -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 android.support.design.widget.FloatingActionButton +import com.pitchedapps.frost.contracts.* import com.pitchedapps.frost.views.FrostRecyclerView import io.reactivex.disposables.Disposable @@ -48,6 +46,8 @@ interface FragmentContract : FrostContentContainer { */ fun firstLoadRequest() + fun updateFab(contract: MainFabContract) + /** * Single callable action to be executed upon creation * Note that this call is not guaranteed diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt index cdeaa3c1..51df4606 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/RecyclerFragmentBase.kt @@ -31,7 +31,7 @@ abstract class RecyclerFragment : BaseFragment(), RecyclerContentContract { } } - override final fun reload(progress: (Int) -> Unit, callback: (Boolean) -> Unit) { + final override fun reload(progress: (Int) -> Unit, callback: (Boolean) -> Unit) { reloadImpl(progress) { if (it) callback(it) @@ -49,7 +49,7 @@ abstract class GenericRecyclerFragment<T, Item : IItem<*, *>> : RecyclerFragment val adapter: ModelAdapter<T, Item> = ModelAdapter(this::mapper) - override final fun bind(recyclerView: FrostRecyclerView) { + final override fun bind(recyclerView: FrostRecyclerView) { recyclerView.adapter = getAdapter() recyclerView.onReloadClear = { adapter.clear() } bindImpl(recyclerView) @@ -81,7 +81,7 @@ abstract class FrostParserFragment<T : Any, Item : IItem<*, *>> : RecyclerFragme val adapter: ItemAdapter<Item> = ItemAdapter() - override final fun bind(recyclerView: FrostRecyclerView) { + final override fun bind(recyclerView: FrostRecyclerView) { recyclerView.adapter = getAdapter() recyclerView.onReloadClear = { adapter.clear() } bindImpl(recyclerView) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt index cdeea064..8000c106 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt @@ -1,7 +1,12 @@ package com.pitchedapps.frost.fragments +import android.webkit.WebView +import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.pitchedapps.frost.R +import com.pitchedapps.frost.contracts.MainFabContract import com.pitchedapps.frost.facebook.FbItem +import com.pitchedapps.frost.injectors.JsActions +import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.views.FrostWebView import com.pitchedapps.frost.web.FrostWebViewClient import com.pitchedapps.frost.web.FrostWebViewClientMenu @@ -24,4 +29,20 @@ class WebFragment : BaseFragment() { else -> FrostWebViewClient(web) } + override fun updateFab(contract: MainFabContract) { + L.e { "Update fab" } + val web = core as? WebView + if (web == null) { + L.e { "Webview not found in fragment $baseEnum" } + return super.updateFab(contract) + } + if (baseEnum.isFeed) { + contract.showFab(GoogleMaterial.Icon.gmd_edit) { + JsActions.CREATE_POST.inject(web) + } + L.e { "UPP" } + return + } + super.updateFab(contract) + } }
\ No newline at end of file |