Comments sync menu button added and added timer controls to comment bar

pull/14/head
Andrew Shaw 14 years ago
parent 06381f4fb5
commit 7fd11fd094

@ -5,6 +5,7 @@ import greendroid.widget.AsyncImageView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -50,9 +51,10 @@ import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.SyncV2Service.SyncResultCallback; import com.todoroo.astrid.service.SyncV2Service.SyncResultCallback;
import com.todoroo.astrid.timers.TimerActionControlSet.TimerStoppedListener;
import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.utility.Flags;
public class EditNoteActivity extends LinearLayout { public class EditNoteActivity extends LinearLayout implements TimerStoppedListener {
@ -71,6 +73,8 @@ public class EditNoteActivity extends LinearLayout {
private TextView loadingText; private TextView loadingText;
private final View commentsBar; private final View commentsBar;
private final View parentView; private final View parentView;
private View timerView;
private View commentButton;
private int commentItems = 10; private int commentItems = 10;
private final List<UpdatesChangedListener> listeners = new LinkedList<UpdatesChangedListener>(); private final List<UpdatesChangedListener> listeners = new LinkedList<UpdatesChangedListener>();
@ -124,7 +128,10 @@ public class EditNoteActivity extends LinearLayout {
// --- UI preparation // --- UI preparation
private void setUpInterface() { private void setUpInterface() {
final View commentButton = commentsBar.findViewById(R.id.commentButton);
timerView = commentsBar.findViewById(R.id.timer_container);
commentButton = commentsBar.findViewById(R.id.commentButton);
commentField = (EditText) commentsBar.findViewById(R.id.commentField); commentField = (EditText) commentsBar.findViewById(R.id.commentField);
commentField.setOnEditorActionListener(new OnEditorActionListener() { commentField.setOnEditorActionListener(new OnEditorActionListener() {
@Override @Override
@ -140,6 +147,7 @@ public class EditNoteActivity extends LinearLayout {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
commentButton.setVisibility((s.length() > 0) ? View.VISIBLE : View.GONE); commentButton.setVisibility((s.length() > 0) ? View.VISIBLE : View.GONE);
timerView.setVisibility((s.length() > 0) ? View.GONE : View.VISIBLE);
} }
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -150,6 +158,21 @@ public class EditNoteActivity extends LinearLayout {
// //
} }
}); });
commentField.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
timerView.setVisibility(View.GONE);
commentButton.setVisibility(View.VISIBLE);
}
else {
timerView.setVisibility(View.VISIBLE);
commentButton.setVisibility(View.GONE);
}
}
});
commentButton.setOnClickListener(new OnClickListener() { commentButton.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -168,6 +191,7 @@ public class EditNoteActivity extends LinearLayout {
//TODO add loading text back in //TODO add loading text back in
// loadingText = (TextView) findViewById(R.id.loading); // loadingText = (TextView) findViewById(R.id.loading);
loadingText = new TextView(getContext()); loadingText = new TextView(getContext());
} }
private void setUpListAdapter() { private void setUpListAdapter() {
@ -349,9 +373,12 @@ public class EditNoteActivity extends LinearLayout {
} }
private void addComment() { private void addComment() {
addComment(commentField.getText().toString(), "task_comment"); //$NON-NLS-1$
}
private void addComment(String message, String actionCode) {
Update update = new Update(); Update update = new Update();
update.setValue(Update.MESSAGE, commentField.getText().toString()); update.setValue(Update.MESSAGE, message);
update.setValue(Update.ACTION_CODE, "task_comment"); //$NON-NLS-1$ update.setValue(Update.ACTION_CODE, actionCode);
update.setValue(Update.USER_ID, 0L); update.setValue(Update.USER_ID, 0L);
update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID)); update.setValue(Update.TASK, task.getValue(Task.REMOTE_ID));
update.setValue(Update.CREATION_DATE, DateUtilities.now()); update.setValue(Update.CREATION_DATE, DateUtilities.now());
@ -452,4 +479,20 @@ public class EditNoteActivity extends LinearLayout {
if (listeners.contains(listener)) if (listeners.contains(listener))
listeners.remove(listener); listeners.remove(listener);
} }
@Override
public void timerStarted(Task task) {
// TODO Auto-generated method stub
addComment(getContext().getString(R.string.TEA_timer_comment_started) + " " + DateUtilities.getTimeString(getContext(), new Date()), "task_started"); //$NON-NLS-1$
}
@Override
public void timerStopped(Task task) {
// TODO Auto-generated method stub
String elapsedTime = DateUtils.formatElapsedTime(task.getValue(Task.ELAPSED_SECONDS));
addComment(getContext().getString(R.string.TEA_timer_comment_stopped) + " " +
DateUtilities.getTimeString(getContext(), new Date()) + "\n" + getContext().getString(R.string.TEA_timer_comment_spent) + " " + elapsedTime, "task_stopped"); //$NON-NLS-1$
}
} }

