Prefer AppCompat classes
AppCompat is the preferred way to go for any app targetting a wider range of SDKs. Replace all activities and fragments with their AppCompat variants and fixup method calls to use support variants. Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.wireguard.android.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.databinding.CallbackRegistry;
|
||||
import android.databinding.CallbackRegistry.NotifierCallback;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.backend.GoBackend;
|
||||
@@ -17,7 +17,7 @@ import java.util.Objects;
|
||||
* Base class for activities that need to remember the currently-selected tunnel.
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity extends Activity {
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
private static final String KEY_SELECTED_TUNNEL = "selected_tunnel";
|
||||
|
||||
private final SelectionChangeRegistry selectionChangeRegistry = new SelectionChangeRegistry();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.wireguard.android.activity;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -28,6 +29,7 @@ public class MainActivity extends BaseActivity {
|
||||
private State state = State.EMPTY;
|
||||
|
||||
private boolean moveToState(final State nextState) {
|
||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
Log.i(TAG, "Moving from " + state.name() + " to " + nextState.name());
|
||||
if (nextState == state) {
|
||||
return false;
|
||||
@@ -37,16 +39,16 @@ public class MainActivity extends BaseActivity {
|
||||
return true;
|
||||
} else if (nextState.layer == state.layer + 1) {
|
||||
final Fragment fragment = Fragment.instantiate(this, nextState.fragment);
|
||||
final FragmentTransaction transaction = getFragmentManager().beginTransaction()
|
||||
final FragmentTransaction transaction = fragmentManager.beginTransaction()
|
||||
.replace(R.id.master_fragment, fragment)
|
||||
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
|
||||
if (state.layer > 0)
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
} else if (nextState.layer == state.layer - 1) {
|
||||
if (getFragmentManager().getBackStackEntryCount() == 0)
|
||||
if (fragmentManager.getBackStackEntryCount() == 0)
|
||||
return false;
|
||||
getFragmentManager().popBackStack();
|
||||
fragmentManager.popBackStack();
|
||||
} else if (nextState.layer < state.layer - 1) {
|
||||
moveToState(State.ofLayer(state.layer - 1));
|
||||
moveToState(nextState);
|
||||
@@ -121,8 +123,8 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void updateActionBar() {
|
||||
if (getActionBar() != null)
|
||||
getActionBar().setDisplayHomeAsUpEnabled(state.layer > State.LIST.layer);
|
||||
if (getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(state.layer > State.LIST.layer);
|
||||
}
|
||||
|
||||
private enum State {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.wireguard.android.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.R;
|
||||
@@ -19,7 +20,7 @@ import java.util.List;
|
||||
* Interface for changing application-global persistent settings.
|
||||
*/
|
||||
|
||||
public class SettingsActivity extends Activity {
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
@FunctionalInterface
|
||||
public interface PermissionRequestCallback {
|
||||
void done(String[] permissions, int[] grantResults);
|
||||
@@ -56,7 +57,7 @@ public class SettingsActivity extends Activity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
final PermissionRequestCallback f = permissionRequestCallbacks.get(requestCode);
|
||||
if (f != null) {
|
||||
permissionRequestCallbacks.remove(requestCode);
|
||||
@@ -67,17 +68,16 @@ public class SettingsActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
|
||||
getFragmentManager().beginTransaction()
|
||||
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragment {
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
public void onCreatePreferences(final Bundle savedInstanceState, final String key) {
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
if (Application.getComponent().getBackendType() != WgQuickBackend.class) {
|
||||
final Preference toolsInstaller =
|
||||
|
||||
@@ -14,8 +14,8 @@ public class TunnelCreatorActivity extends BaseActivity {
|
||||
@SuppressWarnings("UnnecessaryFullyQualifiedName")
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getFragmentManager().findFragmentById(android.R.id.content) == null) {
|
||||
getFragmentManager().beginTransaction()
|
||||
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(android.R.id.content, new TunnelEditorFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user