Skip to content

Commit

Permalink
[Teacher][MBL-14841] Empty state added for modules with no items (#1066)
Browse files Browse the repository at this point in the history
* [Teacher] Empty state added for modules with no items

refs: MBL-14829
affects: Teacher
release note: Empty state added for modules with no items.
  • Loading branch information
hermannakos authored Oct 20, 2020
1 parent c01f32d commit 70917b7
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,25 @@ object ModuleListPresenter : Presenter<ModuleListModel, ModuleListViewState> {
val courseColor = model.course.color

items += model.modules.map { module ->
val moduleItems = module.items.map { item ->
if (item.type.equals(ModuleItem.Type.SubHeader.name, ignoreCase = true)) {
ModuleListItemData.ModuleItemData(
id = item.id,
title = null,
subtitle = item.title,
iconResId = null,
isPublished = item.published,
indent = item.indent * indentWidth,
tintColor = 0,
enabled = false
)
} else {
createModuleItemData(item, context, indentWidth, courseColor, item.id in model.loadingModuleItemIds)
val moduleItems: List<ModuleListItemData> = if (module.items.isNotEmpty()) {
module.items.map { item ->
if (item.type.equals(ModuleItem.Type.SubHeader.name, ignoreCase = true)) {
ModuleListItemData.ModuleItemData(
id = item.id,
title = null,
subtitle = item.title,
iconResId = null,
isPublished = item.published,
indent = item.indent * indentWidth,
tintColor = 0,
enabled = false
)
} else {
createModuleItemData(item, context, indentWidth, courseColor, item.id in model.loadingModuleItemIds)
}
}
} else {
listOf(ModuleListItemData.EmptyItem(module.id))
}
ModuleListItemData.ModuleData(
id = module.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ModuleListRecyclerAdapter(
register(ModuleListModuleBinder())
register(ModuleListItemBinder())
register(ModuleListLoadingBinder())
register(ModuleListEmptyItemBinder())
}

fun setData(items: List<ModuleListItemData>, collapsedModuleIds: Set<Long>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ sealed class ModuleListItemData {

object Loading : ModuleListItemData()

data class EmptyItem(val moduleId: Long) : ModuleListItemData()

data class FullError(val buttonColor: Int): ModuleListItemData()

data class InlineError(val buttonColor: Int): ModuleListItemData()
Expand All @@ -38,7 +40,7 @@ sealed class ModuleListItemData {
val id: Long,
val name: String,
val isPublished: Boolean?,
val moduleItems: List<ModuleItemData>
val moduleItems: List<ModuleListItemData>
): ModuleListItemData()

data class ModuleItemData(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2019 - present Instructure, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.instructure.teacher.features.modules.list.ui.binders

import com.instructure.teacher.R
import com.instructure.teacher.adapters.ListItemBinder
import com.instructure.teacher.features.modules.list.ui.ModuleListCallback
import com.instructure.teacher.features.modules.list.ui.ModuleListItemData

class ModuleListEmptyItemBinder : ListItemBinder<ModuleListItemData.EmptyItem, ModuleListCallback>() {

override val layoutResId: Int
get() = R.layout.adapter_module_empty_item

override val bindBehavior = NoBind()

override fun getItemId(item: ModuleListItemData.EmptyItem): Long = item.moduleId
}
32 changes: 32 additions & 0 deletions apps/teacher/src/main/res/layout/adapter_module_empty_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2019 - present Instructure, Inc.
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, version 3 of the License.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp">

<TextView
android:id="@+id/emptyModuleItemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/noItemsToDisplayShort" />

</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ModuleListPresenterTest : Assert() {
id = 1L,
name = "Module 1",
isPublished = true,
moduleItems = emptyList()
moduleItems = listOf(ModuleListItemData.EmptyItem(1L))
)
moduleItemTemplate = ModuleItem(
id = 1000L,
Expand Down

0 comments on commit 70917b7

Please sign in to comment.