Skip to content

Instantly share code, notes, and snippets.

@nicolasjafelle
Last active December 20, 2015 07:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nicolasjafelle/6091872 to your computer and use it in GitHub Desktop.
Save nicolasjafelle/6091872 to your computer and use it in GitHub Desktop.
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