2020-08-03 09:11:54 +08:00
|
|
|
|
package com.sl.house_property;
|
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
|
|
import android.support.v4.app.FragmentTransaction;
|
2020-08-14 17:07:43 +08:00
|
|
|
|
import android.view.MotionEvent;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
import android.view.View;
|
|
|
|
|
|
import android.widget.RadioButton;
|
|
|
|
|
|
import android.widget.RadioGroup;
|
|
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
import com.gyf.immersionbar.ImmersionBar;
|
2020-08-21 13:39:24 +08:00
|
|
|
|
import com.sl.house_property.cart.CartFragment;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
import com.sl.house_property.databinding.ActivityMainTabBinding;
|
2020-08-11 14:48:10 +08:00
|
|
|
|
import com.sl.house_property.discovery.DiscoveryFragment;
|
2020-09-18 09:14:08 +08:00
|
|
|
|
import com.sl.house_property.discovery.LikeFragment;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
2020-08-03 09:11:54 +08:00
|
|
|
|
import tools.Config;
|
|
|
|
|
|
|
|
|
|
|
|
public class MainTabActivity extends BaseActivity<ActivityMainTabBinding>
|
2020-09-21 10:45:32 +08:00
|
|
|
|
implements View.OnClickListener,
|
2020-08-03 09:11:54 +08:00
|
|
|
|
Main1Fragment.OnFragmentInteractionListener,
|
|
|
|
|
|
Main2Fragment.OnFragmentInteractionListener,
|
|
|
|
|
|
Main3Fragment.OnFragmentInteractionListener,
|
2020-08-14 17:07:43 +08:00
|
|
|
|
Main4Fragment.OnFragmentInteractionListener {
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
|
|
|
|
|
/*定义的全局返回码,例如在主界面的某个Fragment点击某一项后进入下一个界面后
|
|
|
|
|
|
如果在下一个界面有数据更改,需要Fragment刷新时,通过setResult方法通知主界面,主界面的
|
|
|
|
|
|
onActivityResult方法会接收到通知,再刷新相应的Fragment
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public static final int RESUlT_CODE_0 = 201;//首页
|
2020-08-11 14:48:10 +08:00
|
|
|
|
public static final int RESUlT_CODE_1 = 202;//发现
|
|
|
|
|
|
public static final int RESUlT_CODE_2 = 203;//购物车
|
2020-08-14 17:07:43 +08:00
|
|
|
|
// public static final int RESUlT_CODE_3 = 204;//
|
2020-08-03 09:11:54 +08:00
|
|
|
|
public static final int RESUlT_CODE_4 = 205;//我的
|
2020-08-14 17:07:43 +08:00
|
|
|
|
private RadioGroup radioGroup;
|
|
|
|
|
|
private MainFragment fragment0;
|
|
|
|
|
|
private DiscoveryFragment fragment1;
|
|
|
|
|
|
private Main3Fragment fragment2;
|
2020-08-21 13:39:24 +08:00
|
|
|
|
private CartFragment fragment3;
|
2020-08-14 17:07:43 +08:00
|
|
|
|
private Main4Fragment fragment4;
|
2021-02-28 19:36:01 +08:00
|
|
|
|
// private LikeFragment likeFragment;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
private Fragment currentFragment;
|
|
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
private int myeditcode = 1000;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
private int nowradioId;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
2020-09-18 09:14:08 +08:00
|
|
|
|
// @Override
|
2020-08-14 17:07:43 +08:00
|
|
|
|
// public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
|
|
// switch (ev.getAction()) {
|
|
|
|
|
|
// case MotionEvent.ACTION_DOWN:
|
|
|
|
|
|
//
|
|
|
|
|
|
// UtilHelpers.hideKeyboard(ev, getCurrentFocus(), this);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return super.dispatchTouchEvent(ev);
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
2020-09-18 09:14:08 +08:00
|
|
|
|
public void visibilyBottom(int isVisibily) {
|
2020-08-14 17:07:43 +08:00
|
|
|
|
findViewById(R.id.rl_bottom).setVisibility(isVisibily);
|
|
|
|
|
|
}
|
2020-09-18 09:14:08 +08:00
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
//2. 保存MyOnTouchListener接口的列表
|
|
|
|
|
|
private ArrayList<MyOnTouchListener> onTouchListeners = new ArrayList<MyOnTouchListener>();
|
2020-09-18 09:14:08 +08:00
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
//1.触摸事件接口
|
|
|
|
|
|
public interface MyOnTouchListener {
|
|
|
|
|
|
public boolean onTouch(MotionEvent ev);
|
|
|
|
|
|
}
|
2020-09-18 09:14:08 +08:00
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
|
|
|
|
|
for (MyOnTouchListener listener : onTouchListeners) {
|
2020-09-18 09:14:08 +08:00
|
|
|
|
// listener.onTouch(ev);
|
2020-08-14 17:07:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
return super.dispatchTouchEvent(ev);
|
|
|
|
|
|
}
|
2020-09-18 09:14:08 +08:00
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
//4.提供给Fragment通过getActivity()方法来注册自己的触摸事件的方法
|
|
|
|
|
|
public void registerMyOnTouchListener(MyOnTouchListener myOnTouchListener) {
|
|
|
|
|
|
onTouchListeners.add(myOnTouchListener);
|
|
|
|
|
|
}
|
2020-09-18 09:14:08 +08:00
|
|
|
|
|
2020-08-14 17:07:43 +08:00
|
|
|
|
//5.提供给Fragment通过getActivity()方法来注销自己的触摸事件的方法
|
|
|
|
|
|
public void unregisterMyOnTouchListener(MyOnTouchListener myOnTouchListener) {
|
|
|
|
|
|
onTouchListeners.remove(myOnTouchListener);
|
|
|
|
|
|
}
|
2020-09-18 09:14:08 +08:00
|
|
|
|
|
2020-08-03 09:11:54 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected int getLayoutResId() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return R.layout.activity_main_tab;
|
|
|
|
|
|
}
|
2020-08-14 17:07:43 +08:00
|
|
|
|
|
2020-08-03 09:11:54 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
2020-08-14 17:07:43 +08:00
|
|
|
|
Config.getInstance(MainTabActivity.this).put("MainTabActivity", true);
|
2020-08-03 09:11:54 +08:00
|
|
|
|
//setPhotoSysyrmbar();
|
2020-08-14 17:07:43 +08:00
|
|
|
|
//setSytemBar(R.color.colorPrimary);//设置主题样式
|
|
|
|
|
|
//setFramentMarginTop();
|
|
|
|
|
|
ImmersionBar.with(this)
|
|
|
|
|
|
.keyboardEnable(true) //解决软键盘与底部输入框冲突问题
|
|
|
|
|
|
// .keyboardEnable(true, WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE
|
|
|
|
|
|
// | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) //软键盘自动弹出
|
|
|
|
|
|
.init();
|
2020-08-03 09:11:54 +08:00
|
|
|
|
initView();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("MissingSuperCall")
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onSaveInstanceState(Bundle outState) {
|
2020-08-14 17:07:43 +08:00
|
|
|
|
super.onSaveInstanceState(outState);
|
2020-08-03 09:11:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initView() {
|
2020-08-14 17:07:43 +08:00
|
|
|
|
radioGroup = mDataBinding.radioGroup;
|
|
|
|
|
|
for (int i = 0; i < radioGroup.getChildCount(); i++) {
|
|
|
|
|
|
RadioButton myRadioButton = (RadioButton) radioGroup.getChildAt(i);
|
2020-08-03 09:11:54 +08:00
|
|
|
|
myRadioButton.setOnClickListener(this);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
mDataBinding.button.setChecked(true);
|
2020-08-14 17:07:43 +08:00
|
|
|
|
nowradioId = mDataBinding.button.getId();
|
2020-08-03 09:11:54 +08:00
|
|
|
|
mDataBinding.getRoot().setBackground(getResources().getDrawable(R.drawable.background_slowly));
|
2020-08-14 17:07:43 +08:00
|
|
|
|
changeFragment(mDataBinding.button.getId());
|
2020-08-03 09:11:54 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void changeFragment(int i) {
|
|
|
|
|
|
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
|
|
|
if (currentFragment != null)
|
|
|
|
|
|
fragmentTransaction.hide(currentFragment);
|
|
|
|
|
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
|
|
case R.id.button:
|
|
|
|
|
|
// mDataBinding.getRoot().setBackground(getResources().getDrawable(R.drawable.background_slowly));
|
|
|
|
|
|
if (fragment0 == null) {
|
|
|
|
|
|
fragment0 = MainFragment.newInstance("", "");
|
|
|
|
|
|
fragmentTransaction.add(R.id.mycontent, fragment0, "fragment0");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
fragmentTransaction.show(fragment0);
|
|
|
|
|
|
}
|
|
|
|
|
|
currentFragment = fragment0;
|
|
|
|
|
|
|
|
|
|
|
|
//setSytemBar(R.color.transparent);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case R.id.button1:
|
|
|
|
|
|
// mDataBinding.getRoot().setBackground(getResources().getDrawable(R.drawable.background_slowly));
|
|
|
|
|
|
if (fragment1 == null) {
|
|
|
|
|
|
|
2020-08-11 14:48:10 +08:00
|
|
|
|
fragment1 = DiscoveryFragment.newInstance("", "");
|
2020-08-03 09:11:54 +08:00
|
|
|
|
fragmentTransaction.add(R.id.mycontent, fragment1, "fragment1");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
fragmentTransaction.show(fragment1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currentFragment = fragment1;
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
case R.id.button2:
|
|
|
|
|
|
|
|
|
|
|
|
if (fragment2 == null) {
|
|
|
|
|
|
fragment2 = Main3Fragment.newInstance("", "");
|
|
|
|
|
|
fragmentTransaction.add(R.id.mycontent, fragment2, "fragment2");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
fragmentTransaction.show(fragment2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currentFragment = fragment2;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case R.id.button3:
|
|
|
|
|
|
// mDataBinding.getRoot().setBackground(getResources().getDrawable(R.drawable.background_slowly));
|
|
|
|
|
|
if (fragment3 == null) {
|
2020-08-21 13:39:24 +08:00
|
|
|
|
fragment3 = CartFragment.newInstance();
|
2020-08-03 09:11:54 +08:00
|
|
|
|
fragmentTransaction.add(R.id.mycontent, fragment3, "fragment3");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
fragmentTransaction.show(fragment3);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currentFragment = fragment3;
|
|
|
|
|
|
break;
|
|
|
|
|
|
case R.id.button4:
|
|
|
|
|
|
|
|
|
|
|
|
// mDataBinding.getRoot().setBackground(getResources().getDrawable(R.mipmap.beijing));
|
|
|
|
|
|
if (fragment4 == null) {
|
|
|
|
|
|
fragment4 = Main4Fragment.newInstance("", "");
|
|
|
|
|
|
fragmentTransaction.add(R.id.mycontent, fragment4, "fragment4");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
fragmentTransaction.show(fragment4);
|
|
|
|
|
|
}
|
|
|
|
|
|
currentFragment = fragment4;
|
|
|
|
|
|
break;
|
2021-02-28 19:36:01 +08:00
|
|
|
|
// case R.id.like:
|
|
|
|
|
|
// if (likeFragment == null) {
|
|
|
|
|
|
// likeFragment = LikeFragment.newInstance();
|
|
|
|
|
|
// fragmentTransaction.add(R.id.mycontent, likeFragment, "likeFragment");
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
// fragmentTransaction.show(likeFragment);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// currentFragment = likeFragment;
|
|
|
|
|
|
// break;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
|
|
|
fragmentTransaction.commit();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.fillInStackTrace();
|
|
|
|
|
|
fragmentTransaction.commitAllowingStateLoss();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2020-08-14 17:07:43 +08:00
|
|
|
|
|
2020-08-03 09:11:54 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public void onClick(View view) {
|
2020-08-14 17:07:43 +08:00
|
|
|
|
if (view.getId() == nowradioId) return;
|
|
|
|
|
|
RadioButton myRadioButton = (RadioButton) findViewById(nowradioId);
|
|
|
|
|
|
if (view.getId() == R.id.button4) {
|
|
|
|
|
|
if ((Config.getInstance(MainTabActivity.this).getUser() == null)) {
|
|
|
|
|
|
Intent intent = new Intent(MainTabActivity.this, LoginActivity.class);
|
2020-08-03 09:11:54 +08:00
|
|
|
|
startActivity(intent);
|
2020-08-14 17:07:43 +08:00
|
|
|
|
myRadioButton = (RadioButton) view;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
myRadioButton.setChecked(false);
|
2020-08-14 17:07:43 +08:00
|
|
|
|
myRadioButton = (RadioButton) findViewById(nowradioId);
|
2020-08-03 09:11:54 +08:00
|
|
|
|
myRadioButton.setChecked(true);
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
myRadioButton.setChecked(false);
|
2020-08-14 17:07:43 +08:00
|
|
|
|
myRadioButton = (RadioButton) view;
|
2020-08-03 09:11:54 +08:00
|
|
|
|
myRadioButton.setChecked(true);
|
2020-08-14 17:07:43 +08:00
|
|
|
|
nowradioId = view.getId();
|
2020-08-03 09:11:54 +08:00
|
|
|
|
changeFragment(view.getId());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void onFragmentInteraction(Uri uri) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
|
|
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
2020-08-14 17:07:43 +08:00
|
|
|
|
if (resultCode == RESUlT_CODE_4) {
|
|
|
|
|
|
if (currentFragment == fragment4) {
|
2020-08-03 09:11:54 +08:00
|
|
|
|
// if(fragment0!=null){
|
|
|
|
|
|
// fragmentTransaction.remove(fragment0);
|
|
|
|
|
|
// fragment0 = null;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if(fragment1!=null){
|
|
|
|
|
|
// fragmentTransaction.remove(fragment1);
|
|
|
|
|
|
// fragment1 = null;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if(fragment2!=null){
|
|
|
|
|
|
// fragmentTransaction.remove(fragment2);
|
|
|
|
|
|
// fragment2 = null;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// if(fragment3!=null){
|
|
|
|
|
|
// fragmentTransaction.remove(fragment3);
|
|
|
|
|
|
// fragment3 = null;
|
|
|
|
|
|
// }
|
|
|
|
|
|
//
|
|
|
|
|
|
// fragmentTransaction.remove(fragment4);
|
|
|
|
|
|
// mDataBinding.getRoot().setBackground(getResources().getDrawable(R.mipmap.beijing));
|
|
|
|
|
|
// if (fragment4 == null) {
|
|
|
|
|
|
// fragment4 = Main4Fragment.newInstance("", "");
|
|
|
|
|
|
// fragmentTransaction.add(R.id.mycontent, fragment4, "fragment4");
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
//
|
|
|
|
|
|
// }
|
|
|
|
|
|
// fragmentTransaction.show(fragment4);
|
|
|
|
|
|
// currentFragment = fragment4;
|
2020-08-14 17:07:43 +08:00
|
|
|
|
fragment4.refreshData();
|
|
|
|
|
|
}
|
2020-08-03 09:11:54 +08:00
|
|
|
|
try {
|
|
|
|
|
|
// fragmentTransaction.commit();
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.fillInStackTrace();
|
|
|
|
|
|
fragmentTransaction.commitAllowingStateLoss();
|
|
|
|
|
|
}
|
2020-08-14 17:07:43 +08:00
|
|
|
|
} else if (resultCode == myeditcode) {
|
|
|
|
|
|
if (currentFragment == fragment1) {
|
2020-08-03 09:11:54 +08:00
|
|
|
|
fragment1.loadData();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
|
super.onDestroy();
|
2020-08-14 17:07:43 +08:00
|
|
|
|
Config.getInstance(MainTabActivity.this).put("MainTabActivity", false);
|
2020-08-03 09:11:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|