Skip to content

Commit ea110eb

Browse files
committed
Use new milestone dialog in issue edit screen
1 parent 5063c78 commit ea110eb

File tree

1 file changed

+16
-71
lines changed

1 file changed

+16
-71
lines changed

app/src/main/java/com/gh4a/activities/IssueEditActivity.java

Lines changed: 16 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.graphics.Typeface;
2222
import android.os.Bundle;
2323
import android.support.annotation.IdRes;
24+
import android.support.annotation.Nullable;
2425
import android.support.design.widget.AppBarLayout;
2526
import android.support.design.widget.CoordinatorLayout;
2627
import android.support.design.widget.FloatingActionButton;
@@ -42,13 +43,14 @@
4243
import com.gh4a.Gh4Application;
4344
import com.gh4a.ProgressDialogTask;
4445
import com.gh4a.R;
46+
import com.gh4a.dialogs.MilestoneDialog;
47+
import com.gh4a.fragment.IssueMilestoneListFragment;
4548
import com.gh4a.loader.CollaboratorListLoader;
4649
import com.gh4a.loader.IsCollaboratorLoader;
4750
import com.gh4a.loader.IssueTemplateLoader;
4851
import com.gh4a.loader.LabelListLoader;
4952
import com.gh4a.loader.LoaderCallbacks;
5053
import com.gh4a.loader.LoaderResult;
51-
import com.gh4a.loader.MilestoneListLoader;
5254
import com.gh4a.loader.ProgressDialogLoaderCallbacks;
5355
import com.gh4a.utils.ApiHelpers;
5456
import com.gh4a.utils.AvatarHandler;
@@ -68,7 +70,7 @@
6870

6971
public class IssueEditActivity extends BasePagerActivity implements
7072
AppBarLayout.OnOffsetChangedListener, View.OnClickListener,
71-
View.OnFocusChangeListener {
73+
View.OnFocusChangeListener, IssueMilestoneListFragment.SelectionCallback {
7274
public static Intent makeCreateIntent(Context context, String repoOwner, String repoName) {
7375
// can't reuse makeEditIntent here, because even a null extra counts for hasExtra()
7476
return new Intent(context, IssueEditActivity.class)
@@ -85,7 +87,6 @@ public static Intent makeEditIntent(Context context, String repoOwner,
8587
}
8688

8789
private static final int REQUEST_MANAGE_LABELS = 1000;
88-
private static final int REQUEST_MANAGE_MILESTONES = 1001;
8990

9091
private static final int[] TITLES = {
9192
R.string.issue_body, R.string.preview, R.string.settings
@@ -95,7 +96,6 @@ public static Intent makeEditIntent(Context context, String repoOwner,
9596
private String mRepoName;
9697

9798
private boolean mIsCollaborator;
98-
private List<Milestone> mAllMilestone;
9999
private List<User> mAllAssignee;
100100
private List<Label> mAllLabels;
101101
private Issue mEditIssue;
@@ -129,21 +129,6 @@ protected void onResultReady(List<Label> result) {
129129
}
130130
};
131131

132-
private final LoaderCallbacks<List<Milestone>> mMilestoneCallback =
133-
new ProgressDialogLoaderCallbacks<List<Milestone>>(this, this) {
134-
@Override
135-
protected Loader<LoaderResult<List<Milestone>>> onCreateLoader() {
136-
return new MilestoneListLoader(IssueEditActivity.this,
137-
mRepoOwner, mRepoName, ApiHelpers.IssueState.OPEN);
138-
}
139-
@Override
140-
protected void onResultReady(List<Milestone> result) {
141-
mAllMilestone = result;
142-
showMilestonesDialog();
143-
getSupportLoaderManager().destroyLoader(1);
144-
}
145-
};
146-
147132
private final LoaderCallbacks<List<User>> mCollaboratorListCallback =
148133
new ProgressDialogLoaderCallbacks<List<User>>(this, this) {
149134
@Override
@@ -318,10 +303,9 @@ protected boolean canSwipeToRefresh() {
318303
@Override
319304
public void onRefresh() {
320305
mAllAssignee = null;
321-
mAllMilestone = null;
322306
mAllLabels = null;
323307
mIsCollaborator = false;
324-
forceLoaderReload(0, 1, 2, 3);
308+
forceLoaderReload(0, 2, 3);
325309
super.onRefresh();
326310
}
327311

@@ -390,63 +374,24 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
390374
// Require reload of labels
391375
mAllLabels = null;
392376
}
393-
} else if (requestCode == REQUEST_MANAGE_MILESTONES) {
394-
if (resultCode == RESULT_OK) {
395-
// Require reload of milestones
396-
mAllMilestone = null;
397-
}
398377
} else {
399378
super.onActivityResult(requestCode, resultCode, data);
400379
}
401380
}
402381

403-
private void showMilestonesDialog() {
404-
if (mAllMilestone == null) {
405-
getSupportLoaderManager().initLoader(1, null, mMilestoneCallback);
406-
} else {
407-
final String[] milestones = new String[mAllMilestone.size() + 1];
408-
Milestone selectedMilestone = mEditIssue.getMilestone();
409-
int selected = 0;
410-
411-
milestones[0] = getResources().getString(R.string.issue_clear_milestone);
412-
for (int i = 1; i <= mAllMilestone.size(); i++) {
413-
Milestone m = mAllMilestone.get(i - 1);
414-
milestones[i] = m.getTitle();
415-
if (selectedMilestone != null && m.getNumber() == selectedMilestone.getNumber()) {
416-
selected = i;
417-
}
418-
}
382+
@Override
383+
public void onMilestoneSelected(@Nullable Milestone milestone) {
384+
mEditIssue.setMilestone(milestone);
385+
updateOptionViews();
386+
}
419387

420-
final DialogInterface.OnClickListener selectCb = new DialogInterface.OnClickListener() {
421-
@Override
422-
public void onClick(DialogInterface dialog, int which) {
423-
if (which == 0) {
424-
mEditIssue.setMilestone(null);
425-
} else {
426-
mEditIssue.setMilestone(mAllMilestone.get(which - 1));
427-
}
428-
updateOptionViews();
429-
dialog.dismiss();
430-
}
431-
};
388+
private void showMilestonesDialog() {
389+
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName);
390+
getSupportFragmentManager().beginTransaction()
391+
.add(dialog, "dialog_milestone")
392+
.commitAllowingStateLoss();
432393

433-
new AlertDialog.Builder(this)
434-
.setCancelable(true)
435-
.setTitle(R.string.issue_milestone_hint)
436-
.setSingleChoiceItems(milestones, selected, selectCb)
437-
.setNegativeButton(R.string.cancel, null)
438-
.setNeutralButton(R.string.issue_manage_milestones,
439-
new DialogInterface.OnClickListener() {
440-
@Override
441-
public void onClick(DialogInterface dialog, int which) {
442-
Intent intent = IssueMilestoneListActivity.makeIntent(
443-
IssueEditActivity.this, mRepoOwner, mRepoName,
444-
mEditIssue.getPullRequest() != null);
445-
startActivityForResult(intent, REQUEST_MANAGE_MILESTONES);
446-
}
447-
})
448-
.show();
449-
}
394+
// TODO: Button to manage milestones
450395
}
451396

452397
private void showAssigneesDialog() {

0 commit comments

Comments
 (0)