Make TagUpdatesFragment work in all layouts and with general activity feed

pull/14/head
Sam Bosley 13 years ago
parent bff430ef51
commit 9f0f19fdc9

@ -56,6 +56,8 @@ public class TagUpdatesFragment extends ListFragment {
private Bitmap picture = null;
public static final String TAG_UPDATES_FRAGMENT = "tagupdates_fragment";
private static final int MENU_REFRESH_ID = Menu.FIRST;
@Autowired ActFmPreferenceService actFmPreferenceService;
@ -67,6 +69,11 @@ public class TagUpdatesFragment extends ListFragment {
DependencyInjectionService.getInstance().inject(this);
}
public TagUpdatesFragment(TagData tagData) {
this();
this.tagData = tagData;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -83,7 +90,8 @@ public class TagUpdatesFragment extends ListFragment {
setHasOptionsMenu(true);
tagData = getActivity().getIntent().getParcelableExtra(TagViewFragment.EXTRA_TAG_DATA);
if (tagData == null)
tagData = getActivity().getIntent().getParcelableExtra(TagViewFragment.EXTRA_TAG_DATA);
OnTouchListener onTouch = new OnTouchListener() {
@Override
@ -93,6 +101,10 @@ public class TagUpdatesFragment extends ListFragment {
}
};
if (tagData == null) {
getView().findViewById(R.id.updatesFooter).setVisibility(View.GONE);
}
addCommentField = (EditText) getView().findViewById(R.id.commentField);
addCommentField.setOnTouchListener(onTouch);
@ -100,8 +112,11 @@ public class TagUpdatesFragment extends ListFragment {
}
protected void setUpUpdateList() {
ActionBar ab = ((AstridActivity) getActivity()).getSupportActionBar();
((TextView) ab.getCustomView().findViewById(R.id.title)).setText(this.getString(R.string.tag_updates_title, tagData.getValue(TagData.NAME)));
if (getActivity() instanceof TagUpdatesActivity) {
ActionBar ab = ((AstridActivity) getActivity()).getSupportActionBar();
String title = (tagData == null) ? getString(R.string.TLA_all_activity) : getString(R.string.tag_updates_title, tagData.getValue(TagData.NAME));
((TextView) ab.getCustomView().findViewById(R.id.title)).setText(title);
}
final ImageButton commentButton = (ImageButton) getView().findViewById(R.id.commentButton);
addCommentField = (EditText) getView().findViewById(R.id.commentField);
addCommentField.setOnEditorActionListener(new OnEditorActionListener() {
@ -165,7 +180,7 @@ public class TagUpdatesFragment extends ListFragment {
private void refreshUpdatesList() {
if(!actFmPreferenceService.isLoggedIn() || tagData.getValue(Task.REMOTE_ID) <= 0)
if(tagData != null && tagData.getValue(Task.REMOTE_ID) <= 0)
return;
if(updateAdapter == null) {
@ -195,12 +210,6 @@ public class TagUpdatesFragment extends ListFragment {
}
}
// @Override
// public void finish() {
// super.finish();
// AndroidUtilities.callOverridePendingTransition(this, R.anim.slide_right_in, R.anim.slide_right_out);
// }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle my own menus
@ -219,21 +228,26 @@ public class TagUpdatesFragment extends ListFragment {
private void refreshActivity(boolean manual) {
final ProgressBarSyncResultCallback callback = new ProgressBarSyncResultCallback(
getActivity(), R.id.progressBar, new Runnable() {
@Override
public void run() {
refreshUpdatesList();
}
});
@Override
public void run() {
refreshUpdatesList();
}
});
callback.started();
callback.incrementMax(100);
actFmSyncService.fetchUpdatesForTag(tagData, manual, new Runnable() {
Runnable doneRunnable = new Runnable() {
@Override
public void run() {
callback.incrementProgress(50);
callback.finished();
}
});
};
if (tagData != null) {
actFmSyncService.fetchUpdatesForTag(tagData, manual, doneRunnable);
} else {
actFmSyncService.fetchPersonalUpdates(manual, doneRunnable);
}
callback.incrementProgress(50);
}

@ -126,14 +126,6 @@ public class TagViewFragment extends TaskListFragment {
}
};
@Override
protected void commentsButtonClicked() {
Intent intent = new Intent(getActivity(), TagUpdatesActivity.class);
intent.putExtra(EXTRA_TAG_DATA, tagData);
startActivity(intent);
AndroidUtilities.callOverridePendingTransition(getActivity(), R.anim.slide_left_in, R.anim.slide_left_out);
}
/* (non-Javadoc)
* @see com.todoroo.astrid.activity.TaskListActivity#getListBody(android.view.ViewGroup)
*/
@ -217,6 +209,11 @@ public class TagViewFragment extends TaskListFragment {
// }
}
@Override
protected TagData getTagDataForUpdates() {
return tagData;
}
@Override
public void loadTaskListContent(boolean requery) {
super.loadTaskListContent(requery);

@ -779,32 +779,8 @@ public final class ActFmSyncService {
* @param done
*/
public void fetchUpdatesForTag(final TagData tagData, final boolean manual, Runnable done) {
invokeFetchList("activity", manual, new ListItemProcessor<Update>() {
@Override
protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException {
Update remote = new Update();
for(int i = 0; i < list.length(); i++) {
JSONObject item = list.getJSONObject(i);
readIds(locals, item, remote);
JsonHelper.updateFromJson(item, remote);
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
if(remote.getId() == AbstractModel.NO_ID)
updateDao.createNew(remote);
else
updateDao.saveExisting(remote);
remote.clear();
}
}
@Override
protected HashMap<Long, Long> getLocalModels() {
TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID,
Update.REMOTE_ID).where(Update.REMOTE_ID.in(remoteIds)).orderBy(
Order.asc(Update.REMOTE_ID)));
return cursorToMap(cursor, updateDao, Update.REMOTE_ID, Update.ID);
}
}, done, "updates:" + tagData.getId(), "tag_id", tagData.getValue(TagData.REMOTE_ID));
invokeFetchList("activity", manual, new UpdateListItemProcessor(), done,
"updates:" + tagData.getId(), "tag_id", tagData.getValue(TagData.REMOTE_ID));
}
/**
@ -814,32 +790,44 @@ public final class ActFmSyncService {
* @param runnable
*/
public void fetchUpdatesForTask(final Task task, boolean manual, Runnable done) {
invokeFetchList("activity", manual, new ListItemProcessor<Update>() {
@Override
protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException {
Update remote = new Update();
for(int i = 0; i < list.length(); i++) {
JSONObject item = list.getJSONObject(i);
readIds(locals, item, remote);
JsonHelper.updateFromJson(item, remote);
invokeFetchList("activity", manual, new UpdateListItemProcessor(), done,
"comments:" + task.getId(), "task_id", task.getValue(Task.REMOTE_ID));
}
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
if(remote.getId() == AbstractModel.NO_ID)
updateDao.createNew(remote);
else
updateDao.saveExisting(remote);
remote.clear();
}
}
/**
* Fetch updates for the current user asynchronously
* @param manual
* @param done
*/
public void fetchPersonalUpdates(boolean manual, Runnable done) {
invokeFetchList("activity", manual, new UpdateListItemProcessor(), done, "personal");
}
@Override
protected HashMap<Long, Long> getLocalModels() {
TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID,
Update.REMOTE_ID).where(Update.REMOTE_ID.in(remoteIds)).orderBy(
Order.asc(Update.REMOTE_ID)));
return cursorToMap(cursor, updateDao, Update.REMOTE_ID, Update.ID);
private class UpdateListItemProcessor extends ListItemProcessor<Update> {
@Override
protected void mergeAndSave(JSONArray list, HashMap<Long,Long> locals) throws JSONException {
Update remote = new Update();
for(int i = 0; i < list.length(); i++) {
JSONObject item = list.getJSONObject(i);
readIds(locals, item, remote);
JsonHelper.updateFromJson(item, remote);
Flags.set(Flags.ACTFM_SUPPRESS_SYNC);
if(remote.getId() == AbstractModel.NO_ID)
updateDao.createNew(remote);
else
updateDao.saveExisting(remote);
remote.clear();
}
}, done, "comments:" + task.getId(), "task_id", task.getValue(Task.REMOTE_ID));
}
@Override
protected HashMap<Long, Long> getLocalModels() {
TodorooCursor<Update> cursor = updateDao.query(Query.select(Update.ID,
Update.REMOTE_ID).where(Update.REMOTE_ID.in(remoteIds)).orderBy(
Order.asc(Update.REMOTE_ID)));
return cursorToMap(cursor, updateDao, Update.REMOTE_ID, Update.ID);
}
}
/**

@ -62,7 +62,7 @@
android:layout_height="fill_parent"
style="@style/TEA_Separator"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip"/>/>
android:layout_marginTop="4dip"/>
<ImageView
android:id="@+id/comments"

@ -86,11 +86,4 @@
astrid:defaultSrc="@android:drawable/ic_menu_gallery"
android:scaleType="fitCenter"/>
<View
android:id="@+id/TEA_Separator"
style="@style/TEA_Separator"
android:layout_width="fill_parent"
android:layout_height="1px" />
</LinearLayout>

@ -167,7 +167,7 @@
<item>low priority</item>
</string-array>
<string name="TLA_all_activity">All Activity</string>
<!-- ====================================================== TaskAdapter == -->

@ -13,6 +13,7 @@ import android.view.View;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.actfm.TagUpdatesFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem;
@ -20,6 +21,7 @@ import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.IntentFilter;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.core.SearchFilter;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.reminders.NotificationFragment;
import com.todoroo.astrid.reminders.Notifications;
@ -152,6 +154,19 @@ public class AstridActivity extends FragmentActivity
}
}
public void setupActivityFragment(TagData tagData) {
if (fragmentLayout != LAYOUT_TRIPLE)
return;
findViewById(R.id.taskedit_fragment_container).setVisibility(View.VISIBLE);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
TagUpdatesFragment updates = new TagUpdatesFragment(tagData);
transaction.replace(R.id.taskedit_fragment_container, updates, TagUpdatesFragment.TAG_UPDATES_FRAGMENT);
transaction.commit();
}
protected final void setupTasklistFragmentWithFilter(Filter filter) {
setupTasklistFragmentWithFilterAndCustomTaskList(filter, TaskListFragment.class);
}

@ -126,6 +126,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
if(editFragment != null && editFragment.getVisibility() == View.INVISIBLE) {
fragmentLayout = LAYOUT_TRIPLE;
actionBar.getCustomView().findViewById(R.id.comments).setVisibility(View.GONE);
} else {
fragmentLayout = LAYOUT_DOUBLE;
createEditPopover();

@ -77,6 +77,8 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.andlib.widget.GestureService;
import com.todoroo.andlib.widget.GestureService.GestureInterface;
import com.todoroo.astrid.actfm.ActFmLoginActivity;
import com.todoroo.astrid.actfm.TagUpdatesActivity;
import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.activity.SortSelectionActivity.OnSortSelectedListener;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.adapter.TaskAdapter.OnCompletedTaskListener;
@ -94,6 +96,7 @@ import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.helper.MetadataHelper;
@ -328,6 +331,7 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
getListView().setItemsCanFocus(false);
}
if (Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1) > -1)
upgradeService.showChangeLog(getActivity(),
Preferences.getInt(AstridPreferences.P_UPGRADE_FROM, -1));
@ -361,6 +365,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
});
}
protected TagData getTagDataForUpdates() {
return null;
}
protected void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
@ -395,6 +403,8 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
}
setUpTaskList();
((AstridActivity) getActivity()).setupActivityFragment(getTagDataForUpdates());
// FIXME put this into the wrapper activity
if (Constants.DEBUG)
getActivity().setTitle("[D] " + filter.title); //$NON-NLS-1$
@ -1193,7 +1203,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
* Comments button in action bar was clicked
*/
protected void commentsButtonClicked() {
// Subclasses can override
Intent intent = new Intent(getActivity(), TagUpdatesActivity.class);
intent.putExtra(TagViewFragment.EXTRA_TAG_DATA, getTagDataForUpdates());
startActivity(intent);
AndroidUtilities.callOverridePendingTransition(getActivity(), R.anim.slide_left_in, R.anim.slide_left_out);
}
private static void showAlertForMarkupTask(AstridActivity activity, Task task, String originalText) {

@ -133,6 +133,10 @@ public class TagDataService {
*/
@SuppressWarnings("nls")
public TodorooCursor<Update> getUpdates(TagData tagData) {
if (tagData == null)
return updateDao.query(Query.select(Update.PROPERTIES).where(
Criterion.all).
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(

Loading…
Cancel
Save