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 0b2deebe9e
commit 63210c6aa6
5 changed files with 43 additions and 35 deletions

View File

@ -206,6 +206,13 @@ public class SendTab extends ShareMethod {
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();
uiStateIntent.putExtra(EXTRA_CLIENT_RECORDS, records);
broadcastUIState(uiStateIntent);
@ -230,6 +237,7 @@ public class SendTab extends ShareMethod {
Intent uiStateIntent = getUIStateIntent();
uiStateIntent.putExtra(OVERRIDE_INTENT, intent);
broadcastUIState(uiStateIntent);
}

View File

@ -112,17 +112,12 @@ public class SendTabDeviceListArrayAdapter extends ArrayAdapter<ParcelableClient
}
// The remaining states delegate to the SentTabTargetSelectedListener.
final String listenerGUID;
ParcelableClientRecord clientRecord = getItem(position);
final ParcelableClientRecord clientRecord = getItem(position);
if (currentState == State.LIST) {
row.setText(clientRecord.name);
row.setCompoundDrawablesWithIntrinsicBounds(getImage(clientRecord), 0, 0, 0);
listenerGUID = clientRecord.guid;
} else {
listenerGUID = null;
}
final String listenerGUID = clientRecord.guid;
row.setOnClickListener(new OnClickListener() {
@Override
@ -130,6 +125,14 @@ public class SendTabDeviceListArrayAdapter extends ArrayAdapter<ParcelableClient
listener.onSendTabTargetSelected(listenerGUID);
}
});
} else {
row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
listener.onSendTabActionSelected();
}
});
}
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.LOADING;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.NONE;
import static org.mozilla.gecko.overlays.ui.SendTabList.State.SHOW_DEVICES;
import java.util.Arrays;
@ -111,16 +110,9 @@ public class SendTabList extends ListView {
public void setSyncClients(final ParcelableClientRecord[] 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));
if (size <= MAXIMUM_INLINE_ELEMENTS) {
if (clients.length <= MAXIMUM_INLINE_ELEMENTS) {
// Show the list of devices in-line.
switchState(LIST);
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.
* 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() {
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)
*/
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").
*/
public void sendTab(String targetGUID) {
// If an override intent has been set, dispatch it.
if (sendTabOverrideIntent != null) {
@Override
public void onSendTabActionSelected() {
// This requires an override intent.
Assert.isTrue(sendTabOverrideIntent != null);
startActivity(sendTabOverrideIntent);
finish();
return;
}
@Override
public void onSendTabTargetSelected(String targetGUID) {
// targetGUID being null with no override intent should be an impossible state.
Assert.isTrue(targetGUID != null);
@ -320,11 +323,6 @@ public class ShareDialog extends LocaleAware.LocaleAwareActivity implements Send
slideOut();
}
@Override
public void onSendTabTargetSelected(String targetGUID) {
sendTab(targetGUID);
}
public void addToReadingList() {
startService(getServiceIntent(ShareMethod.Type.ADD_TO_READING_LIST));
slideOut();