Outline specific error fragment for hotspot

This commit is contained in:
Sebastian Kürten
2021-05-29 07:26:28 +02:00
committed by Torsten Grote
parent 6cd70e0e7f
commit e39c99fd6c
4 changed files with 182 additions and 3 deletions

View File

@@ -10,7 +10,6 @@ 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.BaseFragment.BaseFragmentListener;
import org.briarproject.briar.android.fragment.ErrorFragment;
import org.briarproject.briar.android.hotspot.HotspotState.HotspotError;
import org.briarproject.briar.android.hotspot.HotspotState.HotspotStarted;
@@ -62,9 +61,14 @@ public class HotspotActivity extends BriarActivity
showFragment(fm, new HotspotFragment(), tag);
}
} else if (hotspotState instanceof HotspotError) {
// TODO: handle rotation gracefully. If we just use
// fm.findFragmentByTag(HotspotErrorFragment.TAG) == null)
// we might hide multiple errors. Maybe we could update the
// error message of the existing fragment in that case
String error = ((HotspotError) hotspotState).getError();
Fragment f = ErrorFragment.newInstance(error);
showFragment(getSupportFragmentManager(), f, ErrorFragment.TAG);
Fragment f = HotspotErrorFragment.newInstance(error);
showFragment(getSupportFragmentManager(), f,
HotspotErrorFragment.TAG);
}
});

View File

@@ -0,0 +1,61 @@
package org.briarproject.briar.android.hotspot;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.fragment.BaseFragment;
import androidx.annotation.Nullable;
@MethodsNotNullByDefault
@ParametersNotNullByDefault
public class HotspotErrorFragment extends BaseFragment {
public static final String TAG = HotspotErrorFragment.class.getName();
private static final String ERROR_MSG = "errorMessage";
public static HotspotErrorFragment newInstance(String message) {
HotspotErrorFragment f = new HotspotErrorFragment();
Bundle args = new Bundle();
args.putString(ERROR_MSG, message);
f.setArguments(args);
return f;
}
private String errorMessage;
@Override
public String getUniqueTag() {
return TAG;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
if (args == null) throw new AssertionError();
errorMessage = args.getString(ERROR_MSG);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View v = inflater
.inflate(R.layout.fragment_hotspot_error, container, false);
TextView msg = v.findViewById(R.id.errorMessageDetail);
msg.setText(errorMessage);
return v;
}
}