@@ -49,6 +49,7 @@ public class MainActivity extends AppCompatActivity {
4949 Button mRetryButton ;
5050 Button mSetAddressButton ;
5151 Button mFindServerButton ;
52+ TextView mAddressText ;
5253
5354 DbHelper dbHelper ;
5455 SharedPreferences prefs = null ;
@@ -68,12 +69,16 @@ protected void onCreate(Bundle savedInstanceState) {
6869 mStatusText = findViewById (R .id .main_activity_status );
6970 mRetryButton = findViewById (R .id .retry_button );
7071 mFindServerButton = findViewById (R .id .find_server_button );
72+ mAddressText = findViewById (R .id .main_activity_address_tv );
73+
74+ mAddressText .setText (dbHelper .getServerAddress ());
7175
7276 // The retry button attempts to contact the server again.
7377 mRetryButton .setOnClickListener (new OnOneOffClickListener () {
7478 @ Override
7579 public void onSingleClick (View v ) {
7680 try {
81+ mStatusText .setText ("Connecting..." );
7782 checkState ();
7883 } catch (Exception e ) {
7984 showError (e .getMessage ());
@@ -107,13 +112,15 @@ protected void onResume() {
107112 mRetryButton .setVisibility (View .INVISIBLE );
108113 mFindServerButton .setVisibility (View .VISIBLE );
109114 mSetAddressButton .setVisibility (View .VISIBLE );
115+ mAddressText .setVisibility (View .VISIBLE );
110116 prefs .edit ().putBoolean ("firstrun" , false ).apply ();
111117 } else {
112118 // Hide the buttons by default. This stops them showing during transitions between activities
113119 mStatusText .setVisibility (View .INVISIBLE );
114120 mRetryButton .setVisibility (View .INVISIBLE );
115121 mSetAddressButton .setVisibility (View .INVISIBLE );
116122 mFindServerButton .setVisibility (View .INVISIBLE );
123+ mAddressText .setVisibility (View .INVISIBLE );
117124 // When arriving at this page, immediately contact the server to see which screen the app
118125 // should be on, and start that activity
119126 try {
@@ -151,6 +158,7 @@ private void showError(String errorText) {
151158 mRetryButton .setVisibility (View .VISIBLE );
152159 mFindServerButton .setVisibility (View .VISIBLE );
153160 mSetAddressButton .setVisibility (View .VISIBLE );
161+ mAddressText .setVisibility (View .VISIBLE );
154162 }
155163
156164 /**
@@ -172,10 +180,9 @@ private void checkState() {
172180 }, error -> {
173181 // Show a different error message depending on the error
174182 if (error instanceof TimeoutError || error instanceof NoConnectionError ) {
175- showError ("Could not connect to network " );
183+ showError ("Could not connect" );
176184 } else if (error instanceof ServerError ) {
177185 showError ("Could not connect to server" );
178- showError (error .getMessage ());
179186 }
180187 Log .v ("ErrorListener" , String .valueOf (error ));
181188 });
0 commit comments