Skip to content

Commit 1d92573

Browse files
committed
[bugfix] 修改邮问文字上限,添加header中的app版本号
1 parent 3f9ed33 commit 1d92573

File tree

9 files changed

+76
-24
lines changed

9 files changed

+76
-24
lines changed

build_logic/src/main/kotlin/versions/Dependencies.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@ val android = listOf(
6363
"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle",
6464
"androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle",
6565
"androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle",
66+
//解决PendingIntent对android12兼容问题
67+
"androidx.work:work-runtime-ktx:2.7.1",
6668
)
6769

68-
//"androidx.work:work-runtime-ktx:2.7.1",
70+
//,
6971

7072
// "androidx.navigation:navigation-runtime-ktx:2.4.1",
7173
// "androidx.navigation:navigation-fragment-ktx:2.4.1",

lib_common/src/main/java/com/mredrock/cyxbs/common/BaseApp.kt

+5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ abstract class BaseApp : Application() {
1212
companion object {
1313
lateinit var appContext: Context
1414
private set
15+
lateinit var version:String
16+
private set
1517
}
1618

1719
@CallSuper
1820
override fun onCreate() {
1921
super.onCreate()
2022
appContext = this
23+
appContext.packageManager.getPackageInfo(appContext.packageName,0).let {
24+
version = it.versionName
25+
}
2126
}
2227
}

lib_common/src/main/java/com/mredrock/cyxbs/common/network/ApiGenerator.kt

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.mredrock.cyxbs.common.network
22

