导航菜单

页面标题

页面副标题

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

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

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


package dev.gtr.pos.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.tbuonomo.viewpagerdotsindicator.DotsIndicator;
import dev.gtr.pos.BuildConfig;
import dev.gtr.pos.R;
import dev.gtr.pos.activity.MainActivity;
import dev.gtr.pos.adapter.AdapterTypeDropDown;
import dev.gtr.pos.adapter.AdapterViewpager;
import dev.gtr.pos.api.ApiClient;
import dev.gtr.pos.config.Constant;
import dev.gtr.pos.model.CategoryUnitList;
import dev.gtr.pos.model.LoginCredential;
import dev.gtr.pos.model.ModelErrorLogin;
import dev.gtr.pos.model.NotificationApps;
import dev.gtr.pos.posworker.NotificationWorker;
import es.dmoral.toasty.Toasty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import kotlinx.coroutines.DebugKt;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {
    AdapterTypeDropDown adapterTypeDropDown;
    AdapterViewpager adapterViewpager;
    AlertDialog.Builder alertBuilder;
    AlertDialog.Builder alertBuilderCompany;
    AlertDialog alertDialog;
    AlertDialog alertDialogCompany;
    CardView cardViewProgress;
    String comList;
    DotsIndicator dotsIndicator;
    SharedPreferences.Editor editor;
    String email;
    String firstTime;
    ImageView imageViewCompany;
    ImageView imageViewMore;
    ImageView imageViewRefresh;
    LocationManager lm;
    LocationListener locationListener;
    String pass;
    String selectedCompany;
    SharedPreferences sharedPreferences;
    TextView textViewNotificationCounter;
    TextView textViewVersion;
    ArrayList<CategoryUnitList> typeDropDown;
    ViewPager viewPagerMain;
    PeriodicWorkRequest workRequest;
    String version = BuildConfig.VERSION_NAME;
    ArrayList<CategoryUnitList> warehouse = new ArrayList<>();
    boolean justIn = true;
    boolean logout = false;
    double lat = 0.0d;
    double lang = 0.0d;

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_main);
        this.viewPagerMain = findViewById(R.id.viewPager_main);
        this.imageViewCompany = (ImageView) findViewById(R.id.img_company);
        this.dotsIndicator = (DotsIndicator) findViewById(R.id.dots_indicator);
        this.textViewVersion = (TextView) findViewById(R.id.textview_version);
        this.imageViewMore = (ImageView) findViewById(R.id.imageview_more);
        this.imageViewRefresh = (ImageView) findViewById(R.id.imageView_refresh);
        this.cardViewProgress = findViewById(R.id.cardView_progress);
        this.textViewNotificationCounter = (TextView) findViewById(R.id.textView_notification);
        this.alertBuilderCompany = new AlertDialog.Builder(this);
        this.lm = (LocationManager) getSystemService(FirebaseAnalytics.Param.LOCATION);
        requestNotificationPermission(this);
        int i = 0;
        AdapterViewpager adapterViewpager = new AdapterViewpager(getSupportFragmentManager(), 0, 1);
        this.adapterViewpager = adapterViewpager;
        this.viewPagerMain.setAdapter(adapterViewpager);
        this.textViewVersion.setText("Version: " + this.version);
        SharedPreferences sharedPreferences = getSharedPreferences("LOGIN", 0);
        this.sharedPreferences = sharedPreferences;
        this.editor = sharedPreferences.edit();
        this.firstTime = this.sharedPreferences.getString("FTIME", null);
        this.comList = this.sharedPreferences.getString("COMPLIST", null);
        this.email = this.sharedPreferences.getString("EMAIl", null);
        this.pass = this.sharedPreferences.getString("PASS", null);
        Constant.Token = this.sharedPreferences.getString("TOKEN", null);
        Constant.ComId = this.sharedPreferences.getString("COMID", null);
        Constant.uId = this.sharedPreferences.getString("UID", null);
        if (this.comList != null) {
            this.typeDropDown = (ArrayList) new Gson().fromJson(this.comList, new TypeToken<ArrayList<CategoryUnitList>>() {
            }.getType());
            while (true) {
                if (i >= this.typeDropDown.size()) {
                    break;
                }
                if (Constant.ComId.equals(this.typeDropDown.get(i).getValue())) {
                    this.typeDropDown.get(i).setSelectedForType(true);
                    break;
                }
                i++;
            }
        }
        this.imageViewMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PopupMenu popupMenu = new PopupMenu(MainActivity.this, view);
                popupMenu.getMenuInflater().inflate(R.menu.popup_menu, popupMenu.getMenu());
                popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        if (menuItem.getItemId() == 2131296754) {
                            MainActivity.this.logOut(MainActivity.this.lat, MainActivity.this.lang);
                        }
                        if (menuItem.getItemId() == 2131297029) {
                            MainActivity.this.startActivity(new Intent((Context) MainActivity.this, (Class<?>) TaskActivity.class));
                        }
                        if (menuItem.getItemId() != 2131296961) {
                            return true;
                        }
                        MainActivity.this.startActivity(new Intent((Context) MainActivity.this, (Class<?>) SettingsActivity.class));
                        return true;
                    }
                });
                popupMenu.show();
            }
        });
        this.locationListener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                MainActivity.this.lat = location.getLatitude();
                MainActivity.this.lang = location.getLongitude();
                if (MainActivity.this.lang != 0.0d && MainActivity.this.lat != 0.0d) {
                    boolean z = MainActivity.this.justIn;
                }
                if (MainActivity.this.lang == 0.0d || MainActivity.this.lat == 0.0d || !MainActivity.this.logout) {
                    return;
                }
                MainActivity mainActivity = MainActivity.this;
                mainActivity.logOut(mainActivity.lat, MainActivity.this.lang);
            }
        };
        this.imageViewRefresh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.this.getDashBoard();
            }
        });
        this.imageViewCompany.setOnClickListener(new AnonymousClass5());
        getLatLong();
        getNotification();
        getWareHouses();
        if (this.firstTime == null) {
            this.workRequest = new PeriodicWorkRequest.Builder(NotificationWorker.class, 15L, TimeUnit.MINUTES).addTag("POSWORKER").build();
            WorkManager.getInstance(this).enqueue(this.workRequest);
            this.editor.putString("FTIME", "1");
            this.editor.apply();
        }
        getAutoLogin(null, null);
    }

    class AnonymousClass5 implements View.OnClickListener {
        AnonymousClass5() {
        }

        @Override
        public void onClick(View view) {
            View inflate = MainActivity.this.getLayoutInflater().inflate(R.layout.alert_sl_list, (ViewGroup) null);
            RecyclerView findViewById = inflate.findViewById(R.id.recyclerview_sl);
            try {
                MainActivity.this.adapterTypeDropDown = new AdapterTypeDropDown(MainActivity.this.getApplicationContext(), MainActivity.this.typeDropDown);
                MainActivity.this.adapterTypeDropDown.setOnClickType(new AdapterTypeDropDown.OnClickType() {
                    @Override
                    public final void OnClick(CategoryUnitList categoryUnitList, int i) {
                        MainActivity.AnonymousClass5.this.m118lambda$onClick$1$devgtrposactivityMainActivity$5(categoryUnitList, i);
                    }
                });
                findViewById.setLayoutManager(new LinearLayoutManager(MainActivity.this.getApplicationContext()));
                findViewById.setAdapter(MainActivity.this.adapterTypeDropDown);
                findViewById.setHasFixedSize(true);
            } catch (Exception unused) {
            }
            MainActivity.this.alertBuilderCompany.setView(inflate);
            MainActivity mainActivity = MainActivity.this;
            mainActivity.alertDialogCompany = mainActivity.alertBuilderCompany.create();
            MainActivity.this.alertDialogCompany.getWindow().setBackgroundDrawableResource(R.drawable.shape_alert_back);
            MainActivity.this.alertDialogCompany.show();
        }

        void m118lambda$onClick$1$devgtrposactivityMainActivity$5(CategoryUnitList categoryUnitList, int i) {
            for (int i2 = 0; i2 < MainActivity.this.typeDropDown.size(); i2++) {
                if (i == i2) {
                    MainActivity.this.selectedCompany = categoryUnitList.getValue();
                    categoryUnitList.setSelectedForType(true);
                    MainActivity.this.alertDialogCompany.dismiss();
                } else {
                    MainActivity.this.typeDropDown.get(i2).setSelectedForType(false);
                }
            }
            Collections.sort(MainActivity.this.typeDropDown, new Comparator() {
                @Override
                public final int compare(Object obj, Object obj2) {
                    int compare;
                    compare = Boolean.compare(((CategoryUnitList) obj).getSelectedForType().booleanValue(), ((CategoryUnitList) obj2).getSelectedForType().booleanValue());
                    return compare;
                }
            });
            Collections.reverse(MainActivity.this.typeDropDown);
            MainActivity.this.adapterTypeDropDown.notifyDataSetChanged();
            if (MainActivity.this.selectedCompany.equals(Constant.ComId)) {
                return;
            }
            MainActivity mainActivity = MainActivity.this;
            mainActivity.login(mainActivity.email, MainActivity.this.pass, MainActivity.this.lang, MainActivity.this.lat, MainActivity.this.selectedCompany);
        }
    }

    public void login(final String str, final String str2, double d, final double d2, String str3) {
        this.cardViewProgress.setVisibility(0);
        ApiClient.getInstance(this).getApi().getCredential(str, str2, String.valueOf(d), String.valueOf(d2), str3).enqueue(new Callback<LoginCredential>() {
            @Override
            public void onResponse(Call<LoginCredential> call, Response<LoginCredential> response) {
                if (response.isSuccessful()) {
                    MainActivity.this.cardViewProgress.setVisibility(8);
                    MainActivity.this.editor.putString("TOKEN", response.body().getToken());
                    MainActivity.this.editor.putString("COMID", response.body().getComId());
                    MainActivity.this.editor.putString("UID", response.body().getUserId());
                    MainActivity.this.editor.putString("EMAIl", str);
                    MainActivity.this.editor.putString("USERNAME", response.body().getUserName());
                    MainActivity.this.editor.putString("COMPNAME", response.body().getCompName());
                    MainActivity.this.editor.putString("ROLENAME", response.body().getRoleName());
                    MainActivity.this.editor.putString("DefaultCurrency", response.body().getDefaultCurrencyId());
                    MainActivity.this.editor.putString("DECIMALPOINT", response.body().getDecimalField());
                    MainActivity.this.editor.putString("PASS", str2);
                    MainActivity.this.editor.putInt("ISLOGIN", 1);
                    MainActivity.this.editor.putInt("CHECK", 0);
                    MainActivity.this.editor.putString("COMPLIST", new Gson().toJson(response.body().getCompList()));
                    MainActivity.this.editor.putString("SALEBARCODE", response.body().getWeightScaleBarcodeStartWith());
                    MainActivity.this.editor.putString("warehouses", null);
                    MainActivity.this.editor.apply();
                    Constant.Token = MainActivity.this.sharedPreferences.getString("TOKEN", null);
                    Constant.ComId = MainActivity.this.sharedPreferences.getString("COMID", null);
                    Constant.uId = MainActivity.this.sharedPreferences.getString("UID", null);
                    Constant.DefaultCurrency = MainActivity.this.sharedPreferences.getString("DefaultCurrency", null);
                    MainActivity.this.adapterViewpager = new AdapterViewpager(MainActivity.this.getSupportFragmentManager(), 0, 1);
                    MainActivity.this.viewPagerMain.setAdapter(MainActivity.this.adapterViewpager);
                    MainActivity.this.adapterViewpager.notifyDataSetChanged();
                    MainActivity.this.getWareHouses();
                    return;
                }
                if (response.code() == 401) {
                    MainActivity.this.cardViewProgress.setVisibility(8);
                    try {
                        ModelErrorLogin modelErrorLogin = (ModelErrorLogin) new GsonBuilder().create().fromJson(response.errorBody().string(), ModelErrorLogin.class);
                        if (modelErrorLogin.getMessage() != null && !modelErrorLogin.getMessage().contains("Unauthorized")) {
                            Toasty.error((Context) MainActivity.this, (CharSequence) ("" + modelErrorLogin.getMessage()), 0).show();
                            MainActivity mainActivity = MainActivity.this;
                            mainActivity.logOut(d2, mainActivity.lang);
                        } else {
                            Toasty.error((Context) MainActivity.this, (CharSequence) "Your email or password may incorrect", 0).show();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onFailure(Call<LoginCredential> call, Throwable th) {
                MainActivity.this.cardViewProgress.setVisibility(8);
            }
        });
    }

    public void getWareHouses() {
        ApiClient.getInstance(this).getApi().getWareHouses("Bearer " + Constant.Token).enqueue(new Callback<List<CategoryUnitList>>() {
            @Override
            public void onFailure(Call<List<CategoryUnitList>> call, Throwable th) {
            }

            @Override
            public void onResponse(Call<List<CategoryUnitList>> call, Response<List<CategoryUnitList>> response) {
                if (response.isSuccessful()) {
                    for (CategoryUnitList categoryUnitList : response.body()) {
                        MainActivity.this.warehouse.add(new CategoryUnitList(categoryUnitList.getValue(), categoryUnitList.getText()));
                    }
                    MainActivity.this.editor.putString("warehouses", new Gson().toJson(response.body()));
                    MainActivity.this.editor.apply();
                }
            }
        });
    }

    public void requestNotificationPermission(final Context context) {
        if (Build.VERSION.SDK_INT >= 33) {
            if (ActivityCompat.checkSelfPermission(this, "android.permission.POST_NOTIFICATIONS") == 0) {
                Log.e("Notification Permission", "permission  granted");
                return;
            }
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, "android.permission.POST_NOTIFICATIONS")) {
                requestPermissions(new String[]{"android.permission.POST_NOTIFICATIONS"}, 1);
                return;
            }
            if (ActivityCompat.checkSelfPermission(this, "android.permission.POST_NOTIFICATIONS") == -1) {
                requestPermissions(new String[]{"android.permission.POST_NOTIFICATIONS"}, 1);
                return;
            }
            Log.e("Notification Permission", "Permission Denied");
            if (NotificationManagerCompat.from(context).areNotificationsEnabled()) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setTitle("Permission Required");
            builder.setMessage("Please enable notification permissions in settings to receive notifications.");
            builder.setPositiveButton("Go to Settings", new DialogInterface.OnClickListener() {
                @Override
                public final void onClick(DialogInterface dialogInterface, int i) {
                    MainActivity.lambda$requestNotificationPermission$0(context, dialogInterface, i);
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            });
            builder.show();
        }
    }

    static void lambda$requestNotificationPermission$0(Context context, DialogInterface dialogInterface, int i) {
        if (NotificationManagerCompat.from(context).areNotificationsEnabled()) {
            return;
        }
        Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setData(Uri.parse("package:" + context.getPackageName()));
        context.startActivity(intent);
    }

    private void getLatLong() {
        boolean isLocationEnabled;
        if (ActivityCompat.checkSelfPermission(this, "android.permission.ACCESS_FINE_LOCATION") != 0 && ActivityCompat.checkSelfPermission(this, "android.permission.ACCESS_COARSE_LOCATION") != 0) {
            ActivityCompat.requestPermissions(this, new String[]{"android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"}, 1);
            return;
        }
        if (Build.VERSION.SDK_INT >= 28) {
            isLocationEnabled = this.lm.isLocationEnabled();
            if (isLocationEnabled) {
                this.lm.requestLocationUpdates("network", 0L, 0.0f, this.locationListener);
            } else {
                Toasty.warning((Context) this, (CharSequence) "Please Turned On Location", 1).show();
            }
        }
    }

    private void getNotification() {
        SharedPreferences sharedPreferences = getSharedPreferences("LOGIN", 0);
        this.sharedPreferences = sharedPreferences;
        Constant.Token = sharedPreferences.getString("TOKEN", null);
        Constant.ComId = this.sharedPreferences.getString("COMID", null);
        Constant.uId = this.sharedPreferences.getString("UID", null);
        ApiClient.getInstance(this).getApi().getNotification("Bearer " + Constant.Token, Constant.uId).enqueue(new Callback<List<NotificationApps>>() {
            @Override
            public void onFailure(Call<List<NotificationApps>> call, Throwable th) {
            }

            @Override
            public void onResponse(Call<List<NotificationApps>> call, Response<List<NotificationApps>> response) {
                if (response.isSuccessful()) {
                    if (response.body().size() > 0) {
                        MainActivity.this.textViewNotificationCounter.setText("" + response.body().size());
                        return;
                    }
                    return;
                }
                MainActivity.this.editor.putString("TOKEN", "");
                MainActivity.this.editor.putString("COMID", "");
                MainActivity.this.editor.putString("UID", "");
                MainActivity.this.editor.putString("EMAIL", "");
                MainActivity.this.editor.putString("PASS", "");
                MainActivity.this.editor.putInt("ISLOGIN", 0);
                MainActivity.this.editor.putInt("CHECK", 0);
                MainActivity.this.editor.putString("SALEBARCODE", "");
                MainActivity.this.editor.putString("ROLENAME", "");
                MainActivity.this.editor.apply();
                MainActivity.this.finish();
                Toasty.success((Context) MainActivity.this, (CharSequence) "Logged Out Successfully", 0).show();
                MainActivity.this.startActivity(new Intent((Context) MainActivity.this, (Class<?>) LoginActivity.class));
            }
        });
    }

    public void logOut(double d, double d2) {
        ApiClient.getInstance(this).getApi().logout("Bearer " + Constant.Token, String.valueOf(d2), String.valueOf(d)).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().toString().equals("true")) {
                        MainActivity.this.editor.putString("TOKEN", "");
                        MainActivity.this.editor.putString("COMID", "");
                        MainActivity.this.editor.putString("UID", "");
                        MainActivity.this.editor.putString("EMAIL", "");
                        MainActivity.this.editor.putString("PASS", "");
                        MainActivity.this.editor.putInt("ISLOGIN", 0);
                        MainActivity.this.editor.putInt("CHECK", 0);
                        MainActivity.this.editor.putString("SALEBARCODE", "");
                        MainActivity.this.editor.putString("ROLENAME", "");
                        MainActivity.this.editor.apply();
                        MainActivity.this.finish();
                        MainActivity.this.logout = false;
                        Toasty.success((Context) MainActivity.this, (CharSequence) "Logged Out Successfully", 0).show();
                        MainActivity.this.startActivity(new Intent((Context) MainActivity.this, (Class<?>) LoginActivity.class));
                        return;
                    }
                    return;
                }
                Log.e("logout", "" + response.code());
            }
        });
    }

    private void getAutoLogin(String str, String str2) {
        ApiClient.getInstance(this).getApi().autoLogin("Bearer " + Constant.Token, String.valueOf(str2), String.valueOf(str)).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()) {
                    Log.e(DebugKt.DEBUG_PROPERTY_VALUE_AUTO, response.body().toString());
                    MainActivity.this.justIn = false;
                } else if (response.code() == 401) {
                    MainActivity.this.startActivity(new Intent((Context) MainActivity.this, (Class<?>) LoginActivity.class));
                    MainActivity.this.finish();
                }
            }
        });
    }

    public void onBackPressed() {
        this.alertBuilder = new AlertDialog.Builder(this);
        View inflate = getLayoutInflater().inflate(R.layout.layout_custom_delete_alert, (ViewGroup) null);
        TextView textView = (TextView) inflate.findViewById(R.id.cancel);
        TextView textView2 = (TextView) inflate.findViewById(R.id.submit);
        ((TextView) inflate.findViewById(R.id.textView_sure)).setText("Are you want to exit ?");
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.this.alertDialog.dismiss();
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MainActivity.this.alertDialog.dismiss();
                MainActivity.super.onBackPressed();
            }
        });
        this.alertBuilder.setView(inflate);
        AlertDialog create = this.alertBuilder.create();
        this.alertDialog = create;
        create.setCanceledOnTouchOutside(false);
        this.alertDialog.show();
    }

    protected void onStart() {
        super.onStart();
    }

    public void getAddress(double d, double d2) {
        Log.e("In", "lat " + d + "lng " + d2);
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        try {
            Log.e("In", "lat " + d + "lng " + d2);
            geocoder.getFromLocation(d, d2, 1).get(0).getAddressLine(0);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void getDashBoard() {
        ApiClient.getInstance(this).getApi().getDashBoard("Bearer " + Constant.Token).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable th) {
            }

            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                if (response.isSuccessful()) {
                    Toasty.success(MainActivity.this.getApplicationContext(), "Reloaded", 0).show();
                }
            }
        });
    }

    protected void onResume() {
        super.onResume();
        getAutoLogin(null, null);
        getNotification();
    }

    protected void onStop() {
        super.onStop();
    }
}