Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 26 additions & 60 deletions app/src/main/java/com/gh4a/activities/IssueEditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.gh4a.Gh4Application;
import com.gh4a.R;
import com.gh4a.ServiceFactory;
import com.gh4a.dialogs.MilestoneDialog;
import com.gh4a.utils.ApiHelpers;
import com.gh4a.utils.AvatarHandler;
import com.gh4a.utils.Optional;
Expand All @@ -53,13 +54,11 @@
import com.meisolsson.githubsdk.model.Content;
import com.meisolsson.githubsdk.model.ContentType;
import com.meisolsson.githubsdk.model.Issue;
import com.meisolsson.githubsdk.model.IssueState;
import com.meisolsson.githubsdk.model.Label;
import com.meisolsson.githubsdk.model.Milestone;
import com.meisolsson.githubsdk.model.User;
import com.meisolsson.githubsdk.model.request.issue.IssueRequest;
import com.meisolsson.githubsdk.service.issues.IssueLabelService;
import com.meisolsson.githubsdk.service.issues.IssueMilestoneService;
import com.meisolsson.githubsdk.service.issues.IssueService;
import com.meisolsson.githubsdk.service.repositories.RepositoryCollaboratorService;
import com.meisolsson.githubsdk.service.repositories.RepositoryContentService;
Expand All @@ -74,7 +73,7 @@

public class IssueEditActivity extends BasePagerActivity implements
AppBarLayout.OnOffsetChangedListener, View.OnClickListener,
View.OnFocusChangeListener {
View.OnFocusChangeListener, MilestoneDialog.SelectionCallback {
public static Intent makeCreateIntent(Context context, String repoOwner, String repoName) {
// can't reuse makeEditIntent here, because even a null extra counts for hasExtra()
return new Intent(context, IssueEditActivity.class)
Expand All @@ -91,7 +90,6 @@ public static Intent makeEditIntent(Context context, String repoOwner,
}

private static final int REQUEST_MANAGE_LABELS = 1000;
private static final int REQUEST_MANAGE_MILESTONES = 1001;

private static final int ID_LOADER_COLLABORATOR_STATUS = 0;

Expand All @@ -103,7 +101,6 @@ public static Intent makeEditIntent(Context context, String repoOwner,
private String mRepoName;

private boolean mIsCollaborator;
private List<Milestone> mAllMilestone;
private List<User> mAllAssignee;
private List<Label> mAllLabels;
private Issue mEditIssue;
Expand Down Expand Up @@ -266,7 +263,6 @@ protected boolean canSwipeToRefresh() {
@Override
public void onRefresh() {
mAllAssignee = null;
mAllMilestone = null;
mAllLabels = null;
mIsCollaborator = false;
loadCollaboratorStatus(true);
Expand Down Expand Up @@ -336,54 +332,36 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Require reload of labels
mAllLabels = null;
}
} else if (requestCode == REQUEST_MANAGE_MILESTONES) {
if (resultCode == RESULT_OK) {
// Require reload of milestones
mAllMilestone = null;
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}

private void showMilestonesDialog() {
if (mAllMilestone == null) {
loadMilestones();
} else {
final String[] milestones = new String[mAllMilestone.size() + 1];
Milestone selectedMilestone = mEditIssue.milestone();
int selected = 0;

milestones[0] = getResources().getString(R.string.issue_clear_milestone);
for (int i = 1; i <= mAllMilestone.size(); i++) {
Milestone m = mAllMilestone.get(i - 1);
milestones[i] = m.title();
if (selectedMilestone != null && m.number().equals(selectedMilestone.number())) {
selected = i;
}
}

final DialogInterface.OnClickListener selectCb = (dialog, which) -> {
mEditIssue = mEditIssue.toBuilder()
.milestone(which == 0 ? null : mAllMilestone.get(which - 1))
.build();
updateOptionViews();
dialog.dismiss();
};

new AlertDialog.Builder(this)
.setCancelable(true)
.setTitle(R.string.issue_milestone_hint)
.setSingleChoiceItems(milestones, selected, selectCb)
.setNegativeButton(R.string.cancel, null)
.setNeutralButton(R.string.issue_manage_milestones, (dialog, which) -> {
Intent intent = IssueMilestoneListActivity.makeIntent(
IssueEditActivity.this, mRepoOwner, mRepoName,
mEditIssue.pullRequest() != null);
startActivityForResult(intent, REQUEST_MANAGE_MILESTONES);
})
.show();
@Override
public void onMilestoneSelected(MilestoneDialog.MilestoneSelection milestoneSelection) {
Milestone milestone;
switch (milestoneSelection.type) {
case NO_MILESTONE:
milestone = null;
break;
case MILESTONE:
milestone = milestoneSelection.milestone;
break;
default:
throw new IllegalArgumentException("Unsupported milestone selection type " + milestoneSelection.type);
}
mEditIssue = mEditIssue.toBuilder()
.milestone(milestone)
.build();
updateOptionViews();
}

private void showMilestonesDialog() {
boolean fromPullRequest = mEditIssue.pullRequest() != null;
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName, fromPullRequest, false, true);
getSupportFragmentManager().beginTransaction()
.add(dialog, "dialog_milestone")
.commitAllowingStateLoss();
}

private void showAssigneesDialog() {
Expand Down Expand Up @@ -611,18 +589,6 @@ private void loadLabels() {
}, this::handleLoadFailure));
}

private void loadMilestones() {
final IssueMilestoneService service = ServiceFactory.get(IssueMilestoneService.class, false);
registerTemporarySubscription(ApiHelpers.PageIterator
.toSingle(page -> service.getRepositoryMilestones(mRepoOwner, mRepoName, "open", page))
.compose(RxUtils::doInBackground)
.compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg))
.subscribe(result -> {
mAllMilestone = result;
showMilestonesDialog();
}, this::handleLoadFailure));
}

private void loadPotentialAssignees() {
final RepositoryCollaboratorService service =
ServiceFactory.get(RepositoryCollaboratorService.class, false);
Expand Down
74 changes: 24 additions & 50 deletions app/src/main/java/com/gh4a/activities/IssueListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
Expand All @@ -38,28 +38,26 @@
import com.gh4a.Gh4Application;
import com.gh4a.R;
import com.gh4a.ServiceFactory;
import com.gh4a.dialogs.MilestoneDialog;
import com.gh4a.fragment.IssueListFragment;
import com.gh4a.fragment.LoadingListFragmentBase;
import com.gh4a.utils.ApiHelpers;
import com.gh4a.utils.RxUtils;
import com.gh4a.utils.SingleFactory;
import com.gh4a.utils.UiUtils;
import com.meisolsson.githubsdk.model.Issue;
import com.meisolsson.githubsdk.model.IssueState;
import com.meisolsson.githubsdk.model.Label;
import com.meisolsson.githubsdk.model.Milestone;
import com.meisolsson.githubsdk.model.User;
import com.meisolsson.githubsdk.service.issues.IssueAssigneeService;
import com.meisolsson.githubsdk.service.issues.IssueLabelService;
import com.meisolsson.githubsdk.service.issues.IssueMilestoneService;

import java.util.List;
import java.util.Locale;

public class IssueListActivity extends BaseFragmentPagerActivity implements
View.OnClickListener, LoadingListFragmentBase.OnRecyclerViewCreatedListener,
SearchView.OnCloseListener, SearchView.OnQueryTextListener,
MenuItem.OnActionExpandListener {
MenuItem.OnActionExpandListener, MilestoneDialog.SelectionCallback {
public static Intent makeIntent(Context context, String repoOwner, String repoName) {
return makeIntent(context, repoOwner, repoName, false);
}
Expand Down Expand Up @@ -94,7 +92,6 @@ public static Intent makeIntent(Context context, String repoOwner, String repoNa
private IssueListFragment mOpenFragment;
private Boolean mIsCollaborator;
private List<Label> mLabels;
private List<Milestone> mMilestones;
private List<User> mAssignees;

private final IssueListFragment.SortDrawerHelper mSortHelper =
Expand Down Expand Up @@ -175,7 +172,6 @@ protected void onInitExtras(Bundle extras) {
@Override
public void onRefresh() {
mAssignees = null;
mMilestones = null;
mLabels = null;
mIsCollaborator = null;
updateRightNavigationDrawer();
Expand Down Expand Up @@ -360,7 +356,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
filterLabel();
return true;
case R.id.filter_by_milestone:
filterMilestone();
showMilestonesDialog();
return true;
case R.id.filter_by_participating:
filterParticipating();
Expand Down Expand Up @@ -468,6 +464,22 @@ protected Intent navigateUp() {
return RepositoryActivity.makeIntent(this, mRepoOwner, mRepoName);
}

@Override
public void onMilestoneSelected(MilestoneDialog.MilestoneSelection milestoneSelection) {
switch (milestoneSelection.type) {
case NO_MILESTONE:
mSelectedMilestone = "";
break;
case ANY_MILESTONE:
mSelectedMilestone = null;
break;
case MILESTONE:
mSelectedMilestone = milestoneSelection.milestone.title();
break;
}
onFilterUpdated();
}

private void setSearchMode(boolean enabled) {
boolean changed = mSearchMode != enabled;
mSearchMode = enabled;
Expand Down Expand Up @@ -550,32 +562,10 @@ private void showLabelsDialog() {
}

private void showMilestonesDialog() {
final String[] milestones = new String[mMilestones.size() + 2];
int selected = mSelectedMilestone != null && mSelectedMilestone.isEmpty() ? 1 : 0;

milestones[0] = getResources().getString(R.string.issue_filter_by_any_milestone);
milestones[1] = getResources().getString(R.string.issue_filter_by_no_milestone);

for (int i = 0; i < mMilestones.size(); i++) {
milestones[i + 2] = mMilestones.get(i).title();
if (TextUtils.equals(mSelectedMilestone, milestones[i + 2])) {
selected = i + 2;
}
}

DialogInterface.OnClickListener selectCb = (dialog, which) -> {
mSelectedMilestone =
which == 0 ? null : which == 1 ? "" : milestones[which];
dialog.dismiss();
onFilterUpdated();
};

new AlertDialog.Builder(this)
.setCancelable(true)
.setTitle(R.string.issue_filter_by_milestone)
.setSingleChoiceItems(milestones, selected, selectCb)
.setNegativeButton(R.string.cancel, null)
.show();
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName, mIsPullRequest, true, false);
getSupportFragmentManager().beginTransaction()
.add(dialog, "dialog_milestone")
.commitAllowingStateLoss();
}

private void onFilterUpdated() {
Expand Down Expand Up @@ -630,22 +620,6 @@ private void filterAssignee() {
}
}

private void filterMilestone() {
if (mMilestones != null) {
showMilestonesDialog();
} else {
final IssueMilestoneService service = ServiceFactory.get(IssueMilestoneService.class, false);
registerTemporarySubscription(ApiHelpers.PageIterator
.toSingle(page -> service.getRepositoryMilestones(mRepoOwner, mRepoName, "open", page))
.compose(RxUtils::doInBackground)
.compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg))
.subscribe(milestones -> {
mMilestones = milestones;
showMilestonesDialog();
}, this::handleLoadFailure));
}
}

private void filterLabel() {
if (mLabels != null) {
showLabelsDialog();
Expand Down
Loading