@Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { final DaisyBookInfo daisyBook = mlistDaisyBook.get(position); boolean isDoubleTap = handleClickItem(position); if (isDoubleTap) { downloadABook(position); } else { speakTextOnHandler(daisyBook.getTitle()); } }
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); } }
/** * Add a record to RecentBooks table * * @param recentBooks */ public void addRecentBook(DaisyBookInfo recentBooks) { ContentValues mValue = new ContentValues(); mValue.put(NAME_KEY_RECENT_BOOKS, recentBooks.getTitle()); mValue.put(PATH_KEY_RECENT_BOOKS, recentBooks.getPath()); mValue.put(SORT_KEY_RECENT_BOOKS, recentBooks.getSort()); try { SQLiteDatabase mdb = getWritableDatabase(); mdb.insert(TABLE_NAME_RECENT_BOOKS, null, mValue); mdb.close(); } catch (Exception e) { PrivateException ex = new PrivateException(e, mContext); ex.writeLogException(); } }
/** * Update a record of RecentBooks table * * @param recentBooks */ public void updateRecentBook(DaisyBookInfo recentBooks) { ContentValues mValue = new ContentValues(); mValue.put(SORT_KEY_RECENT_BOOKS, recentBooks.getSort()); try { SQLiteDatabase mdb = getWritableDatabase(); mdb.update( TABLE_NAME_RECENT_BOOKS, mValue, NAME_KEY_RECENT_BOOKS + "=?", new String[] {recentBooks.getTitle()}); mdb.close(); } catch (Exception e) { PrivateException ex = new PrivateException(e, mContext); ex.writeLogException(); } }
/** 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(); } }
/** * Delete a record of RecentBooks table * * @param recentBooks */ public void deleteRecentBook(DaisyBookInfo recentBooks) { try { SQLiteDatabase mdb = getWritableDatabase(); mdb.delete( TABLE_NAME_RECENT_BOOKS, NAME_KEY_RECENT_BOOKS + "=?", new String[] {String.valueOf(recentBooks.getTitle())}); mdb.close(); } catch (Exception e) { PrivateException ex = new PrivateException(e, mContext); ex.writeLogException(); } }