Przeglądaj źródła

1.添加新版首页module

王鹏鹏 2 lat temu
rodzic
commit
fc9069da74

+ 2 - 2
baselib/build.gradle

@@ -38,7 +38,7 @@ android {
             buildConfigField "String", "BAIDU_SECRETKEY", "\"4AfYdqAyA9PtLOoNFFsyUogDfxoMBmqS\""
             buildConfigField "Boolean", "SINGLE_MODULE", "${singleModule}"
             buildConfigField "String", "BUGLY_APPID", "\"d400f20398\""
-            buildConfigField "String", "API_URL", "\"http://60.205.201.7:8110\""
+            buildConfigField "String", "API_URL", "\"http://192.168.0.120:8110\""
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
 
@@ -52,7 +52,7 @@ android {
             buildConfigField "String", "BAIDU_SECRETKEY", "\"4AfYdqAyA9PtLOoNFFsyUogDfxoMBmqS\""
             buildConfigField "Boolean", "SINGLE_MODULE", "${singleModule}"
             buildConfigField "String", "BUGLY_APPID", "\"ad3db4d529\""
-            buildConfigField "String", "API_URL", "\"http://60.205.201.7:8110\""
+            buildConfigField "String", "API_URL", "\"http://192.168.0.120:8110\""
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }

+ 4 - 1
baselib/src/main/java/com/yingyangfly/baselib/config/AccountConfig.kt

@@ -40,5 +40,8 @@ object AccountConfig {
     const val BAIDU_APPKEY = BuildConfig.BAIDU_APPKEY
     const val BAIDU_SECRETKEY = BuildConfig.BAIDU_SECRETKEY
 
-
+    /**
+     * 接口请求地址
+     */
+    const val API_URL = BuildConfig.API_URL
 }

+ 11 - 0
baselib/src/main/java/com/yingyangfly/baselib/net/ApiService.kt

@@ -0,0 +1,11 @@
+package com.yingyangfly.baselib.net
+
+/**
+ * Author: Austin
+ * Date: 2018/10/9
+ * Description:
+ */
+
+interface ApiService {
+
+}

+ 79 - 0
baselib/src/main/java/com/yingyangfly/baselib/net/convert/XlGsonConverterFactory.java

@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2015 Square, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.yingyangfly.baselib.net.convert;
+
+import com.google.gson.Gson;
+import com.google.gson.TypeAdapter;
+import com.google.gson.reflect.TypeToken;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
+import retrofit2.Converter;
+import retrofit2.Retrofit;
+
+/**
+ * A {@linkplain Converter.Factory converter} which uses Gson for JSON.
+ *
+ * <p>Because Gson is so flexible in the types it supports, this converter assumes that it can
+ * handle all types. If you are mixing JSON serialization with something else (such as protocol
+ * buffers), you must {@linkplain Retrofit.Builder#addConverterFactory(Converter.Factory) add this
+ * instance} last to allow the other converters a chance to see their types.
+ */
+public final class XlGsonConverterFactory extends Converter.Factory {
+    /**
+     * Create an instance using a default {@link Gson} instance for conversion. Encoding to JSON and
+     * decoding from JSON (when no charset is specified by a header) will use UTF-8.
+     */
+    public static XlGsonConverterFactory create() {
+        return create(new Gson());
+    }
+
+    /**
+     * Create an instance using {@code gson} for conversion. Encoding to JSON and decoding from JSON
+     * (when no charset is specified by a header) will use UTF-8.
+     */
+    @SuppressWarnings("ConstantConditions") // Guarding public API nullability.
+    public static XlGsonConverterFactory create(Gson gson) {
+        if (gson == null) throw new NullPointerException("gson == null");
+        return new XlGsonConverterFactory(gson);
+    }
+
+    private final Gson gson;
+
+    private XlGsonConverterFactory(Gson gson) {
+        this.gson = gson;
+    }
+
+    @Override
+    public Converter<ResponseBody, ?> responseBodyConverter(
+            Type type, Annotation[] annotations, Retrofit retrofit) {
+        TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
+        return new XlGsonResponseBodyConverter<>(gson, adapter);
+    }
+
+    @Override
+    public Converter<?, RequestBody> requestBodyConverter(
+            Type type,
+            Annotation[] parameterAnnotations,
+            Annotation[] methodAnnotations,
+            Retrofit retrofit) {
+        TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
+        return new XlGsonRequestBodyConverter<>(gson, adapter);
+    }
+}

+ 53 - 0
baselib/src/main/java/com/yingyangfly/baselib/net/convert/XlGsonRequestBodyConverter.java

@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2015 Square, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.yingyangfly.baselib.net.convert;
+
+import com.google.gson.Gson;
+import com.google.gson.TypeAdapter;
+import com.google.gson.stream.JsonWriter;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
+
+import okhttp3.MediaType;
+import okhttp3.RequestBody;
+import okio.Buffer;
+import retrofit2.Converter;
+
+final class XlGsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
+    private static final MediaType MEDIA_TYPE = MediaType.get("application/json; charset=UTF-8");
+    private static final Charset UTF_8 = Charset.forName("UTF-8");
+
+    private final Gson gson;
+    private final TypeAdapter<T> adapter;
+
+    XlGsonRequestBodyConverter(Gson gson, TypeAdapter<T> adapter) {
+        this.gson = gson;
+        this.adapter = adapter;
+    }
+
+    @Override
+    public RequestBody convert(T value) throws IOException {
+        Buffer buffer = new Buffer();
+        Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
+        JsonWriter jsonWriter = gson.newJsonWriter(writer);
+        adapter.write(jsonWriter, value);
+        jsonWriter.close();
+        return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
+    }
+}

