优化长按app隐藏或显示时列表不会改变
This commit is contained in:
@@ -79,7 +79,7 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
||||
|
||||
if (mSettingsFragment == null) {
|
||||
mSettingsFragment = new SettingsFragment();
|
||||
mFragments.add(mContactFragment);
|
||||
mFragments.add(mSettingsFragment);
|
||||
mFragmentSize += 1;
|
||||
mCurrentIndex += 1;
|
||||
}
|
||||
@@ -153,23 +153,22 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
||||
int end = Math.min(start + APK_PER_FRAGMENT, mAppInfos.size());
|
||||
List<AppInfo> subList = new ArrayList<>(mAppInfos.subList(start, end));
|
||||
Log.e(TAG, "setAppList: subList size = " + subList.size());
|
||||
// AppFragment fragment = AppFragment.newInstance(subList);
|
||||
AppFragment fragment = new AppFragment(subList);
|
||||
fragment.setUpdateCallback(new AppFragment.UpdateCallback() {
|
||||
// AppFragment appFragment = AppFragment.newInstance(subList);
|
||||
AppFragment appFragment = new AppFragment(subList);
|
||||
Log.e(TAG, "setAppList: appFragment hashCode = " + appFragment.hashCode());
|
||||
appFragment.setUpdateCallback(new AppFragment.UpdateCallback() {
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
mViewModel.getOutsideApp();
|
||||
}
|
||||
});
|
||||
mFragments.add(fragment);
|
||||
mFragments.add(appFragment);
|
||||
Log.e(TAG, "setAppList: add mFragments size = " + mFragments.size());
|
||||
}
|
||||
mScaleCircleNavigator.setCircleCount(mFragments.size());
|
||||
mScaleCircleNavigator.notifyDataSetChanged();
|
||||
|
||||
mApkPagerAdapter.setFragments(mFragments);
|
||||
mApkPagerAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
public class BtnClick {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class AppFragment extends BaseMvvmFragment<AppViewModel, FragmentAppBindi
|
||||
|
||||
public AppFragment(List<AppInfo> appInfos) {
|
||||
mAppInfos = appInfos;
|
||||
Log.e(TAG, "AppFragment: mAppInfos = " + mAppInfos.hashCode());
|
||||
}
|
||||
|
||||
public interface UpdateCallback {
|
||||
@@ -68,7 +69,7 @@ public class AppFragment extends BaseMvvmFragment<AppViewModel, FragmentAppBindi
|
||||
|
||||
@Override
|
||||
protected void initView(Bundle bundle) {
|
||||
Log.e(TAG, "initView: ");
|
||||
Log.e(TAG, "initView: " + this.hashCode());
|
||||
|
||||
mAppAdapter = new AppAdapter(LoaderManager.getInstance(this));
|
||||
mAppAdapter.setShortcutCallback(new AppAdapter.ShortcutCallback() {
|
||||
@@ -81,6 +82,13 @@ public class AppFragment extends BaseMvvmFragment<AppViewModel, FragmentAppBindi
|
||||
mViewDataBinding.recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));
|
||||
mViewDataBinding.recyclerView.addItemDecoration(new EqualHeightDecoration(3));
|
||||
mViewDataBinding.recyclerView.setAdapter(mAppAdapter);
|
||||
|
||||
if (mAppInfos != null) {
|
||||
Log.e(TAG, "initView: mAppInfos size = " + mAppInfos.size());
|
||||
Log.e(TAG, "initView: mAppInfos = " + mAppInfos.hashCode());
|
||||
mAppAdapter.setAppInfos(mAppInfos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,10 +109,7 @@ public class AppFragment extends BaseMvvmFragment<AppViewModel, FragmentAppBindi
|
||||
// if (getArguments() != null) {
|
||||
// mAppInfos = (List<AppInfo>) getArguments().getSerializable(ARG_APP_LIST);
|
||||
// }
|
||||
if (mAppInfos != null) {
|
||||
Log.e(TAG, "initData: mAppInfos size = " + mAppInfos.size());
|
||||
mAppAdapter.setAppInfos(mAppInfos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ApkPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
public void setFragments(List<Fragment> fragments) {
|
||||
this.fragments = fragments;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -33,4 +34,15 @@ public class ApkPagerAdapter extends FragmentPagerAdapter {
|
||||
public int getItemPosition(Object object) {
|
||||
return POSITION_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
// 返回Fragment的hashCode,或者任何能唯一标识该Fragment实例的值。
|
||||
// 确保当fragments列表更新后,新的Fragment实例会有新的ID。
|
||||
if (fragments != null && position < fragments.size()) {
|
||||
return fragments.get(position).hashCode();
|
||||
}
|
||||
return super.getItemId(position);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user