Skip to content

Commit

Permalink
fixed#16
Browse files Browse the repository at this point in the history
  • Loading branch information
babanomania committed Jul 7, 2018
1 parent 33a9090 commit 3868125
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 52 deletions.
12 changes: 12 additions & 0 deletions lib/data/DataCache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class DataCache {

String sortTasks = "";

List<int> selectedTaskId = new List<int>();
bool isSelected = false;

final String dbName = "CleanToDoDB.db";
TaskProvider taskProvider = new TaskProvider();
CategoryProvider categoryProvider = new CategoryProvider();
Expand Down Expand Up @@ -431,6 +434,15 @@ class DataCache {

}

deleteSelectedTask() {

this.selectedTaskId.forEach( (id) =>
deleteTask(
tasksData.firstWhere( (_task) => _task.id == id )
)
);
}

deleteTask(Task task) {
tasksData.remove( task );
taskProvider.delete( task.id );
Expand Down
2 changes: 1 addition & 1 deletion lib/detail/TitleDetailTile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TitleDetailTile extends StatelessWidget {
return new ListTile(

leading: new IconButton(
icon: this.completed ? icons.taskCompletedIcon(context) : icons.taskPendingIcon(context),
icon: this.completed ? icons.taskCompletedIcon( false, context) : icons.taskPendingIcon( false, context),
onPressed: (){
this.completed ? this.update_completed( false ): this.update_completed( true );
},
Expand Down
37 changes: 36 additions & 1 deletion lib/lists/CTAppBar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class CTAppBar {
this.searchString, this.doSearch,
this.themeColor, this.updateColor,
this.isShowCompletedTasks, this.updateShowCompletedTasks,
this.sortString, this.updateSortTasks, this.categoryName, this.updateGroupName
this.sortString, this.updateSortTasks, this.categoryName, this.updateGroupName,
this.isSelectedTask, this.unSelectTask, this.deleteSelectedTask,
});

final String appDefaultTitle = 'To-Do';
Expand All @@ -27,6 +28,7 @@ class CTAppBar {
final ValueChanged<int> deleteCategory ;
final ValueChanged<int> deleteCategoryGroup ;

final bool isSelectedTask ;
final bool isSearch ;
final bool isMyDay ;
final bool isGroup ;
Expand All @@ -49,6 +51,9 @@ class CTAppBar {
final ValueChanged<String> updateCategoryName;
final ValueChanged<String> updateGroupName;

final ValueChanged<bool> unSelectTask;
final ValueChanged<bool> deleteSelectedTask;

IconButton colorIcon( Color btnColor, AppColors color, context ){
return new IconButton(
icon: new CircleAvatar(
Expand Down Expand Up @@ -318,6 +323,33 @@ class CTAppBar {

}

AppBar selectedAppBar(){

return new AppBar(

leading: new IconButton(
icon: new Icon( Icons.arrow_back ),
onPressed: (){
unSelectTask(true);
},
),

title: new Text( "Selected" ),

actions: [

new IconButton(
icon: new Icon( Icons.delete ),
onPressed: (){
deleteSelectedTask(true);
},
),

],
);

}

AppBar searchAppBar(){

return new AppBar(
Expand Down Expand Up @@ -470,6 +502,9 @@ class CTAppBar {

AppBar build(context) {

if( isSelectedTask )
return selectedAppBar();

if( isGroup )
return groupAppBar(context);

Expand Down
88 changes: 52 additions & 36 deletions lib/lists/TaskTile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import 'package:clean_todo/styles/AppIcons.dart';

class TaskTile extends StatefulWidget {

TaskTile({ this.task , this.extraTask, this.categoryData, this.toggleTask, this.updateTask, this.deleteTask });
TaskTile({
this.task , this.extraTask, this.categoryData,
this.toggleTask, this.updateTask, this.deleteTask,
this.isSelected = false, this.selectTask,
});

final Task task ;
final Task extraTask ;
Expand All @@ -19,6 +23,9 @@ class TaskTile extends StatefulWidget {
final ValueChanged<Task> updateTask ;
final ValueChanged<Task> deleteTask ;

final bool isSelected;
final ValueChanged<Task> selectTask ;

@override
_TasksTileState createState() => new _TasksTileState();
}
Expand All @@ -34,7 +41,7 @@ class _TasksTileState extends State<TaskTile> {
EdgeInsets tmargin = new EdgeInsets.only( top: 10.0, );
EdgeInsets lmargin = new EdgeInsets.only( left: 10.0, top: 10.0, );

final TextStyle taskSubTitle = new TextStyle( color: Theme.of(context).primaryColorLight, fontWeight: FontWeight.w500 );
final TextStyle taskSubTitle = new TextStyle( color: ( widget.isSelected ? Theme.of(context).highlightColor : Theme.of(context).primaryColorLight ), fontWeight: FontWeight.w500 );
final TextStyle taskSubTitleDue = new TextStyle( color: Theme.of(context).errorColor, fontWeight: FontWeight.w500 );

if( task.category != null ) {
Expand All @@ -59,7 +66,7 @@ class _TasksTileState extends State<TaskTile> {
padding: lmargin,
child: new Row(
children: <Widget>[
icons.listIconDue( context, task.isDue ),
icons.listIconDue( widget.isSelected, context, task.isDue ),
new Text( task.isDue ? 'Due ' + task.deadline : task.deadline,
style: task.isDue ? taskSubTitleDue : taskSubTitle ),
],
Expand All @@ -72,23 +79,23 @@ class _TasksTileState extends State<TaskTile> {
if( task.reminder != null ){
subtitleWidgets.add(
new Padding(
padding: lmargin, child: icons.listIconReminder(context),
padding: lmargin, child: icons.listIconReminder(widget.isSelected, context),
)
);
}

if( task.notes != null ){
subtitleWidgets.add(
new Padding(
padding: lmargin, child : icons.listIconNotes(context),
padding: lmargin, child : icons.listIconNotes(widget.isSelected, context),
)
);
}

if( task.repeat != null && task.repeat != CTRepeatInterval.NONE.index){
subtitleWidgets.add(
new Padding(
padding: lmargin, child: icons.listIconRepeat(context)
padding: lmargin, child: icons.listIconRepeat(widget.isSelected, context)
)
);
}
Expand Down Expand Up @@ -124,49 +131,58 @@ class _TasksTileState extends State<TaskTile> {

}),

child: new ListTile(
child: new ListTileTheme(

leading: new IconButton(
selectedColor: Theme.of(context).highlightColor,
child: new ListTile(
leading: new IconButton(

icon: widget.task.completed ? icons.taskCompletedIcon(context) : icons.taskPendingIcon(context),
icon: widget.task.completed ? icons.taskCompletedIcon(widget.isSelected, context) : icons.taskPendingIcon(widget.isSelected, context),

onPressed: (){
onPressed: (){

this.setState((){
widget.task.completed ? widget.task.completed = false : widget.task.completed = true ;
});
this.setState((){
widget.task.completed ? widget.task.completed = false : widget.task.completed = true ;
});

widget.toggleTask( widget.task );
widget.toggleTask( widget.task );

},
),
},
),

title: new Text( widget.task.title, style : widget.task.completed ? taskTitleChecked : taskTitle ),
title: new Text( widget.task.title, style : widget.task.completed ? taskTitleChecked : taskTitle ),

subtitle: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: getSubtitleWidgets( widget.task ),
),
subtitle: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: getSubtitleWidgets( widget.task ),
),

onTap: (){
onTap: (){

widget.extraTask.copy(widget.task);
widget.extraTask.copy(widget.task);

Navigator.push(
context,
new MaterialPageRoute( builder: (context) =>
new TaskDetail(
task: widget.extraTask,
categoryData: widget.categoryData,
updateTask: (task){
widget.updateTask(task);
},
)
)
);
Navigator.push(
context,
new MaterialPageRoute( builder: (context) =>
new TaskDetail(
task: widget.extraTask,
categoryData: widget.categoryData,
updateTask: (task){
widget.updateTask(task);
},
)
)
);

},
},

selected: widget.isSelected,
onLongPress: ((){
print( "long press on task tile" );
widget.selectTask(widget.task);
}),

),
),
);
}
Expand Down
12 changes: 11 additions & 1 deletion lib/lists/TasksList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import 'package:clean_todo/styles/AppIcons.dart';

class TasksList extends StatefulWidget {

TasksList({ this.tasks, this.extraTask, this.categoryData, this.toggleTask, this.updateTask, this.deleteTask });
TasksList({
this.tasks, this.extraTask, this.categoryData,
this.toggleTask, this.updateTask, this.deleteTask,
this.selectedTask, this.selectTask, this.isSelected,
});

final List<Task> tasks ;
final Task extraTask ;
Expand All @@ -16,6 +20,10 @@ class TasksList extends StatefulWidget {
final ValueChanged<Task> toggleTask;
final ValueChanged<Task> updateTask ;
final ValueChanged<Task> deleteTask ;
final ValueChanged<Task> selectTask ;

final bool isSelected ;
final List<int> selectedTask ;

@override
_TasksListState createState() => new _TasksListState();
Expand Down Expand Up @@ -57,6 +65,8 @@ class _TasksListState extends State<TasksList> {
toggleTask: (task) => widget.toggleTask(task),
updateTask : (task) => widget.updateTask(task),
deleteTask: (task) => widget.deleteTask(task),
isSelected: widget.isSelected ? widget.selectedTask.where( (id) => id == task.id ).length > 0 : false,
selectTask: widget.selectTask,
)

).toList(),
Expand Down
37 changes: 36 additions & 1 deletion lib/lists/TasksPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ class _TasksPageState extends State<TasksPage> {
})
),

isSelectedTask: widget.cache.isSelected,

unSelectTask: ( (_){
this.setState((){
widget.cache.isSelected = false;
widget.cache.selectedTaskId.clear();
});
}),

deleteSelectedTask: ( (_){
this.setState((){
widget.cache.deleteSelectedTask();
widget.cache.isSelected = false;
widget.cache.selectedTaskId.clear();
});
}),

).build(context);

AppSidebar appSidebar = new AppSidebar(
Expand Down Expand Up @@ -281,6 +298,24 @@ class _TasksPageState extends State<TasksPage> {
}),

deleteTask: widget.cache.deleteTask,

isSelected: widget.cache.isSelected,

selectedTask: widget.cache.selectedTaskId,

selectTask: ( (task){
this.setState((){

widget.cache.selectedTaskId.contains( task.id ) ?
widget.cache.selectedTaskId.remove( task.id ):
widget.cache.selectedTaskId.add(task.id);

widget.cache.selectedTaskId.length > 0 ?
widget.cache.isSelected = true :
widget.cache.isSelected = false;
});
}),

);

Widget appBody = widget.cache.showMyDay ? myDayAppBody : listAppBody ;
Expand Down Expand Up @@ -524,7 +559,7 @@ class _TasksPageState extends State<TasksPage> {

);

FloatingActionButton appFab = widget.cache.showMyDay ? null :
FloatingActionButton appFab = ( widget.cache.showMyDay || widget.cache.isSelected )? null :
( ( widget.cache.filterCategory == null ) || widget.cache.filterGroup ? appFabGroup : appFabFilter );

return new Scaffold(
Expand Down
1 change: 1 addition & 0 deletions lib/settings/Themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Themes {
accentColor: primary,
primaryColorLight: primary,
errorColor: error,
highlightColor: primary.withOpacity( 0.7 ),

iconTheme: new IconThemeData(
color: primary,
Expand Down
Loading

0 comments on commit 3868125

Please sign in to comment.