Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helper class that helps you show RoboDialogFragments. You can use it with Roboguice and injected RoboDialogFragments. It is based on the DialogFragmentHelper class of the Github Android app. https://github.com/github/android/blob/master/app/src/main/java/com/github/mobile/ui/DialogFragmentHelper.java
/**
* Dialog fragment helper
*/
public abstract class DialogFragmentHelper extends RoboDialogFragment {
private static final String TAG = "dialog_fragment_helper";
/**
* Show dialog
*/
public static void show(FragmentActivity activity, RoboDialogFragment fragment, Bundle arguments) {
FragmentManager manager = activity.getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
Fragment current = manager.findFragmentByTag(TAG);
if (current != null) {
transaction.remove(current);
//transaction.addToBackStack(null);
transaction.commit();
}
if(fragment.getArguments() == null) {
fragment.setArguments(arguments);
}else {
fragment.getArguments().putAll(arguments);
}
fragment.show(manager, TAG);
}
}
To use simple inject a RoboDialogFragment and use it:
public class MyRoboFragment extends RoboFragment...
@Inject
private ProgressDialogFragment progressDialog;
private void createProgressDialog(int resId) {
Bundle arguments = new Bundle();
arguments.putString(ProgressDialogFragment.MESSAGE, getString(resId));
DialogFragmentHelper.show(getActivity(), progressDialog, arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment