mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Merge pull request #1986 from akkywadhwa/main-presenter-kotlin
Fixed #1985 Converted MainPresenter to Kotlin
This commit is contained in:
commit
adcde1dc31
@ -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
|
||||
}
|
||||
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
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<MainContract.View>
|
||||
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<List<BooksOnDiskListItem>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
compositeDisposable.add(d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<BooksOnDiskListItem> books) {
|
||||
view.addBooks(books);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "Unable to load books", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveBooks(List<BooksOnDiskListItem.BookOnDisk> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2019 Kiwix <android.kiwix.org>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<View?>(), 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<BookOnDisk>) {
|
||||
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) })
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user