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.
This commit is contained in:
		
							parent
							
								
									01f27ac404
								
							
						
					
					
						commit
						d83c15d0d4
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
@ -1,5 +1,5 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<android.support.design.widget.CoordinatorLayout
 | 
			
		||||
<android.support.constraint.ConstraintLayout
 | 
			
		||||
    xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    xmlns:app="http://schemas.android.com/apk/res-auto"
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
			
		||||
@ -7,16 +7,34 @@
 | 
			
		||||
    android:layout_width="match_parent"
 | 
			
		||||
    android:layout_height="match_parent">
 | 
			
		||||
 | 
			
		||||
    <org.fdroid.fdroid.views.BannerUpdatingRepos
 | 
			
		||||
        android:id="@+id/banner_updating_repos"
 | 
			
		||||
        android:layout_width="0dp"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent"
 | 
			
		||||
        app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
        app:layout_constraintEnd_toEndOf="parent"
 | 
			
		||||
        tools:layout_editor_absoluteX="8dp" />
 | 
			
		||||
 | 
			
		||||
    <android.support.v7.widget.RecyclerView
 | 
			
		||||
        android:id="@+id/category_list"
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="match_parent"
 | 
			
		||||
        android:layout_width="0dp"
 | 
			
		||||
        android:layout_height="0dp"
 | 
			
		||||
        tools:listitem="@layout/category_item"
 | 
			
		||||
        app:layout_constraintTop_toBottomOf="@+id/banner_updating_repos"
 | 
			
		||||
        app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
        app:layout_constraintLeft_toRightOf="parent"
 | 
			
		||||
        app:layout_constraintTop_toTopOf="parent"
 | 
			
		||||
        android:scrollbars="vertical" />
 | 
			
		||||
        app:layout_constraintStart_toStartOf="parent"
 | 
			
		||||
        app:layout_constraintEnd_toEndOf="parent"
 | 
			
		||||
        android:scrollbars="vertical"
 | 
			
		||||
        tools:layout_editor_absoluteX="0dp" />
 | 
			
		||||
 | 
			
		||||
    <include layout="@layout/fab_search" />
 | 
			
		||||
    <include layout="@layout/fab_search"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
        app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
        app:layout_constraintEnd_toEndOf="parent"
 | 
			
		||||
        android:layout_marginBottom="@dimen/fab_margin"
 | 
			
		||||
        android:layout_marginEnd="@dimen/fab_margin"
 | 
			
		||||
        android:layout_marginRight="@dimen/fab_margin" />
 | 
			
		||||
 | 
			
		||||
</android.support.design.widget.CoordinatorLayout>
 | 
			
		||||
</android.support.constraint.ConstraintLayout>
 | 
			
		||||
@ -12,16 +12,24 @@
 | 
			
		||||
        android:layout_height="match_parent"
 | 
			
		||||
        android:id="@+id/swipe_to_refresh">
 | 
			
		||||
 | 
			
		||||
        <LinearLayout
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="match_parent"
 | 
			
		||||
            android:orientation="vertical">
 | 
			
		||||
 | 
			
		||||
            <org.fdroid.fdroid.views.BannerUpdatingRepos
 | 
			
		||||
                android:layout_width="match_parent"
 | 
			
		||||
                android:layout_height="wrap_content" />
 | 
			
		||||
 | 
			
		||||
            <android.support.v7.widget.RecyclerView
 | 
			
		||||
                android:id="@+id/app_list"
 | 
			
		||||
                android:layout_width="match_parent"
 | 
			
		||||
                android:layout_height="match_parent"
 | 
			
		||||
                tools:listitem="@layout/app_card_normal"
 | 
			
		||||
            app:layout_constraintBottom_toBottomOf="parent"
 | 
			
		||||
            app:layout_constraintLeft_toRightOf="parent"
 | 
			
		||||
            app:layout_constraintTop_toTopOf="parent"
 | 
			
		||||
                android:scrollbars="vertical" />
 | 
			
		||||
 | 
			
		||||
        </LinearLayout>
 | 
			
		||||
 | 
			
		||||
    </android.support.v4.widget.SwipeRefreshLayout>
 | 
			
		||||
 | 
			
		||||
    <include layout="@layout/fab_search" />
 | 
			
		||||
 | 
			
		||||
@ -30,4 +30,6 @@
 | 
			
		||||
    <dimen name="category_preview__app_list__padding__horizontal">4dp</dimen>
 | 
			
		||||
    <dimen name="category_preview__app_list__padding__horizontal__first">72dp</dimen>
 | 
			
		||||
    <dimen name="category_preview__app_list__padding__vertical">18dp</dimen>
 | 
			
		||||
 | 
			
		||||
    <dimen name="banner__padding">4dp</dimen>
 | 
			
		||||
</resources>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user