+ 59 - 0
baselib/src/main/java/com/yingyangfly/baselib/net/convert/XlGsonResponseBodyConverter.java

@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2015 Square, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.yingyangfly.baselib.net.convert;
+
+import com.google.gson.Gson;
+import com.google.gson.TypeAdapter;
+import com.yingyangfly.baselib.net.BaseBean;
+import com.yingyangfly.baselib.utils.GsonUtil;
+
+import java.io.IOException;
+
+import okhttp3.ResponseBody;
+import retrofit2.Converter;
+
+/**
+ * @author: gold
+ * @time: 2021/12/16 下午1:34
+ * @description: 自定义GsonResponseBodyConverter 处理响应码不为200时,data解析处理
+ * @copyright (C) 2019-2021, XiaoLiu All Rights Reserved
+ */
+final class XlGsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
+    private final Gson gson;
+    private final TypeAdapter<T> adapter;
+
+    XlGsonResponseBodyConverter(Gson gson, TypeAdapter<T> adapter) {
+        this.gson = gson;
+        this.adapter = adapter;
+    }
+
+    @Override
+    public T convert(ResponseBody value) throws IOException {
+        String strJsong = value.string();
+        try {
+            BaseBean bean;
+            bean = gson.fromJson(strJsong, BaseBean.class);
+            if (bean.getErrcode() != 200) {
+                strJsong = GsonUtil.GsonString(bean);
+            }
+            T result = adapter.fromJson(strJsong);
+            return result;
+        } finally {
+            value.close();
+        }
+    }
+
+}

+ 8 - 5
workbenches/src/main/java/com/yingyang/workbenches/WorkbenchesActivity.kt

@@ -214,11 +214,14 @@ class WorkbenchesActivity : BaseMVVMActivity<ActivityWorkbenchesBinding, Workben
                     taskAdapter.setCurrentTaskNum(it.currentTaskNum)
                     taskAdapter.setData(taskList)
                     if (it.currentTaskNum == it.totalTaskNum) {
-                        if (TextUtils.equals(User.getNowDay(), User.getTaskDialogStatus()).not()) {
-                            User.saveTaskDialogStatus(User.getNowDay())
-                            showTipDialog()
-                        } else {
-                            showGameList()
+                        if (TextUtils.equals("0", it.status)) {
+                            //任务完成
+                            if (TextUtils.equals(User.getNowDay(), User.getTaskDialogStatus()).not()) {
+                                User.saveTaskDialogStatus(User.getNowDay())
+                                showTipDialog()
+                            } else {
+                                showGameList()
+                            }
                         }
                     } else {
                         if (TextUtils.equals(User.getNowDay(), User.getTaskDialogStatus()).not()) {