From da12cd34a1dd81669dded5d1487dcea2ea769fd2 Mon Sep 17 00:00:00 2001 From: perol Date: Sat, 1 May 2021 17:52:56 +0800 Subject: [PATCH] upgrade lib --- android/app/build.gradle | 13 +-- .../kotlin/com/perol/pixez/CardAppWidget.kt | 9 -- .../example_appwidget_preview.png | Bin 3522 -> 0 bytes .../app/src/main/res/drawable/ic_search.xml | 10 --- android/build.gradle | 6 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- lib/models/error_message.dart | 48 ++++------- lib/network/api_client.dart | 2 +- lib/network/refresh_token_interceptor.dart | 77 ++++++++++-------- lib/page/splash/splash_store.dart | 2 - 10 files changed, 66 insertions(+), 105 deletions(-) delete mode 100644 android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png delete mode 100644 android/app/src/main/res/drawable/ic_search.xml diff --git a/android/app/build.gradle b/android/app/build.gradle index a0d9cada9..0f1152489 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -69,7 +69,6 @@ println(packageName) apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" -apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 30 @@ -116,19 +115,13 @@ flutter { } dependencies { - implementation project(":weiss") - implementation 'androidx.webkit:webkit:1.3.0' - +// implementation project(":weiss") + implementation 'androidx.webkit:webkit:1.4.0' implementation 'com.github.bumptech.glide:glide:4.11.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' - implementation "androidx.browser:browser:1.3.0" - - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9' implementation('com.waynejo:androidndkgif:0.3.3') implementation 'androidx.preference:preference-ktx:1.1.1' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.google.android.play:core:1.9.1' - implementation 'com.google.android.gms:play-services-wallet:18.1.2' + implementation 'com.google.android.play:core:1.10.0' } diff --git a/android/app/src/main/kotlin/com/perol/pixez/CardAppWidget.kt b/android/app/src/main/kotlin/com/perol/pixez/CardAppWidget.kt index 6394e33d2..4a6c3ff4d 100644 --- a/android/app/src/main/kotlin/com/perol/pixez/CardAppWidget.kt +++ b/android/app/src/main/kotlin/com/perol/pixez/CardAppWidget.kt @@ -21,9 +21,7 @@ import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider import android.content.Context import android.content.Intent -import android.content.SharedPreferences import android.graphics.Bitmap -import android.util.Log import android.widget.RemoteViews import com.bumptech.glide.Glide import com.bumptech.glide.load.model.GlideUrl @@ -32,15 +30,8 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.SimpleTarget import com.bumptech.glide.request.transition.Transition -import io.flutter.embedding.engine.FlutterEngine -import io.flutter.embedding.engine.dart.DartExecutor -import io.flutter.plugin.common.MethodChannel -import io.flutter.view.FlutterCallbackInformation -import io.flutter.view.FlutterMain -import org.json.JSONArray import org.json.JSONObject - /** * Implementation of App Widget functionality. */ diff --git a/android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png b/android/app/src/main/res/drawable-nodpi/example_appwidget_preview.png deleted file mode 100644 index 894b069a4907d258f60b1b2406b90f5a0fe1c35b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3522 zcmaJ^3piA3_a6@xDwm_1J~1d=T*eGD7*t{~G6s#392#aYX)b2QC2|g;(n0D}E^|`S zMRLit5fgHkOAh7IFc`OL+?mN`#$lds_TJBqcXqPd zF27eE1OjbG+uOJTvj{kk%Sr>+x% z-dKicf&VgL23l(Uhm za0C)&0{;8Z0;16gen?jv+rMK0nx$3%lSxBDAfch52BAg zOB5zPOrOHg{*GWnWcboaG$x5k0dFAUeW<}qOD%xue^MaR{(+@1{w@At|m`Dt&2q9Lv6L_Cv9$5E*l zzgN*YfXbvY0;n{w^(h4S5C-o{qHHW2{>uY{L82)PCZ6I;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OCQ^b#rmU}ek9psrNQGMkGbI&~*C-q1L99(zUq3Rx()X0c@?IJ&&rG-8%PYK_BT zioWVRYkGIbx(&bRdvXD?6`WC^{Bwzda2}(c(;-*nZ~6Po4{u8XiLNF*ioaKzz|Ks_fA2lAfZj2#@RD&W8=Ic8TXhtz zH4ySPqp12#TjW$P&gKSr3F9NAX~q?GVB9dgP=z z=~AAO7Zfc2x%Xc#wl79rhmphteq)!~{bMo}q@uCpxB4uj$GtHh>UW*Y`@Km$szVgV zekHhd(d-09_Oy0?AsPAW@iD5Sf}z(~+0G|Dw@$ztzO_aYyoj@=;w6EOm!1P&YIdt%(lZ$xySfS5(>-u>Iw(!y;jb6o@s4CS zpYJ~wq{O-~ibyMYI?74do*wP{u5#veF83tLh4i`oU<1ZE-qDFsP=8`qOhlDTS00+i zuY2BgR~qY8m)rU0hZGkTeXie5R%}EKCZ-l!Xy@UI8<3f&On)5kQkXj;zOVB+{YCwY z0uq}jU$TV@mOmh&4WxGNd~kNpe7;FcHA0xLtkUY{uNI+AX?t>E*txqQ?}&?`S<8r% z`1zGx%qDA-dmcHJA!m96Vlg+|v0dz&gp60C=7_X=$Di1skjBY%YP#J#&rMq62^p&g z)e{tBY6B;0D-0dI9&CPgJuGrkpI7)~KLJTOgDbX-%Q`ajG=9;e{{8r!9&Sju*_XP7 zLw}s(c8`=<-3{wepo!HGY4dD5V?0$_KQ609v`;7dW~~eQ5FhcN&a_F}R4>IoJ|NoGNa5|5PbYeyQ7DPw|>ER*)1m8dQ+n9i{Sh;i?~UqNls^ zXIO7yN`hMZwu6oBWy~YDcHA|^I`Nx$TfH>1{`dD@%u`>NHw1Ou%eRZ-1}ty - - diff --git a/android/build.gradle b/android/build.gradle index 023047718..0e651c8a6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -15,7 +15,7 @@ */ buildscript { - ext.kotlin_version = '1.4.21' + ext.kotlin_version = '1.4.32' repositories { maven { url 'https://maven.aliyun.com/repository/public/' } @@ -27,8 +27,8 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.6.3' - classpath 'com.google.gms:google-services:4.3.4' + classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.google.gms:google-services:4.3.5' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index cf4d2c2eb..917602163 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jul 22 20:02:16 CST 2020 +#Sat May 01 17:18:32 CST 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/lib/models/error_message.dart b/lib/models/error_message.dart index e6362b94c..a64820619 100644 --- a/lib/models/error_message.dart +++ b/lib/models/error_message.dart @@ -13,8 +13,10 @@ * this program. If not, see . * */ -import 'dart:convert' show json; +import 'package:json_annotation/json_annotation.dart'; +part 'error_message.g.dart'; +@JsonSerializable() class ErrorMessage { Error error; @@ -22,49 +24,27 @@ class ErrorMessage { required this.error, }); - factory ErrorMessage.fromJson(jsonRes) => ErrorMessage( - error: Error.fromJson(jsonRes['error']), - ); + factory ErrorMessage.fromJson(Map json) => + _$ErrorMessageFromJson(json); - Map toJson() => { - 'error': error, - }; - - @override - String toString() { - return json.encode(this); - } + Map toJson() => _$ErrorMessageToJson(this); } +@JsonSerializable() class Error { - String user_message; - String message; - String reason; - Object user_message_details; + String? user_message; + String? message; + String? reason; + Object? user_message_details; Error({ required this.user_message, required this.message, required this.reason, - required this.user_message_details, + this.user_message_details, }); - factory Error.fromJson(jsonRes) => Error( - user_message: jsonRes['user_message'], - message: jsonRes['message'], - reason: jsonRes['reason'], - user_message_details: jsonRes['user_message_details'], - ); - - Map toJson() => { - 'user_message': user_message, - 'message': message, - 'reason': reason, - 'user_message_details': user_message_details, - }; + factory Error.fromJson(Map json) => _$ErrorFromJson(json); - @override - String toString() { - return json.encode(this); - } + Map toJson() => _$ErrorToJson(this); } diff --git a/lib/network/api_client.dart b/lib/network/api_client.dart index e6809d506..9d874cdb2 100644 --- a/lib/network/api_client.dart +++ b/lib/network/api_client.dart @@ -57,7 +57,7 @@ class ApiClient { String time = getIsoDate(); if (isBookmark) { httpClient = Dio(apiClient.httpClient.options) - // ..interceptors.add(LogInterceptor(responseBody: true, requestBody: true)) + ..interceptors.add(LogInterceptor(responseBody: true, requestBody: true)) ..interceptors.add(RefreshTokenInterceptor()); (httpClient.httpClientAdapter as DefaultHttpClientAdapter) .onHttpClientCreate = (client) { diff --git a/lib/network/refresh_token_interceptor.dart b/lib/network/refresh_token_interceptor.dart index a2f719575..ea62439e3 100644 --- a/lib/network/refresh_token_interceptor.dart +++ b/lib/network/refresh_token_interceptor.dart @@ -15,11 +15,8 @@ */ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; - import 'package:dio/dio.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:pixez/main.dart'; import 'package:pixez/models/account.dart'; import 'package:pixez/models/error_message.dart'; @@ -72,39 +69,51 @@ class RefreshTokenInterceptor extends InterceptorsWrapper { if (err.response != null && err.response!.statusCode == 400) { DateTime dateTime = DateTime.now(); if ((dateTime.millisecondsSinceEpoch - lastRefreshTime) > 200000) { - apiClient.httpClient.interceptors.errorLock.lock(); - print("lock start ========================"); try { - ErrorMessage errorMessage = ErrorMessage.fromJson(err.response!.data); - if (errorMessage.error.message.contains("OAuth") && - accountStore.now != null) { - final client = OAuthClient(); - AccountPersist accountPersist = accountStore.now!; - Response response1 = await client.postRefreshAuthToken( - refreshToken: accountPersist.refreshToken, - deviceToken: accountPersist.deviceToken); - AccountResponse accountResponse = - Account.fromJson(response1.data).response; - final user = accountResponse.user; - accountStore.updateSingle(AccountPersist( - userId: user.id, - userImage: user.profileImageUrls.px170x170, - accessToken: accountResponse.accessToken, - refreshToken: accountResponse.refreshToken, - deviceToken: "", - passWord: "no more", - name: user.name, - account: user.account, - mailAddress: user.mailAddress, - isPremium: bti(user.isPremium), - xRestrict: user.xRestrict, - isMailAuthorized: bti(user.isMailAuthorized), - id: accountPersist.id)); - lastRefreshTime = DateTime.now().millisecondsSinceEpoch; + if (err.response!.statusCode == HttpStatus.badRequest) { + apiClient.httpClient.interceptors.errorLock.lock(); + print("lock start ========================"); + ErrorMessage errorMessage = + ErrorMessage.fromJson(err.response!.data); + if (errorMessage.error.message!.contains("OAuth") && + accountStore.now != null) { + final client = OAuthClient(); + AccountPersist accountPersist = accountStore.now!; + Response response1 = await client.postRefreshAuthToken( + refreshToken: accountPersist.refreshToken, + deviceToken: accountPersist.deviceToken); + AccountResponse accountResponse = + Account.fromJson(response1.data).response; + final user = accountResponse.user; + accountStore.updateSingle(AccountPersist( + userId: user.id, + userImage: user.profileImageUrls.px170x170, + accessToken: accountResponse.accessToken, + refreshToken: accountResponse.refreshToken, + deviceToken: "", + passWord: "no more", + name: user.name, + account: user.account, + mailAddress: user.mailAddress, + isPremium: bti(user.isPremium), + xRestrict: user.xRestrict, + isMailAuthorized: bti(user.isMailAuthorized), + id: accountPersist.id)); + lastRefreshTime = DateTime.now().millisecondsSinceEpoch; + apiClient.httpClient.interceptors.errorLock.unlock(); + print("unlock ========================"); + } else if (errorMessage.error.message!.contains("Limit")) { + lastRefreshTime = 0; + apiClient.httpClient.interceptors.errorLock.unlock(); + print("unlock ========================"); + return handler.reject(err); + } else { + lastRefreshTime = 0; + apiClient.httpClient.interceptors.errorLock.unlock(); + print("unlock ========================"); + return handler.reject(err); + } } - if (errorMessage.error.message.contains("Limit")) {} - apiClient.httpClient.interceptors.errorLock.unlock(); - print("unlock ========================"); } catch (e) { print(e); lastRefreshTime = 0; diff --git a/lib/page/splash/splash_store.dart b/lib/page/splash/splash_store.dart index 21d764ac9..9f0579783 100644 --- a/lib/page/splash/splash_store.dart +++ b/lib/page/splash/splash_store.dart @@ -14,8 +14,6 @@ * */ -import 'dart:math'; - import 'package:mobx/mobx.dart'; import 'package:pixez/component/pixiv_image.dart'; import 'package:pixez/er/hoster.dart';