Skip to content

Commit

Permalink
move initFragment() to BaseActivity so that it can be better accessed
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Mar 24, 2023
1 parent 73c0429 commit de940dd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 63 deletions.
37 changes: 37 additions & 0 deletions src/org/thoughtcrime/securesms/BaseActionBarActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -90,4 +95,36 @@ public void makeSearchMenuVisible(final Menu menu, final MenuItem searchItem, bo
}
}
}

protected <T extends Fragment> T initFragment(@IdRes int target,
@NonNull T fragment)
{
return initFragment(target, fragment, null);
}

protected <T extends Fragment> T initFragment(@IdRes int target,
@NonNull T fragment,
@Nullable Locale locale)
{
return initFragment(target, fragment, locale, null);
}

protected <T extends Fragment> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")");
Expand Down Expand Up @@ -48,36 +39,4 @@ protected final void onCreate(Bundle savedInstanceState) {

protected void onPreCreate() {}
protected void onCreate(Bundle savedInstanceState, boolean ready) {}

protected <T extends Fragment> T initFragment(@IdRes int target,
@NonNull T fragment)
{
return initFragment(target, fragment, null);
}

protected <T extends Fragment> T initFragment(@IdRes int target,
@NonNull T fragment,
@Nullable Locale locale)
{
return initFragment(target, fragment, locale, null);
}

protected <T extends Fragment> 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;
}
}
22 changes: 0 additions & 22 deletions src/org/thoughtcrime/securesms/qr/BackupTransferActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -221,19 +214,4 @@ public void appendSSID(final TextView textView) {
}).start();
}
}

protected <T extends Fragment> 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;
}
}

0 comments on commit de940dd

Please sign in to comment.