Skip to content

Commit

Permalink
Merge branch 'course-overview-bug-fixes' into ci-cd+provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber authored Feb 2, 2024
2 parents 4f9c187 + 4e7484e commit 1cc1e0d
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 155 deletions.
13 changes: 10 additions & 3 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
</array>
<array>
<string>https</string>
</array>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
Expand All @@ -52,6 +52,13 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>CFBundleLocalizations</key>
<array>
<string>en</string>
<string>fr</string>
<string>de</string>
<string>es</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"my_courses": "Meine Kurse",
"public_courses": "Öffentliche Kurse",
"live_now": "Jetzt Live",
"live_now": "Live",
"pinned_courses": "Angeheftete Kurse",
"pinned_empty": "Sie haben keine angehefteten Kurse.",
"pin": "Anheften",
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"my_courses": "My Courses",
"public_courses": "Public Courses",
"live_now": "Live Now",
"live_now": "Live",
"pinned_courses": "Pinned Courses",
"pinned_empty": "You have no pinned courses.",
"pin": "Pin",
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"my_courses": "Mis Cursos",
"public_courses": "Cursos Públicos",
"live_now": "En Vivo Ahora",
"live_now": "En Vivo",
"pinned_courses": "Cursos Anclados",
"pinned_empty": "No tienes cursos anclados.",
"pin": "Anclar",
Expand Down
22 changes: 19 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/models/user/user_state_model.dart';
Expand All @@ -6,6 +7,7 @@ import 'package:gocast_mobile/utils/UserPreferences.dart';
import 'package:gocast_mobile/utils/globals.dart';
import 'package:gocast_mobile/utils/theme.dart';
import 'package:gocast_mobile/navigation_tab.dart';
import 'package:gocast_mobile/views/course_view/downloaded_courses_view/downloaded_courses_view.dart';
import 'package:gocast_mobile/views/course_view/list_courses_view/public_courses_view.dart';
import 'package:gocast_mobile/views/login_view/internal_login_view.dart';
import 'package:gocast_mobile/views/on_boarding_view/welcome_screen_view.dart';
Expand Down Expand Up @@ -42,6 +44,8 @@ class App extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
_checkConnectivityAndRedirect(context, ref);

final userState = ref.watch(userViewModelProvider);

bool isLoggedIn = ref.watch(userViewModelProvider).user != null;
Expand All @@ -51,6 +55,7 @@ class App extends ConsumerWidget {
_setupNotifications(ref, userState);

return MaterialApp(
debugShowCheckedModeBanner: false,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
Expand All @@ -59,10 +64,10 @@ class App extends ConsumerWidget {
],
supportedLocales: L10n.all,
locale: Locale(UserPreferences.getLanguage()),
theme: appTheme, // Your light theme
darkTheme: darkAppTheme, // Define your dark theme
theme: appTheme,
darkTheme: darkAppTheme,
themeMode:
ref.watch(themeModeProvider), // Use the theme mode from the provider
ref.watch(themeModeProvider),
navigatorKey: navigatorKey,
scaffoldMessengerKey: scaffoldMessengerKey,
home: !isLoggedIn
Expand All @@ -72,6 +77,16 @@ class App extends ConsumerWidget {
);
}

void _checkConnectivityAndRedirect(BuildContext context, WidgetRef ref) {
Connectivity().checkConnectivity().then((connectivityResult) {
if (connectivityResult == ConnectivityResult.none) {
WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pushReplacementNamed('/downloads');
});
}
});
}

