1
1
package com .gh4a .dialogs ;
2
2
3
+ import android .app .Activity ;
3
4
import android .content .Context ;
5
+ import android .content .Intent ;
4
6
import android .os .Bundle ;
5
7
import android .support .annotation .Nullable ;
6
8
import android .support .v4 .app .Fragment ;
10
12
import android .widget .Button ;
11
13
12
14
import com .gh4a .R ;
15
+ import com .gh4a .activities .IssueMilestoneListActivity ;
13
16
import com .gh4a .fragment .IssueMilestoneListFragment ;
14
17
import com .meisolsson .githubsdk .model .Milestone ;
15
18
@@ -18,26 +21,35 @@ public class MilestoneDialog extends BasePagerDialog
18
21
private static final String EXTRA_OWNER = "owner" ;
19
22
private static final String EXTRA_REPO = "repo" ;
20
23
private static final String EXTRA_SHOW_ANY_MILESTONE = "show_any_milestone" ;
24
+ private static final String EXTRA_SHOW_MANAGE_MILESTONES_BUTTON = "show_manage_milestones_button" ;
25
+ private static final String EXTRA_FROM_PULL_REQUEST = "from_pull_request" ;
21
26
private static final int [] TITLES = new int []{
22
27
R .string .open , R .string .closed
23
28
};
29
+ private static final int REQUEST_MANAGE_MILESTONES = 3000 ;
24
30
25
31
public static MilestoneDialog newInstance (String repoOwner , String repoName ,
26
- boolean showAnyMilestoneButton ) {
32
+ boolean fromPullRequest , boolean showAnyMilestoneButton ,
33
+ boolean showManageMilestonesButton ) {
27
34
MilestoneDialog dialog = new MilestoneDialog ();
28
35
Bundle args = new Bundle ();
29
36
args .putString (EXTRA_OWNER , repoOwner );
30
37
args .putString (EXTRA_REPO , repoName );
38
+ args .putBoolean (EXTRA_FROM_PULL_REQUEST , fromPullRequest );
31
39
args .putBoolean (EXTRA_SHOW_ANY_MILESTONE , showAnyMilestoneButton );
40
+ args .putBoolean (EXTRA_SHOW_MANAGE_MILESTONES_BUTTON , showManageMilestonesButton );
32
41
dialog .setArguments (args );
33
42
return dialog ;
34
43
}
35
44
36
45
private String mRepoOwner ;
37
46
private String mRepoName ;
47
+ private boolean mFromPullRequest ;
38
48
private boolean mShowAnyMilestoneButton ;
49
+ private boolean mShowManageMilestonesButton ;
39
50
private Button mNoMilestoneButton ;
40
51
private Button mAnyMilestoneButton ;
52
+ private Button mManageMilestonesButton ;
41
53
private SelectionCallback mSelectionCallback ;
42
54
43
55
@ Override
@@ -46,7 +58,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
46
58
Bundle args = getArguments ();
47
59
mRepoOwner = args .getString (EXTRA_OWNER );
48
60
mRepoName = args .getString (EXTRA_REPO );
61
+ mFromPullRequest = args .getBoolean (EXTRA_FROM_PULL_REQUEST );
49
62
mShowAnyMilestoneButton = args .getBoolean (EXTRA_SHOW_ANY_MILESTONE );
63
+ mShowManageMilestonesButton = args .getBoolean (EXTRA_SHOW_MANAGE_MILESTONES_BUTTON );
50
64
}
51
65
52
66
@ Override
@@ -68,6 +82,9 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
68
82
mAnyMilestoneButton = addButton (R .string .issue_filter_by_any_milestone );
69
83
}
70
84
mNoMilestoneButton = addButton (R .string .issue_filter_by_no_milestone );
85
+ if (mShowManageMilestonesButton ) {
86
+ mManageMilestonesButton = addButton (R .string .issue_manage_milestones );
87
+ }
71
88
return view ;
72
89
}
73
90
@@ -77,19 +94,34 @@ public void onClick(View v) {
77
94
onMilestoneSelected (MilestoneSelection .Type .NO_MILESTONE );
78
95
} else if (v == mAnyMilestoneButton ) {
79
96
onMilestoneSelected (MilestoneSelection .Type .ANY_MILESTONE );
97
+ } else if (v == mManageMilestonesButton ) {
98
+ Intent intent = IssueMilestoneListActivity .makeIntent (
99
+ getContext (), mRepoOwner , mRepoName , mFromPullRequest );
100
+ startActivityForResult (intent , REQUEST_MANAGE_MILESTONES );
80
101
} else {
81
102
super .onClick (v );
82
103
}
83
104
}
84
105
106
+ @ Override
107
+ public void onActivityResult (int requestCode , int resultCode , Intent data ) {
108
+ if (requestCode == REQUEST_MANAGE_MILESTONES ) {
109
+ if (resultCode == Activity .RESULT_OK ) {
110
+ refreshPages ();
111
+ }
112
+ } else {
113
+ super .onActivityResult (requestCode , resultCode , data );
114
+ }
115
+ }
116
+
85
117
@ Override
86
118
protected int [] getTabTitleResIds () {
87
119
return TITLES ;
88
120
}
89
121
90
122
@ Override
91
123
protected Fragment makeFragment (int position ) {
92
- return IssueMilestoneListFragment .newInstance (mRepoOwner , mRepoName , position == 1 , false );
124
+ return IssueMilestoneListFragment .newInstance (mRepoOwner , mRepoName , position == 1 , mFromPullRequest );
93
125
}
94
126
95
127
@ Override
0 commit comments