mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Don't start hotspot while running and use proper ErrorFragment
This commit is contained in:
committed by
Sebastian Kürten
parent
99da50d37c
commit
6f8d7167db
@@ -17,7 +17,7 @@ import androidx.annotation.Nullable;
|
|||||||
@ParametersNotNullByDefault
|
@ParametersNotNullByDefault
|
||||||
public class ErrorFragment extends BaseFragment {
|
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";
|
private static final String ERROR_MSG = "errorMessage";
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ package org.briarproject.briar.android.hotspot;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
|
||||||
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
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.HotspotError;
|
||||||
import org.briarproject.briar.android.hotspot.HotspotState.HotspotStarted;
|
import org.briarproject.briar.android.hotspot.HotspotState.HotspotStarted;
|
||||||
|
|
||||||
@@ -17,10 +17,10 @@ import javax.annotation.Nullable;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
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.android.util.UiUtils.showFragment;
|
||||||
import static org.briarproject.briar.api.android.AndroidNotificationManager.ACTION_STOP_HOTSPOT;
|
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);
|
showFragment(fm, new HotspotFragment(), tag);
|
||||||
}
|
}
|
||||||
} else if (hotspotState instanceof HotspotError) {
|
} else if (hotspotState instanceof HotspotError) {
|
||||||
// TODO ErrorFragment
|
|
||||||
String error = ((HotspotError) hotspotState).getError();
|
String error = ((HotspotError) hotspotState).getError();
|
||||||
Toast.makeText(this, error, LENGTH_LONG).show();
|
Fragment f = ErrorFragment.newInstance(error);
|
||||||
|
showFragment(getSupportFragmentManager(), f, ErrorFragment.TAG);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -72,8 +72,15 @@ class HotspotViewModel extends DbViewModel
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
void startHotspot() {
|
void startHotspot() {
|
||||||
hotspotManager.startWifiP2pHotspot();
|
HotspotState s = state.getValue();
|
||||||
notificationManager.showHotspotNotification();
|
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
|
@UiThread
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class WebServer extends NanoHTTPD {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
res = newFixedLengthResponse(INTERNAL_ERROR, MIME_PLAINTEXT,
|
res = newFixedLengthResponse(INTERNAL_ERROR, MIME_PLAINTEXT,
|
||||||
INTERNAL_ERROR.getDescription());
|
ctx.getString(R.string.hotspot_error_web_server_serve));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ public class WebServer extends NanoHTTPD {
|
|||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
logException(LOG, WARNING, e);
|
logException(LOG, WARNING, e);
|
||||||
res = newFixedLengthResponse(NOT_FOUND, MIME_PLAINTEXT,
|
res = newFixedLengthResponse(NOT_FOUND, MIME_PLAINTEXT,
|
||||||
"Error 404, file not found.");
|
ctx.getString(R.string.hotspot_error_web_server_serve));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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_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_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_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_tab_manual">Manual</string>
|
||||||
<string name="hotspot_manual_wifi">To download the app on another phone, please connect to this Wi-Fi network:</string>
|
<string name="hotspot_manual_wifi">To download the app on another phone, please connect to this Wi-Fi network:</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user