зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1322714 - Convert RecentTabsAdapter and GeckoPreferences events; r=sebastian
Convert "ClosedTabs:Data" and "Sanitize:Finished" events used in RecentTabsAdapter and GeckoPreferences from NativeJSObject events to GeckoBundle events.
This commit is contained in:
Родитель
4898d47131
Коммит
89ed582051
|
@ -25,9 +25,9 @@ import org.mozilla.gecko.R;
|
|||
import org.mozilla.gecko.SessionParser;
|
||||
import org.mozilla.gecko.home.CombinedHistoryAdapter.RecentTabsUpdateHandler;
|
||||
import org.mozilla.gecko.home.CombinedHistoryPanel.PanelStateUpdateHandler;
|
||||
import org.mozilla.gecko.util.BundleEventListener;
|
||||
import org.mozilla.gecko.util.EventCallback;
|
||||
import org.mozilla.gecko.util.NativeEventListener;
|
||||
import org.mozilla.gecko.util.NativeJSObject;
|
||||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -37,7 +37,8 @@ import static org.mozilla.gecko.home.CombinedHistoryItem.ItemType;
|
|||
import static org.mozilla.gecko.home.CombinedHistoryPanel.OnPanelLevelChangeListener.PanelLevel.CHILD_RECENT_TABS;
|
||||
|
||||
public class RecentTabsAdapter extends RecyclerView.Adapter<CombinedHistoryItem>
|
||||
implements CombinedHistoryRecyclerView.AdapterContextMenuBuilder, NativeEventListener {
|
||||
implements CombinedHistoryRecyclerView.AdapterContextMenuBuilder,
|
||||
BundleEventListener {
|
||||
private static final String LOGTAG = "GeckoRecentTabsAdapter";
|
||||
|
||||
private static final int NAVIGATION_BACK_BUTTON_INDEX = 0;
|
||||
|
@ -82,26 +83,26 @@ public class RecentTabsAdapter extends RecyclerView.Adapter<CombinedHistoryItem>
|
|||
}
|
||||
|
||||
public void startListeningForClosedTabs() {
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this, "ClosedTabs:Data");
|
||||
EventDispatcher.getInstance().registerUiThreadListener(this, "ClosedTabs:Data");
|
||||
GeckoAppShell.notifyObservers("ClosedTabs:StartNotifications", null);
|
||||
}
|
||||
|
||||
public void stopListeningForClosedTabs() {
|
||||
GeckoAppShell.notifyObservers("ClosedTabs:StopNotifications", null);
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "ClosedTabs:Data");
|
||||
EventDispatcher.getInstance().unregisterUiThreadListener(this, "ClosedTabs:Data");
|
||||
recentlyClosedTabsReceived = false;
|
||||
}
|
||||
|
||||
public void startListeningForHistorySanitize() {
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener(this, "Sanitize:Finished");
|
||||
EventDispatcher.getInstance().registerUiThreadListener(this, "Sanitize:Finished");
|
||||
}
|
||||
|
||||
public void stopListeningForHistorySanitize() {
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Sanitize:Finished");
|
||||
EventDispatcher.getInstance().unregisterUiThreadListener(this, "Sanitize:Finished");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(String event, NativeJSObject message, EventCallback callback) {
|
||||
public void handleMessage(String event, GeckoBundle message, EventCallback callback) {
|
||||
switch (event) {
|
||||
case "ClosedTabs:Data":
|
||||
updateRecentlyClosedTabs(message);
|
||||
|
@ -112,39 +113,35 @@ public class RecentTabsAdapter extends RecyclerView.Adapter<CombinedHistoryItem>
|
|||
}
|
||||
}
|
||||
|
||||
private void updateRecentlyClosedTabs(NativeJSObject message) {
|
||||
final NativeJSObject[] tabs = message.getObjectArray("tabs");
|
||||
private void updateRecentlyClosedTabs(final GeckoBundle message) {
|
||||
final GeckoBundle[] tabs = message.getBundleArray("tabs");
|
||||
final int length = tabs.length;
|
||||
|
||||
final ClosedTab[] closedTabs = new ClosedTab[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
final NativeJSObject tab = tabs[i];
|
||||
closedTabs[i] = new ClosedTab(tab.getString("url"), tab.getString("title"), tab.getObject("data").toString());
|
||||
final GeckoBundle tab = tabs[i];
|
||||
closedTabs[i] = new ClosedTab(tab.getString("url"), tab.getString("title"),
|
||||
tab.getString("data"));
|
||||
}
|
||||
|
||||
// Only modify recentlyClosedTabs on the UI thread.
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Save some data about the old panel state, so we can be
|
||||
// smarter about notifying the recycler view which bits changed.
|
||||
int prevClosedTabsCount = recentlyClosedTabs.length;
|
||||
boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
|
||||
int prevSectionHeaderIndex = getSectionHeaderIndex();
|
||||
// Save some data about the old panel state, so we can be
|
||||
// smarter about notifying the recycler view which bits changed.
|
||||
int prevClosedTabsCount = recentlyClosedTabs.length;
|
||||
boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
|
||||
int prevSectionHeaderIndex = getSectionHeaderIndex();
|
||||
|
||||
recentlyClosedTabs = closedTabs;
|
||||
recentlyClosedTabsReceived = true;
|
||||
recentTabsUpdateHandler.onRecentTabsCountUpdated(
|
||||
getClosedTabsCount(), recentlyClosedTabsReceived);
|
||||
panelStateUpdateHandler.onPanelStateUpdated(CHILD_RECENT_TABS);
|
||||
recentlyClosedTabs = closedTabs;
|
||||
recentlyClosedTabsReceived = true;
|
||||
recentTabsUpdateHandler.onRecentTabsCountUpdated(
|
||||
getClosedTabsCount(), recentlyClosedTabsReceived);
|
||||
panelStateUpdateHandler.onPanelStateUpdated(CHILD_RECENT_TABS);
|
||||
|
||||
// Handle the section header hiding/unhiding.
|
||||
updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
|
||||
// Handle the section header hiding/unhiding.
|
||||
updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
|
||||
|
||||
// Update the "Recently closed" part of the tab list.
|
||||
updateTabsList(prevClosedTabsCount, recentlyClosedTabs.length, getFirstRecentTabIndex(), getLastRecentTabIndex());
|
||||
}
|
||||
});
|
||||
// Update the "Recently closed" part of the tab list.
|
||||
updateTabsList(prevClosedTabsCount, recentlyClosedTabs.length,
|
||||
getFirstRecentTabIndex(), getLastRecentTabIndex());
|
||||
}
|
||||
|
||||
private void readPreviousSessionData() {
|
||||
|
@ -211,30 +208,24 @@ public class RecentTabsAdapter extends RecyclerView.Adapter<CombinedHistoryItem>
|
|||
private void clearLastSessionData() {
|
||||
final ClosedTab[] emptyLastSessionTabs = new ClosedTab[0];
|
||||
|
||||
// Only modify mLastSessionTabs on the UI thread.
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Save some data about the old panel state, so we can be
|
||||
// smarter about notifying the recycler view which bits changed.
|
||||
int prevClosedTabsCount = lastSessionTabs.length;
|
||||
boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
|
||||
int prevSectionHeaderIndex = getSectionHeaderIndex();
|
||||
// Save some data about the old panel state, so we can be
|
||||
// smarter about notifying the recycler view which bits changed.
|
||||
int prevClosedTabsCount = lastSessionTabs.length;
|
||||
boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
|
||||
int prevSectionHeaderIndex = getSectionHeaderIndex();
|
||||
|
||||
lastSessionTabs = emptyLastSessionTabs;
|
||||
recentTabsUpdateHandler.onRecentTabsCountUpdated(
|
||||
getClosedTabsCount(), recentlyClosedTabsReceived);
|
||||
panelStateUpdateHandler.onPanelStateUpdated(CHILD_RECENT_TABS);
|
||||
lastSessionTabs = emptyLastSessionTabs;
|
||||
recentTabsUpdateHandler.onRecentTabsCountUpdated(
|
||||
getClosedTabsCount(), recentlyClosedTabsReceived);
|
||||
panelStateUpdateHandler.onPanelStateUpdated(CHILD_RECENT_TABS);
|
||||
|
||||
// Handle the section header hiding.
|
||||
updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
|
||||
// Handle the section header hiding.
|
||||
updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
|
||||
|
||||
// Handle the "tabs from last time" being cleared.
|
||||
if (prevClosedTabsCount > 0) {
|
||||
notifyItemRangeRemoved(getFirstLastSessionTabIndex(), prevClosedTabsCount);
|
||||
}
|
||||
}
|
||||
});
|
||||
// Handle the "tabs from last time" being cleared.
|
||||
if (prevClosedTabsCount > 0) {
|
||||
notifyItemRangeRemoved(getFirstLastSessionTabIndex(), prevClosedTabsCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateHeaderVisibility(boolean prevSectionHeaderVisibility, int prevSectionHeaderIndex) {
|
||||
|
|
|
@ -47,7 +47,6 @@ import org.mozilla.gecko.util.EventCallback;
|
|||
import org.mozilla.gecko.util.GeckoBundle;
|
||||
import org.mozilla.gecko.util.HardwareUtils;
|
||||
import org.mozilla.gecko.util.InputOptionsUtils;
|
||||
import org.mozilla.gecko.util.NativeEventListener;
|
||||
import org.mozilla.gecko.util.NativeJSObject;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
|
@ -106,7 +105,6 @@ public class GeckoPreferences
|
|||
extends AppCompatPreferenceActivity
|
||||
implements BundleEventListener,
|
||||
GeckoActivityStatus,
|
||||
NativeEventListener,
|
||||
OnPreferenceChangeListener,
|
||||
OnSharedPreferenceChangeListener
|
||||
{
|
||||
|
@ -371,8 +369,7 @@ public class GeckoPreferences
|
|||
// Use setResourceToOpen to specify these extras.
|
||||
Bundle intentExtras = getIntent().getExtras();
|
||||
|
||||
EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener) this,
|
||||
"Sanitize:Finished");
|
||||
EventDispatcher.getInstance().registerUiThreadListener(this, "Sanitize:Finished");
|
||||
|
||||
// Add handling for long-press click.
|
||||
// This is only for Android 3.0 and below (which use the long-press-context-menu paradigm).
|
||||
|
@ -507,8 +504,7 @@ public class GeckoPreferences
|
|||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener) this,
|
||||
"Sanitize:Finished");
|
||||
EventDispatcher.getInstance().unregisterUiThreadListener(this, "Sanitize:Finished");
|
||||
|
||||
if (mPrefsRequest != null) {
|
||||
PrefsHelper.removeObserver(mPrefsRequest);
|
||||
|
@ -619,25 +615,15 @@ public class GeckoPreferences
|
|||
.fromEvent(message)
|
||||
.callback(callback)
|
||||
.buildAndShow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(final String event, final NativeJSObject message, final EventCallback callback) {
|
||||
try {
|
||||
switch (event) {
|
||||
case "Sanitize:Finished":
|
||||
boolean success = message.getBoolean("success");
|
||||
final int stringRes = success ? R.string.private_data_success : R.string.private_data_fail;
|
||||
} else if ("Sanitize:Finished".equals(event)) {
|
||||
final boolean success = message.getBoolean("success");
|
||||
final int stringRes = success ? R.string.private_data_success : R.string.private_data_fail;
|
||||
|
||||
SnackbarBuilder.builder(GeckoPreferences.this)
|
||||
.message(stringRes)
|
||||
.duration(Snackbar.LENGTH_LONG)
|
||||
.buildAndShow();
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
||||
SnackbarBuilder.builder(this)
|
||||
.message(stringRes)
|
||||
.duration(Snackbar.LENGTH_LONG)
|
||||
.buildAndShow();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1766,7 +1766,7 @@ SessionStore.prototype = {
|
|||
return {
|
||||
url: lastEntry.url,
|
||||
title: lastEntry.title || "",
|
||||
data: tab
|
||||
data: JSON.stringify(tab),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче