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
Родитель 178692e841
Коммит 15accfcf63
8 изменённых файлов: 51 добавлений и 37 удалений

Просмотреть файл

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

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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,15 +249,11 @@ 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();
return true;
}
(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,22 +358,34 @@ public abstract class HomeFragment extends Fragment {
}
}
BrowserDB.removeBookmarksWithURL(cr, mUrl);
BrowserDB.removeHistoryEntry(cr, mUrl);
switch(mType) {
case BOOKMARKS:
BrowserDB.removeBookmarksWithURL(cr, mUrl);
break;
BrowserDB.removeReadingListItemWithURL(cr, mUrl);
case HISTORY:
BrowserDB.removeHistoryEntry(cr, mUrl);
break;
final JSONObject json = new JSONObject();
try {
json.put("url", mUrl);
json.put("notify", false);
} catch (JSONException e) {
Log.e(LOGTAG, "error building JSON arguments");
case READING_LIST:
BrowserDB.removeReadingListItemWithURL(cr, mUrl);
final JSONObject json = new JSONObject();
try {
json.put("url", mUrl);
json.put("notify", false);
} catch (JSONException e) {
Log.e(LOGTAG, "error building JSON arguments");
}
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", json.toString());
GeckoAppShell.sendEventToGecko(e);
break;
default:
Log.e(LOGTAG, "Can't remove item type " + mType.toString());
break;
}
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", json.toString());
GeckoAppShell.sendEventToGecko(e);
return null;
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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