Commit 140778ec by amateur

1

1 parent c33fea97
package com.whaty.nafmii.activity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioButton;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.polysoft.nafmii.enums.ModulesEnum;
import com.polysoft.nafmii.fragment.TestFragment;
import com.whaty.nafmii.R;
import com.polysoft.nafmii.fragment.home.ModulesFragmentMgr;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class TestHomeActivity extends WebviewActivity implements View.OnClickListener, ModulesFragmentMgr.OnChangeModuleListener {
private ModulesFragmentMgr modulesMgr;
private HashMap<ModulesEnum, RadioButton> moduleViewsMap;
private HashMap<ModulesEnum, Fragment> mFragmentMap = new HashMap<>();
private View footerView;
private ModulesEnum currentModule;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.activity_home);
this.initView();
this.initHomeModule();
}
@Override
public void onCoreInitFinished(boolean flag) {
}
private void initView() {
this.footerView = super.findViewById(R.id.home_footer_group);
this.footerView.setVisibility(View.VISIBLE);
HashMap<ModulesEnum, RadioButton> modulesMap = new HashMap<>();
modulesMap.put(ModulesEnum.HOME, super.findViewById(R.id.home_btn_home));
modulesMap.put(ModulesEnum.MEMBER, super.findViewById(R.id.home_btn_member));
modulesMap.put(ModulesEnum.LEARN, super.findViewById(R.id.home_btn_learn));
modulesMap.put(ModulesEnum.MY, super.findViewById(R.id.home_btn_my));
for (Map.Entry<ModulesEnum, RadioButton> modulesEnumRadioButtonEntry : modulesMap.entrySet()) {
modulesEnumRadioButtonEntry.getValue().setOnClickListener(this);
}
this.moduleViewsMap = modulesMap;
}
private void initHomeModule() {
int containerId = R.id.home_container_framelayout;
this.mFragmentMap.put(ModulesEnum.HOME, TestFragment.newInstance("首页"));
this.mFragmentMap.put(ModulesEnum.MEMBER, TestFragment.newInstance("会员"));
this.mFragmentMap.put(ModulesEnum.LEARN, TestFragment.newInstance("学习"));
this.mFragmentMap.put(ModulesEnum.MY, TestFragment.newInstance("我的"));
FragmentManager manager = getSupportFragmentManager();
Iterator<ModulesEnum> iterator = this.mFragmentMap.keySet().iterator();
while(iterator.hasNext()) {
ModulesEnum key = iterator.next();
Fragment fragment = this.mFragmentMap.get(key);
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(containerId, fragment, key.name).hide(fragment).commitNow();
}
FragmentTransaction transaction = manager.beginTransaction();
Fragment fragment = this.mFragmentMap.get(ModulesEnum.HOME);
transaction.show(fragment).commitNow();
this.currentModule = ModulesEnum.HOME;
}
@SuppressLint("NonConstantResourceId")
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.home_btn_home:
this.changeModule(ModulesEnum.HOME, null);
break;
case R.id.home_btn_member:
this.changeModule(ModulesEnum.MEMBER, null);
break;
case R.id.home_btn_learn:
this.changeModule(ModulesEnum.LEARN, null);
break;
case R.id.home_btn_my:
this.changeModule(ModulesEnum.MY, null);
break;
default:
break;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// if (!this.modulesMgr.onBackStack()) {
// return false;
// }
// }
return super.onKeyDown(keyCode, event);
}
@Override
public void changeModule(ModulesEnum module, Fragment fragment2) {
if (this.currentModule == module) {
return;
}
RadioButton moduleButton = this.moduleViewsMap.get(module);
Fragment fragment = this.mFragmentMap.get(module);
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.hide(manager.findFragmentByTag(this.currentModule.name));
transaction.addToBackStack("").show(fragment).commit();
if (null != moduleButton) {
moduleButton.setChecked(true);
}
this.currentModule = module;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!