made items actually deltable

This commit is contained in:
Christian Schabesberger 2018-04-24 22:02:23 +02:00
parent c470909f19
commit a09b9d3e4d
2 changed files with 20 additions and 19 deletions

View File

@ -63,24 +63,15 @@ public class SuggestionListAdapter extends RecyclerView.Adapter<SuggestionListAd
public void onBindViewHolder(SuggestionItemHolder holder, int position) { public void onBindViewHolder(SuggestionItemHolder holder, int position) {
final SuggestionItem currentItem = getItem(position); final SuggestionItem currentItem = getItem(position);
holder.updateFrom(currentItem); holder.updateFrom(currentItem);
holder.queryView.setOnClickListener(new View.OnClickListener() { holder.queryView.setOnClickListener(v -> {
@Override
public void onClick(View v) {
if (listener != null) listener.onSuggestionItemSelected(currentItem); if (listener != null) listener.onSuggestionItemSelected(currentItem);
}
}); });
holder.queryView.setOnLongClickListener(new View.OnLongClickListener() { holder.queryView.setOnLongClickListener(v -> {
@Override
public boolean onLongClick(View v) {
if (listener != null) listener.onSuggestionItemLongClick(currentItem); if (listener != null) listener.onSuggestionItemLongClick(currentItem);
return true; return true;
}
}); });
holder.insertView.setOnClickListener(new View.OnClickListener() { holder.insertView.setOnClickListener(v -> {
@Override
public void onClick(View v) {
if (listener != null) listener.onSuggestionItemInserted(currentItem); if (listener != null) listener.onSuggestionItemInserted(currentItem);
}
}); });
} }

View File

@ -7,6 +7,7 @@ import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -32,6 +33,8 @@ import java.util.List;
import icepick.State; import icepick.State;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
public abstract class StatisticsPlaylistFragment public abstract class StatisticsPlaylistFragment
extends BaseLocalListFragment<List<StreamStatisticsEntry>, Void> { extends BaseLocalListFragment<List<StreamStatisticsEntry>, Void> {
@ -46,6 +49,8 @@ public abstract class StatisticsPlaylistFragment
/* Used for independent events */ /* Used for independent events */
private Subscription databaseSubscription; private Subscription databaseSubscription;
private HistoryRecordManager recordManager; private HistoryRecordManager recordManager;
private CompositeDisposable disposables = new CompositeDisposable();
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Abstracts // Abstracts
@ -288,11 +293,16 @@ public abstract class StatisticsPlaylistFragment
.get(index); .get(index);
if(infoItem instanceof StreamStatisticsEntry) { if(infoItem instanceof StreamStatisticsEntry) {
final StreamStatisticsEntry entry = (StreamStatisticsEntry) infoItem; final StreamStatisticsEntry entry = (StreamStatisticsEntry) infoItem;
recordManager.deleteStreamHistory(entry.streamId); final Disposable onDelte = recordManager.deleteStreamHistory(entry.streamId)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
howManyDelted -> Snackbar.make(getView(), R.string.one_item_deleted,
Snackbar.LENGTH_SHORT).show(),
throwable -> showSnackBarError(throwable,
UserAction.SOMETHING_ELSE, "none",
"Deleting item failed", R.string.general_error));
Snackbar.make(getView(), R.string.one_item_deleted, Snackbar.LENGTH_SHORT) disposables.add(onDelte);
.show();
startLoading(true);
} }
} }