Fixed a bug with computing tab for position in task edit fragment

pull/14/head
Sam Bosley 12 years ago
parent 9a4608899a
commit 0d79623c32

@ -724,7 +724,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
}
long idParam = intent.getLongExtra(TOKEN_ID, -1L);
System.err.println("ID: " + idParam);
if (idParam > -1L) {
model = taskService.fetchById(idParam, Task.PROPERTIES);
if (model != null && model.containsNonNullValue(Task.REMOTE_ID)) {
@ -735,6 +735,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
// not found by id or was never passed an id
if (model == null) {
System.err.println("Model is null");
String valuesAsString = intent.getStringExtra(TOKEN_VALUES);
ContentValues values = null;
try {
@ -1257,14 +1258,15 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
*/
public int getTabForPosition(int position) {
Activity activity = getActivity();
String pageTitle = mAdapter.getTitle(position);
if (pageTitle.equals(activity.getString(R.string.TEA_tab_activity)))
int tab = TaskEditViewPager.getPageForPosition(position, tabStyle);
switch(tab) {
case TaskEditViewPager.TAB_SHOW_ACTIVITY:
return TAB_VIEW_UPDATES;
else if (pageTitle.equals(activity.getString(R.string.TEA_tab_more)))
case TaskEditViewPager.TAB_SHOW_MORE:
return TAB_VIEW_MORE;
else if (pageTitle.equals(activity.getString(R.string.TEA_tab_web)))
case TaskEditViewPager.TAB_SHOW_WEB:
return TAB_VIEW_WEB_SERVICES;
}
// error experienced
return TAB_VIEW_MORE;

@ -37,6 +37,17 @@ public class TaskEditViewPager extends PagerAdapter implements TitleProvider {
titles = titleList.toArray(new String[titleList.size()]);
}
public static int getPageForPosition(int position, int tabStyle) {
int numOnesEncountered = 0;
for (int i = 0; i <= 2; i++) {
if ((tabStyle & (1 << i)) > 0)
numOnesEncountered++;
if (numOnesEncountered == position + 1)
return 1 << i;
}
return -1;
}
@Override
public int getCount() {
return titles.length;

Loading…
Cancel
Save