package com.cpm.lorealbaMabeline.dailyactivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.cpm.lorealbaMabeline.Database.Lorealba_Database;
import com.cpm.lorealbaMabeline.R;
import com.cpm.lorealbaMabeline.constant.CommonFunctions;
import com.cpm.lorealbaMabeline.constant.CommonString;
import com.cpm.lorealbaMabeline.delegates.PrefHelper;

public class NotificationDetailActivity extends AppCompatActivity {
    String visit_date, username, counter_id, userType, title, body, path, type, keyId;
    private SharedPreferences preferences = null;
    private SharedPreferences.Editor editor = null;
    TextView tv_title_text, tv_message;
    Lorealba_Database db;
    VideoView videoView;
    CardView card_text;
    ImageView imgview;
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification_detail);
        context = this;
       preferences = PrefHelper.getPrefs(context);
        counter_id = preferences.getString(CommonString.KEY_COUNTER_ID, "");
        visit_date = preferences.getString(CommonString.KEY_DATE, "");
        username = preferences.getString(CommonString.KEY_USERNAME, "");
        userType = preferences.getString(CommonString.KEY_USER_TYPE, "");
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        if (!CommonFunctions.isTablet(this)) {
            toolbar.setTitleTextAppearance(this, R.style.changestext_sizefor_mobile);
        }

        setTitle("Details");
        db = new Lorealba_Database(this);

        type = getIntent().getStringExtra("type");
        title = getIntent().getStringExtra("Title");
        body = getIntent().getStringExtra("Body");
        path = getIntent().getStringExtra("Path");

        keyId = getIntent().getStringExtra("KEY_ID");
        db.open();
        db.updateNotificationDetails("1", keyId);
        db.open();
        db.insertnotification_users(username,visit_date, counter_id,keyId);

        tv_title_text = (TextView) findViewById(R.id.tv_title);
        tv_message = (TextView) findViewById(R.id.tv_message);
        card_text = (CardView) findViewById(R.id.parent_text_msg);


        imgview = (ImageView) findViewById(R.id.img_notification);
        videoView = (VideoView) findViewById(R.id.video_view);
        tv_title_text.setText(title);
        tv_message.setText(body);

        if (type != null && type.equalsIgnoreCase("Image")) {
            imgview.setVisibility(View.VISIBLE);

            Glide.with(this).load(path)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .skipMemoryCache(true)
                    .into(imgview);

        } else if (type != null && type.equalsIgnoreCase("Video")) {
            videoView.setVisibility(View.VISIBLE);
            videoView.setVideoPath(path);
            videoView.start();
        } else {
            if (path != null) {
                imgview.setVisibility(View.VISIBLE);

                Glide.with(this)
                        .load(path)
                        .diskCacheStrategy(DiskCacheStrategy.NONE)
                        .skipMemoryCache(true)
                        .into(imgview);
            } else {
                imgview.setVisibility(View.GONE);
            }

        }

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent resultIntent = new Intent();
// TODO Add extras or a data URI to this intent as appropriate.
                resultIntent.putExtra("some_key", "String data");
                setResult(Activity.RESULT_OK, resultIntent);
                finish();
            }
        });
    }

    @Override
    public void onBackPressed() {
    }
}
