Compare commits
No commits in common. "b79d68c7a285583f84c378dc41243ee99e8f66f8" and "0874ffa98e718e72c01eb0636fb6604333661084" have entirely different histories.
b79d68c7a2
...
0874ffa98e
@ -1,5 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:markdown/markdown.dart' as md;
|
|
||||||
import 'api_service.dart';
|
import 'api_service.dart';
|
||||||
import 'structs.dart';
|
import 'structs.dart';
|
||||||
import 'emailView.dart';
|
import 'emailView.dart';
|
||||||
@ -9,28 +8,24 @@ class EmailListScreen extends StatefulWidget {
|
|||||||
final Future<List<String>> Function(List<String>, String) getEmailContent;
|
final Future<List<String>> Function(List<String>, String) getEmailContent;
|
||||||
final String folder;
|
final String folder;
|
||||||
final GlobalKey<_EmailListScreenState> key;
|
final GlobalKey<_EmailListScreenState> key;
|
||||||
final Function(List<GetThreadResponse>)? onSelectionChanged;
|
|
||||||
|
|
||||||
EmailListScreen({
|
EmailListScreen(
|
||||||
required this.key,
|
{required this.key,
|
||||||
required this.emails,
|
required this.emails,
|
||||||
required this.getEmailContent,
|
required this.getEmailContent,
|
||||||
required this.folder,
|
required this.folder})
|
||||||
this.onSelectionChanged,
|
: super(key: key);
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_EmailListScreenState createState() => _EmailListScreenState();
|
_EmailListScreenState createState() => _EmailListScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EmailListScreenState extends State<EmailListScreen>
|
class _EmailListScreenState extends State<EmailListScreen> {
|
||||||
with TickerProviderStateMixin {
|
|
||||||
late List<bool> selectStates; // for checkboxes if its selected or not
|
late List<bool> selectStates; // for checkboxes if its selected or not
|
||||||
late List<GetThreadResponse> selectedEmails =
|
late List<GetThreadResponse> selectedEmails =
|
||||||
[]; // holds the emails that are selected i.e. the emails that got the checkbox on
|
[]; // holds the emails that are selected i.e. the emails that got the checkbox on
|
||||||
final Set<int> _hoveredRows = {}; //the row that is being hovered over atm
|
final Set<int> _hoveredRows = {}; //the row that is being hovered over atm
|
||||||
bool bulkSelectMenu = false;
|
bool bulkSelectMenu = false;
|
||||||
final GlobalKey<EmailPageState> _emailPageKey = GlobalKey<EmailPageState>();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -47,57 +42,21 @@ class _EmailListScreenState extends State<EmailListScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool selectAllChecks(bool selectionType) {
|
bool selectAllChecks(bool selectionType) {
|
||||||
//perhaps it should return a list of the selected
|
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedEmails = [];
|
|
||||||
if (selectionType) {
|
if (selectionType) {
|
||||||
bulkSelectMenu = true;
|
bulkSelectMenu = true;
|
||||||
for (int email = 0; email < selectStates.length; email++) {
|
}
|
||||||
selectStates[email] = selectionType;
|
for (int email = 0; email < selectStates.length; email++) {
|
||||||
selectedEmails.add(widget.emails[email]);
|
selectStates[email] = selectionType;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int email = 0; email < selectStates.length; email++) {
|
|
||||||
selectStates[email] = selectionType;
|
|
||||||
}
|
|
||||||
selectedEmails = [];
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
widget.onSelectionChanged?.call(selectedEmails);
|
|
||||||
printTheSelected();
|
printTheSelected();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool markAsRead(bool read) {
|
|
||||||
print("markasread $read");
|
|
||||||
setState(() {
|
|
||||||
if (read) {
|
|
||||||
//read
|
|
||||||
for (int email = 0; email < selectedEmails.length; email++) {
|
|
||||||
selectedEmails[email].seen = read;
|
|
||||||
ApiService()
|
|
||||||
.markAsSeen(selectedEmails[email].id); //the remote or .json
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//unread
|
|
||||||
for (int email = 0; email < selectedEmails.length; email++) {
|
|
||||||
selectedEmails[email].seen = read;
|
|
||||||
ApiService()
|
|
||||||
.markAsUnseen(selectedEmails[email].id); //the remote or .json
|
|
||||||
print(selectedEmails[email].subject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<GetThreadResponse> listOfSelectedThreads() {
|
|
||||||
return selectedEmails;
|
|
||||||
}
|
|
||||||
|
|
||||||
void printTheSelected() {
|
void printTheSelected() {
|
||||||
for (int i = 0; i < selectedEmails.length; i++) {
|
for (int i = 0; i < selectedEmails.length; i++) {
|
||||||
print(selectedEmails[i].subject);
|
print(selectedEmails);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,19 +83,11 @@ class _EmailListScreenState extends State<EmailListScreen>
|
|||||||
setState(() {
|
setState(() {
|
||||||
//works great
|
//works great
|
||||||
selectStates[index] = value ?? false;
|
selectStates[index] = value ?? false;
|
||||||
|
if (value!) {
|
||||||
setState(() {
|
selectedEmails.add(widget.emails[index]);
|
||||||
if (value!) {
|
} else {
|
||||||
selectedEmails.add(widget.emails[index]);
|
selectedEmails.remove(widget.emails[index]);
|
||||||
//here i must update the other side
|
}
|
||||||
_emailPageKey.currentState?.getListOfSelected();
|
|
||||||
} else {
|
|
||||||
selectedEmails.remove(widget.emails[index]);
|
|
||||||
_emailPageKey.currentState?.getListOfSelected();
|
|
||||||
}
|
|
||||||
widget.onSelectionChanged?.call(selectedEmails);
|
|
||||||
print(selectedEmails);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -146,6 +97,7 @@ class _EmailListScreenState extends State<EmailListScreen>
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [Text(email.subject)],
|
children: [Text(email.subject)],
|
||||||
),
|
),
|
||||||
|
// tileColor: () ,
|
||||||
trailing: _hoveredRows.contains(index)
|
trailing: _hoveredRows.contains(index)
|
||||||
? Row(
|
? Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
@ -209,12 +161,10 @@ class _EmailListScreenState extends State<EmailListScreen>
|
|||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class EmailPage extends StatefulWidget {
|
class EmailPage extends StatefulWidget {
|
||||||
|
EmailPage({Key? key}) : super(key: key);
|
||||||
String selectedFolder = "INBOX"; //starter
|
String selectedFolder = "INBOX"; //starter
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int page = 1;
|
int page = 1;
|
||||||
final Function(List<GetThreadResponse>)? onSelectionChanged;
|
|
||||||
|
|
||||||
EmailPage({Key? key, this.onSelectionChanged}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
EmailPageState createState() => EmailPageState();
|
EmailPageState createState() => EmailPageState();
|
||||||
@ -289,19 +239,9 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
|
|
||||||
bool selectAllEmails(bool selectionType) {
|
bool selectAllEmails(bool selectionType) {
|
||||||
emailListKey.currentState?.selectAllChecks(selectionType);
|
emailListKey.currentState?.selectAllChecks(selectionType);
|
||||||
return selectionType;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool markSelectedAsRead(bool selectionType) {
|
|
||||||
emailListKey.currentState?.markAsRead(selectionType);
|
|
||||||
return selectionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<GetThreadResponse> getListOfSelected() {
|
|
||||||
return emailListKey.currentState!.listOfSelectedThreads() ?? [];
|
|
||||||
}
|
|
||||||
// return [GetThreadResponse(id: 1, messages: [], subject: "subject", date: DateTime(2025), from_name: "from_name", from_address: "from_address", to: [], seen: false)];
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -311,7 +251,6 @@ class EmailPageState extends State<EmailPage> {
|
|||||||
// getEmailContent: apiService.fetchEmailContent,
|
// getEmailContent: apiService.fetchEmailContent,
|
||||||
getEmailContent: apiService.fetchMarkdownContent,
|
getEmailContent: apiService.fetchMarkdownContent,
|
||||||
folder: widget.selectedFolder, //try to grab from it directly
|
folder: widget.selectedFolder, //try to grab from it directly
|
||||||
onSelectionChanged: widget.onSelectionChanged,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
];
|
];
|
||||||
bool _checkboxState = false;
|
bool _checkboxState = false;
|
||||||
bool bulkOptionsState = false;
|
bool bulkOptionsState = false;
|
||||||
List<GetThreadResponse> selectedThreads =
|
|
||||||
[]; //this should store the emails that are being stored downstream too
|
|
||||||
|
|
||||||
List<String> _tabs = ['Emails'];
|
List<String> _tabs = ['Emails'];
|
||||||
Map<String, Widget> _tabWidgets = {};
|
Map<String, Widget> _tabWidgets = {};
|
||||||
@ -42,11 +40,6 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
_tabController = TabController(length: _tabs.length, vsync: this);
|
_tabController = TabController(length: _tabs.length, vsync: this);
|
||||||
_tabWidgets['Emails'] = EmailPage(
|
_tabWidgets['Emails'] = EmailPage(
|
||||||
key: _emailPageKey,
|
key: _emailPageKey,
|
||||||
onSelectionChanged: (updatedList) {
|
|
||||||
setState(() {
|
|
||||||
selectedThreads = updatedList;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,45 +354,24 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
Icons.arrow_drop_down_outlined),
|
Icons.arrow_drop_down_outlined),
|
||||||
itemBuilder: (BuildContext context) =>
|
itemBuilder: (BuildContext context) =>
|
||||||
<PopupMenuEntry<String>>[
|
<PopupMenuEntry<String>>[
|
||||||
PopupMenuItem<String>(
|
const PopupMenuItem<String>(
|
||||||
//select all
|
child: Text("All")),
|
||||||
child: Text("All"),
|
const PopupMenuItem<String>(
|
||||||
onTap: () {
|
child: Text("None")),
|
||||||
_emailPageKey.currentState!
|
const PopupMenuItem<String>(
|
||||||
.selectAllEmails(true);
|
child: Text("Read")),
|
||||||
},
|
const PopupMenuItem<String>(
|
||||||
),
|
child: Text("Unread")),
|
||||||
PopupMenuItem<String>(
|
const PopupMenuItem<String>(
|
||||||
child: Text("None"),
|
|
||||||
onTap: () {
|
|
||||||
_emailPageKey.currentState!
|
|
||||||
.selectAllEmails(false);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
child: Text("Read"),
|
|
||||||
onTap: () {
|
|
||||||
//select the read
|
|
||||||
},
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
//select the unread
|
|
||||||
child: Text("Unread"),
|
|
||||||
onTap: () {
|
|
||||||
//select the unread
|
|
||||||
},
|
|
||||||
),
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
child: Text("Starred")),
|
child: Text("Starred")),
|
||||||
PopupMenuItem<String>(
|
const PopupMenuItem<String>(
|
||||||
child: Text("Unstarred")),
|
child: Text("Unstarred")),
|
||||||
],
|
],
|
||||||
onSelected: (String result) {
|
onSelected: (String result) {
|
||||||
print("result $result");
|
print("result $result");
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (selectedThreads.isNotEmpty) ...<Widget>[
|
if (bulkOptionsState) ...<Widget>[
|
||||||
//this needs to know if anything got selected,
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: null,
|
onPressed: null,
|
||||||
icon: Icon(Icons.archive_outlined)),
|
icon: Icon(Icons.archive_outlined)),
|
||||||
@ -407,11 +379,7 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
onPressed: null,
|
onPressed: null,
|
||||||
icon: Icon(Icons.delete_outlined)),
|
icon: Icon(Icons.delete_outlined)),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
onPressed: null,
|
||||||
_emailPageKey.currentState!
|
|
||||||
.markSelectedAsRead(
|
|
||||||
true); //mark as read
|
|
||||||
},
|
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.mark_email_read_outlined)),
|
Icons.mark_email_read_outlined)),
|
||||||
IconButton(
|
IconButton(
|
||||||
@ -422,10 +390,9 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
PopupMenuButton<String>(
|
PopupMenuButton<String>(
|
||||||
icon: const Icon(Icons.more_vert),
|
icon: const Icon(Icons.more_vert),
|
||||||
itemBuilder: (BuildContext context) {
|
itemBuilder: (BuildContext context) {
|
||||||
if (selectedThreads.isEmpty) {
|
if (!bulkOptionsState) {
|
||||||
//why tf?
|
|
||||||
return <PopupMenuEntry<String>>[
|
return <PopupMenuEntry<String>>[
|
||||||
PopupMenuItem<String>(
|
const PopupMenuItem<String>(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons
|
Icon(Icons
|
||||||
@ -436,28 +403,19 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
Text("Mark all as read")
|
Text("Mark all as read")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
|
||||||
_emailPageKey.currentState!
|
|
||||||
.selectAllEmails(true);
|
|
||||||
_emailPageKey.currentState!
|
|
||||||
.markSelectedAsRead(true);
|
|
||||||
_emailPageKey.currentState!
|
|
||||||
.selectAllEmails(false);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
const PopupMenuDivider(),
|
const PopupMenuDivider(),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
child: Text(
|
child: Text(
|
||||||
"Select messages to see more actions",
|
"Select messages to see more actions",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors
|
color: Colors
|
||||||
.blueGrey.shade300),
|
.blueGrey.shade300),
|
||||||
),
|
))
|
||||||
)
|
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
return <PopupMenuEntry<String>>[
|
return <PopupMenuEntry<String>>[
|
||||||
PopupMenuItem<String>(
|
const PopupMenuItem<String>(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons
|
Icon(Icons
|
||||||
@ -468,34 +426,28 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
Text("Mark as unread")
|
Text("Mark as unread")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
|
||||||
_emailPageKey.currentState!
|
|
||||||
.markSelectedAsRead(
|
|
||||||
false);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
const PopupMenuItem<String>(
|
const PopupMenuItem<String>(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.snooze_outlined),
|
Icon(Icons.snooze_outlined),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 4.0,
|
width: 4.0,
|
||||||
),
|
),
|
||||||
Text("Snooze")
|
Text("Snooze")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const PopupMenuItem<String>(
|
const PopupMenuItem<String>(
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons
|
Icon(Icons.star_border_outlined),
|
||||||
.star_border_outlined),
|
const SizedBox(
|
||||||
const SizedBox(
|
width: 4.0,
|
||||||
width: 4.0,
|
),
|
||||||
),
|
Text("Add star")
|
||||||
Text("Add star")
|
],
|
||||||
],
|
),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user