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

Commit ef7f76a2 authored by James Lemieux's avatar James Lemieux Committed by Android (Google) Code Review
Browse files

Merge "Avoid opening multiple share sheets when sharing laps" into ub-deskclock-huddle

parents 6b7f170d 9b0a12ca
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -94,9 +94,6 @@ public final class StopwatchFragment extends DeskClockFragment {
    /** Displays the current stopwatch time. */
    /** Displays the current stopwatch time. */
    private CountingTimerView mTimeText;
    private CountingTimerView mTimeText;


    /** Number of laps the stopwatch is tracking. */
    private int mLapCount;

    /** The public no-arg constructor required by all fragments. */
    /** The public no-arg constructor required by all fragments. */
    public StopwatchFragment() {
    public StopwatchFragment() {
        super(STOPWATCH);
        super(STOPWATCH);
@@ -140,7 +137,6 @@ public final class StopwatchFragment extends DeskClockFragment {
        super.onStart();
        super.onStart();


        // Conservatively assume the data in the adapter has changed while the fragment was paused.
        // Conservatively assume the data in the adapter has changed while the fragment was paused.
        mLapCount = mLapsAdapter.getItemCount();
        mLapsAdapter.notifyDataSetChanged();
        mLapsAdapter.notifyDataSetChanged();


        // Synchronize the user interface with the data model.
        // Synchronize the user interface with the data model.
@@ -228,12 +224,14 @@ public final class StopwatchFragment extends DeskClockFragment {
    @Override
    @Override
    public void onUpdateFabButtons(@NonNull Button left, @NonNull Button right) {
    public void onUpdateFabButtons(@NonNull Button left, @NonNull Button right) {
        final Resources resources = getResources();
        final Resources resources = getResources();
        left.setEnabled(true);
        left.setText(R.string.sw_reset_button);
        left.setText(R.string.sw_reset_button);
        left.setContentDescription(resources.getString(R.string.sw_reset_button));
        left.setContentDescription(resources.getString(R.string.sw_reset_button));


        switch (getStopwatch().getState()) {
        switch (getStopwatch().getState()) {
            case RESET:
            case RESET:
                left.setVisibility(INVISIBLE);
                left.setVisibility(INVISIBLE);
                right.setEnabled(true);
                right.setVisibility(INVISIBLE);
                right.setVisibility(INVISIBLE);
                break;
                break;
            case RUNNING:
            case RUNNING:
@@ -245,6 +243,7 @@ public final class StopwatchFragment extends DeskClockFragment {
                right.setVisibility(VISIBLE);
                right.setVisibility(VISIBLE);
                break;
                break;
            case PAUSED:
            case PAUSED:
                right.setEnabled(true);
                right.setText(R.string.sw_share_button);
                right.setText(R.string.sw_share_button);
                right.setContentDescription(resources.getString(R.string.sw_share_button));
                right.setContentDescription(resources.getString(R.string.sw_share_button));
                break;
                break;
@@ -295,6 +294,9 @@ public final class StopwatchFragment extends DeskClockFragment {
     * Send stopwatch time and lap times to an external sharing application.
     * Send stopwatch time and lap times to an external sharing application.
     */
     */
    private void doShare() {
    private void doShare() {
        // Disable the fab buttons to avoid double-taps on the share button.
        updateFab(BUTTONS_DISABLE);

        final String[] subjects = getResources().getStringArray(R.array.sw_share_strings);
        final String[] subjects = getResources().getStringArray(R.array.sw_share_strings);
        final String subject = subjects[(int) (Math.random() * subjects.length)];
        final String subject = subjects[(int) (Math.random() * subjects.length)];
        final String text = mLapsAdapter.getShareText();
        final String text = mLapsAdapter.getShareText();
@@ -350,7 +352,6 @@ public final class StopwatchFragment extends DeskClockFragment {


        // Ensure the newly added lap is visible on screen.
        // Ensure the newly added lap is visible on screen.
        mLapsList.scrollToPosition(0);
        mLapsList.scrollToPosition(0);
        mLapCount = mLapsAdapter.getItemCount();
    }
    }


    /**
    /**
@@ -528,7 +529,6 @@ public final class StopwatchFragment extends DeskClockFragment {
        @Override
        @Override
        public void stopwatchUpdated(Stopwatch before, Stopwatch after) {
        public void stopwatchUpdated(Stopwatch before, Stopwatch after) {
            if (after.isReset()) {
            if (after.isReset()) {
                mLapCount = 0;
                if (DataModel.getDataModel().isApplicationInForeground()) {
                if (DataModel.getDataModel().isApplicationInForeground()) {
                    updateUI(BUTTONS_IMMEDIATE);
                    updateUI(BUTTONS_IMMEDIATE);
                }
                }