Add confirmation dialog before reseting statistics
This commit is contained in:
parent
49660946f8
commit
4f65aa015a
@ -1,6 +1,7 @@
|
|||||||
package de.danoeh.antennapod.fragment.preferences;
|
package de.danoeh.antennapod.fragment.preferences;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -23,6 +24,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||||
import de.danoeh.antennapod.adapter.StatisticsListAdapter;
|
import de.danoeh.antennapod.adapter.StatisticsListAdapter;
|
||||||
|
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
||||||
import de.danoeh.antennapod.core.storage.DBReader;
|
import de.danoeh.antennapod.core.storage.DBReader;
|
||||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
@ -76,7 +78,8 @@ public class StatisticsFragment extends Fragment {
|
|||||||
refreshStatistics();
|
refreshStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void onDestroyView() {
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
if (disposable != null) {
|
if (disposable != null) {
|
||||||
disposable.dispose();
|
disposable.dispose();
|
||||||
@ -96,7 +99,7 @@ public class StatisticsFragment extends Fragment {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (item.getItemId() == R.id.statistics_reset) {
|
if (item.getItemId() == R.id.statistics_reset) {
|
||||||
resetStatistics();
|
confirmResetStatistics();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@ -125,21 +128,37 @@ public class StatisticsFragment extends Fragment {
|
|||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetStatistics() {
|
private void confirmResetStatistics() {
|
||||||
if (!countAll) {
|
if (!countAll) {
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
ConfirmationDialog conDialog = new ConfirmationDialog(
|
||||||
feedStatisticsList.setVisibility(View.GONE);
|
getActivity(),
|
||||||
if (disposable != null) {
|
R.string.statistics_reset_data_title,
|
||||||
disposable.dispose();
|
R.string.statistics_reset_data_msg) {
|
||||||
}
|
|
||||||
|
|
||||||
disposable = Completable.fromFuture(DBWriter.resetStatistics())
|
@Override
|
||||||
.subscribeOn(Schedulers.io())
|
public void onConfirmButtonPressed(
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
DialogInterface dialog) {
|
||||||
.subscribe(this::refreshStatistics, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
dialog.dismiss();
|
||||||
|
doResetStatistics();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
conDialog.createNewDialog().show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doResetStatistics() {
|
||||||
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
|
feedStatisticsList.setVisibility(View.GONE);
|
||||||
|
if (disposable != null) {
|
||||||
|
disposable.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
disposable = Completable.fromFuture(DBWriter.resetStatistics())
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(this::refreshStatistics, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshStatistics() {
|
private void refreshStatistics() {
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
progressBar.setVisibility(View.VISIBLE);
|
||||||
feedStatisticsList.setVisibility(View.GONE);
|
feedStatisticsList.setVisibility(View.GONE);
|
||||||
|
@ -38,6 +38,8 @@
|
|||||||
<string name="statistics_mode_count_all">Sum up all podcasts marked as played</string>
|
<string name="statistics_mode_count_all">Sum up all podcasts marked as played</string>
|
||||||
<string name="statistics_speed_not_counted">Notice: Playback speed is never taken into account.</string>
|
<string name="statistics_speed_not_counted">Notice: Playback speed is never taken into account.</string>
|
||||||
<string name="statistics_reset_data">Reset statistics data</string>
|
<string name="statistics_reset_data">Reset statistics data</string>
|
||||||
|
<string name="statistics_reset_data_title">Reset statistics data</string>
|
||||||
|
<string name="statistics_reset_data_msg">This will erase the history of duration played for all episodes. Are you sure you want to proceed ?</string>
|
||||||
|
|
||||||
<!-- Main activity -->
|
<!-- Main activity -->
|
||||||
<string name="drawer_open">Open menu</string>
|
<string name="drawer_open">Open menu</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user