void _handleErrors(WidgetRef ref, UserState userState) {
// Check for errors in userState and show a SnackBar if there are any
if (userState.error != null) {
Expand All @@ -91,6 +106,7 @@ class App extends ConsumerWidget {
'/login': (context) => const InternalLoginScreen(),
'/navigationTab': (context) => const NavigationTab(),
'/publiccourses': (context) => const PublicCourses(),
'/downloads': (context) => const DownloadedCourses(),
};
}

Expand Down
11 changes: 8 additions & 3 deletions lib/models/download/download_state_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,31 @@ class DownloadState {
class VideoDetails {
final String filePath;
final String name;
final int duration; // Duration in seconds or your preferred unit
final String duration; // Duration in seconds or your preferred unit
final String description;
final String date;

const VideoDetails({
required this.filePath,
required this.name,
required this.duration,
required this.description,
required this.date,
});

VideoDetails copyWith({
String? filePath,
String? name,
int? duration,
String? duration,
String? description,
String? date,
}) {
return VideoDetails(
filePath: filePath ?? this.filePath,
name: name ?? this.name,
duration: duration ?? this.duration,
description: description,
description: description ?? this.description,
date: date ?? this.date,
);
}
}
53 changes: 53 additions & 0 deletions lib/utils/tools.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'dart:ui';

import 'package:flutter/material.dart';

class Tools {

//private constructor
Tools._();

static String extractCourseIds(String title) {
final pattern = RegExp(r'(?:CIT|IN|MA|CH|MW|PH)\d[\w-]*');
final matches = pattern.allMatches(title);
List<String> ids = [];
for (var match in matches) {
ids.add(match.group(0)!);
}
return ids.join(' , ');
}

static String formatDuration(int durationInMinutes) {
int hours = durationInMinutes ~/ 60;
int minutes = durationInMinutes % 60;
int seconds = 0;

String formattedHours = hours < 10 ? '0$hours' : '$hours';
String formattedMinutes = minutes < 10 ? '0$minutes' : '$minutes';
String formattedSeconds = seconds < 10 ? '0$seconds' : '$seconds';

return '$formattedHours:$formattedMinutes:$formattedSeconds';
}

static Color colorPicker(tumID) {
if (tumID.length < 2) return Colors.grey;
switch (tumID.substring(0, 2)) {
case 'IN':
return Colors.blue;
case 'MA':
return Colors.purple;
case 'CH':
return Colors.green;
case 'PH':
return Colors.orange;
case 'MW':
return Colors.red;
case 'EL':
return Colors.black87;
case 'CI':
return Colors.teal;
default:
return Colors.grey;
}
}
}
18 changes: 12 additions & 6 deletions lib/view_models/download_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'dart:convert';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/models/download/download_state_model.dart';
import 'package:gocast_mobile/utils/tools.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:path_provider/path_provider.dart';
import 'package:dio/dio.dart';
import 'package:logger/logger.dart';
import 'dart:io';
import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pb.dart';


class DownloadViewModel extends StateNotifier<DownloadState> {
final Logger _logger = Logger();
Expand Down Expand Up @@ -34,31 +37,32 @@ class DownloadViewModel extends StateNotifier<DownloadState> {
name: videoDetailsMap['name'],
duration: videoDetailsMap['duration'],
description: videoDetailsMap['description'],
date: videoDetailsMap['date'],
);
return MapEntry(int.parse(key), videoDetails);
}).cast<int, VideoDetails>(); // Ensure the map has the correct type
state = state.copyWith(downloadedVideos: downloadedVideos);
}
}

Future<String> downloadVideo(String videoUrl, int streamId, String fileName,
String streamName, int streamDuration, String description,) async {
Future<String> downloadVideo(String videoUrl, Stream stream, String streamName, String streamDate) async {
try {
final directory = await getApplicationDocumentsDirectory();
final filePath = '${directory.path}/$fileName';
final filePath = '${directory.path}/${streamName.replaceAll(' ', '_')}.mp4';
Dio dio = Dio();
await dio.download(videoUrl, filePath);
_logger.d('Downloaded video to: $filePath');

final prefs = await SharedPreferences.getInstance();
final int streamIdInt = streamId.toInt();
final int streamIdInt = stream.id.toInt();

// Create a map for the video details
final videoDetailsMap = {
'filePath': filePath,
'name': streamName,
'duration': streamDuration,
'description': description,
'duration': Tools.formatDuration(stream.end.toDateTime().difference(stream.start.toDateTime()).inMinutes),
'description': stream.description,
'date': streamDate,
};

// Convert video details map to JSON string
Expand All @@ -82,6 +86,7 @@ class DownloadViewModel extends StateNotifier<DownloadState> {
name: videoDetailsMap['name'],
duration: videoDetailsMap['duration'],
description: videoDetailsMap['description'],
date: videoDetailsMap['date'],
);
return MapEntry(key, videoDetails);
}).cast<int, VideoDetails>();
Expand Down Expand Up @@ -167,5 +172,6 @@ class DownloadViewModel extends StateNotifier<DownloadState> {
}



}

2 changes: 1 addition & 1 deletion lib/views/chat_view/suggested_streams_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SuggestedStreamsWidget extends StatelessWidget {
final stream = suggestedStreams[index];
return ListTile(
leading: const Icon(Icons.play_circle_outline),
title: Text(stream.name),
title: Text(stream.name != '' ? stream.name : 'Lecture: ${DateFormat('EEEE. dd', Localizations.localeOf(context).toString()).format(stream.start.toDateTime())}'),
subtitle: Text(
DateFormat('dd MMMM yyyy').format(stream.start.toDateTime()),
),
Expand Down
66 changes: 0 additions & 66 deletions lib/views/components/custom_search_filter_top_nav_bar.dart

This file was deleted.

Loading

0 comments on commit 1cc1e0d

Please sign in to comment.