In my Database i have a table called Account
which looks kinda like this
@Entity(tableName = "accounts", primaryKeys = ["server_id", "account_id"])
data class Account(
@ColumnInfo(name = "server_id")
val serverId: Long,
@ColumnInfo(name = "account_id")
val accountId: Int,
@ColumnInfo(name = "first_name", defaultValue = "")
var firstname: String
)
So lets say that we have the following Database snapshot
server_id account_id first_name 1 10 Zak 1 11 Tom 1 12 Bob 1 13 Jim 1 14 Mike
Now i also have the following POJO which represents an available video room inside a chatRoom
data class RoomInfo(
@SerializedName("m")
val participantIntList: List<Int>,
@SerializedName("o")
val roomId: String,
@SerializedName("s")
val status: Int
)
So i get an incoming response from my Socket which is like the following
[
{"m": [10, 11, 12], "o": "room_technical", "s": 1},
{"m": [13, 14], "o": "room_operation", "s": 1}
]
which i map it in a List so i have
val roomInfo: LiveData<List<RoomInfo>> = socketManager.roomInfo
// So the value is basically the json converted to a list of RoomInfos using Gson
In order to display this available list of Rooms to the User i need to convert the m (which is the members that are inside the room right now) from accountIds to account.firstnames.
So what i want to have finally is a List of a new object called RoomInfoItem which will hold the list of the rooms with the accountIds converted to firstNames from the Account table of the Database.
data class RoomInfoItem(
val roomInfo: RoomInfo,
val participantNames: List<String>
)
So if we make the transformation we need to have the following result
RoomInfo (
// RoomInfo
{"m": [10, 11, 12], "o": "room_technical", "s": 1},
// Participant names
["Zak", "Tom", "Bob"]
)
RoomInfo (
// RoomInfo
{"m": [13, 14], "o": "room_operation", "s": 1},
// Participant names
["Jim", "Mike"]
)
My Activity needs to observe a LiveData with the RoomInfoItems so what i want is given the LiveData<List> to transform it to LiveData<List>. How can i do that?
> ? It means when some of RoomInfo will changed then you will call getParticipantNames for each item in list and you will observe changes of all data ... Or maybe when user do something u need observe data only for one RoomInfo object (RoomInfoItem) ?
– Artem Viter Jun 14 '21 at 12:44>. In every roomInfo there is a List (accountIds). I want to Transform the LiveData
– james04 Jun 14 '21 at 15:51> to LiveData
>. So for every roomInfo in the initial List i need to access the Database.