use of org.kiwix.kiwixmobile.database.BookDao in project kiwix-android by kiwix.
the class ZimFileSelectPresenter method loadLocalZimFileFromDb.
public void loadLocalZimFileFromDb(Context context) {
BookDao bookDao = new BookDao(KiwixDatabase.getInstance(context));
ArrayList<LibraryNetworkEntity.Book> books = bookDao.getBooks();
getMvpView().showFiles(books);
}
use of org.kiwix.kiwixmobile.database.BookDao in project kiwix-android by kiwix.
the class LibraryPresenter method loadRunningDownloadsFromDb.
void loadRunningDownloadsFromDb(Context context) {
BookDao bookDao = new BookDao(KiwixDatabase.getInstance(context));
for (LibraryNetworkEntity.Book book : bookDao.getDownloadingBooks()) {
if (!DownloadFragment.mDownloads.containsValue(book)) {
book.url = book.remoteUrl;
getMvpView().downloadFile(book);
}
}
}
use of org.kiwix.kiwixmobile.database.BookDao in project kiwix-android by kiwix.
the class DownloadService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) {
return START_NOT_STICKY;
}
String log = intent.getAction();
log += " : ";
if (intent.hasExtra(NOTIFICATION_ID)) {
log += intent.getIntExtra(NOTIFICATION_ID, -3);
}
Log.d(KIWIX_TAG, log);
if (intent.hasExtra(NOTIFICATION_ID) && intent.getAction().equals(ACTION_STOP)) {
stopDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
return START_NOT_STICKY;
}
if (intent.hasExtra(NOTIFICATION_ID) && (intent.getAction().equals(ACTION_PAUSE))) {
if (KiwixMobileActivity.wifiOnly && !NetworkUtils.isWiFi(getApplicationContext())) {
Log.i(KIWIX_TAG, "Not connected to WiFi, and wifiOnly is enabled");
startActivity(new Intent(this, ZimManageActivity.class).setAction(ACTION_NO_WIFI).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
this.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
} else {
toggleDownload(intent.getIntExtra(NOTIFICATION_ID, 0));
}
return START_NOT_STICKY;
}
SD_CARD = sharedPreferenceUtil.getPrefStorage();
KIWIX_ROOT = SD_CARD + "/Kiwix/";
KIWIX_ROOT = checkWritable(KIWIX_ROOT);
Log.d(KIWIX_TAG, "Using KIWIX_ROOT: " + KIWIX_ROOT);
notificationTitle = intent.getExtras().getString(DownloadIntent.DOWNLOAD_ZIM_TITLE);
LibraryNetworkEntity.Book book = (LibraryNetworkEntity.Book) intent.getSerializableExtra(EXTRA_BOOK);
int notificationID = book.getId().hashCode();
if (downloadStatus.get(notificationID, -1) == PAUSE || downloadStatus.get(notificationID, -1) == PLAY) {
return START_NOT_STICKY;
}
notifications.add(notificationTitle);
final Intent target = new Intent(this, KiwixMobileActivity.class);
target.putExtra(EXTRA_LIBRARY, true);
bookDao = new BookDao(KiwixDatabase.getInstance(this));
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), notificationID, target, PendingIntent.FLAG_CANCEL_CURRENT);
Intent pauseIntent = new Intent(this, this.getClass()).setAction(ACTION_PAUSE).putExtra(NOTIFICATION_ID, notificationID);
Intent stopIntent = new Intent(this, this.getClass()).setAction(ACTION_STOP).putExtra(NOTIFICATION_ID, notificationID);
PendingIntent pausePending = PendingIntent.getService(getBaseContext(), notificationID, pauseIntent, PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent stopPending = PendingIntent.getService(getBaseContext(), notificationID, stopIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Action pause = new NotificationCompat.Action(R.drawable.ic_pause_black_24dp, getString(R.string.download_pause), pausePending);
NotificationCompat.Action stop = new NotificationCompat.Action(R.drawable.ic_stop_black_24dp, getString(R.string.download_stop), stopPending);
notification.put(notificationID, new NotificationCompat.Builder(this).setContentTitle(getResources().getString(R.string.zim_file_downloading) + " " + notificationTitle).setProgress(100, 0, false).setSmallIcon(R.drawable.kiwix_notification).setColor(Color.BLACK).setContentIntent(pendingIntent).addAction(pause).addAction(stop).setOngoing(true));
notificationManager.notify(notificationID, notification.get(notificationID).build());
downloadStatus.put(notificationID, PLAY);
LibraryFragment.downloadingBooks.remove(book);
String url = intent.getExtras().getString(DownloadIntent.DOWNLOAD_URL_PARAMETER);
downloadBook(url, notificationID, book);
return START_REDELIVER_INTENT;
}
use of org.kiwix.kiwixmobile.database.BookDao in project kiwix-android by kiwix.
the class ZimFileSelectFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
KiwixApplication.getApplicationComponent().inject(this);
zimManageActivity = (ZimManageActivity) super.getActivity();
presenter.attachView(this);
// Replace LinearLayout by the type of the root element of the layout you're trying to load
llLayout = (RelativeLayout) inflater.inflate(R.layout.zim_list, container, false);
new LanguageUtils(super.getActivity()).changeFont(super.getActivity().getLayoutInflater(), sharedPreferenceUtil);
mFileMessage = llLayout.findViewById(R.id.file_management_no_files);
mZimFileList = llLayout.findViewById(R.id.zimfilelist);
mFiles = new ArrayList<>();
// SwipeRefreshLayout for the list view
swipeRefreshLayout = llLayout.findViewById(R.id.zim_swiperefresh);
swipeRefreshLayout.setOnRefreshListener(this::refreshFragment);
// A boolean to distinguish between a user refresh and a normal loading
mHasRefresh = false;
mRescanAdapter = new RescanDataAdapter(zimManageActivity, 0, mFiles);
// Allow temporary use of ZimContentProvider to query books
ZimContentProvider.canIterate = true;
presenter.loadLocalZimFileFromDb(zimManageActivity);
bookDao = new BookDao(KiwixDatabase.getInstance(zimManageActivity));
// We must return the loaded Layout
return llLayout;
}
Aggregations