package com.team.app.activities;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.team.app.Constant;
import com.team.app.Functions;
import com.team.app.R;
import com.team.app.adapter.TipsAdapter;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.AdapterStatus;

import java.util.Map;

public class TipsActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    private AdView adView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tips);
        MobileAds.initialize(this, initializationStatus -> {
            Map<String, AdapterStatus> statusMap = initializationStatus.getAdapterStatusMap();
            for (String adapterClass : statusMap.keySet()) {
                AdapterStatus status = statusMap.get(adapterClass);
            }
            FrameLayout adContainerView0 = findViewById(R.id.bannerAdView);
            if(Constant.adShown && !Constant.BANNER_ADS_ID.equals("")) {
                adView = new com.google.android.gms.ads.AdView(this);
                adView.setAdUnitId(Constant.BANNER_ADS_ID);
                adContainerView0.addView(adView);
                adView.setAdSize(Functions.getAdSize(this));
                adView.loadAd(new AdRequest.Builder().build());
                adContainerView0.setVisibility(View.VISIBLE);
            }
        });
        findViewById(R.id.back).setOnClickListener(view -> TipsActivity.this.onBackPressed());
        findViewById(R.id.gifImage).setOnClickListener(view -> startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse(getResources().getString(R.string.fantasy_power_11_link)))));
        recyclerView = findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new TipsAdapter(this));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(adView != null) {
            adView.destroy();
        }
    }
}
