WIP: Don't show self in Bonjour peer list. Implement UI for peer list.

Peers are shown as proper list items now, subject to feedback from Carrie.
TODO: Need to figure out how to combine bluetooth and bonjour with same
fingerprint.
This commit is contained in:
Peter Serwylo 2015-06-27 10:12:26 +10:00
parent 30669f8058
commit 22b072962e
15 changed files with 85 additions and 12 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingBottom="2dip"
android:paddingTop="2dip">
<RelativeLayout
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginLeft="?attr/listPreferredItemPaddingLeft"
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/circle"
android:tint="@color/swap_light_grey_icon"/>
<ImageView
android:id="@+id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerInParent="true"
tools:src="@drawable/ic_bluetooth_white" />
</RelativeLayout>
<TextView
android:id="@+id/peer_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="?attr/listPreferredItemPaddingLeft"
android:layout_marginStart="?android:attr/listPreferredItemPaddingStart"
android:textSize="20sp"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="Nexus 4" />
</LinearLayout>

View File

@ -21,5 +21,6 @@
<color name="swap_bright_blue">#00b9e6</color>
<color name="swap_light_text">#bbbbbb</color>
<color name="swap_grey_icon">#4a4a4a</color>
<color name="swap_light_grey_icon">#bbbbbb</color>
</resources>

View File

@ -153,9 +153,11 @@ public class UpdateService extends IntentService implements ProgressListener {
}
public void hideDialog() {
dialog.hide();
dialog.dismiss();
dialog = null;
if (dialog != null) {
dialog.hide();
dialog.dismiss();
dialog = null;
}
}
@Override
@ -220,9 +222,15 @@ public class UpdateService extends IntentService implements ProgressListener {
}
public static UpdateReceiver updateRepoNow(String address, Context context) {
return updateRepoNow(address, context, true);
}
public static UpdateReceiver updateRepoNow(String address, Context context, boolean showDialog) {
Intent intent = new Intent(context, UpdateService.class);
UpdateReceiver receiver = new UpdateReceiver(new Handler());
receiver.showDialog(context);
if (showDialog) {
receiver.showDialog(context);
}
intent.putExtra(EXTRA_RECEIVER, receiver);
if (!TextUtils.isEmpty(address)) {
intent.putExtra(EXTRA_ADDRESS, address);

View File

@ -148,7 +148,7 @@ public class SwapManager {
Log.e(TAG, "Oops, got a different peer to swap with than initially planned.");
}
return UpdateService.updateRepoNow(peer.getRepoAddress(), context);
return UpdateService.updateRepoNow(peer.getRepoAddress(), context, false);
}
/**

View File

@ -3,6 +3,8 @@ package org.fdroid.fdroid.localrepo.peers;
import android.bluetooth.BluetoothDevice;
import android.os.Parcel;
import org.fdroid.fdroid.R;
// TODO: Still to be implemented.
public class BluetoothPeer implements Peer {
@ -19,12 +21,12 @@ public class BluetoothPeer implements Peer {
@Override
public String getName() {
return "Bluetooth: " + device.getName();
return device.getName();
}
@Override
public int getIcon() {
return android.R.drawable.stat_sys_data_bluetooth;
return R.drawable.ic_bluetooth_white;
}
@Override

View File

@ -5,6 +5,10 @@ import android.net.wifi.WifiManager;
import android.os.AsyncTask;
import android.util.Log;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.localrepo.LocalRepoKeyStore;
import java.io.IOException;
import java.net.InetAddress;
@ -106,9 +110,18 @@ public class BonjourFinder extends PeerFinder<BonjourPeer> implements ServiceLis
addFDroidService(event);
}
/**
* Broadcasts the fact that a Bonjour peer was found to swap with.
* Checks that the service is an F-Droid service, and also that it is not the F-Droid service
* for this device (by comparing its signing fingerprint to our signing fingerprint).
*/
private void addFDroidService(ServiceEvent event) {
final ServiceInfo serviceInfo = event.getInfo();
if (serviceInfo.getPropertyString("type").startsWith("fdroidrepo")) {
final String type = serviceInfo.getPropertyString("type");
final String fingerprint = serviceInfo.getPropertyString("fingerprint");
final boolean isFDroid = type != null && type.startsWith("fdroidrepo");
final boolean isSelf = FDroidApp.repo != null && fingerprint != null && fingerprint.equalsIgnoreCase(FDroidApp.repo.fingerprint);
if (isFDroid && !isSelf) {
foundPeer(new BonjourPeer(serviceInfo));
}
}

View File

@ -21,12 +21,12 @@ public class BonjourPeer implements Peer {
@Override
public String getName() {
return "Bonjour: " + serviceInfo.getName();
return serviceInfo.getName();
}
@Override
public int getIcon() {
return R.drawable.wifi;
return R.drawable.ic_network_wifi_white;
}
@Override

View File

@ -6,6 +6,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Build;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
@ -22,6 +24,7 @@ import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
@ -72,11 +75,12 @@ public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(android.R.layout.two_line_list_item, parent, false);
convertView = LayoutInflater.from(getContext()).inflate(R.layout.swap_peer_list_item, parent, false);
}
Peer peer = getItem(position);
((TextView)convertView.findViewById(android.R.id.text1)).setText(peer.getName());
((TextView)convertView.findViewById(R.id.peer_name)).setText(peer.getName());
((ImageView)convertView.findViewById(R.id.icon)).setImageDrawable(getResources().getDrawable(peer.getIcon()));
return convertView;
}