Merge pull request #117 from poisdeux/testifconnectedtonetwork
Implemented checking if network is enabled when searching for hosts
This commit is contained in:
commit
cae7e21aa4
|
@ -4,6 +4,7 @@
|
|||
|
||||
<!-- Permissions -->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
|
|
@ -17,6 +17,8 @@ package org.xbmc.kore.ui.hosts;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
|
@ -118,6 +120,11 @@ public class AddHostFragmentZeroconf extends Fragment {
|
|||
* Starts the service discovery, setting up the UI accordingly
|
||||
*/
|
||||
public void startSearching() {
|
||||
if( ! isNetworkConnected() ) {
|
||||
noNetworkConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
LogUtils.LOGD(TAG, "Starting service discovery...");
|
||||
searchCancelled = false;
|
||||
final Handler handler = new Handler();
|
||||
|
@ -125,6 +132,7 @@ public class AddHostFragmentZeroconf extends Fragment {
|
|||
@Override
|
||||
public void run() {
|
||||
WifiManager wifiManager = (WifiManager)getActivity().getSystemService(Context.WIFI_SERVICE);
|
||||
|
||||
WifiManager.MulticastLock multicastLock = null;
|
||||
try {
|
||||
// Get wifi ip address
|
||||
|
@ -279,6 +287,44 @@ public class AddHostFragmentZeroconf extends Fragment {
|
|||
|
||||
}
|
||||
|
||||
private void noNetworkConnection() {
|
||||
titleTextView.setText(R.string.no_network_connection);
|
||||
messageTextView.setText(Html.fromHtml(getString(R.string.wizard_search_no_network_connection)));
|
||||
messageTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
hostListGridView.setVisibility(View.GONE);
|
||||
|
||||
nextButton.setVisibility(View.VISIBLE);
|
||||
nextButton.setText(R.string.next);
|
||||
nextButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.onAddHostZeroconfNoHost();
|
||||
}
|
||||
});
|
||||
|
||||
previousButton.setVisibility(View.VISIBLE);
|
||||
previousButton.setText(R.string.search_again);
|
||||
previousButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startSearching();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isNetworkConnected() {
|
||||
ConnectivityManager cm =
|
||||
(ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||
boolean isConnected = activeNetwork != null &&
|
||||
activeNetwork.isConnectedOrConnecting();
|
||||
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter used to show the hosts in the {@link GridView}
|
||||
*/
|
||||
|
|
|
@ -80,9 +80,14 @@
|
|||
I couldn\'t find any media center on your network.<br/>If you need help configuring it, check <a href="http://syncedsynapse.com/kore/kore-faq/>here</a>.<br/><br/>
|
||||
Click <i>Search</i> to search again or <i>Next</i> for manual configuration.
|
||||
]]></string>
|
||||
<string name="wizard_search_no_network_connection"><![CDATA[
|
||||
Please enable the network connection.<br/><br/>
|
||||
Click <i>Search</i> to search again or <i>Next</i> for manual configuration.
|
||||
]]></string>
|
||||
<string name="wizard_search_host_found"><![CDATA[
|
||||
I found these media centers on your network.<br/><br/>Select one to add or press <i>Next</i> to manually add a new one.
|
||||
]]></string>
|
||||
<string name="no_network_connection">No network connection</string>
|
||||
<string name="searching">Searching…</string>
|
||||
<string name="no_xbmc_found">No media center found</string>
|
||||
<string name="xbmc_found">Media center found</string>
|
||||
|
|
Loading…
Reference in New Issue