Don't start hotspot while running and use proper ErrorFragment

This commit is contained in:
Torsten Grote
2021-05-18 16:05:17 -03:00
committed by Sebastian Kürten
parent 99da50d37c
commit 6f8d7167db
5 changed files with 18 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ import androidx.annotation.Nullable;
@ParametersNotNullByDefault
public class ErrorFragment extends BaseFragment {
private static final String TAG = ErrorFragment.class.getName();
public static final String TAG = ErrorFragment.class.getName();
private static final String ERROR_MSG = "errorMessage";

View File

@@ -3,13 +3,13 @@ package org.briarproject.briar.android.hotspot;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.activity.BriarActivity;
import org.briarproject.briar.android.fragment.ErrorFragment;
import org.briarproject.briar.android.hotspot.HotspotState.HotspotError;
import org.briarproject.briar.android.hotspot.HotspotState.HotspotStarted;
@@ -17,10 +17,10 @@ import javax.annotation.Nullable;
import javax.inject.Inject;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import static android.widget.Toast.LENGTH_LONG;
import static org.briarproject.briar.android.util.UiUtils.showFragment;
import static org.briarproject.briar.api.android.AndroidNotificationManager.ACTION_STOP_HOTSPOT;
@@ -60,9 +60,9 @@ public class HotspotActivity extends BriarActivity {
showFragment(fm, new HotspotFragment(), tag);
}
} else if (hotspotState instanceof HotspotError) {
// TODO ErrorFragment
String error = ((HotspotError) hotspotState).getError();
Toast.makeText(this, error, LENGTH_LONG).show();
Fragment f = ErrorFragment.newInstance(error);
showFragment(getSupportFragmentManager(), f, ErrorFragment.TAG);
}
});

View File

@@ -72,8 +72,15 @@ class HotspotViewModel extends DbViewModel
@UiThread
void startHotspot() {
hotspotManager.startWifiP2pHotspot();
notificationManager.showHotspotNotification();
HotspotState s = state.getValue();
if (s instanceof HotspotStarted) {
// Don't try to start again, if already started, just re-set value.
// This can happen if the user navigates back to intro fragment.
state.setValue(s);
} else {
hotspotManager.startWifiP2pHotspot();
notificationManager.showHotspotNotification();
}
}
@UiThread

View File

@@ -65,7 +65,7 @@ public class WebServer extends NanoHTTPD {
} catch (Exception e) {
logException(LOG, WARNING, e);
res = newFixedLengthResponse(INTERNAL_ERROR, MIME_PLAINTEXT,
INTERNAL_ERROR.getDescription());
ctx.getString(R.string.hotspot_error_web_server_serve));
}
return res;
}
@@ -123,7 +123,7 @@ public class WebServer extends NanoHTTPD {
} catch (FileNotFoundException e) {
logException(LOG, WARNING, e);
res = newFixedLengthResponse(NOT_FOUND, MIME_PLAINTEXT,
"Error 404, file not found.");
ctx.getString(R.string.hotspot_error_web_server_serve));
}
return res;
}

View File

@@ -713,7 +713,8 @@
<string name="hotspot_error_start_callback_failed_unknown">Hotspot failed to start with an unknown error, reason %d</string>
<string name="hotspot_error_start_callback_no_group_info">Hotspot failed to start: no group info</string>
<string name="hotspot_error_web_server_start">Error starting web server!</string>
<string name="hotspot_flag_test">Warning: This is a debug app that can NOT be installed on another device</string>
<string name="hotspot_error_web_server_serve">Error presenting website.\n\nPlease send feedback (with anonymous data) via the Briar app if the issue persists.</string>
<string name="hotspot_flag_test">Warning: This app was installed with Android Studio and can NOT be installed on another device.</string>
<string name="hotspot_tab_manual">Manual</string>
<string name="hotspot_manual_wifi">To download the app on another phone, please connect to this Wi-Fi network:</string>