Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CardAttachmentsBottomsheetBehaviorCallback.java « attachments « card « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 13fc2a676d4304bfa7882000886ba2448059b997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package it.niedermann.nextcloud.deck.ui.card.attachments;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.ColorInt;
import androidx.annotation.DimenRes;
import androidx.annotation.NonNull;
import androidx.annotation.Px;
import androidx.core.content.ContextCompat;

import com.google.android.material.animation.ArgbEvaluatorCompat;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;

public class CardAttachmentsBottomsheetBehaviorCallback extends BottomSheetBehavior.BottomSheetCallback {
    @NonNull
    private final OnBackPressedCallback backPressedCallback;
    @NonNull
    private final FloatingActionButton fab;
    @NonNull
    private final View pickerBackdrop;
    @NonNull
    private final BottomNavigationView bottomNavigation;
    @ColorInt
    private final int backdropColorExpanded;
    @ColorInt
    private final int backdropColorCollapsed;
    @Px
    private final int bottomNavigationHeight;

    private float lastOffset = -1;

    public CardAttachmentsBottomsheetBehaviorCallback(@NonNull Context context,
                                                      @NonNull OnBackPressedCallback backPressedCallback,
                                                      @NonNull FloatingActionButton fab,
                                                      @NonNull View pickerBackdrop,
                                                      @NonNull BottomNavigationView bottomNavigation,
                                                      @DimenRes int bottomNavigationHeight
    ) {
        this.backPressedCallback = backPressedCallback;
        this.fab = fab;
        this.pickerBackdrop = pickerBackdrop;
        this.bottomNavigation = bottomNavigation;
        final var color = ContextCompat.getColor(context, android.R.color.black);
        this.backdropColorExpanded = Color.argb(127, Color.red(color), Color.green(color), Color.blue(color));
        this.backdropColorCollapsed = ContextCompat.getColor(context, android.R.color.transparent);
        this.bottomNavigationHeight = context.getResources().getDimensionPixelSize(bottomNavigationHeight);
    }

    @Override
    public void onStateChanged(@NonNull View bottomSheet, int newState) {
        if (newState == STATE_HIDDEN) {
            backPressedCallback.setEnabled(false);
            if (pickerBackdrop.getVisibility() != GONE) {
                pickerBackdrop.setVisibility(GONE);
            }
        } else if (pickerBackdrop.getVisibility() != VISIBLE) {
            pickerBackdrop.setVisibility(VISIBLE);
        }
    }

    @Override
    public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        if (slideOffset <= 0) {
            final float bottomSheetPercentageShown = slideOffset * -1;
            pickerBackdrop.setBackgroundColor(ArgbEvaluatorCompat.getInstance().evaluate(bottomSheetPercentageShown, backdropColorExpanded, backdropColorCollapsed));
            bottomNavigation.setTranslationY(bottomSheetPercentageShown * bottomNavigationHeight);
            if (slideOffset <= lastOffset && slideOffset != 0) {
                fab.show();
            } else {
                fab.hide();
            }
        }
        lastOffset = slideOffset;
    }
}