Skip to content

Commit 1757a50

Browse files
committed
Add back option to select "any milestone"
1 parent ea110eb commit 1757a50

File tree

6 files changed

+84
-57
lines changed

6 files changed

+84
-57
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public void onMilestoneSelected(@Nullable Milestone milestone) {
386386
}
387387

388388
private void showMilestonesDialog() {
389-
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName);
389+
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName, false);
390390
getSupportFragmentManager().beginTransaction()
391391
.add(dialog, "dialog_milestone")
392392
.commitAllowingStateLoss();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ protected Intent navigateUp() {
450450

451451
@Override
452452
public void onMilestoneSelected(@Nullable Milestone milestone) {
453-
mSelectedMilestone = milestone != null ? milestone.getTitle() : "";
453+
mSelectedMilestone = milestone != null ? milestone.getTitle() : null;
454454
invalidateFragments();
455455
}
456456

@@ -541,7 +541,7 @@ public void onClick(DialogInterface dialog, int which) {
541541
}
542542

543543
private void showMilestonesDialog() {
544-
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName);
544+
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName, true);
545545
getSupportFragmentManager().beginTransaction()
546546
.add(dialog, "dialog_milestone")
547547
.commitAllowingStateLoss();

app/src/main/java/com/gh4a/dialogs/BasePagerDialog.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
import android.view.View;
1111
import android.view.ViewGroup;
1212
import android.widget.Button;
13+
import android.widget.LinearLayout;
1314

1415
import com.gh4a.R;
1516

1617
public abstract class BasePagerDialog extends DialogFragment implements View.OnClickListener {
18+
private LinearLayout mButtonBar;
19+
1720
@Nullable
1821
@Override
1922
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@@ -39,15 +42,11 @@ public int getCount() {
3942
}
4043
});
4144

45+
mButtonBar = view.findViewById(R.id.button_bar);
46+
4247
Button cancelButton = view.findViewById(R.id.cancel_button);
4348
cancelButton.setOnClickListener(this);
4449

45-
Button deselectButton = view.findViewById(R.id.deselect_button);
46-
if (showDeselectButton()) {
47-
deselectButton.setVisibility(View.VISIBLE);
48-
deselectButton.setOnClickListener(this);
49-
}
50-
5150
return view;
5251
}
5352

