Commit b1881e24 authored by 吳展維's avatar 吳展維
Browse files

multifocus

No related merge requests found
Showing with 63 additions and 0 deletions
+63 -0
package com.example.jetsnack.model
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
class FocusRoom(val id1: String, val id2: String, val id3:String ,val id4:String, val roomId:String,val start:Boolean) : Parcelable {
constructor() : this("", "", "", "","",false)
}
\ No newline at end of file
......@@ -17,6 +17,7 @@
package com.example.jetsnack.ui.home
import android.content.res.Configuration
import android.net.Uri
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
......@@ -44,8 +45,16 @@ import androidx.navigation.NavHostController
import com.example.jetsnack.R
import com.example.jetsnack.database.Dogs
import com.example.jetsnack.database.Select_index
import com.example.jetsnack.model.FocusRoom
import com.example.jetsnack.models.User
import com.example.jetsnack.ui.components.JetsnackDivider
import com.example.jetsnack.ui.theme.*
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import kotlinx.android.synthetic.main.activity_main.*
import java.time.format.TextStyle
@OptIn(ExperimentalComposeUiApi::class)
......@@ -494,7 +503,52 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
)
}
}
var Isfull=false
fun multiFocusBuild(roomId:String,id1:String){
val uid = FirebaseAuth.getInstance().uid ?: ""
val ref = FirebaseDatabase.getInstance().getReference("/focusRooms/$uid")
val focusRoom = FocusRoom(id1,"" , "", "",roomId,false)
ref.setValue(focusRoom)
}
fun enterFocusRoom(invitedId:String,RoomId:String){
val ref = FirebaseDatabase.getInstance().getReference("/focusRooms")
ref.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(p0: DataSnapshot) {
// Get Post object and use the values to update the UI
p0.children.forEach {
val room = it.getValue(FocusRoom::class.java)
if (room != null) {
if(room.id2!=""){
val ref2 = FirebaseDatabase.getInstance().getReference("/focusRooms/$RoomId/id2")
ref2.setValue(invitedId)
}
else if(room.id2!=""){
val ref2 = FirebaseDatabase.getInstance().getReference("/focusRooms/$RoomId/id2")
ref2.setValue(invitedId)
}
else if(room.id3!=""){
val ref2 = FirebaseDatabase.getInstance().getReference("/focusRooms/$RoomId/id3")
ref2.setValue(invitedId)
}
else if(room.id4!=""){
val ref2 = FirebaseDatabase.getInstance().getReference("/focusRooms/$RoomId/id4")
ref2.setValue(invitedId)
}
else {
Isfull=true
}
}
}
}
override fun onCancelled(error: DatabaseError) {
}
})
}
fun multiFocusStart(RoomId:String){
val ref = FirebaseDatabase.getInstance().getReference("/focusRooms/$RoomId/start")
ref.setValue(true)
}
@Preview("defa", showBackground = true)
@Composable
fun MulModeHostPreview() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment