Attribute value must be constant

Author: jeenashyjuCreated Feb 1, 2024Updated Feb 12, 2025

package com.microtechsoftwaresolutions.suitappssfa.Fragements;

import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Address; import android.location.Geocoder; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import butterknife.BindView; import butterknife.ButterKnife; import androidx.annotation.RequiresApi; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.cardview.widget.CardView; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.GridLayoutManager;

import com.microtechsoftwaresolutions.suitappssfa.R; import com.microtechsoftwaresolutions.suitappssfa.Activity.BaseActivity; import com.microtechsoftwaresolutions.suitappssfa.App.SuitAppsSFA; //import com.microtechsoftwaresolutions.suitappssfa.CallApi.ApiCall; import com.microtechsoftwaresolutions.suitappssfa.Constant.Constant; import com.microtechsoftwaresolutions.suitappssfa.Helper.DatabaseHelper; import com.microtechsoftwaresolutions.suitappssfa.Helper.SessionManager_Login; import com.microtechsoftwaresolutions.suitappssfa.Model.DateFormater; import com.microtechsoftwaresolutions.suitappssfa.Model.EmployeeLocation; import com.microtechsoftwaresolutions.suitappssfa.Model.PlacesList; import com.microtechsoftwaresolutions.suitappssfa.Model.Products; import com.microtechsoftwaresolutions.suitappssfa.Services.AutoSyncDirectSale; import com.microtechsoftwaresolutions.suitappssfa.Services.AutoSyncLocation; import com.microtechsoftwaresolutions.suitappssfa.Services.GpsTracker2;

import org.json.JSONArray; import org.json.JSONObject;

import java.io.IOException; import java.text.DateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; import butterknife.BindView;

import butterknife.BindView; import butterknife.ButterKnife;

import static android.content.ContentValues.TAG; import static com.microtechsoftwaresolutions.suitappssfa.R.id.directsaletotal;

/**

  • Created by : jisha ann mathew
  • Created date : 22-Apr-17.
  • Created for : Base fragment contains Tabs */

public class BaseFragment extends Fragment { GridLayoutManager gridLayoutManager; // @BindView(R.id.tablayout) // TabLayout tabLayout; // @BindView(R.id.viewpager) // ViewPager viewpager; // ViewPagerAdapter adapter;

****@BindView(R.id.pendingtarget)**
TextView mytarget;
**@BindView(R.id.directsaletotal)**
TextView  directsaletotal;
**@BindView(R.id.user_name)**
TextView username;
**@BindView(R.id.totalproducts)**
TextView totalproducts;
**@BindView(R.id.totalnewcustomer)**
TextView txtnewcustomer;
**@BindView(R.id.totalcustomers)**
TextView txtexcustomer;
**@BindView(R.id.myCardView4)**
CardView createdcustomers;
@BindView(R.id.checkin)
TextView checkincustomer;
**@BindView(R.id.directsalecardview)**
CardView directsale;

@BindView(R.id.ex_customerscardview) CardView excustomer; @BindView(R.id.pendcust) TextView txtcustomer; @BindView(R.id.totalsalesCardView) CardView totalsalesCardView;

CardView productsCardView;**

TextView MRNG;
CardView myCardView3;

// @BindView(R.id.ltSaleOrder) // LinearLayout ltSaleOrder;

String Total_STOCK, Total_SALE, Total_AVAIL, Total_VATAMT, Total_Products, DATE, TIME,Cust,count;
String USERNAME,PASSWORD,COMPANYID;
String sLatitude,sLongitude;

private TextView salesTotal;
ArrayList<Products> Stockitem;

String dayOfTheWeek,Day,CompanyID,EmpId,RouteID,Date;
HashMap<String, String> user;

SessionManager_Login savedSession;
String userid,companyid,routeid,target;
String currentDate;
private ActionBarDrawerToggle mDrawerToggle;
SessionManager_Login loginSession;
SessionManager_Login logout;
DatabaseHelper helper;
ArrayList<PlacesList> placesListArrayList=null;
ArrayList<Products> productArrayList;
Products products;
int position=0;
public static int currentPage=0;



@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_home, container, false);
    ButterKnife.bind(this, view);
    SuitAppsSFA.setFullscreen(getActivity());
    helper = new DatabaseHelper(getActivity());
    Stockitem = new ArrayList<Products>();
    salesTotal=(TextView)view.findViewById(R.id.total_salesdone);
    myCardView3=(CardView) view.findViewById(R.id.myCardView3);
    username=(TextView)view.findViewById(R.id.user_name) ;
    MRNG=(TextView)view.findViewById(R.id.gudmrng);
    mytarget=(TextView)view.findViewById(R.id.pendingtarget);

    directsaletotal=(TextView)view.findViewById(R.id.directsaletotal);
    username=(TextView) view.findViewById(R.id.user_name);
    totalproducts=(TextView)view.findViewById(R.id.totalproducts) ;
    txtnewcustomer=(TextView)view.findViewById(R.id.totalnewcustomer);
    txtexcustomer=(TextView)view.findViewById(R.id.totalcustomers);

    checkincustomer=(TextView) view.findViewById(R.id.checkin);
    txtcustomer=(TextView)view.findViewById(R.id.pendcust) ;



    helper = new DatabaseHelper(getActivity());
    loginSession = new SessionManager_Login(getActivity());
    logout = new SessionManager_Login(getActivity());
    HashMap<String, String> user = loginSession.getUserDetails();
    userid = user.get(SessionManager_Login.KEY_UserID);
    USERNAME=user.get(SessionManager_Login.KEY_NAME);
    dayPicker();
    settotal();
    settarget();
    setexcustomers();
    settotalproducts();
    setnewcustomers();
    setdirectsalecount();
    setcustomer();
    getLocation();
    locService1();
    getActivity().setTitle("SuitApps");


    Calendar c = Calendar.getInstance();
    int timeOfDay = c.get(Calendar.HOUR_OF_DAY);

    if (timeOfDay >= 0 && timeOfDay < 12) {
        MRNG.setText("Good Morning");
    } else if (timeOfDay >= 12 && timeOfDay < 16) {
        MRNG.setText("Good Afternoon");
    } else if (timeOfDay >= 16 && timeOfDay < 21) {
        MRNG.setText("Good Evening");
    } else if (timeOfDay >= 21 && timeOfDay < 24) {
        MRNG.setText("Good Night");
    }
    return view;
}

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().setTitle("SuitApps");
    username.setText(USERNAME);


}

//region Backpress
/**
 * Could handle back press.
 * @return true if back press was handled
 */
public boolean onBackPressed() {

    return false;
}
@RequiresApi(api = Build.VERSION_CODES.N)
private void dayPicker() {
   // Calendar calendar = Calendar.getInstance();
    //String dayOfTheWeek = calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("EEEE");
    Date d = new Date();
    dayOfTheWeek = sdf.format(d);
}

public void settotal(){
    String myTarget=helper.setTotal(userid);
    directsaletotal.setText(myTarget);
}

public void settarget(){
    String myTarget=helper.setTarget(userid);
    mytarget.setText(myTarget);
}
public void setexcustomers(){
    int excustomer=helper.customerRowCount();
    String count=String.valueOf(excustomer);
    txtexcustomer.setText(count);
}

public void setcustomer(){
    int excustomer=helper.customerCount(DATE);
    int ascustomer = helper.customerASCount(DATE);
    int d = excustomer + ascustomer;
    String count = String.valueOf(d);
    checkincustomer.setText(count);
    int excust = Integer.parseInt((txtexcustomer.getText().toString()));
    int checkin = Integer.parseInt(checkincustomer.getText().toString());
    int pendingcust =(excust-checkin);
    Cust = String.valueOf(pendingcust );
    txtcustomer.setText(Cust);
}


public void setdirectsalecount(){
    int directsale=helper.DS_sync_Count();
    String count=String.valueOf(directsale);
    salesTotal.setText(count);
}

public void settotalproducts(){
    int productcount=helper.ProductRowCount();
    String count=String.valueOf(productcount);
    totalproducts.setText((count));

}
public void setnewcustomers(){
    int newcustomer=helper.NewcustomerRowCount();
    String count=String.valueOf(newcustomer);
    txtnewcustomer.setText((count));

}



@Override
public void onResume() {
    super.onResume();

    if (getView() == null) {
        return;
    }

    getView().setFocusableInTouchMode(true);
    getView().requestFocus();
    getView().setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {

            if (keyEvent.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {


                DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int choice) {
                        switch (choice) {
                            case DialogInterface.BUTTON_POSITIVE:
                                logout.logoutUser();
                                Intent intent = new Intent(getActivity(), BaseActivity.class);
                                intent.putExtra("logout",0 );
                                startActivity(intent);
                                Toast.makeText(getActivity(), "Logout Succesfully", Toast.LENGTH_LONG).show();
                                dialog.dismiss();

                                break;
                            case DialogInterface.BUTTON_NEGATIVE:
                                dialog.dismiss();
                                break;
                        }
                    }
                };

                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setMessage("WARNING :  Are you sure ? Do you want to Logout ?")
                        .setPositiveButton("Yes", dialogClickListener)
                        .setNegativeButton("No", dialogClickListener).show();



                return true;
            }
            return false;
        }
    });
}

