优化长按app隐藏或显示时列表不会改变
This commit is contained in:
@@ -79,7 +79,7 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
|
|
||||||
if (mSettingsFragment == null) {
|
if (mSettingsFragment == null) {
|
||||||
mSettingsFragment = new SettingsFragment();
|
mSettingsFragment = new SettingsFragment();
|
||||||
mFragments.add(mContactFragment);
|
mFragments.add(mSettingsFragment);
|
||||||
mFragmentSize += 1;
|
mFragmentSize += 1;
|
||||||
mCurrentIndex += 1;
|
mCurrentIndex += 1;
|
||||||
}
|
}
|
||||||
@@ -153,23 +153,22 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
int end = Math.min(start + APK_PER_FRAGMENT, mAppInfos.size());
|
int end = Math.min(start + APK_PER_FRAGMENT, mAppInfos.size());
|
||||||
List<AppInfo> subList = new ArrayList<>(mAppInfos.subList(start, end));
|
List<AppInfo> subList = new ArrayList<>(mAppInfos.subList(start, end));
|
||||||
Log.e(TAG, "setAppList: subList size = " + subList.size());
|
Log.e(TAG, "setAppList: subList size = " + subList.size());
|
||||||
// AppFragment fragment = AppFragment.newInstance(subList);
|
// AppFragment appFragment = AppFragment.newInstance(subList);
|
||||||
AppFragment fragment = new AppFragment(subList);
|
AppFragment appFragment = new AppFragment(subList);
|
||||||
fragment.setUpdateCallback(new AppFragment.UpdateCallback() {
|
Log.e(TAG, "setAppList: appFragment hashCode = " + appFragment.hashCode());
|
||||||
|
appFragment.setUpdateCallback(new AppFragment.UpdateCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate() {
|
public void onUpdate() {
|
||||||
mViewModel.getOutsideApp();
|
mViewModel.getOutsideApp();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mFragments.add(fragment);
|
mFragments.add(appFragment);
|
||||||
Log.e(TAG, "setAppList: add mFragments size = " + mFragments.size());
|
Log.e(TAG, "setAppList: add mFragments size = " + mFragments.size());
|
||||||
}
|
}
|
||||||
mScaleCircleNavigator.setCircleCount(mFragments.size());
|
mScaleCircleNavigator.setCircleCount(mFragments.size());
|
||||||
mScaleCircleNavigator.notifyDataSetChanged();
|
mScaleCircleNavigator.notifyDataSetChanged();
|
||||||
|
|
||||||
mApkPagerAdapter.setFragments(mFragments);
|
mApkPagerAdapter.setFragments(mFragments);
|
||||||
mApkPagerAdapter.notifyDataSetChanged();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BtnClick {
|
public class BtnClick {
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class AppFragment extends BaseMvvmFragment<AppViewModel, FragmentAppBindi
|
|||||||
|
|
||||||
public AppFragment(List<AppInfo> appInfos) {
|
public AppFragment(List<AppInfo> appInfos) {
|
||||||
mAppInfos = appInfos;
|
mAppInfos = appInfos;
|
||||||
|
Log.e(TAG, "AppFragment: mAppInfos = " + mAppInfos.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface UpdateCallback {
|
public interface UpdateCallback {
|
||||||
@@ -68,7 +69,7 @@ public class AppFragment extends BaseMvvmFragment<AppViewModel, FragmentAppBindi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initView(Bundle bundle) {
|
protected void initView(Bundle bundle) {
|
||||||
Log.e(TAG, "initView: ");
|
Log.e(TAG, "initView: " + this.hashCode());
|
||||||
|
|
||||||
mAppAdapter = new AppAdapter(LoaderManager.getInstance(this));
|
mAppAdapter = new AppAdapter(LoaderManager.getInstance(this));
|
||||||
mAppAdapter.setShortcutCallback(new AppAdapter.ShortcutCallback() {
|
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.setLayoutManager(new GridLayoutManager(mContext, 3));
|
||||||
mViewDataBinding.recyclerView.addItemDecoration(new EqualHeightDecoration(3));
|
mViewDataBinding.recyclerView.addItemDecoration(new EqualHeightDecoration(3));
|
||||||
mViewDataBinding.recyclerView.setAdapter(mAppAdapter);
|
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
|
@Override
|
||||||
@@ -101,10 +109,7 @@ public class AppFragment extends BaseMvvmFragment<AppViewModel, FragmentAppBindi
|
|||||||
// if (getArguments() != null) {
|
// if (getArguments() != null) {
|
||||||
// mAppInfos = (List<AppInfo>) getArguments().getSerializable(ARG_APP_LIST);
|
// mAppInfos = (List<AppInfo>) getArguments().getSerializable(ARG_APP_LIST);
|
||||||
// }
|
// }
|
||||||
if (mAppInfos != null) {
|
|
||||||
Log.e(TAG, "initData: mAppInfos size = " + mAppInfos.size());
|
|
||||||
mAppAdapter.setAppInfos(mAppInfos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class ApkPagerAdapter extends FragmentPagerAdapter {
|
|||||||
|
|
||||||
public void setFragments(List<Fragment> fragments) {
|
public void setFragments(List<Fragment> fragments) {
|
||||||
this.fragments = fragments;
|
this.fragments = fragments;
|
||||||
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -33,4 +34,15 @@ public class ApkPagerAdapter extends FragmentPagerAdapter {
|
|||||||
public int getItemPosition(Object object) {
|
public int getItemPosition(Object object) {
|
||||||
return POSITION_NONE;
|
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