Skip to content

Commit

Permalink
Fixes #364 Bridge Wizard status TextView is preserved on device rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmold committed Jul 28, 2020
1 parent 8990c90 commit e006fce
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public class BridgeWizardActivity extends AppCompatActivity {

private static int MOAT_REQUEST_CODE = 666;

private TextView mTvStatus;
private static TextView mTvStatus;
private RadioButton mBtDirect;
private RadioButton mBtObfs4;
private RadioButton mBtMeek;
private RadioButton mBtCustom;

private static final String BUNDLE_KEY_TV_STATUS_VISIBILITY = "visibility";
private static final String BUNDLE_KEY_TV_STATUS_TEXT = "text";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -49,7 +51,12 @@ protected void onCreate(Bundle savedInstanceState) {
}

mTvStatus = findViewById(R.id.lbl_bridge_test_status);
mTvStatus.setVisibility(View.GONE);
if (savedInstanceState == null) {
mTvStatus.setVisibility(View.GONE);
} else {
mTvStatus.setVisibility(savedInstanceState.getInt(BUNDLE_KEY_TV_STATUS_VISIBILITY, View.GONE));
mTvStatus.setText(savedInstanceState.getString(BUNDLE_KEY_TV_STATUS_TEXT, ""));
}

setTitle(getString(R.string.bridges));

Expand Down Expand Up @@ -86,7 +93,6 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
super.onResume();

evaluateBridgeListState();
}

Expand Down Expand Up @@ -117,8 +123,7 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
else {
evaluateBridgeListState();
}
}
else {
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
Expand Down Expand Up @@ -165,14 +170,20 @@ protected void onPostExecute(Boolean result) {
// Post Code
if (result) {
mTvStatus.setText(R.string.testing_bridges_success);

} else {
mTvStatus.setText(R.string.testing_bridges_fail);

}
}
}


@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt(BUNDLE_KEY_TV_STATUS_VISIBILITY, mTvStatus.getVisibility());
savedInstanceState.putString(BUNDLE_KEY_TV_STATUS_TEXT, mTvStatus.getText().toString());
super.onSaveInstanceState(savedInstanceState);
}

@SuppressWarnings("SameParameterValue")
private static boolean isHostReachable(String serverAddress, int serverTCPport, int timeoutMS) {
boolean connected = false;
Expand All @@ -185,8 +196,7 @@ private static boolean isHostReachable(String serverAddress, int serverTCPport,
connected = true;
socket.close();
}
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}

Expand All @@ -198,14 +208,11 @@ private void evaluateBridgeListState() {

if (!Prefs.bridgesEnabled()) {
mBtDirect.setChecked(true);
}
else if (Prefs.getBridgesList().equals("meek")) {
} else if (Prefs.getBridgesList().equals("meek")) {
mBtMeek.setChecked(true);
}
else if (Prefs.getBridgesList().equals("obfs4")) {
} else if (Prefs.getBridgesList().equals("obfs4")) {
mBtObfs4.setChecked(true);
}
else {
} else {
mBtCustom.setChecked(true);
}
}
Expand Down

0 comments on commit e006fce

Please sign in to comment.