Skip to content

Commit 1b99466

Browse files
author
David Graeff
committed
Add scene help button and show help for first time when clicked on "+" button. IconThemeDialog in MaterialDesign. Fix for scenes as widgets.
1 parent 1ea9b3e commit 1b99466

File tree

13 files changed

+128
-48
lines changed

13 files changed

+128
-48
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
defaultConfig {
1717
minSdkVersion 17
1818
targetSdkVersion 22
19-
versionCode 117
20-
versionName "7.1"
19+
versionCode 119
20+
versionName "8.0"
2121
applicationId appID
2222
testApplicationId "oly.netpowerctrl.tests"
2323
testInstrumentationRunner "android.test.InstrumentationTestRunner"

app/src/main/java/oly/netpowerctrl/devices/DeviceQuery.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.os.Handler;
44
import android.os.Looper;
55
import android.os.Message;
6+
import android.support.annotation.NonNull;
67
import android.util.Log;
78

89
import java.util.ArrayList;
@@ -134,15 +135,16 @@ private void deviceSuccess(Credentials credentials) {
134135
if (Thread.currentThread() != thread) throw new RuntimeException();
135136
Log.w(TAG, "Response " + credentials.deviceName);
136137
handler.removeMessages(MSG_REQUEST, credentials);
137-
for (DevicesObserver devicesObserver : devicesObserverList) {
138+
for (Iterator<DevicesObserver> iterator = devicesObserverList.iterator(); iterator.hasNext(); ) {
139+
DevicesObserver devicesObserver = iterator.next();
138140
if (!devicesObserver.credentialsList.containsKey(credentials.deviceUID)) continue;
139141
devicesObserver.credentialsList.remove(credentials.deviceUID);
140142
devicesObserver.success.add(credentials);
141-
checkObserverFinished(devicesObserver);
143+
checkObserverFinished(iterator, devicesObserver);
142144
}
143145
}
144146

145-
private void checkObserverFinished(DevicesObserver devicesObserver) {
147+
private void checkObserverFinished(@NonNull Iterator<DevicesObserver> iterator, @NonNull DevicesObserver devicesObserver) {
146148
if (Thread.currentThread() != thread) throw new RuntimeException();
147149
if (!devicesObserver.credentialsList.isEmpty()) return;
148150

@@ -157,25 +159,21 @@ private void checkObserverFinished(DevicesObserver devicesObserver) {
157159
handler.sendMessageDelayed(handler.obtainMessage(MSG_RECHECK_MINIMUM_TIME, devicesObserver), devicesObserver.minimumTimeInMS - runtimeMS);
158160
return;
159161
}
160-
// Finished
161-
for (Iterator<DevicesObserver> iterator = devicesObserverList.iterator(); iterator.hasNext(); ) {
162-
if (iterator.next() == devicesObserver) {
163-
iterator.remove();
164-
mainHandler.sendMessage(mainHandler.obtainMessage(0, devicesObserver));
165-
break;
166-
}
167-
}
162+
163+
iterator.remove();
164+
mainHandler.sendMessage(mainHandler.obtainMessage(0, devicesObserver));
168165
}
169166

170167
private void deviceFailed(Credentials credentials) {
171168
Log.w(TAG, "Query failed " + credentials.getDeviceName());
172169
if (Thread.currentThread() != thread) throw new RuntimeException();
173170
handler.removeMessages(MSG_REQUEST, credentials);
174-
for (DevicesObserver devicesObserver : devicesObserverList) {
171+
for (Iterator<DevicesObserver> iterator = devicesObserverList.iterator(); iterator.hasNext(); ) {
172+
DevicesObserver devicesObserver = iterator.next();
175173
if (!devicesObserver.credentialsList.containsKey(credentials.deviceUID)) continue;
176174
devicesObserver.credentialsList.remove(credentials.deviceUID);
177175
devicesObserver.failed.add(credentials);
178-
checkObserverFinished(devicesObserver);
176+
checkObserverFinished(iterator, devicesObserver);
179177
}
180178
}
181179

@@ -194,7 +192,13 @@ private void devicesTimeout(DevicesObserver devicesObserver) {
194192
dataService.connections.put(l);
195193
}
196194
}
197-
checkObserverFinished(devicesObserver);
195+
196+
for (Iterator<DevicesObserver> iterator = devicesObserverList.iterator(); iterator.hasNext(); ) {
197+
if (iterator.next() == devicesObserver) {
198+
checkObserverFinished(iterator, devicesObserver);
199+
break;
200+
}
201+
}
198202
}
199203

200204
/**
@@ -287,7 +291,12 @@ public void handleMessage(Message msg) {
287291
}
288292
case MSG_RECHECK_MINIMUM_TIME: {
289293
DevicesObserver devicesObserver = (DevicesObserver) msg.obj;
290-
checkObserverFinished(devicesObserver);
294+
for (Iterator<DevicesObserver> iterator = devicesObserverList.iterator(); iterator.hasNext(); ) {
295+
if (iterator.next() == devicesObserver) {
296+
checkObserverFinished(iterator, devicesObserver);
297+
break;
298+
}
299+
}
291300
break;
292301
}
293302
case MSG_RESPONSE: {

app/src/main/java/oly/netpowerctrl/executables/ExecutableHideShowDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
7070
public Dialog onCreateDialog(Bundle savedInstanceState) {
7171
dataService = DataService.getService();
7272

73-
Dialog dialog = new com.rey.material.app.Dialog(getActivity());
73+
Dialog dialog = new Dialog(getActivity());
7474
dialog.setTitle(R.string.device_shown_actions);
7575
dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
7676
dialog.positiveActionClickListener(new View.OnClickListener() {

app/src/main/java/oly/netpowerctrl/executables/ExecutablesFragment.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import oly.netpowerctrl.network.Utils;
5454
import oly.netpowerctrl.preferences.PreferencesFragment;
5555
import oly.netpowerctrl.preferences.SharedPrefs;
56+
import oly.netpowerctrl.scenes.SceneHelp;
5657
import oly.netpowerctrl.ui.EmptyListener;
5758
import oly.netpowerctrl.ui.FragmentUtils;
5859
import oly.netpowerctrl.ui.ItemShadowDecoration;
@@ -297,9 +298,13 @@ public void onClick(View view) {
297298
btnAdd.setOnClickListener(new View.OnClickListener() {
298299
@Override
299300
public void onClick(View view) {
300-
Intent it = new Intent(getActivity(), EditActivity.class);
301-
it.putExtra(EditActivity.CREATE_SCENE, true);
302-
startActivityForResult(it, EditActivity.REQUEST_CODE);
301+
if (SharedPrefs.getInstance().isFirstTimeSceneAdd()) {
302+
SceneHelp.showHelp(getActivity());
303+
} else {
304+
Intent it = new Intent(getActivity(), EditActivity.class);
305+
it.putExtra(EditActivity.CREATE_SCENE, true);
306+
startActivityForResult(it, EditActivity.REQUEST_CODE);
307+
}
303308
}
304309
});
305310

app/src/main/java/oly/netpowerctrl/main/EditActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import oly.netpowerctrl.scenes.Scene;
4949
import oly.netpowerctrl.scenes.SceneElementsAddDialog;
5050
import oly.netpowerctrl.scenes.SceneElementsAssigning;
51+
import oly.netpowerctrl.scenes.SceneHelp;
5152
import oly.netpowerctrl.timer.Timer;
5253
import oly.netpowerctrl.timer.TimerAdapter;
5354
import oly.netpowerctrl.timer.TimerEditFragmentDialog;
@@ -282,6 +283,14 @@ public void onClick(View view) {
282283
}
283284
});
284285

286+
View btnHelp = findViewById(R.id.btnHelp);
287+
btnHelp.setOnClickListener(new View.OnClickListener() {
288+
@Override
289+
public void onClick(View view) {
290+
SceneHelp.showHelp(EditActivity.this);
291+
}
292+
});
293+
285294
btnNFC = (Button) findViewById(R.id.btnNFC);
286295
btnNFC.setOnClickListener(new View.OnClickListener() {
287296
@Override

app/src/main/java/oly/netpowerctrl/plugin_anel/AnelPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ private int executeDeviceBatch(@NonNull IOConnection ioConnection,
155155
for (int id = 1; id <= 8; ++id) {
156156
Executable oi = dataService.executables.findByUID(makeExecutableUID(credentials.deviceUID, id));
157157
if (oi == null) {
158-
Log.e(getPluginID(), "executeDeviceBatch. Did not find " + makeExecutableUID(credentials.deviceUID, id) + " " + credentials.getDeviceName());
158+
// For Anel devices with only 3 outputs we will run into this case
159+
//Log.e(getPluginID(), "executeDeviceBatch. Did not find " + makeExecutableUID(credentials.deviceUID, id) + " " + credentials.getDeviceName());
159160
continue;
160161
}
161162
if (oi.current_value == 0) // Only take "ON" commands into account for the bulk change byte

app/src/main/java/oly/netpowerctrl/preferences/LogDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void onClick(View view) {
112112
@Override
113113
public Dialog onCreateDialog(Bundle savedInstanceState) {
114114
isDialog = true;
115-
Dialog dialog = new com.rey.material.app.Dialog(getActivity());
115+
Dialog dialog = new Dialog(getActivity());
116116
dialog.setTitle(R.string.device_shown_actions);
117117
dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
118118
dialog.positiveActionClickListener(new View.OnClickListener() {

app/src/main/java/oly/netpowerctrl/preferences/SharedPrefs.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ public void setOpenAutoIssues(long last_access) {
296296
prefs.edit().putLong("open_auto_issues_last_access", last_access).apply();
297297
}
298298

299+
public boolean isFirstTimeSceneAdd() {
300+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
301+
boolean first = prefs.getBoolean("isFirstTimeSceneAdd2", true);
302+
prefs.edit().putBoolean("isFirstTimeSceneAdd2", false).apply();
303+
return first;
304+
}
305+
299306
private static class SingletonHolder {
300307
public static final SharedPrefs instance = new SharedPrefs();
301308
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package oly.netpowerctrl.scenes;
2+
3+
import android.content.Context;
4+
import android.view.View;
5+
6+
import com.rey.material.app.Dialog;
7+
import com.rey.material.app.SimpleDialog;
8+
9+
import oly.netpowerctrl.R;
10+
11+
/**
12+
* Show help for scene dialog
13+
*/
14+
public class SceneHelp {
15+
public static void showHelp(Context context) {
16+
final SimpleDialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight);
17+
builder.title(context.getString(R.string.scene_add));
18+
builder.message(context.getString(R.string.help_scene));
19+
builder.positiveAction(context.getString(android.R.string.ok));
20+
final Dialog dialog = builder.build(context);
21+
dialog.positiveActionClickListener(new View.OnClickListener() {
22+
@Override
23+
public void onClick(View view) {
24+
dialog.dismiss();
25+
}
26+
});
27+
dialog.show();
28+
}
29+
}

app/src/main/java/oly/netpowerctrl/ui/IconThemeDialog.java

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package oly.netpowerctrl.ui;
22

3-
import android.app.AlertDialog;
4-
import android.app.Dialog;
53
import android.app.DialogFragment;
6-
import android.content.DialogInterface;
74
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
import android.view.LayoutInflater;
87
import android.view.View;
8+
import android.view.ViewGroup;
99
import android.widget.ImageView;
1010
import android.widget.RadioButton;
1111

12+
import com.rey.material.app.Dialog;
13+
1214
import java.io.IOException;
1315

1416
import oly.netpowerctrl.R;
@@ -18,14 +20,16 @@
1820
* Try to setup all found devices, The dialog shows a short log about the actions.
1921
*/
2022
public class IconThemeDialog extends DialogFragment {
23+
private SoftRadioGroup radioGroupTheme;
2124
public IconThemeDialog() {
2225
}
2326

27+
@Nullable
2428
@Override
25-
public Dialog onCreateDialog(Bundle savedInstanceState) {
26-
View rootView = getActivity().getLayoutInflater().inflate(R.layout.fragment_icon_theme, null, false);
29+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
30+
View rootView = inflater.inflate(R.layout.fragment_icon_theme, container, false);
2731

28-
final SoftRadioGroup radioGroupTheme = new SoftRadioGroup();
32+
radioGroupTheme = new SoftRadioGroup();
2933
radioGroupTheme.addView((RadioButton) rootView.findViewById(R.id.theme1));
3034
radioGroupTheme.addView((RadioButton) rootView.findViewById(R.id.theme2));
3135
radioGroupTheme.addView((RadioButton) rootView.findViewById(R.id.theme3));
@@ -55,18 +59,24 @@ public void onClick(View view) {
5559
}
5660
}
5761

58-
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
59-
builder.setView(rootView)
60-
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
61-
@Override
62-
public void onClick(DialogInterface dialogInterface, int i) {
63-
int index = radioGroupTheme.getCheckedRadioButtonIndex();
64-
if (index != -1) {
65-
String[] icon_themes = getResources().getStringArray(R.array.default_fallback_icon_set_keys);
66-
LoadStoreIconData.setDefaultFallbackIconSet(icon_themes[index]);
67-
}
68-
}
69-
});
70-
return builder.create();
62+
return rootView;
63+
}
64+
65+
@Override
66+
public com.rey.material.app.Dialog onCreateDialog(Bundle savedInstanceState) {
67+
Dialog dialog = new com.rey.material.app.Dialog(getActivity());
68+
dialog.layoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
69+
dialog.positiveActionClickListener(new View.OnClickListener() {
70+
@Override
71+
public void onClick(View view) {
72+
int index = radioGroupTheme.getCheckedRadioButtonIndex();
73+
if (index != -1) {
74+
String[] icon_themes = getResources().getStringArray(R.array.default_fallback_icon_set_keys);
75+
LoadStoreIconData.setDefaultFallbackIconSet(icon_themes[index]);
76+
}
77+
dismiss();
78+
}
79+
}).positiveAction(android.R.string.ok);
80+
return dialog;
7181
}
7282
}

0 commit comments

Comments
 (0)