Skip to content

Commit

Permalink
Prevent tapping on dropdown while a movie is being created
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKun committed Sep 4, 2023
1 parent e740ce0 commit 254f837
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 78 deletions.
6 changes: 6 additions & 0 deletions lib/controllers/video_count_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '../utils/shared_preferences_util.dart';
class VideoCountController extends GetxController {
final Rx<int> videoCount = SharedPrefsUtil.getInt('videoCount')!.obs;
final Rx<int> movieCount = SharedPrefsUtil.getInt('movieCount')!.obs;
final Rx<bool> isProcessing = false.obs;

void increaseVideoCount() {
videoCount.value++;
Expand All @@ -30,4 +31,9 @@ class VideoCountController extends GetxController {
videoCount.refresh();
SharedPrefsUtil.putInt('videoCount', videoCount.value);
}

void setIsProcessing(bool value) {
isProcessing.value = value;
isProcessing.refresh();
}
}
8 changes: 5 additions & 3 deletions lib/pages/home/create_movie/widgets/create_movie_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CreateMovieButton extends StatefulWidget {

class _CreateMovieButtonState extends State<CreateMovieButton> {
final String logTag = '[CREATE MOVIE] - ';
final VideoCountController _movieCount = Get.find();
final VideoCountController controller = Get.find();
bool isProcessing = false;
String progress = '';

Expand All @@ -48,6 +48,7 @@ class _CreateMovieButtonState extends State<CreateMovieButton> {
WakelockPlus.enable();
final List<String> copiesToDelete = [];

controller.setIsProcessingMovie(true);
setState(() {
isProcessing = true;
});
Expand Down Expand Up @@ -297,7 +298,7 @@ class _CreateMovieButtonState extends State<CreateMovieButton> {
// Creating txt that will be used with ffmpeg to concatenate all videos
final String txtPath = await Utils.writeTxt(selectedVideos);
final String outputPath =
'${SharedPrefsUtil.getString('moviesPath')}OSD-Movie-${_movieCount.movieCount.value}-$today.mp4';
'${SharedPrefsUtil.getString('moviesPath')}OSD-Movie-${controller.movieCount.value}-$today.mp4';
Utils.logInfo('${logTag}Movie will be saved as: $outputPath');

setState(() {
Expand All @@ -309,7 +310,7 @@ class _CreateMovieButtonState extends State<CreateMovieButton> {
.then(
(session) async {
final returnCode = await session.getReturnCode();
_movieCount.increaseMovieCount();
controller.increaseMovieCount();
if (ReturnCode.isSuccess(returnCode)) {
showDialog(
barrierDismissible: false,
Expand Down Expand Up @@ -379,6 +380,7 @@ class _CreateMovieButtonState extends State<CreateMovieButton> {
StorageUtils.deleteFile(copy);
});

controller.setIsProcessingMovie(false);
setState(() {
isProcessing = false;
});
Expand Down
150 changes: 75 additions & 75 deletions lib/pages/home/create_movie/widgets/create_movie_options.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../../controllers/video_count_controller.dart';
import '../../../../enums/export_date_range.dart';
// import '../../../../enums/export_orientations.dart';
import '../../../../routes/app_pages.dart';
Expand All @@ -20,6 +21,7 @@ class CreateMovieOptions extends StatefulWidget {
class _CreateMovieOptionsState extends State<CreateMovieOptions> {
ExportDateRange _exportPeriodGroupValue = ExportDateRange.allTime;
final List<ExportDateRange> _exportPeriods = ExportDateRange.values;
final VideoCountController controller = Get.find();

final dropdownBorder = OutlineInputBorder(
borderSide: BorderSide(
Expand All @@ -35,8 +37,7 @@ class _CreateMovieOptionsState extends State<CreateMovieOptions> {
super.initState();
Future.delayed(const Duration(milliseconds: 200), () {
setState(() {
selectedVideos =
Utils.getSelectedVideosFromStorage(_exportPeriodGroupValue);
selectedVideos = Utils.getSelectedVideosFromStorage(_exportPeriodGroupValue);
});
});
}
Expand Down Expand Up @@ -107,76 +108,77 @@ class _CreateMovieOptionsState extends State<CreateMovieOptions> {
alignment: Alignment.centerLeft,
child: SizedBox(
width: 300,
child: DropdownButtonFormField<ExportDateRange>(
value: _exportPeriodGroupValue,
icon: const Icon(Icons.expand_more),
iconSize: 24,
elevation: 16,
borderRadius: BorderRadius.circular(12),
isExpanded: true,
dropdownColor: ThemeService().isDarkTheme()
? AppColors.dark
: AppColors.light,
decoration: InputDecoration(
enabledBorder: dropdownBorder,
focusedBorder: dropdownBorder,
border: dropdownBorder,
filled: true,
fillColor: ThemeService().isDarkTheme()
? AppColors.dark
: AppColors.light,
),
onChanged: (newValue) async {
setState(() {
_exportPeriodGroupValue = newValue!;
});
child: Obx(
() => IgnorePointer(
ignoring: controller.isProcessingMovie.value,
child: DropdownButtonFormField<ExportDateRange>(
value: _exportPeriodGroupValue,
icon: const Icon(Icons.expand_more),
iconSize: 24,
elevation: 16,
borderRadius: BorderRadius.circular(12),
isExpanded: true,
dropdownColor:
ThemeService().isDarkTheme() ? AppColors.dark : AppColors.light,
decoration: InputDecoration(
enabledBorder: dropdownBorder,
focusedBorder: dropdownBorder,
border: dropdownBorder,
filled: true,
fillColor: ThemeService().isDarkTheme()
? AppColors.dark
: AppColors.light,
),
onChanged: (newValue) async {
setState(() {
_exportPeriodGroupValue = newValue!;
});

if (newValue == ExportDateRange.custom) {
// Needs more than 1 video to create movie
if (selectedVideos!.length < 2) {
showDialog(
barrierDismissible: false,
context: Get.context!,
builder: (context) => CustomDialog(
isDoubleAction: false,
title: 'movieErrorTitle'.tr,
content: 'movieInsufficientVideos'.tr,
actionText: 'Ok',
actionColor: AppColors.green,
action: () => Get.back(),
),
);
return;
}
Get.toNamed(
Routes.SELECT_VIDEOS_FROM_STORAGE,
);
return;
}
// To show loading
setState(() {
selectedVideos = null;
});
// Update values
Future.delayed(const Duration(milliseconds: 100),
() {
setState(() {
selectedVideos =
Utils.getSelectedVideosFromStorage(
_exportPeriodGroupValue,
);
});
});
},
items: _exportPeriods
.map<DropdownMenuItem<ExportDateRange>>(
(ExportDateRange value) {
return DropdownMenuItem<ExportDateRange>(
value: value,
child: Text(value.localizationLabel.tr),
);
},
).toList(),
if (newValue == ExportDateRange.custom) {
// Needs more than 1 video to create movie
if (selectedVideos!.length < 2) {
showDialog(
barrierDismissible: false,
context: Get.context!,
builder: (context) => CustomDialog(
isDoubleAction: false,
title: 'movieErrorTitle'.tr,
content: 'movieInsufficientVideos'.tr,
actionText: 'Ok',
actionColor: AppColors.green,
action: () => Get.back(),
),
);
return;
}
Get.toNamed(
Routes.SELECT_VIDEOS_FROM_STORAGE,
);
return;
}
// To show loading
setState(() {
selectedVideos = null;
});
// Update values
Future.delayed(const Duration(milliseconds: 100), () {
setState(() {
selectedVideos = Utils.getSelectedVideosFromStorage(
_exportPeriodGroupValue,
);
});
});
},
items: _exportPeriods.map<DropdownMenuItem<ExportDateRange>>(
(ExportDateRange value) {
return DropdownMenuItem<ExportDateRange>(
value: value,
child: Text(value.localizationLabel.tr),
);
},
).toList(),
),
),
),
),
),
Expand All @@ -188,8 +190,7 @@ class _CreateMovieOptionsState extends State<CreateMovieOptions> {

const Spacer(),

if (selectedVideos != null &&
_exportPeriodGroupValue != ExportDateRange.custom)
if (selectedVideos != null && _exportPeriodGroupValue != ExportDateRange.custom)
Text(
'${'clipsFound'.tr}: ${getClipsFound()}',
style: TextStyle(
Expand All @@ -202,8 +203,7 @@ class _CreateMovieOptionsState extends State<CreateMovieOptions> {
size: 32.0,
),
const Spacer(),
if (selectedVideos != null &&
_exportPeriodGroupValue != ExportDateRange.custom)
if (selectedVideos != null && _exportPeriodGroupValue != ExportDateRange.custom)
Column(
children: [
Text(
Expand Down

0 comments on commit 254f837

Please sign in to comment.