Bug 1064263 - Part 1: avoid crash when Sync is partially configured. r=nalexander

This commit is contained in:
Richard Newman 2014-10-16 19:50:41 -07:00
parent 7f46e2bf27
commit 9388b058dc
5 changed files with 43 additions and 35 deletions

View File

@ -206,6 +206,13 @@ public class SendTab extends ShareMethod {
i++; i++;
} }
if (validGUIDs.isEmpty()) {
// Guess we'd better override. We have no clients.
// This does the broadcast for us.
setOverrideIntent(FxAccountGetStartedActivity.class);
return;
}
Intent uiStateIntent = getUIStateIntent(); Intent uiStateIntent = getUIStateIntent();
uiStateIntent.putExtra(EXTRA_CLIENT_RECORDS, records); uiStateIntent.putExtra(EXTRA_CLIENT_RECORDS, records);
broadcastUIState(uiStateIntent); broadcastUIState(uiStateIntent);
@ -230,6 +237,7 @@ public class SendTab extends ShareMethod {
Intent uiStateIntent = getUIStateIntent(); Intent uiStateIntent = getUIStateIntent();
uiStateIntent.putExtra(OVERRIDE_INTENT, intent); uiStateIntent.putExtra(OVERRIDE_INTENT, intent);
broadcastUIState(uiStateIntent); broadcastUIState(uiStateIntent);
} }

View File

@ -112,24 +112,27 @@ public class SendTabDeviceListArrayAdapter extends ArrayAdapter<ParcelableClient
} }
// The remaining states delegate to the SentTabTargetSelectedListener. // The remaining states delegate to the SentTabTargetSelectedListener.
final String listenerGUID; final ParcelableClientRecord clientRecord = getItem(position);
ParcelableClientRecord clientRecord = getItem(position);
if (currentState == State.LIST) { if (currentState == State.LIST) {
row.setText(clientRecord.name); row.setText(clientRecord.name);
row.setCompoundDrawablesWithIntrinsicBounds(getImage(clientRecord), 0, 0, 0); row.setCompoundDrawablesWithIntrinsicBounds(getImage(clientRecord), 0, 0, 0);
listenerGUID = clientRecord.guid; final String listenerGUID = clientRecord.guid;
} else {
listenerGUID = null;
}
row.setOnClickListener(new OnClickListener() { row.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
listener.onSendTabTargetSelected(listenerGUID); listener.onSendTabTargetSelected(listenerGUID);
} }
}); });
} else {
row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
listener.onSendTabActionSelected();
}
});
}
return row; return row;
} }

View File

@ -6,7 +6,6 @@ package org.mozilla.gecko.overlays.ui;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.LIST; import static org.mozilla.gecko.overlays.ui.SendTabList.State.LIST;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.LOADING; import static org.mozilla.gecko.overlays.ui.SendTabList.State.LOADING;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.NONE;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.SHOW_DEVICES; import static org.mozilla.gecko.overlays.ui.SendTabList.State.SHOW_DEVICES;
import java.util.Arrays; import java.util.Arrays;
@ -111,16 +110,9 @@ public class SendTabList extends ListView {
public void setSyncClients(final ParcelableClientRecord[] c) { public void setSyncClients(final ParcelableClientRecord[] c) {
final ParcelableClientRecord[] clients = c == null ? new ParcelableClientRecord[0] : c; final ParcelableClientRecord[] clients = c == null ? new ParcelableClientRecord[0] : c;
int size = clients.length;
if (size == 0) {
// Just show a button to set up Sync (or whatever).
switchState(NONE);
return;
}
clientListAdapter.setClientRecordList(Arrays.asList(clients)); clientListAdapter.setClientRecordList(Arrays.asList(clients));
if (size <= MAXIMUM_INLINE_ELEMENTS) { if (clients.length <= MAXIMUM_INLINE_ELEMENTS) {
// Show the list of devices in-line. // Show the list of devices in-line.
switchState(LIST); switchState(LIST);
return; return;
@ -133,7 +125,7 @@ public class SendTabList extends ListView {
/** /**
* Get an AlertDialog listing all devices, allowing the user to select the one they want. * Get an AlertDialog listing all devices, allowing the user to select the one they want.
* Used when more than MAXIMUM_INLINE_ELEMENTS devices are found (to avoid displaying them all * Used when more than MAXIMUM_INLINE_ELEMENTS devices are found (to avoid displaying them all
* inline and looking crazy. * inline and looking crazy).
*/ */
public AlertDialog getDialog() { public AlertDialog getDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

View File

@ -15,4 +15,11 @@ public interface SendTabTargetSelectedListener {
* @param targetGUID The GUID of the ClientRecord the element represents (if any, otherwise null) * @param targetGUID The GUID of the ClientRecord the element represents (if any, otherwise null)
*/ */
public void onSendTabTargetSelected(String targetGUID); public void onSendTabTargetSelected(String targetGUID);
/**
* Called when the overall Send Tab item is clicked.
*
* This implies that the clients list was unavailable.
*/
public void onSendTabActionSelected();
} }

View File

@ -295,14 +295,17 @@ public class ShareDialog extends LocaleAware.LocaleAwareActivity implements Send
* launching Fennec"). * launching Fennec").
*/ */
public void sendTab(String targetGUID) { @Override
// If an override intent has been set, dispatch it. public void onSendTabActionSelected() {
if (sendTabOverrideIntent != null) { // This requires an override intent.
startActivity(sendTabOverrideIntent); Assert.isTrue(sendTabOverrideIntent != null);
finish();
return;
}
startActivity(sendTabOverrideIntent);
finish();
}
@Override
public void onSendTabTargetSelected(String targetGUID) {
// targetGUID being null with no override intent should be an impossible state. // targetGUID being null with no override intent should be an impossible state.
Assert.isTrue(targetGUID != null); Assert.isTrue(targetGUID != null);
@ -320,11 +323,6 @@ public class ShareDialog extends LocaleAware.LocaleAwareActivity implements Send
slideOut(); slideOut();
} }
@Override
public void onSendTabTargetSelected(String targetGUID) {
sendTab(targetGUID);
}
public void addToReadingList() { public void addToReadingList() {
startService(getServiceIntent(ShareMethod.Type.ADD_TO_READING_LIST)); startService(getServiceIntent(ShareMethod.Type.ADD_TO_READING_LIST));
slideOut(); slideOut();