Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup base activities #2508

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,54 +39,4 @@ protected final void onCreate(Bundle savedInstanceState) {

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

@Override
protected void onResume() {
Log.i(TAG, "onResume()");
super.onResume();
}

@Override
protected void onPause() {
Log.i(TAG, "onPause()");
super.onPause();
}

@Override
protected void onDestroy() {
Log.i(TAG, "onDestroy()");
super.onDestroy();
}

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;
}
}