@ -1,13 +1,14 @@
package com.todoroo.astrid.timers; package com.todoroo.astrid.timers;
import java.util.LinkedList;
import java.util.List;
import android.app.Activity; import android.app.Activity;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.format.DateUtils;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.Chronometer; import android.widget.Chronometer;
import android.widget.TextView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
@ -18,20 +19,21 @@ public class TimerActionControlSet extends TaskEditControlSet {
private final Button timerButton; private final Button timerButton;
private final Chronometer chronometer; private final Chronometer chronometer;
private final TextView timerLabel; private final View timerContainer;
private boolean timerActive; private boolean timerActive;
private final Activity activity; private final Activity activity;
private Task task; private Task task;
private TimerStoppedListener listener; private final List<TimerStoppedListener> listeners = new LinkedList<TimerStoppedListener>();
public TimerActionControlSet(Activity activity, View parent) { public TimerActionControlSet(Activity activity, View parent) {
super(activity, -1); super(activity, -1);
this.activity = activity; this.activity = activity;
timerButton = (Button) parent.findViewById(R.id.timer_button); timerButton = (Button) parent.findViewById(R.id.timer_button);
timerButton.setOnClickListener(timerListener);
timerContainer = (View) parent.findViewById(R.id.timer_container);
timerContainer.setOnClickListener(timerListener);
chronometer = (Chronometer) parent.findViewById(R.id.timer); chronometer = (Chronometer) parent.findViewById(R.id.timer);
timerLabel = (TextView) parent.findViewById(R.id.timer_label);
} }
@Override @Override
@ -58,11 +60,14 @@ public class TimerActionControlSet extends TaskEditControlSet {
public void onClick(View v) { public void onClick(View v) {
if (timerActive) { if (timerActive) {
TimerPlugin.updateTimer(activity, task, false); TimerPlugin.updateTimer(activity, task, false);
if (listener != null)
for(TimerStoppedListener listener : listeners)
listener.timerStopped(task); listener.timerStopped(task);
chronometer.stop(); chronometer.stop();
} else { } else {
TimerPlugin.updateTimer(activity, task, true); TimerPlugin.updateTimer(activity, task, true);
for(TimerStoppedListener listener : listeners)
listener.timerStarted(task);
chronometer.start(); chronometer.start();
} }
timerActive = !timerActive; timerActive = !timerActive;
@ -86,23 +91,26 @@ public class TimerActionControlSet extends TaskEditControlSet {
long elapsed = task.getValue(Task.ELAPSED_SECONDS) * 1000L; long elapsed = task.getValue(Task.ELAPSED_SECONDS) * 1000L;
if (timerActive) { if (timerActive) {
chronometer.setVisibility(View.VISIBLE); chronometer.setVisibility(View.VISIBLE);
timerLabel.setVisibility(View.GONE);
elapsed += DateUtilities.now() - task.getValue(Task.TIMER_START); elapsed += DateUtilities.now() - task.getValue(Task.TIMER_START);
chronometer.setBase(SystemClock.elapsedRealtime() - elapsed); chronometer.setBase(SystemClock.elapsedRealtime() - elapsed);
chronometer.start(); chronometer.start();
} else { } else {
chronometer.setVisibility(View.GONE); chronometer.setVisibility(View.INVISIBLE);
timerLabel.setVisibility(View.VISIBLE);
timerLabel.setText(DateUtils.formatElapsedTime(elapsed / 1000L));
chronometer.stop(); chronometer.stop();
} }
} }
public interface TimerStoppedListener { public interface TimerStoppedListener {
public void timerStopped(Task task); public void timerStopped(Task task);
public void timerStarted(Task task);
}
public void addListener(TimerStoppedListener listener) {
this.listeners.add(listener);
} }
public void setListener(TimerStoppedListener listener) { public void removeListener(TimerStoppedListener listener) {
this.listener = listener; if (listeners.contains(listener))
listeners.remove(listener);
} }
} }

@ -87,4 +87,9 @@ public class TimerControlSet extends PopupControlSet implements TimerStoppedList
elapsed.readFromTask(task); elapsed.readFromTask(task);
} }
@Override
public void timerStarted(Task task) {
return;
}
} }