@@ -61,22 +60,26 @@ public void onResume() {
6160

6261
@Override
6362
public void onClick(View v) {
64-
switch (v.getId()) {
65-
case R.id.cancel_button:
66-
dismiss();
67-
break;
68-
case R.id.deselect_button:
69-
onDeselect();
70-
break;
63+
if (v.getId() == R.id.cancel_button) {
64+
dismiss();
7165
}
7266
}
7367

74-
protected abstract int[] getTabTitleResIds();
75-
76-
protected abstract Fragment makeFragment(int position);
68+
protected Button addButton(int textResId) {
69+
Button button = (Button) getLayoutInflater()
70+
.inflate(R.layout.dialog_button, mButtonBar, false);
71+
button.setText(textResId);
72+
button.setOnClickListener(this);
7773

78-
protected abstract boolean showDeselectButton();
74+
mButtonBar.addView(button, mButtonBar.getChildCount() - 1);
75+
if (mButtonBar.getChildCount() >= 3) {
76+
mButtonBar.setOrientation(LinearLayout.VERTICAL);
77+
}
7978

80-
protected void onDeselect() {
79+
return button;
8180
}
81+
82+
protected abstract int[] getTabTitleResIds();
83+
84+
protected abstract Fragment makeFragment(int position);
8285
}

app/src/main/java/com/gh4a/dialogs/MilestoneDialog.java

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import android.support.annotation.Nullable;
55
import android.support.v4.app.Fragment;
66
import android.support.v4.app.FragmentActivity;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.widget.Button;
711

812
import com.gh4a.R;
913
import com.gh4a.fragment.IssueMilestoneListFragment;
@@ -14,52 +18,68 @@ public class MilestoneDialog extends BasePagerDialog
1418
implements IssueMilestoneListFragment.SelectionCallback {
1519
private static final String EXTRA_OWNER = "owner";
1620
private static final String EXTRA_REPO = "repo";
21+
private static final String EXTRA_SHOW_ANY_MILESTONE = "show_any_milestone";
1722
private static final int[] TITLES = new int[] {
1823
R.string.open, R.string.closed
1924
};
2025

21-
public static MilestoneDialog newInstance(String repoOwner, String repoName) {
26+
public static MilestoneDialog newInstance(String repoOwner, String repoName,
27+
boolean showAnyMilestoneButton) {
2228
MilestoneDialog dialog = new MilestoneDialog();
2329
Bundle args = new Bundle();
2430
args.putString(EXTRA_OWNER, repoOwner);
2531
args.putString(EXTRA_REPO, repoName);
32+
args.putBoolean(EXTRA_SHOW_ANY_MILESTONE, showAnyMilestoneButton);
2633
dialog.setArguments(args);
2734
return dialog;
2835
}
2936

3037
private String mRepoOwner;
3138
private String mRepoName;
39+
private boolean mShowAnyMilestoneButton;
40+
private Button mNoMilestoneButton;
41+
private Button mAnyMilestoneButton;
3242

3343
@Override
3444
public void onCreate(@Nullable Bundle savedInstanceState) {
3545
super.onCreate(savedInstanceState);
3646
Bundle args = getArguments();
3747
mRepoOwner = args.getString(EXTRA_OWNER);
3848
mRepoName = args.getString(EXTRA_REPO);
49+
mShowAnyMilestoneButton = args.getBoolean(EXTRA_SHOW_ANY_MILESTONE);
3950
}
4051

52+
@Nullable
4153
@Override
42-
protected int[] getTabTitleResIds() {
43-
return TITLES;
54+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
55+
@Nullable Bundle savedInstanceState) {
56+
View view = super.onCreateView(inflater, container, savedInstanceState);
57+
if (mShowAnyMilestoneButton) {
58+
mAnyMilestoneButton = addButton(R.string.issue_filter_by_any_milestone);
59+
}
60+
mNoMilestoneButton = addButton(R.string.issue_filter_by_no_milestone);
61+
return view;
4462
}
4563

4664
@Override
47-
protected Fragment makeFragment(int position) {
48-
return IssueMilestoneListFragment.newInstance(
49-
mRepoOwner,
50-
mRepoName,
51-
position == 1,
52-
false);
65+
public void onClick(View v) {
66+
if (v == mNoMilestoneButton) {
67+
onMilestoneSelected(new Milestone().setTitle(""));
68+
} else if (v == mAnyMilestoneButton) {
69+
onMilestoneSelected(null);
70+
} else {
71+
super.onClick(v);
72+
}
5373
}
5474

5575
@Override
56-
protected boolean showDeselectButton() {
57-
return true;
76+
protected int[] getTabTitleResIds() {
77+
return TITLES;
5878
}
5979

6080
@Override
61-
protected void onDeselect() {
62-
onMilestoneSelected(null);
81+
protected Fragment makeFragment(int position) {
82+
return IssueMilestoneListFragment.newInstance(mRepoOwner, mRepoName, position == 1, false);
6383
}
6484

6585
@Override
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Button
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
style="?buttonBarButtonStyle"
6+
android:layout_width="wrap_content"
7+
android:layout_height="wrap_content"
8+
tools:text="Button" />
Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout
2+
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
5+
android:layout_height="match_parent"
6+
android:orientation="vertical">
67

78
<android.support.v4.view.ViewPager
89
android:id="@+id/dialog_pager"
910
android:layout_width="match_parent"
10-
android:layout_height="match_parent"
11-
android:layout_above="@+id/cancel_button">
11+
android:layout_height="0dp"
12+
android:layout_weight="1">
1213

1314
<android.support.design.widget.TabLayout
1415
android:id="@+id/dialog_pager_tabs"
@@ -17,25 +18,20 @@
1718

1819
</android.support.v4.view.ViewPager>
1920

20-
<Button
21-
android:id="@+id/deselect_button"
22-
style="@style/Widget.AppCompat.Button.Borderless.Colored"
23-
android:layout_width="wrap_content"
21+
<LinearLayout
22+
android:id="@+id/button_bar"
23+
android:layout_width="match_parent"
2424
android:layout_height="wrap_content"
25-
android:layout_alignParentBottom="true"
26-
android:layout_gravity="right|end"
27-
android:layout_toLeftOf="@+id/cancel_button"
28-
android:text="@string/deselect"
29-
android:visibility="gone" />
25+
android:gravity="right|end"
26+
android:orientation="horizontal">
3027

31-
<Button
32-
android:id="@+id/cancel_button"
33-
style="@style/Widget.AppCompat.Button.Borderless.Colored"
34-
android:layout_width="wrap_content"
35-
android:layout_height="wrap_content"
36-
android:layout_alignParentBottom="true"
37-
android:layout_alignParentRight="true"
38-
android:layout_gravity="right|end"
39-
android:text="@string/cancel" />
28+
<Button
29+
android:id="@+id/cancel_button"
30+
style="?buttonBarButtonStyle"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
android:text="@string/cancel" />
34+
35+
</LinearLayout>
4036

41-
</RelativeLayout>
37+
</LinearLayout>

0 commit comments

Comments
 (0)