From 9dda62153a4d98c392cc3537299591dee15cb2e2 Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Fri, 26 Feb 2016 00:50:55 +0800 Subject: [PATCH] added remove feedback for saved searches --- .../api/twitter/model/ResponseList.java | 10 ++++++++ .../activity/support/MediaViewerActivity.java | 6 +++-- .../twidere/adapter/SavedSearchesAdapter.java | 16 ++++++++++-- .../support/SavedSearchesListFragment.java | 25 ++++++++++++++++--- .../message/SavedSearchDestroyedEvent.java | 21 ++++++++++++++++ .../twidere/util/AsyncTwitterWrapper.java | 4 ++- 6 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/message/SavedSearchDestroyedEvent.java diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/ResponseList.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/ResponseList.java index b0d412b61..1a9dea0a7 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/ResponseList.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/model/ResponseList.java @@ -54,6 +54,16 @@ public class ResponseList extends AbstractList implements TwitterResponse return list.get(location); } + @Override + public T remove(int location) { + return list.remove(location); + } + + @Override + public void clear() { + list.clear(); + } + @Override public int size() { return list.size(); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java index aefa6b86b..725fc0b8d 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/MediaViewerActivity.java @@ -36,6 +36,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; import android.support.v4.app.NavUtils; import android.support.v4.app.TaskStackBuilder; import android.support.v4.content.FileProvider; @@ -848,8 +849,9 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements @Override protected void onMediaLoadStateChange(@State int state) { mMediaLoadState = state; - if (getUserVisibleHint()) { - getActivity().supportInvalidateOptionsMenu(); + final FragmentActivity activity = getActivity(); + if (getUserVisibleHint() && activity != null) { + activity.supportInvalidateOptionsMenu(); } } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/adapter/SavedSearchesAdapter.java b/twidere/src/main/java/org/mariotaku/twidere/adapter/SavedSearchesAdapter.java index 9ab392162..63c2a5bbb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/adapter/SavedSearchesAdapter.java +++ b/twidere/src/main/java/org/mariotaku/twidere/adapter/SavedSearchesAdapter.java @@ -30,8 +30,8 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList; import org.mariotaku.twidere.api.twitter.model.SavedSearch; /** -* Created by mariotaku on 15/4/29. -*/ + * Created by mariotaku on 15/4/29. + */ public class SavedSearchesAdapter extends BaseAdapter { private ResponseList mData; @@ -77,4 +77,16 @@ public class SavedSearchesAdapter extends BaseAdapter { notifyDataSetChanged(); } + public boolean removeItem(long accountId, long searchId) { + if (mData == null) return false; + for (int i = 0, mDataSize = mData.size(); i < mDataSize; i++) { + SavedSearch search = mData.get(i); + if (search.getId() == searchId) { + mData.remove(i); + notifyDataSetChanged(); + return true; + } + } + return false; + } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java index 7df011c9a..d916c6c13 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/support/SavedSearchesListFragment.java @@ -28,15 +28,17 @@ import android.view.View; import android.widget.AdapterView; import android.widget.ListView; +import com.squareup.otto.Subscribe; + import org.mariotaku.twidere.adapter.SavedSearchesAdapter; +import org.mariotaku.twidere.api.twitter.model.ResponseList; +import org.mariotaku.twidere.api.twitter.model.SavedSearch; import org.mariotaku.twidere.loader.support.SavedSearchesLoader; +import org.mariotaku.twidere.model.message.SavedSearchDestroyedEvent; import java.util.Collections; import java.util.Comparator; -import org.mariotaku.twidere.api.twitter.model.ResponseList; -import org.mariotaku.twidere.api.twitter.model.SavedSearch; - import static org.mariotaku.twidere.util.Utils.openTweetSearch; public class SavedSearchesListFragment extends AbsContentListViewFragment implements @@ -64,6 +66,18 @@ public class SavedSearchesListFragment extends AbsContentListViewFragment