diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DialogModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DialogModule.kt index d9ad67405..c60954060 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DialogModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DialogModule.kt @@ -34,5 +34,5 @@ abstract class DialogModule { abstract fun bindDialogShower(alertDialogShower: AlertDialogShower): DialogShower @Binds - abstract fun bindMainPresenter(mainPresenter: MainPresenter): MainContract.Presenter + internal abstract fun bindMainPresenter(mainPresenter: MainPresenter): MainContract.Presenter } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainPresenter.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainPresenter.java deleted file mode 100644 index d80fdc393..000000000 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainPresenter.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.kiwix.kiwixmobile.core.main; - -import android.util.Log; -import io.reactivex.CompletableObserver; -import io.reactivex.SingleObserver; -import io.reactivex.disposables.Disposable; -import java.util.List; -import javax.inject.Inject; -import org.kiwix.kiwixmobile.core.base.BasePresenter; -import org.kiwix.kiwixmobile.core.bookmark.BookmarkItem; -import org.kiwix.kiwixmobile.core.data.DataSource; -import org.kiwix.kiwixmobile.core.di.ActivityScope; -import org.kiwix.kiwixmobile.core.history.HistoryListItem; -import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem; - -/** - * Presenter for {@link MainActivity}. - */ - -@ActivityScope -public class MainPresenter extends BasePresenter - implements MainContract.Presenter { - - private static final String TAG = "MainPresenter"; - private final DataSource dataSource; - - @Inject public MainPresenter(DataSource dataSource) { - this.dataSource = dataSource; - } - - @Override - public void loadBooks() { - dataSource.getLanguageCategorizedBooks() - .subscribe(new SingleObserver>() { - @Override - public void onSubscribe(Disposable d) { - compositeDisposable.add(d); - } - - @Override - public void onSuccess(List books) { - view.addBooks(books); - } - - @Override - public void onError(Throwable e) { - Log.e(TAG, "Unable to load books", e); - } - }); - } - - @Override - public void saveBooks(List book) { - dataSource.saveBooks(book) - .subscribe(new CompletableObserver() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onComplete() { - loadBooks(); - } - - @Override - public void onError(Throwable e) { - Log.e(TAG, "Unable to save books", e); - } - }); - } - - @Override - public void saveHistory(HistoryListItem.HistoryItem history) { - dataSource.saveHistory(history) - .subscribe(new CompletableObserver() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onComplete() { - - } - - @Override - public void onError(Throwable e) { - Log.e(TAG, "Unable to save history", e); - } - }); - } - - @Override - public void saveBookmark(BookmarkItem bookmark) { - dataSource.saveBookmark(bookmark) - .subscribe(new CompletableObserver() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onComplete() { - - } - - @Override - public void onError(Throwable e) { - Log.e(TAG, "Unable to save bookmark", e); - } - }); - } - - @Override - public void deleteBookmark(String bookmarkUrl) { - dataSource.deleteBookmark(bookmarkUrl) - .subscribe(new CompletableObserver() { - @Override - public void onSubscribe(Disposable d) { - - } - - @Override - public void onComplete() { - - } - - @Override - public void onError(Throwable e) { - Log.e(TAG, "Unable to delete bookmark", e); - } - }); - } -} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainPresenter.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainPresenter.kt new file mode 100644 index 000000000..a87f02de1 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainPresenter.kt @@ -0,0 +1,62 @@ +/* + * Kiwix Android + * Copyright (c) 2019 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package org.kiwix.kiwixmobile.core.main + +import android.util.Log +import org.kiwix.kiwixmobile.core.base.BasePresenter +import org.kiwix.kiwixmobile.core.bookmark.BookmarkItem +import org.kiwix.kiwixmobile.core.data.DataSource +import org.kiwix.kiwixmobile.core.di.ActivityScope +import org.kiwix.kiwixmobile.core.history.HistoryListItem.HistoryItem +import org.kiwix.kiwixmobile.core.main.MainContract.Presenter +import org.kiwix.kiwixmobile.core.main.MainContract.View +import org.kiwix.kiwixmobile.core.zim_manager.fileselect_view.adapter.BooksOnDiskListItem.BookOnDisk +import javax.inject.Inject + +private const val TAG = "MainPresenter" + +@ActivityScope +internal class MainPresenter @Inject constructor(private val dataSource: DataSource) : + BasePresenter(), Presenter { + override fun loadBooks() { + compositeDisposable.add( + dataSource.languageCategorizedBooks.subscribe( + view!!::addBooks + ) { e -> Log.e(TAG, "Unable to load books", e) }) + } + + override fun saveBooks(book: List) { + dataSource.saveBooks(book) + .subscribe(::loadBooks) { e -> Log.e(TAG, "Unable to save books", e) } + } + + override fun saveHistory(history: HistoryItem) { + dataSource.saveHistory(history) + .subscribe({}, { e -> Log.e(TAG, "Unable to save history", e) }) + } + + override fun saveBookmark(bookmark: BookmarkItem) { + dataSource.saveBookmark(bookmark) + .subscribe({}, { e -> Log.e(TAG, "Unable to save bookmark", e) }) + } + + override fun deleteBookmark(bookmarkUrl: String) { + dataSource.deleteBookmark(bookmarkUrl) + .subscribe({}, { e -> Log.e(TAG, "Unable to delete bookmark", e) }) + } +}