导航菜单

页面标题

页面副标题

EFFICIENT POS v1.5.7 - EmployeeActivity.java 源代码

正在查看: EFFICIENT POS v1.5.7 应用的 EmployeeActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package dev.gtr.pos.activity;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
import dev.gtr.pos.R;
import dev.gtr.pos.adapter.AdapterEmployye;
import dev.gtr.pos.api.ApiClient;
import dev.gtr.pos.config.Constant;
import dev.gtr.pos.config.LinearLayoutWrapper;
import dev.gtr.pos.model.CustomerType;
import dev.gtr.pos.model.Employee;
import es.dmoral.toasty.Toasty;
import java.net.SocketTimeoutException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EmployeeActivity extends AppCompatActivity implements View.OnClickListener {
    AdapterEmployye adapterCustomer;
    AlertDialog alertDialogAdd;
    AlertDialog alertDialogDel;
    AlertDialog.Builder builderAdd;
    AlertDialog.Builder builderDel;
    Calendar calendar;
    CardView cardViewFrom;
    CardView cardViewTo;
    ConstraintLayout constraintLayoutAdd;
    ConstraintLayout constraintLayoutDate;
    ConstraintLayout constraintLayoutDel;
    ConstraintLayout constraintLayoutEdit;
    ConstraintLayout constraintLayoutSearch;
    ConstraintLayout constraintLayoutView;
    List<String> cookies;
    int currentItem;
    ArrayList<CustomerType> custGroup;
    ArrayList<CustomerType> custType;
    String customerId;
    String customerName;
    SimpleDateFormat dateFormat;
    EditText editTextSearch;
    int flag;
    String fromSupp;
    ImageView imageViewAdd;
    ImageView imageViewBack;
    ImageView imageViewDel;
    ImageView imageViewEdit;
    ImageView imageViewSearch;
    ImageView imageViewView;
    ArrayList<Employee.AccountList> items;
    LinearLayoutWrapper linearLayoutManager;
    DatePickerDialog.OnDateSetListener onDateSetListenerFrom;
    DatePickerDialog.OnDateSetListener onDateSetListenerTo;
    ProgressBar progressBar;
    RecyclerView recyclerView;
    String selectedCustText;
    String selectedGroupText;
    String selectedValueCust;
    String selectedValueGroup;
    TextView textViewFromDate;
    TextView textViewTitle;
    TextView textViewToDate;
    int total_Item;
    int selectedPosition = -1;
    boolean isCustomerCalling = true;
    boolean isFirstTime = true;
    int pageSize = 10;
    int pages = 1;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_employee2);
        this.recyclerView = findViewById(R.id.recyclerview_customer);
        this.imageViewBack = (ImageView) findViewById(R.id.imageView_back);
        this.imageViewAdd = (ImageView) findViewById(R.id.imageview_add);
        this.imageViewDel = (ImageView) findViewById(R.id.imageview_paylist);
        this.imageViewEdit = (ImageView) findViewById(R.id.imageview_rec);
        this.constraintLayoutAdd = findViewById(2131296331);
        this.constraintLayoutEdit = findViewById(R.id.rec_pay);
        this.constraintLayoutDel = findViewById(R.id.pay);
        this.imageViewView = (ImageView) findViewById(R.id.imageView_view);
        this.constraintLayoutView = findViewById(R.id.view);
        this.textViewTitle = (TextView) findViewById(R.id.textView_title);
        this.editTextSearch = (EditText) findViewById(R.id.editText_search);
        this.imageViewSearch = (ImageView) findViewById(R.id.imageview_search);
        this.textViewToDate = (TextView) findViewById(R.id.textView_toDate);
        this.textViewFromDate = (TextView) findViewById(R.id.textView_fromDate);
        this.constraintLayoutSearch = findViewById(R.id.search);
        this.progressBar = (ProgressBar) findViewById(R.id.progress_cust);
        this.cardViewTo = findViewById(R.id.cardView_toDate);
        this.cardViewFrom = findViewById(R.id.cardView_fromDate);
        this.constraintLayoutDate = findViewById(R.id.constraintLayout23);
        this.imageViewBack.setOnClickListener(this);
        init();
        getAllCustomer(".", 0);
        getCustType();
        getCustGroup();
    }

    public void init() {
        Intent intent = getIntent();
        this.flag = intent.getIntExtra(Constant.REQ_PURCHASE_SALES_TO_CustomerDetails, 0);
        this.fromSupp = intent.getStringExtra("FROMSUPP");
        this.textViewTitle.setText(getString(R.string.customer));
        this.items = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        this.calendar = calendar;
        int i = calendar.get(1);
        int i2 = this.calendar.get(2);
        int i3 = this.calendar.get(5);
        this.dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
        this.calendar.set(i, i2, i3);
        this.textViewToDate.setText(this.dateFormat.format(this.calendar.getTime()));
        this.textViewFromDate.setText(this.dateFormat.format(this.calendar.getTime()));
        this.onDateSetListenerTo = new DatePickerDialog.OnDateSetListener() {
            @Override
            public final void onDateSet(DatePicker datePicker, int i4, int i5, int i6) {
                EmployeeActivity.this.m93lambda$init$0$devgtrposactivityEmployeeActivity(datePicker, i4, i5, i6);
            }
        };
        this.onDateSetListenerFrom = new DatePickerDialog.OnDateSetListener() {
            @Override
            public final void onDateSet(DatePicker datePicker, int i4, int i5, int i6) {
                EmployeeActivity.this.m94lambda$init$1$devgtrposactivityEmployeeActivity(datePicker, i4, i5, i6);
            }
        };
        this.linearLayoutManager = new LinearLayoutWrapper(getApplicationContext());
        AdapterEmployye adapterEmployye = new AdapterEmployye(this.items, this);
        this.adapterCustomer = adapterEmployye;
        adapterEmployye.setOnItemClick(new AdapterEmployye.OnItemClick() {
            @Override
            public void OnLongClick(Employee.AccountList accountList, int i4, View view) {
            }

            @Override
            public void onClick(Employee.AccountList accountList, int i4) {
            }

            @Override
            public void onViewClick(Employee.AccountList accountList, int i4, View view) {
            }
        });
        this.recyclerView.setLayoutManager(this.linearLayoutManager);
        this.recyclerView.setAdapter(this.adapterCustomer);
        this.recyclerView.setHasFixedSize(true);
        this.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            public void onScrolled(RecyclerView recyclerView, int i4, int i5) {
                super.onScrolled(recyclerView, i4, i5);
                EmployeeActivity employeeActivity = EmployeeActivity.this;
                employeeActivity.currentItem = employeeActivity.linearLayoutManager.getChildCount();
                EmployeeActivity employeeActivity2 = EmployeeActivity.this;
                employeeActivity2.total_Item = employeeActivity2.linearLayoutManager.getItemCount();
                int findFirstVisibleItemPosition = EmployeeActivity.this.linearLayoutManager.findFirstVisibleItemPosition();
                if (EmployeeActivity.this.currentItem + findFirstVisibleItemPosition + 1 > EmployeeActivity.this.total_Item && i5 > 0 && EmployeeActivity.this.editTextSearch.getText().toString().isEmpty() && !EmployeeActivity.this.isCustomerCalling) {
                    EmployeeActivity.this.isCustomerCalling = true;
                    EmployeeActivity.this.adapterCustomer.setLoading(true);
                    EmployeeActivity.this.adapterCustomer.notifyItemInserted(EmployeeActivity.this.items.size());
                    EmployeeActivity employeeActivity3 = EmployeeActivity.this;
                    employeeActivity3.getAllCustomer(".", employeeActivity3.total_Item);
                    return;
                }
                if (EmployeeActivity.this.currentItem + findFirstVisibleItemPosition + 1 <= EmployeeActivity.this.total_Item || i5 <= 0 || EmployeeActivity.this.editTextSearch.getText().toString().isEmpty() || EmployeeActivity.this.isCustomerCalling) {
                    return;
                }
                EmployeeActivity.this.isCustomerCalling = true;
                EmployeeActivity.this.adapterCustomer.setLoading(true);
                EmployeeActivity.this.adapterCustomer.notifyItemInserted(EmployeeActivity.this.items.size());
                EmployeeActivity employeeActivity4 = EmployeeActivity.this;
                employeeActivity4.getAllCustomer(employeeActivity4.editTextSearch.getText().toString(), EmployeeActivity.this.total_Item);
            }
        });
    }

    void m93lambda$init$0$devgtrposactivityEmployeeActivity(DatePicker datePicker, int i, int i2, int i3) {
        this.dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
        Calendar calendar = Calendar.getInstance();
        calendar.set(i, i2, i3);
        this.textViewToDate.setText(this.dateFormat.format(calendar.getTime()));
    }

    void m94lambda$init$1$devgtrposactivityEmployeeActivity(DatePicker datePicker, int i, int i2, int i3) {
        this.dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
        Calendar calendar = Calendar.getInstance();
        calendar.set(i, i2, i3);
        this.textViewFromDate.setText(this.dateFormat.format(calendar.getTime()));
    }

    public void ShowDate(DatePickerDialog.OnDateSetListener onDateSetListener) {
        Calendar calendar = Calendar.getInstance();
        DatePickerDialog datePickerDialog = new DatePickerDialog(this, R.style.customsDate, onDateSetListener, calendar.get(1), calendar.get(2), calendar.get(5));
        datePickerDialog.show();
        datePickerDialog.getButton(-2).setTextColor(getResources().getColor(R.color.black_mart));
        datePickerDialog.getButton(-1).setTextColor(getResources().getColor(R.color.black_mart));
    }

    private void DeleteCustomer(String str, final int i) {
        ApiClient.getInstance(getApplicationContext()).getApi().deleteCustomer("Bearer " + Constant.Token, str).enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful()) {
                    if (response.body().equals("true")) {
                        EmployeeActivity.this.progressBar.setVisibility(8);
                        EmployeeActivity.this.items.remove(i);
                        EmployeeActivity.this.adapterCustomer.notifyItemRemoved(i);
                        EmployeeActivity.this.adapterCustomer.notifyItemRangeChanged(i, EmployeeActivity.this.items.size() - 1);
                        if (EmployeeActivity.this.items.size() > 0) {
                            EmployeeActivity.this.textViewTitle.setText("Customer( " + EmployeeActivity.this.items.size() + " )");
                        }
                        Toasty.success(EmployeeActivity.this.getApplicationContext(), "Deleted Successfully", 0).show();
                        return;
                    }
                    return;
                }
                EmployeeActivity.this.progressBar.setVisibility(8);
                Toasty.error(EmployeeActivity.this.getApplicationContext(), "Can't delete", 0).show();
            }

            @Override
            public void onFailure(Call<String> call, Throwable th) {
                EmployeeActivity.this.progressBar.setVisibility(8);
            }
        });
    }

    public void getAllCustomer(String str, final int i) {
        ApiClient.getInstance(this).getApi().getEmployeeList("Bearer " + Constant.Token, this.pages, this.pageSize, str).enqueue(new Callback<Employee>() {
            @Override
            public void onResponse(Call<Employee> call, Response<Employee> response) {
                if (response.isSuccessful()) {
                    EmployeeActivity.this.isCustomerCalling = false;
                    EmployeeActivity.this.progressBar.setVisibility(8);
                    if (EmployeeActivity.this.items.size() > 0) {
                        EmployeeActivity.this.adapterCustomer.setLoading(false);
                        EmployeeActivity.this.adapterCustomer.notifyItemRemoved(EmployeeActivity.this.items.size() - 1);
                    }
                    if (EmployeeActivity.this.pages <= Integer.parseInt(response.body().getPageInfo().getPageCount())) {
                        EmployeeActivity.this.cookies = response.headers().values("set-Cookie");
                        EmployeeActivity.this.items.addAll(response.body().getAccountList());
                        EmployeeActivity.this.adapterCustomer.notifyItemRangeInserted(i, EmployeeActivity.this.items.size());
                        EmployeeActivity.this.pages++;
                    }
                    if (EmployeeActivity.this.items.size() > 0) {
                        EmployeeActivity.this.adapterCustomer.notifyDataSetChanged();
                        EmployeeActivity.this.textViewTitle.setText("Employee( " + EmployeeActivity.this.items.size() + " )");
                    }
                }
                if (response.code() == 500) {
                    EmployeeActivity.this.progressBar.setVisibility(8);
                    if (EmployeeActivity.this.items.size() > 0) {
                        EmployeeActivity.this.adapterCustomer.setLoading(false);
                        EmployeeActivity.this.adapterCustomer.notifyItemRemoved(EmployeeActivity.this.items.size() - 1);
                    }
                    Toasty.error(EmployeeActivity.this.getApplicationContext(), "Internal Server Error", 0).show();
                } else {
                    Log.e("cust", "" + response.code());
                }
                EmployeeActivity.this.isFirstTime = false;
            }

            @Override
            public void onFailure(Call<Employee> call, Throwable th) {
                EmployeeActivity.this.progressBar.setVisibility(8);
                if (EmployeeActivity.this.items.size() > 0) {
                    EmployeeActivity.this.adapterCustomer.setLoading(false);
                    EmployeeActivity.this.adapterCustomer.notifyItemRemoved(EmployeeActivity.this.items.size() - 1);
                }
                EmployeeActivity.this.isFirstTime = false;
                if (th instanceof SocketTimeoutException) {
                    Toast.makeText((Context) EmployeeActivity.this, (CharSequence) "Please Connect through Internet", 0).show();
                }
            }
        });
    }

    private void updateCustomer(int i, String str, String str2, String str3, String str4, String str5, String str6, String str7, String str8, String str9, String str10, String str11) {
        ApiClient.getInstance(getApplicationContext()).getApi().updateCustomer("Bearer " + Constant.Token, str3, str4, str5, str6, str7, str8, str9, str10, str11).enqueue(new Callback<String>() {
            @Override
            public void onFailure(Call<String> call, Throwable th) {
            }

            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                response.isSuccessful();
            }
        });
    }

    private void AddCustomer(String str, String str2, String str3, String str4, String str5, String str6, String str7, String str8) {
        ApiClient.getInstance(getApplicationContext()).getApi().createCustomer("Bearer " + Constant.Token, str, str2, str3, str4, str5, str6, str7, str8).enqueue(new Callback<String>() {
            @Override
            public void onFailure(Call<String> call, Throwable th) {
            }

            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if (response.isSuccessful()) {
                    if (response.body().contains("true")) {
                        EmployeeActivity.this.progressBar.setVisibility(8);
                        Toasty.success(EmployeeActivity.this.getApplicationContext(), "Added Successfully", 0).show();
                        EmployeeActivity.this.items.clear();
                        EmployeeActivity.this.adapterCustomer.notifyDataSetChanged();
                        EmployeeActivity.this.pages = 1;
                        EmployeeActivity.this.progressBar.setVisibility(0);
                        EmployeeActivity.this.getAllCustomer(".", 0);
                        return;
                    }
                    EmployeeActivity.this.progressBar.setVisibility(8);
                    Toasty.error(EmployeeActivity.this.getApplicationContext(), "Can't Add", 0).show();
                }
            }
        });
    }

    private void getCustType() {
        ApiClient.getInstance(getApplicationContext()).getApi().getCustTypeDropDown("Bearer " + Constant.Token).enqueue(new Callback<List<CustomerType>>() {
            @Override
            public void onFailure(Call<List<CustomerType>> call, Throwable th) {
            }

            @Override
            public void onResponse(Call<List<CustomerType>> call, Response<List<CustomerType>> response) {
                if (response.isSuccessful()) {
                    EmployeeActivity.this.custType = new ArrayList<>();
                    for (CustomerType customerType : response.body()) {
                        Log.e("value", "" + customerType.getValue());
                        EmployeeActivity.this.custType.add(new CustomerType(customerType.getDisable(), customerType.getGroup(), customerType.getSelect(), customerType.getText(), customerType.getValue()));
                    }
                }
            }
        });
    }

    private void getCustGroup() {
        ApiClient.getInstance(getApplicationContext()).getApi().groupDropDown("Bearer " + Constant.Token).enqueue(new Callback<List<CustomerType>>() {
            @Override
            public void onFailure(Call<List<CustomerType>> call, Throwable th) {
            }

            @Override
            public void onResponse(Call<List<CustomerType>> call, Response<List<CustomerType>> response) {
                if (response.isSuccessful()) {
                    EmployeeActivity.this.custGroup = new ArrayList<>();
                    EmployeeActivity.this.custGroup.add(new CustomerType("-1", "-1", "-1", "Select--", "-1"));
                    for (CustomerType customerType : response.body()) {
                        Log.e("val", "" + customerType.getValue());
                        EmployeeActivity.this.custGroup.add(new CustomerType(customerType.getDisable(), customerType.getGroup(), customerType.getSelect(), customerType.getText(), customerType.getValue()));
                    }
                }
            }
        });
    }

    @Override
    public void onClick(View view) {
        if (view == this.imageViewBack) {
            finish();
        }
    }

    public void onBackPressed() {
        super.onBackPressed();
    }

    protected void onResume() {
        if (!this.isFirstTime) {
            this.pages = 1;
            this.items.clear();
            this.adapterCustomer.notifyDataSetChanged();
            this.progressBar.setVisibility(0);
            getAllCustomer(".", 0);
        }
        super.onResume();
    }
}