Fix for app crash

This commit is contained in:
mhutti1 2016-09-25 19:21:41 +01:00
parent ece26a422d
commit b4be999b44

View File

@ -35,14 +35,15 @@ import java.util.LinkedHashMap;
public class DownloadFragment extends Fragment {
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, LibraryNetworkEntity.Book> mDownloads = new LinkedHashMap<Integer, LibraryNetworkEntity.Book>();
public static LinkedHashMap<Integer, String> mDownloadFiles = new LinkedHashMap<Integer, String>();
public RelativeLayout relLayout;
public static ListView listView;
public static DownloadAdapter downloadAdapter;
private ZimManageActivity zimManageActivity;
CoordinatorLayout mainLayout;
private static FragmentActivity faActivity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
faActivity = (FragmentActivity) super.getActivity();
@ -71,7 +72,7 @@ public class DownloadFragment extends Fragment {
}
if (listView.getCount() == 0) {
noDownloadsText.setVisibility(View.VISIBLE);
} else if (listView.getCount() > 0){
} else if (listView.getCount() > 0) {
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 Integer[] mKeys;
public DownloadAdapter(LinkedHashMap<Integer, LibraryNetworkEntity.Book> data){
public DownloadAdapter(LinkedHashMap<Integer, LibraryNetworkEntity.Book> data) {
mData = data;
mKeys = mData.keySet().toArray(new Integer[data.size()]);
}
@ -101,7 +103,8 @@ public class DownloadFragment extends Fragment {
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);
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,24 +195,27 @@ 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){
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);
Bitmap bitmap= BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
public Bitmap StringToBitMap(String encodedString) {
try {
byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
return bitmap;
}catch(Exception e){
} catch (Exception e) {
e.getMessage();
return null;
}