Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- App Link-->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" android:host="resonate.aossie.org" android:pathPrefix="/room" />
<data android:scheme="https" android:host="resonate.aossie.org" android:pathPrefix="/room" />
</intent-filter>
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
Expand Down
9 changes: 9 additions & 0 deletions lib/controllers/auth_state_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class AuthStateController extends GetxController {
await setUserProfileData();
}

Future<bool> get getLoginState async {
try{
appwriteUser = await account.get();
return true;
}catch(e){
return false;
}
}

Future<void> setUserProfileData() async {
isInitializing.value = true;
try {
Expand Down
66 changes: 49 additions & 17 deletions lib/controllers/rooms_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ class RoomsController extends GetxController {
await getRooms();
}

Future<AppwriteRoom> createRoomObject(Document room, String userUid) async{
// Get three particpant data to use for memberAvatar widget
var participantCollectionRef = await databases.listDocuments(
databaseId: masterDatabaseId,
collectionId: participantsCollectionId,
queries: [Query.equal("roomId", room.data["\$id"]), Query.limit(3)]);
List<String> memberAvatarUrls = [];
for (var p in participantCollectionRef.documents) {
Document participantDoc = await databases.getDocument(
databaseId: userDatabaseID, collectionId: usersCollectionID, documentId: p.data["uid"]);
memberAvatarUrls.add(participantDoc.data["profileImageUrl"]);
}

// Create appwrite room object and add it to rooms list
AppwriteRoom appwriteRoom = AppwriteRoom(
id: room.data['\$id'],
name: room.data["name"],
description: room.data["description"],
totalParticipants: room.data["totalParticipants"],
tags: room.data["tags"],
memberAvatarUrls: memberAvatarUrls,
state: RoomState.live,
isUserAdmin: room.data["adminUid"] == userUid);

return appwriteRoom;
}

Future<void> getRooms() async {
try {
isLoading.value = true;
Expand All @@ -38,17 +65,7 @@ class RoomsController extends GetxController {
await databases.listDocuments(databaseId: masterDatabaseId, collectionId: roomsCollectionId);

for (var room in roomsCollectionRef.documents) {

// Get three particpant data to use for memberAvatar widget
var participantCollectionRef = await databases.listDocuments(databaseId: masterDatabaseId, collectionId: participantsCollectionId, queries:[Query.equal("roomId", room.data["\$id"]), Query.limit(3)]);
List<String> memberAvatarUrls = [];
for (var p in participantCollectionRef.documents){
Document participantDoc = await databases.getDocument(databaseId: userDatabaseID, collectionId: usersCollectionID, documentId: p.data["uid"]);
memberAvatarUrls.add(participantDoc.data["profileImageUrl"]);
}

// Create appwrite room object and add it to rooms list
AppwriteRoom appwriteRoom = AppwriteRoom(id: room.data['\$id'], name: room.data["name"], description: room.data["description"], totalParticipants: room.data["totalParticipants"], tags: room.data["tags"], memberAvatarUrls: memberAvatarUrls, state: RoomState.live, isUserAdmin: room.data["adminUid"] == userUid);
AppwriteRoom appwriteRoom = await createRoomObject(room, userUid);
rooms.add(appwriteRoom);
}
update();
Expand All @@ -59,26 +76,41 @@ class RoomsController extends GetxController {
}
}

Future getRoomById(String roomId) async {
try {
Document room = await databases.getDocument(
databaseId: masterDatabaseId, collectionId: roomsCollectionId, documentId: roomId);
String userUid = Get.find<AuthStateController>().uid!;

AppwriteRoom appwriteRoom = await createRoomObject(room, userUid);
return appwriteRoom;
} catch (e) {
log(e.toString());
}
}

Future<void> joinRoom({required AppwriteRoom room}) async {
try{
try {
// Display Loading Dialog
Get.dialog(
Center(child: LoadingAnimationWidget.threeRotatingDots(color: Colors.amber, size: Get.pixelRatio*20),),
Center(
child: LoadingAnimationWidget.threeRotatingDots(color: Colors.amber, size: Get.pixelRatio * 20),
),
barrierDismissible: false,
name: "Loading Dialog"
);
name: "Loading Dialog");

// Get the token and livekit url and join livekit room
AuthStateController authStateController = Get.find<AuthStateController>();
String myDocId = await RoomService.joinRoom(roomId: room.id, userId: authStateController.uid!, isAdmin: room.isUserAdmin);
String myDocId =
await RoomService.joinRoom(roomId: room.id, userId: authStateController.uid!, isAdmin: room.isUserAdmin);
room.myDocId = myDocId;

// Close the loading dialog
Get.back();

// Open the Room Bottom Sheet to interact in the room
Get.find<TabViewController>().openRoomSheet(room);
}catch(e){
} catch (e) {
log(e.toString());
// Close the loading dialog
Get.back();
Expand Down
60 changes: 58 additions & 2 deletions lib/controllers/tabview_controller.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import 'dart:async';
import 'dart:developer';

import 'package:app_links/app_links.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:resonate/controllers/auth_state_controller.dart';
import 'package:resonate/controllers/rooms_controller.dart';
import 'package:resonate/models/appwrite_room.dart';
import 'package:resonate/utils/colors.dart';
import 'package:resonate/views/widgets/room_tile.dart';

import '../views/screens/room_screen.dart';

Expand All @@ -10,6 +17,57 @@ class TabViewController extends GetxController {
getIndex() => _selectedIndex.value;
setIndex(index) => _selectedIndex.value = index;

late AppLinks _appLinks;
StreamSubscription<Uri>? _linkSubscription;

@override
void onInit() {
super.onInit();
initAppLinks();
}

@override
void onDispose() {
_linkSubscription?.cancel();
super.dispose();
}

Future<void> initAppLinks() async {
_appLinks = AppLinks();

// Check initial link if app was in cold state (terminated)
final appLink = await _appLinks.getInitialAppLink();
if (appLink != null) {
log('getInitialAppLink: $appLink');
openAppLink(appLink);
}

// Handle link when app is in warm state (front or background)
_linkSubscription = _appLinks.uriLinkStream.listen((uri) {
log('onAppLink: $uri');
openAppLink(uri);
});
}

void openAppLink(Uri uri) async {
try {
String roomId = uri.pathSegments.last;
bool isUserLoggedIn = await Get.find<AuthStateController>().getLoginState;
if (isUserLoggedIn) {
AppwriteRoom appwriteRoom = await Get.find<RoomsController>().getRoomById(roomId);
Get.defaultDialog(
title: "Join Room",
titleStyle: const TextStyle(color: Colors.amber, fontSize: 25),
content: Column(
children: [RoomTile(room: appwriteRoom)],
),
backgroundColor: AppColor.bgBlackColor);
}
} catch (e) {
log("Open App Link ERROR : ${e.toString()}");
}
}

void openRoomSheet(AppwriteRoom room) {
showModalBottomSheet(
context: Get.context!,
Expand All @@ -26,5 +84,3 @@ class TabViewController extends GetxController {
isDismissible: false);
}
}


4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
errorColor: const Color(0xFDFF0000),
),
fontFamily:
GoogleFonts.poppins(fontWeight: FontWeight.w500).fontFamily,
GoogleFonts.poppins(fontWeight: FontWeight.w500).fontFamily,
iconTheme: Get.theme.iconTheme.copyWith(
color: AppColor.yellowColor,
),
Expand Down Expand Up @@ -56,4 +56,4 @@ class MyApp extends StatelessWidget {
getPages: AppPages.pages,
);
}
}
}
17 changes: 13 additions & 4 deletions lib/views/widgets/room_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:resonate/controllers/rooms_controller.dart';
import 'package:share_plus/share_plus.dart';

import '../../models/appwrite_room.dart';
import '../../utils/colors.dart';
Expand All @@ -10,7 +11,7 @@ import '../../utils/enums/room_state.dart';
class RoomTile extends StatelessWidget {
final AppwriteRoom room;

RoomTile({super.key, required this.room});
RoomTile({required this.room});

Text buildTags() {
String tagString = "";
Expand Down Expand Up @@ -148,9 +149,17 @@ class RoomTile extends StatelessWidget {
SizedBox(
width: Get.width * 0.04,
),
const Icon(
Icons.share,
color: Colors.black,
GestureDetector(
child: Icon(
Icons.share,
color: Colors.black,
),
onTap: () {
String roomLink = "https://resonate.aossie.org/room/${room.id}";
Share.share('🎉 Let\'s Resonate 🎉\n'
'🎙️ Room Topic: ${room.name}\n'
'🔗 Link: $roomLink\n');
},
),
],
),
Expand Down
24 changes: 24 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.0"
app_links:
dependency: "direct main"
description:
name: app_links
sha256: "16725e716afd0634a5441654b1dda2b6c5557aa230884b5e1f41a5aa546a4cb6"
url: "https://pub.dev"
source: hosted
version: "3.4.3"
appwrite:
dependency: "direct main"
description:
Expand Down Expand Up @@ -944,6 +952,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.1"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: "6cec740fa0943a826951223e76218df002804adb588235a8910dc3d6b0654e11"
url: "https://pub.dev"
source: hosted
version: "7.1.0"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "357412af4178d8e11d14f41723f80f12caea54cf0d5cd29af9dcdab85d58aea7"
url: "https://pub.dev"
source: hosted
version: "3.3.0"
shelf:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ dependencies:
flutter_secure_storage: ^8.0.0
focused_menu: ^1.0.5
livekit_client: 1.3.3
app_links: ^3.4.3
share_plus: ^7.1.0

dev_dependencies:
flutter_test:
Expand Down