Added contextual empty view around network status.
This commit is contained in:
@@ -28,6 +28,10 @@
|
|||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
|
android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
|
||||||
|
|
||||||
|
<!-- Permissions required to make our UI more friendly -->
|
||||||
|
<uses-permission
|
||||||
|
android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.example.android.sunshine.app.data.WeatherContract;
|
import com.example.android.sunshine.app.data.WeatherContract;
|
||||||
import com.example.android.sunshine.app.sync.SunshineSyncAdapter;
|
import com.example.android.sunshine.app.sync.SunshineSyncAdapter;
|
||||||
@@ -255,6 +256,7 @@ public class ForecastFragment extends Fragment implements LoaderManager.LoaderCa
|
|||||||
// to, do so now.
|
// to, do so now.
|
||||||
mListView.smoothScrollToPosition(mPosition);
|
mListView.smoothScrollToPosition(mPosition);
|
||||||
}
|
}
|
||||||
|
updateEmptyView();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -268,4 +270,22 @@ public class ForecastFragment extends Fragment implements LoaderManager.LoaderCa
|
|||||||
mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
|
mForecastAdapter.setUseTodayLayout(mUseTodayLayout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Updates the empty list view with contextually relevant information that the user can
|
||||||
|
use to determine why they aren't seeing weather.
|
||||||
|
*/
|
||||||
|
private void updateEmptyView() {
|
||||||
|
if ( mForecastAdapter.getCount() == 0 ) {
|
||||||
|
TextView tv = (TextView) getView().findViewById(R.id.listview_forecast_empty);
|
||||||
|
if ( null != tv ) {
|
||||||
|
// if cursor is empty, why? do we have an invalid location
|
||||||
|
int message = R.string.empty_forecast_list;
|
||||||
|
if (!Utility.isNetworkAvailable(getActivity()) ) {
|
||||||
|
message = R.string.empty_forecast_list_no_network;
|
||||||
|
}
|
||||||
|
tv.setText(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,8 @@ package com.example.android.sunshine.app;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.format.Time;
|
import android.text.format.Time;
|
||||||
|
|
||||||
@@ -246,4 +248,19 @@ public class Utility {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the network is available or about to become available.
|
||||||
|
*
|
||||||
|
* @param c Context used to get the ConnectivityManager
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static public boolean isNetworkAvailable(Context c) {
|
||||||
|
ConnectivityManager cm =
|
||||||
|
(ConnectivityManager)c.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
|
||||||
|
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||||
|
return activeNetwork != null &&
|
||||||
|
activeNetwork.isConnectedOrConnecting();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -111,5 +111,7 @@
|
|||||||
|
|
||||||
<!-- Empty Weather Database -->
|
<!-- Empty Weather Database -->
|
||||||
<string name="empty_forecast_list">No Weather Information Available</string>
|
<string name="empty_forecast_list">No Weather Information Available</string>
|
||||||
|
<string name="empty_forecast_list_no_network">No weather information available. The network is not available to fetch weather data.</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user