New file |
| | |
| | | package com.application.zhangshi_app_android.ui; |
| | | |
| | | import android.graphics.Color; |
| | | import android.view.ViewGroup; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | import androidx.databinding.DataBindingUtil; |
| | | import androidx.databinding.ViewDataBinding; |
| | | import androidx.drawerlayout.widget.DrawerLayout; |
| | | |
| | | import com.android.app_base.base.view.BaseActivity; |
| | | import com.android.app_base.base.viewmodel.BaseViewModel; |
| | | import com.android.app_base.manager.AppManager; |
| | | import com.application.zhangshi_app_android.R; |
| | | import com.application.zhangshi_app_android.ui.function.FamilyAssetsActivity; |
| | | import com.application.zhangshi_app_android.ui.function.FamilyMemorabiliaActivity; |
| | | import com.application.zhangshi_app_android.ui.function.GrowthExperienceActivity; |
| | | import com.application.zhangshi_app_android.ui.function.HomeDevicesActivity; |
| | | import com.hjq.bar.TitleBar; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author Ljj |
| | | * @date 2023.04.01. 18:21 |
| | | * @desc 该APP里统一侧拉栏的Activity基类 |
| | | */ |
| | | public abstract class DLBaseActivity<VDB extends ViewDataBinding,VM extends BaseViewModel> extends BaseActivity<VDB,VM> { |
| | | /** |
| | | * 侧拉栏 |
| | | */ |
| | | private DrawerLayout mDrawerLayout; |
| | | private Map<Class,LinearLayout> classMap = new HashMap<>(); |
| | | @Override |
| | | protected VDB initViewBinding() { |
| | | if (isDrawerLayoutEnabled()){ |
| | | mDrawerLayout = new DrawerLayout(this); |
| | | mDrawerLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); |
| | | VDB mBinding = DataBindingUtil.inflate(getLayoutInflater(), getLayoutId(), mDrawerLayout, true); |
| | | if (getDrawerLayoutId() > 0){ |
| | | getLayoutInflater().inflate(getDrawerLayoutId(), mDrawerLayout, true); |
| | | }else { |
| | | throw new IllegalArgumentException("没给侧拉栏布局就不要开启侧拉栏啦"); |
| | | } |
| | | setContentView(mDrawerLayout); |
| | | return mBinding; |
| | | } |
| | | return super.initViewBinding(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 是否开启侧拉栏 |
| | | */ |
| | | protected boolean isDrawerLayoutEnabled() { |
| | | return true; |
| | | } |
| | | /** |
| | | * 获取侧拉栏的id |
| | | * @return layout的id |
| | | */ |
| | | protected int getDrawerLayoutId(){ |
| | | return R.layout.layout_drawer; |
| | | }; |
| | | |
| | | @Override |
| | | protected void onResume() { |
| | | super.onResume(); |
| | | |
| | | if (mDrawerLayout != null) { |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_home_root_net)); |
| | | classMap.put(FamilyMemorabiliaActivity.class,(LinearLayout) findViewById(R.id.dl_family_memorabilia)); |
| | | classMap.put(FamilyAssetsActivity.class,(LinearLayout) findViewById(R.id.dl_family_assets)); |
| | | classMap.put(HomeDevicesActivity.class,(LinearLayout) findViewById(R.id.dl_home_devices)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_honor_collection)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_little_doctor)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_clean_storage)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_contacts)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_pet)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_income_and_expenses)); |
| | | classMap.put(GrowthExperienceActivity.class,(LinearLayout) findViewById(R.id.dl_growing_up)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_marriage)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_property)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_hundred_wish)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_health_care)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_certificate_of_honor)); |
| | | classMap.put(null,(LinearLayout) findViewById(R.id.dl_privacy)); |
| | | setSelectItem(classMap.get(getClass())); |
| | | for (Map.Entry<Class, LinearLayout> set : classMap.entrySet()) { |
| | | set.getValue().setOnClickListener(v -> { |
| | | if (set.getKey() != null){ |
| | | AppManager.getAppManager().startActivity(set.getKey()); |
| | | } |
| | | }); |
| | | } |
| | | mDrawerLayout.setScrimColor(getResources().getColor(R.color.color_shadow)); |
| | | } |
| | | } |
| | | private void setSelectItem(LinearLayout linearLayout) { |
| | | if (linearLayout == null){ |
| | | return; |
| | | } |
| | | TextView textView = (TextView) linearLayout.getChildAt(1); |
| | | ImageView imageView = (ImageView) linearLayout.getChildAt(2); |
| | | textView.setTextColor(Color.parseColor("#FFF6739F")); |
| | | imageView.setBackgroundResource(R.drawable.ic_vector_pink); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取DrawerLayout |
| | | */ |
| | | @Nullable |
| | | public DrawerLayout getDrawerLayout() { |
| | | return mDrawerLayout; |
| | | } |
| | | |
| | | @Override |
| | | public void onLeftClick(TitleBar titleBar) { |
| | | super.onRightClick(titleBar); |
| | | mDrawerLayout.open(); |
| | | } |
| | | } |