added remove feedback for saved searches

This commit is contained in:
Mariotaku Lee 2016-02-26 00:50:55 +08:00
parent 4788ab956d
commit 9dda62153a
6 changed files with 74 additions and 8 deletions

View File

@ -54,6 +54,16 @@ public class ResponseList<T> extends AbstractList<T> 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();

View File

@ -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();
}
}
}

View File

@ -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<SavedSearch> 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;
}
}

View File

@ -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<SavedSearchesAdapter> implements
@ -64,6 +66,18 @@ public class SavedSearchesListFragment extends AbsContentListViewFragment<SavedS
showProgress();
}
@Override
public void onStop() {
mBus.unregister(this);
super.onStop();
}
@Override
public void onStart() {
super.onStart();
mBus.register(this);
}
@NonNull
@Override
protected SavedSearchesAdapter onCreateAdapter(Context context, boolean compact) {
@ -116,4 +130,9 @@ public class SavedSearchesListFragment extends AbsContentListViewFragment<SavedS
return getLoaderManager().hasRunningLoaders();
}
@Subscribe
public void onSavedSearchDestroyed(SavedSearchDestroyedEvent event) {
SavedSearchesAdapter adapter = getAdapter();
adapter.removeItem(event.getAccountId(), event.getSearchId());
}
}

View File

@ -0,0 +1,21 @@
package org.mariotaku.twidere.model.message;
/**
* Created by mariotaku on 16/2/26.
*/
public class SavedSearchDestroyedEvent {
private final long accountId, searchId;
public SavedSearchDestroyedEvent(long accountId, long searchId) {
this.accountId = accountId;
this.searchId = searchId;
}
public long getAccountId() {
return accountId;
}
public long getSearchId() {
return searchId;
}
}

View File

@ -66,6 +66,7 @@ import org.mariotaku.twidere.model.message.FollowRequestTaskEvent;
import org.mariotaku.twidere.model.message.FriendshipUpdatedEvent;
import org.mariotaku.twidere.model.message.FriendshipUserUpdatedEvent;
import org.mariotaku.twidere.model.message.ProfileUpdatedEvent;
import org.mariotaku.twidere.model.message.SavedSearchDestroyedEvent;
import org.mariotaku.twidere.model.message.StatusDestroyedEvent;
import org.mariotaku.twidere.model.message.StatusListChangedEvent;
import org.mariotaku.twidere.model.message.StatusRetweetedEvent;
@ -82,6 +83,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.DirectMessages.Outbox;
import org.mariotaku.twidere.provider.TwidereDataStore.Drafts;
import org.mariotaku.twidere.provider.TwidereDataStore.Statuses;
import org.mariotaku.twidere.service.BackgroundOperationService;
import org.mariotaku.twidere.task.AbstractTask;
import org.mariotaku.twidere.task.GetActivitiesAboutMeTask;
import org.mariotaku.twidere.task.GetActivitiesByFriendsTask;
import org.mariotaku.twidere.task.GetDirectMessagesTask;
@ -89,7 +91,6 @@ import org.mariotaku.twidere.task.GetHomeTimelineTask;
import org.mariotaku.twidere.task.GetLocalTrendsTask;
import org.mariotaku.twidere.task.GetSavedSearchesTask;
import org.mariotaku.twidere.task.ManagedAsyncTask;
import org.mariotaku.twidere.task.AbstractTask;
import org.mariotaku.twidere.task.twitter.GetActivitiesTask;
import org.mariotaku.twidere.task.util.TaskStarter;
import org.mariotaku.twidere.util.collection.LongSparseMap;
@ -1719,6 +1720,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
if (result.hasData()) {
final String message = mContext.getString(R.string.search_name_deleted, result.getData().getQuery());
Utils.showOkMessage(mContext, message, false);
bus.post(new SavedSearchDestroyedEvent(mAccountId, mSearchId));
} else {
Utils.showErrorMessage(mContext, R.string.action_deleting_search, result.getException(), false);
}