Bug 1062257 - Handle HomeFragment deletions by panel/type instead of universally. r=margaret

This commit is contained in:
Chenxia Liu 2014-09-12 17:12:33 -07:00
parent 178692e841
commit 15accfcf63
8 changed files with 51 additions and 37 deletions

View File

@ -13,12 +13,13 @@ import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.home.BookmarksListAdapter.FolderInfo;
import org.mozilla.gecko.home.BookmarksListAdapter.OnRefreshFolderListener;
import org.mozilla.gecko.home.BookmarksListAdapter.RefreshType;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
@ -78,6 +79,7 @@ public class BookmarksPanel extends HomeFragment {
info.url = cursor.getString(cursor.getColumnIndexOrThrow(Bookmarks.URL));
info.title = cursor.getString(cursor.getColumnIndexOrThrow(Bookmarks.TITLE));
info.bookmarkId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
info.itemType = RemoveItemType.BOOKMARKS;
return info;
}
});

View File

@ -18,8 +18,8 @@ import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserContract.History;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.util.ThreadUtils;
import android.app.AlertDialog;
import android.content.ContentResolver;
@ -95,6 +95,7 @@ public class HistoryPanel extends HomeFragment {
info.url = cursor.getString(cursor.getColumnIndexOrThrow(Combined.URL));
info.title = cursor.getString(cursor.getColumnIndexOrThrow(Combined.TITLE));
info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(Combined.HISTORY_ID));
info.itemType = RemoveItemType.HISTORY;
final int bookmarkIdCol = cursor.getColumnIndexOrThrow(Combined.BOOKMARK_ID);
if (cursor.isNull(bookmarkIdCol)) {
// If this is a combined cursor, we may get a history item without a

View File

@ -7,7 +7,6 @@ package org.mozilla.gecko.home;
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
import org.mozilla.gecko.home.HomeConfig.PanelType;
import org.mozilla.gecko.home.HomePager;
import android.content.Context;
import android.os.Bundle;

View File

@ -24,6 +24,12 @@ public class HomeContextMenuInfo extends AdapterContextMenuInfo {
public int historyId = -1;
public int bookmarkId = -1;
public int readingListItemId = -1;
public RemoveItemType itemType = null;
// Item type to be handled with "Remove" selection.
public static enum RemoveItemType {
BOOKMARKS, HISTORY, READING_LIST
}
public HomeContextMenuInfo(View targetView, int position, long id) {
super(targetView, position, id);

View File

@ -21,6 +21,7 @@ import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.db.BrowserContract.SuggestedSites;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.TopSitesGridView.TopSitesGridContextMenuInfo;
import org.mozilla.gecko.util.Clipboard;
@ -248,16 +249,12 @@ public abstract class HomeFragment extends Fragment {
}
if (itemId == R.id.home_remove) {
if (info instanceof TopSitesGridContextMenuInfo) {
(new RemoveItemByUrlTask(context, info.url, info.position)).execute();
return true;
}
// For Top Sites grid items, position is required in case item is Pinned.
final int position = info instanceof TopSitesGridContextMenuInfo ? info.position : -1;
if (info.isInReadingList() || info.hasBookmarkId() || info.hasHistoryId()) {
(new RemoveItemByUrlTask(context, info.url)).execute();
(new RemoveItemByUrlTask(context, info.url, info.itemType, position)).execute();
return true;
}
}
return false;
}
@ -316,7 +313,6 @@ public abstract class HomeFragment extends Fragment {
return mCanLoadHint;
}
protected abstract void load();
protected boolean canLoad() {
@ -332,27 +328,22 @@ public abstract class HomeFragment extends Fragment {
mIsLoaded = true;
}
private static class RemoveItemByUrlTask extends UIAsyncTask.WithoutParams<Void> {
protected static class RemoveItemByUrlTask extends UIAsyncTask.WithoutParams<Void> {
private final Context mContext;
private final String mUrl;
private final RemoveItemType mType;
private final int mPosition;
/**
* Remove bookmark/history/reading list item by url.
*/
public RemoveItemByUrlTask(Context context, String url) {
this(context, url, -1);
}
/**
* Remove bookmark/history/reading list item by url, and also unpin the
* Remove bookmark/history/reading list type item by url, and also unpin the
* Top Sites grid item at index <code>position</code>.
*/
public RemoveItemByUrlTask(Context context, String url, int position) {
public RemoveItemByUrlTask(Context context, String url, RemoveItemType type, int position) {
super(ThreadUtils.getBackgroundHandler());
mContext = context;
mUrl = url;
mType = type;
mPosition = position;
}
@ -367,9 +358,16 @@ public abstract class HomeFragment extends Fragment {
}
}
switch(mType) {
case BOOKMARKS:
BrowserDB.removeBookmarksWithURL(cr, mUrl);
BrowserDB.removeHistoryEntry(cr, mUrl);
break;
case HISTORY:
BrowserDB.removeHistoryEntry(cr, mUrl);
break;
case READING_LIST:
BrowserDB.removeReadingListItemWithURL(cr, mUrl);
final JSONObject json = new JSONObject();
@ -382,7 +380,12 @@ public abstract class HomeFragment extends Fragment {
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", json.toString());
GeckoAppShell.sendEventToGecko(e);
break;
default:
Log.e(LOGTAG, "Can't remove item type " + mType.toString());
break;
}
return null;
}

View File

@ -14,6 +14,7 @@ import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.db.BrowserContract.ReadingListItems;
import org.mozilla.gecko.db.BrowserContract.URLColumns;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import android.content.Context;
@ -97,6 +98,7 @@ public class ReadingListPanel extends HomeFragment {
info.url = cursor.getString(cursor.getColumnIndexOrThrow(ReadingListItems.URL));
info.title = cursor.getString(cursor.getColumnIndexOrThrow(ReadingListItems.TITLE));
info.readingListItemId = cursor.getInt(cursor.getColumnIndexOrThrow(ReadingListItems._ID));
info.itemType = RemoveItemType.READING_LIST;
return info;
}
});

View File

@ -12,7 +12,6 @@ import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.ThumbnailHelper;
import org.mozilla.gecko.db.BrowserContract.TopSites;
import org.mozilla.gecko.db.TopSitesCursorWrapper;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.util.StringUtils;
@ -20,7 +19,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
@ -277,6 +275,7 @@ public class TopSitesGridView extends GridView {
public TopSitesGridContextMenuInfo(View targetView, int position, long id) {
super(targetView, position, id);
this.itemType = RemoveItemType.HISTORY;
}
}
}

View File

@ -25,6 +25,7 @@ import org.mozilla.gecko.db.URLMetadata;
import org.mozilla.gecko.favicons.Favicons;
import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.home.PinSiteDialog.OnSiteSelectedListener;
import org.mozilla.gecko.home.TopSitesGridView.OnEditPinnedSiteListener;
@ -179,6 +180,7 @@ public class TopSitesPanel extends HomeFragment {
info.url = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.URL));
info.title = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.TITLE));
info.historyId = cursor.getInt(cursor.getColumnIndexOrThrow(TopSites.HISTORY_ID));
info.itemType = RemoveItemType.HISTORY;
final int bookmarkIdCol = cursor.getColumnIndexOrThrow(TopSites.BOOKMARK_ID);
if (cursor.isNull(bookmarkIdCol)) {
// If this is a combined cursor, we may get a history item without a