From de940dda904047759f8d4f6f411473afe1914fdb Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 24 Mar 2023 18:40:38 +0100 Subject: [PATCH] move initFragment() to BaseActivity so that it can be better accessed --- .../securesms/BaseActionBarActivity.java | 37 +++++++++++++++++ .../PassphraseRequiredActionBarActivity.java | 41 ------------------- .../securesms/qr/BackupTransferActivity.java | 22 ---------- 3 files changed, 37 insertions(+), 63 deletions(-) diff --git a/src/org/thoughtcrime/securesms/BaseActionBarActivity.java b/src/org/thoughtcrime/securesms/BaseActionBarActivity.java index ef9a31d901..d636541251 100644 --- a/src/org/thoughtcrime/securesms/BaseActionBarActivity.java +++ b/src/org/thoughtcrime/securesms/BaseActionBarActivity.java @@ -9,17 +9,22 @@ import android.view.ViewConfiguration; import android.view.WindowManager; +import androidx.annotation.IdRes; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; import org.thoughtcrime.securesms.util.Prefs; import java.lang.reflect.Field; +import java.util.Locale; public abstract class BaseActionBarActivity extends AppCompatActivity { private static final String TAG = BaseActionBarActivity.class.getSimpleName(); + public static final String LOCALE_EXTRA = "locale_extra"; @Override protected void onCreate(Bundle savedInstanceState) { @@ -90,4 +95,36 @@ public void makeSearchMenuVisible(final Menu menu, final MenuItem searchItem, bo } } } + + protected T initFragment(@IdRes int target, + @NonNull T fragment) + { + return initFragment(target, fragment, null); + } + + protected T initFragment(@IdRes int target, + @NonNull T fragment, + @Nullable Locale locale) + { + return initFragment(target, fragment, locale, null); + } + + protected T initFragment(@IdRes int target, + @NonNull T fragment, + @Nullable Locale locale, + @Nullable Bundle extras) + { + Bundle args = new Bundle(); + args.putSerializable(LOCALE_EXTRA, locale); + + if (extras != null) { + args.putAll(extras); + } + + fragment.setArguments(args); + getSupportFragmentManager().beginTransaction() + .replace(target, fragment) + .commitAllowingStateLoss(); + return fragment; + } } diff --git a/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java b/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java index 1786cd1603..e8fb9d93a0 100644 --- a/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java +++ b/src/org/thoughtcrime/securesms/PassphraseRequiredActionBarActivity.java @@ -4,21 +4,12 @@ import android.os.Bundle; import android.util.Log; -import androidx.annotation.IdRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; - import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.service.GenericForegroundService; -import java.util.Locale; - public abstract class PassphraseRequiredActionBarActivity extends BaseActionBarActivity { private static final String TAG = PassphraseRequiredActionBarActivity.class.getSimpleName(); - public static final String LOCALE_EXTRA = "locale_extra"; - @Override protected final void onCreate(Bundle savedInstanceState) { Log.w(TAG, "onCreate(" + savedInstanceState + ")"); @@ -48,36 +39,4 @@ protected final void onCreate(Bundle savedInstanceState) { protected void onPreCreate() {} protected void onCreate(Bundle savedInstanceState, boolean ready) {} - - protected T initFragment(@IdRes int target, - @NonNull T fragment) - { - return initFragment(target, fragment, null); - } - - protected T initFragment(@IdRes int target, - @NonNull T fragment, - @Nullable Locale locale) - { - return initFragment(target, fragment, locale, null); - } - - protected T initFragment(@IdRes int target, - @NonNull T fragment, - @Nullable Locale locale, - @Nullable Bundle extras) - { - Bundle args = new Bundle(); - args.putSerializable(LOCALE_EXTRA, locale); - - if (extras != null) { - args.putAll(extras); - } - - fragment.setArguments(args); - getSupportFragmentManager().beginTransaction() - .replace(target, fragment) - .commitAllowingStateLoss(); - return fragment; - } } diff --git a/src/org/thoughtcrime/securesms/qr/BackupTransferActivity.java b/src/org/thoughtcrime/securesms/qr/BackupTransferActivity.java index 1f41b90d2e..7ebceb223e 100644 --- a/src/org/thoughtcrime/securesms/qr/BackupTransferActivity.java +++ b/src/org/thoughtcrime/securesms/qr/BackupTransferActivity.java @@ -1,7 +1,5 @@ package org.thoughtcrime.securesms.qr; -import static org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity.LOCALE_EXTRA; - import android.content.Context; import android.content.Intent; import android.net.wifi.WifiInfo; @@ -12,12 +10,9 @@ import android.view.MenuItem; import android.widget.TextView; -import androidx.annotation.IdRes; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.Fragment; import org.thoughtcrime.securesms.BaseActionBarActivity; import org.thoughtcrime.securesms.ConversationListActivity; @@ -31,8 +26,6 @@ import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.Util; -import java.util.Locale; - public class BackupTransferActivity extends BaseActionBarActivity { private final static String TAG = BackupTransferActivity.class.getSimpleName(); @@ -221,19 +214,4 @@ public void appendSSID(final TextView textView) { }).start(); } } - - protected T initFragment(@IdRes int target, - @NonNull T fragment, - @Nullable Locale locale, - @Nullable Bundle extras) - { - Bundle args = new Bundle(); - args.putSerializable(LOCALE_EXTRA, locale); - if (extras != null) { - args.putAll(extras); - } - fragment.setArguments(args); - getSupportFragmentManager().beginTransaction().replace(target, fragment).commitAllowingStateLoss(); - return fragment; - } }