This commit is contained in:
wangcongtao
2020-07-02 10:51:18 +08:00
parent dde7367801
commit a6e94ae897
4 changed files with 37 additions and 37 deletions

View File

@@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
import com.mogo.module.apps.model.AppInfo;
import java.util.ArrayList;
import java.util.List;
/**
@@ -24,17 +25,23 @@ public class AppsAdapter extends BaseAdapter {
private List< AppInfo > mAppInfos;
public AppsAdapter( List< AppInfo > appInfos ) {
this.mAppInfos = appInfos;
}
public void refreshAppInfos( List< AppInfo > mAppInfos ) {
this.mAppInfos = mAppInfos;
notifyDataSetChanged();
List< AppInfo > newList = new ArrayList<>( appInfos );
this.mAppInfos = new ArrayList<>();
if ( newList != null && !newList.isEmpty() ) {
for ( AppInfo appInfo : newList ) {
if ( mAppInfos.contains( appInfo ) ) {
continue;
}
mAppInfos.add( appInfo );
}
}
}
@Override
public int getCount() {
return mAppInfos == null ? 0 : mAppInfos.size();
int size = mAppInfos == null ? 0 : mAppInfos.size();
size = size > AppsConst.TOTAL_SIZE_EACH_PAGE ? AppsConst.TOTAL_SIZE_EACH_PAGE : size;
return size;
}
@Override

View File

@@ -80,11 +80,6 @@ public class AppsPresenter extends Presenter< AppsView > {
Logger.d( TAG, "apps: %s", appInfoList );
final Map< Integer, List< AppInfo > > result = addOthersEntrances( appInfoList );
try {
filterSamePackage( result );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
UiThreadHandler.post( () -> {
if ( mView != null ) {
mView.renderApps( result );
@@ -159,30 +154,6 @@ public class AppsPresenter extends Presenter< AppsView > {
return result;
}
private void filterSamePackage( Map< Integer, List< AppInfo > > appInfoMap ) {
if ( appInfoMap == null || appInfoMap.isEmpty() ) {
return;
}
for ( Map.Entry< Integer, List< AppInfo > > integerListEntry : appInfoMap.entrySet() ) {
if ( integerListEntry == null ) {
continue;
}
List< AppInfo > oldList = integerListEntry.getValue();
if ( oldList == null
|| oldList.size() > AppsConst.TOTAL_SIZE_EACH_PAGE ) {
return;
}
List< AppInfo > appInfos = new ArrayList<>();
for ( AppInfo appInfo : oldList ) {
if ( appInfos.contains( appInfo ) ) {
continue;
}
appInfos.add( appInfo );
}
integerListEntry.setValue( appInfos );
}
}
/**
* 扩容
*