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
@ -35,14 +35,15 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class DownloadFragment extends Fragment {
|
public class DownloadFragment extends Fragment {
|
||||||
|
|
||||||
public static LinkedHashMap<Integer, LibraryNetworkEntity.Book> mDownloads= new LinkedHashMap<Integer, LibraryNetworkEntity.Book>();
|
public static LinkedHashMap<Integer, LibraryNetworkEntity.Book> mDownloads = new LinkedHashMap<Integer, LibraryNetworkEntity.Book>();
|
||||||
public static LinkedHashMap<Integer, String> mDownloadFiles= new LinkedHashMap<Integer, String>();
|
public static LinkedHashMap<Integer, String> mDownloadFiles = new LinkedHashMap<Integer, String>();
|
||||||
public RelativeLayout relLayout;
|
public RelativeLayout relLayout;
|
||||||
public static ListView listView;
|
public static ListView listView;
|
||||||
public static DownloadAdapter downloadAdapter;
|
public static DownloadAdapter downloadAdapter;
|
||||||
private ZimManageActivity zimManageActivity;
|
private ZimManageActivity zimManageActivity;
|
||||||
CoordinatorLayout mainLayout;
|
CoordinatorLayout mainLayout;
|
||||||
private static FragmentActivity faActivity;
|
private static FragmentActivity faActivity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
faActivity = (FragmentActivity) super.getActivity();
|
faActivity = (FragmentActivity) super.getActivity();
|
||||||
@ -71,7 +72,7 @@ public class DownloadFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
if (listView.getCount() == 0) {
|
if (listView.getCount() == 0) {
|
||||||
noDownloadsText.setVisibility(View.VISIBLE);
|
noDownloadsText.setVisibility(View.VISIBLE);
|
||||||
} else if (listView.getCount() > 0){
|
} else if (listView.getCount() > 0) {
|
||||||
noDownloadsText.setVisibility(View.GONE);
|
noDownloadsText.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +82,8 @@ public class DownloadFragment extends Fragment {
|
|||||||
|
|
||||||
private LinkedHashMap<Integer, LibraryNetworkEntity.Book> mData = new LinkedHashMap<Integer, LibraryNetworkEntity.Book>();
|
private LinkedHashMap<Integer, LibraryNetworkEntity.Book> mData = new LinkedHashMap<Integer, LibraryNetworkEntity.Book>();
|
||||||
private Integer[] mKeys;
|
private Integer[] mKeys;
|
||||||
public DownloadAdapter(LinkedHashMap<Integer, LibraryNetworkEntity.Book> data){
|
|
||||||
|
public DownloadAdapter(LinkedHashMap<Integer, LibraryNetworkEntity.Book> data) {
|
||||||
mData = data;
|
mData = data;
|
||||||
mKeys = mData.keySet().toArray(new Integer[data.size()]);
|
mKeys = mData.keySet().toArray(new Integer[data.size()]);
|
||||||
}
|
}
|
||||||
@ -101,7 +103,8 @@ public class DownloadFragment extends Fragment {
|
|||||||
return arg0;
|
return arg0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProgress(int progress, int notificationID){
|
public void updateProgress(int progress, int notificationID) {
|
||||||
|
if (isAdded()) {
|
||||||
int position = Arrays.asList(mKeys).indexOf(notificationID);
|
int position = Arrays.asList(mKeys).indexOf(notificationID);
|
||||||
ViewGroup viewGroup = (ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition());
|
ViewGroup viewGroup = (ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition());
|
||||||
ProgressBar downloadProgress = (ProgressBar) viewGroup.findViewById(R.id.downloadProgress);
|
ProgressBar downloadProgress = (ProgressBar) viewGroup.findViewById(R.id.downloadProgress);
|
||||||
@ -109,7 +112,7 @@ public class DownloadFragment extends Fragment {
|
|||||||
if (progress == 100) {
|
if (progress == 100) {
|
||||||
ImageView pause = (ImageView) viewGroup.findViewById(R.id.pause);
|
ImageView pause = (ImageView) viewGroup.findViewById(R.id.pause);
|
||||||
pause.setEnabled(false);
|
pause.setEnabled(false);
|
||||||
if (isAdded()) {
|
{
|
||||||
Snackbar completeSnack = Snackbar.make(mainLayout, getResources().getString(R.string.download_complete_snackbar), Snackbar.LENGTH_LONG);
|
Snackbar completeSnack = Snackbar.make(mainLayout, getResources().getString(R.string.download_complete_snackbar), Snackbar.LENGTH_LONG);
|
||||||
String fileName = mDownloadFiles.get(mKeys[position]);
|
String fileName = mDownloadFiles.get(mKeys[position]);
|
||||||
completeSnack.setAction(getResources().getString(R.string.open), new View.OnClickListener() {
|
completeSnack.setAction(getResources().getString(R.string.open), new View.OnClickListener() {
|
||||||
@ -125,6 +128,7 @@ public class DownloadFragment extends Fragment {
|
|||||||
updateNoDownloads();
|
updateNoDownloads();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
@ -191,24 +195,27 @@ public class DownloadFragment extends Fragment {
|
|||||||
public static class Download {
|
public static class Download {
|
||||||
public String title;
|
public String title;
|
||||||
public int progress;
|
public int progress;
|
||||||
|
|
||||||
public Download(String title) {
|
public Download(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
progress = 0;
|
progress = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void addDownload(int position, LibraryNetworkEntity.Book book, String fileName){
|
|
||||||
|
public static void addDownload(int position, LibraryNetworkEntity.Book book, String fileName) {
|
||||||
mDownloads.put(position, book);
|
mDownloads.put(position, book);
|
||||||
mDownloadFiles.put(position, fileName);
|
mDownloadFiles.put(position, fileName);
|
||||||
downloadAdapter.notifyDataSetChanged();
|
downloadAdapter.notifyDataSetChanged();
|
||||||
updateNoDownloads();
|
updateNoDownloads();
|
||||||
}
|
}
|
||||||
public Bitmap StringToBitMap(String encodedString){
|
|
||||||
try{
|
public Bitmap StringToBitMap(String encodedString) {
|
||||||
byte [] encodeByte= Base64.decode(encodedString,Base64.DEFAULT);
|
try {
|
||||||
Bitmap bitmap= BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
|
byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
|
||||||
|
Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}catch(Exception e){
|
} catch (Exception e) {
|
||||||
e.getMessage();
|
e.getMessage();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user