aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/PlaybackSpeedBottomSheetFragment.java
blob: e0fbb15188ee8b6936592b808434d7aa0020fcb3 (plain) (blame)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package ml.docilealligator.infinityforreddit.bottomsheetfragments;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity;
import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity;
import ml.docilealligator.infinityforreddit.activities.ViewVideoActivity;
import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment;
import ml.docilealligator.infinityforreddit.databinding.FragmentPlaybackSpeedBinding;
import ml.docilealligator.infinityforreddit.fragments.ViewImgurVideoFragment;
import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryVideoFragment;
import ml.docilealligator.infinityforreddit.utils.Utils;

public class PlaybackSpeedBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {

    public static final String EXTRA_PLAYBACK_SPEED = "EPS";

    private Activity activity;

    public PlaybackSpeedBottomSheetFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        FragmentPlaybackSpeedBinding binding = FragmentPlaybackSpeedBinding.inflate(inflater, container, false);

        int playbackSpeed = getArguments().getInt(EXTRA_PLAYBACK_SPEED, ViewVideoActivity.PLAYBACK_SPEED_NORMAL);
        switch (playbackSpeed) {
            case ViewVideoActivity.PLAYBACK_SPEED_25:
                binding.playbackSpeed025TextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
            case ViewVideoActivity.PLAYBACK_SPEED_50:
                binding.playbackSpeed050TextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
            case ViewVideoActivity.PLAYBACK_SPEED_75:
                binding.playbackSpeed075TextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
            case ViewVideoActivity.PLAYBACK_SPEED_NORMAL:
                binding.playbackSpeedNormalTextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
            case ViewVideoActivity.PLAYBACK_SPEED_125:
                binding.playbackSpeed125TextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
            case ViewVideoActivity.PLAYBACK_SPEED_150:
                binding.playbackSpeed150TextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
            case ViewVideoActivity.PLAYBACK_SPEED_175:
                binding.playbackSpeed175TextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
            case ViewVideoActivity.PLAYBACK_SPEED_200:
                binding.playbackSpeed200TextViewPlaybackSpeedBottomSheetFragment.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_playback_speed_day_night_24dp, 0);
                break;
        }

        binding.playbackSpeed025TextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_25);
            dismiss();
        });

        binding.playbackSpeed050TextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_50);
            dismiss();
        });

        binding.playbackSpeed075TextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_75);
            dismiss();
        });

        binding.playbackSpeedNormalTextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_NORMAL);
            dismiss();
        });

        binding.playbackSpeed125TextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_125);
            dismiss();
        });

        binding.playbackSpeed150TextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_150);
            dismiss();
        });

        binding.playbackSpeed175TextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_175);
            dismiss();
        });

        binding.playbackSpeed200TextViewPlaybackSpeedBottomSheetFragment.setOnClickListener(view -> {
            setPlaybackSpeed(ViewVideoActivity.PLAYBACK_SPEED_200);
            dismiss();
        });

        if (activity instanceof ViewVideoActivity) {
            if (((ViewVideoActivity) activity).typeface != null) {
                Utils.setFontToAllTextViews(binding.getRoot(), ((ViewVideoActivity) activity).typeface);
            }
        } else if (activity instanceof ViewImgurMediaActivity) {
            if (((ViewImgurMediaActivity) activity).typeface != null) {
                Utils.setFontToAllTextViews(binding.getRoot(), ((ViewImgurMediaActivity) activity).typeface);
            }
        } else if (activity instanceof ViewRedditGalleryActivity) {
            if (((ViewRedditGalleryActivity) activity).typeface != null) {
                Utils.setFontToAllTextViews(binding.getRoot(), ((ViewRedditGalleryActivity) activity).typeface);
            }
        }
        return binding.getRoot();
    }

    private void setPlaybackSpeed(int playbackSpeed) {
        if (activity instanceof ViewVideoActivity) {
            ((ViewVideoActivity) activity).setPlaybackSpeed(playbackSpeed);
        } else {
            Fragment parentFragment = getParentFragment();
            if (parentFragment instanceof ViewImgurVideoFragment) {
                ((ViewImgurVideoFragment) parentFragment).setPlaybackSpeed(playbackSpeed);
            } else if (parentFragment instanceof ViewRedditGalleryVideoFragment) {
                ((ViewRedditGalleryVideoFragment) parentFragment).setPlaybackSpeed(playbackSpeed);
            }
        }
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        activity = (Activity) context;
    }
}