Skip to content

Commit

Permalink
separate course card and small stream card
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainaamr committed Jan 28, 2024
1 parent 57cea83 commit 6e5ab6f
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 176 deletions.
201 changes: 32 additions & 169 deletions lib/views/course_view/components/course_card.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
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:gocast_mobile/views/components/view_all_button.dart';
import 'package:url_launcher/url_launcher.dart';

class CourseCard extends StatelessWidget {
final String title;
final String tumID;
final VoidCallback onTap;
final int courseId;

final bool isCourse; //true: course, false: stream

//for displaying courses
final bool? live;
Expand All @@ -21,21 +18,12 @@ class CourseCard extends StatelessWidget {

//for displaying livestreams
final String? subtitle;
final String? roomName;
final String? roomNumber;
final String? viewerCount;
final String? path;

const CourseCard({
super.key,
required this.isCourse,
required this.title,
this.subtitle,
required this.tumID,
this.roomName,
this.roomNumber,
this.viewerCount,
this.path,
required this.courseId,
required this.onTap,
this.live,
Expand Down Expand Up @@ -70,66 +58,19 @@ class CourseCard extends StatelessWidget {
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: isCourse
? _buildCourseCard(
themeData,
cardWidth,
context,
course!,
child: _buildCourseCard(
themeData,
cardWidth,
context,
course!,
onPinUnpin!,
isPinned!,
)
: _buildStreamCard(
themeData,
cardWidth,
),
),
),
);
}

Widget _buildStreamCard(ThemeData themeData, double cardWidth) {
return Container(
width: cardWidth,
padding: const EdgeInsets.all(8.0),
color: themeData.cardColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildCourseTumID(),
_buildCourseViewerCount(themeData),
],
),
const SizedBox(height: 2),
Row(
children: [
SizedBox(
width: 100,
child: _buildCourseImage(),
),
const SizedBox(width: 15),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 10),
_buildCourseTitle(themeData.textTheme),
_buildCourseSubtitle(themeData.textTheme),
const SizedBox(height: 15),
_buildLocation(),
],
),
),
],
),
],
),
);
}

Widget _buildCourseCard(
ThemeData themeData,
double cardWidth,
Expand Down Expand Up @@ -224,114 +165,9 @@ class CourseCard extends StatelessWidget {
false;
}

Widget _buildCourseImage() {
if (path == null) return const SizedBox();
return Stack(
children: [
AspectRatio(
aspectRatio: 16 / 12,
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.asset(
path!,
fit: BoxFit.cover,
),
),
),
],
);
}

Widget _buildLocation() {
if (roomNumber == null) return const SizedBox();

final Uri url = Uri.parse('https://nav.tum.de/room/$roomNumber');

return InkWell(
onTap: () async {
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
}
},
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const Icon(
Icons.room,
size: 20,
),
Text(roomName ?? "Location"),
Transform.scale(
scale: 0.6, // Adjust the scale factor as needed
child: ViewAllButton(onViewAll: () {}),
),
],
),
);
}

Widget _buildCourseTumID() {
return Text(
tumID,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 14,
color: Colors.grey,
height: 0.9,
),
);
}

Widget _buildCourseTitle(TextTheme textTheme) {
return Text(
title,
overflow: TextOverflow.ellipsis,
maxLines: 2,
softWrap: true,
style: textTheme.titleMedium?.copyWith(
fontSize: 16,
fontWeight: FontWeight.w700,
height: 1.2,
) ??
const TextStyle(),
);
}

Widget _buildCourseSubtitle(TextTheme textTheme) {
if (subtitle == null) return const SizedBox();

return Text(
subtitle!, //nullcheck already passed
overflow: TextOverflow.ellipsis,
style: textTheme.labelSmall?.copyWith(
fontSize: 14,
fontWeight: FontWeight.w400,
height: 1,
) ??
const TextStyle(),
);
}

Widget _buildCourseViewerCount(ThemeData themeData) {
if (viewerCount == null) return const SizedBox();
return Container(
decoration: BoxDecoration(
color: themeData.shadowColor.withOpacity(0.15),
borderRadius: BorderRadius.circular(4),
),
padding: const EdgeInsets.all(3),
child: Text(
"${viewerCount!} viewers",
style: themeData.textTheme.labelSmall?.copyWith(
fontSize: 12,
height: 1,
) ??
const TextStyle(),
),
);
}

Widget _buildCourseIsLive() {
if (live == null) return const SizedBox();
Expand Down Expand Up @@ -382,4 +218,31 @@ class CourseCard extends StatelessWidget {
return Colors.grey;
}
}

Widget _buildCourseTitle(TextTheme textTheme) {
return Text(
title,
overflow: TextOverflow.ellipsis,
maxLines: 2,
softWrap: true,
style: textTheme.titleMedium?.copyWith(
fontSize: 16,
fontWeight: FontWeight.w700,
height: 1.2,
) ??
const TextStyle(),
);
}

Widget _buildCourseTumID() {
return Text(
tumID,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 14,
color: Colors.grey,
height: 0.9,
),
);
}
}
1 change: 0 additions & 1 deletion lib/views/course_view/components/course_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class CourseSection extends StatelessWidget {
course: course,
isPinned: isPinned,
onPinUnpin: (course) => _togglePin(course, isPinned),
isCourse: true,
title: course.name,
tumID: course.tUMOnlineIdentifier,
live: streams.any((stream) => stream.courseID == course.id),
Expand Down
6 changes: 3 additions & 3 deletions lib/views/course_view/components/live_stream_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ 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/constants.dart';
import 'package:gocast_mobile/views/course_view/components/course_card.dart';

import 'package:gocast_mobile/views/course_view/components/pulse_background.dart';
import 'package:gocast_mobile/views/course_view/components/small_stream_card.dart';
import 'package:gocast_mobile/views/video_view/video_player.dart';

/// CourseSection
Expand Down Expand Up @@ -86,8 +87,7 @@ class LiveStreamSection extends StatelessWidget {
final course =
courses.where((course) => course.id == stream.courseID).first;

return CourseCard(
isCourse: false,
return SmallStreamCard(
title: stream.name,
subtitle: course.name,
tumID: course.tUMOnlineIdentifier,
Expand Down
Loading

0 comments on commit 6e5ab6f

Please sign in to comment.