1414import android .view .MenuItem ;
1515import android .view .View ;
1616import android .widget .EditText ;
17+ import android .widget .ProgressBar ;
1718
1819import com .google .gson .JsonObject ;
1920
@@ -59,6 +60,7 @@ public class AppealActivity extends AppCompatActivity implements View.OnClickLis
5960 private FloatingActionButton mFab ;
6061 private EditText mNumber ;
6162 private EditText mDescription ;
63+ private ProgressBar mProgress ;
6264
6365 private AuthorizationService mAuthService ;
6466
@@ -79,9 +81,7 @@ public void onTokenRequestCompleted(@Nullable TokenResponse response,
7981 submitNumber ();
8082 } else {
8183 Log .e (TAG , "error token response: " + ex );
82- Snackbar .make (mFab , R .string .auth_failed , Snackbar .LENGTH_LONG )
83- .setAction (android .R .string .ok , null )
84- .show ();
84+ showSubmitFailed ();
8585 }
8686 }
8787 };
@@ -98,6 +98,7 @@ protected void onCreate(Bundle savedInstanceState) {
9898 mFab = findViewById (R .id .add );
9999 mNumber = findViewById (R .id .number );
100100 mDescription = findViewById (R .id .description );
101+ mProgress = findViewById (R .id .progress );
101102
102103 mFab .setOnClickListener (this );
103104
@@ -131,6 +132,7 @@ public void onClick(View v) {
131132 switch (v .getId ()) {
132133 case R .id .add :
133134 if (validateInputs ()) {
135+ showProgress ();
134136 checkAuthState ();
135137 }
136138 break ;
@@ -139,6 +141,16 @@ public void onClick(View v) {
139141 }
140142 }
141143
144+ private void showProgress () {
145+ mProgress .setVisibility (View .VISIBLE );
146+ mFab .hide ();
147+ }
148+
149+ private void hideProgress () {
150+ mProgress .setVisibility (View .GONE );
151+ mFab .show ();
152+ }
153+
142154 private void checkAuthState () {
143155 mAuthState = readAuthState ();
144156 if (mAuthState != null && mAuthState .isAuthorized ()) {
@@ -210,9 +222,7 @@ public void onFailure(@NonNull Call call, @NonNull IOException e) {
210222 @ Override
211223 public void onResponse (@ NonNull Call call , @ NonNull Response response ) {
212224 if (response .code () == 201 ) {
213- Snackbar .make (mFab , R .string .thanks_feedback , Snackbar .LENGTH_LONG )
214- .setAction (android .R .string .ok , null )
215- .show ();
225+ showSubmitSucceed ();
216226 Log .d (TAG , "submit succeed" );
217227 } else {
218228 showSubmitFailed ();
@@ -223,10 +233,29 @@ public void onResponse(@NonNull Call call, @NonNull Response response) {
223233
224234 }
225235
236+ private void showSubmitSucceed () {
237+ mFab .post (new Runnable () {
238+ @ Override
239+ public void run () {
240+ hideProgress ();
241+ Snackbar .make (mFab , R .string .thanks_feedback , Snackbar .LENGTH_LONG )
242+ .setAction (android .R .string .ok , null )
243+ .show ();
244+ }
245+ });
246+ }
247+
226248 private void showSubmitFailed () {
227- Snackbar .make (mFab , R .string .auth_failed , Snackbar .LENGTH_LONG )
228- .setAction (android .R .string .ok , null )
229- .show ();
249+ mFab .post (new Runnable () {
250+ @ Override
251+ public void run () {
252+ hideProgress ();
253+ Snackbar .make (mFab , R .string .auth_failed , Snackbar .LENGTH_LONG )
254+ .setAction (android .R .string .ok , null )
255+ .show ();
256+ }
257+ });
258+
230259 }
231260
232261 private String getUidFromJwt (String token ) {
0 commit comments