Skip to content

Commit 89b7ccb

Browse files
committed
add progress bar
1 parent 7ab4908 commit 89b7ccb

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

app/src/main/java/org/xdty/callerinfo/activity/AppealActivity.java

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.view.MenuItem;
1515
import android.view.View;
1616
import android.widget.EditText;
17+
import android.widget.ProgressBar;
1718

1819
import 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) {

app/src/main/res/layout/activity_appeal.xml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@
5959
android:id="@+id/prompt"
6060
android:layout_width="wrap_content"
6161
android:layout_height="wrap_content"
62-
android:layout_marginBottom="16dp"
62+
android:layout_marginBottom="100dp"
6363
android:lineSpacingExtra="4dp"
6464
android:paddingEnd="8dp"
6565
android:paddingStart="8dp"
6666
android:text="@string/number_appeal_prompt"
6767
android:textSize="12sp"
68-
app:layout_constraintBottom_toTopOf="@+id/add"
68+
app:layout_constraintBottom_toBottomOf="parent"
6969
app:layout_constraintEnd_toEndOf="parent"
70-
app:layout_constraintStart_toStartOf="parent"/>
70+
app:layout_constraintStart_toStartOf="parent"
71+
/>
7172

7273
<android.support.design.widget.FloatingActionButton
7374
android:id="@+id/add"
@@ -81,4 +82,17 @@
8182
app:layout_constraintBottom_toBottomOf="parent"
8283
app:layout_constraintEnd_toEndOf="parent"
8384
app:srcCompat="@drawable/ic_send_white_24dp"/>
85+
86+
<ProgressBar
87+
android:id="@+id/progress"
88+
style="@style/Widget.AppCompat.ProgressBar"
89+
android:layout_width="wrap_content"
90+
android:layout_height="wrap_content"
91+
android:layout_gravity="center"
92+
android:indeterminateDuration="2000"
93+
android:visibility="gone"
94+
app:layout_constraintBottom_toBottomOf="parent"
95+
app:layout_constraintEnd_toEndOf="parent"
96+
app:layout_constraintStart_toStartOf="parent"
97+
app:layout_constraintTop_toTopOf="parent"/>
8498
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)