@ -51,40 +51,5 @@
android:freezesText="true"/> android:freezesText="true"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="40dip"
android:layout_height="35dip"
android:layout_marginLeft="5dip"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_weight="1"
android:visibility="gone">
<Button
android:id="@+id/timer_button"
android:layout_width="25dip"
android:layout_height="25dip"
android:layout_weight="1"/>
<Chronometer
android:id="@+id/timer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:visibility="visible"
android:textColor="@color/task_edit_details"
android:textSize="10sp" />
<TextView
android:id="@+id/timer_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:textColor="@color/task_edit_details"
android:textSize="10sp"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

@ -119,6 +119,11 @@
android:id="@+id/updatesFooter" android:id="@+id/updatesFooter"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
<<<<<<< HEAD
=======
android:layout_weight="1"
android:background="#fff"
>>>>>>> 8b70e98... Changed timer layout
android:minHeight="47dip" android:minHeight="47dip"
android:layout_weight="1" android:layout_weight="1"
android:padding="3dip" android:padding="3dip"
@ -158,6 +163,33 @@
<!-- Extended Add Button --> <!-- Extended Add Button -->
<LinearLayout
android:id="@+id/timer_container"
android:layout_width="40dip"
android:layout_height="35dip"
android:layout_marginLeft="5dip"
android:gravity="top"
android:orientation="vertical"
android:layout_weight="1">
<Button
android:id="@+id/timer_button"
android:layout_width="25dip"
android:layout_height="25dip"
android:maxHeight="25dip"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:layout_weight="1"/>
<Chronometer
android:id="@+id/timer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:visibility="visible"
android:textColor="@color/task_edit_details"
android:textSize="10sp" />
</LinearLayout>
<ImageButton <ImageButton
android:id="@+id/commentButton" android:id="@+id/commentButton"
android:layout_width="39dip" android:layout_width="39dip"

@ -22,4 +22,14 @@
<!-- Title for TEA --> <!-- Title for TEA -->
<string name="TEA_timer_controls">Timer Controls</string> <string name="TEA_timer_controls">Timer Controls</string>
<!-- Edit Notes: create comment for when timer is started -->
<string name="TEA_timer_comment_started">started this task:</string>
<!-- Edit Notes: create comment for when timer is stopped -->
<string name="TEA_timer_comment_stopped">stopped doing this task:</string>
<!-- Edit Notes: comment to notify how long was spent on task -->
<string name="TEA_timer_comment_spent">Time spent:</string>
</resources> </resources>

