-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.kt
More file actions
380 lines (362 loc) · 13.1 KB
/
Copy pathMainActivity.kt
File metadata and controls
380 lines (362 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
package com.example.jitsimeet
//import android.content.Context
//import android.content.Intent
//import android.os.Bundle
//import android.widget.Toast
//import androidx.activity.ComponentActivity
//import androidx.activity.compose.setContent
//import androidx.compose.foundation.layout.*
//import androidx.compose.material3.Button
//import androidx.compose.material3.OutlinedTextField
//import androidx.compose.material3.Text
//import androidx.compose.runtime.*
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.platform.LocalContext
//import androidx.compose.ui.text.input.TextFieldValue
//import androidx.compose.ui.tooling.preview.Preview
//import androidx.compose.ui.unit.dp
//import com.google.firebase.Firebase
//import com.google.firebase.auth.auth
//import com.google.firebase.initialize
//import org.jitsi.meet.sdk.JitsiMeet
//import org.jitsi.meet.sdk.JitsiMeetActivity
//import org.jitsi.meet.sdk.JitsiMeetConferenceOptions
//import java.net.URL
//
//import android.content.BroadcastReceiver
//import android.content.IntentFilter
//import androidx.compose.material3.TextField
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.getValue
//import org.jitsi.meet.sdk.BroadcastEvent
//import org.jitsi.meet.sdk.BroadcastIntentHelper
//import timber.log.Timber
//import java.net.MalformedURLException
//
//class MainActivity : ComponentActivity() {
//
//// private val broadcastReceiver = MyBroadcastReceiver()
// private var isReceiverRegistered = false
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// val serverURL: URL
// serverURL = try {
// // When using JaaS, replace "https://meet.jit.si" with the proper serverURL
// URL("https://meet.jit.si")
// } catch (e: MalformedURLException) {
// e.printStackTrace()
// throw RuntimeException("Invalid server URL!")
// }
// val isReceiverRegistered = savedInstanceState?.getBoolean(KEY_RECEIVER_REGISTERED, false) ?: false
//
// val defaultOptions = JitsiMeetConferenceOptions.Builder()
// .setServerURL(serverURL)
// // When using JaaS, set the obtained JWT here
// //.setToken("MyJWT")
// // Different features flags can be set
// //.setFeatureFlag("toolbox.enabled", false)
// //.setFeatureFlag("filmstrip.enabled", false)
// .setFeatureFlag("welcomepage.enabled", false)
// .build()
// JitsiMeet.setDefaultConferenceOptions(defaultOptions)
// registerReceiverIfNeeded()
//
//// registerForBroadcastMessages()
// setContent {
// MyApp()
// }
// }
//
// private fun registerReceiverIfNeeded() {
// if (!isReceiverRegistered) {
// val intentFilter = IntentFilter().apply {
// // Add appropriate actions to the intent filter
// }
// registerReceiver(broadcastReceiver, intentFilter)
// isReceiverRegistered = true
// }
// }
// override fun onSaveInstanceState(outState: Bundle) {
// // Save the receiver registration state
// outState.putBoolean(KEY_RECEIVER_REGISTERED, isReceiverRegistered)
// super.onSaveInstanceState(outState)
// }
//
// inner class MyBroadcastReceiver : BroadcastReceiver() {
// override fun onReceive(context: Context?, intent: Intent?) {
// onBroadcastReceived(intent)
// }
// }
//
// private fun registerForBroadcastMessages() {
// val intentFilter = IntentFilter()
//
// for (type in BroadcastEvent.Type.values()) {
// intentFilter.addAction(type.action)
// }
//
// registerReceiver(broadcastReceiver, intentFilter)
// }
//
// override fun onDestroy() {
// unregisterReceiver(broadcastReceiver)
// super.onDestroy()
// }
//
// private val broadcastReceiver = object : BroadcastReceiver() {
// override fun onReceive(context: Context?, intent: Intent?) {
// onBroadcastReceived(intent)
// }
// }
//
// private fun onBroadcastReceived(intent: Intent?) {
// if (intent != null) {
// val event = BroadcastEvent(intent)
// when (event.type) {
// BroadcastEvent.Type.CONFERENCE_JOINED -> Timber.i("Conference Joined with url%s", event.getData()["url"])
// BroadcastEvent.Type.PARTICIPANT_JOINED -> Timber.i("Participant joined%s", event.getData()["name"])
// else -> Timber.i("Received event: %s", event.type)
// }
// }
// }
//
// private fun hangUp() {
// val hangupBroadcastIntent: Intent = BroadcastIntentHelper.buildHangUpIntent()
// sendBroadcast(hangupBroadcastIntent)
// }
// companion object {
// private const val KEY_RECEIVER_REGISTERED = "receiver_registered"
// }
//}
//
//@Composable
//fun MyApp() {
// val context = LocalContext.current
// var conferenceName by remember { mutableStateOf("") }
//
// Column(
// modifier = Modifier
// .fillMaxSize()
// .padding(16.dp),
// verticalArrangement = Arrangement.Top,
// horizontalAlignment = Alignment.CenterHorizontally
// ) {
// Button(
// onClick = {
// // Handle favorites button click
// Toast.makeText(context, "Favorites clicked!", Toast.LENGTH_SHORT).show()
// val intent = Intent(context, FavoritesActivity::class.java)
// context.startActivity(intent)
// }
// ) {
// Text("Favorites")
// }
// Spacer(modifier = Modifier.height(16.dp))
// Column(
// modifier = Modifier
// .fillMaxWidth()
// .padding(horizontal = 16.dp),
// verticalArrangement = Arrangement.Center,
// horizontalAlignment = Alignment.CenterHorizontally
// ) {
// Text("Enter Conference Name:")
// Spacer(modifier = Modifier.height(8.dp))
// TextField(
// value = conferenceName,
// onValueChange = { conferenceName = it },
// label = { Text("Conference Name") },
// modifier = Modifier.fillMaxWidth()
// )
// Spacer(modifier = Modifier.height(16.dp))
// Button(
// onClick = {
// if (conferenceName.isNotBlank()) {
// joinConference(context, conferenceName)
// }
// }
// ) {
// Text("Join Conference")
// }
// }
// }
//}
//
//
//fun joinConference(context: Context, conferenceName: String) {
// val options = JitsiMeetConferenceOptions.Builder()
// .setRoom(conferenceName)
// .build()
// JitsiMeetActivity.launch(context, options)
//}
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.room.Room
import com.google.firebase.auth.FirebaseAuth
import java.io.Serializable
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// enableEdgeToEdge()
// val db = Room.databaseBuilder(
// applicationContext,
// AppDatabase::class.java, "database-name"
// ).build()
// val userDao = db.userDao()
setContent {
// LoginActivityTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
MyApp(FirebaseAuth.getInstance())
// }
}
}
}
}
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
@Composable
fun MyApp(auth: FirebaseAuth) {
val context = LocalContext.current
var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var confirmPassword by remember { mutableStateOf("") }
var isLogin by remember { mutableStateOf(true) }
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Jitsi Meet",
style = MaterialTheme.typography.displayMedium,
modifier = Modifier.padding(bottom = 16.dp)
.align(Alignment.CenterHorizontally)
)
Spacer(modifier = Modifier.height(50.dp))
OutlinedTextField(
value = email,
onValueChange = { email = it },
label = { Text("Email") },
modifier = Modifier.fillMaxWidth()
)
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(
value = password,
onValueChange = { password = it },
label = { Text("Password") },
modifier = Modifier.fillMaxWidth(),
visualTransformation = PasswordVisualTransformation()
)
Spacer(modifier = Modifier.height(16.dp))
if (!isLogin) {
OutlinedTextField(
value = confirmPassword,
onValueChange = { confirmPassword = it },
label = { Text("Confirm Password") },
modifier = Modifier.fillMaxWidth(),
visualTransformation = PasswordVisualTransformation()
)
Spacer(modifier = Modifier.height(16.dp))
}
Button(
onClick = {
if (isLogin) {
// Sign in with Firebase
signInWithFirebase(auth, email, password, context)
} else {
// Register with Firebase
registerWithFirebase(auth, email, password, context)
}
},
modifier = Modifier.fillMaxWidth()
) {
Text(if (isLogin) "Login" else "Register")
}
Spacer(modifier = Modifier.height(16.dp))
TextButton(
onClick = { isLogin = !isLogin },
modifier = Modifier.align(Alignment.CenterHorizontally)
) {
Text(if (isLogin) "Need an account? Register" else "Already have an account? Login")
}
}
}
private fun signInWithFirebase(
auth: FirebaseAuth,
email: String,
password: String,
// userDao: UserDao,
context: Context
) {
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(context as Activity) { task ->
if (task.isSuccessful) {
Log.d("login", "signInWithFirebase:success")
Toast.makeText(context, "Login successful", Toast.LENGTH_SHORT).show()
val intent = Intent(context, LoginActivity::class.java)
// intent.putExtra("dao", userDao)
context.startActivity(intent)
} else {
// Login failed, show an error message
Toast.makeText(context, "Login failed", Toast.LENGTH_SHORT).show()
}
}
}
private fun registerWithFirebase(
auth: FirebaseAuth,
email: String,
password: String,
context: Context
) {
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(context as Activity) { task ->
if (task.isSuccessful) {
// Registration successful
// You might want to automatically sign in the user after registration
// For now, just show a toast
Log.d("register", "registerWithFirebase:success")
Toast.makeText(context, "Registration successful", Toast.LENGTH_SHORT).show()
} else {
// Registration failed, show an error message
Toast.makeText(context, "Registration failed", Toast.LENGTH_SHORT).show()
}
}
}