package com.pixelnx.localhelp.ui.notice;


import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

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

import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.androidnetworking.AndroidNetworking;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.ParsedRequestListener;

import com.pixelnx.localhelp.R;
import com.pixelnx.localhelp.model.ModelUserData;
import com.pixelnx.localhelp.utils.Consts;
import com.pixelnx.localhelp.utils.sharedpref.SharedPref;
import com.pixelnx.localhelp.utils.widgets.CustomTextSemiBold;

    public class ActivityCustomerNotifications extends Activity implements View.OnClickListener {
        ImageView backIv;
        CustomTextSemiBold heading;
         SharedPref sharedPref;
        ModelUserData modelUserData;
        Context mContext;
        RecyclerView rvNoticeList;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_notifications);
            mContext=ActivityCustomerNotifications.this;
            initial();
        }

        void initial() {
            backIv = findViewById(R.id.backIv);
            heading = findViewById(R.id.Heading);
            sharedPref = SharedPref.getInstance(mContext);
            modelUserData = sharedPref.getUser(Consts.Status.SP);
            heading.setText(R.string.notifications);
            backIv.setOnClickListener(this);
            rvNoticeList=findViewById(R.id.rvNoticeList);
            rvNoticeList.setLayoutManager(new LinearLayoutManager(mContext));



            AndroidNetworking.post(Consts.Status.BASE_URL + Consts.Status.GET_NOTICE_API)
                    .addBodyParameter(Consts.Status.USER_ID, "" + modelUserData.getData().getUserId())
                    .setTag(Consts.Status.SEARCH_API)
                    .build().
                    getAsObject(ModelNotice.class, new ParsedRequestListener<ModelNotice>() {
                @Override
                public void onResponse(ModelNotice response) {

                    if(response.getStatus().equalsIgnoreCase("1")){
                        AdapterNoticeList adapterNoticeList=new AdapterNoticeList(mContext,response.getOrderData());
                        rvNoticeList.setAdapter(adapterNoticeList);}

                }

                @Override
                public void onError(ANError anError) {
                    Toast.makeText(mContext,"Something went wrong!!!",Toast.LENGTH_SHORT).show();

                }
            });


        }

        @Override
        public void onClick(View view) {
            if (view.getId() == R.id.backIv) {
                onBackPressed();
            }

        }
    }