Merge pull request #2533 from AntennaPod/remove_preference_activity_gingerbread
Remove PreferenceActivityGingerbread
This commit is contained in:
commit
0614b53400
|
@ -15,6 +15,7 @@ import java.util.List;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.activity.OnlineFeedViewActivity;
|
||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||
import de.danoeh.antennapod.core.feed.Feed;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
|
@ -22,7 +23,6 @@ import de.danoeh.antennapod.fragment.DownloadsFragment;
|
|||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.preferences.PreferenceController;
|
||||
|
||||
/**
|
||||
* User interface tests for MainActivity
|
||||
|
@ -155,7 +155,7 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv
|
|||
public void testGoToPreferences() {
|
||||
openNavDrawer();
|
||||
solo.clickOnText(solo.getString(R.string.settings_label));
|
||||
solo.waitForActivity(PreferenceController.getPreferenceActivity());
|
||||
solo.waitForActivity(PreferenceActivity.class);
|
||||
}
|
||||
|
||||
public void testDrawerPreferencesHideSomeElements() {
|
||||
|
|
|
@ -96,15 +96,6 @@
|
|||
android:name=".activity.DownloadAuthenticationActivity"
|
||||
android:launchMode="singleInstance"/>
|
||||
|
||||
<activity
|
||||
android:name=".activity.PreferenceActivityGingerbread"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:label="@string/settings_label">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="de.danoeh.antennapod.activity.MainActivity"/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.PreferenceActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
|
|
|
@ -18,7 +18,6 @@ import de.danoeh.antennapod.BuildConfig;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.util.flattr.FlattrUtils;
|
||||
import de.danoeh.antennapod.preferences.PreferenceController;
|
||||
|
||||
/** Guides the user through the authentication process */
|
||||
|
||||
|
@ -104,7 +103,7 @@ public class FlattrAuthActivity extends ActionBarActivity {
|
|||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
if (authSuccessful) {
|
||||
Intent intent = new Intent(this, PreferenceController.getPreferenceActivity());
|
||||
Intent intent = new Intent(this, PreferenceActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
|
|
|
@ -64,7 +64,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
|||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.fragment.SubscriptionFragment;
|
||||
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
||||
import de.danoeh.antennapod.preferences.PreferenceController;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
|
@ -173,7 +172,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
|
|||
|
||||
findViewById(R.id.nav_settings).setOnClickListener(v -> {
|
||||
drawerLayout.closeDrawer(navDrawer);
|
||||
startActivity(new Intent(MainActivity.this, PreferenceController.getPreferenceActivity()));
|
||||
startActivity(new Intent(MainActivity.this, PreferenceActivity.class));
|
||||
});
|
||||
|
||||
FragmentTransaction transaction = fm.beginTransaction();
|
||||
|
|
|
@ -61,7 +61,6 @@ import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
|||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.fragment.SubscriptionFragment;
|
||||
import de.danoeh.antennapod.menuhandler.NavDrawerActivity;
|
||||
import de.danoeh.antennapod.preferences.PreferenceController;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import rx.Observable;
|
||||
import rx.Subscription;
|
||||
|
@ -270,7 +269,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
|
|||
|
||||
findViewById(R.id.nav_settings).setOnClickListener(v -> {
|
||||
drawerLayout.closeDrawer(navDrawer);
|
||||
startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceController.getPreferenceActivity()));
|
||||
startActivity(new Intent(MediaplayerInfoActivity.this, PreferenceActivity.class));
|
||||
});
|
||||
|
||||
butPlaybackSpeed = (Button) findViewById(R.id.butPlaybackSpeed);
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
@ -30,7 +28,6 @@ public class PreferenceActivity extends AppCompatActivity {
|
|||
private PreferenceController preferenceController;
|
||||
private MainFragment prefFragment;
|
||||
private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() {
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
public Preference findPreference(CharSequence key) {
|
||||
return prefFragment.findPreference(key);
|
||||
|
@ -42,7 +39,6 @@ public class PreferenceActivity extends AppCompatActivity {
|
|||
}
|
||||
};
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// This must be the FIRST thing we do, otherwise other code may not have the
|
||||
|
@ -95,7 +91,6 @@ public class PreferenceActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public static class MainFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
package de.danoeh.antennapod.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.preferences.PreferenceController;
|
||||
|
||||
/**
|
||||
* PreferenceActivity for API 10. In order to change the behavior of the preference UI, see
|
||||
* PreferenceController.
|
||||
*/
|
||||
public class PreferenceActivityGingerbread extends android.preference.PreferenceActivity {
|
||||
private static final String TAG = "PreferenceActivity";
|
||||
private final PreferenceController.PreferenceUI preferenceUI = new PreferenceController.PreferenceUI() {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Preference findPreference(CharSequence key) {
|
||||
return PreferenceActivityGingerbread.this.findPreference(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return PreferenceActivityGingerbread.this;
|
||||
}
|
||||
};
|
||||
private PreferenceController preferenceController;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
setTheme(UserPreferences.getTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
preferenceController = new PreferenceController(preferenceUI);
|
||||
preferenceController.onCreate();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
preferenceController.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
preferenceController.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
preferenceController.onStop();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onApplyThemeResource(Theme theme, int resid, boolean first) {
|
||||
theme.applyStyle(UserPreferences.getTheme(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
preferenceController.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
|
||||
Preference preference) {
|
||||
super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
if (preference != null)
|
||||
if (preference instanceof PreferenceScreen)
|
||||
if (((PreferenceScreen) preference).getDialog() != null)
|
||||
((PreferenceScreen) preference)
|
||||
.getDialog()
|
||||
.getWindow()
|
||||
.getDecorView()
|
||||
.setBackgroundDrawable(
|
||||
this.getWindow().getDecorView()
|
||||
.getBackground().getConstantState()
|
||||
.newDrawable()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -56,8 +56,6 @@ import de.danoeh.antennapod.activity.AboutActivity;
|
|||
import de.danoeh.antennapod.activity.DirectoryChooserActivity;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.activity.MediaplayerActivity;
|
||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||
import de.danoeh.antennapod.activity.PreferenceActivityGingerbread;
|
||||
import de.danoeh.antennapod.activity.StatisticsActivity;
|
||||
import de.danoeh.antennapod.asynctask.ExportWorker;
|
||||
import de.danoeh.antennapod.core.export.ExportWriter;
|
||||
|
@ -97,8 +95,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
|||
private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";
|
||||
private static final String AUTO_DL_PREF_SCREEN = "prefAutoDownloadSettings";
|
||||
private static final String PREF_PLAYBACK_SPEED_LAUNCHER = "prefPlaybackSpeedLauncher";
|
||||
public static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher";
|
||||
public static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher";
|
||||
private static final String PREF_PLAYBACK_REWIND_DELTA_LAUNCHER = "prefPlaybackRewindDeltaLauncher";
|
||||
private static final String PREF_PLAYBACK_FAST_FORWARD_DELTA_LAUNCHER = "prefPlaybackFastForwardDeltaLauncher";
|
||||
private static final String PREF_GPODNET_LOGIN = "pref_gpodnet_authenticate";
|
||||
private static final String PREF_GPODNET_SETLOGIN_INFORMATION = "pref_gpodnet_setlogin_information";
|
||||
private static final String PREF_GPODNET_SYNC = "pref_gpodnet_sync";
|
||||
|
@ -132,19 +130,6 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
|||
.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preference activity that should be used on this device.
|
||||
*
|
||||
* @return PreferenceActivity if the API level is greater than 10, PreferenceActivityGingerbread otherwise.
|
||||
*/
|
||||
public static Class<? extends Activity> getPreferenceActivity() {
|
||||
if (Build.VERSION.SDK_INT > 10) {
|
||||
return PreferenceActivity.class;
|
||||
} else {
|
||||
return PreferenceActivityGingerbread.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if(key.equals(UserPreferences.PREF_SONIC)) {
|
||||
|
@ -230,12 +215,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
|||
.setOnPreferenceChangeListener(
|
||||
(preference, newValue) -> {
|
||||
Intent i = new Intent(activity, MainActivity.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
| Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
} else {
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
}
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
| Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.finish();
|
||||
activity.startActivity(i);
|
||||
return true;
|
||||
|
@ -513,7 +494,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
|||
alert.setTitle(R.string.export_error_label);
|
||||
alert.setMessage(error.getMessage());
|
||||
alert.show();
|
||||
}, () -> progressDialog.dismiss());
|
||||
}, progressDialog::dismiss);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -786,61 +767,56 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
|
|||
WifiManager wifiservice = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
|
||||
|
||||
if (networks != null) {
|
||||
Collections.sort(networks, new Comparator<WifiConfiguration>() {
|
||||
@Override
|
||||
public int compare(WifiConfiguration x, WifiConfiguration y) {
|
||||
return x.SSID.compareTo(y.SSID);
|
||||
}
|
||||
});
|
||||
selectedNetworks = new CheckBoxPreference[networks.size()];
|
||||
List<String> prefValues = Arrays.asList(UserPreferences
|
||||
.getAutodownloadSelectedNetworks());
|
||||
PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN);
|
||||
Preference.OnPreferenceClickListener clickListener = preference -> {
|
||||
if (preference instanceof CheckBoxPreference) {
|
||||
String key = preference.getKey();
|
||||
List<String> prefValuesList = new ArrayList<>(
|
||||
Arrays.asList(UserPreferences
|
||||
.getAutodownloadSelectedNetworks())
|
||||
);
|
||||
boolean newValue = ((CheckBoxPreference) preference)
|
||||
.isChecked();
|
||||
Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
|
||||
|
||||
int index = prefValuesList.indexOf(key);
|
||||
if (index >= 0 && !newValue) {
|
||||
// remove network
|
||||
prefValuesList.remove(index);
|
||||
} else if (index < 0 && newValue) {
|
||||
prefValuesList.add(key);
|
||||
}
|
||||
|
||||
UserPreferences.setAutodownloadSelectedNetworks(
|
||||
prefValuesList.toArray(new String[prefValuesList.size()])
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
// create preference for each known network. attach listener and set
|
||||
// value
|
||||
for (int i = 0; i < networks.size(); i++) {
|
||||
WifiConfiguration config = networks.get(i);
|
||||
|
||||
CheckBoxPreference pref = new CheckBoxPreference(activity);
|
||||
String key = Integer.toString(config.networkId);
|
||||
pref.setTitle(config.SSID);
|
||||
pref.setKey(key);
|
||||
pref.setOnPreferenceClickListener(clickListener);
|
||||
pref.setPersistent(false);
|
||||
pref.setChecked(prefValues.contains(key));
|
||||
selectedNetworks[i] = pref;
|
||||
prefScreen.addPreference(pref);
|
||||
}
|
||||
} else {
|
||||
if (networks == null) {
|
||||
Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
|
||||
return;
|
||||
}
|
||||
Collections.sort(networks, (x, y) -> x.SSID.compareTo(y.SSID));
|
||||
selectedNetworks = new CheckBoxPreference[networks.size()];
|
||||
List<String> prefValues = Arrays.asList(UserPreferences
|
||||
.getAutodownloadSelectedNetworks());
|
||||
PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN);
|
||||
Preference.OnPreferenceClickListener clickListener = preference -> {
|
||||
if (preference instanceof CheckBoxPreference) {
|
||||
String key = preference.getKey();
|
||||
List<String> prefValuesList = new ArrayList<>(
|
||||
Arrays.asList(UserPreferences
|
||||
.getAutodownloadSelectedNetworks())
|
||||
);
|
||||
boolean newValue = ((CheckBoxPreference) preference)
|
||||
.isChecked();
|
||||
Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
|
||||
|
||||
int index = prefValuesList.indexOf(key);
|
||||
if (index >= 0 && !newValue) {
|
||||
// remove network
|
||||
prefValuesList.remove(index);
|
||||
} else if (index < 0 && newValue) {
|
||||
prefValuesList.add(key);
|
||||
}
|
||||
|
||||
UserPreferences.setAutodownloadSelectedNetworks(
|
||||
prefValuesList.toArray(new String[prefValuesList.size()])
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
// create preference for each known network. attach listener and set
|
||||
// value
|
||||
for (int i = 0; i < networks.size(); i++) {
|
||||
WifiConfiguration config = networks.get(i);
|
||||
|
||||
CheckBoxPreference pref = new CheckBoxPreference(activity);
|
||||
String key = Integer.toString(config.networkId);
|
||||
pref.setTitle(config.SSID);
|
||||
pref.setKey(key);
|
||||
pref.setOnPreferenceClickListener(clickListener);
|
||||
pref.setPersistent(false);
|
||||
pref.setChecked(prefValues.contains(key));
|
||||
selectedNetworks[i] = pref;
|
||||
prefScreen.addPreference(pref);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue