Enable "Send F-Droid" in main swap screen.
This commit is contained in:
parent
a82032d5d0
commit
b05080bbd9
@ -264,7 +264,7 @@ public class FDroidApp extends Application {
|
|||||||
return ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();
|
return ((BluetoothManager) getSystemService(BLUETOOTH_SERVICE)).getAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
|
public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
|
||||||
if (resultCode == Activity.RESULT_CANCELED)
|
if (resultCode == Activity.RESULT_CANCELED)
|
||||||
return;
|
return;
|
||||||
String bluetoothPackageName = null;
|
String bluetoothPackageName = null;
|
||||||
|
@ -63,7 +63,6 @@ import java.util.TimerTask;
|
|||||||
* The following UI elements don't do anything:
|
* The following UI elements don't do anything:
|
||||||
* + TODO: Change wifi by touching network name during swap start screen
|
* + TODO: Change wifi by touching network name during swap start screen
|
||||||
* + TODO: The "?" button in the top right of the swap start screen doesn't do anything
|
* + TODO: The "?" button in the top right of the swap start screen doesn't do anything
|
||||||
* + TODO: The "Send F-Droid" button doesn't do anything
|
|
||||||
*
|
*
|
||||||
* TODO: Show "Waiting for other device to finish setting up swap" when only F-Droid shown in swap
|
* TODO: Show "Waiting for other device to finish setting up swap" when only F-Droid shown in swap
|
||||||
* TODO: Handle "not connected to wifi" more gracefully. For example, Bonjour discovery falls over.
|
* TODO: Handle "not connected to wifi" more gracefully. For example, Bonjour discovery falls over.
|
||||||
|
@ -47,7 +47,9 @@ public class BluetoothSwap extends SwapType {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
|
case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
|
||||||
|
if (server != null && server.isRunning()) {
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Only other is BluetoothAdapter.SCAN_MODE_CONNECTABLE. For now don't handle that.
|
// Only other is BluetoothAdapter.SCAN_MODE_CONNECTABLE. For now don't handle that.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.fdroid.fdroid.views.swap;
|
package org.fdroid.fdroid.views.swap;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -16,7 +15,6 @@ import android.support.annotation.ColorRes;
|
|||||||
import android.support.annotation.LayoutRes;
|
import android.support.annotation.LayoutRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.NavUtils;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
@ -32,7 +30,6 @@ import android.widget.Toast;
|
|||||||
import com.google.zxing.integration.android.IntentIntegrator;
|
import com.google.zxing.integration.android.IntentIntegrator;
|
||||||
import com.google.zxing.integration.android.IntentResult;
|
import com.google.zxing.integration.android.IntentResult;
|
||||||
|
|
||||||
import org.fdroid.fdroid.AppDetails;
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.NfcHelper;
|
import org.fdroid.fdroid.NfcHelper;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
@ -55,7 +52,6 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@ -109,8 +105,9 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
private static final String TAG = "SwapWorkflowActivity";
|
private static final String TAG = "SwapWorkflowActivity";
|
||||||
|
|
||||||
private static final int CONNECT_TO_SWAP = 1;
|
private static final int CONNECT_TO_SWAP = 1;
|
||||||
private static final int REQUEST_BLUETOOTH_ENABLE = 2;
|
private static final int REQUEST_BLUETOOTH_ENABLE_FOR_SWAP = 2;
|
||||||
private static final int REQUEST_BLUETOOTH_DISCOVERABLE = 3;
|
private static final int REQUEST_BLUETOOTH_DISCOVERABLE = 3;
|
||||||
|
private static final int REQUEST_BLUETOOTH_ENABLE_FOR_SEND = 4;
|
||||||
|
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
private InnerView currentView;
|
private InnerView currentView;
|
||||||
@ -357,8 +354,22 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendFDroid() {
|
public void sendFDroid() {
|
||||||
// TODO: What is available here? Currently we support Bluetooth (see main menu in F-Droid)
|
// If Bluetooth has not been enabled/turned on, then enabling device discoverability
|
||||||
// and Android Beam (try touching two devices together when in the app details view).
|
// will automatically enable Bluetooth.
|
||||||
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
if (adapter != null) {
|
||||||
|
if (adapter.getState() != BluetoothAdapter.STATE_ON) {
|
||||||
|
Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
|
||||||
|
discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
|
||||||
|
startActivityForResult(discoverBt, REQUEST_BLUETOOTH_ENABLE_FOR_SEND);
|
||||||
|
} else {
|
||||||
|
sendFDroidApk();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendFDroidApk() {
|
||||||
|
((FDroidApp) getApplication()).sendViaBluetooth(this, Activity.RESULT_OK, "org.fdroid.fdroid");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
@ -491,7 +502,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
} else if (requestCode == CONNECT_TO_SWAP && resultCode == Activity.RESULT_OK) {
|
} else if (requestCode == CONNECT_TO_SWAP && resultCode == Activity.RESULT_OK) {
|
||||||
finish();
|
finish();
|
||||||
} else if (requestCode == REQUEST_BLUETOOTH_ENABLE) {
|
} else if (requestCode == REQUEST_BLUETOOTH_ENABLE_FOR_SWAP) {
|
||||||
|
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
Log.d(TAG, "User enabled Bluetooth, will make sure we are discoverable.");
|
Log.d(TAG, "User enabled Bluetooth, will make sure we are discoverable.");
|
||||||
@ -510,6 +521,8 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
Log.d(TAG, "User chose not to make Bluetooth discoverable, so doing nothing (i.e. sticking with wifi).");
|
Log.d(TAG, "User chose not to make Bluetooth discoverable, so doing nothing (i.e. sticking with wifi).");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (requestCode == REQUEST_BLUETOOTH_ENABLE_FOR_SEND) {
|
||||||
|
sendFDroidApk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,7 +549,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Bluetooth disabled, asking user to enable it.");
|
Log.d(TAG, "Bluetooth disabled, asking user to enable it.");
|
||||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||||
startActivityForResult(enableBtIntent, REQUEST_BLUETOOTH_ENABLE);
|
startActivityForResult(enableBtIntent, REQUEST_BLUETOOTH_ENABLE_FOR_SWAP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user