WIP: Make bluetooth/bonjour peers parcelable.
The Bluetooth peer need only parcel up the BluetoothDevice, which itself is parcelable. The wifi peer requires the JmDNS ServiceInfo class to be parcelled. For this, I took the most full on looking constructor, and parcelled up each individual property of the service info object which is required by that constructor. Also made the scan qr button hooked up to the swap process, and fixed minor bugs with the "visible via wifi" TextView setup.
This commit is contained in:
parent
8ae3ae3e80
commit
5e9931fa03
@ -61,7 +61,7 @@
|
|||||||
android:paddingStart="15dp"
|
android:paddingStart="15dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/swap_visible_bluetooth"
|
tools:text="@string/swap_visible_bluetooth"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -77,6 +77,7 @@
|
|||||||
<Switch
|
<Switch
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
tools:checked="true"
|
||||||
android:id="@+id/switch_bluetooth" />
|
android:id="@+id/switch_bluetooth" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@ -100,9 +101,10 @@
|
|||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/wifi_visible"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/swap_not_visible_wifi"
|
tools:text="@string/swap_not_visible_wifi"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -128,6 +130,7 @@
|
|||||||
<Switch
|
<Switch
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
tools:checked="false"
|
||||||
android:id="@+id/switch_wifi" />
|
android:id="@+id/switch_wifi" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@ -176,6 +179,7 @@
|
|||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/btn_send_fdroid"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:drawableStart="@drawable/ic_fdroid_grey"
|
android:drawableStart="@drawable/ic_fdroid_grey"
|
||||||
@ -185,6 +189,7 @@
|
|||||||
android:background="@android:color/transparent" />
|
android:background="@android:color/transparent" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
android:id="@+id/btn_qr_scanner"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:drawableStart="@drawable/ic_qr_grey"
|
android:drawableStart="@drawable/ic_qr_grey"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.fdroid.fdroid.localrepo.peers;
|
package org.fdroid.fdroid.localrepo.peers;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.os.Parcel;
|
||||||
|
|
||||||
// TODO: Still to be implemented.
|
// TODO: Still to be implemented.
|
||||||
public class BluetoothPeer implements Peer {
|
public class BluetoothPeer implements Peer {
|
||||||
@ -26,4 +27,28 @@ public class BluetoothPeer implements Peer {
|
|||||||
return peer != null && peer instanceof BluetoothPeer && ((BluetoothPeer)peer).device.getAddress() == device.getAddress();
|
return peer != null && peer instanceof BluetoothPeer && ((BluetoothPeer)peer).device.getAddress() == device.getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeParcelable(this.device, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BluetoothPeer(Parcel in) {
|
||||||
|
this.device = in.readParcelable(BluetoothDevice.class.getClassLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<BluetoothPeer> CREATOR = new Creator<BluetoothPeer>() {
|
||||||
|
public BluetoothPeer createFromParcel(Parcel source) {
|
||||||
|
return new BluetoothPeer(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BluetoothPeer[] newArray(int size) {
|
||||||
|
return new BluetoothPeer[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,10 @@ public class BonjourFinder extends PeerFinder<BonjourPeer> implements ServiceLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
mMulticastLock.release();
|
if (mMulticastLock != null) {
|
||||||
|
mMulticastLock.release();
|
||||||
|
}
|
||||||
|
|
||||||
if (mJmdns == null)
|
if (mJmdns == null)
|
||||||
return;
|
return;
|
||||||
mJmdns.removeServiceListener(HTTP_SERVICE_TYPE, this);
|
mJmdns.removeServiceListener(HTTP_SERVICE_TYPE, this);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.fdroid.fdroid.localrepo.peers;
|
package org.fdroid.fdroid.localrepo.peers;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
|
|
||||||
import javax.jmdns.ServiceInfo;
|
import javax.jmdns.ServiceInfo;
|
||||||
@ -26,10 +28,50 @@ public class BonjourPeer implements Peer {
|
|||||||
public boolean equals(Peer peer) {
|
public boolean equals(Peer peer) {
|
||||||
if (peer != null && peer instanceof BonjourPeer) {
|
if (peer != null && peer instanceof BonjourPeer) {
|
||||||
BonjourPeer that = (BonjourPeer)peer;
|
BonjourPeer that = (BonjourPeer)peer;
|
||||||
// TODO: Don't us "name" for comparing, but rather fingerprint of the swap repo.
|
// TODO: Don't use "name" for comparing, but rather fingerprint of the swap repo.
|
||||||
return that.serviceInfo.getName().equals(this.serviceInfo.getName());
|
return that.serviceInfo.getName().equals(this.serviceInfo.getName());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(serviceInfo.getType());
|
||||||
|
dest.writeString(serviceInfo.getName());
|
||||||
|
dest.writeString(serviceInfo.getSubtype());
|
||||||
|
dest.writeInt(serviceInfo.getPort());
|
||||||
|
dest.writeInt(serviceInfo.getWeight());
|
||||||
|
dest.writeInt(serviceInfo.getPriority());
|
||||||
|
dest.writeByte(serviceInfo.isPersistent() ? (byte) 1 : (byte) 0);
|
||||||
|
dest.writeString(serviceInfo.getTextString());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected BonjourPeer(Parcel in) {
|
||||||
|
String type = in.readString();
|
||||||
|
String name = in.readString();
|
||||||
|
String subtype = in.readString();
|
||||||
|
int port = in.readInt();
|
||||||
|
int weight = in.readInt();
|
||||||
|
int priority = in.readInt();
|
||||||
|
boolean persistent = in.readByte() != 0;
|
||||||
|
String text = in.readString();
|
||||||
|
|
||||||
|
this.serviceInfo = ServiceInfo.create(type, name, subtype, port, weight, priority, persistent, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<BonjourPeer> CREATOR = new Creator<BonjourPeer>() {
|
||||||
|
public BonjourPeer createFromParcel(Parcel source) {
|
||||||
|
return new BonjourPeer(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BonjourPeer[] newArray(int size) {
|
||||||
|
return new BonjourPeer[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package org.fdroid.fdroid.localrepo.peers;
|
package org.fdroid.fdroid.localrepo.peers;
|
||||||
|
|
||||||
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
|
|
||||||
import java.io.Serializable;
|
public interface Peer extends Parcelable {
|
||||||
|
|
||||||
public interface Peer extends Serializable {
|
|
||||||
|
|
||||||
String getName();
|
String getName();
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import android.view.MenuInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
@ -30,7 +31,6 @@ import org.fdroid.fdroid.FDroidApp;
|
|||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.localrepo.SwapManager;
|
import org.fdroid.fdroid.localrepo.SwapManager;
|
||||||
import org.fdroid.fdroid.localrepo.peers.Peer;
|
import org.fdroid.fdroid.localrepo.peers.Peer;
|
||||||
import org.fdroid.fdroid.localrepo.peers.PeerFinder;
|
|
||||||
|
|
||||||
public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.InnerView {
|
public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.InnerView {
|
||||||
|
|
||||||
@ -107,6 +107,23 @@ public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.
|
|||||||
uiInitPeers();
|
uiInitPeers();
|
||||||
uiInitBluetooth();
|
uiInitBluetooth();
|
||||||
uiInitWifi();
|
uiInitWifi();
|
||||||
|
uiInitButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void uiInitButtons() {
|
||||||
|
findViewById(R.id.btn_send_fdroid).setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
getActivity().sendFDroid();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
findViewById(R.id.btn_qr_scanner).setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
getActivity().showSelectApps();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +201,7 @@ public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.
|
|||||||
|
|
||||||
private void uiInitWifi() {
|
private void uiInitWifi() {
|
||||||
|
|
||||||
final TextView textBluetoothVisible = (TextView)findViewById(R.id.bluetooth_visible);
|
final TextView textWifiVisible = (TextView)findViewById(R.id.wifi_visible);
|
||||||
|
|
||||||
viewWifiId = (TextView)findViewById(R.id.device_id_wifi);
|
viewWifiId = (TextView)findViewById(R.id.device_id_wifi);
|
||||||
viewWifiNetwork = (TextView)findViewById(R.id.wifi_network);
|
viewWifiNetwork = (TextView)findViewById(R.id.wifi_network);
|
||||||
@ -195,10 +212,10 @@ public class StartSwapView extends LinearLayout implements SwapWorkflowActivity.
|
|||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
textBluetoothVisible.setText(getContext().getString(R.string.swap_visible_wifi));
|
textWifiVisible.setText(getContext().getString(R.string.swap_visible_wifi));
|
||||||
uiUpdatePeersInfo();
|
uiUpdatePeersInfo();
|
||||||
} else {
|
} else {
|
||||||
textBluetoothVisible.setText(getContext().getString(R.string.swap_not_visible_wifi));
|
textWifiVisible.setText(getContext().getString(R.string.swap_not_visible_wifi));
|
||||||
uiUpdatePeersInfo();
|
uiUpdatePeersInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,11 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
inflateInnerView(R.layout.swap_select_apps);
|
inflateInnerView(R.layout.swap_select_apps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendFDroid() {
|
||||||
|
// TODO: What is availble here? Currently we support Bluetooth (see main menu in F-Droid)
|
||||||
|
// and Android Beam (try touching two devices together when in the app details view).
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Figure out whether they have changed since last time UpdateAsyncTask was run.
|
// TODO: Figure out whether they have changed since last time UpdateAsyncTask was run.
|
||||||
// If the local repo is running, then we can ask it what apps it is swapping and compare with that.
|
// If the local repo is running, then we can ask it what apps it is swapping and compare with that.
|
||||||
// Otherwise, probably will need to scan the file system.
|
// Otherwise, probably will need to scan the file system.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user