From a88e2df174124765769849dae09318565307ba40 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 8 Feb 2016 00:45:30 -0600 Subject: [PATCH] Remove ViewPager from task edit --- .../astrid/activity/TaskEditFragment.java | 93 +------------------ .../astrid/activity/TaskEditViewPager.java | 45 --------- .../astrid/notes/EditNoteActivity.java | 23 +---- src/main/res/layout/fragment_task_edit.xml | 10 +- 4 files changed, 6 insertions(+), 165 deletions(-) delete mode 100644 src/main/java/com/todoroo/astrid/activity/TaskEditViewPager.java diff --git a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java index 660e566b1..426c59aae 100755 --- a/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskEditFragment.java @@ -12,21 +12,17 @@ import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.support.v4.graphics.drawable.DrawableCompat; -import android.support.v4.view.ViewPager; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; -import android.view.ViewParent; import android.widget.EditText; import android.widget.FrameLayout; -import android.widget.ScrollView; +import android.widget.LinearLayout; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.actfm.ActFmCameraModule; @@ -72,7 +68,7 @@ import static android.app.Activity.RESULT_OK; * @author timsu * */ -public final class TaskEditFragment extends InjectingFragment implements EditNoteActivity.UpdatesChangedListener, Toolbar.OnMenuItemClickListener { +public final class TaskEditFragment extends InjectingFragment implements Toolbar.OnMenuItemClickListener { public interface TaskEditFragmentCallbackHandler { void taskEditFinished(); @@ -125,9 +121,8 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot private EditNoteActivity editNotes; - @Bind(R.id.pager) ViewPager mPager; @Bind(R.id.updatesFooter) View commentsBar; - @Bind(R.id.edit_scroll) ScrollView scrollView; + @Bind(R.id.edit_body) LinearLayout body; @Bind(R.id.commentField) EditText commentField; @Bind(R.id.toolbar) Toolbar toolbar; @@ -238,8 +233,7 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot taskService, this, getView(), model.getId()); editNotes.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); - - editNotes.addListener(this); + body.addView(editNotes); } } @@ -255,31 +249,7 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot if (timerControl != null) { timerControl.setEditNotes(editNotes); } - editNotes.addListener(this); - } - - if (!showEditComments) { - return; } - - TaskEditViewPager adapter = new TaskEditViewPager(); - adapter.parent = this; - - mPager.setAdapter(adapter); - - setCurrentTab(0); - setPagerHeightForPosition(); - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - updatesChanged(); - } - }, 500L); - } - - private void setCurrentTab(int position) { - mPager.setCurrentItem(position); } public Task stopTimer() { @@ -476,61 +446,6 @@ public final class TaskEditFragment extends InjectingFragment implements EditNot * ====================================================================== */ - public View getPageView() { - return editNotes; - } - - private void setPagerHeightForPosition() { - int height = 0; - - View view = editNotes; - if (mPager == null) { - return; - } - - int desiredWidth = MeasureSpec.makeMeasureSpec(view.getWidth(), - MeasureSpec.AT_MOST); - view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); - height = Math.max(view.getMeasuredHeight(), height); - LayoutParams pagerParams = mPager.getLayoutParams(); - if (height > 0 && height != pagerParams.height) { - pagerParams.height = height; - mPager.setLayoutParams(pagerParams); - } - } - - // EditNoteActivity Listener when there are new updates/comments - @Override - public void updatesChanged() { - if (mPager != null) { - setPagerHeightForPosition(); - } - } - - // EditNoteActivity Lisener when there are new updates/comments - @Override - public void commentAdded() { - setPagerHeightForPosition(); - scrollToView(editNotes); - } - - // Scroll to view in edit task - public void scrollToView(View v) { - View child = v; - int top = v.getTop(); - while (!child.equals(scrollView) ) { - top += child.getTop(); - ViewParent parentView = child.getParent(); - if (parentView != null && View.class.isInstance(parentView)) { - child = (View) parentView; - } - else { - break; - } - } - scrollView.smoothScrollTo(0, top); - } - private void hideKeyboard() { getEditTitleControlSet().hideKeyboard(); AndroidUtilities.hideSoftInputForViews(getActivity(), commentField); diff --git a/src/main/java/com/todoroo/astrid/activity/TaskEditViewPager.java b/src/main/java/com/todoroo/astrid/activity/TaskEditViewPager.java deleted file mode 100644 index a043a45dc..000000000 --- a/src/main/java/com/todoroo/astrid/activity/TaskEditViewPager.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.activity; - -import android.os.Parcelable; -import android.support.v4.view.PagerAdapter; -import android.support.v4.view.ViewPager; -import android.view.View; - -public class TaskEditViewPager extends PagerAdapter { - - public TaskEditFragment parent; - - @Override - public int getCount() { - return 1; - } - - @Override - public Object instantiateItem(View pager, int position) { - View pageView = parent.getPageView(); - - ((ViewPager) pager).addView(pageView, 0); - return pageView; - } - - @Override - public void destroyItem(View pager, int position, Object view) { - ((ViewPager) pager).removeView((View) view); - } - - @Override - public boolean isViewFromObject(View view, Object object) { - return view.equals(object); - } - - @Override - public Parcelable saveState() { - return null; - } - -} diff --git a/src/main/java/com/todoroo/astrid/notes/EditNoteActivity.java b/src/main/java/com/todoroo/astrid/notes/EditNoteActivity.java index d3992d99e..e5f85d541 100644 --- a/src/main/java/com/todoroo/astrid/notes/EditNoteActivity.java +++ b/src/main/java/com/todoroo/astrid/notes/EditNoteActivity.java @@ -5,7 +5,6 @@ */ package com.todoroo.astrid.notes; -import android.app.Activity; import android.app.Fragment; import android.content.Intent; import android.database.sqlite.SQLiteException; @@ -52,8 +51,6 @@ import org.tasks.R; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; import timber.log.Timber; @@ -82,13 +79,6 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene private final int cameraButton; - private final List listeners = new LinkedList<>(); - - public interface UpdatesChangedListener { - void updatesChanged(); - void commentAdded(); - } - public EditNoteActivity( ActFmCameraModule actFmCameraModule, MetadataDao metadataDao, @@ -282,14 +272,10 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene }); this.addView(loadMore); } - - for (UpdatesChangedListener l : listeners) { - l.updatesChanged(); - } } public View getUpdateNotes(NoteOrUpdate note, ViewGroup parent) { - View convertView = ((Activity)activity).getLayoutInflater().inflate( + View convertView = activity.getLayoutInflater().inflate( R.layout.comment_adapter_row, parent, false); bindView(convertView, note); return convertView; @@ -375,9 +361,6 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene } setUpListAdapter(); - for (UpdatesChangedListener l : listeners) { - l.commentAdded(); - } } private static class NoteOrUpdate { @@ -426,10 +409,6 @@ public class EditNoteActivity extends LinearLayout implements TimerActionListene } } - public void addListener(UpdatesChangedListener listener) { - listeners.add(listener); - } - @Override public void timerStarted(Task t) { addComment(String.format("%s %s", //$NON-NLS-1$ diff --git a/src/main/res/layout/fragment_task_edit.xml b/src/main/res/layout/fragment_task_edit.xml index 179a0d437..5ac6e3c98 100644 --- a/src/main/res/layout/fragment_task_edit.xml +++ b/src/main/res/layout/fragment_task_edit.xml @@ -15,13 +15,13 @@ - -