Unread comment count in header for tags

pull/14/head
Sam Bosley 13 years ago
parent fd260dd87c
commit bc659fd48b

@ -29,6 +29,7 @@ import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.actfm.ActFmCameraModule.ClearImageCallback;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
@ -55,7 +56,10 @@ public class TagUpdatesFragment extends ListFragment {
private Bitmap picture = null;
public static final String TAG_UPDATES_FRAGMENT = "tagupdates_fragment";
public static final String TAG_UPDATES_FRAGMENT = "tagupdates_fragment"; //$NON-NLS-1$
//Append tag data remote id to this preference
public static final String UPDATES_LAST_VIEWED = "updates_last_viewed_"; //$NON-NLS-1$
private static final int MENU_REFRESH_ID = Menu.FIRST;
@ -192,6 +196,10 @@ public class TagUpdatesFragment extends ListFragment {
cursor.requery();
getActivity().startManagingCursor(cursor);
}
if (tagData != null) {
Preferences.setLong(UPDATES_LAST_VIEWED + tagData.getValue(TagData.REMOTE_ID), DateUtilities.now());
}
}
@Override

@ -40,6 +40,7 @@ import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
@ -47,6 +48,7 @@ import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.helper.ProgressBarSyncResultCallback;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.tags.TagFilterExposer;
@ -224,6 +226,20 @@ public class TagViewFragment extends TaskListFragment {
tagData.setValue(TagData.TASK_COUNT, count);
tagDataService.save(tagData);
}
if (tagData != null) {
long lastViewedComments = Preferences.getLong(TagUpdatesFragment.UPDATES_LAST_VIEWED + tagData.getValue(TagData.REMOTE_ID), 0);
int unreadCount = 0;
TodorooCursor<Update> commentCursor = tagDataService.getUpdatesWithExtraCriteria(tagData, Update.CREATION_DATE.gt(lastViewedComments));
try {
unreadCount = commentCursor.getCount();
} finally {
commentCursor.close();
}
TaskListActivity tla = (TaskListActivity) getActivity();
tla.setCommentsCount(unreadCount);
}
}
// --------------------------------------------------------- refresh data
@ -247,6 +263,7 @@ public class TagViewFragment extends TaskListFragment {
@Override
public void run() {
ContextManager.getContext().sendBroadcast(new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH));
// Update comment unreadCount
}
}));
Preferences.setLong(LAST_FETCH_KEY + tagData.getId(), DateUtilities.now());

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/comment_blue_filled_pressed"/>
<item android:state_focused="true" android:drawable="@drawable/comment_blue_filled_pressed"/>
<item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/comment_blue_filled_normal"/>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/comment_dark_blue_filled_pressed"/>
<item android:state_focused="true" android:drawable="@drawable/comment_dark_blue_filled_pressed"/>
<item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/comment_dark_blue_filled_normal"/>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/comment_red_filled_pressed"/>
<item android:state_focused="true" android:drawable="@drawable/comment_red_filled_pressed"/>
<item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/comment_red_filled_normal"/>
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

@ -64,12 +64,12 @@
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"/>
<ImageButton
<Button
android:id="@+id/comments"
android:layout_width="51dip"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:src="?attr/asCommentButtonImg"
android:scaleType="fitCenter"/>
android:background="?attr/asCommentButtonImg"
android:textColor="@android:color/white"
android:paddingBottom="6dip"/>
</LinearLayout>

@ -17,7 +17,7 @@
<attr name="asFilterHeaderColor" format="color"/>
<attr name="asFilterHeaderBackground" format="reference"/>
<attr name="asFilterCountColor" format="color"/>
<attr name="asMembersHeaderBackground" format="reference"/>
<attr name="asMembersHeaderBackground" format="color"/>
<attr name="asSeparatorBackground" format="color"/>
<attr name="asThemeTextColor" format="color"/>
@ -25,6 +25,7 @@
<attr name="asAddButtonImg" format="reference" />
<attr name="asMicButtonImg" format="reference" />
<attr name="asCommentButtonImg" format="reference" />
<attr name="asFilledCommentButtonImg" format="reference" />
<attr name="asTaskEditArrow" format="reference" />
<attr name="asRepeatIcon" format="reference" />
<attr name="asMainMenu" format="reference" />

