Skip to content

3. Development

Naitbobbes edited this page Mar 21, 2018 · 18 revisions

1. General Important Classes

MainActivity

This class is responsible for the main functionality of the app. It handles the following:

  • Authentification and GUI setup (#authAndGuiInit, #initActivity, #GuiSetup)
  • Navigation (#onNavigationItemSelected)
  • Reminder functions (#reminderServiceConnection, #notifyReminderService)
  • Create/delete Lists (#addListToNav, #startListDialog, #onCustomMenuItemClickListener)
  • Create tasks (#initFab)
  • Filter tasks (#onOptionsItemSelected)
  • Display tasks (#showAllTasks, #showTasksOfList)
  • Long click operations on tasks (#onCreateContextMenu, #onContextItemSelected)
  • Hints (#hints)

ExpandableTodoTaskAdapter

Manages the following functionality of an expandable task item:

  • Set the view of a expandable task item (#getGroupView)
  • Snackbar when deleting (#getGroupView)
  • Filter and sorting conditions (#addSortCondition, #removeSortCondition, #filterTasks, #sortTasks)
  • Computes progress of a task by the number of done subtasks (#hasAutoProgress, #getProgressDone)

ProcessTodoTaskDialog

This class handles the dialog that appears when a task will be created or edited:

  • Initialize the view of the dialog (#initGui)
  • Handle if progress is dependend on done subtasks (#hasAutoProgress, #makeProgressGone)
  • Reminder- & deadline values default -1
  • Context menus for priority and list (#onCreateContextMenu, #onMenuItemSelected, #updateLists)

2. Database Classes

ToDo List uses a sqlite database where tables for tasks (TTodoTask), subtasks (TTodoSubTask) and lists (TTodoList) are stored. To organize these tables, the app uses the class DatabaseHelper and DBQueryHandler

DatabaseHelper

This class extends SQLiteOpenHelper and is responsible for fundamental things such as:

  • Create all tables mentioned above (#createAll)
  • Delete all tables (#deleteAll)

To get an instance of the database the common way is to use DatabaseHelper.getInstance(Context context). You can get readable or writable Database by calling #getReadableDatabase or #getWritableDatabase. This is important to work with DBQueryhandler.

DBQueryHandler

With this class the developer is able to update and change entries of the tables:

  • get next task to do (#getNextDueTask)
  • get tasks for reminder (#getTasksToRemind)
  • delete a list (#deleteTodoList)
  • delete a task (#deleteTodoTask)
  • get all todo tasks (#getAllTodoTasks)

    ... methods are self-explaining.

3. Notifications

ReminderService

The class ReminderService defines a service that is responsible to set a notification for the next due task. It is used inside the MainActivity by calling notifyReminderService(TodoTask currentTask). To catch tasks that have a reminder set DBQueryHandler.getTaskToRemind(SQLiteDatabase, long, HashSet<Integer>) can be called. The service uses an AlarmManager to awaken itself and trigger a notification.

NotificationHelper

The NotificationHelper is a class that is used in ReminderService in order to manage notifications. This class creates notifications based on the used SDK-version of the device. SDK-versions that are <= 26 need so called NotificationChannels which are created in createChannel().

4. Widget

The widget consists of 4 classes that will be explained in the following section.

TodoListWidgetConfigureActivity

This class represents the initialization of the appwidget. What it does is to let a user configure the list of which the tasks will be shown on the widget. It defines the view in the onCreate() method where a spinner is used to choose one of the existing lists that the user has created beforehand. A click on the button stores the chosen list as shared preference with the saveTitlePref(Context context, int AppWidgetId, String text) method and can be loaded by loadTitlePref(Context context, int AppWidgetID). In order to show all currently available lists updateLists() is called to update the "lists" ArrayAdapter. To return the string of the chosen list getSelectedItem() can be called.

WidgetViewsFactory

The WidgetViewsFactory class extends RemoteViewsFactory and defines the view of the individual tasks inside the ListView of the appwidget in getViewAt(int position). To get the set list out of the configuration activity, getListName(Context context, int AppWidgetId) returns a String of the list's name by calling loadTitlePref() of TodoListWidgetConfigureActivity that returns the shared preference which was stored before.

TodoListWidgetService

This class is a service that extends RemoteViewsService and does nothing but creating a new WidgetViewsFactory object that will be needed in TodoListWidget.

TodoListWidget

Here are updates and clicks on the widget itself managed. The layout of the overall widget is defined by a RemoteView "views". The onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) method is responsible for updating the content of our widget. The whole update implementation can be found in updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId that is called in onUpdate.

Clone this wiki locally