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

Commit 21ed120c authored by Trogel's avatar Trogel Committed by Michael W
Browse files

DeskClock: Fix updating remaining time in timer

When a TimerViewHolder is bound to a Timer, we need to start
TimerFragment$TimeUpdateRunnable to get the remaining time updated
continously.

Previously, if a running timer was not bound to a holder and then became
bound, only the circle animation was running, but the remaining time was
updated just once.

Calling updateTime in TimerViewHolder.onBind is no longer needed, since
TimerFragment$TimeUpdateRunnable will do that via
TimerAdapter.updateTime.

Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/8474
Change-Id: I096605db590d200e8b20f36762bded4d0d32ca79
parent 6ef8dcae
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -41,9 +41,11 @@ class TimerAdapter extends RecyclerView.Adapter implements TimerListener {
    /** Maps each timer id to the corresponding {@link TimerViewHolder} that draws it. */
    private final Map<Integer, TimerViewHolder> mHolders = new ArrayMap<>();
    private final TimerClickHandler mTimerClickHandler;
    private final TimerBindHandler mTimerBindHandler;

    public TimerAdapter(TimerClickHandler timerClickHandler) {
    public TimerAdapter(TimerClickHandler timerClickHandler, TimerBindHandler timerBindHandler) {
        mTimerClickHandler = timerClickHandler;
        mTimerBindHandler = timerBindHandler;
    }

    @Override
@@ -65,6 +67,7 @@ class TimerAdapter extends RecyclerView.Adapter implements TimerListener {
        TimerViewHolder holder = (TimerViewHolder) itemViewHolder;
        mHolders.put(getTimer(position).getId(), holder);
        holder.onBind(getTimer(position).getId());
        mTimerBindHandler.onBindTimer();
    }

    @Override
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.deskclock.timer;

import androidx.fragment.app.Fragment;

import com.android.deskclock.data.Timer;
import com.android.deskclock.timer.TimerFragment;

/**
 * Handler to start updating time.
 */
public final class TimerBindHandler {

    private final TimerFragment mTimerFragment;

    public TimerBindHandler(TimerFragment timerFragment) {
        mTimerFragment = timerFragment;
    }

    public void onBindTimer() {
        mTimerFragment.onBindTimer();
    }
}
+8 −2
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public final class TimerFragment extends DeskClockFragment {
    private View mCurrentView;
    private RecyclerView mRecyclerView;
    private TimerClickHandler mTimerClickHandler;
    private TimerBindHandler mTimerBindHandler;

    private Serializable mTimerSetupState;

@@ -104,7 +105,8 @@ public final class TimerFragment extends DeskClockFragment {
        final View view = inflater.inflate(R.layout.timer_fragment, container, false);

        mTimerClickHandler = new TimerClickHandler(this);
        mAdapter = new TimerAdapter(mTimerClickHandler);
        mTimerBindHandler = new TimerBindHandler(this);
        mAdapter = new TimerAdapter(mTimerClickHandler, mTimerBindHandler);
        mRecyclerView = view.findViewById(R.id.recycler_view);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.setLayoutManager(getLayoutManager(view.getContext()));
@@ -318,6 +320,10 @@ public final class TimerFragment extends DeskClockFragment {
        return super.onKeyDown(keyCode, event);
    }

    public void onBindTimer() {
      startUpdatingTime();
    }

    /**
     * Display the view that creates a new timer.
     */
@@ -468,7 +474,7 @@ public final class TimerFragment extends DeskClockFragment {

    private Timer getTimer() {
        if (mAdapter == null) {
            TimerAdapter adapter = new TimerAdapter(mTimerClickHandler);
            TimerAdapter adapter = new TimerAdapter(mTimerClickHandler, mTimerBindHandler);
            return adapter.getItemCount() == 0 ? null : adapter.getTimer(0);
        }

+0 −1
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ public class TimerViewHolder extends RecyclerView.ViewHolder {

    public void onBind(int timerId) {
        mTimerId = timerId;
        updateTime();
    }

    private void setLayoutParams(View view) {