Skip to content

Commit

Permalink
fix StreamSection to display tumID
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityDarkLab committed Feb 2, 2024
1 parent 496f095 commit 4e7484e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 137 deletions.
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;
}
}
}
14 changes: 2 additions & 12 deletions lib/view_models/download_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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';
Expand Down Expand Up @@ -59,7 +60,7 @@ class DownloadViewModel extends StateNotifier<DownloadState> {
final videoDetailsMap = {
'filePath': filePath,
'name': streamName,
'duration': _formatDuration(stream.end.toDateTime().difference(stream.start.toDateTime()).inMinutes),
'duration': Tools.formatDuration(stream.end.toDateTime().difference(stream.start.toDateTime()).inMinutes),
'description': stream.description,
'date': streamDate,
};
Expand Down Expand Up @@ -170,17 +171,6 @@ class DownloadViewModel extends StateNotifier<DownloadState> {
}
}

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';
}


}
Expand Down
66 changes: 0 additions & 66 deletions lib/views/components/custom_search_filter_top_nav_bar.dart

This file was deleted.

51 changes: 4 additions & 47 deletions lib/views/course_view/components/course_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pb.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:gocast_mobile/utils/tools.dart';

class CourseCard extends StatelessWidget {
final String title;
Expand Down Expand Up @@ -48,7 +49,7 @@ class CourseCard extends StatelessWidget {
bool? isPinned,
required bool isLoggedIn,
}) {
final tumID = _extractCourseIds(title);
final tumID = Tools.extractCourseIds(title);
return CourseCard._(
key: key,
title: title,
Expand Down Expand Up @@ -208,10 +209,6 @@ class CourseCard extends StatelessWidget {
false;
}





Widget _buildCourseIsLive(BuildContext context) {
if (live == null) return const SizedBox();
return live!
Expand All @@ -238,31 +235,11 @@ class CourseCard extends StatelessWidget {
Widget _buildCourseColor() {
return Container(
width: 5,
color: _colorPicker(),
color: Tools.colorPicker(tumID),
);
}

Color _colorPicker() {
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;
}
}


Widget _buildCourseTitle(TextTheme textTheme) {
return Text(
Expand Down Expand Up @@ -291,25 +268,5 @@ class CourseCard extends StatelessWidget {
);
}

static String _extractCourseIds(String title) {
// This pattern is designed to repeatedly capture course IDs with specified prefixes,
// followed by alphanumeric characters and possibly separated by commas within brackets or parentheses.
// It uses a global search to find all occurrences of such patterns.
final pattern = RegExp(r'(?:CIT|IN|MA|CH|MW|PH)\d[\w-]*');
final matches = pattern.allMatches(title);

// Initialize an empty list to collect IDs.
List<String> ids = [];

// Iterate over all matches and add the matched ID to the list.
for (var match in matches) {
ids.add(match.group(0)!); // Safe to use `!` as allMatches() only returns non-null matches.
}

// Join extracted IDs with a dash.
return ids.join(' , ');
}



}
3 changes: 2 additions & 1 deletion lib/views/course_view/components/live_stream_section.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pb.dart';
import 'package:gocast_mobile/utils/tools.dart';

import 'package:gocast_mobile/views/course_view/components/pulse_background.dart';
import 'package:gocast_mobile/views/course_view/components/small_stream_card.dart';
Expand Down Expand Up @@ -85,7 +86,7 @@ class LiveStreamSection extends StatelessWidget {
return SmallStreamCard(
title: stream.item1.name,
subtitle: course.name,
tumID: course.tUMOnlineIdentifier,
tumID: Tools.extractCourseIds(course.name),
roomName: stream.item1.roomName,
roomNumber: stream.item1.roomCode,
path: imagePath,
Expand Down
13 changes: 2 additions & 11 deletions lib/views/course_view/components/stream_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/base/networking/api/gocast/api_v2.pb.dart';
import 'package:gocast_mobile/providers.dart';
import 'package:gocast_mobile/utils/constants.dart';
import 'package:gocast_mobile/utils/tools.dart';
import 'package:gocast_mobile/views/video_view/video_player.dart';
import 'package:intl/intl.dart';

Expand Down Expand Up @@ -168,17 +169,7 @@ class StreamCardState extends ConsumerState<StreamCard> {
);
}

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';
}

Widget _buildStreamDate(ThemeData themeData) {
return Container(
Expand All @@ -205,7 +196,7 @@ class StreamCardState extends ConsumerState<StreamCard> {
),
padding: const EdgeInsets.all(5),
child: Text(
formatDuration(widget.stream.end.toDateTime().difference(widget.stream.start.toDateTime()).inMinutes),
Tools.formatDuration(widget.stream.end.toDateTime().difference(widget.stream.start.toDateTime()).inMinutes),
style: themeData.textTheme.labelSmall?.copyWith(
fontSize: 12,
color: Colors.white,
Expand Down

0 comments on commit 4e7484e

Please sign in to comment.