Last active
December 20, 2015 07:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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