Got ad view working on edit page

pull/14/head
Tim Su 13 years ago
parent c0896268bf
commit 493ea204c9

@ -97,6 +97,7 @@ import com.todoroo.astrid.ui.HideUntilControlSet;
import com.todoroo.astrid.ui.ImportanceControlSet; import com.todoroo.astrid.ui.ImportanceControlSet;
import com.todoroo.astrid.ui.ReminderControlSet; import com.todoroo.astrid.ui.ReminderControlSet;
import com.todoroo.astrid.ui.TaskEditMoreControls; import com.todoroo.astrid.ui.TaskEditMoreControls;
import com.todoroo.astrid.ui.WebServicesView;
import com.todoroo.astrid.voice.VoiceInputAssistant; import com.todoroo.astrid.voice.VoiceInputAssistant;
import com.viewpagerindicator.TabPageIndicator; import com.viewpagerindicator.TabPageIndicator;
@ -244,6 +245,16 @@ public final class TaskEditFragment extends Fragment implements
private long remoteId = 0; private long remoteId = 0;
private boolean moreExpanded = false; private boolean moreExpanded = false;
private WebServicesView webServices = null;
public static final int TAB_STYLE_NONE = 0;
public static final int TAB_STYLE_ACTIVITY = 1;
public static final int TAB_STYLE_ACTIVITY_WEB = 2;
public static final int TAB_STYLE_WEB = 3;
private int tabStyle = TAB_STYLE_NONE;
/* /*
* ====================================================================== * ======================================================================
* ======================================================= initialization * ======================================================= initialization
@ -355,17 +366,30 @@ public final class TaskEditFragment extends Fragment implements
} }
private void loadMoreContainer() { private void loadMoreContainer() {
View more_tab = (View) getView().findViewById(R.id.more_container); View moreSection = (View) getView().findViewById(R.id.more_header);
View more_section = (View) getView().findViewById(R.id.more_header); View moreTab = (View) getView().findViewById(R.id.more_container);
View commentsBar = (View) getView().findViewById(R.id.updatesFooter); View commentsBar = (View) getView().findViewById(R.id.updatesFooter);
long idParam = getActivity().getIntent().getLongExtra(TOKEN_ID, long idParam = getActivity().getIntent().getLongExtra(TOKEN_ID, -1L);
-1L);
if (remoteId > 0 && idParam > -1L) { boolean hasTitle = !TextUtils.isEmpty(model.getValue(Task.TITLE));
boolean hasRemoteId = remoteId > 0 && idParam > -1L;
if(hasTitle && hasRemoteId)
tabStyle = TAB_STYLE_ACTIVITY_WEB;
else if(hasTitle)
tabStyle = TAB_STYLE_WEB;
else if(hasRemoteId)
tabStyle = TAB_STYLE_ACTIVITY;
else
tabStyle = TAB_STYLE_NONE;
if (hasRemoteId) {
if (editNotes == null) { if (editNotes == null) {
editNotes = new EditNoteActivity(this, getView(), editNotes = new EditNoteActivity(this, getView(),
idParam); idParam);
editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
editNotes.addListener(this); editNotes.addListener(this);
if (timerAction != null) { if (timerAction != null) {
@ -375,51 +399,61 @@ public final class TaskEditFragment extends Fragment implements
else { else {
editNotes.loadViewForTaskID(idParam); editNotes.loadViewForTaskID(idParam);
} }
if (mAdapter == null) {
mAdapter = new TaskEditViewPager(getActivity());
mAdapter.parent = this;
mPager = (ViewPager) getView().findViewById(R.id.pager); if (editNotes.numberOfComments() == 0) {
mPager.setAdapter(mAdapter); setCurrentTab(TAB_VIEW_MORE);
} else {
mIndicator = (TabPageIndicator) getView().findViewById( Handler refreshHandler = new Handler();
R.id.indicator); refreshHandler.postDelayed(refreshActivity, 1000);
mIndicator.setViewPager(mPager); }
mIndicator.setOnPageChangeListener(this);
if (editNotes.numberOfComments() == 0) { editNotes.addListener(this);
setCurrentTab(TAB_VIEW_MORE); }
} else {
Handler refreshHandler = new Handler();
refreshHandler.postDelayed(refreshActivity, 1000);
} if(hasTitle) {
editNotes.addListener(this); if(webServices == null) {
webServices = new WebServicesView(getActivity());
webServices.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
webServices.setTask(model);
} else {
webServices.refresh();
} }
}
if(tabStyle != TAB_STYLE_NONE) {
mAdapter = new TaskEditViewPager(getActivity(), tabStyle);
mAdapter.parent = this;
mPager = (ViewPager) getView().findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mIndicator = (TabPageIndicator) getView().findViewById(
R.id.indicator);
mIndicator.setViewPager(mPager);
mIndicator.setOnPageChangeListener(this);
if (moreControls.getParent() != null && moreControls.getParent() != mPager) { if (moreControls.getParent() != null && moreControls.getParent() != mPager) {
((ViewGroup) moreControls.getParent()).removeView(moreControls); ((ViewGroup) moreControls.getParent()).removeView(moreControls);
} }
commentsBar.setVisibility(View.VISIBLE);
more_tab.setVisibility(View.VISIBLE);
more_section.setVisibility(View.GONE);
commentsBar.setVisibility(View.VISIBLE);
moreSection.setVisibility(View.GONE);
moreTab.setVisibility(View.VISIBLE);
} else { } else {
moreSection.setVisibility(View.VISIBLE);
commentsBar.setVisibility(View.GONE);
if (moreControls.getParent() != null) { if (moreControls.getParent() != null) {
if (moreControls.getParent() == more_section) { if (moreControls.getParent() == moreSection) {
setPagerHeightForPosition(TAB_VIEW_MORE); setPagerHeightForPosition(TAB_VIEW_MORE);
} }
else { else {
((ViewGroup) moreControls.getParent()).removeView(moreControls); ((ViewGroup) moreControls.getParent()).removeView(moreControls);
} }
} }
if (moreExpanded){ if (moreExpanded)
autoExpandMore(); autoExpandMore();
}
more_section.setVisibility(View.VISIBLE);
more_tab.setVisibility(View.GONE);
commentsBar.setVisibility(View.GONE);
} }
} }
@ -1113,17 +1147,25 @@ public final class TaskEditFragment extends Fragment implements
*/ */
public View getPageView(int position) { public View getPageView(int position) {
if (position == 1) { if ((tabStyle == TAB_STYLE_WEB && position == 0) ||
(tabStyle != TAB_STYLE_WEB && position == 1)) {
moreControls.setLayoutParams(mPager.getLayoutParams()); moreControls.setLayoutParams(mPager.getLayoutParams());
setViewHeightBasedOnChildren(moreControls); setViewHeightBasedOnChildren(moreControls);
return moreControls; return moreControls;
} else if (position == 0) { } else if (tabStyle != TAB_STYLE_WEB && position == 0) {
return editNotes; return editNotes;
} else {
return null; } else if((tabStyle == TAB_STYLE_WEB && position == 1) ||
(tabStyle == TAB_STYLE_ACTIVITY_WEB && position == 2)) {
return webServices;
} else {
throw new RuntimeException("Error - requested position " + position
+ ", tab style " + tabStyle);
} }
} }
@ -1172,7 +1214,6 @@ public final class TaskEditFragment extends Fragment implements
@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
this.setPagerHeightForPosition(position); this.setPagerHeightForPosition(position);
} }

