Bug 771024 - Reveal entire device list in Send Tab activity; correct scrolling/checking interaction; make Send Tab do database work on background thread. r=liuche,nalexander

--HG--
extra : rebase_source : 4ae6190cb5db1b0778161b332ea71d15148e5c1c
This commit is contained in:
Nick Alexander 2012-07-11 14:37:38 -07:00
parent 613efaabc5
commit 6fdd883ff0
3 changed files with 64 additions and 34 deletions

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/SyncLayout" >
style="@style/SyncLayout.Vertical" >
<LinearLayout
android:id="@+id/sendtab_top"
style="@style/SyncTop">
style="@style/SyncTop" >
<ImageView
style="@style/SyncTopIcon" />
<TextView
@ -11,20 +11,16 @@
android:text="@string/sync_title_send_tab" />
</LinearLayout>
<LinearLayout
android:id="@+id/device_list_layout"
<ListView
android:id="@+id/device_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/sendtab_top"
android:layout_above="@+id/send_button"
style="@style/SyncLayout.Vertical" >
<ListView
android:id="@+id/device_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
android:layout_above="@+id/sendtab_bottom" >
</ListView>
<LinearLayout
android:id="@id/sendtab_bottom"
style="@style/SyncBottom" >
<Button
style="@style/SyncButton"

View File

@ -1,8 +1,10 @@
package org.mozilla.gecko.sync.setup.activities;
import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
import java.util.ArrayList;
import java.util.List;
import org.mozilla.gecko.R;
import org.mozilla.gecko.sync.repositories.domain.ClientRecord;
import android.content.Context;
import android.view.View;
@ -31,20 +33,27 @@ public class ClientRecordArrayAdapter extends ArrayAdapter<Object> {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Context context = this.getContext();
View view = View.inflate(context, R.layout.sync_list_item, null);
setSelectable(view, true);
view.setBackgroundResource(android.R.drawable.menuitem_background);
// Reuse View objects if they exist.
View row = convertView;
if (row == null) {
row = View.inflate(context, R.layout.sync_list_item, null);
setSelectable(row, true);
row.setBackgroundResource(android.R.drawable.menuitem_background);
}
final ClientRecord clientRecord = clientRecordList[position];
ImageView clientType = (ImageView) view.findViewById(R.id.img);
TextView clientName = (TextView) view.findViewById(R.id.client_name);
CheckBox checkbox = (CheckBox) view.findViewById(R.id.check);
ImageView clientType = (ImageView) row.findViewById(R.id.img);
TextView clientName = (TextView) row.findViewById(R.id.client_name);
// Set up checkbox and restore stored state.
CheckBox checkbox = (CheckBox) row.findViewById(R.id.check);
checkbox.setChecked(checkedItems[position]);
setSelectable(checkbox, false);
clientName.setText(clientRecord.name);
clientType.setImageResource(getImage(clientRecord));
view.setOnClickListener(new OnClickListener() {
row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
CheckBox item = (CheckBox) view.findViewById(R.id.check);
@ -64,14 +73,14 @@ public class ClientRecordArrayAdapter extends ArrayAdapter<Object> {
});
return view;
return row;
}
public String[] getCheckedGUIDs() {
String[] guids = new String[numCheckedGUIDs];
for (int i = 0, j = 0; i < checkedItems.length; i++) {
public List<String> getCheckedGUIDs() {
final List<String> guids = new ArrayList<String>();
for (int i = 0; i < checkedItems.length; i++) {
if (checkedItems[i]) {
guids[j++] = clientRecordList[i].guid;
guids.add(clientRecordList[i].guid);
}
}
return guids;

View File

@ -21,7 +21,9 @@ import org.mozilla.gecko.sync.syncadapter.SyncAdapter;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
@ -29,7 +31,6 @@ import android.widget.Toast;
public class SendTabActivity extends Activity {
public static final String LOG_TAG = "SendTabActivity";
private ListView listview;
private ClientRecordArrayAdapter arrayAdapter;
private AccountManager accountManager;
private Account localAccount;
@ -49,14 +50,29 @@ public class SendTabActivity extends Activity {
registerDisplayURICommand();
setContentView(R.layout.sync_send_tab);
arrayAdapter = new ClientRecordArrayAdapter(this, R.layout.sync_list_item, getClientArray());
listview = (ListView) findViewById(R.id.device_list);
listview.setAdapter(arrayAdapter);
final ListView listview = (ListView) findViewById(R.id.device_list);
listview.setItemsCanFocus(true);
listview.setTextFilterEnabled(true);
listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
enableSend(false);
// Fetching the client list hits the clients database, so we spin this onto
// a background task.
final Context context = this;
new AsyncTask<Void, Void, ClientRecord[]>() {
@Override
protected ClientRecord[] doInBackground(Void... params) {
return getClientArray();
}
@Override
protected void onPostExecute(final ClientRecord[] clientArray) {
// We're allowed to update the UI from here.
arrayAdapter = new ClientRecordArrayAdapter(context, R.layout.sync_list_item, clientArray);
listview.setAdapter(arrayAdapter);
}
}.execute();
}
private static void registerDisplayURICommand() {
@ -102,14 +118,23 @@ public class SendTabActivity extends Activity {
final String title = extras.getString(Intent.EXTRA_SUBJECT);
final CommandProcessor processor = CommandProcessor.getProcessor();
final String[] guids = arrayAdapter.getCheckedGUIDs();
final String clientGUID = getAccountGUID();
final List<String> guids = arrayAdapter.getCheckedGUIDs();
if (clientGUID == null || guids == null) {
// Should never happen.
Logger.warn(LOG_TAG, "clientGUID? " + (clientGUID == null) + " or guids? " + (guids == null) +
" was null; aborting without sending tab.");
finish();
return;
}
// Perform tab sending on another thread.
new Thread() {
@Override
public void run() {
for (int i = 0; i < guids.length; i++) {
processor.sendURIToClientForDisplay(uri, guids[i], title, getAccountGUID(), getApplicationContext());
for (String guid : guids) {
processor.sendURIToClientForDisplay(uri, guid, title, clientGUID, getApplicationContext());
}
Logger.info(LOG_TAG, "Requesting immediate clients stage sync.");