mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 12:42:56 -04:00
Fix for app crash
This commit is contained in:
parent
ece26a422d
commit
b4be999b44
@ -43,6 +43,7 @@ public class DownloadFragment extends Fragment {
|
||||
private ZimManageActivity zimManageActivity;
|
||||
CoordinatorLayout mainLayout;
|
||||
private static FragmentActivity faActivity;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
faActivity = (FragmentActivity) super.getActivity();
|
||||
@ -81,6 +82,7 @@ public class DownloadFragment extends Fragment {
|
||||
|
||||
private LinkedHashMap<Integer, LibraryNetworkEntity.Book> mData = new LinkedHashMap<Integer, LibraryNetworkEntity.Book>();
|
||||
private Integer[] mKeys;
|
||||
|
||||
public DownloadAdapter(LinkedHashMap<Integer, LibraryNetworkEntity.Book> data) {
|
||||
mData = data;
|
||||
mKeys = mData.keySet().toArray(new Integer[data.size()]);
|
||||
@ -102,6 +104,7 @@ public class DownloadFragment extends Fragment {
|
||||
}
|
||||
|
||||
public void updateProgress(int progress, int notificationID) {
|
||||
if (isAdded()) {
|
||||
int position = Arrays.asList(mKeys).indexOf(notificationID);
|
||||
ViewGroup viewGroup = (ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition());
|
||||
ProgressBar downloadProgress = (ProgressBar) viewGroup.findViewById(R.id.downloadProgress);
|
||||
@ -109,7 +112,7 @@ public class DownloadFragment extends Fragment {
|
||||
if (progress == 100) {
|
||||
ImageView pause = (ImageView) viewGroup.findViewById(R.id.pause);
|
||||
pause.setEnabled(false);
|
||||
if (isAdded()) {
|
||||
{
|
||||
Snackbar completeSnack = Snackbar.make(mainLayout, getResources().getString(R.string.download_complete_snackbar), Snackbar.LENGTH_LONG);
|
||||
String fileName = mDownloadFiles.get(mKeys[position]);
|
||||
completeSnack.setAction(getResources().getString(R.string.open), new View.OnClickListener() {
|
||||
@ -125,6 +128,7 @@ public class DownloadFragment extends Fragment {
|
||||
updateNoDownloads();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
@ -191,18 +195,21 @@ public class DownloadFragment extends Fragment {
|
||||
public static class Download {
|
||||
public String title;
|
||||
public int progress;
|
||||
|
||||
public Download(String title) {
|
||||
this.title = title;
|
||||
progress = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void addDownload(int position, LibraryNetworkEntity.Book book, String fileName) {
|
||||
mDownloads.put(position, book);
|
||||
mDownloadFiles.put(position, fileName);
|
||||
downloadAdapter.notifyDataSetChanged();
|
||||
updateNoDownloads();
|
||||
}
|
||||
|
||||
public Bitmap StringToBitMap(String encodedString) {
|
||||
try {
|
||||
byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
|
||||
|
Loading…
x
Reference in New Issue
Block a user