1515 */
1616package org .lineageos .updater ;
1717
18- import android .app .ProgressDialog ;
1918import android .content .BroadcastReceiver ;
2019import android .content .ComponentName ;
2120import android .content .Context ;
22- import android .content .DialogInterface ;
2321import android .content .Intent ;
2422import android .content .IntentFilter ;
2523import android .content .ServiceConnection ;
4240import android .view .Menu ;
4341import android .view .MenuItem ;
4442import android .view .View ;
43+ import android .view .animation .Animation ;
44+ import android .view .animation .LinearInterpolator ;
45+ import android .view .animation .RotateAnimation ;
4546import android .widget .TextView ;
4647
4748import 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