Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Add swipe t delete too DownloadCard
Browse files Browse the repository at this point in the history
  • Loading branch information
GravityDarkLab committed Jan 29, 2024
1 parent 3366535 commit 7557415
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/views/course_view/components/course_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CourseCard extends StatelessWidget {
course!,
onPinUnpin!,
isPinned!,
)
),
),
),
);
Expand Down
49 changes: 42 additions & 7 deletions lib/views/course_view/components/small_stream_card.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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/utils/constants.dart';
import 'package:url_launcher/url_launcher.dart';
Expand All @@ -7,13 +8,13 @@ class SmallStreamCard extends StatelessWidget {
final String title;
final String tumID;
final VoidCallback onTap;
final int courseId;
final int? courseId;

//for displaying courses
final bool? live;

final bool? isDownloaded;
final Course? course;

final Function(int)? showDeleteConfirmationDialog;
//for displaying livestreams
final String? subtitle;
final String? roomName;
Expand All @@ -29,10 +30,12 @@ class SmallStreamCard extends StatelessWidget {
this.roomName,
this.roomNumber,
this.path,
required this.courseId,
this.courseId,
required this.onTap,
this.live,
this.course,
this.isDownloaded,
this.showDeleteConfirmationDialog,
});

@override
Expand Down Expand Up @@ -71,6 +74,32 @@ class SmallStreamCard extends StatelessWidget {
}

Widget _buildStreamCard(ThemeData themeData, double cardWidth) {
return (isDownloaded!=null && showDeleteConfirmationDialog!=null) ? _buildDownloadedCard(themeData, cardWidth) : _buildLiveCard(themeData, cardWidth);
}

Widget _buildDownloadedCard (ThemeData themeData, double cardWidth) {
return Slidable(
key: Key(courseId.toString()),
closeOnScroll: true,
endActionPane: ActionPane(
motion: const DrawerMotion(),
dragDismissible: true,
children: [
SlidableAction(
onPressed: (_) => showDeleteConfirmationDialog!(courseId!),
autoClose: true,
backgroundColor: Colors.red,
foregroundColor: Colors.white,
icon: Icons.delete_rounded,
label: 'Delete',
),
],
),
child: _buildLiveCard(themeData, cardWidth*1.3),
);
}

Widget _buildLiveCard(ThemeData themeData, double cardWidth) {
return Container(
width: cardWidth,
padding: const EdgeInsets.all(8.0),
Expand Down Expand Up @@ -120,12 +149,19 @@ class SmallStreamCard extends StatelessWidget {
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
// Keep the rounded corners
child: Image.network(
child: path == null
? Image.asset(
AppImages.course1,
fit: BoxFit.cover,
)
:
Image.network(
path!, // Use the image URL
fit: BoxFit.cover, // Maintain the cover fit
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null)
if (loadingProgress == null) {
return child; // Image is fully loaded
}
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
Expand All @@ -139,7 +175,6 @@ class SmallStreamCard extends StatelessWidget {
// Provide a fallback asset image in case of error
return Image.asset(
AppImages.course1,
// Path to your default/fallback image asset
fit: BoxFit.cover,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/views/components/base_view.dart';
import 'package:gocast_mobile/views/components/custom_search_top_nav_bar.dart';
import 'package:gocast_mobile/views/course_view/components/small_stream_card.dart';

import 'package:gocast_mobile/views/course_view/downloaded_courses_view/download_card.dart';

import '../../../utils/constants.dart';

Expand All @@ -14,7 +14,7 @@ import '../../../utils/constants.dart';
/// It takes a [title] to display the title of the section and
/// dynamically generates a horizontal list of courses.
class DownloadCoursesContentView extends ConsumerWidget {
final List<VideoCard> videoCards;
final List<SmallStreamCard> videoCards;
final CustomSearchTopNavBar customAppBar;

const DownloadCoursesContentView({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:gocast_mobile/models/download/download_state_model.dart';
import 'package:gocast_mobile/providers.dart';
import 'package:gocast_mobile/views/components/custom_search_top_nav_bar.dart';
import 'package:gocast_mobile/views/course_view/downloaded_courses_view/download_card.dart';
import 'package:gocast_mobile/views/course_view/components/small_stream_card.dart';
import 'package:gocast_mobile/views/course_view/downloaded_courses_view/download_content_view.dart';
import 'package:gocast_mobile/views/video_view/offline_video_player/offline_video_player.dart';

Expand All @@ -16,6 +16,7 @@ class DownloadedCourses extends ConsumerStatefulWidget {

class DownloadedCoursesState extends ConsumerState<DownloadedCourses> {
final TextEditingController searchController = TextEditingController();

void _showDeleteConfirmationDialog(int videoId) {
showDialog(
context: context,
Expand Down Expand Up @@ -44,6 +45,7 @@ class DownloadedCoursesState extends ConsumerState<DownloadedCourses> {
},
);
}

//TODO: void _handleSortOptionSelected(String choice) {}

@override
Expand Down Expand Up @@ -74,30 +76,31 @@ class DownloadedCoursesState extends ConsumerState<DownloadedCourses> {
final String videoName = videoDetails.name;
final int durationSeconds = videoDetails.duration;
final String formattedDuration = "${(durationSeconds ~/ 3600).toString().padLeft(2, '0')}:${((durationSeconds % 3600) ~/ 60).toString().padLeft(2, '0')}:${(durationSeconds % 60).toString().padLeft(2, '0')}";
return VideoCard(
duration:
formattedDuration,
imageName: 'assets/images/course1.png',
// Update as necessary
title: videoName,
// Replace with the appropriate title
date: "",
// Replace with the appropriate date
onTap: () {
return SmallStreamCard(
isDownloaded: true,
courseId: videoId,
title: videoName,
subtitle: formattedDuration,
tumID: "TUMID",
showDeleteConfirmationDialog: _showDeleteConfirmationDialog,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) =>
OfflineVideoPlayerPage(localPath: localPath),
),
);
MaterialPageRoute(
builder: (context) =>
OfflineVideoPlayerPage(localPath: localPath),
),
);
},
onDelete: () {
_showDeleteConfirmationDialog(videoId);
},
);
);
}).toList(),
),
),
);

}
}


// onDelete: () {
// _showDeleteConfirmationDialog(videoId);
// },

0 comments on commit 7557415

Please sign in to comment.