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