Add row dividers dynamically

pull/413/head
Alex Baker 9 years ago
parent c68141d2d4
commit dc989f0277

@ -62,10 +62,11 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
void taskEditFinished();
}
public static TaskEditFragment newTaskEditFragment(boolean isNewTask, Task task) {
public static TaskEditFragment newTaskEditFragment(boolean isNewTask, Task task, int numFragments) {
TaskEditFragment taskEditFragment = new TaskEditFragment();
taskEditFragment.isNewTask = isNewTask;
taskEditFragment.model = task;
taskEditFragment.numFragments = numFragments;
return taskEditFragment;
}
@ -74,6 +75,7 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
private static final String EXTRA_TASK = "extra_task";
private static final String EXTRA_IS_NEW_TASK = "extra_is_new_task";
private static final String EXTRA_NUM_FRAGMENTS = "extra_num_fragments";
@Inject TaskService taskService;
@Inject UserActivityDao userActivityDao;
@ -88,12 +90,13 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
@BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.comments) LinearLayout comments;
@BindView(R.id.control_sets) LinearLayout controlSets;
// --- other instance variables
/** true if editing started with a new task */
private boolean isNewTask = false;
private int numFragments;
/** task model */
Task model = null;
@ -119,6 +122,7 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
if (savedInstanceState != null) {
model = savedInstanceState.getParcelable(EXTRA_TASK);
isNewTask = savedInstanceState.getBoolean(EXTRA_IS_NEW_TASK);
numFragments = savedInstanceState.getInt(EXTRA_NUM_FRAGMENTS);
}
final boolean backButtonSavesTask = preferences.backButtonSavesTask();
@ -148,8 +152,8 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
commentsController.initialize(model, comments);
commentsController.reloadView();
for (int i = 0 ; i < TaskEditControlSetFragmentManager.TASK_EDIT_CONTROL_FRAGMENT_ROWS.length - taskEditControlSetFragmentManager.getNumRows() ; i++) {
view.findViewById(TaskEditControlSetFragmentManager.TASK_EDIT_DIVIDER_ROWS[i]).setVisibility(View.GONE);
for (int i = numFragments - 2; i > 1 ; i--) {
controlSets.addView(inflater.inflate(R.layout.task_edit_row_divider, controlSets, false), i);
}
return view;
@ -303,6 +307,7 @@ public final class TaskEditFragment extends InjectingFragment implements Toolbar
outState.putParcelable(EXTRA_TASK, model);
outState.putBoolean(EXTRA_IS_NEW_TASK, isNewTask);
outState.putInt(EXTRA_NUM_FRAGMENTS, numFragments);
}
/*

@ -305,10 +305,11 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
return;
}
boolean isNewTask = task.getTitle().length() == 0;
List<TaskEditControlFragment> controlFragments = taskEditControlSetFragmentManager.createNewFragments(isNewTask, task);
loadTaskEditFragment(
false,
newTaskEditFragment(isNewTask, task),
taskEditControlSetFragmentManager.createNewFragments(isNewTask, task));
newTaskEditFragment(isNewTask, task, controlFragments.size()),
controlFragments);
}
@Override

@ -51,19 +51,6 @@ public class TaskEditControlSetFragmentManager {
R.id.row_10,
};
public static final int[] TASK_EDIT_DIVIDER_ROWS = new int[] {
R.id.row_divider_10,
R.id.row_divider_9,
R.id.row_divider_8,
R.id.row_divider_7,
R.id.row_divider_6,
R.id.row_divider_5,
R.id.row_divider_4,
R.id.row_divider_3,
R.id.row_divider_2,
R.id.row_divider_1
};
private static final int[] TASK_EDIT_CONTROL_SET_FRAGMENTS = new int[] {
EditTitleControlSet.TAG,
DeadlineControlSet.TAG,
@ -108,10 +95,6 @@ public class TaskEditControlSetFragmentManager {
}
}
public int getNumRows() {
return numRows;
}
public List<TaskEditControlFragment> createNewFragments(boolean isNewTask, Task task) {
List<TaskEditControlFragment> taskEditControlFragments = new ArrayList<>();
for (int i = 0; i < numRows; i++) {

@ -20,6 +20,7 @@
android:overScrollMode="never">
<LinearLayout
android:id="@+id/control_sets"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
@ -35,90 +36,55 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_1"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_2"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_3"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_3"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_4"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_4"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_5"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_5"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_6"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_6"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_7"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_7"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_8"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_8"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_9"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_9"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_10"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/row_divider_10"
style="@style/task_edit_row_divider" />
<FrameLayout
android:id="@+id/row_11"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/comments"

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<View style="@style/task_edit_row_divider" />
Loading…
Cancel
Save