Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9dcfb27c authored by Austin Tankiang's avatar Austin Tankiang Committed by Android (Google) Code Review
Browse files

Merge changes I63631cd2,I456cff33 into main

* changes:
  Apply extra round corners to first and last job item cards
  Add scrollbars to the job progress panel
parents 611087fc 1b2e13be
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@
    xmlns:app="http://schemas.android.com/apk/res-auto"
    style="@style/JobProgressItemCardStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    android:layout_height="wrap_content"
    android:layout_marginHorizontal="@dimen/job_progress_list_margin">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
+1 −1
Original line number Diff line number Diff line
@@ -43,9 +43,9 @@
                android:id="@+id/job_progress_list"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="@dimen/job_progress_list_margin"
                android:paddingBottom="@dimen/job_progress_list_margin"
                android:clipToPadding="false"
                android:scrollbars="vertical"
                app:layout_constraintHeight_max="@dimen/job_progress_list_max_height"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
+3 −1
Original line number Diff line number Diff line
@@ -202,9 +202,11 @@

    <style name="JobProgressItemCardStyle" parent="@style/Widget.Material3.CardView.Filled">
        <item name="cardBackgroundColor">?attr/colorSurfaceContainer</item>
        <item name="shapeAppearance">@style/ShapeAppearance.Material3.Corner.ExtraSmall</item>
        <item name="shapeAppearance">@style/JobProgressItemCardBaseShape</item>
    </style>

    <style name="JobProgressItemCardBaseShape" parent="@style/ShapeAppearance.Material3.Corner.ExtraSmall" />

    <style name="JobProgressItemTitleStyle" parent="">
        <item name="android:textAppearance">@style/JobProgressItemTitleText</item>
    </style>
+37 −32
Original line number Diff line number Diff line
@@ -19,10 +19,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Canvas
import android.graphics.Path
import android.graphics.Rect
import android.graphics.RectF
import android.text.format.Formatter
import android.util.Log
import android.view.LayoutInflater
@@ -33,7 +30,6 @@ import android.widget.Button
import android.widget.PopupWindow
import android.widget.ProgressBar
import android.widget.TextView
import androidx.core.view.isEmpty
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.ListAdapter
@@ -44,7 +40,9 @@ import com.android.documentsui.services.FileOperationService.EXTRA_PROGRESS
import com.android.documentsui.services.Job
import com.android.documentsui.services.JobProgress
import com.android.documentsui.util.FormatUtils
import com.google.android.material.card.MaterialCardView
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.google.android.material.shape.ShapeAppearanceModel

/**
 * Adds a gap between items in a vertical Recycler View.
@@ -64,29 +62,6 @@ private class VerticalMarginItemDecoration(
    }
}

/**
 * Adds rounded corners to the extremes (i.e. the first and last items in a list) of the Recycler
 * View. It does this by getting the bounding box of all items and clipping the canvas to a rounded
 * rectangle of the same size.
 */
private class RoundedCornerExtremitiesItemDecoration(
    private val mCornerRadius: Float
) : RecyclerView.ItemDecoration() {
    override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
        if (parent.isEmpty()) return

        val firstRect = Rect()
        val lastRect = Rect()
        parent.getDecoratedBoundsWithMargins(parent.getChildAt(0), firstRect)
        parent.getDecoratedBoundsWithMargins(parent.getChildAt(parent.childCount - 1), lastRect)
        firstRect.union(lastRect)

        val path = Path()
        path.addRoundRect(RectF(firstRect), mCornerRadius, mCornerRadius, Path.Direction.CW)
        c.clipPath(path)
    }
}

/**
 * JobPanelController is responsible for receiving broadcast updates from the [FileOperationService]
 * and updating a given menu item to reflect the current progress.
@@ -160,9 +135,42 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() {
    class ProgressListAdapter(val mController: JobPanelController) :
        ListAdapter<JobProgress, ProgressItemHolder>(JobDiffCallback) {

        companion object {
            // Constants for the different view types created by this adapter. The type depends on
            // the position of the item in the list.
            private const val VIEW_MIDDLE = 0
            private const val VIEW_TOP = 1
            private const val VIEW_BOTTOM = 2
            private const val VIEW_TOP_BOTTOM = 3
        }

        override fun getItemViewType(position: Int): Int {
            if (itemCount == 1) return VIEW_TOP_BOTTOM
            if (position == 0) return VIEW_TOP
            if (position == itemCount - 1) return VIEW_BOTTOM
            return VIEW_MIDDLE
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProgressItemHolder {
            val view = LayoutInflater.from(parent.context)
                .inflate(R.layout.job_progress_item, parent, false)
            val context = parent.context
            val view = LayoutInflater.from(context)
                .inflate(R.layout.job_progress_item, parent, false) as MaterialCardView
            if (viewType != 0) {
                val outerRadius =
                    context.resources.getDimension(R.dimen.job_progress_list_corner_radius)
                view.shapeAppearanceModel = ShapeAppearanceModel
                    .builder(context, R.style.JobProgressItemCardBaseShape, 0)
                    .apply {
                        if (viewType == VIEW_TOP_BOTTOM || viewType == VIEW_TOP) {
                            setTopLeftCornerSize(outerRadius)
                            setTopRightCornerSize(outerRadius)
                        }
                        if (viewType == VIEW_TOP_BOTTOM || viewType == VIEW_BOTTOM) {
                            setBottomLeftCornerSize(outerRadius)
                            setBottomRightCornerSize(outerRadius)
                        }
                    }.build()
            }
            return ProgressItemHolder(mController, view)
        }

@@ -246,9 +254,6 @@ class JobPanelController(private val mContext: Context) : BroadcastReceiver() {
                addItemDecoration(VerticalMarginItemDecoration(
                    mContext.resources.getDimensionPixelSize(R.dimen.job_progress_list_gap)
                ))
                addItemDecoration(RoundedCornerExtremitiesItemDecoration(
                    mContext.resources.getDimension(R.dimen.job_progress_list_corner_radius)
                ))
                itemAnimator = null
                adapter = listAdapter
            }