Skip to content

Commit

Permalink
Discussion's user profile (#69)
Browse files Browse the repository at this point in the history
* Added screen another users profile with open from discussion screen

* Added AnothersProfileViewModel unit tests

* Accessibility support
  • Loading branch information
PavloNetrebchuk authored Oct 13, 2023
1 parent 50a4952 commit 0557842
Show file tree
Hide file tree
Showing 18 changed files with 717 additions and 156 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/org/openedx/app/AppRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.openedx.discussion.presentation.search.DiscussionSearchThreadFragment
import org.openedx.discussion.presentation.threads.DiscussionAddThreadFragment
import org.openedx.discussion.presentation.threads.DiscussionThreadsFragment
import org.openedx.profile.presentation.ProfileRouter
import org.openedx.profile.presentation.anothers_account.AnothersProfileFragment
import org.openedx.profile.presentation.delete.DeleteProfileFragment
import org.openedx.profile.presentation.edit.EditProfileFragment
import org.openedx.profile.presentation.settings.video.VideoQualityFragment
Expand Down Expand Up @@ -223,6 +224,16 @@ class AppRouter : AuthRouter, DiscoveryRouter, DashboardRouter, CourseRouter, Di
DiscussionSearchThreadFragment.newInstance(courseId)
)
}

override fun navigateToAnothersProfile(
fm: FragmentManager,
username: String
) {
replaceFragmentWithBackStack(
fm,
AnothersProfileFragment.newInstance(username)
)
}
//endregion

//region ProfileRouter
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import org.openedx.profile.presentation.settings.video.VideoSettingsViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.qualifier.named
import org.koin.dsl.module
import org.openedx.profile.presentation.anothers_account.AnothersProfileViewModel

