Skip to content

Commit

Permalink
Add back option to select "any milestone"
Browse files Browse the repository at this point in the history
  • Loading branch information
Tunous committed Sep 24, 2017
1 parent ea110eb commit 1757a50
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void onMilestoneSelected(@Nullable Milestone milestone) {
}

private void showMilestonesDialog() {
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName);
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName, false);
getSupportFragmentManager().beginTransaction()
.add(dialog, "dialog_milestone")
.commitAllowingStateLoss();
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/gh4a/activities/IssueListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ protected Intent navigateUp() {

@Override
public void onMilestoneSelected(@Nullable Milestone milestone) {
mSelectedMilestone = milestone != null ? milestone.getTitle() : "";
mSelectedMilestone = milestone != null ? milestone.getTitle() : null;
invalidateFragments();
}

Expand Down Expand Up @@ -541,7 +541,7 @@ public void onClick(DialogInterface dialog, int which) {
}

private void showMilestonesDialog() {
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName);
MilestoneDialog dialog = MilestoneDialog.newInstance(mRepoOwner, mRepoName, true);
getSupportFragmentManager().beginTransaction()
.add(dialog, "dialog_milestone")
.commitAllowingStateLoss();
Expand Down
39 changes: 21 additions & 18 deletions app/src/main/java/com/gh4a/dialogs/BasePagerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import com.gh4a.R;

public abstract class BasePagerDialog extends DialogFragment implements View.OnClickListener {
private LinearLayout mButtonBar;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
Expand All @@ -39,15 +42,11 @@ public int getCount() {
}
});

mButtonBar = view.findViewById(R.id.button_bar);

Button cancelButton = view.findViewById(R.id.cancel_button);
cancelButton.setOnClickListener(this);

Button deselectButton = view.findViewById(R.id.deselect_button);
if (showDeselectButton()) {
deselectButton.setVisibility(View.VISIBLE);
deselectButton.setOnClickListener(this);
}

return view;
}

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

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.cancel_button:
dismiss();
break;
case R.id.deselect_button:
onDeselect();
break;
if (v.getId() == R.id.cancel_button) {
dismiss();
}
}

protected abstract int[] getTabTitleResIds();

protected abstract Fragment makeFragment(int position);
protected Button addButton(int textResId) {
Button button = (Button) getLayoutInflater()
.inflate(R.layout.dialog_button, mButtonBar, false);
button.setText(textResId);
button.setOnClickListener(this);

protected abstract boolean showDeselectButton();
mButtonBar.addView(button, mButtonBar.getChildCount() - 1);
if (mButtonBar.getChildCount() >= 3) {
mButtonBar.setOrientation(LinearLayout.VERTICAL);
}

protected void onDeselect() {
return button;
}

protected abstract int[] getTabTitleResIds();

protected abstract Fragment makeFragment(int position);
}
46 changes: 33 additions & 13 deletions app/src/main/java/com/gh4a/dialogs/MilestoneDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.gh4a.R;
import com.gh4a.fragment.IssueMilestoneListFragment;
Expand All @@ -14,52 +18,68 @@ public class MilestoneDialog extends BasePagerDialog
implements IssueMilestoneListFragment.SelectionCallback {
private static final String EXTRA_OWNER = "owner";
private static final String EXTRA_REPO = "repo";
private static final String EXTRA_SHOW_ANY_MILESTONE = "show_any_milestone";
private static final int[] TITLES = new int[] {
R.string.open, R.string.closed
};

public static MilestoneDialog newInstance(String repoOwner, String repoName) {
public static MilestoneDialog newInstance(String repoOwner, String repoName,
boolean showAnyMilestoneButton) {
MilestoneDialog dialog = new MilestoneDialog();
Bundle args = new Bundle();
args.putString(EXTRA_OWNER, repoOwner);
args.putString(EXTRA_REPO, repoName);
args.putBoolean(EXTRA_SHOW_ANY_MILESTONE, showAnyMilestoneButton);
dialog.setArguments(args);
return dialog;
}

private String mRepoOwner;
private String mRepoName;
private boolean mShowAnyMilestoneButton;
private Button mNoMilestoneButton;
private Button mAnyMilestoneButton;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
mRepoOwner = args.getString(EXTRA_OWNER);
mRepoName = args.getString(EXTRA_REPO);
mShowAnyMilestoneButton = args.getBoolean(EXTRA_SHOW_ANY_MILESTONE);
}

@Nullable
@Override
protected int[] getTabTitleResIds() {
return TITLES;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
if (mShowAnyMilestoneButton) {
mAnyMilestoneButton = addButton(R.string.issue_filter_by_any_milestone);
}
mNoMilestoneButton = addButton(R.string.issue_filter_by_no_milestone);
return view;
}

@Override
protected Fragment makeFragment(int position) {
return IssueMilestoneListFragment.newInstance(
mRepoOwner,
mRepoName,
position == 1,
false);
public void onClick(View v) {
if (v == mNoMilestoneButton) {
onMilestoneSelected(new Milestone().setTitle(""));
} else if (v == mAnyMilestoneButton) {
onMilestoneSelected(null);
} else {
super.onClick(v);
}
}

@Override
protected boolean showDeselectButton() {
return true;
protected int[] getTabTitleResIds() {
return TITLES;
}

@Override
protected void onDeselect() {
onMilestoneSelected(null);
protected Fragment makeFragment(int position) {
return IssueMilestoneListFragment.newInstance(mRepoOwner, mRepoName, position == 1, false);
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/dialog_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="?buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Button" />
42 changes: 19 additions & 23 deletions app/src/main/res/layout/dialog_pager.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v4.view.ViewPager
android:id="@+id/dialog_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/cancel_button">
android:layout_height="0dp"
android:layout_weight="1">

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

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

<Button
android:id="@+id/deselect_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/button_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="right|end"
android:layout_toLeftOf="@+id/cancel_button"
android:text="@string/deselect"
android:visibility="gone" />
android:gravity="right|end"
android:orientation="horizontal">

<Button
android:id="@+id/cancel_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_gravity="right|end"
android:text="@string/cancel" />
<Button
android:id="@+id/cancel_button"
style="?buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel" />

</LinearLayout>

</RelativeLayout>
</LinearLayout>

0 comments on commit 1757a50

Please sign in to comment.