|
|
@@ -1,6 +1,8 @@
|
|
|
package com.uas.appworks.crm3_0.activity;
|
|
|
|
|
|
|
|
|
+import android.graphics.PixelFormat;
|
|
|
+import android.nfc.Tag;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.app.FragmentTransaction;
|
|
|
@@ -14,6 +16,8 @@ import com.modular.apputils.widget.DivideRadioGroup;
|
|
|
import com.uas.appworks.R;
|
|
|
import com.uas.appworks.crm3_0.fragment.CustomerListFragment;
|
|
|
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* 客户列表界面
|
|
|
*/
|
|
|
@@ -21,71 +25,95 @@ public class CustomerListActivity extends BaseActivity {
|
|
|
private final String LIST = "List";
|
|
|
private final String MAP = "Map";
|
|
|
|
|
|
- private Fragment lastFragment;
|
|
|
+ private Fragment mCurrentFragment;
|
|
|
private String mCaller;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_customer_list_3_0);
|
|
|
+// getWindow().setFormat(PixelFormat.TRANSLUCENT);
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
|
if (getIntent() != null) {
|
|
|
String title = getIntent().getStringExtra(Constants.Intents.TITLE);
|
|
|
- mCaller = getIntent().getStringExtra(Constants.Intents.CALLER);
|
|
|
+ mCaller = getIntent().getStringExtra(Constants.Intents.CALLER);
|
|
|
if (!TextUtils.isEmpty(title)) {
|
|
|
setTitle(title + "列表");
|
|
|
} else {
|
|
|
setTitle("列表");
|
|
|
}
|
|
|
}
|
|
|
- if (TextUtils.isEmpty(mCaller)){
|
|
|
+ if (TextUtils.isEmpty(mCaller)) {
|
|
|
mCaller = "Customer!Base";
|
|
|
}
|
|
|
DivideRadioGroup tabBottomRg = findViewById(R.id.tabBottomRg);
|
|
|
- Fragment listFragment = CustomerListFragment.newInstance(1,mCaller);
|
|
|
- changeFragment(listFragment, LIST);
|
|
|
+ changeFragment(LIST);
|
|
|
tabBottomRg.setOnCheckedChangeListener(new DivideRadioGroup.OnCheckedChangeListener() {
|
|
|
@Override
|
|
|
public void onCheckedChanged(DivideRadioGroup group, int checkedId) {
|
|
|
- Fragment fragment = null;
|
|
|
String tag = null;
|
|
|
if (R.id.customerListRb == checkedId) {
|
|
|
- fragment = getSupportFragmentManager().findFragmentByTag(LIST);
|
|
|
- if (fragment == null) {
|
|
|
- fragment = CustomerListFragment.newInstance(1,mCaller);
|
|
|
- }
|
|
|
tag = LIST;
|
|
|
} else if (R.id.customerLocationRb == checkedId) {
|
|
|
- fragment = getSupportFragmentManager().findFragmentByTag(MAP);
|
|
|
- if (fragment == null) {
|
|
|
- fragment = CustomerListFragment.newInstance(2,mCaller);
|
|
|
- }
|
|
|
tag = MAP;
|
|
|
}
|
|
|
- changeFragment(fragment, tag);
|
|
|
+ changeFragment(tag);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void changeFragment(Fragment addFragment, String tag) {
|
|
|
+ private void changeFragment(String tag) {
|
|
|
+ Fragment addFragment = getAddFragment(tag);
|
|
|
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();// 开始事物
|
|
|
if (addFragment == null) {
|
|
|
return;
|
|
|
}
|
|
|
- if (addFragment == lastFragment) {
|
|
|
+ if (addFragment == mCurrentFragment) {
|
|
|
return;
|
|
|
}
|
|
|
- if (lastFragment != null && lastFragment != addFragment) {// 如果最后一次加载的不是现在要加载的Fragment,那么僵最后一次加载的移出
|
|
|
- fragmentTransaction.detach(lastFragment);
|
|
|
+ if (mCurrentFragment != null && mCurrentFragment != addFragment) {// 如果最后一次加载的不是现在要加载的Fragment,那么僵最后一次加载的移出
|
|
|
+ fragmentTransaction.detach(mCurrentFragment);
|
|
|
}
|
|
|
if (!addFragment.isAdded())// 如果还没有添加,就加上
|
|
|
fragmentTransaction.add(R.id.customerFl, addFragment, tag);
|
|
|
if (addFragment.isDetached())
|
|
|
fragmentTransaction.attach(addFragment);
|
|
|
- lastFragment = addFragment;
|
|
|
+ mCurrentFragment = addFragment;
|
|
|
fragmentTransaction.commitAllowingStateLoss();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // 获取当前的fragment
|
|
|
+ private Fragment getAddFragment(String mTag) {
|
|
|
+ Fragment mAddFragment = getSupportFragmentManager().findFragmentByTag(mTag);
|
|
|
+ if (mAddFragment == null) {
|
|
|
+ if (mTag.equals(MAP)) {
|
|
|
+ mAddFragment = CustomerListFragment.newInstance(2, mCaller);
|
|
|
+ } else {
|
|
|
+ mAddFragment = CustomerListFragment.newInstance(1, mCaller);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return mAddFragment;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void changeTab(String mTag) {
|
|
|
+ Fragment mAddFragment = getAddFragment(mTag);
|
|
|
+ if (mCurrentFragment != mAddFragment) {
|
|
|
+ FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
|
|
|
+ if (mCurrentFragment != null) {
|
|
|
+ mTransaction.hide(mCurrentFragment);
|
|
|
+ }
|
|
|
+ if (!mAddFragment.isAdded()) {
|
|
|
+ mTransaction.add(R.id.customerFl, mAddFragment, mTag);
|
|
|
+ } else {
|
|
|
+ mTransaction.show(mAddFragment);
|
|
|
+ }
|
|
|
+ mCurrentFragment = mAddFragment;
|
|
|
+ mTransaction.commitNowAllowingStateLoss();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|