Skip to content

Commit 1c3e9c4

Browse files
author
zhujiang2
committed
修复展示的问题,优化性能
目前已知问题,设置线性颜色无效
1 parent 90938a8 commit 1c3e9c4

File tree

10 files changed

+94
-33
lines changed

10 files changed

+94
-33
lines changed

app/proguard-rules.pro

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,59 @@
5757

5858
# 导航
5959
-keep class com.amap.api.navi.**{*;}
60-
-keep class com.autonavi.**{*;}
60+
-keep class com.autonavi.**{*;}
61+
62+
-dontwarn com.amap.api.location.AMapLocation
63+
-dontwarn com.amap.api.location.AMapLocationClient
64+
-dontwarn com.amap.api.location.AMapLocationClientOption$AMapLocationMode
65+
-dontwarn com.amap.api.location.AMapLocationClientOption
66+
-dontwarn com.amap.api.location.AMapLocationListener
67+
68+
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
69+
# EnclosingMethod is required to use InnerClasses.
70+
-keepattributes Signature, InnerClasses, EnclosingMethod
71+
72+
# Retrofit does reflection on method and parameter annotations.
73+
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
74+
75+
# Keep annotation default values (e.g., retrofit2.http.Field.encoded).
76+
-keepattributes AnnotationDefault
77+
78+
# Retain service method parameters when optimizing.
79+
-keepclassmembers,allowshrinking,allowobfuscation interface * {
80+
@retrofit2.http.* <methods>;
81+
}
82+
83+
# Ignore annotation used for build tooling.
84+
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
85+
86+
# Ignore JSR 305 annotations for embedding nullability information.
87+
-dontwarn javax.annotation.**
88+
89+
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
90+
-dontwarn kotlin.Unit
91+
92+
# Top-level functions that can only be used by Kotlin.
93+
-dontwarn retrofit2.KotlinExtensions
94+
-dontwarn retrofit2.KotlinExtensions$*
95+
96+
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
97+
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
98+
-if interface * { @retrofit2.http.* <methods>; }
99+
-keep,allowobfuscation interface <1>
100+
101+
# Keep inherited services.
102+
-if interface * { @retrofit2.http.* <methods>; }
103+
-keep,allowobfuscation interface * extends <1>
104+
105+
# With R8 full mode generic signatures are stripped for classes that are not
106+
# kept. Suspend functions are wrapped in continuations where the type argument
107+
# is used.
108+
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
109+
110+
# R8 full mode strips generic signatures from return types if not kept.
111+
-if interface * { @retrofit2.http.* public *** *(...); }
112+
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
113+
114+
# With R8 full mode generic signatures are stripped for classes that are not kept.
115+
-keep,allowobfuscation,allowshrinking class retrofit2.Response

app/release/app-release.apk

-429 KB
Binary file not shown.

app/release/output-metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"type": "SINGLE",
1212
"filters": [],
1313
"attributes": [],
14-
"versionCode": 42,
15-
"versionName": "4.5.0",
14+
"versionCode": 43,
15+
"versionName": "4.5.1",
1616
"outputFile": "app-release.apk"
1717
}
1818
],

app/src/main/kotlin/com/zj/weather/view/list/WeatherListPage.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import androidx.compose.runtime.collectAsState
1515
import androidx.compose.runtime.getValue
1616
import androidx.compose.ui.Modifier
1717
import androidx.compose.ui.platform.LocalContext
18+
import androidx.compose.ui.platform.LocalFocusManager
1819
import androidx.compose.ui.res.dimensionResource
1920
import androidx.compose.ui.tooling.preview.Preview
2021
import com.zj.model.PlayError
@@ -39,6 +40,7 @@ fun WeatherListPage(
3940
onBack: () -> Unit,
4041
) {
4142
val context = LocalContext.current
43+
val focusManager = LocalFocusManager.current
4244
val locationBeanState by weatherListViewModel.locationBeanList.collectAsState()
4345
WeatherListPage(
4446
locationBeanState = locationBeanState,
@@ -52,6 +54,7 @@ fun WeatherListPage(
5254
toWeatherDetails = { cityInfo ->
5355
weatherListViewModel.insertCityInfo(cityInfo)
5456
(context as Activity).hideIme()
57+
focusManager.clearFocus()
5558
onBack()
5659
})
5760
}

app/src/main/kotlin/com/zj/weather/view/map/MapCompose.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.zj.weather.view.map
22

3-
import android.app.Application
4-
import androidx.compose.foundation.layout.*
3+
import androidx.compose.foundation.layout.Column
4+
import androidx.compose.foundation.layout.fillMaxSize
5+
import androidx.compose.foundation.layout.navigationBarsPadding
6+
import androidx.compose.foundation.layout.statusBarsPadding
57
import androidx.compose.runtime.Composable
68
import androidx.compose.runtime.DisposableEffect
79
import androidx.compose.runtime.remember
@@ -17,7 +19,6 @@ import com.amap.api.maps2d.model.CameraPosition
1719
import com.amap.api.maps2d.model.LatLng
1820
import com.amap.api.maps2d.model.Marker
1921
import com.amap.api.maps2d.model.MarkerOptions
20-
import com.zj.model.PlayError
2122
import com.zj.utils.XLog
2223
import com.zj.utils.checkNetConnect
2324
import com.zj.utils.lce.ErrorContent

app/src/main/kotlin/com/zj/weather/view/weather/WeatherViewPager.kt

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ private fun Weather(
6969
return@forEachIndexed
7070
}
7171
}
72-
if (indexOf >= 0 && indexOf != pagerState.currentPage) {
73-
LaunchedEffect(Unit) {
74-
pagerState.scrollToPage(indexOf)
75-
defaultCityState.value = null
76-
}
72+
if (indexOf < 0 || indexOf == pagerState.currentPage) return
73+
LaunchedEffect(Unit) {
74+
pagerState.scrollToPage(indexOf)
75+
XLog.d("scrollToPage:$indexOf")
76+
defaultCityState.value = null
7777
}
7878
}
7979

@@ -133,10 +133,7 @@ fun WeatherViewPager(
133133
toWeatherList: () -> Unit,
134134
) {
135135
Box(
136-
modifier = Modifier
137-
.fillMaxSize()
138-
.navigationBarsPadding()
139-
.statusBarsPadding()
136+
modifier = Modifier.fillMaxSize()
140137
) {
141138
HorizontalPager(modifier = Modifier, state = pagerState, key = {
142139
try {
@@ -170,14 +167,7 @@ fun WeatherViewPager(
170167
pageCount = cityInfoList.size,
171168
modifier = Modifier
172169
.align(Alignment.BottomCenter)
173-
.padding(16.dp),
170+
.padding(bottom = 25.dp),
174171
)
175172
}
176-
}
177-
178-
fun getLocation(cityInfo: CityInfo?): String {
179-
if (cityInfo == null) return "CN101010100"
180-
return cityInfo.locationId.ifEmpty {
181-
cityInfo.location
182-
}
183-
}
173+
}

app/src/main/kotlin/com/zj/weather/view/weather/viewmodel/WeatherViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import com.zj.utils.XLog
1818
import com.zj.utils.checkCoroutines
1919
import com.zj.utils.checkNetConnect
2020
import com.zj.utils.view.showToast
21+
import com.zj.utils.weather.getLocationForCityInfo
2122
import com.zj.weather.R
22-
import com.zj.weather.view.weather.getLocation
2323
import com.zj.weather.widget.today.LOCATION_REFRESH
2424
import dagger.hilt.android.lifecycle.HiltViewModel
2525
import kotlinx.coroutines.Dispatchers
@@ -93,7 +93,7 @@ class WeatherViewModel @Inject constructor(
9393
}
9494

9595
fun getWeather(cityInfo: CityInfo) {
96-
val location = getLocation(cityInfo)
96+
val location = getLocationForCityInfo(cityInfo)
9797
if (weatherMap.containsKey(location)) {
9898
val weather = weatherMap[location]
9999
if (weather != null && weather.first + FIFTEEN_MINUTES > System.currentTimeMillis()) {

app/src/main/kotlin/com/zj/weather/widget/WeatherWidgetUtils.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import android.appwidget.AppWidgetManager
44
import android.content.Context
55
import com.zj.model.*
66
import com.zj.model.room.entity.CityInfo
7-
import com.zj.model.weather.WeatherNowBean
87
import com.zj.network.PlayWeatherNetwork
98
import com.zj.utils.XLog
109
import com.zj.utils.weather.getDateWeekName
10+
import com.zj.utils.weather.getLocationForCityInfo
1111
import com.zj.weather.R
12-
import com.zj.weather.view.weather.getLocation
1312
import com.zj.weather.widget.today.TodayWeatherRemoteViewsFactory
1413
import com.zj.weather.widget.week.WeatherRemoteViewsFactory
1514
import com.zj.weather.widget.week.WeekWeather
@@ -90,7 +89,7 @@ object WeatherWidgetUtils : CoroutineScope by MainScope() {
9089
appWidgetId: Int
9190
) {
9291
XLog.w("notifyWeatherWidget: Refresh the weather")
93-
getWeather7Day(context = context, location = getLocation(cityInfo = cityInfo)) { items ->
92+
getWeather7Day(context = context, location = getLocationForCityInfo(cityInfo = cityInfo)) { items ->
9493
WeatherRemoteViewsFactory.setWidgetItemList(items)
9594
val mgr = AppWidgetManager.getInstance(context)
9695
mgr.notifyAppWidgetViewDataChanged(

app/src/main/kotlin/com/zj/weather/widget/today/TodayWeatherWidget.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.appwidget.AppWidgetProvider
66
import android.content.Context
77
import android.content.Intent
88
import android.net.Uri
9-
import android.os.Build
109
import android.util.SizeF
1110
import android.widget.RemoteViews
1211
import com.zj.weather.MainActivity
@@ -15,10 +14,10 @@ import com.zj.weather.widget.WeatherWidgetUtils
1514
import com.zj.weather.widget.utils.deleteCityInfoPref
1615
import com.zj.weather.widget.utils.loadCityInfoPref
1716
import com.zj.model.room.entity.CityInfo
18-
import com.zj.weather.view.weather.getLocation
1917
import com.zj.utils.XLog
2018
import com.zj.utils.isSOrLater
2119
import com.zj.utils.weather.IconUtils
20+
import com.zj.utils.weather.getLocationForCityInfo
2221

2322
const val CLICK_TODAY_ACTION = "com.zj.weather.widget.today.CLICK_TODAY_ACTION"
2423
const val LOCATION_REFRESH = "com.zj.weather.LOCATION_REFRESH"
@@ -110,7 +109,7 @@ private fun buildRemoteViews(
110109
) {
111110
WeatherWidgetUtils.getWeather7Day(
112111
context = context,
113-
location = getLocation(cityInfo = cityInfo)
112+
location = getLocationForCityInfo(cityInfo = cityInfo)
114113
) { items ->
115114
val nowBaseBean = items[0]
116115
views.setTextViewText(R.id.today_tv_location, "${cityInfo?.city} ${cityInfo?.name}")
@@ -136,7 +135,7 @@ private fun buildRemoteViews(
136135
val intent = Intent(context, TodayWeatherWidgetService::class.java).apply {
137136
// Add the app widget ID to the intent extras.
138137
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId)
139-
putExtra(LOCATION_INFO, getLocation(cityInfo = cityInfo))
138+
putExtra(LOCATION_INFO, getLocationForCityInfo(cityInfo = cityInfo))
140139
data = Uri.parse(toUri(Intent.URI_INTENT_SCHEME))
141140
}
142141
// 设置 RemoteViews 对象以使用 RemoteViews 适配器

utils/src/main/java/com/zj/utils/weather/WeatherUtils.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
package com.zj.utils.weather
22

33
import android.content.Context
4+
import com.zj.model.room.entity.CityInfo
45
import com.zj.model.weather.WeatherDailyBean
56
import com.zj.utils.R
67
import com.zj.utils.XLog
78
import java.util.Calendar
89

10+
11+
/**
12+
* 获取需要查询的location sting
13+
*
14+
* @param cityInfo 城市信息
15+
*/
16+
fun getLocationForCityInfo(cityInfo: CityInfo?): String {
17+
if (cityInfo == null) return "CN101010100"
18+
return cityInfo.locationId.ifEmpty {
19+
cityInfo.location
20+
}
21+
}
22+
923
/**
1024
* 从7天中获取今天的天气,因为里面有紫外线和日出日落信息
1125
*

0 commit comments

Comments
 (0)