From b222c5b53dbc968d36e22a5a4d0d5792bf30bd45 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Mon, 22 Apr 2019 15:07:03 -0700 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/1843 - Scaffolds MVI component for Collection Creation --- .../CollectionCreationComponent.kt | 44 +++++++++++++++++++ .../collections/CollectionCreationUIView.kt | 30 +++++++++++++ .../collections/CreateCollectionFragment.kt | 18 ++++++-- .../drawable/create_collection_background.xml | 9 ++++ .../main/res/drawable/home_header_shadow.xml | 3 ++ .../layout/component_collection_creation.xml | 11 +++++ .../res/layout/fragment_create_collection.xml | 7 ++- 7 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt create mode 100644 app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt create mode 100644 app/src/main/res/drawable/create_collection_background.xml create mode 100644 app/src/main/res/layout/component_collection_creation.xml diff --git a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt new file mode 100644 index 0000000000..b28bca799a --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationComponent.kt @@ -0,0 +1,44 @@ +package org.mozilla.fenix.collections + +import android.view.ViewGroup +import org.mozilla.fenix.mvi.Action +import org.mozilla.fenix.mvi.ActionBusFactory +import org.mozilla.fenix.mvi.Change +import org.mozilla.fenix.mvi.Reducer +import org.mozilla.fenix.mvi.UIComponent +import org.mozilla.fenix.mvi.ViewState + +/* This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +sealed class CollectionCreationState : ViewState { + object Empty : CollectionCreationState() +} + +sealed class CollectionCreationChange : Change { + +} + +sealed class CollectionCreationAction : Action { + +} + +class CollectionCreationComponent( + private val container: ViewGroup, + bus: ActionBusFactory, + override var initialState: CollectionCreationState = CollectionCreationState.Empty +) : UIComponent( + bus.getManagedEmitter(CollectionCreationAction::class.java), + bus.getSafeManagedObservable(CollectionCreationChange::class.java) +) { + override val reducer: Reducer = { state, change -> + CollectionCreationState.Empty + } + + override fun initView() = CollectionCreationUIView(container, actionEmitter, changesObservable) + + init { + render(reducer) + } +} \ No newline at end of file diff --git a/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt new file mode 100644 index 0000000000..40779bd15f --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/collections/CollectionCreationUIView.kt @@ -0,0 +1,30 @@ +package org.mozilla.fenix.collections + +/* This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import android.view.LayoutInflater +import android.view.ViewGroup +import org.mozilla.fenix.R +import io.reactivex.Observer +import io.reactivex.Observable +import io.reactivex.functions.Consumer +import org.mozilla.fenix.mvi.UIView + +class CollectionCreationUIView( + container: ViewGroup, + actionEmitter: Observer, + changesObservable: Observable +) : UIView( + container, + actionEmitter, + changesObservable +) { + override val view = LayoutInflater.from(container.context) + .inflate(R.layout.component_collection_creation, container, true) + + override fun updateView() = Consumer { + + } +} \ No newline at end of file diff --git a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt index 8388652042..892b68fce9 100644 --- a/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/collections/CreateCollectionFragment.kt @@ -1,23 +1,33 @@ package org.mozilla.fenix.collections +/* This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup - +import kotlinx.android.synthetic.main.fragment_create_collection.view.* import org.mozilla.fenix.R +import org.mozilla.fenix.mvi.ActionBusFactory class CreateCollectionFragment : Fragment() { + private lateinit var collectionCreationComponent: CollectionCreationComponent + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_create_collection, container, false) - } + val view = inflater.inflate(R.layout.fragment_create_collection, container, false) + collectionCreationComponent = CollectionCreationComponent( + view.create_collection_wrapper, + ActionBusFactory.get(this) + ) + return view + } } diff --git a/app/src/main/res/drawable/create_collection_background.xml b/app/src/main/res/drawable/create_collection_background.xml new file mode 100644 index 0000000000..de5e8f42bc --- /dev/null +++ b/app/src/main/res/drawable/create_collection_background.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/app/src/main/res/drawable/home_header_shadow.xml b/app/src/main/res/drawable/home_header_shadow.xml index 3c06e6bbae..7619a98731 100644 --- a/app/src/main/res/drawable/home_header_shadow.xml +++ b/app/src/main/res/drawable/home_header_shadow.xml @@ -1,4 +1,7 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_create_collection.xml b/app/src/main/res/layout/fragment_create_collection.xml index 779424a78e..c735fe9ccf 100644 --- a/app/src/main/res/layout/fragment_create_collection.xml +++ b/app/src/main/res/layout/fragment_create_collection.xml @@ -1,11 +1,10 @@ - -