Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ public void dismiss() {
showActivityBar();
}

if (getFragmentManager() != null) {
getFragmentManager().popBackStackImmediate();
try {
getParentFragmentManager().popBackStackImmediate();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void dismiss() {
showActivityBar();
}

getFragmentManager().popBackStackImmediate();
getParentFragmentManager().popBackStackImmediate();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
mImageManager.loadIntoCircle(mHeaderAvatar, ImageType.AVATAR_WITHOUT_BACKGROUND, mPhotoUrl);
}
} else {
mDialog = (FullScreenDialogFragment) getFragmentManager().findFragmentByTag(FullScreenDialogFragment.TAG);
mDialog = (FullScreenDialogFragment) getParentFragmentManager()
.findFragmentByTag(FullScreenDialogFragment.TAG);

if (mDialog != null) {
mDialog.setOnConfirmListener(this);
Expand Down Expand Up @@ -603,7 +604,7 @@ protected void launchDialog() {
.setContent(UsernameChangerFullScreenDialogFragment.class, bundle)
.build();

mDialog.show(getActivity().getSupportFragmentManager(), FullScreenDialogFragment.TAG);
mDialog.show(requireActivity().getSupportFragmentManager(), FullScreenDialogFragment.TAG);
}

protected void loadAvatar(final String avatarUrl, String injectFilePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,22 +379,18 @@ class DomainRegistrationDetailsFragment : Fragment() {
)
}

@Suppress("DEPRECATION")
private fun showStatePicker(states: List<SupportedStateResponse>) {
val dialogFragment = StatePickerDialogFragment.newInstance(states.toCollection(ArrayList()))
dialogFragment.setTargetFragment(this, 0)
dialogFragment.show(requireFragmentManager(), StatePickerDialogFragment.TAG)
dialogFragment.show(childFragmentManager, StatePickerDialogFragment.TAG)
}

@Suppress("DEPRECATION")
private fun showCountryPicker(countries: List<SupportedDomainCountry>) {
val dialogFragment = CountryPickerDialogFragment.newInstance(
countries.toCollection(
ArrayList()
)
)
dialogFragment.setTargetFragment(this, 0)
dialogFragment.show(requireFragmentManager(), CountryPickerDialogFragment.TAG)
dialogFragment.show(childFragmentManager, CountryPickerDialogFragment.TAG)
}

private fun DomainRegistrationDetailsFragmentBinding.toggleFormProgressIndictor(visible: Boolean) {
Expand Down Expand Up @@ -472,13 +468,9 @@ class DomainRegistrationDetailsFragment : Fragment() {
as ArrayList<SupportedStateResponse>
}

@Suppress("DEPRECATION", "UseCheckOrError")
@Suppress("UseCheckOrError")
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
if (targetFragment == null) {
throw IllegalStateException("StatePickerDialogFragment is missing a targetFragment ")
}

viewModel = ViewModelProvider(targetFragment!!, viewModelFactory)
viewModel = ViewModelProvider(requireParentFragment(), viewModelFactory)
.get(DomainRegistrationDetailsViewModel::class.java)
val builder = MaterialAlertDialogBuilder(requireContext())
builder.setTitle(R.string.domain_registration_state_picker_dialog_title)
Expand Down Expand Up @@ -521,13 +513,9 @@ class DomainRegistrationDetailsFragment : Fragment() {
as ArrayList<SupportedDomainCountry>
}

@Suppress("DEPRECATION", "UseCheckOrError")
@Suppress("UseCheckOrError")
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
if (targetFragment == null) {
throw IllegalStateException("CountryPickerDialogFragment is missing a targetFragment ")
}

viewModel = ViewModelProvider(targetFragment!!, viewModelFactory)
viewModel = ViewModelProvider(requireParentFragment(), viewModelFactory)
.get(DomainRegistrationDetailsViewModel::class.java)
val builder = MaterialAlertDialogBuilder(requireContext())
builder.setTitle(R.string.domain_registration_country_picker_dialog_title)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.wordpress.android.ui.main;

import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
Expand All @@ -15,6 +13,8 @@
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.SearchView;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand Down Expand Up @@ -818,7 +818,7 @@ public void onDestroyActionMode(@NonNull ActionMode actionMode) {
}
}

public static void addSite(Activity activity, boolean hasAccessToken, SiteCreationSource source) {
public static void addSite(FragmentActivity activity, boolean hasAccessToken, SiteCreationSource source) {
if (hasAccessToken) {
if (!BuildConfig.ENABLE_ADD_SELF_HOSTED_SITE) {
ActivityLauncher.newBlogForResult(activity, source);
Expand All @@ -833,36 +833,35 @@ public static void addSite(Activity activity, boolean hasAccessToken, SiteCreati
}
}

@SuppressWarnings("deprecation")
private static void showAddSiteDialog(Activity activity, SiteCreationSource source) {
private static void showAddSiteDialog(FragmentActivity activity, SiteCreationSource source) {
DialogFragment dialog = new AddSiteDialog();
Bundle args = new Bundle();
args.putString(ARG_SITE_CREATION_SOURCE, source.getLabel());
dialog.setArguments(args);
dialog.show(activity.getFragmentManager(), AddSiteDialog.ADD_SITE_DIALOG_TAG);
dialog.show(activity.getSupportFragmentManager(), AddSiteDialog.ADD_SITE_DIALOG_TAG);
}

/*
* dialog which appears after user taps "Add site" - enables choosing whether to create
* a new wp.com blog or add an existing self-hosted one
/**
* Dialog which appears after user taps "Add site" - enables choosing whether to create
* a new wp.com blog or add an existing self-hosted one.
*
* @apiNote Must pass {@link SitePickerActivity#ARG_SITE_CREATION_SOURCE} in arguments when creating this dialog.
*/
@SuppressWarnings("deprecation")
public static class AddSiteDialog extends DialogFragment {
static final String ADD_SITE_DIALOG_TAG = "add_site_dialog";

@NonNull
@Override
@SuppressWarnings("deprecation")
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
SiteCreationSource source =
SiteCreationSource.fromString(getArguments().getString(ARG_SITE_CREATION_SOURCE));
SiteCreationSource.fromString(requireArguments().getString(ARG_SITE_CREATION_SOURCE));
CharSequence[] items =
{getString(R.string.site_picker_create_wpcom),
getString(R.string.site_picker_add_self_hosted)};
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity());
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireActivity());
builder.setTitle(R.string.site_picker_add_site);
builder.setAdapter(
new ArrayAdapter<>(getActivity(), R.layout.add_new_site_dialog_item, R.id.text, items),
new ArrayAdapter<>(requireActivity(), R.layout.add_new_site_dialog_item, R.id.text, items),
(dialog, which) -> {
if (which == 0) {
ActivityLauncher.newBlogForResult(getActivity(), source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ public static PersonDetailFragment newInstance(long currentUserId, long personId
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((WordPress) getActivity().getApplicationContext()).component().inject(this);
((WordPress) requireActivity().getApplicationContext()).component().inject(this);

if (savedInstanceState == null) {
mCurrentUserId = getArguments().getLong(ARG_CURRENT_USER_ID);
mPersonId = getArguments().getLong(ARG_PERSON_ID);
mLocalTableBlogId = getArguments().getInt(ARG_LOCAL_TABLE_BLOG_ID);
mPersonType = (Person.PersonType) getArguments().getSerializable(ARG_PERSON_TYPE);
mCurrentUserId = requireArguments().getLong(ARG_CURRENT_USER_ID);
mPersonId = requireArguments().getLong(ARG_PERSON_ID);
mLocalTableBlogId = requireArguments().getInt(ARG_LOCAL_TABLE_BLOG_ID);
mPersonType = (Person.PersonType) requireArguments().getSerializable(ARG_PERSON_TYPE);
} else {
mCurrentUserId = savedInstanceState.getLong(ARG_CURRENT_USER_ID);
mPersonId = savedInstanceState.getLong(ARG_PERSON_ID);
Expand Down Expand Up @@ -121,8 +121,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.person_detail_fragment, container, false);

Toolbar toolbar = rootView.findViewById(R.id.toolbar_main);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
Expand Down Expand Up @@ -257,7 +257,7 @@ private void showRoleChangeDialog() {
mSiteStore.getSiteByLocalId(
mLocalTableBlogId),
person.getRole());
dialog.show(getFragmentManager(), null);
dialog.show(getChildFragmentManager(), null);
}

// used to optimistically update the role
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public static AddCategoryFragment newInstance(SiteModel site) {
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
((WordPress) getActivity().getApplication()).component().inject(this);
((WordPress) requireActivity().getApplication()).component().inject(this);

initSite(savedInstanceState);

AlertDialog.Builder builder =
new MaterialAlertDialogBuilder(new ContextThemeWrapper(getActivity(), R.style.PostSettingsTheme));
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
LayoutInflater inflater = requireActivity().getLayoutInflater();

// Inflate view
//noinspection InflateParams
Expand All @@ -72,7 +72,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
@Override
public void onStart() {
super.onStart();
AlertDialog dialog = (AlertDialog) getDialog();
AlertDialog dialog = (AlertDialog) requireDialog();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -88,15 +88,15 @@ private void initSite(Bundle savedInstanceState) {
if (getArguments() != null) {
mSite = (SiteModel) getArguments().getSerializable(WordPress.SITE);
} else {
mSite = (SiteModel) getActivity().getIntent().getSerializableExtra(WordPress.SITE);
mSite = (SiteModel) requireActivity().getIntent().getSerializableExtra(WordPress.SITE);
}
} else {
mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
}

if (mSite == null) {
ToastUtils.showToast(getActivity(), R.string.blog_not_found, ToastUtils.Duration.SHORT);
getFragmentManager().popBackStack();
ToastUtils.showToast(requireActivity(), R.string.blog_not_found, ToastUtils.Duration.SHORT);
getParentFragmentManager().popBackStack();
}
}

Expand All @@ -115,7 +115,7 @@ private boolean addCategory() {
categoryName,
parentId
);
((SelectCategoriesActivity) getActivity()).categoryAdded(newCategory);
((SelectCategoriesActivity) requireActivity()).categoryAdded(newCategory);

return true;
}
Expand Down