private void downloadABook(int position) { boolean isConnected = DaisyBookUtil.getConnectivityStatus(DaisyReaderDownloadBooks.this) != Constants.CONNECT_TYPE_NOT_CONNECTED; IntentController intent = new IntentController(DaisyReaderDownloadBooks.this); if (isConnected) { if (checkFolderIsExist()) { mDaisyBook = mlistDaisyBook.get(position); String link = mDaisyBook.getPath(); if (checkStorage(link) != 0) { String params[] = {link}; runAsynTask(params); } else { intent.pushToDialog( DaisyReaderDownloadBooks.this.getString(R.string.error_not_enough_space), DaisyReaderDownloadBooks.this.getString(R.string.error_title), R.raw.error, false, false, null); } } } else { intent.pushToDialog( DaisyReaderDownloadBooks.this.getString(R.string.error_connect_internet), DaisyReaderDownloadBooks.this.getString(R.string.error_title), R.raw.error, false, false, null); } }
/** After completing background task Dismiss the progress dialogs * */ @Override protected void onPostExecute(Boolean result) { if (alertDialog != null) { alertDialog.dismiss(); } mProgressDialog.dismiss(); try { if (result) { DaisyBook daisyBook = new DaisyBook(); String path = PATH + mName; daisyBook = DaisyBookUtil.getDaisy202Book(path); DaisyBookInfo daisyBookInfo = new DaisyBookInfo(); daisyBookInfo.setAuthor(daisyBook.getAuthor()); Date date = daisyBook.getDate(); String sDate = formatDateOrReturnEmptyString(date); daisyBookInfo.setDate(sDate); daisyBookInfo.setPath(path); daisyBookInfo.setPublisher(daisyBook.getPublisher()); daisyBookInfo.setSort(mDaisyBook.getSort()); daisyBookInfo.setTitle(daisyBook.getTitle()); if (mSql.addDaisyBook(daisyBookInfo, Constants.TYPE_DOWNLOADED_BOOK)) { Intent intent = new Intent(DaisyReaderDownloadBooks.this, DaisyReaderDownloadedBooks.class); DaisyReaderDownloadBooks.this.startActivity(intent); } } } catch (Exception e) { PrivateException ex = new PrivateException(e, DaisyReaderDownloadBooks.this); ex.writeLogException(); } }