package de.jg_cody.Teraplex.ui.zeitsteuerung;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TimePicker;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import java.util.Base64;
import java.util.Objects;

import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R;

public class ZeitsteuerungFragment extends Fragment {

    private ZeitsteuerungViewModel zeitsteuerungViewModel;
    TimePicker timePicker;

    @RequiresApi(api = Build.VERSION_CODES.O)
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        zeitsteuerungViewModel =
                new ViewModelProvider(this).get(ZeitsteuerungViewModel.class);
        View root = inflater.inflate(R.layout.fragment_zeitsteuerung, container, false);
        SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
        String Background = p.getString("Background", null);
        if (Background != null) {
            ImageView I = root.findViewById(R.id.Background);
            byte[] BA = Base64.getDecoder().decode(Background);
            I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
            I.setScaleType(ImageView.ScaleType.CENTER_CROP);
        }
        TimePicker timePicker = (TimePicker) root.findViewById(R.id.timePicker);
        timePicker.setIs24HourView(true);
        return root;
    }
}