Closed isabsent closed 6 years ago
I recommend that you use AppCompatActivity
from the support-library (which my library relies on) instead of android.app.Activity
. This will also allow you to use newer features and material design on older android versions. It extends the core android.app.Activity
, thus you should be able to just replace it without any compatibility issues to your existing code. You only need to change the getFragmentManager()
calls to getSupportFragmentManager()
in case you are using it.
android.app.Activity
↳android.support.v4.app.FragmentActivity
↳android.support.v7.app.AppCompatActivity
Any update on this @isabsent?
It is acceptable for new project, but I would not like to change existing code now. Would you be so kind to made a fork of your library with android.app.Activity?
I have tried to remove all support
dependencies from your code. It is quite simple. The problem exists only for resultFragment = resultFragment.getParentFragment()
in eltos.simpledialogfragment.SimpleDialog
class. It requires API 17 to use a method getParentFragment()
. Is it possible to change only this part of your code somehow to make API level little bit lower? API 14 would be nice :)
Based on
Fragment resultFragment = getTargetFragment();
while (!handled && resultFragment != null){
if (resultFragment instanceof OnDialogResultListener){
handled = ((OnDialogResultListener) getTargetFragment())
.onResult(getTag(), which, extras);
}
resultFragment = resultFragment.getParentFragment();
}
I can suppose you need resultFragment = resultFragment.getParentFragment()
only if SimpleDialog
was called from other Fragment
and therefore if I call your dialogs from an Activity
and not from Fragment
this part of code will never used. Am I right?
I think it is much easier for you to change to the support library (i.e. adding functionality) instead of me trying to make the library work without it (i.e. removing functionality). I don't think rewriting the library is that simple and I will not spend time on this (I don't have much free time momentarly anyways and if you don't want to change existing code then why would I change the whole library?). However, it seems that you already put some effort into this. So please feel free to continue your Work; I will happily accept a merge request if you find a propper solution.
Concerning your last question: Yes, that is exactly what happens here. You might want to check the api-level and call this function only on devices running 17+.
I have ended with this code in eltos.simpledialogfragment.SimpleDialog
:
while (!handled && resultFragment != null){
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
if (resultFragment instanceof OnDialogResultListener) {
handled = ((OnDialogResultListener) getTargetFragment())
.onResult(getTag(), which, extras);
}
resultFragment = resultFragment.getParentFragment();
} else {
Toast.makeText(getActivity(), "Do not use this fork of SimpleDialogFragment library from a Fragment if API < 17!", Toast.LENGTH_LONG).show();
break;
}
}
for android.app.Activity
and android.app.Fragment
instead of support
classes.
You do realise that this is an infinite loop on devices running API<17 and will not even call the target fragments onResult
method, don't you?
Thanks! Fixed by means of break;
:)
I am trying to adopt your lib for my project in which I need to show some dialogs in the android.app.Activity but not the FragmentActivity.
What should I write at the first argument of the
show
method?