1. bugfix
This commit is contained in:
@@ -25,22 +25,12 @@ public class AppsAdapter extends BaseAdapter {
|
||||
private List< AppInfo > mAppInfos;
|
||||
|
||||
public AppsAdapter( List< AppInfo > appInfos ) {
|
||||
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 );
|
||||
}
|
||||
}
|
||||
this.mAppInfos = new ArrayList<>( appInfos );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
int size = mAppInfos == null ? 0 : mAppInfos.size();
|
||||
size = size > AppsConst.TOTAL_SIZE_EACH_PAGE ? AppsConst.TOTAL_SIZE_EACH_PAGE : size;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.mogo.utils.ThreadPoolService;
|
||||
import com.mogo.utils.UiThreadHandler;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.sql.ClientInfoStatus;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -80,9 +81,10 @@ public class AppsPresenter extends Presenter< AppsView > {
|
||||
|
||||
Logger.d( TAG, "apps: %s", appInfoList );
|
||||
final Map< Integer, List< AppInfo > > result = addOthersEntrances( appInfoList );
|
||||
final Map< Integer, List< AppInfo > > newResult = rePutInOrderAppList( result );
|
||||
UiThreadHandler.post( () -> {
|
||||
if ( mView != null ) {
|
||||
mView.renderApps( result );
|
||||
mView.renderApps( newResult );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
@@ -172,6 +174,39 @@ public class AppsPresenter extends Presenter< AppsView > {
|
||||
}
|
||||
}
|
||||
|
||||
private Map< Integer, List< AppInfo > > rePutInOrderAppList( Map< Integer, List< AppInfo > > target ) {
|
||||
if ( target == null || target.isEmpty() ) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
Map< Integer, List< AppInfo > > result = new HashMap<>();
|
||||
synchronized ( target ) {
|
||||
List< AppInfo > list = new ArrayList<>();
|
||||
for ( List< AppInfo > value : target.values() ) {
|
||||
for ( AppInfo appInfo : value ) {
|
||||
if ( list.contains( appInfo ) ) {
|
||||
continue;
|
||||
}
|
||||
list.add( appInfo );
|
||||
}
|
||||
}
|
||||
int page = 0;
|
||||
int counter = 0;
|
||||
for ( AppInfo appInfo : list ) {
|
||||
if ( counter < AppsConst.TOTAL_SIZE_EACH_PAGE ) {
|
||||
counter++;
|
||||
} else {
|
||||
page++;
|
||||
counter = 0;
|
||||
}
|
||||
if ( !result.containsKey( page ) ) {
|
||||
result.put( page, new ArrayList<>() );
|
||||
}
|
||||
result.get( page ).add( appInfo );
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void launch( AppInfo appInfo ) {
|
||||
if ( appInfo == null ) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user