Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ole.planet.myplanet.model

data class ChatShareTargets(
val community: RealmMyTeam?,
val teams: List<RealmMyTeam>,
val enterprises: List<RealmMyTeam>,
val community: TeamSummary?,
val teams: List<TeamSummary>,
val enterprises: List<TeamSummary>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.ole.planet.myplanet.model

data class TeamSummary(
val _id: String,
val name: String,
val teamType: String?,
val teamPlanetCode: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.ole.planet.myplanet.model.RealmMyLibrary
import org.ole.planet.myplanet.model.RealmMyTeam
import org.ole.planet.myplanet.model.RealmTeamTask
import org.ole.planet.myplanet.model.RealmUser
import org.ole.planet.myplanet.model.TeamSummary
import org.ole.planet.myplanet.model.Transaction

data class JoinedMemberData(
Expand Down Expand Up @@ -40,15 +41,19 @@ interface TeamsRepository {
suspend fun markTeamUploaded(teamId: String?, rev: String)
suspend fun getAllActiveTeams(): List<RealmMyTeam>
suspend fun getMyTeamsFlow(userId: String): Flow<List<RealmMyTeam>>
@Deprecated("Use getTeamSummaries instead", ReplaceWith("getTeamSummaries()"))
suspend fun getShareableTeams(): List<RealmMyTeam>
suspend fun getTeamSummaries(): List<TeamSummary>
suspend fun getShareableEnterprises(): List<RealmMyTeam>
suspend fun getShareableEnterpriseSummaries(): List<TeamSummary>
suspend fun getTeamResources(teamId: String): List<RealmMyLibrary>
suspend fun getTeamCourses(teamId: String): List<RealmMyCourse>
suspend fun addCoursesToTeam(teamId: String, courseIds: List<String>)
suspend fun getTeamByDocumentIdOrTeamId(id: String): RealmMyTeam?
suspend fun getTeamByIdOrTeamId(id: String): RealmMyTeam?
suspend fun getTeamLinks(): List<RealmMyTeam>
suspend fun getTeamById(teamId: String): RealmMyTeam?
suspend fun getTeamSummaryById(teamId: String): TeamSummary?
suspend fun getTaskTeamInfo(taskId: String): Triple<String, String, String>?
suspend fun getJoinRequestTeamId(requestId: String): String?
suspend fun getTaskNotifications(userId: String?): List<Triple<String, String, String>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.ole.planet.myplanet.model.RealmMyTeam
import org.ole.planet.myplanet.model.RealmTeamLog
import org.ole.planet.myplanet.model.RealmTeamTask
import org.ole.planet.myplanet.model.RealmUser
import org.ole.planet.myplanet.model.TeamSummary
import org.ole.planet.myplanet.model.Transaction
import org.ole.planet.myplanet.services.UploadManager
import org.ole.planet.myplanet.services.UserSessionManager
Expand Down Expand Up @@ -155,6 +156,7 @@ class TeamsRepositoryImpl @Inject constructor(
}
}

@Deprecated("Use getTeamSummaries instead", ReplaceWith("getTeamSummaries()"))
override suspend fun getShareableTeams(): List<RealmMyTeam> {
return queryList(RealmMyTeam::class.java) {
isEmpty("teamId")
Expand All @@ -163,6 +165,14 @@ class TeamsRepositoryImpl @Inject constructor(
}
}

override suspend fun getTeamSummaries(): List<TeamSummary> {
// Delegation to Realm-returning method is intentional and solely for type isolation at the boundary.
return getShareableTeams().mapNotNull { team ->
val id = team._id ?: return@mapNotNull null
TeamSummary(id, team.name ?: "", team.teamType, team.teamPlanetCode)
}
}

override suspend fun getShareableEnterprises(): List<RealmMyTeam> {
return queryList(RealmMyTeam::class.java) {
isEmpty("teamId")
Expand All @@ -171,6 +181,14 @@ class TeamsRepositoryImpl @Inject constructor(
}
}

override suspend fun getShareableEnterpriseSummaries(): List<TeamSummary> {
// Delegation to Realm-returning method is intentional and solely for type isolation at the boundary.
return getShareableEnterprises().mapNotNull { team ->
val id = team._id ?: return@mapNotNull null
TeamSummary(id, team.name ?: "", team.teamType, team.teamPlanetCode)
}
}

override suspend fun getTeamResources(teamId: String): List<RealmMyLibrary> {
val resourceIds = getResourceIds(teamId)
val linkedResources = if (resourceIds.isEmpty()) {
Expand Down Expand Up @@ -244,6 +262,13 @@ class TeamsRepositoryImpl @Inject constructor(
return findByField(RealmMyTeam::class.java, "_id", teamId)
}

override suspend fun getTeamSummaryById(teamId: String): TeamSummary? {
// Delegation to Realm-returning method is intentional and solely for type isolation at the boundary.
val team = getTeamById(teamId) ?: return null
val id = team._id ?: return null
return TeamSummary(id, team.name ?: "", team.teamType, team.teamPlanetCode)
}

override suspend fun getTaskTeamInfo(taskId: String): Triple<String, String, String>? {
val task = findByField(RealmTeamTask::class.java, "id", taskId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.ole.planet.myplanet.model.RealmChatHistory
import org.ole.planet.myplanet.model.RealmConversation
import org.ole.planet.myplanet.model.RealmMyTeam
import org.ole.planet.myplanet.model.RealmNews
import org.ole.planet.myplanet.model.TeamSummary
import org.ole.planet.myplanet.model.RealmUser
import org.ole.planet.myplanet.ui.teams.TeamsSelectionAdapter
import org.ole.planet.myplanet.utils.DiffUtils
Expand Down Expand Up @@ -245,7 +246,7 @@ class ChatHistoryAdapter(
}
}

private fun showGrandChildRecyclerView(items: List<RealmMyTeam>, section: String, realmChatHistory: RealmChatHistory) {
private fun showGrandChildRecyclerView(items: List<TeamSummary>, section: String, realmChatHistory: RealmChatHistory) {
val grandChildDialogBinding = GrandChildRecyclerviewDialogBinding.inflate(LayoutInflater.from(context))
var dialog: AlertDialog? = null

Expand Down Expand Up @@ -274,7 +275,7 @@ class ChatHistoryAdapter(
dialog.show()
}

private fun showEditTextAndShareButton(team: RealmMyTeam? = null, section: String, chatHistory: RealmChatHistory) {
private fun showEditTextAndShareButton(team: TeamSummary? = null, section: String, chatHistory: RealmChatHistory) {
val addNoteDialogBinding = AddNoteDialogBinding.inflate(LayoutInflater.from(context))
val builder = AlertDialog.Builder(context, R.style.AlertDialogTheme)
builder.setView(addNoteDialogBinding.root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,14 @@ class ChatHistoryFragment : Fragment() {
}

private suspend fun loadShareTargets(parentCode: String?, communityName: String?): ChatShareTargets {
val teams = teamsRepository.getShareableTeams()
val enterprises = teamsRepository.getShareableEnterprises()
val teams = teamsRepository.getTeamSummaries()
val enterprises = teamsRepository.getShareableEnterpriseSummaries()
val communityId = if (!communityName.isNullOrBlank() && !parentCode.isNullOrBlank()) {
"$communityName@$parentCode"
} else {
null
}
val community = communityId?.let { teamsRepository.getTeamById(it) }
val community = communityId?.let { teamsRepository.getTeamSummaryById(it) }
return ChatShareTargets(community, teams, enterprises)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import android.widget.TextView
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.model.RealmMyTeam
import org.ole.planet.myplanet.model.TeamSummary
import org.ole.planet.myplanet.utils.DiffUtils

class TeamsSelectionAdapter(private val section: String, private val onClick: (RealmMyTeam) -> Unit) :
ListAdapter<RealmMyTeam, TeamsSelectionAdapter.TeamSelectionViewHolder>(
DiffUtils.itemCallback<RealmMyTeam>(
class TeamsSelectionAdapter(private val section: String, private val onClick: (TeamSummary) -> Unit) :
ListAdapter<TeamSummary, TeamsSelectionAdapter.TeamSelectionViewHolder>(
DiffUtils.itemCallback<TeamSummary>(
{ old, new -> old._id == new._id },
{ old, new -> old.name == new.name }
)
Expand All @@ -22,7 +22,7 @@ class TeamsSelectionAdapter(private val section: String, private val onClick: (R
private val textView: TextView = itemView.findViewById(R.id.textView)
private val teamIcon: ImageView = itemView.findViewById(R.id.teamIcon)

fun bind(item: RealmMyTeam) {
fun bind(item: TeamSummary) {
textView.text = item.name
if (section == itemView.context.getString(R.string.teams)) {
teamIcon.setImageResource(R.drawable.team)
Expand Down