mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-24 05:04:50 -04:00
Refactor logic for using WDM.sendToDevice()
This commit is contained in:
parent
227b5228f8
commit
0f97a2e8e5
@ -91,7 +91,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements
|
|||||||
private FileListAdapter fileListAdapter;
|
private FileListAdapter fileListAdapter;
|
||||||
|
|
||||||
private List<WifiP2pDevice> availablePeerDevices = new ArrayList<WifiP2pDevice>();
|
private List<WifiP2pDevice> availablePeerDevices = new ArrayList<WifiP2pDevice>();
|
||||||
private boolean hasSenderStartedConnection = false;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -141,11 +140,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements
|
|||||||
|
|
||||||
@OnItemClick(R.id.list_peer_devices)
|
@OnItemClick(R.id.list_peer_devices)
|
||||||
void onItemClick(int position) {
|
void onItemClick(int position) {
|
||||||
/* Connection can only be initiated by user of the sender device, & only when transfer has not been started */
|
|
||||||
if (!isFileSender || hasSenderStartedConnection) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WifiP2pDevice senderSelectedPeerDevice =
|
WifiP2pDevice senderSelectedPeerDevice =
|
||||||
(WifiP2pDevice) listViewPeerDevices.getAdapter().getItem(position);
|
(WifiP2pDevice) listViewPeerDevices.getAdapter().getItem(position);
|
||||||
wifiDirectManager.sendToDevice(senderSelectedPeerDevice);
|
wifiDirectManager.sendToDevice(senderSelectedPeerDevice);
|
||||||
@ -222,11 +216,6 @@ public class LocalFileTransferActivity extends AppCompatActivity implements
|
|||||||
textViewPeerDevices.setVisibility(View.INVISIBLE);
|
textViewPeerDevices.setVisibility(View.INVISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSenderStartedConnection() {
|
|
||||||
this.hasSenderStartedConnection = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFileStatusChanged(int itemIndex) {
|
public void onFileStatusChanged(int itemIndex) {
|
||||||
fileListAdapter.notifyItemChanged(itemIndex);
|
fileListAdapter.notifyItemChanged(itemIndex);
|
||||||
|
@ -75,6 +75,7 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener, WifiP2
|
|||||||
|
|
||||||
private ArrayList<Uri> fileUriArrayList; // For sender device, stores uris of the files
|
private ArrayList<Uri> fileUriArrayList; // For sender device, stores uris of the files
|
||||||
private boolean isFileSender = false; // Whether the device is the file sender or not
|
private boolean isFileSender = false; // Whether the device is the file sender or not
|
||||||
|
private boolean hasSenderStartedConnection = false;
|
||||||
|
|
||||||
public WifiDirectManager(@NonNull LocalFileTransferActivity activity) {
|
public WifiDirectManager(@NonNull LocalFileTransferActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
@ -219,13 +220,18 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener, WifiP2
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendToDevice(@NonNull WifiP2pDevice senderSelectedPeerDevice) {
|
public void sendToDevice(@NonNull WifiP2pDevice senderSelectedPeerDevice) {
|
||||||
|
/* Connection can only be initiated by user of the sender device, & only when transfer has not been started */
|
||||||
|
if (!isFileSender || hasSenderStartedConnection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.senderSelectedPeerDevice = senderSelectedPeerDevice;
|
this.senderSelectedPeerDevice = senderSelectedPeerDevice;
|
||||||
|
|
||||||
alertDialogShower.show(
|
alertDialogShower.show(
|
||||||
new KiwixDialog.FileTransferConfirmation(senderSelectedPeerDevice.deviceName),
|
new KiwixDialog.FileTransferConfirmation(senderSelectedPeerDevice.deviceName),
|
||||||
new Function0<Unit>() {
|
new Function0<Unit>() {
|
||||||
@Override public Unit invoke() {
|
@Override public Unit invoke() {
|
||||||
((Callbacks) activity).onSenderStartedConnection();
|
hasSenderStartedConnection = true;
|
||||||
connect();
|
connect();
|
||||||
displayToast(R.string.performing_handshake, Toast.LENGTH_LONG);
|
displayToast(R.string.performing_handshake, Toast.LENGTH_LONG);
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
@ -466,8 +472,6 @@ public class WifiDirectManager implements WifiP2pManager.ChannelListener, WifiP2
|
|||||||
|
|
||||||
void updateListOfAvailablePeers(@NonNull WifiP2pDeviceList peers);
|
void updateListOfAvailablePeers(@NonNull WifiP2pDeviceList peers);
|
||||||
|
|
||||||
void onSenderStartedConnection();
|
|
||||||
|
|
||||||
void onFilesForTransferAvailable(@NonNull ArrayList<FileItem> filesForTransfer);
|
void onFilesForTransferAvailable(@NonNull ArrayList<FileItem> filesForTransfer);
|
||||||
|
|
||||||
void onFileStatusChanged(int itemIndex);
|
void onFileStatusChanged(int itemIndex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user