package com.yono.messeripos;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textview.MaterialTextView;

public class SplashScreen extends AppCompatActivity {
    ImageView img;
    MaterialTextView textView;
    SharedPreferences sharedPreferences;
    public static final String MY_SHARED_PREFERENCES = "my_shared_preferences";
    public static final String SESSION = "session";
    public static Boolean session;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.activity_splash);
        img = findViewById(R.id.image_splash);
        textView = findViewById(R.id.messer_id);

        Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.translate);
        img.startAnimation(animation);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                textView.setVisibility(View.VISIBLE);
                Animation txt = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in);
                textView.startAnimation(txt);
            }
        }, 700);
        sharedPreferences = getSharedPreferences(MY_SHARED_PREFERENCES, Context.MODE_PRIVATE);
        session = sharedPreferences.getBoolean(SESSION, false);



        new Handler(Looper.getMainLooper()).postDelayed(()->{
            if (session){
                startActivity(new Intent(SplashScreen.this, MainActivity.class));
                finish();
            }else{
                startActivity(new Intent(SplashScreen.this, LoginActivity.class));
                finish();
            }
        }, 3500);
    }
}
