Skip to content

Commit

Permalink
Rename all occurences of Master/Detail to Overview/Detail.
Browse files Browse the repository at this point in the history
Fixes the kotlin half of #1188.
  • Loading branch information
zach-klippenstein committed Jun 8, 2020
1 parent 8197f95 commit a536ef3
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.squareup.sample.container

import com.squareup.sample.container.masterdetail.MasterDetailContainer
import com.squareup.sample.container.overviewdetail.OverviewDetailContainer
import com.squareup.sample.container.panel.PanelContainer
import com.squareup.sample.container.panel.ScrimContainer
import com.squareup.workflow.ui.ViewRegistry

val SampleContainers = ViewRegistry(
BackButtonScreen.Binding, MasterDetailContainer, PanelContainer, ScrimContainer
BackButtonScreen.Binding, OverviewDetailContainer, PanelContainer, ScrimContainer
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.sample.container.masterdetail
package com.squareup.sample.container.overviewdetail

import com.squareup.workflow.ui.ViewEnvironmentKey

/**
* [com.squareup.workflow.ui.ViewEnvironment] value that informs views
* whether they're children of a [MasterDetailContainer], and if so
* whether they're children of a [OverviewDetailContainer], and if so
* in what configuration.
*/
enum class MasterDetailConfig {
enum class OverviewDetailConfig {
/**
* There is no [MasterDetailContainer] above here.
* There is no [OverviewDetailContainer] above here.
*/
None,

/**
* Drawing on the master side of a master / detail split screen.
* Drawing on the overview side of a overview / detail split screen.
*/
Master,
Overview,

/**
* Drawing on the detail side of a master / detail split screen.
* Drawing on the detail side of a overview / detail split screen.
*/
Detail,

Expand All @@ -43,7 +43,7 @@ enum class MasterDetailConfig {
*/
Single;

companion object : ViewEnvironmentKey<MasterDetailConfig>(MasterDetailConfig::class) {
companion object : ViewEnvironmentKey<OverviewDetailConfig>(OverviewDetailConfig::class) {
override val default = None
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,68 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.squareup.sample.container.masterdetail
package com.squareup.sample.container.overviewdetail

import android.view.View
import android.view.View.INVISIBLE
import android.view.View.VISIBLE
import com.squareup.sample.container.R
import com.squareup.sample.container.masterdetail.MasterDetailConfig.Detail
import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master
import com.squareup.sample.container.masterdetail.MasterDetailConfig.Single
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Detail
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Overview
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Single
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.ViewFactory
import com.squareup.workflow.ui.ViewEnvironment
import com.squareup.workflow.ui.WorkflowViewStub
import com.squareup.workflow.ui.backstack.BackStackScreen

/**
* Displays [MasterDetailScreen] renderings in either split pane or single pane
* Displays [OverviewDetailScreen] renderings in either split pane or single pane
* treatment, depending on the setup of the given [View]. The view must provide
* either a single [WorkflowViewStub] with id [R.id.master_detail_single_stub],
* or else two with ids [R.id.master_stub] and [R.id.detail_stub].
* either a single [WorkflowViewStub] with id [R.id.overview_detail_single_stub],
* or else two with ids [R.id.overview_stub] and [R.id.detail_stub].
*
* For single pane layouts, [MasterDetailScreen] is repackaged as a [BackStackScreen]
* with [MasterDetailScreen.masterRendering] as the base of the stack.
* For single pane layouts, [OverviewDetailScreen] is repackaged as a [BackStackScreen]
* with [OverviewDetailScreen.overviewRendering] as the base of the stack.
*/
class MasterDetailContainer(view: View) : LayoutRunner<MasterDetailScreen> {
class OverviewDetailContainer(view: View) : LayoutRunner<OverviewDetailScreen> {

private val masterStub: WorkflowViewStub? = view.findViewById(R.id.master_stub)
private val overviewStub: WorkflowViewStub? = view.findViewById(R.id.overview_stub)
private val detailStub: WorkflowViewStub? = view.findViewById(R.id.detail_stub)
private val singleStub: WorkflowViewStub? = view.findViewById(R.id.master_detail_single_stub)
private val singleStub: WorkflowViewStub? = view.findViewById(R.id.overview_detail_single_stub)

init {
check((singleStub == null) xor (masterStub == null && detailStub == null)) {
"Layout must define only R.id.master_detail_single_stub, " +
"or else both R.id.master_stub and R.id.detail_stub"
check((singleStub == null) xor (overviewStub == null && detailStub == null)) {
"Layout must define only R.id.overview_detail_single_stub, " +
"or else both R.id.overview_stub and R.id.detail_stub"
}
}

override fun showRendering(
rendering: MasterDetailScreen,
rendering: OverviewDetailScreen,
viewEnvironment: ViewEnvironment
) {
if (singleStub == null) renderSplitView(rendering, viewEnvironment)
else renderSingleView(rendering, viewEnvironment, singleStub)
}

private fun renderSplitView(
rendering: MasterDetailScreen,
rendering: OverviewDetailScreen,
viewEnvironment: ViewEnvironment
) {
if (rendering.detailRendering == null && rendering.selectDefault != null) {
rendering.selectDefault!!.invoke()
} else {
masterStub!!.update(
rendering.masterRendering,
viewEnvironment + (MasterDetailConfig to Master)
overviewStub!!.update(
rendering.overviewRendering,
viewEnvironment + (OverviewDetailConfig to Overview)
)
rendering.detailRendering
?.let { detail ->
detailStub!!.actual.visibility = VISIBLE
detailStub.update(
detail,
viewEnvironment + (MasterDetailConfig to Detail)
viewEnvironment + (OverviewDetailConfig to Detail)
)
}
?: run {
Expand All @@ -84,20 +84,20 @@ class MasterDetailContainer(view: View) : LayoutRunner<MasterDetailScreen> {
}

private fun renderSingleView(
rendering: MasterDetailScreen,
rendering: OverviewDetailScreen,
viewEnvironment: ViewEnvironment,
stub: WorkflowViewStub
) {
val combined: BackStackScreen<*> = rendering.detailRendering
?.let { rendering.masterRendering + it }
?: rendering.masterRendering
?.let { rendering.overviewRendering + it }
?: rendering.overviewRendering

stub.update(combined, viewEnvironment + (MasterDetailConfig to Single))
stub.update(combined, viewEnvironment + (OverviewDetailConfig to Single))
}

companion object : ViewFactory<MasterDetailScreen> by LayoutRunner.Binding(
type = MasterDetailScreen::class,
layoutId = R.layout.master_detail,
runnerConstructor = ::MasterDetailContainer
companion object : ViewFactory<OverviewDetailScreen> by LayoutRunner.Binding(
type = OverviewDetailScreen::class,
layoutId = R.layout.overview_detail,
runnerConstructor = ::OverviewDetailContainer
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
>

<com.squareup.workflow.ui.WorkflowViewStub
android:id="@+id/master_stub"
android:id="@+id/detail_stub"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:layout_weight="70"
/>

<View
Expand All @@ -34,10 +34,10 @@
/>

<com.squareup.workflow.ui.WorkflowViewStub
android:id="@+id/detail_stub"
android:id="@+id/overview_stub"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70"
android:layout_weight="30"
/>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:layout_width="match_parent" android:layout_height="match_parent">

<com.squareup.workflow.ui.WorkflowViewStub
android:id="@+id/master_detail_single_stub"
android:id="@+id/overview_detail_single_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
>

<com.squareup.workflow.ui.WorkflowViewStub
android:id="@+id/detail_stub"
android:id="@+id/overview_stub"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="70"
android:layout_weight="30"
/>

<View
Expand All @@ -34,10 +34,10 @@
/>

<com.squareup.workflow.ui.WorkflowViewStub
android:id="@+id/master_stub"
android:id="@+id/detail_stub"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="30"
android:layout_weight="70"
/>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
~ limitations under the License.
-->
<resources>
<item name="master_detail" type="layout">@layout/master_detail_split</item>
<item name="overview_detail" type="layout">@layout/overview_detail_split</item>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
~ limitations under the License.
-->
<resources>
<item name="master_detail" type="layout">@layout/master_detail_split</item>
<item name="overview_detail" type="layout">@layout/overview_detail_split</item>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
~ limitations under the License.
-->
<resources>
<item name="master_detail" type="layout">@layout/master_detail_single</item>
<item name="overview_detail" type="layout">@layout/overview_detail_single</item>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.squareup.sample.container.masterdetail.MasterDetailConfig
import com.squareup.sample.container.masterdetail.MasterDetailConfig.Master
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig
import com.squareup.sample.container.overviewdetail.OverviewDetailConfig.Overview
import com.squareup.sample.container.poetryapp.R
import com.squareup.workflow.ui.LayoutRunner
import com.squareup.workflow.ui.LayoutRunner.Companion.bind
Expand Down Expand Up @@ -66,7 +66,7 @@ class PoemListLayoutRunner(view: View) : LayoutRunner<PoemListRendering> {
parent: ViewGroup,
viewType: Int
): ViewHolder {
val selectable = environment[MasterDetailConfig] == Master
val selectable = environment[OverviewDetailConfig] == Overview
val layoutId = if (selectable) {
R.layout.list_row_selectable
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.squareup.sample.poetryapp

import com.squareup.sample.container.masterdetail.MasterDetailScreen
import com.squareup.sample.container.overviewdetail.OverviewDetailScreen
import com.squareup.sample.poetry.PoemWorkflow
import com.squareup.sample.poetry.model.Poem
import com.squareup.workflow.RenderContext
Expand All @@ -28,7 +28,7 @@ import com.squareup.workflow.ui.backstack.BackStackScreen
typealias SelectedPoem = Int

object PoemsBrowserWorkflow :
StatefulWorkflow<List<Poem>, SelectedPoem, Nothing, MasterDetailScreen>() {
StatefulWorkflow<List<Poem>, SelectedPoem, Nothing, OverviewDetailScreen>() {
override fun initialState(
props: List<Poem>,
snapshot: Snapshot?
Expand All @@ -41,16 +41,16 @@ object PoemsBrowserWorkflow :
props: List<Poem>,
state: SelectedPoem,
context: RenderContext<SelectedPoem, Nothing>
): MasterDetailScreen {
val poems: MasterDetailScreen =
): OverviewDetailScreen {
val poems: OverviewDetailScreen =
context.renderChild(PoemListWorkflow, props) { selected -> choosePoem(selected) }
.copy(selection = state)
.let { MasterDetailScreen(BackStackScreen(it)) }
.let { OverviewDetailScreen(BackStackScreen(it)) }

return if (state == -1) {
poems
} else {
val poem: MasterDetailScreen =
val poem: OverviewDetailScreen =
context.renderChild(PoemWorkflow, props[state]) { clearSelection }
poems + poem
}
Expand Down
Loading

0 comments on commit a536ef3

Please sign in to comment.