Skip to content

Commit 28be10b

Browse files
author
Gabriele M
committed
Replace refresh dialog with icon animation
Change-Id: I6d2cc649b9fa8883a7256d8ecb62cb56bbf5dd59
1 parent efa1a14 commit 28be10b

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
<string name="menu_show_changelog">Show changelog</string>
6262
<string name="menu_changelog_url" translatable="false">https://download.lineageos.org/<xliff:g id="device_name">%1$s</xliff:g>/changes</string>
6363

64-
<string name="dialog_checking_for_updates">Checking for updates</string>
6564
<string name="snack_updates_found">New updates found</string>
6665
<string name="snack_no_updates_found">No new updates found</string>
6766
<string name="snack_updates_check_failed">The update check failed. Please check your internet connection and try again later.</string>

src/org/lineageos/updater/UpdatesActivity.java

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
*/
1616
package org.lineageos.updater;
1717

18-
import android.app.ProgressDialog;
1918
import android.content.BroadcastReceiver;
2019
import android.content.ComponentName;
2120
import android.content.Context;
22-
import android.content.DialogInterface;
2321
import android.content.Intent;
2422
import android.content.IntentFilter;
2523
import android.content.ServiceConnection;
@@ -42,6 +40,9 @@
4240
import android.view.Menu;
4341
import android.view.MenuItem;
4442
import android.view.View;
43+
import android.view.animation.Animation;
44+
import android.view.animation.LinearInterpolator;
45+
import android.view.animation.RotateAnimation;
4546
import android.widget.TextView;
4647

4748
import org.json.JSONException;
@@ -71,6 +72,9 @@ public class UpdatesActivity extends UpdatesListActivity {
7172

7273
private UpdatesListAdapter mAdapter;
7374

75+
private View mRefreshIconView;
76+
private RotateAnimation mRefreshAnimation;
77+
7478
@Override
7579
protected void onCreate(Bundle savedInstanceState) {
7680
super.onCreate(savedInstanceState);
@@ -147,6 +151,11 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
147151
// This can't be collapsed without a touchscreen
148152
appBar.setExpanded(false);
149153
}
154+
155+
mRefreshAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
156+
Animation.RELATIVE_TO_SELF, 0.5f);
157+
mRefreshAnimation.setInterpolator(new LinearInterpolator());
158+
mRefreshAnimation.setDuration(1000);
150159
}
151160

152161
@Override
@@ -353,23 +362,17 @@ private void downloadUpdatesList(final boolean manualRefresh) {
353362
String url = Utils.getServerURL(this);
354363
Log.d(TAG, "Checking " + url);
355364

356-
final ProgressDialog progressDialog = new ProgressDialog(this);
357-
progressDialog.setTitle(R.string.app_name);
358-
progressDialog.setMessage(getString(R.string.dialog_checking_for_updates));
359-
progressDialog.setIndeterminate(true);
360-
progressDialog.setCancelable(true);
361-
362365
DownloadClient.DownloadCallback callback = new DownloadClient.DownloadCallback() {
363366
@Override
364367
public void onFailure(final boolean cancelled) {
365368
Log.e(TAG, "Could not download updates list");
366369
runOnUiThread(new Runnable() {
367370
@Override
368371
public void run() {
369-
progressDialog.dismiss();
370372
if (!cancelled) {
371373
showSnackbar(R.string.snack_updates_check_failed, Snackbar.LENGTH_LONG);
372374
}
375+
refreshAnimationStop();
373376
}
374377
});
375378
}
@@ -386,7 +389,7 @@ public void onSuccess(File destination) {
386389
public void run() {
387390
Log.d(TAG, "List downloaded");
388391
processNewJson(jsonFile, jsonFileTmp, manualRefresh);
389-
progressDialog.dismiss();
392+
refreshAnimationStop();
390393
}
391394
});
392395
}
@@ -405,14 +408,7 @@ public void run() {
405408
return;
406409
}
407410

408-
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
409-
@Override
410-
public void onCancel(DialogInterface dialog) {
411-
progressDialog.dismiss();
412-
downloadClient.cancel();
413-
}
414-
});
415-
progressDialog.show();
411+
refreshAnimationStart();
416412
downloadClient.start();
417413
}
418414

@@ -446,4 +442,22 @@ private void handleDownloadStatusChange(String downloadId) {
446442
public void showSnackbar(int stringId, int duration) {
447443
Snackbar.make(findViewById(R.id.main_container), stringId, duration).show();
448444
}
445+
446+
private void refreshAnimationStart() {
447+
if (mRefreshIconView == null) {
448+
mRefreshIconView = findViewById(R.id.menu_refresh);
449+
}
450+
if (mRefreshIconView != null) {
451+
mRefreshAnimation.setRepeatCount(Animation.INFINITE);
452+
mRefreshIconView.startAnimation(mRefreshAnimation);
453+
mRefreshIconView.setEnabled(false);
454+
}
455+
}
456+
457+
private void refreshAnimationStop() {
458+
if (mRefreshIconView != null) {
459+
mRefreshAnimation.setRepeatCount(0);
460+
mRefreshIconView.setEnabled(true);
461+
}
462+
}
449463
}

0 commit comments

Comments
 (0)