Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/F4zination/DUO
Browse files Browse the repository at this point in the history
  • Loading branch information
oriventi committed Apr 24, 2024
2 parents 2a05d39 + 3c42a04 commit 5c2e402
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion duo_client/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.0'
repositories {
google()
mavenCentral()
Expand Down
4 changes: 2 additions & 2 deletions duo_client/lib/provider/api_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class ApiProvider extends ChangeNotifier implements AbstractServerConnection {
}

@override
Future<int> joinSession(String token, int sessionId, String pin) {
return _serverConnection!.joinSession(token, sessionId, pin);
Future<int> joinSession(String token, int sessionId) {
return _serverConnection!.joinSession(token, sessionId);
}

@override
Expand Down
21 changes: 15 additions & 6 deletions duo_client/lib/screens/lobby_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class _LobbyScreenState extends ConsumerState<LobbyScreen>
final int inviteCode = Random().nextInt(999999);
late final ApiProvider _apiProvider;
int sessionID = -1;
String displaySessionID = '';
late final StorageProvider _storageProvider;

void createLobby() async {
Expand All @@ -36,6 +37,14 @@ class _LobbyScreenState extends ConsumerState<LobbyScreen>
.then(
(value) {
sessionID = value;
if (value.toString().length < 6) {
for (int i = 0; i < 6 - value.toString().length; i++) {
displaySessionID += '0';
}
displaySessionID += value.toString();
} else {
displaySessionID = value.toString();
}
setState(() {
creatingLobby = false;
});
Expand Down Expand Up @@ -124,47 +133,47 @@ class _LobbyScreenState extends ConsumerState<LobbyScreen>
padding: const EdgeInsets.all(8.0),
child: AddTile(
Dialog: InviteDialog(
invideCode: inviteCode,
invideCode: displaySessionID,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: AddTile(
Dialog: InviteDialog(
invideCode: inviteCode,
invideCode: displaySessionID,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: AddTile(
Dialog: InviteDialog(
invideCode: inviteCode,
invideCode: displaySessionID,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: AddTile(
Dialog: InviteDialog(
invideCode: inviteCode,
invideCode: displaySessionID,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: AddTile(
Dialog: InviteDialog(
invideCode: inviteCode,
invideCode: displaySessionID,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: AddTile(
Dialog: InviteDialog(
invideCode: inviteCode,
invideCode: displaySessionID,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion duo_client/lib/utils/connection/abstract_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ abstract class AbstractServerConnection {
Future<int> registerUser(String username);
Future<int> loginUser(String uuid);
Future<int> createSession(String token, String pin);
Future<int> joinSession(String token, int sessionId, String pin);
Future<int> joinSession(String token, int sessionId);
Future<int> disconnectSession(String token, int sessionId);
}
5 changes: 2 additions & 3 deletions duo_client/lib/utils/connection/grpc_server_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ class GrpcServerConnection extends AbstractServerConnection {
}

@override
Future<int> joinSession(String token, int sessionId, String pin) async {
Future<int> joinSession(String token, int sessionId) async {
try {
ResponseStream<SessionStream> stream =
client.joinSession(JoinSessionRequest()
..token = token
..sessionId = sessionId
..pin = pin);
..sessionId = sessionId);

await for (SessionStream ss in stream) {
print('Received: ${ss.sessionState.users.length}');
Expand Down
6 changes: 3 additions & 3 deletions duo_client/lib/widgets/invite_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class InviteDialog extends StatelessWidget {
InviteDialog({super.key, required this.invideCode});

late final Friend friendInvited;
final int invideCode;
final String invideCode;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -51,15 +51,15 @@ class InviteDialog extends StatelessWidget {
child: Row(
children: [
Text(
'Join via Code: ${invideCode.toString()}',
'Join via Code: $invideCode',
style: const TextStyle(color: Colors.white, fontSize: 16),
),
const Spacer(),
IconButton(
onPressed: () => showDialog(
context: context,
builder: (context) => QrJoinDialog(
id: invideCode.toString(),
id: invideCode,
)),
icon: const Icon(
Icons.qr_code_2_rounded,
Expand Down
17 changes: 12 additions & 5 deletions duo_client/lib/widgets/join_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';

class JoinDialog extends ConsumerStatefulWidget {
const JoinDialog({Key? key});
const JoinDialog({super.key});

@override
ConsumerState<JoinDialog> createState() => _JoinDialogState();
}

class _JoinDialogState extends ConsumerState<JoinDialog> {
TextEditingController _controller = TextEditingController();
final TextEditingController _controller = TextEditingController();
bool wrongInviteCode = false;
String hintText = 'Enter the invite code to join a game';

Expand Down Expand Up @@ -76,12 +76,19 @@ class _JoinDialogState extends ConsumerState<JoinDialog> {
))),
IconButton(
onPressed: () async {
print('Joining session with invite code ${_controller.text}');
if (_controller.text.isEmpty || _controller.text.length < 6) {
setState(() {
wrongInviteCode = true;
hintText = 'Invite code needs to be 6 digits long';
});
return;
}
int stauts = await ref.read(apiProvider).joinSession(
ref.read(storageProvider).accessToken,
5,
_controller.text);
int.parse(_controller.text));
if (stauts == 0) {
print(
'Joining session with invite code ${_controller.text}');
Navigator.of(context)
.pushReplacementNamed(LobbyScreen.route);
} else {
Expand Down
8 changes: 4 additions & 4 deletions duo_client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -716,18 +716,18 @@ packages:
dependency: "direct main"
description:
name: share_plus
sha256: ef3489a969683c4f3d0239010cc8b7a2a46543a8d139e111c06c558875083544
sha256: ed3fcea4f789ed95913328e629c0c53e69e80e08b6c24542f1b3576046c614e8
url: "https://pub.dev"
source: hosted
version: "9.0.0"
version: "7.0.2"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "0f9e4418835d1b2c3ae78fdb918251959106cefdbc4dd43526e182f80e82f6d4"
sha256: "251eb156a8b5fa9ce033747d73535bf53911071f8d3b6f4f0b578505ce0d4496"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "3.4.0"
shelf:
dependency: transitive
description:
Expand Down
4 changes: 4 additions & 0 deletions duo_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ dependencies:
animated_background: ^2.0.0
flutter_spinkit: ^5.2.1
qr_flutter: ^4.1.0
<<<<<<< HEAD
share_plus: ^9.0.0
qr_scanner_overlay: ^0.0.2
mobile_scanner: 3.2.0
=======
share_plus: 7.0.2
>>>>>>> 3c42a046046a6c2f618bd060decbd47a67ee3acc


dev_dependencies:
Expand Down
1 change: 0 additions & 1 deletion proto/session_messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ message CreateSessionResponse{
message JoinSessionRequest{
string token = 1;
int32 session_id = 2;
string pin = 3;
}

message SessionStream{
Expand Down

0 comments on commit 5c2e402

Please sign in to comment.