mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-15 10:26:53 -04:00
Add clear history option
This commit is contained in:
parent
a086bb74ec
commit
0947fe9acc
@ -25,4 +25,6 @@ public interface DataSource {
|
||||
Completable saveHistory(History history);
|
||||
|
||||
Completable deleteHistory(List<History> historyList);
|
||||
|
||||
Completable clearHistory();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package org.kiwix.kiwixmobile.data;
|
||||
import org.kiwix.kiwixmobile.data.local.dao.BookDao;
|
||||
import org.kiwix.kiwixmobile.data.local.dao.HistoryDao;
|
||||
import org.kiwix.kiwixmobile.data.local.dao.NetworkLanguageDao;
|
||||
import org.kiwix.kiwixmobile.data.local.dao.RecentSearchDao;
|
||||
import org.kiwix.kiwixmobile.data.local.entity.History;
|
||||
import org.kiwix.kiwixmobile.di.qualifiers.IO;
|
||||
import org.kiwix.kiwixmobile.di.qualifiers.MainThread;
|
||||
@ -29,19 +30,24 @@ import io.reactivex.Single;
|
||||
public class Repository implements DataSource {
|
||||
|
||||
private final BookDao bookDao;
|
||||
private final NetworkLanguageDao languageDao;
|
||||
private final HistoryDao historyDao;
|
||||
private final NetworkLanguageDao languageDao;
|
||||
private final RecentSearchDao recentSearchDao;
|
||||
private final Scheduler io;
|
||||
private final Scheduler mainThread;
|
||||
|
||||
@Inject
|
||||
Repository(@IO Scheduler io, @MainThread Scheduler mainThread,
|
||||
BookDao bookDao, NetworkLanguageDao languageDao, HistoryDao historyDao) {
|
||||
BookDao bookDao,
|
||||
HistoryDao historyDao,
|
||||
NetworkLanguageDao languageDao,
|
||||
RecentSearchDao recentSearchDao) {
|
||||
this.io = io;
|
||||
this.mainThread = mainThread;
|
||||
this.bookDao = bookDao;
|
||||
this.languageDao = languageDao;
|
||||
this.historyDao = historyDao;
|
||||
this.recentSearchDao = recentSearchDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,4 +121,13 @@ public class Repository implements DataSource {
|
||||
return Completable.fromAction(() -> historyDao.deleteHistory(historyList))
|
||||
.subscribeOn(io);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Completable clearHistory() {
|
||||
return Completable.fromAction(() -> {
|
||||
historyDao.deleteHistory(historyDao.getHistoryList(false));
|
||||
recentSearchDao.deleteSearchHistory();
|
||||
})
|
||||
.subscribeOn(io);
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,9 @@ public class HistoryDao {
|
||||
|
||||
public void deleteHistory(List<History> historyList) {
|
||||
for (History history : historyList) {
|
||||
kiwixDatabase.deleteWhere(History.class, History.TIME_STAMP.eq(history.getTimeStamp()));
|
||||
if (history != null) {
|
||||
kiwixDatabase.deleteWhere(History.class, History.TIME_STAMP.eq(history.getTimeStamp()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.base.BaseActivity;
|
||||
@ -158,11 +159,20 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
|
||||
case R.id.menu_history_toggle:
|
||||
item.setChecked(!item.isChecked());
|
||||
sharedPreferenceUtil.setShowHistoryCurrentBook(item.isChecked());
|
||||
presenter.loadHistory(sharedPreferenceUtil.getShowHistoryCurrentBook());
|
||||
return true;
|
||||
|
||||
case R.id.menu_history_clear:
|
||||
presenter.deleteHistory(new ArrayList<>(fullHistory));
|
||||
fullHistory.clear();
|
||||
historyList.clear();
|
||||
historyAdapter.notifyDataSetChanged();
|
||||
Toast.makeText(this, R.string.all_history_cleared_toast, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ import org.kiwix.kiwixmobile.BuildConfig;
|
||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.base.BaseActivity;
|
||||
import org.kiwix.kiwixmobile.data.local.dao.RecentSearchDao;
|
||||
import org.kiwix.kiwixmobile.main.MainActivity;
|
||||
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
||||
import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil;
|
||||
@ -115,23 +114,20 @@ public class KiwixSettingsActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
public static class PrefsFragment extends PreferenceFragment implements
|
||||
SettingsContract.View,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener, StorageSelectDialog.OnSelectListener {
|
||||
|
||||
@Inject
|
||||
SettingsPresenter presenter;
|
||||
@Inject
|
||||
SharedPreferenceUtil sharedPreferenceUtil;
|
||||
|
||||
private SliderPreference mSlider;
|
||||
|
||||
@Inject
|
||||
RecentSearchDao recentSearchDao;
|
||||
|
||||
@Inject SharedPreferenceUtil sharedPreferenceUtil;
|
||||
|
||||
void setupDagger() {
|
||||
KiwixApplication.getApplicationComponent().inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
KiwixApplication.getApplicationComponent().inject(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setupDagger();
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
boolean auto_night_mode = sharedPreferenceUtil.getPrefAutoNightMode();
|
||||
@ -158,10 +154,6 @@ public class KiwixSettingsActivity extends BaseActivity {
|
||||
new LanguageUtils(getActivity()).changeFont(getActivity().getLayoutInflater(), sharedPreferenceUtil);
|
||||
}
|
||||
|
||||
private void deleteSearchHistoryFromDb() {
|
||||
recentSearchDao.deleteSearchHistory();
|
||||
}
|
||||
|
||||
private void setStorage() {
|
||||
if (BuildConfig.IS_CUSTOM_APP) {
|
||||
getPreferenceScreen().removePreference(findPreference("pref_storage"));
|
||||
@ -274,15 +266,14 @@ public class KiwixSettingsActivity extends BaseActivity {
|
||||
int warningResId;
|
||||
if (sharedPreferenceUtil.nightMode()) {
|
||||
warningResId = R.drawable.ic_warning_white;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
warningResId = R.drawable.ic_warning_black;
|
||||
}
|
||||
new AlertDialog.Builder(getActivity(), dialogStyle())
|
||||
.setTitle(getResources().getString(R.string.clear_all_history_dialog_title))
|
||||
.setMessage(getResources().getString(R.string.clear_recent_and_tabs_history_dialog))
|
||||
.setPositiveButton(android.R.string.yes, (dialog, which) -> {
|
||||
deleteSearchHistoryFromDb();
|
||||
presenter.clearHistory();
|
||||
allHistoryCleared = true;
|
||||
Toast.makeText(getActivity(), getResources().getString(R.string.all_history_cleared_toast), Toast.LENGTH_SHORT).show();
|
||||
})
|
||||
@ -321,7 +312,7 @@ public class KiwixSettingsActivity extends BaseActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void openFolderSelect(){
|
||||
public void openFolderSelect() {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
StorageSelectDialog dialogFragment = new StorageSelectDialog();
|
||||
Bundle b = new Bundle();
|
||||
|
@ -0,0 +1,13 @@
|
||||
package org.kiwix.kiwixmobile.settings;
|
||||
|
||||
import org.kiwix.kiwixmobile.base.BaseContract;
|
||||
|
||||
interface SettingsContract {
|
||||
interface View extends BaseContract.View<Presenter> {
|
||||
|
||||
}
|
||||
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
void clearHistory();
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.kiwix.kiwixmobile.settings;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.kiwix.kiwixmobile.base.BasePresenter;
|
||||
import org.kiwix.kiwixmobile.data.DataSource;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.reactivex.CompletableObserver;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
|
||||
class SettingsPresenter extends BasePresenter<SettingsContract.View> implements SettingsContract.Presenter {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
SettingsPresenter(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHistory() {
|
||||
dataSource.clearHistory()
|
||||
.subscribe(new CompletableObserver() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("SettingsPresenter", e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -15,4 +15,9 @@
|
||||
android:checkable="true"
|
||||
android:title="@string/history_from_current_book"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_history_clear"
|
||||
android:title="@string/pref_clear_all_history_title"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
Loading…
x
Reference in New Issue
Block a user