From d83c15d0d4336d6555ae741d0e85f90cf9886bc4 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 5 Apr 2017 10:45:15 +1000 Subject: [PATCH] Show "Updating repositories" banner in main UI. Previously this was only shown in the notifications. This does not show the full progress of the update, but at least it provides a rudimentary level of feedback. In the future it can be modified to show more substantial feedback if required. --- .../java/org/fdroid/fdroid/UpdateService.java | 13 +++ .../fdroid/views/BannerUpdatingRepos.java | 81 +++++++++++++++++++ .../main/res/layout/main_tab_categories.xml | 34 ++++++-- .../main/res/layout/main_tab_whats_new.xml | 22 +++-- app/src/main/res/values/dimens.xml | 2 + 5 files changed, 137 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/org/fdroid/fdroid/views/BannerUpdatingRepos.java diff --git a/app/src/main/java/org/fdroid/fdroid/UpdateService.java b/app/src/main/java/org/fdroid/fdroid/UpdateService.java index 265651e6f..de53b6432 100644 --- a/app/src/main/java/org/fdroid/fdroid/UpdateService.java +++ b/app/src/main/java/org/fdroid/fdroid/UpdateService.java @@ -90,6 +90,8 @@ public class UpdateService extends IntentService { private NotificationCompat.Builder notificationBuilder; private AppUpdateStatusManager appUpdateStatusManager; + private static boolean updating; + public UpdateService() { super("UpdateService"); } @@ -136,6 +138,14 @@ public class UpdateService extends IntentService { } + /** + * Whether or not a repo update is currently in progress. Used to show feedback throughout + * the app to users, so they know something is happening. + */ + public static boolean isUpdating() { + return updating; + } + @Override public void onCreate() { super.onCreate(); @@ -365,6 +375,7 @@ public class UpdateService extends IntentService { return; } + updating = true; notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build()); LocalBroadcastManager.getInstance(this).registerReceiver(updateStatusReceiver, new IntentFilter(LOCAL_ACTION_STATUS)); @@ -452,6 +463,8 @@ public class UpdateService extends IntentService { } catch (Exception e) { Log.e(TAG, "Exception during update processing", e); sendStatus(this, STATUS_ERROR_GLOBAL, e.getMessage()); + } finally { + updating = false; } long time = System.currentTimeMillis() - startTime; diff --git a/app/src/main/java/org/fdroid/fdroid/views/BannerUpdatingRepos.java b/app/src/main/java/org/fdroid/fdroid/views/BannerUpdatingRepos.java new file mode 100644 index 000000000..a5eff101f --- /dev/null +++ b/app/src/main/java/org/fdroid/fdroid/views/BannerUpdatingRepos.java @@ -0,0 +1,81 @@ +package org.fdroid.fdroid.views; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.support.v4.content.LocalBroadcastManager; +import android.util.AttributeSet; +import android.view.Gravity; +import android.view.View; + +import org.fdroid.fdroid.R; +import org.fdroid.fdroid.UpdateService; + +/** + * Widget which reflects whether or not a repo update is currently in progress or not. If so, shows + * some sort of feedback to the user. + */ +public class BannerUpdatingRepos extends android.support.v7.widget.AppCompatTextView { + + public BannerUpdatingRepos(Context context) { + this(context, null); + } + + public BannerUpdatingRepos(Context context, AttributeSet attrs) { + this(context, attrs, android.R.attr.textViewStyle); + } + + public BannerUpdatingRepos(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + int padding = (int) getResources().getDimension(R.dimen.banner__padding); + setPadding(padding, padding, padding, padding); + setBackgroundColor(0xFF4A4A4A); + setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); + setText(R.string.update_notification_title); + setTextColor(0xFFFFFFFF); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + monitorRepoUpdates(); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + stopMonitoringRepoUpdates(); + } + + private void monitorRepoUpdates() { + if (isInEditMode()) { + return; + } + + LocalBroadcastManager.getInstance(getContext()).registerReceiver(onRepoFeedback, new IntentFilter(UpdateService.LOCAL_ACTION_STATUS)); + setBannerIsVisible(UpdateService.isUpdating()); + } + + private void setBannerIsVisible(boolean isUpdating) { + if (isUpdating) { + setVisibility(View.VISIBLE); + } else { + setVisibility(View.GONE); + } + } + + private void stopMonitoringRepoUpdates() { + LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(onRepoFeedback); + } + + private final BroadcastReceiver onRepoFeedback = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + // Anything other than a STATUS_INFO broadcast signifies that it was complete (and out + // banner should be removed). + boolean isInfo = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, 0) == UpdateService.STATUS_INFO; + setBannerIsVisible(isInfo); + } + }; +} diff --git a/app/src/main/res/layout/main_tab_categories.xml b/app/src/main/res/layout/main_tab_categories.xml index 2d9310292..22257c8b3 100644 --- a/app/src/main/res/layout/main_tab_categories.xml +++ b/app/src/main/res/layout/main_tab_categories.xml @@ -1,5 +1,5 @@ - + + + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + android:scrollbars="vertical" + tools:layout_editor_absoluteX="0dp" /> - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/main_tab_whats_new.xml b/app/src/main/res/layout/main_tab_whats_new.xml index 073f0f9a0..e0cc009e2 100644 --- a/app/src/main/res/layout/main_tab_whats_new.xml +++ b/app/src/main/res/layout/main_tab_whats_new.xml @@ -12,15 +12,23 @@ android:layout_height="match_parent" android:id="@+id/swipe_to_refresh"> - + android:orientation="vertical"> + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 547e4acc4..054dd03be 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -30,4 +30,6 @@ 4dp 72dp 18dp + + 4dp