Differential D18212 Diff 53433 src/org/kde/kdeconnect/UserInterface/DeviceSettingsAlertDialogFragment.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/UserInterface/DeviceSettingsAlertDialogFragment.java
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Erik Duisters <e.duisters1@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | package org.kde.kdeconnect.UserInterface; | ||||
22 | | ||||
23 | import android.content.Intent; | ||||
24 | import android.os.Bundle; | ||||
25 | | ||||
26 | import androidx.annotation.NonNull; | ||||
27 | import androidx.annotation.Nullable; | ||||
28 | | ||||
29 | public class DeviceSettingsAlertDialogFragment extends AlertDialogFragment { | ||||
30 | private static final String KEY_PLUGIN_KEY = "PluginKey"; | ||||
31 | private static final String KEY_DEVICE_ID = "DeviceId"; | ||||
32 | | ||||
33 | private String pluginKey; | ||||
34 | private String deviceId; | ||||
35 | | ||||
36 | public DeviceSettingsAlertDialogFragment() {} | ||||
37 | | ||||
38 | @Override | ||||
39 | public void onCreate(@Nullable Bundle savedInstanceState) { | ||||
40 | super.onCreate(savedInstanceState); | ||||
41 | | ||||
42 | Bundle args = getArguments(); | ||||
43 | | ||||
44 | if (args == null || !args.containsKey(KEY_PLUGIN_KEY)) { | ||||
45 | throw new RuntimeException("You must call Builder.setPluginKey() to set the plugin"); | ||||
46 | } | ||||
47 | if (!args.containsKey(KEY_DEVICE_ID)) { | ||||
48 | throw new RuntimeException("You must call Builder.setDeviceId() to set the device"); | ||||
49 | } | ||||
50 | | ||||
51 | pluginKey = args.getString(KEY_PLUGIN_KEY); | ||||
52 | deviceId = args.getString(KEY_DEVICE_ID); | ||||
53 | | ||||
54 | setCallback(new Callback() { | ||||
55 | @Override | ||||
56 | public void onPositiveButtonClicked() { | ||||
57 | Intent intent = new Intent(requireActivity(), DeviceSettingsActivity.class); | ||||
58 | | ||||
59 | intent.putExtra(DeviceSettingsActivity.EXTRA_DEVICE_ID, deviceId); | ||||
60 | intent.putExtra(DeviceSettingsActivity.EXTRA_PLUGIN_KEY, pluginKey); | ||||
61 | requireActivity().startActivity(intent); | ||||
62 | } | ||||
63 | }); | ||||
64 | } | ||||
65 | | ||||
66 | public static class Builder extends AbstractBuilder<DeviceSettingsAlertDialogFragment.Builder, DeviceSettingsAlertDialogFragment> { | ||||
67 | @Override | ||||
68 | public DeviceSettingsAlertDialogFragment.Builder getThis() { | ||||
69 | return this; | ||||
70 | } | ||||
71 | | ||||
72 | public DeviceSettingsAlertDialogFragment.Builder setPluginKey(String pluginKey) { | ||||
73 | args.putString(KEY_PLUGIN_KEY, pluginKey); | ||||
74 | return getThis(); | ||||
75 | } | ||||
76 | | ||||
77 | public DeviceSettingsAlertDialogFragment.Builder setDeviceId(String deviceId) { | ||||
78 | args.putString(KEY_DEVICE_ID, deviceId); | ||||
79 | return getThis(); | ||||
80 | } | ||||
81 | | ||||
82 | @Override | ||||
83 | protected DeviceSettingsAlertDialogFragment createFragment() { | ||||
84 | return new DeviceSettingsAlertDialogFragment(); | ||||
85 | } | ||||
86 | } | ||||
87 | } |