|
|
@ -22,10 +22,14 @@ import java.util.Date;
|
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
|
|
|
import java.util.TimerTask;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.content.res.Resources;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.Handler;
|
|
|
|
|
|
|
|
import android.view.Menu;
|
|
|
|
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TextView;
|
|
|
@ -46,6 +50,9 @@ import com.timsu.astrid.widget.NumberPickerDialog;
|
|
|
|
public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
private static final int ACTIVITY_EDIT = 0;
|
|
|
|
private static final int ACTIVITY_EDIT = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int EDIT_ID = Menu.FIRST;
|
|
|
|
|
|
|
|
private static final int DELETE_ID = Menu.FIRST + 1;
|
|
|
|
|
|
|
|
|
|
|
|
private TextView name;
|
|
|
|
private TextView name;
|
|
|
|
private TextView elapsed;
|
|
|
|
private TextView elapsed;
|
|
|
|
private TextView estimated;
|
|
|
|
private TextView estimated;
|
|
|
@ -78,6 +85,8 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
return controller.fetchTaskForView(identifier);
|
|
|
|
return controller.fetchTaskForView(identifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- initialization
|
|
|
|
|
|
|
|
|
|
|
|
private void setUpUIComponents() {
|
|
|
|
private void setUpUIComponents() {
|
|
|
|
Resources r = getResources();
|
|
|
|
Resources r = getResources();
|
|
|
|
setTitle(r.getString(R.string.taskView_title));
|
|
|
|
setTitle(r.getString(R.string.taskView_title));
|
|
|
@ -115,7 +124,7 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// update the UI
|
|
|
|
// update the timer UI
|
|
|
|
updateTimer = new Timer();
|
|
|
|
updateTimer = new Timer();
|
|
|
|
updateTimer.scheduleAtFixedRate(elapsedTimeUpdater, 0, 1000);
|
|
|
|
updateTimer.scheduleAtFixedRate(elapsedTimeUpdater, 0, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -125,10 +134,7 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
edit.setOnClickListener(new View.OnClickListener() {
|
|
|
|
edit.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent intent = new Intent(TaskView.this, TaskEdit.class);
|
|
|
|
editButtonClick();
|
|
|
|
intent.putExtra(TaskEdit.LOAD_INSTANCE_TOKEN,
|
|
|
|
|
|
|
|
model.getTaskIdentifier().getId());
|
|
|
|
|
|
|
|
startActivityForResult(intent, ACTIVITY_EDIT);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -139,11 +145,7 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
model.setTimerStart(new Date());
|
|
|
|
model.setTimerStart(new Date());
|
|
|
|
controller.saveTask(model);
|
|
|
|
controller.saveTask(model);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
long start = model.getTimerStart().getTime();
|
|
|
|
model.stopTimerAndUpdateElapsedTime();
|
|
|
|
model.setTimerStart(null);
|
|
|
|
|
|
|
|
long secondsElapsed = (System.currentTimeMillis() - start)/1000;
|
|
|
|
|
|
|
|
model.setElapsedSeconds((int) (model.getElapsedSeconds() +
|
|
|
|
|
|
|
|
secondsElapsed));
|
|
|
|
|
|
|
|
controller.saveTask(model);
|
|
|
|
controller.saveTask(model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -196,16 +198,34 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
view.setText(text);
|
|
|
|
view.setText(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
|
|
|
super.onCreateOptionsMenu(menu);
|
|
|
|
|
|
|
|
MenuItem item;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item = menu.add(Menu.NONE, EDIT_ID, 0, R.string.edit_label);
|
|
|
|
|
|
|
|
item.setIcon(android.R.drawable.ic_menu_edit);
|
|
|
|
|
|
|
|
item.setAlphabeticShortcut('s');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item = menu.add(Menu.NONE, DELETE_ID, 0, R.string.delete_label);
|
|
|
|
|
|
|
|
item.setIcon(android.R.drawable.ic_menu_delete);
|
|
|
|
|
|
|
|
item.setAlphabeticShortcut('d');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- event handlers
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode,
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode,
|
|
|
|
Intent intent) {
|
|
|
|
Intent intent) {
|
|
|
|
if(resultCode == RESULT_CANCELED)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if user edits a task, take them straight to the listing page
|
|
|
|
// if user doesn't click 'back', finish this activity too
|
|
|
|
|
|
|
|
if(resultCode != RESULT_CANCELED) {
|
|
|
|
setResult(resultCode);
|
|
|
|
setResult(resultCode);
|
|
|
|
finish();
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
protected void onPause() {
|
|
|
@ -218,6 +238,54 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
populateFields();
|
|
|
|
populateFields();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
/** Cancel the timer thread */
|
|
|
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
updateTimer.cancel();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- event response methods
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void editButtonClick() {
|
|
|
|
|
|
|
|
Intent intent = new Intent(TaskView.this, TaskEdit.class);
|
|
|
|
|
|
|
|
intent.putExtra(TaskEdit.LOAD_INSTANCE_TOKEN,
|
|
|
|
|
|
|
|
model.getTaskIdentifier().getId());
|
|
|
|
|
|
|
|
startActivityForResult(intent, ACTIVITY_EDIT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void deleteButtonClick() {
|
|
|
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
|
|
|
|
.setTitle(R.string.delete_title)
|
|
|
|
|
|
|
|
.setMessage(R.string.delete_this_task_title)
|
|
|
|
|
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
|
|
|
|
.setPositiveButton(android.R.string.ok,
|
|
|
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
|
|
|
controller.deleteTask(model.getTaskIdentifier());
|
|
|
|
|
|
|
|
setResult(RESULT_OK);
|
|
|
|
|
|
|
|
finish();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
|
|
|
|
|
|
|
switch(item.getItemId()) {
|
|
|
|
|
|
|
|
case EDIT_ID:
|
|
|
|
|
|
|
|
editButtonClick();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case DELETE_ID:
|
|
|
|
|
|
|
|
deleteButtonClick();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return super.onMenuItemSelected(featureId, item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Update components that depend on elapsed time */
|
|
|
|
/** Update components that depend on elapsed time */
|
|
|
|
private void updateElapsedTimeText() {
|
|
|
|
private void updateElapsedTimeText() {
|
|
|
|
Resources r = getResources();
|
|
|
|
Resources r = getResources();
|
|
|
@ -253,12 +321,5 @@ public class TaskView extends TaskModificationActivity<TaskModelForView> {
|
|
|
|
|
|
|
|
|
|
|
|
progressDialog.setInitialValue(model.getProgressPercentage());
|
|
|
|
progressDialog.setInitialValue(model.getProgressPercentage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
/** Cancel the timer thread */
|
|
|
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
updateTimer.cancel();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|