1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 20:31:16 +00:00

Fix NPE in DrawerFragment if syncthing is terminated (fixes #1148) (#1149)

This commit is contained in:
Catfriend1 2018-06-17 23:32:13 +02:00 committed by Audrius Butkevicius
parent eb1266508f
commit 9ecc9d79d8

View file

@ -4,6 +4,7 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -38,6 +39,8 @@ import java.util.TimerTask;
*/
public class DrawerFragment extends Fragment implements View.OnClickListener {
private static final String TAG = "DrawerFragment";
private TextView mCpuUsage;
private TextView mRamUsage;
private TextView mDownload;
@ -206,15 +209,24 @@ public class DrawerFragment extends Fragment implements View.OnClickListener {
*/
private void showQrCode() {
RestApi restApi = mActivity.getApi();
if (restApi == null) {
Toast.makeText(mActivity, R.string.syncthing_terminated, Toast.LENGTH_SHORT).show();
return;
}
try {
String apiKey = restApi.getGui().apiKey;
String deviceId = restApi.getLocalDevice().deviceID;
URL url = restApi.getUrl();
//The QRCode request takes one paramteer called "text", which is the text to be converted to a QRCode.
String apiKey = mActivity.getApi().getGui().apiKey;
String deviceId = mActivity.getApi().getLocalDevice().deviceID;
URL url = mActivity.getApi().getUrl();
new ImageGetRequest(mActivity, url, ImageGetRequest.QR_CODE_GENERATOR, apiKey,
ImmutableMap.of("text", deviceId),qrCodeBitmap -> {
mActivity.showQrCodeDialog(deviceId, qrCodeBitmap);
mActivity.closeDrawer();
}, error -> Toast.makeText(mActivity, R.string.could_not_access_deviceid, Toast.LENGTH_SHORT).show());
} catch (Exception e) {
Log.e(TAG, "showQrCode", e);
}
}
@Override