extracting the inner carousel fragment classes

This commit is contained in:
Adam Brown 2021-12-15 15:53:16 +00:00
parent c0db9f7ca1
commit 633f495e2c
4 changed files with 106 additions and 50 deletions

View File

@ -21,21 +21,13 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.core.view.isVisible
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import com.airbnb.epoxy.TypedEpoxyController
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.resources.StringProvider
import im.vector.app.databinding.FragmentFtueSplashCarouselBinding
import im.vector.app.features.VectorFeatures
@ -142,45 +134,3 @@ class FtueAuthSplashCarouselFragment : AbstractFtueAuthFragment<FragmentFtueSpla
}
}
}
data class SplashCarouselState(
val items: List<Item>
) {
data class Item(
val title: String,
val body: String,
@DrawableRes val image: Int,
@DrawableRes val pageBackground: Int
)
}
class SplashCarouselController @Inject constructor() : TypedEpoxyController<SplashCarouselState>() {
override fun buildModels(data: SplashCarouselState) {
data.items.forEachIndexed { index, item ->
splashCarouselItem {
id(index)
item(item)
}
}
}
}
@EpoxyModelClass(layout = im.vector.app.R.layout.item_splash_carousel)
abstract class SplashCarouselItem : VectorEpoxyModel<SplashCarouselItem.Holder>() {
@EpoxyAttribute
lateinit var item: SplashCarouselState.Item
override fun bind(holder: Holder) {
holder.view.setBackgroundResource(item.pageBackground)
holder.image.setImageResource(item.image)
holder.title.text = item.title
holder.body.text = item.body
}
class Holder : VectorEpoxyHolder() {
val image by bind<ImageView>(im.vector.app.R.id.carousel_item_image)
val title by bind<TextView>(im.vector.app.R.id.carousel_item_title)
val body by bind<TextView>(im.vector.app.R.id.carousel_item_body)
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.onboarding.ftueauth
import com.airbnb.epoxy.TypedEpoxyController
import javax.inject.Inject
class SplashCarouselController @Inject constructor() : TypedEpoxyController<SplashCarouselState>() {
override fun buildModels(data: SplashCarouselState) {
data.items.forEachIndexed { index, item ->
splashCarouselItem {
id(index)
item(item)
}
}
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.onboarding.ftueauth
import android.widget.ImageView
import android.widget.TextView
import com.airbnb.epoxy.EpoxyAttribute
import com.airbnb.epoxy.EpoxyModelClass
import im.vector.app.R
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
@EpoxyModelClass(layout = R.layout.item_splash_carousel)
abstract class SplashCarouselItem : VectorEpoxyModel<SplashCarouselItem.Holder>() {
@EpoxyAttribute
lateinit var item: SplashCarouselState.Item
override fun bind(holder: Holder) {
holder.view.setBackgroundResource(item.pageBackground)
holder.image.setImageResource(item.image)
holder.title.text = item.title
holder.body.text = item.body
}
class Holder : VectorEpoxyHolder() {
val image by bind<ImageView>(R.id.carousel_item_image)
val title by bind<TextView>(R.id.carousel_item_title)
val body by bind<TextView>(R.id.carousel_item_body)
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.onboarding.ftueauth
import androidx.annotation.DrawableRes
data class SplashCarouselState(
val items: List<Item>
) {
data class Item(
val title: String,
val body: String,
@DrawableRes val image: Int,
@DrawableRes val pageBackground: Int
)
}