Skip to content

Instantly share code, notes, and snippets.

@hateum
Forked from nicolasjafelle/DialogFragmentHelper
Created July 29, 2013 03:00
Show Gist options
  • Save hateum/6101912 to your computer and use it in GitHub Desktop.
Save hateum/6101912 to your computer and use it in GitHub Desktop.
/**
* 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