导航菜单

页面标题

页面副标题

AdaModal v1.4.0 - RegionSelectActivity.java 源代码

正在查看: AdaModal v1.4.0 应用的 RegionSelectActivity.java JAVA 源代码文件

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


package com.common.fine.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.common.fine.R;
import com.common.fine.adapter.OnRecyclerItemClickListener;
import com.common.fine.adapter.RegionItemAdapter;
import com.common.fine.database.RegionDbOpenHelper;
import com.common.fine.databinding.ActivityRegionSelectBinding;
import com.common.fine.model.RegionItem;
import com.common.fine.utils.StoreUtil;
import com.common.fine.widget.LoadingUtils;
import java.io.File;
import java.io.IOException;
import java.util.List;

public class RegionSelectActivity extends AppCompatActivity implements OnRecyclerItemClickListener {
    public static final String REGION_SELECT_CITY = "REGION_SELECT_CITY";
    public static final String REGION_SELECT_DISTRICT = "REGION_SELECT_DISTRICT";
    public static final String REGION_SELECT_PROVINCE = "REGION_SELECT_PROVINCE";
    public static final String REGION_SELECT_STRING = "REGION_SELECT_STRING";
    public static final String REGION_SELECT_VILLAGE = "REGION_SELECT_VILLAGE";
    private ActivityRegionSelectBinding binding;
    RegionDbOpenHelper mDbOpenHelper;
    private List<RegionItem> mDistrictList;
    private List<RegionItem> mProvinceList;
    private List<RegionItem> mRegenCiesList;
    RegionItemAdapter mRegionItemAdapter;
    private int mSelectStep = 0;
    private RegionItem mSelectedCity;
    private RegionItem mSelectedDistrict;
    private RegionItem mSelectedProvince;
    private RegionItem mSelectedVillage;
    private List<RegionItem> mVillageList;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.binding = (ActivityRegionSelectBinding) DataBindingUtil.setContentView(this, R.layout.activity_region_select);
        new Thread() {
            @Override
            public void run() {
                RegionSelectActivity.this.prepareDatabaseAsync();
            }
        }.start();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setTitle(getString(R.string.please_select_province));
        this.binding.regionItemList.setItemAnimator(new DefaultItemAnimator());
        this.binding.regionItemList.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    public void onItemClick(View view, int i) {
        int i2 = this.mSelectStep;
        if (i2 == 0) {
            if (this.mProvinceList.size() <= i) {
                return;
            }
            setTitle(getString(R.string.please_select_city));
            RegionItem regionItem = this.mProvinceList.get(i);
            this.mSelectedProvince = regionItem;
            List<RegionItem> subItemList = this.mDbOpenHelper.getSubItemList(RegionDbOpenHelper.TABLE_NAME_REGENCIES, regionItem.getId());
            this.mRegenCiesList = subItemList;
            this.mRegionItemAdapter.setRegionItemList(subItemList);
            this.binding.regionItemList.smoothScrollToPosition(0);
            this.mSelectStep++;
            return;
        }
        if (i2 == 1) {
            if (this.mRegenCiesList.size() <= i) {
                return;
            }
            setTitle(getString(R.string.please_select_zone));
            RegionItem regionItem2 = this.mRegenCiesList.get(i);
            this.mSelectedCity = regionItem2;
            List<RegionItem> subItemList2 = this.mDbOpenHelper.getSubItemList(RegionDbOpenHelper.TABLE_NAME_DISTRICTS, regionItem2.getId());
            this.mDistrictList = subItemList2;
            this.mRegionItemAdapter.setRegionItemList(subItemList2);
            this.binding.regionItemList.smoothScrollToPosition(0);
            this.mSelectStep++;
            return;
        }
        if (i2 == 2) {
            if (this.mDistrictList.size() <= i) {
                return;
            }
            setTitle(getString(R.string.please_select_village));
            RegionItem regionItem3 = this.mDistrictList.get(i);
            this.mSelectedDistrict = regionItem3;
            List<RegionItem> subItemList3 = this.mDbOpenHelper.getSubItemList(RegionDbOpenHelper.TABLE_NAME_VILLAGES, regionItem3.getId());
            this.mVillageList = subItemList3;
            this.mRegionItemAdapter.setRegionItemList(subItemList3);
            this.binding.regionItemList.smoothScrollToPosition(0);
            this.mSelectStep++;
            return;
        }
        if (i2 == 3 && this.mVillageList.size() > i) {
            this.mSelectedVillage = this.mVillageList.get(i);
            onSelectFinished();
        }
    }

    private void onSelectFinished() {
        String str = this.mSelectedProvince.getName() + " " + this.mSelectedCity.getName() + " " + this.mSelectedDistrict.getName() + " " + this.mSelectedVillage.getName();
        Intent intent = getIntent();
        intent.putExtra(REGION_SELECT_STRING, str);
        intent.putExtra(REGION_SELECT_PROVINCE, this.mSelectedProvince);
        intent.putExtra(REGION_SELECT_CITY, this.mSelectedCity);
        intent.putExtra(REGION_SELECT_DISTRICT, this.mSelectedDistrict);
        intent.putExtra(REGION_SELECT_VILLAGE, this.mSelectedVillage);
        setResult(-1, intent);
        finish();
    }

    @Override
    public void onBackPressed() {
        int i = this.mSelectStep;
        if (i == 0) {
            super.onBackPressed();
            return;
        }
        if (i == 1) {
            setTitle(R.string.please_select_province);
            this.mRegionItemAdapter.setRegionItemList(this.mProvinceList);
            this.mSelectStep--;
        } else if (i == 2) {
            setTitle(R.string.please_select_city);
            this.mRegionItemAdapter.setRegionItemList(this.mRegenCiesList);
            this.mSelectStep--;
        } else {
            if (i != 3) {
                return;
            }
            setTitle(R.string.please_select_zone);
            this.mRegionItemAdapter.setRegionItemList(this.mDistrictList);
            this.mSelectStep--;
        }
    }

    public void prepareDatabaseAsync() {
        LoadingUtils.dismiss();
        File databasePath = getDatabasePath(RegionDbOpenHelper.REGION_DB_NAME);
        if (!databasePath.exists()) {
            try {
                StoreUtil.copyAssets(this, RegionDbOpenHelper.REGION_DB_NAME, databasePath.getPath());
            } catch (IOException unused) {
            }
        }
        this.mDbOpenHelper = new RegionDbOpenHelper(this, RegionDbOpenHelper.REGION_DB_NAME);
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                LoadingUtils.dismiss();
                RegionSelectActivity.this.setupSelectUi();
            }
        });
    }

    public void setupSelectUi() {
        List<RegionItem> provinceList = this.mDbOpenHelper.getProvinceList();
        this.mProvinceList = provinceList;
        if (provinceList != null) {
            this.mRegionItemAdapter = new RegionItemAdapter(this, this.mProvinceList);
            this.binding.regionItemList.setAdapter(this.mRegionItemAdapter);
            this.mRegionItemAdapter.setOnItemClickListener(this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RegionDbOpenHelper regionDbOpenHelper = this.mDbOpenHelper;
        if (regionDbOpenHelper != null) {
            regionDbOpenHelper.close();
        }
    }
}