Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug when the name of subcategory is empty #263

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ val screenModule = module {
viewModel { CourseSearchViewModel(get(), get(), get(), get(), get()) }
viewModel { SelectDialogViewModel(get()) }

single { DiscussionRepository(get(), get()) }
single { DiscussionRepository(get(), get(), get()) }
factory { DiscussionInteractor(get()) }
viewModel { (courseId: String) -> DiscussionTopicsViewModel(get(), get(), get(), courseId) }
viewModel { (courseId: String, topicId: String, threadType: String) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@ package org.openedx.discussion.data.repository

import org.openedx.core.data.model.BlocksCompletionBody
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.system.ResourceManager
import org.openedx.discussion.R
import org.openedx.discussion.data.api.DiscussionApi
import org.openedx.discussion.data.model.request.*
import org.openedx.discussion.data.model.request.CommentBody
import org.openedx.discussion.data.model.request.FollowBody
import org.openedx.discussion.data.model.request.ReadBody
import org.openedx.discussion.data.model.request.ReportBody
import org.openedx.discussion.data.model.request.ThreadBody
import org.openedx.discussion.data.model.request.VoteBody
import org.openedx.discussion.domain.model.CommentsData
import org.openedx.discussion.domain.model.ThreadsData
import org.openedx.discussion.domain.model.Topic

class DiscussionRepository(
private val api: DiscussionApi,
private val preferencesManager: CorePreferences
) {
private val preferencesManager: CorePreferences,
private val resourceManager: ResourceManager
) {

private val topics = mutableListOf<Topic>()
private var currentCourseId = ""

suspend fun getCourseTopics(courseId: String): List<Topic> {
val topicsData = api.getCourseTopics(courseId).mapToDomain()
val defaultTopicName = resourceManager.getString(R.string.discussion_unnamed_subcategory)
currentCourseId = courseId
topics.clear()
topics.addAll(topicsData.nonCoursewareTopics)
Expand All @@ -27,6 +36,11 @@ class DiscussionRepository(
topics.addAll(it.children)
}
}
topics.forEachIndexed { index, topic ->
if (topic.name.isBlank()) {
topics[index] = topic.copy(name = defaultTopicName)
}
}
return topics.toList()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openedx.discussion.domain.model


data class TopicsData(
val coursewareTopics: List<Topic>,
val nonCoursewareTopics: List<Topic>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.*
import androidx.compose.material.Card
import androidx.compose.material.Divider
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ChevronRight
import androidx.compose.material.icons.outlined.HelpOutline
Expand Down Expand Up @@ -94,7 +109,10 @@ fun ThreadMainItem(
.error(org.openedx.core.R.drawable.core_ic_default_profile_picture)
.placeholder(org.openedx.core.R.drawable.core_ic_default_profile_picture)
.build(),
contentDescription = stringResource(id = org.openedx.core.R.string.core_accessibility_user_profile_image, thread.author),
contentDescription = stringResource(
id = org.openedx.core.R.string.core_accessibility_user_profile_image,
thread.author
),
modifier = Modifier
.size(48.dp)
.clip(MaterialTheme.appShapes.material.medium)
Expand Down Expand Up @@ -245,7 +263,10 @@ fun CommentItem(
.error(org.openedx.core.R.drawable.core_ic_default_profile_picture)
.placeholder(org.openedx.core.R.drawable.core_ic_default_profile_picture)
.build(),
contentDescription = stringResource(id = org.openedx.core.R.string.core_accessibility_user_profile_image, comment.author),
contentDescription = stringResource(
id = org.openedx.core.R.string.core_accessibility_user_profile_image,
comment.author
),
modifier = Modifier
.size(32.dp)
.clip(CircleShape)
Expand Down Expand Up @@ -395,7 +416,10 @@ fun CommentMainItem(
.error(org.openedx.core.R.drawable.core_ic_default_profile_picture)
.placeholder(org.openedx.core.R.drawable.core_ic_default_profile_picture)
.build(),
contentDescription = stringResource(id = org.openedx.core.R.string.core_accessibility_user_profile_image, comment.author),
contentDescription = stringResource(
id = org.openedx.core.R.string.core_accessibility_user_profile_image,
comment.author
),
modifier = Modifier
.size(32.dp)
.clip(CircleShape)
Expand Down Expand Up @@ -504,7 +528,8 @@ fun ThreadItem(
text = textType,
painter = icon,
color = MaterialTheme.appColors.textPrimaryVariant,
textStyle = MaterialTheme.appTypography.labelSmall)
textStyle = MaterialTheme.appTypography.labelSmall
)
if (thread.unreadCommentCount > 0 && !thread.read) {
Row(
modifier = Modifier,
Expand Down Expand Up @@ -562,7 +587,8 @@ fun ThreadItem(
),
painter = painterResource(id = R.drawable.discussion_ic_responses),
color = MaterialTheme.appColors.textAccent,
textStyle = MaterialTheme.appTypography.labelLarge)
textStyle = MaterialTheme.appTypography.labelLarge
)
}

}
Expand Down
1 change: 1 addition & 0 deletions discussion/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<string name="discussion_anonymous">anonymous</string>
<string name="discussion_no_yet">No discussions yet</string>
<string name="discussion_click_button_create_discussion">Click the button below to create your first discussion.</string>
<string name="discussion_unnamed_subcategory">Unnamed subcategory</string>


<plurals name="discussion_votes">
Expand Down
Loading