2018-12-31 18:07:36 +01:00
|
|
|
/*
|
2020-11-28 22:36:47 +01:00
|
|
|
* Copyright (C) 2020 Stefan Schüller <sschueller@techdroid.com>
|
2018-12-31 18:07:36 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2020-11-28 22:36:47 +01:00
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-12-31 18:07:36 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2020-11-28 22:36:47 +01:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-12-31 18:07:36 +01:00
|
|
|
*
|
2020-11-28 22:36:47 +01:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-12-31 18:07:36 +01:00
|
|
|
*/
|
2018-03-11 14:51:39 +01:00
|
|
|
package net.schueller.peertube.activity;
|
|
|
|
|
2020-11-22 13:54:54 +01:00
|
|
|
import android.content.SharedPreferences;
|
2018-03-11 14:51:39 +01:00
|
|
|
import android.os.Bundle;
|
2020-11-22 13:54:54 +01:00
|
|
|
import android.preference.PreferenceManager;
|
2019-03-03 00:48:33 +01:00
|
|
|
|
2020-11-22 13:54:54 +01:00
|
|
|
import android.util.Log;
|
2018-12-24 11:42:25 +01:00
|
|
|
import androidx.appcompat.app.ActionBar;
|
2020-11-22 13:54:54 +01:00
|
|
|
import androidx.appcompat.app.AlertDialog.Builder;
|
2020-06-27 23:28:52 +02:00
|
|
|
import androidx.appcompat.widget.Toolbar;
|
2020-07-08 12:31:30 +02:00
|
|
|
import androidx.preference.Preference;
|
2020-06-27 23:28:52 +02:00
|
|
|
import androidx.preference.PreferenceFragmentCompat;
|
2018-12-18 21:07:03 +01:00
|
|
|
|
2020-11-22 13:54:54 +01:00
|
|
|
import androidx.preference.SwitchPreference;
|
2020-07-08 12:31:30 +02:00
|
|
|
import net.schueller.peertube.BuildConfig;
|
2018-03-11 14:51:39 +01:00
|
|
|
import net.schueller.peertube.R;
|
2019-03-03 00:48:33 +01:00
|
|
|
|
2020-06-27 23:28:52 +02:00
|
|
|
public class SettingsActivity extends CommonActivity {
|
2018-03-11 14:51:39 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2018-12-24 11:42:25 +01:00
|
|
|
|
2020-06-27 23:28:52 +02:00
|
|
|
setContentView(R.layout.activity_settings);
|
|
|
|
getSupportFragmentManager()
|
|
|
|
.beginTransaction()
|
|
|
|
.replace(R.id.settings, new SettingsFragment())
|
|
|
|
.commit();
|
2020-07-04 17:26:01 +02:00
|
|
|
|
|
|
|
// Attaching the layout to the toolbar object
|
|
|
|
Toolbar toolbar = findViewById(R.id.tool_bar_settings);
|
|
|
|
// Setting toolbar as the ActionBar with setSupportActionBar() call
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
|
2018-03-11 14:51:39 +01:00
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
|
|
if (actionBar != null) {
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
2020-07-04 17:26:01 +02:00
|
|
|
actionBar.setHomeAsUpIndicator(R.drawable.ic_baseline_close_24);
|
2018-03-11 14:51:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-04 17:26:01 +02:00
|
|
|
@Override
|
|
|
|
public boolean onSupportNavigateUp() {
|
|
|
|
finish(); // close this activity as oppose to navigating up
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-27 23:28:52 +02:00
|
|
|
public static class SettingsFragment extends PreferenceFragmentCompat {
|
2018-03-11 14:51:39 +01:00
|
|
|
@Override
|
2020-06-27 23:28:52 +02:00
|
|
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
|
|
|
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
2020-07-08 12:31:30 +02:00
|
|
|
|
|
|
|
// write Build Time into pref
|
|
|
|
Preference pref = findPreference("pref_buildtime");
|
|
|
|
assert pref != null;
|
|
|
|
pref.setSummary(Long.toString(BuildConfig.BUILD_TIME));
|
|
|
|
|
2020-11-22 13:54:54 +01:00
|
|
|
// double check disabling SSL
|
|
|
|
final SwitchPreference insecure = (SwitchPreference) findPreference("pref_accept_insecure");
|
|
|
|
if (insecure != null) {
|
|
|
|
insecure.setOnPreferenceChangeListener((preference, newValue) -> {
|
|
|
|
|
|
|
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
SharedPreferences.Editor editor = sharedPref.edit();
|
|
|
|
|
|
|
|
boolean currentValue = sharedPref.getBoolean("pref_accept_insecure", false);
|
|
|
|
|
|
|
|
if (newValue instanceof Boolean && ((Boolean) newValue) != currentValue) {
|
|
|
|
final boolean enable = (Boolean) newValue;
|
|
|
|
|
|
|
|
Log.v("pref", "enable: " + enable);
|
|
|
|
Log.v("pref", "currentValue: " + currentValue);
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
new Builder(preference.getContext())
|
|
|
|
.setTitle(R.string.pref_insecure_confirm_title)
|
|
|
|
.setMessage(R.string.pref_insecure_confirm_message)
|
|
|
|
.setIcon(R.drawable.ic_info_black_24dp)
|
|
|
|
.setNegativeButton(R.string.pref_insecure_confirm_no, (dialog, whichButton) -> {
|
|
|
|
// do nothing
|
|
|
|
})
|
|
|
|
.setPositiveButton(R.string.pref_insecure_confirm_yes, (dialog, whichButton) -> {
|
|
|
|
// OK has been pressed => force the new value and update the checkbox display
|
|
|
|
editor.putBoolean("pref_accept_insecure", true);
|
|
|
|
editor.apply();
|
|
|
|
insecure.setChecked(true);
|
|
|
|
}).create().show();
|
|
|
|
// by default ignore the pref change, which can only be validated when OK is pressed
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2019-03-03 01:03:32 +01:00
|
|
|
}
|
2018-03-11 14:51:39 +01:00
|
|
|
}
|
|
|
|
}
|