Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
吳展維
final
Commits
f7d312b0
Commit
f7d312b0
authored
2 years ago
by
黃盛揚
Browse files
Options
Download
Email Patches
Plain Diff
update
parent
c78b7d23
master
main
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/com/example/jetsnack/model/FocusRoom.kt
+2
-1
app/src/main/java/com/example/jetsnack/model/FocusRoom.kt
app/src/main/java/com/example/jetsnack/ui/home/多人模式.kt
+48
-23
app/src/main/java/com/example/jetsnack/ui/home/多人模式.kt
with
50 additions
and
24 deletions
+50
-24
app/src/main/java/com/example/jetsnack/model/FocusRoom.kt
View file @
f7d312b0
...
...
@@ -4,6 +4,7 @@ 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
,
val
sec
:
Int
)
:
Parcelable
{
class
FocusRoom
(
val
id1
:
String
,
val
id2
:
String
,
val
id3
:
String
,
val
id4
:
String
,
val
roomId
:
String
,
val
start
:
Boolean
,
var
sec
:
Int
)
:
Parcelable
{
constructor
()
:
this
(
""
,
""
,
""
,
""
,
""
,
false
,
0
)
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/src/main/java/com/example/jetsnack/ui/home/多人模式.kt
View file @
f7d312b0
...
...
@@ -16,8 +16,10 @@
package
com.example.jetsnack.ui.home
import
android.annotation.SuppressLint
import
android.content.res.Configuration
import
android.net.Uri
import
android.util.Log
import
androidx.compose.foundation.*
import
androidx.compose.foundation.layout.*
import
androidx.compose.foundation.shape.CircleShape
...
...
@@ -54,21 +56,26 @@ 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
kotlinx.coroutines.delay
import
java.time.format.TextStyle
import
kotlin.time.Duration.Companion.seconds
@SuppressLint
(
"UnrememberedMutableState"
)
@OptIn
(
ExperimentalComposeUiApi
::
class
)
@Composable
fun
MulModeHost
(
modifier
:
Modifier
=
Modifier
,
navController
:
NavHostController
)
{
var
showAlertDialog1
by
remember
{
mutableStateOf
(
false
)
}
var
showAlertDialog2
by
remember
{
mutableStateOf
(
false
)
}
var
showAlertDialog3
by
remember
{
mutableStateOf
(
false
)
}
var
reset
by
remember
{
mutableStateOf
(
false
)
}
var
total
by
remember
{
mutableStateOf
(
focusRoom
.
sec
)
}
total
=
focusRoom
.
sec
var
focus_state
by
remember
{
mutableStateOf
<
Hours
>(
FullHours
(
1
,
30
))
}
va
r
focus_hour
by
remember
{
mutableStateOf
(
1
)
}
va
r
focus_min
by
remember
{
mutableStateOf
(
30
)
}
va
l
focus_hour
=
total
/
3600
va
l
focus_min
=
(
total
%
3600
)
/
60
var
rest_state
by
remember
{
mutableStateOf
<
Hours
>(
FullHours
(
2
,
0
))
}
var
rest_min
by
remember
{
mutableStateOf
(
2
)
}
var
rest_sec
by
remember
{
mutableStateOf
(
0
)
}
var
total
by
remember
{
mutableStateOf
(
0
)
}
Column
(
horizontalAlignment
=
Alignment
.
CenterHorizontally
)
{
val
selectindex
by
remember
{
mutableStateOf
(
Select_index
)
}
Spacer
(
Modifier
.
height
(
48
.
dp
))
...
...
@@ -82,6 +89,12 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
.
background
(
Shadow0
)
.
padding
(
10
.
dp
)
)
{
LaunchedEffect
(
Unit
)
{
while
(
true
)
{
delay
(
1
.
seconds
)
reset
=
!
reset
}
}
/*Spacer(Modifier.height(48.dp))*/
Row
(
modifier
=
Modifier
...
...
@@ -194,7 +207,9 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
)
{
Column
(
horizontalAlignment
=
Alignment
.
CenterHorizontally
,
modifier
=
Modifier
.
clickable
{
if
(
user
.
id
==
focusRoom
.
id1
)
showAlertDialog1
=
true
}
modifier
=
Modifier
.
clickable
{
if
(
user
.
id
==
focusRoom
.
id1
)
showAlertDialog1
=
true
}
)
{
Text
(
text
=
"專注計時器"
,
fontSize
=
20
.
sp
)
Divider
(
...
...
@@ -202,7 +217,10 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
color
=
Color
.
Gray
,
thickness
=
1
.
dp
,
)
Text
(
text
=
String
.
format
(
" %02d:%02d ▼"
,
focus_hour
,
focus_min
),
fontSize
=
24
.
sp
)
Text
(
text
=
String
.
format
(
" %02d:%02d ▼"
,
focus_hour
,
focus_min
),
fontSize
=
24
.
sp
)
}
/*Spacer(Modifier.width(40.dp))
Column(
...
...
@@ -225,8 +243,8 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
Shadow4
)
.
clickable
{
total
=
focus_hour
*
3600
+
focus_min
*
60
navController
.
navigate
(
"focusProcessMul/$
total
"
)
multiFocusStart
(
focusRoom
.
roomId
)
navController
.
navigate
(
"focusProcessMul/$
{focusRoom.sec}
"
)
}
)
{
Text
(
text
=
"多人開始"
,
color
=
Color
.
White
,
fontSize
=
20
.
sp
)
...
...
@@ -328,9 +346,9 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
colors
=
ButtonDefaults
.
buttonColors
(
Shadow3
),
modifier
=
Modifier
.
width
(
100
.
dp
),
onClick
=
{
total
=
focus_state
.
hours
*
3600
+
focus_state
.
minutes
*
60
timeUpdate
(
total
,
focusRoom
.
roomId
)
showAlertDialog1
=
false
focus_hour
=
focus_state
.
hours
focus_min
=
focus_state
.
minutes
}
)
{
Text
(
"確定"
,
fontSize
=
18
.
sp
)
...
...
@@ -486,7 +504,7 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
Text
(
text
=
focusRoom
.
roomId
,
fontSize
=
23
.
sp
,
color
=
Color
(
0xff000000
),
letterSpacing
=
3
.
sp
color
=
Color
(
0xff000000
),
letterSpacing
=
3
.
sp
)
Spacer
(
Modifier
.
height
(
20
.
dp
))
}
...
...
@@ -500,44 +518,48 @@ fun MulModeHost(modifier: Modifier = Modifier, navController: NavHostController)
)
}
}
fun
gethash
(
id
:
String
):
String
{
return
id
.
substring
(
0
,
6
)
fun
gethash
(
id
:
String
):
String
{
return
id
.
substring
(
0
,
6
)
}
fun
multiFocusBuild
(
id1
:
String
){
fun
multiFocusBuild
(
id1
:
String
)
{
val
id
=
gethash
(
user
.
id
)
val
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
"/focusRooms/$id"
)
focusRoom
=
FocusRoom
(
id1
,
""
,
""
,
""
,
id
,
false
,
900
)
focusRoom
=
FocusRoom
(
id1
,
""
,
""
,
""
,
id
,
false
,
900
)
MutipleFocus
.
START
=
false
MutipleFocus
.
Isfull
=
false
MutipleFocus
.
nowTime
=
900
ref
.
setValue
(
focusRoom
)
val
ref1
=
FirebaseDatabase
.
getInstance
().
getReference
(
"/focusRooms"
)
ref1
.
add
ListenerForSingle
ValueEvent
(
object
:
ValueEventListener
{
ref1
.
addValueEvent
Listener
(
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
.
roomId
==
id
)
{
focusRoom
=
room
if
(
room
.
roomId
==
id
)
{
focusRoom
=
room
}
}
}
}
override
fun
onCancelled
(
error
:
DatabaseError
)
{
}
})
}
fun
enterFocusRoom
(
invitedId
:
String
,
RoomId
:
String
){
fun
enterFocusRoom
(
invitedId
:
String
,
RoomId
:
String
)
{
val
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
"/focusRooms"
)
ref
.
add
ListenerForSingle
ValueEvent
(
object
:
ValueEventListener
{
ref
.
addValueEvent
Listener
(
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
.
roomId
==
RoomId
)
{
if
(
room
.
roomId
==
RoomId
)
{
MutipleFocus
.
correct
=
true
if
(
room
.
id2
==
""
)
{
val
ref2
=
FirebaseDatabase
.
getInstance
()
...
...
@@ -554,25 +576,28 @@ fun enterFocusRoom(invitedId:String,RoomId:String){
}
else
{
MutipleFocus
.
Isfull
=
true
}
focusRoom
=
room
focusRoom
=
room
}
}
}
}
override
fun
onCancelled
(
error
:
DatabaseError
)
{
}
})
}
fun
multiFocusStart
(
RoomId
:
String
){
fun
multiFocusStart
(
RoomId
:
String
)
{
val
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
"/focusRooms/$RoomId/start"
)
ref
.
setValue
(
true
)
}
fun
timeUpdate
(
sec
:
Int
,
RoomId
:
String
){
fun
timeUpdate
(
sec
:
Int
,
RoomId
:
String
)
{
val
ref
=
FirebaseDatabase
.
getInstance
().
getReference
(
"/focusRooms/$RoomId/sec"
)
ref
.
setValue
(
sec
)
}
@Preview
(
"defa"
,
showBackground
=
true
)
@Composable
fun
MulModeHostPreview
()
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help