11package com .gh4a .dialogs ;
22
3+ import android .app .Activity ;
34import android .content .Context ;
5+ import android .content .Intent ;
46import android .os .Bundle ;
57import android .support .annotation .Nullable ;
68import android .support .v4 .app .Fragment ;
1012import android .widget .Button ;
1113
1214import com .gh4a .R ;
15+ import com .gh4a .activities .IssueMilestoneListActivity ;
1316import com .gh4a .fragment .IssueMilestoneListFragment ;
1417import com .meisolsson .githubsdk .model .Milestone ;
1518
@@ -18,26 +21,35 @@ public class MilestoneDialog extends BasePagerDialog
1821 private static final String EXTRA_OWNER = "owner" ;
1922 private static final String EXTRA_REPO = "repo" ;
2023 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" ;
2126 private static final int [] TITLES = new int []{
2227 R .string .open , R .string .closed
2328 };
29+ private static final int REQUEST_MANAGE_MILESTONES = 3000 ;
2430
2531 public static MilestoneDialog newInstance (String repoOwner , String repoName ,
26- boolean showAnyMilestoneButton ) {
32+ boolean fromPullRequest , boolean showAnyMilestoneButton ,
33+ boolean showManageMilestonesButton ) {
2734 MilestoneDialog dialog = new MilestoneDialog ();
2835 Bundle args = new Bundle ();
2936 args .putString (EXTRA_OWNER , repoOwner );
3037 args .putString (EXTRA_REPO , repoName );
38+ args .putBoolean (EXTRA_FROM_PULL_REQUEST , fromPullRequest );
3139 args .putBoolean (EXTRA_SHOW_ANY_MILESTONE , showAnyMilestoneButton );
40+ args .putBoolean (EXTRA_SHOW_MANAGE_MILESTONES_BUTTON , showManageMilestonesButton );
3241 dialog .setArguments (args );
3342 return dialog ;
3443 }
3544
3645 private String mRepoOwner ;
3746 private String mRepoName ;
47+ private boolean mFromPullRequest ;
3848 private boolean mShowAnyMilestoneButton ;
49+ private boolean mShowManageMilestonesButton ;
3950 private Button mNoMilestoneButton ;
4051 private Button mAnyMilestoneButton ;
52+ private Button mManageMilestonesButton ;
4153 private SelectionCallback mSelectionCallback ;
4254
4355 @ Override
@@ -46,7 +58,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
4658 Bundle args = getArguments ();
4759 mRepoOwner = args .getString (EXTRA_OWNER );
4860 mRepoName = args .getString (EXTRA_REPO );
61+ mFromPullRequest = args .getBoolean (EXTRA_FROM_PULL_REQUEST );
4962 mShowAnyMilestoneButton = args .getBoolean (EXTRA_SHOW_ANY_MILESTONE );
63+ mShowManageMilestonesButton = args .getBoolean (EXTRA_SHOW_MANAGE_MILESTONES_BUTTON );
5064 }
5165
5266 @ Override
@@ -68,6 +82,9 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
6882 mAnyMilestoneButton = addButton (R .string .issue_filter_by_any_milestone );
6983 }
7084 mNoMilestoneButton = addButton (R .string .issue_filter_by_no_milestone );
85+ if (mShowManageMilestonesButton ) {
86+ mManageMilestonesButton = addButton (R .string .issue_manage_milestones );
87+ }
7188 return view ;
7289 }
7390
@@ -77,19 +94,34 @@ public void onClick(View v) {
7794 onMilestoneSelected (MilestoneSelection .Type .NO_MILESTONE );
7895 } else if (v == mAnyMilestoneButton ) {
7996 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 );
80101 } else {
81102 super .onClick (v );
82103 }
83104 }
84105
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+
85117 @ Override
86118 protected int [] getTabTitleResIds () {
87119 return TITLES ;
88120 }
89121
90122 @ Override
91123 protected Fragment makeFragment (int position ) {
92- return IssueMilestoneListFragment .newInstance (mRepoOwner , mRepoName , position == 1 , false );
124+ return IssueMilestoneListFragment .newInstance (mRepoOwner , mRepoName , position == 1 , mFromPullRequest );
93125 }
94126
95127 @ Override
0 commit comments