1
1
package oly .netpowerctrl .main ;
2
2
3
3
import android .annotation .SuppressLint ;
4
- import android .app .Fragment ;
4
+ import android .app .Activity ;
5
5
import android .app .ProgressDialog ;
6
+ import android .content .Context ;
7
+ import android .content .ContextWrapper ;
6
8
import android .content .Intent ;
7
9
import android .graphics .Bitmap ;
8
10
import android .graphics .Canvas ;
18
20
import android .support .v7 .widget .Toolbar ;
19
21
import android .text .Editable ;
20
22
import android .text .TextWatcher ;
21
- import android .view .MenuInflater ;
22
- import android .view .MenuItem ;
23
23
import android .view .View ;
24
24
import android .widget .Button ;
25
25
import android .widget .CompoundButton ;
26
26
import android .widget .EditText ;
27
27
import android .widget .ImageView ;
28
- import android .widget .PopupMenu ;
29
28
import android .widget .TextView ;
30
29
import android .widget .Toast ;
31
30
49
48
import oly .netpowerctrl .scenes .SceneElementsAddDialog ;
50
49
import oly .netpowerctrl .scenes .SceneElementsAssigning ;
51
50
import oly .netpowerctrl .scenes .SceneHelp ;
52
- import oly .netpowerctrl .timer .Timer ;
53
- import oly .netpowerctrl .timer .TimerAdapter ;
54
- import oly .netpowerctrl .timer .TimerEditFragmentDialog ;
55
51
import oly .netpowerctrl .ui .FragmentUtils ;
56
- import oly .netpowerctrl .ui .LineDividerDecoration ;
57
- import oly .netpowerctrl .ui .RecyclerItemClickListener ;
58
- import oly .netpowerctrl .ui .RecyclerViewWithAdapter ;
59
52
import oly .netpowerctrl .ui .notifications .InAppNotifications ;
60
53
import oly .netpowerctrl .utils .AndroidShortcuts ;
61
54
import oly .netpowerctrl .utils .AnimationController ;
@@ -85,7 +78,6 @@ public class EditActivity extends ActionBarActivity implements LoadStoreIconData
85
78
CompoundButton chk_hide ;
86
79
private int mEditType = EDIT_TYPE_SHORTCUT ;
87
80
private Set <String > checked_groups = new TreeSet <>();
88
- private View executable_timers ;
89
81
private boolean isChanged = false ;
90
82
private FloatingActionButton btnSaveOrTrash ;
91
83
// If we are editing a scene, sceneElementsAssigning will be set up.
@@ -104,8 +96,6 @@ public class EditActivity extends ActionBarActivity implements LoadStoreIconData
104
96
private boolean isFavourite ;
105
97
// Groups
106
98
private FlowLayout groups_layout ;
107
- // Timers
108
- private TimerAdapter timerAdapter ;
109
99
// Other
110
100
private Toast toast ;
111
101
private boolean iconMenuVisible = false ;
@@ -171,58 +161,6 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
171
161
chk_hide = (CompoundButton ) findViewById (R .id .chk_hide );
172
162
chk_hide .setOnCheckedChangeListener (updateSaveButtonOnChecked );
173
163
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
-
226
164
groups_layout = (FlowLayout ) findViewById (R .id .groups_layout );
227
165
Button btnGroupAdd = (Button ) findViewById (R .id .btnAddGroup );
228
166
btnGroupAdd .setOnClickListener (new View .OnClickListener () {
@@ -283,14 +221,6 @@ public void onClick(View view) {
283
221
}
284
222
});
285
223
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
-
294
224
btnNFC = (Button ) findViewById (R .id .btnNFC );
295
225
btnNFC .setOnClickListener (new View .OnClickListener () {
296
226
@ Override
@@ -354,7 +284,6 @@ public void onServiceFinished(DataService service) {
354
284
355
285
@ Override
356
286
protected void onDestroy () {
357
- timerAdapter .finish ();
358
287
super .onDestroy ();
359
288
}
360
289
@@ -483,8 +412,6 @@ public void onSceneElementsChanged() {
483
412
getSupportActionBar ().setSubtitle (getString (R .string .outlet_edit_title , executable .getTitle ()));
484
413
scene_items_view .setVisibility (View .GONE );
485
414
btnAdd .setVisibility (View .GONE );
486
- executable_timers .setVisibility (View .VISIBLE );
487
- timerAdapter .start (dataService .timers , executable );
488
415
}
489
416
490
417
isLoaded = true ;
@@ -507,15 +434,29 @@ public void onSceneElementsChanged() {
507
434
508
435
private void prepareInterface (DataService dataService ) {
509
436
437
+ View btnHelp = findViewById (R .id .btnHelp );
438
+ final int help_res ;
439
+ final int help_title_res ;
510
440
if (mEditType == EDIT_TYPE_SHORTCUT ) {
511
441
show_mainWindow .setVisibility (View .VISIBLE );
512
442
enable_feedback .setVisibility (View .VISIBLE );
513
443
groups_layout .setVisibility (View .GONE );
514
444
chk_hide .setVisibility (View .GONE );
445
+ help_res = R .string .help_shortcut ;
446
+ help_title_res = R .string .shortcut_new_scene ;
515
447
} else {
516
448
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 ;
517
451
}
518
452
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
+
519
460
chk_hide .setVisibility (View .GONE );
520
461
chk_hide .setChecked (executable .isHidden ());
521
462
@@ -579,6 +520,7 @@ private void save_and_close() {
579
520
}
580
521
581
522
executable .setTitle (newName , this );
523
+ if (progressDialog != null ) return ;
582
524
583
525
if (mEditType == EDIT_TYPE_SHORTCUT ) {
584
526
Intent extra = AndroidShortcuts .createShortcutExecutionIntent (EditActivity .this ,
@@ -663,7 +605,18 @@ public void onActivityResult(int requestCode, int resultCode, Intent imageReturn
663
605
@ Override
664
606
public void onNameChangeResult (boolean success , String error_message ) {
665
607
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
+ }
667
620
progressDialog = null ;
668
621
}
669
622
@@ -672,6 +625,7 @@ public void onNameChangeResult(boolean success, String error_message) {
672
625
Toast .makeText (App .instance , App .instance .getString (R .string .renameFailed , error_message ), Toast .LENGTH_SHORT ).show ();
673
626
} else {
674
627
executable .title = (((EditText ) findViewById (R .id .scene_name )).getText ().toString ().trim ());
628
+ save_and_close ();
675
629
}
676
630
}
677
631
0 commit comments