Browse Source

change download method

yanyi 6 years ago
parent
commit
46c7e227e7

+ 6 - 6
app/build.gradle

@@ -1,11 +1,11 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 26
+    compileSdkVersion 28
     defaultConfig {
         applicationId "com.mylove.okhttp"
         minSdkVersion 15
-        targetSdkVersion 26
+        targetSdkVersion 28
         versionCode 1
         versionName "1.0"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -26,10 +26,10 @@ android {
 
 dependencies {
     implementation fileTree(include: ['*.jar'], dir: 'libs')
-    implementation 'com.android.support:appcompat-v7:26.1.0'
+    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
     testImplementation 'junit:junit:4.12'
-    androidTestImplementation 'com.android.support.test:runner:1.0.1'
-    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
-    compile project(':okhttplib')
+    androidTestImplementation 'com.android.support.test:runner:1.0.2'
+    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
+    implementation project(':okhttplib')
     implementation 'com.yanyi.benyanyi:loglib:1.0.0'
 }

+ 44 - 1
app/src/main/java/com/mylove/okhttp/MainActivity.java

@@ -1,8 +1,10 @@
 package com.mylove.okhttp;
 
 import android.os.Bundle;
+import android.os.Environment;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
+import android.util.Log;
 
 
 /**
@@ -22,6 +24,47 @@ public class MainActivity extends AppCompatActivity {
     }
 
     private void init() {
-        OkHttpInfo.soapDataTopString="";
+        OkHttpInfo.soapDataTopString = "";
+        String url = "http://www.yanyi.red/bluetooth/dfu_pkg0904.zip";
+        String filePath = Environment.getExternalStorageDirectory().toString() + "/dectector/dfu/";
+        OkHttpUtil.getInstance(this).downloadFile(url).download(filePath, new OnDownloadListener() {
+            @Override
+            public void onDownloading(int progress) {
+                Log.d("进度", progress + "");
+            }
+
+            @Override
+            public void onCompleted() {
+
+            }
+
+            @Override
+            public <T> void onSuccess(T message) {
+
+            }
+
+            @Override
+            public void onFailure(Throwable t) {
+
+            }
+        });
+//        val url = "http://www.yanyi.red/bluetooth/dfu_pkg0904.zip"
+//        val filePath = Environment.getExternalStorageDirectory().toString() + "/dectector/dfu/"
+//        OkHttpUtil.getInstance(mContext).downloadFile(url).download(filePath, object : OnDownloadListener {
+//            override fun <String : Any?> onSuccess(message: String) {
+//                JLog.v("路径$message")
+//            }
+//
+//            override fun onFailure(t: Throwable?) {
+//                JLog.e(t!!.message)
+//            }
+//
+//            override fun onDownloading(progress: Int) {
+//                JLog.d("下载进度$progress%")
+//            }
+//
+//            override fun onCompleted() {
+//            }
+//        })
     }
 }

+ 2 - 2
build.gradle

@@ -7,9 +7,9 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.0.1'
+        classpath 'com.android.tools.build:gradle:3.1.4'
         classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
-        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.2'
+        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.3'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files

+ 2 - 2
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,6 @@
-#Thu Nov 16 17:33:07 CST 2017
+#Tue Sep 11 17:19:33 CST 2018
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

+ 1 - 1
okhttplib/bintrayUpload.gradle

@@ -7,7 +7,7 @@ def siteUrl = 'https://github.com/BenYanYi/OkHttp' // 项目主页。
 def gitUrl = 'https://github.com/BenYanYi/OkHttp.git' // Git仓库的url。
 
 group = "com.yanyi.benyanyi"// 唯一包名,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的com.ansen.http就是这里配置的。
-version = "1.0.3"//项目引用的版本号,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的1.0.1就是这里配置的。
+version = "1.0.4"//项目引用的版本号,比如compile 'com.ansen.http:okhttpencapsulation:1.0.1'中的1.0.1就是这里配置的。
 install {
     repositories.mavenInstaller {
         // This generates POM.xml with proper parameters

+ 3 - 4
okhttplib/build.gradle

@@ -1,13 +1,13 @@
 apply plugin: 'com.android.library'
 
 android {
-    compileSdkVersion 26
+    compileSdkVersion 28
 
 
 
     defaultConfig {
         minSdkVersion 14
-        targetSdkVersion 26
+        targetSdkVersion 28
         versionCode 1
         versionName "1.0"
 
@@ -25,7 +25,7 @@ android {
 
 dependencies {
     implementation fileTree(include: ['*.jar'], dir: 'libs')
-    implementation 'com.android.support:appcompat-v7:26.1.0'
+    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
@@ -36,7 +36,6 @@ dependencies {
     implementation 'io.reactivex.rxjava2:rxjava:2.1.4'
     implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
     implementation 'com.google.code.gson:gson:2.8.5'
-    implementation files('lib/android-xml-json.jar')
     implementation 'com.squareup.retrofit2:retrofit:2.4.0'
 }
 apply from: 'bintrayUpload.gradle'

BIN
okhttplib/lib/android-xml-json.jar


+ 10 - 10
okhttplib/src/main/java/com/mylove/okhttp/AutoRequest.java

@@ -35,19 +35,19 @@ public class AutoRequest {
         ObservableRequest.getInstance(mContext, requestType, CallType.SYNC).request(url, oMap, onOkHttpListener);
     }
 
-    public <T> void sync(Map<Object, Object> oMap, Class<T> tClass, onOkHttpListener onOkHttpListener) {
-        ObservableRequests request = ObservableRequests.getInstance(mContext, requestType, CallType.SYNC);
-        request.tClass = tClass;
-        request.request(url, oMap, onOkHttpListener);
-    }
+//    public <T> void sync(Map<Object, Object> oMap, Class<T> tClass, onOkHttpListener onOkHttpListener) {
+//        ObservableRequests request = ObservableRequests.getInstance(mContext, requestType, CallType.SYNC);
+//        request.tClass = tClass;
+//        request.request(url, oMap, onOkHttpListener);
+//    }
 
     public void async(Map<Object, Object> oMap, onOkHttpListener onOkHttpListener) {
         ObservableRequest.getInstance(mContext, requestType, CallType.ASYNC).request(url, oMap, onOkHttpListener);
     }
 
-    public <T> void async(Map<Object, Object> oMap, Class<T> tClass, onOkHttpListener onOkHttpListener) {
-        ObservableRequests request = ObservableRequests.getInstance(mContext, requestType, CallType.ASYNC);
-        request.tClass = tClass;
-        request.request(url, oMap, onOkHttpListener);
-    }
+//    public <T> void async(Map<Object, Object> oMap, Class<T> tClass, onOkHttpListener onOkHttpListener) {
+//        ObservableRequests request = ObservableRequests.getInstance(mContext, requestType, CallType.ASYNC);
+//        request.tClass = tClass;
+//        request.request(url, oMap, onOkHttpListener);
+//    }
 }

+ 6 - 6
okhttplib/src/main/java/com/mylove/okhttp/ObservableRequests.java

@@ -7,8 +7,6 @@ import android.util.Log;
 
 import com.google.gson.Gson;
 
-import org.json.XML;
-
 import java.io.File;
 import java.io.IOException;
 import java.util.Map;
@@ -151,7 +149,7 @@ class ObservableRequests<T> {
                 if ((str.substring(0, 1).equals("<") || str.substring(0, 1).equals("["))
                         && (str.substring(1, 2).equals("\"") || str.substring(1, 2).equals("["))) {
                     try {
-                        str = XML.toJSONObject(str).toString();
+                        subscriber.onNext((T) str);
                     } catch (Exception e) {
                         e.printStackTrace();
                     }
@@ -160,9 +158,10 @@ class ObservableRequests<T> {
                             CacheUtils.getInstance(mContext).setCacheToLocalJson(mCacheUrl, str);
                         }
                     }
+                } else {
+                    T t = new Gson().fromJson(str, tClass);
+                    subscriber.onNext(t);
                 }
-                T t = new Gson().fromJson(str, tClass);
-                subscriber.onNext(t);
             } else {
                 String json = CacheUtils.getInstance(mContext).getCacheToLocalJson(mCacheUrl);
                 if (FormatUtil.isNotEmpty(json)) {
@@ -211,7 +210,8 @@ class ObservableRequests<T> {
                 if ((str.substring(0, 1).equals("<") || str.substring(0, 1).equals("["))
                         && (str.substring(1, 2).equals("\"") || str.substring(1, 2).equals("["))) {
                     try {
-                        str = XML.toJSONObject(str).toString();
+                        //问题
+//                        str = XML.toJSONObject(str).toString();
                     } catch (Exception e) {
                         e.printStackTrace();
                     }