@ -13,12 +13,32 @@ public class TaskEditViewPager extends PagerAdapter implements TitleProvider {
private static String[] titles; private static String[] titles;
public TaskEditFragment parent; public TaskEditFragment parent;
private final int tabStyle;
public TaskEditViewPager(Context context) { public TaskEditViewPager(Context context, int tabStyle) {
titles = new String[] { this.tabStyle = tabStyle;
switch(tabStyle) {
case TaskEditFragment.TAB_STYLE_ACTIVITY_WEB:
titles = new String[] {
context.getString(R.string.TEA_tab_activity),
context.getString(R.string.TEA_tab_more),
context.getString(R.string.TEA_tab_web),
};
break;
case TaskEditFragment.TAB_STYLE_ACTIVITY:
titles = new String[] {
context.getString(R.string.TEA_tab_activity), context.getString(R.string.TEA_tab_activity),
context.getString(R.string.TEA_tab_more), context.getString(R.string.TEA_tab_more),
}; };
break;
case TaskEditFragment.TAB_STYLE_WEB:
titles = new String[] {
context.getString(R.string.TEA_tab_more),
context.getString(R.string.TEA_tab_web),
};
break;
}
} }
@Override @Override
@ -28,8 +48,12 @@ public class TaskEditViewPager extends PagerAdapter implements TitleProvider {
@Override @Override
public Object instantiateItem(View pager, int position) { public Object instantiateItem(View pager, int position) {
System.err.println("adding view for " + position + ", tab style " + tabStyle);
View pageView = parent.getPageView(position); View pageView = parent.getPageView(position);
System.err.println("got pager " + pageView);
((ViewPager) pager).addView(pageView, 0); ((ViewPager) pager).addView(pageView, 0);
return pageView; return pageView;
} }

@ -18,6 +18,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.Gravity; import android.view.Gravity;
@ -88,6 +89,15 @@ public class WebServicesView extends LinearLayout {
inflater = (LayoutInflater) getContext().getSystemService( inflater = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
refresh();
}
public void refresh() {
if(TextUtils.isEmpty(task.getValue(Task.TITLE)))
return;
removeAllViews();
initializeAmazon(); initializeAmazon();
addSectionDivider(); addSectionDivider();

Loading…
Cancel
Save