val screenModule = module {

Expand Down Expand Up @@ -73,6 +74,7 @@ val screenModule = module {
viewModel { VideoSettingsViewModel(get(), get()) }
viewModel { VideoQualityViewModel(get(), get()) }
viewModel { DeleteProfileViewModel(get(), get(), get(), get()) }
viewModel { (username: String) -> AnothersProfileViewModel(get(), get(), username) }

single { CourseRepository(get(), get(), get(),get()) }
factory { CourseInteractor(get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ interface AuthRouter {
fun navigateToSignUp(fm: FragmentManager)

fun navigateToRestorePassword(fm: FragmentManager)

}
3 changes: 2 additions & 1 deletion core/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
<string name="core_android_device_model">Модель пристрою: </string>
<string name="core_insert_feedback">Відгук: </string>
<string name="core_email_subject">Відгук клієнта</string>

<string name="core_date_format_MMMM_dd">dd MMMM</string>
<string name="core_full_date_with_time">dd MMM yyyy HH:mm</string>

<!-- Accessibility-->
<string name="core_accessibility_user_profile_image">%1$s зображення профілю</string>
</resources>
4 changes: 3 additions & 1 deletion core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<string name="core_android_device_model">Device Model: </string>
<string name="core_insert_feedback">Feedback: </string>
<string name="core_email_subject">Customer Feedback</string>

<string name="core_date_format_MMMM_dd">MMMM dd</string>
<string name="core_full_date_with_time">dd MMM yyyy hh:mm aaa</string>

<!-- Accessibility-->
<string name="core_accessibility_user_profile_image">%1$s profile image</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ interface DiscussionRouter {
courseId: String
)

fun navigateToAnothersProfile(
fm: FragmentManager,
username: String
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ class DiscussionCommentsFragment : Fragment() {
requireActivity().supportFragmentManager, it, viewModel.thread.closed
)
},
onUserPhotoClick = { username ->
router.navigateToAnothersProfile(
requireActivity().supportFragmentManager, username
)
},
onAddResponseClick = {
viewModel.createComment(it)
},
Expand Down Expand Up @@ -167,7 +172,8 @@ private fun DiscussionCommentsScreen(
onItemClick: (String, String, Boolean) -> Unit,
onCommentClick: (DiscussionComment) -> Unit,
onAddResponseClick: (String) -> Unit,
onBackClick: () -> Unit
onBackClick: () -> Unit,
onUserPhotoClick: (String) -> Unit
) {
val scaffoldState = rememberScaffoldState()
val scrollState = rememberLazyListState()
Expand Down Expand Up @@ -287,7 +293,11 @@ private fun DiscussionCommentsScreen(
thread = uiState.thread,
onClick = { action, bool ->
onItemClick(action, uiState.thread.id, bool)
})
},
onUserPhotoClick = { username ->
onUserPhotoClick(username)
}
)
}
if (uiState.commentsData.isNotEmpty()) {
item {
Expand Down Expand Up @@ -320,6 +330,9 @@ private fun DiscussionCommentsScreen(
},
onAddCommentClick = {
onCommentClick(comment)
},
onUserPhotoClick = {
onUserPhotoClick(comment.author)
})
}
item {
Expand Down Expand Up @@ -403,6 +416,7 @@ private fun DiscussionCommentsScreen(
}
}
}

is DiscussionCommentsUIState.Loading -> {
Box(
Modifier
Expand Down Expand Up @@ -450,7 +464,8 @@ private fun DiscussionCommentsScreenPreview() {
onBackClick = {},
scrollToBottom = false,
refreshing = false,
onSwipeRefresh = {}
onSwipeRefresh = {},
onUserPhotoClick = {}
)
}
}
Expand Down Expand Up @@ -480,7 +495,8 @@ private fun DiscussionCommentsScreenTabletPreview() {
onBackClick = {},
scrollToBottom = false,
refreshing = false,
onSwipeRefresh = {}
onSwipeRefresh = {},
onUserPhotoClick = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import org.koin.android.ext.android.inject
import org.openedx.core.UIMessage
import org.openedx.core.domain.model.ProfileImage
import org.openedx.core.extension.TextConverter
Expand All @@ -53,6 +54,7 @@ import org.openedx.discussion.presentation.comments.DiscussionCommentsFragment
import org.openedx.discussion.presentation.ui.CommentMainItem
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf
import org.openedx.discussion.presentation.DiscussionRouter
import org.openedx.discussion.R as discussionR

class DiscussionResponsesFragment : Fragment() {
Expand All @@ -61,6 +63,8 @@ class DiscussionResponsesFragment : Fragment() {
parametersOf(requireArguments().parcelable(ARG_COMMENT))
}

private val router by inject<DiscussionRouter>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
lifecycle.addObserver(viewModel)
Expand Down Expand Up @@ -118,6 +122,11 @@ class DiscussionResponsesFragment : Fragment() {
},
onBackClick = {
requireActivity().supportFragmentManager.popBackStack()
},
onUserPhotoClick = { username ->
router.navigateToAnothersProfile(
requireActivity().supportFragmentManager, username
)
}
)
}
Expand Down Expand Up @@ -156,6 +165,7 @@ private fun DiscussionResponsesScreen(
onItemClick: (String, String, Boolean) -> Unit,
addCommentClick: (String) -> Unit,
onBackClick: () -> Unit,
onUserPhotoClick: (String) -> Unit
) {
val scaffoldState = rememberScaffoldState()
val scrollState = rememberLazyListState()
Expand Down Expand Up @@ -290,7 +300,11 @@ private fun DiscussionResponsesScreen(
uiState.mainComment.id,
bool
)
})
},
onUserPhotoClick = {username ->
onUserPhotoClick(username)
}
)
}
if (uiState.mainComment.childCount > 0) {
item {
Expand Down Expand Up @@ -332,7 +346,11 @@ private fun DiscussionResponsesScreen(
comment = comment,
onClick = { action, commentId, bool ->
onItemClick(action, commentId, bool)
})
},
onUserPhotoClick = {username ->
onUserPhotoClick(username)
}
)
}
}
item {
Expand Down Expand Up @@ -464,7 +482,8 @@ private fun DiscussionResponsesScreenPreview() {

},
onBackClick = {},
isClosed = false
isClosed = false,
onUserPhotoClick = {}
)
}
}
Expand Down Expand Up @@ -494,7 +513,8 @@ private fun DiscussionResponsesScreenTabletPreview() {

},
onBackClick = {},
isClosed = false
isClosed = false,
onUserPhotoClick = {}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fun ThreadMainItem(
modifier: Modifier,
thread: org.openedx.discussion.domain.model.Thread,
onClick: (String, Boolean) -> Unit,
onUserPhotoClick: (String) -> Unit
) {
val profileImageUrl = if (thread.users?.get(thread.author)?.image?.hasImage == true) {
thread.users[thread.author]?.image?.imageUrlFull
Expand Down Expand Up @@ -93,14 +94,25 @@ 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 = null,
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)
.clickable {
if (thread.author.isNotEmpty()) {
onUserPhotoClick(thread.author)
}
}
)
Spacer(Modifier.width(16.dp))
Column(
modifier = Modifier.weight(1f),
modifier = Modifier
.weight(1f)
.clickable {
if (thread.author.isNotEmpty()) {
onUserPhotoClick(thread.author)
}
},
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
Expand Down Expand Up @@ -172,6 +184,7 @@ fun CommentItem(
shape: Shape = MaterialTheme.appShapes.cardShape,
onClick: (String, String, Boolean) -> Unit,
onAddCommentClick: () -> Unit = {},
onUserPhotoClick: (String) -> Unit
) {
val profileImageUrl = if (comment.profileImage?.hasImage == true) {
comment.profileImage.imageUrlFull
Expand Down Expand Up @@ -232,15 +245,21 @@ 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 = null,
contentDescription = stringResource(id = org.openedx.core.R.string.core_accessibility_user_profile_image, comment.author),
modifier = Modifier
.size(32.dp)
.clip(CircleShape)

.clickable {
onUserPhotoClick(comment.author)
}
)
Spacer(Modifier.width(12.dp))
Column(
modifier = Modifier.weight(1f),
modifier = Modifier
.weight(1f)
.clickable {
onUserPhotoClick(comment.author)
},
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
Expand Down Expand Up @@ -323,6 +342,7 @@ fun CommentMainItem(
internalPadding: Dp = 16.dp,
comment: DiscussionComment,
onClick: (String, String, Boolean) -> Unit,
onUserPhotoClick: (String) -> Unit
) {
val profileImageUrl = if (comment.profileImage?.hasImage == true) {
comment.profileImage.imageUrlFull
Expand Down Expand Up @@ -375,15 +395,21 @@ 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 = null,
contentDescription = stringResource(id = org.openedx.core.R.string.core_accessibility_user_profile_image, comment.author),
modifier = Modifier
.size(32.dp)
.clip(CircleShape)

.clickable {
onUserPhotoClick(comment.author)
}
)
Spacer(Modifier.width(12.dp))
Column(
modifier = Modifier.weight(1f),
modifier = Modifier
.weight(1f)
.clickable {
onUserPhotoClick(comment.author)
},
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
Expand Down Expand Up @@ -642,9 +668,9 @@ private fun CommentItemPreview() {
CommentItem(
modifier = Modifier.fillMaxWidth(),
comment = mockComment,
onClick = { _, _, _ ->

})
onClick = { _, _, _ -> },
onUserPhotoClick = {}
)
}
}

Expand All @@ -653,9 +679,10 @@ private fun CommentItemPreview() {
private fun ThreadMainItemPreview() {
ThreadMainItem(
modifier = Modifier.fillMaxWidth(),
thread = mockThread, onClick = { _, _ ->

})
thread = mockThread,
onClick = { _, _ -> },
onUserPhotoClick = {}
)
}

private val mockComment = DiscussionComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ data class Account(
yearOfBirth = yearOfBirth,
levelOfEducation = levelOfEducation ?: "",
goals = goals ?: "",
languageProficiencies = languageProficiencies!!.map { it.mapToDomain() },
languageProficiencies = languageProficiencies?.let { languageProficiencyList ->
languageProficiencyList.map { it.mapToDomain() }
} ?: emptyList(),
gender = gender ?: "",
mailingAddress = mailingAddress ?: "",
email = email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class ProfileRepository(
return account.mapToDomain()
}

suspend fun getAccount(username: String): Account {
val account = api.getAccount(username)
return account.mapToDomain()
}

fun getCachedAccount() : Account? {
return profilePreferences.profile?.mapToDomain()
}
Expand Down
Loading

0 comments on commit 0557842

Please sign in to comment.