aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SetAsWallpaperBottomSheetFragment.java
blob: ea2e96a85d089a699a30c4ecffa9a4e8455f6378 (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
package ml.docilealligator.infinityforreddit.bottomsheetfragments;

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

import androidx.annotation.NonNull;

import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback;
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.FragmentSetAsWallpaperBottomSheetBinding;
import ml.docilealligator.infinityforreddit.utils.Utils;

public class SetAsWallpaperBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment {

    public static final String EXTRA_VIEW_PAGER_POSITION = "EVPP";

    private Activity mActivity;

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

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        FragmentSetAsWallpaperBottomSheetBinding binding = FragmentSetAsWallpaperBottomSheetBinding.inflate(inflater, container, false);

        Bundle bundle = getArguments();
        int viewPagerPosition = bundle == null ? -1 : bundle.getInt(EXTRA_VIEW_PAGER_POSITION);

        binding.bothTextViewSetAsWallpaperBottomSheetFragment.setOnClickListener(view -> {
            if (mActivity instanceof SetAsWallpaperCallback) {
                ((SetAsWallpaperCallback) mActivity).setToBoth(viewPagerPosition);
            }
            dismiss();
        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            binding.homeScreenTextViewSetAsWallpaperBottomSheetFragment.setVisibility(View.VISIBLE);
            binding.lockScreenTextViewSetAsWallpaperBottomSheetFragment.setVisibility(View.VISIBLE);

            binding.homeScreenTextViewSetAsWallpaperBottomSheetFragment.setOnClickListener(view -> {
                if (mActivity instanceof SetAsWallpaperCallback) {
                    ((SetAsWallpaperCallback) mActivity).setToHomeScreen(viewPagerPosition);
                }
                dismiss();
            });

            binding.lockScreenTextViewSetAsWallpaperBottomSheetFragment.setOnClickListener(view -> {
                if (mActivity instanceof SetAsWallpaperCallback) {
                    ((SetAsWallpaperCallback) mActivity).setToLockScreen(viewPagerPosition);
                }
                dismiss();
            });
        }

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

        return binding.getRoot();
    }

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