File indexing completed on 2024-12-22 04:41:42

0001 /*
0002  * SPDX-FileCopyrightText: 2019 Erik Duisters <e.duisters1@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 package org.kde.kdeconnect.UserInterface;
0008 
0009 import android.content.Intent;
0010 import android.os.Bundle;
0011 
0012 import androidx.annotation.Nullable;
0013 
0014 public class DeviceSettingsAlertDialogFragment extends AlertDialogFragment {
0015     private static final String KEY_PLUGIN_KEY = "PluginKey";
0016     private static final String KEY_DEVICE_ID = "DeviceId";
0017 
0018     private String pluginKey;
0019     private String deviceId;
0020 
0021     public DeviceSettingsAlertDialogFragment() {}
0022 
0023     @Override
0024     public void onCreate(@Nullable Bundle savedInstanceState) {
0025         super.onCreate(savedInstanceState);
0026 
0027         Bundle args = getArguments();
0028 
0029         if (args == null || !args.containsKey(KEY_PLUGIN_KEY)) {
0030             throw new RuntimeException("You must call Builder.setPluginKey() to set the plugin");
0031         }
0032         if (!args.containsKey(KEY_DEVICE_ID)) {
0033             throw new RuntimeException("You must call Builder.setDeviceId() to set the device");
0034         }
0035 
0036         pluginKey = args.getString(KEY_PLUGIN_KEY);
0037         deviceId = args.getString(KEY_DEVICE_ID);
0038 
0039         setCallback(new Callback() {
0040             @Override
0041             public void onPositiveButtonClicked() {
0042                 Intent intent = new Intent(requireActivity(), PluginSettingsActivity.class);
0043 
0044                 intent.putExtra(PluginSettingsActivity.EXTRA_DEVICE_ID, deviceId);
0045                 intent.putExtra(PluginSettingsActivity.EXTRA_PLUGIN_KEY, pluginKey);
0046                 requireActivity().startActivity(intent);
0047             }
0048         });
0049     }
0050 
0051     public static class Builder extends AbstractBuilder<DeviceSettingsAlertDialogFragment.Builder, DeviceSettingsAlertDialogFragment> {
0052         @Override
0053         public DeviceSettingsAlertDialogFragment.Builder getThis() {
0054             return this;
0055         }
0056 
0057         public DeviceSettingsAlertDialogFragment.Builder setPluginKey(String pluginKey) {
0058             args.putString(KEY_PLUGIN_KEY, pluginKey);
0059             return getThis();
0060         }
0061 
0062         public DeviceSettingsAlertDialogFragment.Builder setDeviceId(String deviceId) {
0063             args.putString(KEY_DEVICE_ID, deviceId);
0064             return getThis();
0065         }
0066 
0067         @Override
0068         protected DeviceSettingsAlertDialogFragment createFragment() {
0069             return new DeviceSettingsAlertDialogFragment();
0070         }
0071     }
0072 }