void getLocation() {
    try {
        getLatitudeAndLongitude();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

GpsTracker2 locationTrack;

public void getLatitudeAndLongitude() throws IOException {
    locationTrack = new GpsTracker2(getActivity());
    try {
        if (ContextCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, 101);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (locationTrack.canGetLocation()) {

        double longitude = locationTrack.getLongitude();
        double latitude = locationTrack.getLatitude();
        Log.d("longitude", " " + longitude);
        Log.d("latitude", " " + latitude);
        String address = getAddress(this,latitude,longitude);
        sLatitude = String.valueOf(latitude);
        sLongitude = String.valueOf(longitude);

    }

}


public String getAddress(BaseFragment ctx, double lat, double lng){
    String fullAdd=null;
    try{
        Geocoder geocoder= new Geocoder(getActivity(), Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(lat,lng,1);
        if(addresses.size()>0){
            Address address = addresses.get(0);
            fullAdd = address.getAddressLine(0);

            String zip = address.getPostalCode();
            String Country = address.getCountryName();
            String localityString = address.getLocality();
            String street = address.getSubLocality();
            String city = address.getCountryName();
            String region_code = address.getCountryCode();
            String zipcode = address.getPostalCode();
            Log.d("street"," "+street );
            Log.d("localityString"," "+localityString );
            Log.d("city"," "+city );
            Log.d("region_code"," "+region_code );
            Log.d("zipcode"," "+zipcode );
            Log.d("max"," "+addresses );
            Log.d("zip", " " + zip);
            Log.d("Country", " " + Country);

            sLatitude = String.valueOf(lat);
            sLongitude = String.valueOf(lng);
            DateFormater dateFormater = new DateFormater();
            dateFormater = SuitAppsSFA.dayPicker();

            EmployeeLocation location = new EmployeeLocation();
            location.setlocid(String.valueOf(0));
            location.setempid(userid);
            location.setdate(dateFormater.getBillDate());
            if(street == null)
            {
                location.setplace(localityString);
            }
            else if(localityString==null) {
                location.setplace(street);
            }
            else{
                location.setplace("NA");
            }
            location.setlatitude(sLatitude);
            location.setlongitude(sLongitude);
            helper.insertLocation(location);

        }


    }catch(IOException ex){
        ex.printStackTrace();
    }
    return fullAdd;
}
private void callSyncService() { getActivity().startService(new Intent(getActivity(), AutoSyncDirectSale.class)); }

// private void callSyncService1() { getActivity().startService(new Intent(getActivity(), AutoSyncCustomer.class)); }

private class GetImage extends AsyncTask<String, Void, JSONObject> {
    ProgressDialog dialog;
    JSONArray jsonarray;
    JSONObject jsonObject = null;
    @Override
    protected JSONObject doInBackground(String... params) {
        // Implement your background task logic here
        // This method runs in the background thread and performs the task
        return null;  // Change the return type based on your implementation
    }
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

// dialog = new ProgressDialog(getActivity()); // dialog.setMessage("Please Wait ....Downloading products....."); // dialog.show(); }

// @Override // protected JSONObject doInBackground(String... params) { // String JsonDATA = params[0]; // return ApiCall.getDataById(Constant.GETITEMIMAGE, JsonDATA); // }

    @Override
    protected void onPostExecute(JSONObject jsonobject) {
        super.onPostExecute(jsonobject);
        //  dialog.dismiss();
        // Locate the NodeList name
        if (jsonobject != null ) {
            new DbInsert_Async1().execute(jsonobject);
        }else {
            SuitAppsSFA.showAToast("Check your Internet connection...");
        }
    }
}
//endregion
//region db insert
private class DbInsert_Async1 extends AsyncTask<JSONObject, Void, ArrayList<Products>>
{
    JSONArray jsonarray =null;
    ProgressDialog progressDialog =null;
    @Override
    protected void onPreExecute() {
        super.onPreExecute();

// progressDialog = new ProgressDialog(getActivity()); // progressDialog.setMessage("Saving images....."); // progressDialog.show(); }

    @Override
    protected ArrayList<Products> doInBackground(JSONObject... params) {
        JSONObject jsonobject = params[0];
        Log.d(TAG, "doInBackground: "+jsonobject);
        try {
            //productList = new ArrayList<String>();
            productArrayList = new ArrayList<Products>();
            // Locate the NodeList name
            jsonarray = jsonobject.getJSONArray("productimagelist");
            for (int i = 0; i < jsonarray.length(); i++) {
                jsonobject = jsonarray.getJSONObject(i);

                products = new Products();

                // products.setImage(jsonobject.toString().getBytes("Image"));


                products.setItemCode(jsonobject.getString("ItemID"));
                //  products.setImage(jsonobject. getString("Image"));
                products.setImage(jsonobject. getString("Image"));
                productArrayList.add(products);

            }

            if(helper.ProductImageRowCount()>0) {
                helper.ProductImagetruncate();
            }

            for(int i = 0; i< productArrayList.size(); i++) {

                helper.insertProductsimage(productArrayList.get(i));
            }
            //   SuitApps.showAToast("Products saved Successfully");
            helper.close();


        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return productArrayList;
    }
    @Override
    protected void onPostExecute(ArrayList<Products> products) {
        super.onPostExecute(products);
        //  progressDialog.dismiss();


    }

}

private void locService1() { getActivity().startService(new Intent(getActivity(), AutoSyncLocation.class)); }

}

error displaying highlated ines means @BindView(R.id.pendingtarget) TextView mytarget;