13
13
import android .app .AlertDialog ;
14
14
import android .app .Dialog ;
15
15
import android .content .BroadcastReceiver ;
16
+ import android .content .Context ;
16
17
import android .content .DialogInterface ;
17
18
import android .content .Intent ;
18
19
import android .content .IntentFilter ;
19
20
import android .content .SharedPreferences ;
20
21
import android .content .pm .PackageInfo ;
21
22
import android .content .pm .PackageManager ;
22
23
import android .content .res .AssetManager ;
24
+ import android .net .ConnectivityManager ;
25
+ import android .net .NetworkInfo ;
23
26
import android .net .Uri ;
24
27
import android .os .Bundle ;
25
28
import android .os .Environment ;
@@ -73,8 +76,6 @@ public class MainActivity extends Activity implements TextToSpeech.OnInitListene
73
76
private SharedPreferences mPrefs ;
74
77
private SharedPreferences .Editor mPrefsEditor ;
75
78
76
- private Menu menu ;
77
-
78
79
private int serversScanned = 0 ;
79
80
AlertDialog .Builder helpDialog ;
80
81
@@ -96,20 +97,6 @@ protected void onCreate(Bundle savedInstanceState) {
96
97
97
98
setContentView (R .layout .main );
98
99
99
- if (hasValidAutoVoice () || hasValidUtter ()) {
100
-
101
- } else if (!hasValidGoogleSearch ()) {
102
- if (!hasValidTasker ()) {
103
- menu .findItem (R .id .menu_install_tasker ).setVisible (true );
104
- }
105
- if (!hasValidUtter ()) {
106
- menu .findItem (R .id .menu_install_utter ).setVisible (true );
107
- }
108
- if (!hasValidAutoVoice ()) {
109
- menu .findItem (R .id .menu_install_autovoice ).setVisible (true );
110
- }
111
- }
112
-
113
100
this .server = gson .fromJson (mPrefs .getString ("Server" , "" ), PlexServer .class );
114
101
this .client = gson .fromJson (mPrefs .getString ("Client" , "" ), PlexClient .class );
115
102
@@ -404,8 +391,12 @@ public void onClick(DialogInterface dialog, int id) {
404
391
});
405
392
usageDialog .show ();
406
393
}
407
-
394
+
408
395
private void searchForPlexServers () {
396
+ if (!isWifiConnected ()) {
397
+ showNoWifiDialog ();
398
+ return ;
399
+ }
409
400
searchDialog = new Dialog (this );
410
401
411
402
searchDialog .setContentView (R .layout .search_popup );
@@ -593,6 +584,10 @@ public void onFailure(Throwable error) {
593
584
}
594
585
595
586
private void getClients () {
587
+ if (!isWifiConnected ()) {
588
+ showNoWifiDialog ();
589
+ return ;
590
+ }
596
591
if (server == null || server .name .equals (getResources ().getString (R .string .scan_all ))) {
597
592
scanForClients ();
598
593
} else {
@@ -718,7 +713,18 @@ private void saveSettings() {
718
713
public boolean onCreateOptionsMenu (Menu _menu ) {
719
714
// Inflate the menu; this adds items to the action bar if it is present.
720
715
getMenuInflater ().inflate (R .menu .menu_main , _menu );
721
- menu = _menu ;
716
+ if (!hasValidAutoVoice () || !hasValidUtter ()) {
717
+ _menu .findItem (R .id .menu_tasker_import ).setVisible (false );
718
+ if (!hasValidTasker ()) {
719
+ _menu .findItem (R .id .menu_install_tasker ).setVisible (true );
720
+ }
721
+ if (!hasValidUtter ()) {
722
+ _menu .findItem (R .id .menu_install_utter ).setVisible (true );
723
+ }
724
+ if (!hasValidAutoVoice ()) {
725
+ _menu .findItem (R .id .menu_install_autovoice ).setVisible (true );
726
+ }
727
+ }
722
728
return true ;
723
729
}
724
730
@@ -805,6 +811,24 @@ public void onClick(DialogInterface d, int n) {
805
811
}
806
812
}
807
813
}
814
+
815
+ public boolean isWifiConnected () {
816
+ ConnectivityManager connManager = (ConnectivityManager ) getSystemService (Context .CONNECTIVITY_SERVICE );
817
+ NetworkInfo mWifi = connManager .getNetworkInfo (ConnectivityManager .TYPE_WIFI );
818
+ return mWifi .isConnected ();
819
+ }
820
+
821
+ public void showNoWifiDialog () {
822
+ AlertDialog .Builder usageDialog = new AlertDialog .Builder (MainActivity .this );
823
+ usageDialog .setTitle (R .string .no_wifi_connection );
824
+ usageDialog .setMessage (R .string .no_wifi_connection_message );
825
+ usageDialog .setPositiveButton (R .string .ok , new DialogInterface .OnClickListener () {
826
+ public void onClick (DialogInterface dialog , int id ) {
827
+ dialog .dismiss ();
828
+ }
829
+ });
830
+ usageDialog .show ();
831
+ }
808
832
}
809
833
810
834
0 commit comments