fix: imageload download logic

This commit is contained in:
wangcongtao
2020-01-06 14:59:03 +08:00
parent f93d15f80a
commit 733ce0c55c
20 changed files with 250 additions and 51 deletions

View File

@@ -101,7 +101,7 @@ public class MogoServiceProvider implements IMogoModuleProvider,
case ServiceConst.MSG_TYPE_REFRESH_DECREASE:
mRefreshRemainingTime -= ServiceConst.DECREASE_INTERVAL;
if ( mRefreshRemainingTime == 0 ) {
notifyRefreshData( mAutoRefreshCallback );
notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback );
} else {
mHandler.sendEmptyMessageDelayed( msg.what, ServiceConst.DECREASE_INTERVAL );
}
@@ -334,19 +334,26 @@ public class MogoServiceProvider implements IMogoModuleProvider,
// 手动刷新触发
if ( mLastZoomLevel - zoom > mCustomRefreshStrategy.getZoomOutLevel() ) {
// 缩放级别缩小
notifyRefreshData( mCustomRefreshCallback );
notifyRefreshData( latLng, getQueryRadius(), mCustomRefreshCallback );
mLastCustomRefreshCenterLocation = latLng;
mLastZoomLevel = zoom;
} else if ( mLastZoomLevel == zoom ) {
// 手动平移
if ( invokeRefreshWhenTranslationByUser( latLng ) ) {
notifyRefreshData( mCustomRefreshCallback );
notifyRefreshData( latLng, getQueryRadius(), mCustomRefreshCallback );
mLastCustomRefreshCenterLocation = latLng;
}
}
Logger.d( TAG, "current map status: %s, zoom = %f, tilt = %f, bearing = %f", latLng, zoom, tilt, bearing );
}
private int getQueryRadius() {
if ( mIsVertical ) {
return ( ( int ) ( getMapCameraFactWidth() / 2 ) );
}
return ( ( int ) ( getMapCameraFactHeight() / 2 ) );
}
/**
* 平移地图刷新策略
*
@@ -379,11 +386,11 @@ public class MogoServiceProvider implements IMogoModuleProvider,
// 自动刷新触发
if ( mLastAutoRefreshLocation == null ) {
mLastAutoRefreshLocation = new MogoLatLng( location.getLatitude(), location.getLongitude() );
notifyRefreshData( mAutoRefreshCallback );
notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback );
} else {
float distance = Utils.calculateLineDistance( mLastAutoRefreshLocation, new MogoLatLng( location.getLatitude(), location.getLongitude() ) );
if ( distance > mAutoRefreshStrategy.getDistance() ) {
notifyRefreshData( mAutoRefreshCallback );
notifyRefreshData( mLastAutoRefreshLocation, 2_000, mAutoRefreshCallback );
}
}
}
@@ -391,9 +398,9 @@ public class MogoServiceProvider implements IMogoModuleProvider,
/**
* 刷新数据
*/
private void notifyRefreshData( RefreshCallback callback ) {
private void notifyRefreshData( MogoLatLng latLng, int radius, RefreshCallback callback ) {
Logger.d( TAG, mAutoRefreshCallback == callback ? "触发自动刷新" : "触发手动刷新" );
mRefreshModel.refreshData( callback );
mRefreshModel.refreshData( latLng, radius, callback );
}
@Override

View File

@@ -6,7 +6,10 @@ import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Single;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.QueryMap;
/**
@@ -17,6 +20,8 @@ import retrofit2.http.QueryMap;
*/
public interface RefreshApiService {
@GET( "" )
Observable< BaseData > refreshData( @QueryMap Map< String, Object > params );
@FormUrlEncoded
@POST( "" )
Observable< BaseData > refreshData( @QueryMap Map< String, Object > params,
@FieldMap Map< String, Object > parameters );
}

View File

@@ -0,0 +1,29 @@
package com.mogo.module.service.network;
import java.util.ArrayList;
import java.util.List;
/**
* @author congtaowang
* @since 2020-01-06
* <p>
* 刷新地图信息接口
*/
public class RefreshBody {
public List< String > dataType = new ArrayList<>();
public int limit = 50;// 请求数量
public int radius = 2_000; // 地理围栏半径(米)
public LatLon location;
public static class LatLon {
private double lat;
private double lon;
public LatLon( double lat, double lon ) {
this.lat = lat;
this.lon = lon;
}
}
}

View File

@@ -6,10 +6,14 @@ import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.data.BaseData;
import com.mogo.commons.network.ParamsProvider;
import com.mogo.commons.network.SubscribeImpl;
import com.mogo.commons.network.Utils;
import com.mogo.map.MogoLatLng;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.network.IMogoNetwork;
import com.mogo.utils.network.RequestOptions;
import com.mogo.utils.network.utils.GsonUtil;
import java.util.HashMap;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
@@ -33,14 +37,21 @@ public class RefreshModel {
this.mRefreshApiService = network.create( RefreshApiService.class, "http://www.baidu.com/" );
}
public void refreshData( final RefreshCallback callback ) {
public void refreshData( MogoLatLng latLng, int radius, final RefreshCallback callback ) {
if ( callback != null ) {
callback.onSuccess();
return;
}
if ( mRefreshApiService != null ) {
final Map< String, Object > params = new ParamsProvider.Builder( mContext ).build();
mRefreshApiService.refreshData( params )
final Map< String, Object > query = new ParamsProvider.Builder( mContext ).build();
final Map< String, Object > field = new HashMap<>();
field.put( "sn", query.get( "sn" ) );
final RefreshBody refreshBody = new RefreshBody();
refreshBody.limit = 50;
refreshBody.location = new RefreshBody.LatLon( latLng.lat, latLng.lng );
refreshBody.radius = radius;
field.put( "data", GsonUtil.jsonFromObject( refreshBody ) );
mRefreshApiService.refreshData( query, field )
.subscribeOn( Schedulers.io() )
.observeOn( AndroidSchedulers.mainThread() )
.subscribe( new SubscribeImpl< BaseData >( RequestOptions.create( mContext ) ) {