@ -136,6 +136,16 @@ public final class TaskEditActivity extends Fragment implements
*/ */
private static final String TASK_IN_PROGRESS = "task_in_progress"; //$NON-NLS-1$ private static final String TASK_IN_PROGRESS = "task_in_progress"; //$NON-NLS-1$
/**
* Task remote id (during orientation change)
*/
private static final String TASK_REMOTE_ID = "task_remote_id"; //$NON-NLS-1$
/**
* Task remote id (during orientation change)
*/
private static final String MORE_EXPANDED = "more_expanded"; //$NON-NLS-1$
/** /**
* Tab to start on * Tab to start on
*/ */
@ -204,6 +214,7 @@ public final class TaskEditActivity extends Fragment implements
private EditNotesControlSet notesControlSet = null; private EditNotesControlSet notesControlSet = null;
private HideUntilControlSet hideUntilControls = null; private HideUntilControlSet hideUntilControls = null;
private TagsControlSet tagsControlSet = null; private TagsControlSet tagsControlSet = null;
private TimerActionControlSet timerAction;
private EditText title; private EditText title;
private TaskEditMoreControls moreControls; private TaskEditMoreControls moreControls;
private EditNoteActivity editNotes; private EditNoteActivity editNotes;
@ -241,6 +252,7 @@ public final class TaskEditActivity extends Fragment implements
private long remoteId = 0; private long remoteId = 0;
private boolean moreExpanded = false;
/* /*
* ====================================================================== * ======================================================================
* ======================================================= initialization * ======================================================= initialization
@ -285,6 +297,13 @@ public final class TaskEditActivity extends Fragment implements
if (task != null) { if (task != null) {
model = task; model = task;
} }
if (savedInstanceState.containsKey(TASK_REMOTE_ID)) {
remoteId = savedInstanceState.getLong(TASK_REMOTE_ID);
}
if (savedInstanceState.containsKey(MORE_EXPANDED)) {
moreExpanded = savedInstanceState.getBoolean(MORE_EXPANDED);
}
} }
getActivity().setResult(Activity.RESULT_OK); getActivity().setResult(Activity.RESULT_OK);
@ -348,8 +367,21 @@ public final class TaskEditActivity extends Fragment implements
View more_section = (View) getView().findViewById(R.id.more_header); View more_section = (View) getView().findViewById(R.id.more_header);
View commentsBar = (View) getView().findViewById(R.id.updatesFooter); View commentsBar = (View) getView().findViewById(R.id.updatesFooter);
if (remoteId > 0) { long idParam = getActivity().getIntent().getLongExtra(TOKEN_ID,
-1L);
if (remoteId > 0 && idParam > -1L) {
if (editNotes == null) {
editNotes = new EditNoteActivity(getActivity(), getView(),
idParam);
editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
if (timerAction != null) {
timerAction.addListener(editNotes);
}
}
else {
editNotes.loadViewForTaskID(idParam);
}
if (mAdapter == null) { if (mAdapter == null) {
mAdapter = new TaskEditViewPager(getActivity()); mAdapter = new TaskEditViewPager(getActivity());
mAdapter.parent = this; mAdapter.parent = this;
@ -386,9 +418,17 @@ public final class TaskEditActivity extends Fragment implements
} else { } else {
if (moreControls.getParent() != null && moreControls.getParent() != more_section) { if (moreControls.getParent() != null) {
if (moreControls.getParent() == more_section) {
setPagerHeightForPosition(TAB_VIEW_MORE);
}
else {
((ViewGroup) moreControls.getParent()).removeView(moreControls); ((ViewGroup) moreControls.getParent()).removeView(moreControls);
} }
}
if (moreExpanded){
autoExpandMore();
}
more_section.setVisibility(View.VISIBLE); more_section.setVisibility(View.VISIBLE);
more_tab.setVisibility(View.GONE); more_tab.setVisibility(View.GONE);
commentsBar.setVisibility(View.GONE); commentsBar.setVisibility(View.GONE);
@ -423,8 +463,8 @@ public final class TaskEditActivity extends Fragment implements
controls.add(editTitle); controls.add(editTitle);
titleControls.addView(editTitle.getDisplayView(), 0, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f)); titleControls.addView(editTitle.getDisplayView(), 0, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
TimerActionControlSet timerAction = new TimerActionControlSet( timerAction = new TimerActionControlSet(
getActivity(), editTitle.getView()); getActivity(), getView());
controls.add(timerAction); controls.add(timerAction);
controls.add(peopleControlSet = new EditPeopleControlSet(getActivity(), controls.add(peopleControlSet = new EditPeopleControlSet(getActivity(),
@ -499,7 +539,7 @@ public final class TaskEditActivity extends Fragment implements
R.layout.control_set_timers, R.layout.control_set_timers,
R.layout.control_set_default_display, R.layout.control_set_default_display,
R.string.TEA_timer_controls); R.string.TEA_timer_controls);
timerAction.setListener(timerControl); timerAction.addListener(timerControl);
controls.add(timerControl); controls.add(timerControl);
controlSetMap.put(getString(R.string.TEA_ctrl_timer_pref), timerControl); controlSetMap.put(getString(R.string.TEA_ctrl_timer_pref), timerControl);
@ -592,11 +632,7 @@ public final class TaskEditActivity extends Fragment implements
public void onClick(View v) { public void onClick(View v) {
fadeIn.setDuration(300); fadeIn.setDuration(300);
fadeOut.setDuration(300); fadeOut.setDuration(300);
LinearLayout moreHeader = (LinearLayout) getView().findViewById( autoExpandMore();
R.id.more_header);
moreHeader.removeAllViews();
moreHeader.addView(moreControls);
moreHeader.setOnClickListener(null);
} }
}; };
// set up save, cancel, and delete buttons // set up save, cancel, and delete buttons
@ -609,6 +645,15 @@ public final class TaskEditActivity extends Fragment implements
} }
private void autoExpandMore() {
moreExpanded = true;
LinearLayout moreHeader = (LinearLayout) getView().findViewById(
R.id.more_header);
moreHeader.removeAllViews();
moreHeader.addView(moreControls);
moreHeader.setOnClickListener(null);
}
private void constructWhenDialog(View whenDialogView) { private void constructWhenDialog(View whenDialogView) {
int theme = ThemeService.getEditDialogTheme(); int theme = ThemeService.getEditDialogTheme();
whenDialog = new Dialog(getActivity(), theme); whenDialog = new Dialog(getActivity(), theme);
@ -750,6 +795,8 @@ public final class TaskEditActivity extends Fragment implements
/** Convenience method to populate fields after setting model to null */ /** Convenience method to populate fields after setting model to null */
public void repopulateFromScratch(Intent intent) { public void repopulateFromScratch(Intent intent) {
model = null; model = null;
remoteId = 0;
moreExpanded = false;
populateFields(intent); populateFields(intent);
} }
@ -1005,13 +1052,17 @@ public final class TaskEditActivity extends Fragment implements
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
if(actFmPreferenceService.isLoggedIn() && remoteId > 0) { }
item = menu.add(Menu.NONE, MENU_COMMENTS_REFRESH_ID, Menu.NONE,
@Override
public void onPrepareOptionsMenu (Menu menu) {
if(actFmPreferenceService.isLoggedIn() && remoteId > 0 && menu.findItem(MENU_COMMENTS_REFRESH_ID) == null) {
MenuItem item = menu.add(Menu.NONE, MENU_COMMENTS_REFRESH_ID, Menu.NONE,
R.string.ENA_refresh_comments); R.string.ENA_refresh_comments);
item.setIcon(R.drawable.ic_menu_refresh); item.setIcon(R.drawable.ic_menu_refresh);
} }
super.onPrepareOptionsMenu(menu);
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
@ -1060,6 +1111,8 @@ public final class TaskEditActivity extends Fragment implements
// stick our task into the outState // stick our task into the outState
outState.putParcelable(TASK_IN_PROGRESS, model); outState.putParcelable(TASK_IN_PROGRESS, model);
outState.putLong(TASK_REMOTE_ID, remoteId);
outState.putBoolean(MORE_EXPANDED, moreExpanded);
} }
@Override @Override

Loading…
Cancel
Save