remove pointless null guards

The cast to AppCompatActivity would throw an exception if it failed.
This commit is contained in:
Hans-Christoph Steiner 2021-03-03 16:22:47 +01:00
parent 2d9d0c30b1
commit 5fe5754a2d

View File

@ -2,17 +2,14 @@ package org.fdroid.fdroid.views.main;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import androidx.appcompat.app.AppCompatActivity;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import org.fdroid.fdroid.R; import org.fdroid.fdroid.R;
import org.fdroid.fdroid.views.PreferencesFragment; import org.fdroid.fdroid.views.PreferencesFragment;
@SuppressWarnings("LineLength")
/** /**
* When attached to the window, the {@link PreferencesFragment} will be added. When detached from * When attached to the window, the {@link PreferencesFragment} will be added. When detached from
* the window, the fragment will be removed. * the window, the fragment will be removed.
@ -52,9 +49,6 @@ public class SettingsView extends FrameLayout {
super.onAttachedToWindow(); super.onAttachedToWindow();
AppCompatActivity activity = (AppCompatActivity) getContext(); AppCompatActivity activity = (AppCompatActivity) getContext();
if (activity == null) {
throw new IllegalArgumentException("Cannot add a SettingsView to activities which are not an AppCompatActivity");
}
if (currentTransaction == null) { if (currentTransaction == null) {
currentTransaction = activity.getSupportFragmentManager().beginTransaction(); currentTransaction = activity.getSupportFragmentManager().beginTransaction();
@ -71,9 +65,6 @@ public class SettingsView extends FrameLayout {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
AppCompatActivity activity = (AppCompatActivity) getContext(); AppCompatActivity activity = (AppCompatActivity) getContext();
if (activity == null) {
throw new IllegalArgumentException("Cannot add a SettingsView to activities which are not an AppCompatActivity");
}
Fragment existingFragment = activity.getSupportFragmentManager().findFragmentByTag("preferences-fragment"); Fragment existingFragment = activity.getSupportFragmentManager().findFragmentByTag("preferences-fragment");
if (existingFragment == null) { if (existingFragment == null) {