2014-11-16 23:14:06 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Albert Vaca Cintora <albertvaka@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-03-08 13:44:54 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-11-16 23:14:06 -08:00
|
|
|
|
2013-09-05 01:37:59 +02:00
|
|
|
package org.kde.kdeconnect.UserInterface;
|
2013-09-03 17:58:59 +02:00
|
|
|
|
|
|
|
import android.os.Bundle;
|
2015-06-13 23:42:07 -07:00
|
|
|
import android.view.MenuItem;
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2013-09-05 01:37:59 +02:00
|
|
|
import org.kde.kdeconnect.BackgroundService;
|
|
|
|
import org.kde.kdeconnect.Device;
|
2019-01-06 12:26:05 +01:00
|
|
|
import org.kde.kdeconnect.Plugins.Plugin;
|
|
|
|
import org.kde.kdeconnect_tp.R;
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2019-01-06 12:26:05 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2019-01-06 12:26:05 +01:00
|
|
|
public class DeviceSettingsActivity
|
|
|
|
extends AppCompatActivity
|
|
|
|
implements PluginPreference.PluginPreferenceCallback {
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2019-01-06 12:26:05 +01:00
|
|
|
public static final String EXTRA_DEVICE_ID = "deviceId";
|
|
|
|
public static final String EXTRA_PLUGIN_KEY = "pluginKey";
|
|
|
|
|
|
|
|
//TODO: Save/restore state
|
2014-10-20 01:13:41 -07:00
|
|
|
static private String deviceId; //Static because if we get here by using the back button in the action bar, the extra deviceId will not be set.
|
|
|
|
|
2013-09-03 17:58:59 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2019-01-06 12:26:05 +01:00
|
|
|
ThemeUtil.setUserPreferredTheme(this);
|
2013-09-03 17:58:59 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2015-06-13 23:42:07 -07:00
|
|
|
|
2019-01-06 12:26:05 +01:00
|
|
|
setContentView(R.layout.activity_device_settings);
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2019-01-06 12:26:05 +01:00
|
|
|
if (getSupportActionBar() != null) {
|
|
|
|
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
|
2014-10-20 01:13:41 -07:00
|
|
|
}
|
|
|
|
|
2019-01-06 12:26:05 +01:00
|
|
|
String pluginKey = null;
|
|
|
|
|
|
|
|
if (getIntent().hasExtra(EXTRA_DEVICE_ID)) {
|
|
|
|
deviceId = getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
|
|
|
|
|
|
|
if (getIntent().hasExtra(EXTRA_PLUGIN_KEY)) {
|
|
|
|
pluginKey = getIntent().getStringExtra(EXTRA_PLUGIN_KEY);
|
2018-05-09 14:02:56 +02:00
|
|
|
}
|
2019-01-06 12:26:05 +01:00
|
|
|
} else if (deviceId == null) {
|
|
|
|
throw new RuntimeException("You must start DeviceSettingActivity using an intent that has a " + EXTRA_DEVICE_ID + " extra");
|
|
|
|
}
|
|
|
|
|
|
|
|
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentPlaceHolder);
|
|
|
|
if (fragment == null) {
|
|
|
|
if (pluginKey == null) {
|
|
|
|
fragment = DeviceSettingsFragment.newInstance(deviceId);
|
|
|
|
} else {
|
|
|
|
Device device = BackgroundService.getInstance().getDevice(deviceId);
|
2019-02-12 13:10:22 +01:00
|
|
|
Plugin plugin = device.getPlugin(pluginKey);
|
2019-02-22 20:08:21 +01:00
|
|
|
fragment = plugin.getSettingsFragment(this);
|
2013-09-03 17:58:59 +02:00
|
|
|
}
|
2019-01-06 12:26:05 +01:00
|
|
|
|
|
|
|
getSupportFragmentManager()
|
|
|
|
.beginTransaction()
|
|
|
|
.add(R.id.fragmentPlaceHolder, fragment)
|
|
|
|
.commit();
|
|
|
|
}
|
2015-06-13 23:42:07 -07:00
|
|
|
}
|
2013-09-03 17:58:59 +02:00
|
|
|
|
2015-06-13 23:42:07 -07:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
if (item.getItemId() == android.R.id.home) {
|
2019-01-06 12:26:05 +01:00
|
|
|
FragmentManager fm = getSupportFragmentManager();
|
|
|
|
|
|
|
|
if (fm.getBackStackEntryCount() > 0) {
|
|
|
|
fm.popBackStack();
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-13 23:42:07 -07:00
|
|
|
}
|
2019-01-06 12:26:05 +01:00
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
2013-09-03 17:58:59 +02:00
|
|
|
}
|
2015-09-09 12:34:42 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
BackgroundService.addGuiInUseCounter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
BackgroundService.removeGuiInUseCounter(this);
|
|
|
|
}
|
|
|
|
|
2019-01-06 12:26:05 +01:00
|
|
|
@Override
|
|
|
|
public void onStartPluginSettingsFragment(Plugin plugin) {
|
|
|
|
setTitle(getString(R.string.plugin_settings_with_name, plugin.getDisplayName()));
|
|
|
|
|
2019-02-22 20:08:21 +01:00
|
|
|
PluginSettingsFragment fragment = plugin.getSettingsFragment(this);
|
2019-01-06 12:26:05 +01:00
|
|
|
|
|
|
|
//TODO: Remove when NotificationFilterActivity has been turned into a PluginSettingsFragment
|
|
|
|
if (fragment == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
getSupportFragmentManager()
|
|
|
|
.beginTransaction()
|
|
|
|
.replace(R.id.fragmentPlaceHolder, fragment)
|
|
|
|
.addToBackStack(null)
|
|
|
|
.commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFinish() {
|
|
|
|
finish();
|
|
|
|
}
|
2019-03-08 13:44:54 +01:00
|
|
|
|
|
|
|
public String getDeviceId() {
|
|
|
|
return deviceId;
|
|
|
|
}
|
2014-11-16 23:14:06 -08:00
|
|
|
}
|