Skip to content

Commit 0f6e355

Browse files
author
David Graeff
committed
Remove all alarm/timer classes. Renaming with anel plugin works now again without activity crash. Remove donations library.
1 parent 0675058 commit 0f6e355

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+371
-2993
lines changed

app/app.iml

-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,5 @@
114114
<orderEntry type="library" exported="" scope="TEST" name="junit-4.11" level="project" />
115115
<orderEntry type="library" exported="" name="ndeftools-util-1.2.4" level="project" />
116116
<orderEntry type="library" exported="" name="cardview-v7-22.0.0" level="project" />
117-
<orderEntry type="module" module-name="Donations" exported="" />
118117
</component>
119118
</module>

app/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ android {
9292
dependencies {
9393
//compile fileTree(dir: 'libs', include: ['*.jar']) :5.2.08 5.0.89
9494
//compile 'com.google.android.gms:play-services:5.2.08'
95-
compile project(':libraries:Donations')
9695
//noinspection GradleDependency
9796
compile 'com.android.support:appcompat-v7:22.0.0'
9897
compile 'com.android.support:support-v13:22.0.0'

app/src/main/java/oly/netpowerctrl/data/AbstractBasePlugin.java

+2
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,6 @@ public boolean isNewIOConnectionAllowed(Credentials credentials) {
9898
*/
9999
public void addNewIOConnection(@NonNull Credentials credentials, @NonNull onNewIOConnection callback) {
100100
}
101+
102+
public abstract boolean supportsRemoteRename();
101103
}

app/src/main/java/oly/netpowerctrl/data/DataService.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import oly.netpowerctrl.main.GuiThreadHandler;
3232
import oly.netpowerctrl.main.MainActivity;
3333
import oly.netpowerctrl.network.NetworkChangedBroadcastReceiver;
34+
import oly.netpowerctrl.network.ReachabilityStates;
35+
import oly.netpowerctrl.network.UDPSend;
3436
import oly.netpowerctrl.plugin_anel.AnelPlugin;
3537
import oly.netpowerctrl.plugin_simpleudp.SimpleUDPPlugin;
36-
import oly.netpowerctrl.preferences.SharedPrefs;
3738
import oly.netpowerctrl.status_bar.FavCollection;
38-
import oly.netpowerctrl.timer.TimerCollection;
3939
import oly.netpowerctrl.utils.Logging;
4040

4141
/**
@@ -59,7 +59,6 @@ public class DataService extends Service implements onDataLoaded, onDataQueryCom
5959
final public CredentialsCollection credentials = new CredentialsCollection(this);
6060
final public GroupCollection groups = new GroupCollection(this);
6161
final public FavCollection favourites = new FavCollection(this);
62-
final public TimerCollection timers = new TimerCollection(this);
6362
final public IOConnectionsCollection connections = new IOConnectionsCollection(this);
6463
private final DataLoadedObserver observersOnDataLoaded = new DataLoadedObserver();
6564
private final List<AbstractBasePlugin> plugins = new ArrayList<>();
@@ -173,9 +172,6 @@ public int onStartCommand(@Nullable final Intent intent, final int flags, final
173172
return START_NOT_STICKY;
174173
} else {
175174
Logging.getInstance().logMain("START");
176-
// Although the next alarm should be registered to android already,
177-
// we do it again, just to be sure.
178-
TimerCollection.armAndroidAlarm(this, SharedPrefs.getNextAlarmCheckTimestamp(this));
179175
}
180176

181177
// We are a singleton, set the instance variable now.
@@ -233,6 +229,8 @@ public void onDestroy() {
233229
loadStoreCollections.finish(this);
234230
loadStoreCollections = null;
235231

232+
UDPSend.killSendThread();
233+
236234
// Clean up
237235
for (AbstractBasePlugin abstractBasePlugin : plugins)
238236
abstractBasePlugin.onDestroy();
@@ -332,7 +330,6 @@ public void clear() {
332330
connections.storage.clear();
333331
credentials.storage.clear();
334332
groups.storage.clear();
335-
timers.storage.clear();
336333
executables.storage.clear();
337334
observersOnDataLoaded.reset();
338335
}
@@ -406,6 +403,14 @@ public void onObserverJobFinished(DevicesObserver devicesObserver) {
406403
}
407404
}
408405

406+
/**
407+
* This is issued by the network observer if no network connection is active (no wlan, no mobile network)
408+
*/
409+
public void makeAllOffline() {
410+
connections.clearNotConfigured();
411+
connections.applyStateToAll(ReachabilityStates.NotReachable);
412+
}
413+
409414
public void remove(Credentials credentials) {
410415
this.executables.remove(credentials);
411416
this.connections.remove(credentials);

app/src/main/java/oly/netpowerctrl/data/LoadStoreCollections.java

-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import oly.netpowerctrl.main.App;
1818
import oly.netpowerctrl.preferences.SharedPrefs;
1919
import oly.netpowerctrl.status_bar.FavItem;
20-
import oly.netpowerctrl.timer.Timer;
2120
import oly.netpowerctrl.ui.notifications.InAppNotifications;
2221
import oly.netpowerctrl.utils.FactoryInterface;
2322
import oly.netpowerctrl.utils.IOInterface;
@@ -80,7 +79,6 @@ public void loadData(final DataService dataService) {
8079
dataService.connections.getStorage().setStorage(this);
8180
dataService.executables.getStorage().setStorage(this);
8281
dataService.groups.getStorage().setStorage(this);
83-
dataService.timers.getStorage().setStorage(this);
8482
dataService.favourites.getStorage().setStorage(this);
8583

8684
new AsyncTask<Void, Void, Boolean>() {
@@ -111,7 +109,6 @@ public void finish(DataService dataService) {
111109
dataService.connections.getStorage().setStorage(null);
112110
dataService.executables.getStorage().setStorage(null);
113111
dataService.groups.getStorage().setStorage(null);
114-
dataService.timers.getStorage().setStorage(null);
115112
dataService.favourites.getStorage().setStorage(null);
116113
}
117114

@@ -223,12 +220,6 @@ private void readOtherThread(final DataService dataService) {
223220
e.printStackTrace();
224221
}
225222

226-
try {
227-
readOtherThreadCollection(dataService.timers.getStorage(), Timer.class, false);
228-
} catch (Exception e) {
229-
e.printStackTrace();
230-
}
231-
232223
try {
233224
readOtherThreadCollection(dataService.favourites.getStorage(), FavItem.class, false);
234225
} catch (Exception e) {

app/src/main/java/oly/netpowerctrl/data/importexport/ImportExport.java

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public static void clearData(DataService dataService) {
3535
loadStoreCollections.clear(dataService.connections.getStorage());
3636
loadStoreCollections.clear(dataService.executables.getStorage());
3737
loadStoreCollections.clear(dataService.credentials.getStorage());
38-
loadStoreCollections.clear(dataService.timers.getStorage());
3938
}
4039

4140
@SuppressWarnings("ResultOfMethodCallIgnored")

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@ public int getCurrentValueToggled() {
138138
public void setTitle(String title, @NonNull onNameChangeResult callback) {
139139
if (title.equals(this.title)) return;
140140

141-
this.title = title;
142-
143-
if (credentials != null) {
141+
if (credentials != null && credentials.getPlugin().supportsRemoteRename()) {
144142
callback.onNameChangeStart(this);
145143
credentials.getPlugin().setTitle(this, title, callback);
146-
}
144+
} else
145+
this.title = title;
147146
}
148147

149148
public boolean isHidden() {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public void onClick(View view) {
299299
@Override
300300
public void onClick(View view) {
301301
if (SharedPrefs.getInstance().isFirstTimeSceneAdd()) {
302-
SceneHelp.showHelp(getActivity());
302+
SceneHelp.showHelp(getActivity(), R.string.scene_add, R.string.help_scene);
303303
} else {
304304
Intent it = new Intent(getActivity(), EditActivity.class);
305305
it.putExtra(EditActivity.CREATE_SCENE, true);

app/src/main/java/oly/netpowerctrl/ioconnection/IOConnectionsCollection.java

+11
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,15 @@ public Set<Integer> getAllUDPReceivePorts(AbstractBasePlugin plugin) {
280280
}
281281
return ports;
282282
}
283+
284+
public void applyStateToAll(ReachabilityStates state) {
285+
for (DeviceIOConnections deviceIOConnections : items.values()) {
286+
for (Iterator<IOConnection> iterator = deviceIOConnections.iterator(); iterator.hasNext(); ) {
287+
IOConnection ioConnection = iterator.next();
288+
ioConnection.resetChanged();
289+
ioConnection.setReachability(state);
290+
putInternal(deviceIOConnections, ioConnection);
291+
}
292+
}
293+
}
283294
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void onCreate() {
8383
config.setFormUriBasicAuthPassword(getString(R.string.acralyzer_http_pwd));
8484
config.setReportType(HttpSender.Type.JSON);
8585
config.setResToastText(R.string.crash_toast_text);
86+
config.setBuildConfigClass(BuildConfig.class);
8687
try {
8788
config.setMode(ReportingInteractionMode.TOAST);
8889
} catch (ACRAConfigurationException e) {

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

+31-77
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package oly.netpowerctrl.main;
22

33
import android.annotation.SuppressLint;
4-
import android.app.Fragment;
4+
import android.app.Activity;
55
import android.app.ProgressDialog;
6+
import android.content.Context;
7+
import android.content.ContextWrapper;
68
import android.content.Intent;
79
import android.graphics.Bitmap;
810
import android.graphics.Canvas;
@@ -18,14 +20,11 @@
1820
import android.support.v7.widget.Toolbar;
1921
import android.text.Editable;
2022
import android.text.TextWatcher;
21-
import android.view.MenuInflater;
22-
import android.view.MenuItem;
2323
import android.view.View;
2424
import android.widget.Button;
2525
import android.widget.CompoundButton;
2626
import android.widget.EditText;
2727
import android.widget.ImageView;
28-
import android.widget.PopupMenu;
2928
import android.widget.TextView;
3029
import android.widget.Toast;
3130

@@ -49,13 +48,7 @@
4948
import oly.netpowerctrl.scenes.SceneElementsAddDialog;
5049
import oly.netpowerctrl.scenes.SceneElementsAssigning;
5150
import oly.netpowerctrl.scenes.SceneHelp;
52-
import oly.netpowerctrl.timer.Timer;
53-
import oly.netpowerctrl.timer.TimerAdapter;
54-
import oly.netpowerctrl.timer.TimerEditFragmentDialog;
5551
import oly.netpowerctrl.ui.FragmentUtils;
56-
import oly.netpowerctrl.ui.LineDividerDecoration;
57-
import oly.netpowerctrl.ui.RecyclerItemClickListener;
58-
import oly.netpowerctrl.ui.RecyclerViewWithAdapter;
5952
import oly.netpowerctrl.ui.notifications.InAppNotifications;
6053
import oly.netpowerctrl.utils.AndroidShortcuts;
6154
import oly.netpowerctrl.utils.AnimationController;
@@ -85,7 +78,6 @@ public class EditActivity extends ActionBarActivity implements LoadStoreIconData
8578
CompoundButton chk_hide;
8679
private int mEditType = EDIT_TYPE_SHORTCUT;
8780
private Set<String> checked_groups = new TreeSet<>();
88-
private View executable_timers;
8981
private boolean isChanged = false;
9082
private FloatingActionButton btnSaveOrTrash;
9183
// If we are editing a scene, sceneElementsAssigning will be set up.
@@ -104,8 +96,6 @@ public class EditActivity extends ActionBarActivity implements LoadStoreIconData
10496
private boolean isFavourite;
10597
// Groups
10698
private FlowLayout groups_layout;
107-
// Timers
108-
private TimerAdapter timerAdapter;
10999
// Other
110100
private Toast toast;
111101
private boolean iconMenuVisible = false;
@@ -171,58 +161,6 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
171161
chk_hide = (CompoundButton) findViewById(R.id.chk_hide);
172162
chk_hide.setOnCheckedChangeListener(updateSaveButtonOnChecked);
173163

174-
executable_timers = findViewById(R.id.executable_timers);
175-
timerAdapter = new TimerAdapter(this);
176-
RecyclerViewWithAdapter<TimerAdapter> recyclerViewWithAdapter = new RecyclerViewWithAdapter<>(this, executable_timers, timerAdapter, R.string.alarms_no_alarms);
177-
recyclerViewWithAdapter.setOnItemClickListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {
178-
@Override
179-
public boolean onItemClick(View view, int position, boolean isLongClick) {
180-
TimerEditFragmentDialog fragment = (TimerEditFragmentDialog)
181-
Fragment.instantiate(EditActivity.this, TimerEditFragmentDialog.class.getName());
182-
fragment.setArguments(TimerEditFragmentDialog.createArgumentsLoadTimer(timerAdapter.getAlarm(position)));
183-
FragmentUtils.changeToDialog(EditActivity.this, fragment);
184-
return false;
185-
}
186-
}, null));
187-
recyclerViewWithAdapter.getRecyclerView().addItemDecoration(new LineDividerDecoration(this, LineDividerDecoration.VERTICAL_LIST) {
188-
@Override
189-
public boolean dividerForPosition(int position) {
190-
return true;
191-
}
192-
});
193-
194-
Button btnTimerAdd = (Button) findViewById(R.id.btnAddTimer);
195-
btnTimerAdd.setOnClickListener(new View.OnClickListener() {
196-
@Override
197-
public void onClick(View view) {
198-
PopupMenu popup = new PopupMenu(EditActivity.this, view);
199-
MenuInflater inflater = popup.getMenuInflater();
200-
inflater.inflate(R.menu.timer_add, popup.getMenu());
201-
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
202-
@Override
203-
public boolean onMenuItemClick(MenuItem menuItem) {
204-
TimerEditFragmentDialog fragmentDialog = (TimerEditFragmentDialog) Fragment.instantiate(EditActivity.this, TimerEditFragmentDialog.class.getName());
205-
switch (menuItem.getItemId()) {
206-
case R.id.menu_timer_android_once:
207-
fragmentDialog.setArguments(TimerEditFragmentDialog.createArgumentNewTimer(Timer.TYPE_ONCE, true, executable));
208-
FragmentUtils.changeToDialog(EditActivity.this, fragmentDialog);
209-
return true;
210-
case R.id.menu_timer_android_weekdays:
211-
fragmentDialog.setArguments(TimerEditFragmentDialog.createArgumentNewTimer(Timer.TYPE_RANGE_ON_WEEKDAYS, true, executable));
212-
FragmentUtils.changeToDialog(EditActivity.this, fragmentDialog);
213-
return true;
214-
case R.id.menu_timer_device_weekdays:
215-
fragmentDialog.setArguments(TimerEditFragmentDialog.createArgumentNewTimer(Timer.TYPE_RANGE_ON_WEEKDAYS, false, executable));
216-
FragmentUtils.changeToDialog(EditActivity.this, fragmentDialog);
217-
return true;
218-
}
219-
throw new RuntimeException("Menu switch missing entry!");
220-
}
221-
});
222-
popup.show();
223-
}
224-
});
225-
226164
groups_layout = (FlowLayout) findViewById(R.id.groups_layout);
227165
Button btnGroupAdd = (Button) findViewById(R.id.btnAddGroup);
228166
btnGroupAdd.setOnClickListener(new View.OnClickListener() {
@@ -283,14 +221,6 @@ public void onClick(View view) {
283221
}
284222
});
285223

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-
294224
btnNFC = (Button) findViewById(R.id.btnNFC);
295225
btnNFC.setOnClickListener(new View.OnClickListener() {
296226
@Override
@@ -354,7 +284,6 @@ public void onServiceFinished(DataService service) {
354284

355285
@Override
356286
protected void onDestroy() {
357-
timerAdapter.finish();
358287
super.onDestroy();
359288
}
360289

@@ -483,8 +412,6 @@ public void onSceneElementsChanged() {
483412
getSupportActionBar().setSubtitle(getString(R.string.outlet_edit_title, executable.getTitle()));
484413
scene_items_view.setVisibility(View.GONE);
485414
btnAdd.setVisibility(View.GONE);
486-
executable_timers.setVisibility(View.VISIBLE);
487-
timerAdapter.start(dataService.timers, executable);
488415
}
489416

490417
isLoaded = true;
@@ -507,15 +434,29 @@ public void onSceneElementsChanged() {
507434

508435
private void prepareInterface(DataService dataService) {
509436

437+
View btnHelp = findViewById(R.id.btnHelp);
438+
final int help_res;
439+
final int help_title_res;
510440
if (mEditType == EDIT_TYPE_SHORTCUT) {
511441
show_mainWindow.setVisibility(View.VISIBLE);
512442
enable_feedback.setVisibility(View.VISIBLE);
513443
groups_layout.setVisibility(View.GONE);
514444
chk_hide.setVisibility(View.GONE);
445+
help_res = R.string.help_shortcut;
446+
help_title_res = R.string.shortcut_new_scene;
515447
} else {
516448
updateGroups(dataService.groups);
449+
help_res = mEditType == EDIT_TYPE_SCENE ? R.string.help_scene : R.string.help_edit_outlet;
450+
help_title_res = mEditType == EDIT_TYPE_SCENE ? R.string.scene_add : R.string.help_edit_outlet_title;
517451
}
518452

453+
btnHelp.setOnClickListener(new View.OnClickListener() {
454+
@Override
455+
public void onClick(View view) {
456+
SceneHelp.showHelp(EditActivity.this, help_title_res, help_res);
457+
}
458+
});
459+
519460
chk_hide.setVisibility(View.GONE);
520461
chk_hide.setChecked(executable.isHidden());
521462

@@ -579,6 +520,7 @@ private void save_and_close() {
579520
}
580521

581522
executable.setTitle(newName, this);
523+
if (progressDialog != null) return;
582524

583525
if (mEditType == EDIT_TYPE_SHORTCUT) {
584526
Intent extra = AndroidShortcuts.createShortcutExecutionIntent(EditActivity.this,
@@ -663,7 +605,18 @@ public void onActivityResult(int requestCode, int resultCode, Intent imageReturn
663605
@Override
664606
public void onNameChangeResult(boolean success, String error_message) {
665607
if (progressDialog != null) {
666-
progressDialog.dismiss();
608+
if (progressDialog.isShowing()) {
609+
//get the Context object that was used to great the dialog
610+
Context context = ((ContextWrapper) progressDialog.getContext()).getBaseContext();
611+
612+
//if the Context used here was an activity AND it hasn't been finished or destroyed
613+
//then dismiss it
614+
if (context instanceof Activity) {
615+
if (!((Activity) context).isFinishing() && !((Activity) context).isDestroyed())
616+
progressDialog.dismiss();
617+
} else //if the Context used wasnt an Activity, then dismiss it too
618+
progressDialog.dismiss();
619+
}
667620
progressDialog = null;
668621
}
669622

@@ -672,6 +625,7 @@ public void onNameChangeResult(boolean success, String error_message) {
672625
Toast.makeText(App.instance, App.instance.getString(R.string.renameFailed, error_message), Toast.LENGTH_SHORT).show();
673626
} else {
674627
executable.title = (((EditText) findViewById(R.id.scene_name)).getText().toString().trim());
628+
save_and_close();
675629
}
676630
}
677631

0 commit comments

Comments
 (0)