Skip to content

Commit

Permalink
Remove non-empty constructors in AssignmentsFragment & MoodleLoginDia…
Browse files Browse the repository at this point in the history
…logFragment causing crashes
  • Loading branch information
therealsujitk committed Mar 15, 2024
1 parent eb1859c commit 43085b9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void onNext(@NonNull JSONObject about) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.add(android.R.id.content, new UpdateDialogFragment(versionName, releaseNotes)).addToBackStack(null).commit();
transaction.add(android.R.id.content, UpdateDialogFragment.newInstance(versionName, releaseNotes)).addToBackStack(null).commit();
}
} catch (Exception ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void onNext(@NonNull JSONObject about) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.add(android.R.id.content, new UpdateDialogFragment(versionName, releaseNotes)).addToBackStack(null).commit();
transaction.add(android.R.id.content, UpdateDialogFragment.newInstance(versionName, releaseNotes)).addToBackStack(null).commit();

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,7 @@ private void displaySignInPage() {
new EmptyStateAdapter.ButtonAttributes() {
@Override
public void onClick() {
MoodleLoginDialogFragment moodleLoginDialogFragment = new MoodleLoginDialogFragment(o -> {
displayAssignmentsPage();
return null;
});

MoodleLoginDialogFragment moodleLoginDialogFragment = new MoodleLoginDialogFragment();
FragmentManager fragmentManager = requireActivity().getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
Expand Down Expand Up @@ -464,6 +460,9 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
getParentFragmentManager().setFragmentResult("customInsets2", result);
});

// Display Assignments if triggered from MoodleLoginDialogFragment
getParentFragmentManager().setFragmentResultListener("displayAssignmentsPage", this, (requestKey, result) -> displayAssignmentsPage());

this.swipeRefreshLayout.setColorSchemeColors(MaterialColors.getColor(this.swipeRefreshLayout, R.attr.colorSurface));
this.swipeRefreshLayout.setProgressBackgroundColorSchemeColor(MaterialColors.getColor(this.swipeRefreshLayout, R.attr.colorPrimary));
this.swipeRefreshLayout.setOnRefreshListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.json.JSONObject;

import java.util.Objects;
import java.util.function.Function;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.SingleObserver;
Expand All @@ -41,17 +40,12 @@ public class MoodleLoginDialogFragment extends DialogFragment {
EditText username, password;

CompositeDisposable compositeDisposable = new CompositeDisposable();
Function<Object, Object> callback;
MoodleApi moodleApi;

public MoodleLoginDialogFragment() {
// Required empty public constructor
}

public MoodleLoginDialogFragment(Function<Object, Object> callback) {
this.callback = callback;
}

private void signIn() {
this.setLoading(true);

Expand Down Expand Up @@ -152,7 +146,7 @@ public void onDestroyView() {
super.onDestroyView();

if (SettingsRepository.isMoodleSignedIn(requireContext())) {
this.callback.apply(null);
getParentFragmentManager().setFragmentResult("displayAssignmentsPage", new Bundle());
}

compositeDisposable.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public ReCaptchaDialogFragment() {
// Required empty public constructor
}

// TODO: Remove this constructor, android fragments should never be created using a non-empty
// constructor as android can sometimes re-create them with the empty constructor.
public ReCaptchaDialogFragment(@NonNull WebView webView, @NonNull OnCancelListener onCancelListener) {
this.onCancelListener = onCancelListener;
this.webView = webView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,27 @@ public UpdateDialogFragment() {
// Required empty public constructor
}

public UpdateDialogFragment(String versionName, String releaseNotes) {
this.versionName = versionName;
this.releaseNotes = releaseNotes;
public static UpdateDialogFragment newInstance(String versionName, String releaseNotes) {
Bundle args = new Bundle();
UpdateDialogFragment fragment = new UpdateDialogFragment();

args.putString("versionName", versionName);
args.putString("releaseNotes", releaseNotes);

fragment.setArguments(args);
return fragment;
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View dialogFragment = inflater.inflate(R.layout.layout_dialog_update, container, false);
Bundle args = getArguments();

if (args != null) {
this.versionName = args.getString("versionName");
this.releaseNotes = args.getString("releaseNotes");
}

TextView description = dialogFragment.findViewById(R.id.text_view_description);
description.setText(Html.fromHtml(this.requireContext().getString(R.string.update_message, this.versionName), Html.FROM_HTML_MODE_LEGACY));
Expand Down

0 comments on commit 43085b9

Please sign in to comment.