mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-17 11:25:34 -04:00
Show "no items available" if returned library XML is empty
This commit fixes #323 by checking if books is null before: Attempt to invoke virtual method 'int java.util.LinkedList.size()' on a null object reference Signed-off-by: David Sn <divad.nnamtdeis@gmail.com>
This commit is contained in:
parent
1fd5cf91ff
commit
e19af7b0cd
@ -141,7 +141,7 @@ public class LibraryFragment extends Fragment
|
||||
|
||||
NetworkInfo network = conMan.getActiveNetworkInfo();
|
||||
if (network == null || !network.isConnected()) {
|
||||
noNetworkConnection();
|
||||
displayNoNetworkConnection();
|
||||
}
|
||||
|
||||
networkBroadcastReceiver = new NetworkBroadcastReceiver();
|
||||
@ -160,6 +160,11 @@ public class LibraryFragment extends Fragment
|
||||
|
||||
@Override
|
||||
public void showBooks(LinkedList<Book> books) {
|
||||
if (books == null) {
|
||||
displayNoItemsAvailable();
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i("kiwix-showBooks", "Contains:" + books.size());
|
||||
libraryAdapter.setAllBooks(books);
|
||||
if (faActivity.searchView != null) {
|
||||
@ -180,7 +185,7 @@ public class LibraryFragment extends Fragment
|
||||
return;
|
||||
}
|
||||
|
||||
networkText.setText(R.string.no_network_msg);
|
||||
networkText.setText(R.string.no_network_connection);
|
||||
networkText.setVisibility(View.VISIBLE);
|
||||
permissionButton.setVisibility(View.GONE);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
@ -188,6 +193,20 @@ public class LibraryFragment extends Fragment
|
||||
TestingUtils.unbindResource(LibraryFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayNoItemsAvailable() {
|
||||
if (books.size() != 0) {
|
||||
Toast.makeText(super.getActivity(), R.string.no_items_available, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
networkText.setText(R.string.no_items_available);
|
||||
networkText.setVisibility(View.VISIBLE);
|
||||
permissionButton.setVisibility(View.GONE);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
TestingUtils.unbindResource(LibraryFragment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayScanningContent() {
|
||||
if (!swipeRefreshLayout.isRefreshing()) {
|
||||
@ -208,10 +227,6 @@ public class LibraryFragment extends Fragment
|
||||
TestingUtils.unbindResource(LibraryFragment.class);
|
||||
}
|
||||
|
||||
public void noNetworkConnection() {
|
||||
displayNoNetworkConnection();
|
||||
}
|
||||
|
||||
public void refreshFragment() {
|
||||
NetworkInfo network = conMan.getActiveNetworkInfo();
|
||||
if (network == null || !network.isConnected()) {
|
||||
|
@ -16,6 +16,8 @@ public interface LibraryViewCallback extends ViewCallback {
|
||||
|
||||
void displayNoNetworkConnection();
|
||||
|
||||
void displayNoItemsAvailable();
|
||||
|
||||
void displayScanningContent();
|
||||
|
||||
void stopScanningContent();
|
||||
|
@ -120,6 +120,7 @@
|
||||
<string name="zim_novid">No Videos</string>
|
||||
<string name="open_partial_zim">This file could be incomplete. Do you wish to attempt to open it?</string>
|
||||
<string name="no_network_connection">No network connection</string>
|
||||
<string name="no_items_available">No items available to download</string>
|
||||
<string name="get_library_over_network">Use network to download content list. (Approximately 6MB)</string>
|
||||
<string name="proceed">Proceed</string>
|
||||
<string name="wait_for_load">Content Still Loading</string>
|
||||
@ -157,7 +158,6 @@
|
||||
<string name="internal_storage">Internal</string>
|
||||
<string name="external_storage">External</string>
|
||||
<string name="zim_already_downloading">Zim is already downloading</string>
|
||||
<string name="no_network_msg">No network connection</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
<string name="confirm_stop_download_title">Stop download?</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user