3+
import android.app.Application
4+
import android.content.pm.PackageManager
35
import android.os.Handler
46
import android.util.SparseArray
57
import com.google.gson.Gson
@@ -23,6 +25,7 @@ import retrofit2.converter.gson.GsonConverterFactory
2325
import java.util.concurrent.TimeUnit
2426
import android.os.Looper
2527
import android.util.Log
28+
import androidx.core.content.PackageManagerCompat
2629
import com.mredrock.cyxbs.common.BaseApp
2730
import com.mredrock.cyxbs.common.utils.LogLocal
2831
import com.mredrock.cyxbs.common.utils.extensions.toast
@@ -150,13 +153,19 @@ object ApiGenerator {
150153
*/
151154
private fun Retrofit.Builder.configRetrofitBuilder(client: ((OkHttpClient.Builder) -> OkHttpClient)): Retrofit.Builder {
152155
return this.client(client.invoke(OkHttpClient().newBuilder().apply {
153-
val logging = HttpLoggingInterceptor(object:HttpLoggingInterceptor.Logger{
154-
override fun log(message: String) {
155-
Log.d("OKHTTP","OKHTTP$message")
156-
LogLocal.log("OKHTTP","OKHTTP$message")
157-
}
158-
})
156+
val logging = HttpLoggingInterceptor { message ->
157+
LogUtils.d("OKHTTP",message)
158+
LogLocal.log("OKHTTP", "OKHTTP$message")
159+
}
159160
logging.level = HttpLoggingInterceptor.Level.BODY
161+
addInterceptor(Interceptor {
162+
val response = proceedPoxyWithTryCatch {
163+
it.proceed(it.request().newBuilder()
164+
.addHeader("APPVersion", BaseApp.version)
165+
.build()
166+
)}
167+
response!!
168+
})
160169
addInterceptor(logging)
161170
//这里是在debug模式下方便开发人员简单确认 http 错误码 和 url(magipoke开始切的)
162171
if (BuildConfig.DEBUG){
@@ -194,6 +203,10 @@ object ApiGenerator {
194203
//不带token请求的OkHttp配置
195204
private fun OkHttpClient.Builder.configureCommonOkHttp(): OkHttpClient {
196205
return this.apply {
206+
/**
207+
* 发送版本号
208+
*/
209+
197210
/**
198211
* 连接失败时切换备用url的Interceptor
199212
* 一旦切换,只有重启app才能切回来(因为如果请求得到的url不是原来的@{link getBaseUrl()},则切换到新的url,而以后访问都用这个新的url了)
@@ -206,6 +219,17 @@ object ApiGenerator {
206219
//带token请求的OkHttp配置
207220
private fun OkHttpClient.Builder.configureTokenOkHttp(): OkHttpClient {
208221
return this.apply {
222+
/**
223+
* 发送版本号
224+
*/
225+
interceptors().add(Interceptor {
226+
val response = proceedPoxyWithTryCatch {
227+
it.proceed(it.request().newBuilder()
228+
.addHeader("version", BaseApp.version)
229+
.build()
230+
)}
231+
return@Interceptor response!!
232+
})
209233
/**
210234
* 连接失败时切换备用url的Interceptor
211235
* 一旦切换,只有重启app才能切回来(因为如果请求得到的url不是原来的@{link getBaseUrl()},则切换到新的url,而以后访问都用这个新的url了)

module_qa/src/main/java/com/mredrock/cyxbs/qa/pages/quiz/ui/QuizActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class QuizActivity : BaseViewModelActivity<QuizViewModel>() {
5050

5151
companion object {
5252
// 允许发送动态的最大字数
53-
const val MAX_CONTENT_SIZE = 500
53+
const val MAX_CONTENT_SIZE = 1000
5454
const val MAX_SELECTABLE_IMAGE_COUNT = 8
5555
const val NOT_DRAFT = "0"
5656
const val UPDATE_DRAFT = "1"

module_qa/src/main/res/values/strings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<string name="qa_unfollow_circle" translatable="false">取消关注圈子成功</string>
8080
<string name="qa_draft_dialog_no_save" translatable="false">不保存</string>
8181
<string name="qa_draft_dialog_cancel" translatable="false">取消</string>
82-
<string name="qa_edit_dynamic_num" translatable="false">0/500</string>
82+
<string name="qa_edit_dynamic_num" translatable="false">0/1000</string>
8383
<string name="qa_choose_one_circle" translatable="false">请选择一个圈子</string>
8484
<string name="qa_dynamic_recommend" translatable="false">推荐</string>
8585
<string name="qa_my_follow_circle" translatable="false">我的关注</string>

module_schoolcar/src/main/java/com/mredrock/cyxbs/discover/schoolcar/SchoolCarActivity.kt

+12-6
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,19 @@ class SchoolCarActivity : BaseActivity(), View.OnClickListener {
9393
aMap.animateCamera(update)
9494
}
9595
cv_positioning -> {
96-
val update =
97-
if (aMap.myLocation.longitude != 0.0 || aMap.myLocation.latitude !== 0.0){
98-
CameraUpdateFactory.newLatLngZoom(LatLng(aMap.myLocation.latitude, aMap.myLocation.longitude), 17f)
99-
}else{
100-
CameraUpdateFactory.newLatLngZoom(LatLng(29.531876, 106.606789), 17f)
96+
aMap.myLocation?.let { location->
97+
location.longitude?.let {
98+
location.latitude?.let {
99+
val update =
100+
if (aMap.myLocation.longitude != 0.0 || aMap.myLocation.latitude !== 0.0){
101+
CameraUpdateFactory.newLatLngZoom(LatLng(aMap.myLocation.latitude, aMap.myLocation.longitude), 17f)
102+
}else{
103+
CameraUpdateFactory.newLatLngZoom(LatLng(29.531876, 106.606789), 17f)
104+
}
105+
aMap.animateCamera(update)
106+
}
107+
}
101108
}
102-
aMap.animateCamera(update)
103109
}
104110
iv_cooperation_logo -> {
105111
val intent = Intent()

module_schoolcar/src/main/java/com/mredrock/cyxbs/discover/schoolcar/widget/SchoolCarsSmoothMove.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class SchoolCarsSmoothMove(private val schoolCarActivity: SchoolCarActivity?, pr
5656
val latLng = LatLng(data.lat,data.lon)
5757
val marker = buildMarker(data.id,data.type,latLng)
5858
marker?.let { marker ->
59-
carMap[data.id] = SchoolCar(data.id,data.type,data.upDate,data.upDate,MovingPointOverlay(schoolCarActivity?.aMap,marker),marker,mutableListOf(latLng),getPolyline(data.type,latLng))
59+
val smoothMarker = MovingPointOverlay(schoolCarActivity?.aMap,marker)
60+
carMap[data.id] = SchoolCar(data.id,data.type,data.upDate,data.upDate,smoothMarker,marker,mutableListOf(latLng,smoothMarker.position),getPolyline(data.type,latLng))
6061
}
61-
carMap[data.id]?.let { car -> smoothMove(car) }
6262
}else{
6363
//这里因为轮询是1s一次,所以说判断一下更新的时间,
6464
if(carMap[data.id]?.upDate != data.upDate){
@@ -92,10 +92,10 @@ class SchoolCarsSmoothMove(private val schoolCarActivity: SchoolCarActivity?, pr
9292
}
9393

9494
private fun smoothMove(car:SchoolCar, mistime:Int = 3) {
95-
if (car.latLngList.size > 4) {
95+
if (car.latLngList.size > 3) {
9696
//停止上一次的移动,然后将上一次的位置加上之后再移动
9797
car.smoothMarker.stopMove()
98-
val list = car.latLngList.subList(car.latLngList.size - 3, car.latLngList.size)
98+
val list = car.latLngList.subList(car.latLngList.size - 2, car.latLngList.size)
9999
list[0] = car.smoothMarker.position
100100
val smoothMarker = MovingPointOverlay(schoolCarActivity?.aMap,car.marker)
101101
smoothMarker.setPoints(list)

module_todo/src/main/java/com/cyxbsmobile_single/module_todo/ui/widget/TodoWidget.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ class TodoWidget : AppWidgetProvider() {
111111
private fun getPendingIntentFlags(isMutable: Boolean = false) =
112112
when {
113113
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
114-
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
115-
114+
PendingIntent.FLAG_MUTABLE
115+
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
116+
PendingIntent.FLAG_IMMUTABLE
117+
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
118+
PendingIntent.FLAG_UPDATE_CURRENT
116119
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
117-
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
118-
120+
PendingIntent.FLAG_UPDATE_CURRENT
119121
else -> PendingIntent.FLAG_UPDATE_CURRENT
120122
}
121123
}

module_widget/src/main/java/com/mredrock/cyxbs/widget/util/Util.kt

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager
55
import android.content.Context
66
import android.content.Intent
77
import android.net.Uri
8+
import android.os.Build
89
import android.os.Bundle
910
import android.widget.Toast
1011
import androidx.annotation.IdRes
@@ -182,7 +183,7 @@ fun getClickIntent(context: Context, widgetId: Int, viewId: Int, requestCode: In
182183
//放进需要设置的viewId
183184
bundle.putInt("Button", viewId)
184185
i.putExtras(bundle)
185-
return PendingIntent.getBroadcast(context, requestCode, i, PendingIntent.FLAG_UPDATE_CURRENT)
186+
return PendingIntent.getBroadcast(context, requestCode, i,getPendingIntentFlags())
186187
}
187188

188189
fun formatTime(calendar: Calendar): String {
@@ -229,3 +230,15 @@ fun startOperation(dataBean: WidgetCourse.DataBean) {
229230
EventBus.getDefault().postSticky(WidgetCourseEvent(mutableListOf(dataBean)))
230231
}
231232
}
233+
private fun getPendingIntentFlags(isMutable: Boolean = false) =
234+
when {
235+
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
236+
PendingIntent.FLAG_MUTABLE
237+
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
238+
PendingIntent.FLAG_IMMUTABLE
239+
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
240+
PendingIntent.FLAG_UPDATE_CURRENT
241+
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
242+
PendingIntent.FLAG_UPDATE_CURRENT
243+
else -> PendingIntent.FLAG_UPDATE_CURRENT
244+
}

0 commit comments

Comments
 (0)