Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce switch case clauses number of lines to increase the readability #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
195 changes: 113 additions & 82 deletions example/src/main/java/com/cocosw/bottomsheet/example/ListAcitivty.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,53 +84,22 @@ private Drawable getRoundedBitmap(int imageId) {
protected Dialog onCreateDialog(final int position, Bundle args) {
switch (action) {
case 0:
sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
casePositionZero(position);
break;
case 1:
sheet = new BottomSheet.Builder(this).sheet(R.menu.noicon).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
casePositionOne(position);
break;

case 2:
sheet = new BottomSheet.Builder(this).darkTheme().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
casePositionTwo(position);
break;
case 3:
sheet = new BottomSheet.Builder(this).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).grid().build();
casePositionThree(position);
break;
case 4:
sheet = new BottomSheet.Builder(this, R.style.BottomSheet_StyleDialog).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
casePositionFour(position);
break;
case 5:
sheet = new BottomSheet.Builder(this).title("To " + adapter.getItem(position)).sheet(R.menu.longlist).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).limit(R.integer.bs_initial_list_row).build();
casePositionFive(position);
break;
case 6:
sheet = getShareActions("Hello " + adapter.getItem(position)).title("Share To " + adapter.getItem(position)).limit(R.integer.no_limit).build();
Expand All @@ -139,59 +108,121 @@ public void onClick(DialogInterface dialog, int which) {
sheet = getShareActions("Hello " + adapter.getItem(position)).title("Share To " + adapter.getItem(position)).build();
break;
case 8:
sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
final Menu menu = sheet.getMenu();
menu.getItem(0).setTitle("MenuClickListener");
menu.getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
q.alert("OnMenuItemClickListener", "You can set OnMenuItemClickListener for each item");
return true;
}
});
menu.getItem(1).setVisible(false);
menu.getItem(2).setEnabled(false);
menu.add(Menu.NONE, 23, Menu.NONE, "Fresh meal!");
menu.findItem(23).setIcon(R.drawable.perm_group_user_dictionary);
menu.findItem(23).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
q.toast("Hello");
return true;
}
});
menu.setGroupVisible(android.R.id.empty,false);
casePositionEight(position);
break;
case 9:
sheet = new BottomSheet.Builder(this, R.style.BottomSheet_CustomizedDialog).grid().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
sheet.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
q.toast("I'm showing");
}
});
sheet.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
q.toast("I'm dismissing");
}
});
casePositionNine(position);
break;

}
return sheet;
}

private void casePositionNine(final int position) {
sheet = new BottomSheet.Builder(this, R.style.BottomSheet_CustomizedDialog).grid().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
sheet.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
q.toast("I'm showing");
}
});
sheet.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
q.toast("I'm dismissing");
}
});
}

private void casePositionEight(final int position) {
sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
final Menu menu = sheet.getMenu();
menu.getItem(0).setTitle("MenuClickListener");
menu.getItem(0).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
q.alert("OnMenuItemClickListener", "You can set OnMenuItemClickListener for each item");
return true;
}
});
menu.getItem(1).setVisible(false);
menu.getItem(2).setEnabled(false);
menu.add(Menu.NONE, 23, Menu.NONE, "Fresh meal!");
menu.findItem(23).setIcon(R.drawable.perm_group_user_dictionary);
menu.findItem(23).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
q.toast("Hello");
return true;
}
});
menu.setGroupVisible(android.R.id.empty,false);
}

private void casePositionFive(final int position) {
sheet = new BottomSheet.Builder(this).title("To " + adapter.getItem(position)).sheet(R.menu.longlist).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).limit(R.integer.bs_initial_list_row).build();
}

private void casePositionFour(final int position) {
sheet = new BottomSheet.Builder(this, R.style.BottomSheet_StyleDialog).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
}

private void casePositionThree(final int position) {
sheet = new BottomSheet.Builder(this).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).grid().build();
}

private void casePositionTwo(final int position) {
sheet = new BottomSheet.Builder(this).darkTheme().title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
}

private void casePositionOne(final int position) {
sheet = new BottomSheet.Builder(this).sheet(R.menu.noicon).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
}

private void casePositionZero(final int position) {
sheet = new BottomSheet.Builder(this).icon(getRoundedBitmap(R.drawable.icon)).title("To " + adapter.getItem(position)).sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ListAcitivty.this.onClick(adapter.getItem(position), which);
}
}).build();
}

private BottomSheet.Builder getShareActions(String text) {
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,7 @@ private int getHeaderSize(){
break;

case GridView.STRETCH_SPACING:
mColumnWidth = requestedColumnWidth;
if (mNumColumns > 1) {
mHorizontalSpacing = requestedHorizontalSpacing +
spaceLeftOver / (mNumColumns - 1);
} else {
mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver;
}
caseGridViewStretchSpacing(spaceLeftOver);
break;

case GridView.STRETCH_SPACING_UNIFORM:
Expand All @@ -138,6 +132,16 @@ private int getHeaderSize(){
return mHeaderWidth;
}

private void caseGridViewStretchSpacing(int spaceLeftOver) {
mColumnWidth = requestedColumnWidth;
if (mNumColumns > 1) {
mHorizontalSpacing = requestedHorizontalSpacing +
spaceLeftOver / (mNumColumns - 1);
} else {
mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver;
}
}


public void setSections(Section... sections) {
mInitialSections = sections;
Expand Down