Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 57 | protected void onCreate(Bundle savedInstanceState) { | |||
---|---|---|---|---|---|
60 | ThemeUtil.setUserPreferredTheme(this); | 60 | ThemeUtil.setUserPreferredTheme(this); | ||
61 | setContentView(R.layout.custom_ip_list); | 61 | setContentView(R.layout.custom_ip_list); | ||
62 | 62 | | |||
63 | list = (ListView) findViewById(android.R.id.list); | 63 | list = (ListView) findViewById(android.R.id.list); | ||
64 | list.setOnItemClickListener(onClickListener); | 64 | list.setOnItemClickListener(onClickListener); | ||
65 | 65 | | |||
66 | list.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList)); | 66 | list.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList)); | ||
67 | 67 | | |||
68 | findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() { | 68 | findViewById(android.R.id.button1).setOnClickListener(v -> addNewDevice()); | ||
69 | @Override | | |||
70 | public void onClick(View v) { | | |||
71 | addNewDevice(); | | |||
72 | } | | |||
73 | }); | | |||
74 | 69 | | |||
75 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | 70 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | ||
76 | ipEntryBox.setOnEditorActionListener(new TextView.OnEditorActionListener() { | 71 | ipEntryBox.setOnEditorActionListener((v, actionId, event) -> { | ||
77 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { | | |||
78 | if (actionId == EditorInfo.IME_ACTION_SEND) { | 72 | if (actionId == EditorInfo.IME_ACTION_SEND) { | ||
79 | addNewDevice(); | 73 | addNewDevice(); | ||
80 | return true; | 74 | return true; | ||
81 | } | 75 | } | ||
82 | return false; | 76 | return false; | ||
83 | } | | |||
84 | }); | 77 | }); | ||
85 | } | 78 | } | ||
86 | 79 | | |||
87 | boolean dialogAlreadyShown = false; | 80 | boolean dialogAlreadyShown = false; | ||
88 | private AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() { | 81 | private AdapterView.OnItemClickListener onClickListener = (parent, view, position, id) -> { | ||
89 | @Override | | |||
90 | public void onItemClick(AdapterView<?> parent, View view, final int position, final long id) { | | |||
91 | 82 | | |||
92 | if (dialogAlreadyShown) { | 83 | if (dialogAlreadyShown) { | ||
93 | return; | 84 | return; | ||
94 | } | 85 | } | ||
95 | 86 | | |||
96 | // remove touched item after confirmation | 87 | // remove touched item after confirmation | ||
97 | DialogInterface.OnClickListener confirmationListener = new DialogInterface.OnClickListener() { | 88 | DialogInterface.OnClickListener confirmationListener = (dialog, which) -> { | ||
98 | @Override | | |||
99 | public void onClick(DialogInterface dialog, int which) { | | |||
100 | switch (which) { | 89 | switch (which) { | ||
101 | case DialogInterface.BUTTON_POSITIVE: | 90 | case DialogInterface.BUTTON_POSITIVE: | ||
102 | ipAddressList.remove(position); | 91 | ipAddressList.remove(position); | ||
103 | saveList(); | 92 | saveList(); | ||
104 | break; | 93 | break; | ||
105 | case DialogInterface.BUTTON_NEGATIVE: | 94 | case DialogInterface.BUTTON_NEGATIVE: | ||
106 | break; | 95 | break; | ||
107 | } | 96 | } | ||
108 | } | | |||
109 | }; | 97 | }; | ||
110 | 98 | | |||
111 | AlertDialog.Builder builder = new AlertDialog.Builder(CustomDevicesActivity.this); | 99 | AlertDialog.Builder builder = new AlertDialog.Builder(CustomDevicesActivity.this); | ||
112 | builder.setMessage("Delete " + ipAddressList.get(position) + " ?"); | 100 | builder.setMessage("Delete " + ipAddressList.get(position) + " ?"); | ||
113 | builder.setPositiveButton("Yes", confirmationListener); | 101 | builder.setPositiveButton("Yes", confirmationListener); | ||
114 | builder.setNegativeButton("No", confirmationListener); | 102 | builder.setNegativeButton("No", confirmationListener); | ||
115 | 103 | | |||
116 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //DismissListener | 104 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //DismissListener | ||
117 | dialogAlreadyShown = true; | 105 | dialogAlreadyShown = true; | ||
118 | builder.setOnDismissListener(new DialogInterface.OnDismissListener() { | 106 | builder.setOnDismissListener(dialog -> dialogAlreadyShown = false); | ||
119 | @Override | | |||
120 | public void onDismiss(DialogInterface dialog) { | | |||
121 | dialogAlreadyShown = false; | | |||
122 | } | | |||
123 | }); | | |||
124 | } | 107 | } | ||
125 | 108 | | |||
126 | builder.show(); | 109 | builder.show(); | ||
127 | } | | |||
128 | }; | 110 | }; | ||
129 | 111 | | |||
130 | private void addNewDevice() { | 112 | private void addNewDevice() { | ||
131 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | 113 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | ||
132 | String enteredText = ipEntryBox.getText().toString().trim(); | 114 | String enteredText = ipEntryBox.getText().toString().trim(); | ||
133 | if (!enteredText.isEmpty()) { | 115 | if (!enteredText.isEmpty()) { | ||
134 | // don't add empty string (after trimming) | 116 | // don't add empty string (after trimming) | ||
135 | ipAddressList.add(enteredText); | 117 | ipAddressList.add(enteredText); | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |