Skip to content

Commit

Permalink
[bugfix] 修改邮问文字上限,添加header中的app版本号
Browse files Browse the repository at this point in the history
  • Loading branch information
owliao committed Apr 13, 2022
1 parent 3f9ed33 commit 1d92573
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 24 deletions.
4 changes: 3 additions & 1 deletion build_logic/src/main/kotlin/versions/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ val android = listOf(
"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle",
"androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle",
"androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle",
//解决PendingIntent对android12兼容问题
"androidx.work:work-runtime-ktx:2.7.1",
)

//"androidx.work:work-runtime-ktx:2.7.1",
//,

// "androidx.navigation:navigation-runtime-ktx:2.4.1",
// "androidx.navigation:navigation-fragment-ktx:2.4.1",
Expand Down
5 changes: 5 additions & 0 deletions lib_common/src/main/java/com/mredrock/cyxbs/common/BaseApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ abstract class BaseApp : Application() {
companion object {
lateinit var appContext: Context
private set
lateinit var version:String
private set
}

@CallSuper
override fun onCreate() {
super.onCreate()
appContext = this
appContext.packageManager.getPackageInfo(appContext.packageName,0).let {
version = it.versionName
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mredrock.cyxbs.common.network

import android.app.Application
import android.content.pm.PackageManager
import android.os.Handler
import android.util.SparseArray
import com.google.gson.Gson
Expand All @@ -23,6 +25,7 @@ import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
import android.os.Looper
import android.util.Log
import androidx.core.content.PackageManagerCompat
import com.mredrock.cyxbs.common.BaseApp
import com.mredrock.cyxbs.common.utils.LogLocal
import com.mredrock.cyxbs.common.utils.extensions.toast
Expand Down Expand Up @@ -150,13 +153,19 @@ object ApiGenerator {
*/
private fun Retrofit.Builder.configRetrofitBuilder(client: ((OkHttpClient.Builder) -> OkHttpClient)): Retrofit.Builder {
return this.client(client.invoke(OkHttpClient().newBuilder().apply {
val logging = HttpLoggingInterceptor(object:HttpLoggingInterceptor.Logger{
override fun log(message: String) {
Log.d("OKHTTP","OKHTTP$message")
LogLocal.log("OKHTTP","OKHTTP$message")
}
})
val logging = HttpLoggingInterceptor { message ->
LogUtils.d("OKHTTP",message)
LogLocal.log("OKHTTP", "OKHTTP$message")
}
logging.level = HttpLoggingInterceptor.Level.BODY
addInterceptor(Interceptor {
val response = proceedPoxyWithTryCatch {
it.proceed(it.request().newBuilder()
.addHeader("APPVersion", BaseApp.version)
.build()
)}
response!!
})
addInterceptor(logging)
//这里是在debug模式下方便开发人员简单确认 http 错误码 和 url(magipoke开始切的)
if (BuildConfig.DEBUG){
Expand Down Expand Up @@ -194,6 +203,10 @@ object ApiGenerator {
//不带token请求的OkHttp配置
private fun OkHttpClient.Builder.configureCommonOkHttp(): OkHttpClient {
return this.apply {
/**
* 发送版本号
*/

/**
* 连接失败时切换备用url的Interceptor
* 一旦切换,只有重启app才能切回来(因为如果请求得到的url不是原来的@{link getBaseUrl()},则切换到新的url,而以后访问都用这个新的url了)
Expand All @@ -206,6 +219,17 @@ object ApiGenerator {
//带token请求的OkHttp配置
private fun OkHttpClient.Builder.configureTokenOkHttp(): OkHttpClient {
return this.apply {
/**
* 发送版本号
*/
interceptors().add(Interceptor {
val response = proceedPoxyWithTryCatch {
it.proceed(it.request().newBuilder()
.addHeader("version", BaseApp.version)
.build()
)}
return@Interceptor response!!
})
/**
* 连接失败时切换备用url的Interceptor
* 一旦切换,只有重启app才能切回来(因为如果请求得到的url不是原来的@{link getBaseUrl()},则切换到新的url,而以后访问都用这个新的url了)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class QuizActivity : BaseViewModelActivity<QuizViewModel>() {

companion object {
// 允许发送动态的最大字数
const val MAX_CONTENT_SIZE = 500
const val MAX_CONTENT_SIZE = 1000
const val MAX_SELECTABLE_IMAGE_COUNT = 8
const val NOT_DRAFT = "0"
const val UPDATE_DRAFT = "1"
Expand Down
2 changes: 1 addition & 1 deletion module_qa/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<string name="qa_unfollow_circle" translatable="false">取消关注圈子成功</string>
<string name="qa_draft_dialog_no_save" translatable="false">不保存</string>
<string name="qa_draft_dialog_cancel" translatable="false">取消</string>
<string name="qa_edit_dynamic_num" translatable="false">0/500</string>
<string name="qa_edit_dynamic_num" translatable="false">0/1000</string>
<string name="qa_choose_one_circle" translatable="false">请选择一个圈子</string>
<string name="qa_dynamic_recommend" translatable="false">推荐</string>
<string name="qa_my_follow_circle" translatable="false">我的关注</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,19 @@ class SchoolCarActivity : BaseActivity(), View.OnClickListener {
aMap.animateCamera(update)
}
cv_positioning -> {
val update =
if (aMap.myLocation.longitude != 0.0 || aMap.myLocation.latitude !== 0.0){
CameraUpdateFactory.newLatLngZoom(LatLng(aMap.myLocation.latitude, aMap.myLocation.longitude), 17f)
}else{
CameraUpdateFactory.newLatLngZoom(LatLng(29.531876, 106.606789), 17f)
aMap.myLocation?.let { location->
location.longitude?.let {
location.latitude?.let {
val update =
if (aMap.myLocation.longitude != 0.0 || aMap.myLocation.latitude !== 0.0){
CameraUpdateFactory.newLatLngZoom(LatLng(aMap.myLocation.latitude, aMap.myLocation.longitude), 17f)
}else{
CameraUpdateFactory.newLatLngZoom(LatLng(29.531876, 106.606789), 17f)
}
aMap.animateCamera(update)
}
}
}
aMap.animateCamera(update)
}
iv_cooperation_logo -> {
val intent = Intent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class SchoolCarsSmoothMove(private val schoolCarActivity: SchoolCarActivity?, pr
val latLng = LatLng(data.lat,data.lon)
val marker = buildMarker(data.id,data.type,latLng)
marker?.let { marker ->
carMap[data.id] = SchoolCar(data.id,data.type,data.upDate,data.upDate,MovingPointOverlay(schoolCarActivity?.aMap,marker),marker,mutableListOf(latLng),getPolyline(data.type,latLng))
val smoothMarker = MovingPointOverlay(schoolCarActivity?.aMap,marker)
carMap[data.id] = SchoolCar(data.id,data.type,data.upDate,data.upDate,smoothMarker,marker,mutableListOf(latLng,smoothMarker.position),getPolyline(data.type,latLng))
}
carMap[data.id]?.let { car -> smoothMove(car) }
}else{
//这里因为轮询是1s一次,所以说判断一下更新的时间,
if(carMap[data.id]?.upDate != data.upDate){
Expand Down Expand Up @@ -92,10 +92,10 @@ class SchoolCarsSmoothMove(private val schoolCarActivity: SchoolCarActivity?, pr
}

private fun smoothMove(car:SchoolCar, mistime:Int = 3) {
if (car.latLngList.size > 4) {
if (car.latLngList.size > 3) {
//停止上一次的移动,然后将上一次的位置加上之后再移动
car.smoothMarker.stopMove()
val list = car.latLngList.subList(car.latLngList.size - 3, car.latLngList.size)
val list = car.latLngList.subList(car.latLngList.size - 2, car.latLngList.size)
list[0] = car.smoothMarker.position
val smoothMarker = MovingPointOverlay(schoolCarActivity?.aMap,car.marker)
smoothMarker.setPoints(list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ class TodoWidget : AppWidgetProvider() {
private fun getPendingIntentFlags(isMutable: Boolean = false) =
when {
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE

PendingIntent.FLAG_MUTABLE
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
PendingIntent.FLAG_IMMUTABLE
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
PendingIntent.FLAG_UPDATE_CURRENT
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE

PendingIntent.FLAG_UPDATE_CURRENT
else -> PendingIntent.FLAG_UPDATE_CURRENT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.annotation.IdRes
Expand Down Expand Up @@ -182,7 +183,7 @@ fun getClickIntent(context: Context, widgetId: Int, viewId: Int, requestCode: In
//放进需要设置的viewId
bundle.putInt("Button", viewId)
i.putExtras(bundle)
return PendingIntent.getBroadcast(context, requestCode, i, PendingIntent.FLAG_UPDATE_CURRENT)
return PendingIntent.getBroadcast(context, requestCode, i,getPendingIntentFlags())
}

fun formatTime(calendar: Calendar): String {
Expand Down Expand Up @@ -229,3 +230,15 @@ fun startOperation(dataBean: WidgetCourse.DataBean) {
EventBus.getDefault().postSticky(WidgetCourseEvent(mutableListOf(dataBean)))
}
}
private fun getPendingIntentFlags(isMutable: Boolean = false) =
when {
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
PendingIntent.FLAG_MUTABLE
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->
PendingIntent.FLAG_IMMUTABLE
isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
PendingIntent.FLAG_UPDATE_CURRENT
!isMutable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ->
PendingIntent.FLAG_UPDATE_CURRENT
else -> PendingIntent.FLAG_UPDATE_CURRENT
}

0 comments on commit 1d92573

Please sign in to comment.