@ -22,6 +22,7 @@
<item name="asAddButtonImg">@drawable/plus_button_blue</item>
<item name="asMicButtonImg">@drawable/mic_button_blue</item>
<item name="asCommentButtonImg">@drawable/comment_blue</item>
<item name="asFilledCommentButtonImg">@drawable/comment_blue_filled</item>
<item name="asEditBackground">#101010</item>
<item name="asEditRowBackground">@drawable/task_edit_background</item>
<item name="asEditTabBackground">@drawable/custom_tab_indicator_dark</item>
@ -68,6 +69,7 @@
<item name="asAddButtonImg">@drawable/plus_button_red</item>
<item name="asMicButtonImg">@drawable/mic_button_red</item>
<item name="asCommentButtonImg">@drawable/comment_red</item>
<item name="asFilledCommentButtonImg">@drawable/comment_red_filled</item>
<item name="asEditRowBackground">@drawable/task_edit_background_white</item>
<item name="asEditTabBackground">@drawable/custom_tab_indicator</item>
<item name="asMainMenu">@drawable/menu_button_red</item>
@ -89,6 +91,7 @@
<item name="asAddButtonImg">@drawable/plus_button_dark_blue</item>
<item name="asMicButtonImg">@drawable/mic_button_dark_blue</item>
<item name="asCommentButtonImg">@drawable/comment_dark_blue</item>
<item name="asFilledCommentButtonImg">@drawable/comment_dark_blue_filled</item>
<item name="asMainMenu">@drawable/menu_button_dark_blue</item>
<item name="asThemeTextColor">@color/dark_blue_theme_color</item>
<item name="asListsDisclosure">@drawable/lists_disclosure_dark_blue</item>

@ -16,6 +16,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.PopupWindow.OnDismissListener;
@ -50,7 +51,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
private ImageView listsNavDisclosure;
private TextView lists;
private ImageView mainMenu;
private ImageView commentsButton;
private Button commentsButton;
private FragmentPopover listsPopover;
private FragmentPopover editPopover;
@ -130,7 +131,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
listsNavDisclosure = (ImageView) actionBar.getCustomView().findViewById(R.id.list_disclosure_arrow);
lists = (TextView) actionBar.getCustomView().findViewById(R.id.list_title);
mainMenu = (ImageView) actionBar.getCustomView().findViewById(R.id.main_menu);
commentsButton = (ImageView) actionBar.getCustomView().findViewById(R.id.comments);
commentsButton = (Button) actionBar.getCustomView().findViewById(R.id.comments);
initializeFragments(actionBar);
createMainMenuPopover();
@ -254,6 +255,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
public boolean onFilterItemClicked(FilterListItem item) {
if (listsPopover != null)
listsPopover.dismiss();
setCommentsCount(0);
return super.onFilterItemClicked(item);
}
@ -326,6 +328,19 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
lists.setText(item.title);
}
public void setCommentsCount(int count) {
TypedValue tv = new TypedValue();
if (count > 0) {
commentsButton.setText(Integer.toString(count));
getTheme().resolveAttribute(R.attr.asFilledCommentButtonImg, tv, false);
} else {
commentsButton.setText(""); //$NON-NLS-1$
getTheme().resolveAttribute(R.attr.asCommentButtonImg, tv, false);
}
commentsButton.setBackgroundResource(tv.data);
}
@Override
public void onBackPressed() {
// manage task edit visibility

@ -131,16 +131,20 @@ public class TagDataService {
* Get updates for this tagData
* @return
*/
@SuppressWarnings("nls")
public TodorooCursor<Update> getUpdates(TagData tagData) {
return getUpdatesWithExtraCriteria(tagData, Criterion.all);
}
@SuppressWarnings("nls")
public TodorooCursor<Update> getUpdatesWithExtraCriteria(TagData tagData, Criterion criterion) {
if (tagData == null)
return updateDao.query(Query.select(Update.PROPERTIES).where(
Criterion.all).
criterion).
orderBy(Order.desc(Update.CREATION_DATE)));
if(tagData.getValue(Task.REMOTE_ID) < 1)
return updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.none));
return updateDao.query(Query.select(Update.PROPERTIES).where(
Update.TAGS.like("%," + tagData.getValue(Task.REMOTE_ID) + ",%")).
return updateDao.query(Query.select(Update.PROPERTIES).where(Criterion.and(criterion,
Update.TAGS.like("%," + tagData.getValue(Task.REMOTE_ID) + ",%"))).
orderBy(Order.desc(Update.CREATION_DATE)));
}

Loading…
Cancel
Save