|
|
|
@ -1,12 +1,16 @@ |
|
|
|
package com.qhclh.ytzh.index.shangpin; |
|
|
|
|
|
|
|
import android.support.v4.app.FragmentTransaction; |
|
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
import com.qhclh.ytzh.R; |
|
|
|
import com.qhclh.ytzh.base.BaseActivity; |
|
|
|
|
|
|
|
import butterknife.BindView; |
|
|
|
import butterknife.OnClick; |
|
|
|
|
|
|
|
/** |
|
|
|
* Created by 青花瓷 on 2017/12/28. |
|
|
|
@ -15,6 +19,35 @@ import butterknife.BindView; |
|
|
|
public class InHouseActivity extends BaseActivity { |
|
|
|
@BindView(R.id.toolbar) |
|
|
|
Toolbar mToolbar; |
|
|
|
|
|
|
|
@BindView(R.id.iv_inhouse_all) |
|
|
|
ImageView iv_inhouse_all; |
|
|
|
@BindView(R.id.tv_inhouse_all) |
|
|
|
TextView tv_inhouse_all; |
|
|
|
|
|
|
|
@BindView(R.id.iv_inhouse_no) |
|
|
|
ImageView iv_inhouse_no; |
|
|
|
@BindView(R.id.tv_inhouse_no) |
|
|
|
TextView tv_inhouse_no; |
|
|
|
|
|
|
|
@BindView(R.id.iv_inhouse_yes) |
|
|
|
ImageView iv_inhouse_yes; |
|
|
|
@BindView(R.id.tv_inhouse_yes) |
|
|
|
TextView tv_inhouse_yes; |
|
|
|
|
|
|
|
///< all |
|
|
|
private static final int TAB_POSITION_ALL = 0; |
|
|
|
///< no |
|
|
|
private static final int TAB_POSITION_NO = 1; |
|
|
|
///< yes |
|
|
|
private static final int TAB_POSITION_YES = 2; |
|
|
|
private int mCurrentTabPosition = -1; |
|
|
|
private int mTargetTabPosition = TAB_POSITION_ALL; |
|
|
|
|
|
|
|
private InHouseAllFragment inHouseAllFragment; |
|
|
|
private InHouseNoFragment inHouseNoFragment; |
|
|
|
private InHouseYesFragment inHouseYesFragment; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected int setLayoutId() { |
|
|
|
return R.layout.act_inhouse; |
|
|
|
@ -28,6 +61,8 @@ public class InHouseActivity extends BaseActivity { |
|
|
|
finish(); |
|
|
|
} |
|
|
|
}); |
|
|
|
///< 点击切换fragment |
|
|
|
onTabClick(mTargetTabPosition); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@ -39,4 +74,124 @@ public class InHouseActivity extends BaseActivity { |
|
|
|
protected void initOper() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@OnClick({R.id.ll_inhouse_all, R.id.ll_inhouse_no, R.id.ll_inhouse_yes}) |
|
|
|
public void onClick(View view) { |
|
|
|
switch (view.getId()) { |
|
|
|
///< all |
|
|
|
case R.id.ll_inhouse_all: { |
|
|
|
onTabClick(TAB_POSITION_ALL); |
|
|
|
break; |
|
|
|
} |
|
|
|
///< no |
|
|
|
case R.id.ll_inhouse_no: { |
|
|
|
onTabClick(TAB_POSITION_NO); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
///< yes |
|
|
|
case R.id.ll_inhouse_yes: { |
|
|
|
onTabClick(TAB_POSITION_YES); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void onTabClick(int tabPosition) { |
|
|
|
if (mCurrentTabPosition == tabPosition) { |
|
|
|
return; |
|
|
|
} |
|
|
|
mCurrentTabPosition = tabPosition; |
|
|
|
changeTabState(tabPosition); |
|
|
|
changeFragment(tabPosition); |
|
|
|
} |
|
|
|
|
|
|
|
private void changeTabState(int tabPosition) { |
|
|
|
clearAllTabState(); |
|
|
|
switch (tabPosition) { |
|
|
|
case TAB_POSITION_ALL: { |
|
|
|
iv_inhouse_all.setImageResource(R.drawable.shouye_3x); |
|
|
|
tv_inhouse_all.setTextColor(getResources().getColor(R.color.colorPrimary)); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case TAB_POSITION_NO: { |
|
|
|
iv_inhouse_no.setImageResource(R.drawable.gongzuo_3x); |
|
|
|
tv_inhouse_no.setTextColor(getResources().getColor(R.color.colorPrimary)); |
|
|
|
break; |
|
|
|
} |
|
|
|
case TAB_POSITION_YES: { |
|
|
|
iv_inhouse_yes.setImageResource(R.drawable.wode_3x); |
|
|
|
tv_inhouse_yes.setTextColor(getResources().getColor(R.color.colorPrimary)); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void clearAllTabState() { |
|
|
|
///< all |
|
|
|
iv_inhouse_all.setImageResource(R.drawable.shouye1_3x); |
|
|
|
tv_inhouse_all.setTextColor(getResources().getColor(R.color.grey_767c82)); |
|
|
|
///< no |
|
|
|
iv_inhouse_no.setImageResource(R.drawable.gongzuo1_3x); |
|
|
|
tv_inhouse_no.setTextColor(getResources().getColor(R.color.grey_767c82)); |
|
|
|
|
|
|
|
///< yes |
|
|
|
iv_inhouse_yes.setImageResource(R.drawable.wode1_3x); |
|
|
|
tv_inhouse_yes.setTextColor(getResources().getColor(R.color.grey_767c82)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void changeFragment(int tabPosition) { |
|
|
|
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
|
|
|
hideFragment(transaction); |
|
|
|
switch (tabPosition) { |
|
|
|
case TAB_POSITION_ALL: { |
|
|
|
if (inHouseAllFragment == null) { |
|
|
|
inHouseAllFragment = new InHouseAllFragment(); |
|
|
|
transaction.add(R.id.inhouse_container, inHouseAllFragment); |
|
|
|
} else { |
|
|
|
transaction.show(inHouseAllFragment); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case TAB_POSITION_NO: { |
|
|
|
if (inHouseNoFragment == null) { |
|
|
|
inHouseNoFragment = new InHouseNoFragment(); |
|
|
|
transaction.add(R.id.inhouse_container, inHouseNoFragment); |
|
|
|
} else { |
|
|
|
transaction.show(inHouseNoFragment); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case TAB_POSITION_YES: { |
|
|
|
if (inHouseYesFragment == null) { |
|
|
|
inHouseYesFragment = new InHouseYesFragment(); |
|
|
|
transaction.add(R.id.inhouse_container, inHouseYesFragment); |
|
|
|
} else { |
|
|
|
transaction.show(inHouseYesFragment); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
transaction.commitAllowingStateLoss(); |
|
|
|
} |
|
|
|
|
|
|
|
private void hideFragment(FragmentTransaction transaction) { |
|
|
|
if (inHouseAllFragment != null) { |
|
|
|
transaction.hide(inHouseAllFragment); |
|
|
|
} |
|
|
|
|
|
|
|
if (inHouseNoFragment != null) { |
|
|
|
transaction.hide(inHouseNoFragment); |
|
|
|
} |
|
|
|
if (inHouseYesFragment != null) { |
|
|
|
transaction.hide(inHouseYesFragment); |
|
|
|
} |
|
|
|
} |
|
|
|
} |