Skip to content

Commit

Permalink
Merge pull request #11 from hkamran80/feature/quran-entry-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
hkamran80 authored Mar 26, 2023
2 parents e555f81 + 09f775d commit f2ba86c
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 26 deletions.
70 changes: 70 additions & 0 deletions lib/screens/quran.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class _QuranScreenState extends State<QuranScreen> {

bool showHelp = false;

int deletingHistoryEntry = -1;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -67,6 +69,69 @@ class _QuranScreenState extends State<QuranScreen> {
}

startingAyah = lastEntry[1] < currentSurahAyahs ? lastEntry[1] + 1 : 1;
} else {
startingSurah = -1;
startingAyah = 0;

endingSurah = -1;
endingAyah = 0;
}
}

void confirmEntryDelete() {
if (deletingHistoryEntry != -1) {
showDialog(
context: context,
builder: (BuildContext context) {
final entry = history[deletingHistoryEntry];
final date = DateTime.parse(entry[0].toString());
final hijriDate = HijriCalendar.fromDate(date);

final starting = (entry[1] as List<String>)[0].split("-");
final ending = (entry[1] as List<String>)[1].split("-");

return AlertDialog(
title: const Text("Confirm Entry Deletion"),
content: SingleChildScrollView(
child: Wrap(
runSpacing: 15,
children: [
const Text(
"Are you sure you want to delete the following entry?"),
StackedCard(
header:
"${DateFormat.MMMMd().format(date)} / ${hijriDate.longMonthName} ${hijriDate.hDay}",
title:
"${surahs[int.parse(starting[0]) - 1]["name"].toString()} ${starting[1]} - ${surahs[int.parse(ending[0]) - 1]["name"].toString()} ${ending[1]}",
fullWidth: true,
),
],
),
),
actions: [
TextButton(
child: const Text(
"Delete",
style: TextStyle(
color: destructiveActionColor,
),
),
onPressed: () {
setState(() {
history.removeAt(deletingHistoryEntry);
setStartingEntry();
});

quran.put("history", history);
deletingHistoryEntry = -1;

Navigator.of(context).pop();
},
),
],
);
},
);
}
}

Expand Down Expand Up @@ -213,6 +278,11 @@ class _QuranScreenState extends State<QuranScreen> {
title:
"${surahs[int.parse(starting[0]) - 1]["name"].toString()} ${starting[1]} - ${surahs[int.parse(ending[0]) - 1]["name"].toString()} ${ending[1]}",
fullWidth: true,
onLongPress: () {
deletingHistoryEntry =
history.indexOf(entry);
confirmEntryDelete();
},
);
},
).toList(),
Expand Down
2 changes: 2 additions & 0 deletions lib/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const inactiveTabLightColor = Color.fromRGBO(0, 0, 0, .25);
const activeTabDarkColor = Color(0xFFFFFFFF);
const inactiveTabDarkColor = Color.fromRGBO(255, 255, 255, .45);

const destructiveActionColor = Color(0xFFEF4444);

bool isDark(BuildContext context) =>
Theme.of(context).brightness == Brightness.dark;

Expand Down
72 changes: 47 additions & 25 deletions lib/widgets/stacked_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,65 @@ class StackedCard extends StatelessWidget {
required this.header,
required this.title,
this.fullWidth,
this.onLongPress,
}) : super(key: key);

final String header;
final String title;
final bool? fullWidth;
final GestureTapCallback? onLongPress;

@override
Widget build(BuildContext context) {
final width = (MediaQuery.of(context).size.width - 50);
final baseWidth = (MediaQuery.of(context).size.width - 50);
final width =
fullWidth != null && fullWidth! ? baseWidth + 10 : baseWidth / 2;

return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: getPrimaryColor(context),
),
width: fullWidth != null && fullWidth! ? width + 10 : width / 2,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
header.toUpperCase(),
style: const TextStyle(
fontSize: 12,
),
final widgetContent = Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
header.toUpperCase(),
style: const TextStyle(
fontSize: 12,
),
Text(
title,
style: const TextStyle(
fontSize: 20,
),
),
Text(
title,
style: const TextStyle(
fontSize: 20,
),
],
),
),
],
),
);

if (onLongPress != null) {
return InkWell(
onLongPress: onLongPress!,
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: getPrimaryColor(context),
),
child: SizedBox(
width: width,
child: widgetContent,
),
),
);
} else {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: getPrimaryColor(context),
),
width: width,
child: widgetContent,
);
}
}
}
2 changes: 1 addition & 1 deletion lib/widgets/wide_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WideCard extends StatelessWidget {

if (onTap != null) {
return InkWell(
onTap: onTap!,
onTap: onTap!,
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
Expand Down

0 comments on commit f2ba86c

Please sign in to comment.