Skip to content

Commit dd38249

Browse files
feat(*): 去掉多余资源
1 parent 9728efa commit dd38249

File tree

10 files changed

+249
-5
lines changed

10 files changed

+249
-5
lines changed

app/src/main/assets/Test.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"code": 200,
3+
"data": {
4+
"rows": [
5+
{
6+
"createTime": "2022-12-26 09:24:19",
7+
"id": "1607306303102074882",
8+
"isDel": 0,
9+
"minioFileName": "",
10+
"noticeCompany": "徐州分中心",
11+
"noticeContent": "元旦放假通知",
12+
"noticeNo": "tzgg221222202020",
13+
"noticePublisher": "超级管理员",
14+
"noticeSketch": "元旦放假通知",
15+
"noticeTime": "2023-01-03 05:45:33",
16+
"noticeTitle": "元旦放假通知",
17+
"read": "1",
18+
"updateTime": "2023-01-03 05:45:32"
19+
},
20+
{
21+
"createTime": "2022-12-27 06:20:41",
22+
"id": "1607260090789085186",
23+
"isDel": 0,
24+
"minioFileName": "未命名1_加水印_1672035640383.pdf",
25+
"noticeCompany": "顶级",
26+
"noticeContent": "图片/视频/代码块测试",
27+
"noticeNo": "tzgg221222202019",
28+
"noticePublisher": "李亚光",
29+
"noticeSketch": "图片/视频/代码块测试",
30+
"noticeTime": "2022-12-26 06:20:42",
31+
"noticeTitle": "图片/视频/代码块测试",
32+
"read": "1",
33+
"updateTime": "2022-12-26 06:20:41"
34+
}
35+
],
36+
"total": 2
37+
},
38+
"message": "请求成功"
39+
}

app/src/main/java/com/pengxh/kt/lib/MainActivity.kt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
package com.pengxh.kt.lib
22

3+
import android.graphics.Color
4+
import android.os.Handler
5+
import android.view.animation.AlphaAnimation
6+
import android.view.animation.AnimationSet
7+
import android.view.animation.TranslateAnimation
8+
import android.widget.TextSwitcher
9+
import android.widget.TextView
10+
import com.google.gson.Gson
11+
import com.google.gson.reflect.TypeToken
312
import com.pengxh.kt.lite.base.KotlinBaseActivity
13+
import com.pengxh.kt.lite.extensions.convertColor
14+
import com.pengxh.kt.lite.extensions.readAssetsFile
15+
import com.pengxh.kt.lite.utils.WeakReferenceHandler
16+
import kotlinx.android.synthetic.main.activity_main.*
17+
import java.text.SimpleDateFormat
18+
import java.util.*
19+
import kotlin.math.abs
420

521

622
class MainActivity : KotlinBaseActivity() {
723

24+
companion object {
25+
lateinit var timer: Timer
26+
}
27+
28+
private val kTag = "MainActivity"
29+
private lateinit var weakReferenceHandler: WeakReferenceHandler
30+
private var noticeBeans: MutableList<NoticeListModel.DataModel.RowsModel> = ArrayList()
31+
private var currentIndex = 0
32+
833
override fun initLayoutView(): Int = R.layout.activity_main
934

1035
override fun setupTopBarLayout() {
@@ -16,10 +41,110 @@ class MainActivity : KotlinBaseActivity() {
1641
}
1742

1843
override fun initData() {
44+
val response = readAssetsFile("Test.json")
45+
val it = Gson().fromJson<NoticeListModel>(
46+
response, object : TypeToken<NoticeListModel>() {}.type
47+
)
48+
noticeBeans = it.data.rows
49+
50+
noticeSwitcherView.setFactory {
51+
val textView = TextView(this)
52+
textView.setTextColor(Color.BLACK)
53+
textView
54+
}
55+
noticeSwitcherView.setAnimation()
56+
57+
timeSwitcherView.setFactory {
58+
val textView = TextView(this)
59+
textView.setTextColor(R.color.hintColor.convertColor(this))
60+
textView
61+
}
62+
timeSwitcherView.setAnimation()
1963

64+
weakReferenceHandler = WeakReferenceHandler(callback)
65+
//消息滚动Timer
66+
timer = Timer()
67+
timer.schedule(object : TimerTask() {
68+
override fun run() {
69+
weakReferenceHandler.sendEmptyMessage(2023030601)
70+
}
71+
}, 0, 3000)
72+
}
73+
74+
private val callback = Handler.Callback { msg ->
75+
when (msg.what) {
76+
2023030601 -> {
77+
if (noticeBeans.size != 0) {
78+
val model = noticeBeans[currentIndex % noticeBeans.size]
79+
80+
noticeSwitcherView.setText(model.noticeTitle)
81+
82+
val deltaT = model.createTime.diffCurrentTime()
83+
val diffTime = if (deltaT < 24) {
84+
"${deltaT}小时前"
85+
} else {
86+
model.createTime.formatToDate()
87+
}
88+
timeSwitcherView.setText(diffTime)
89+
currentIndex++
90+
} else {
91+
noticeSwitcherView.setText("暂无新消息")
92+
timeSwitcherView.setText("--:--")
93+
}
94+
}
95+
}
96+
true
2097
}
2198

2299
override fun initEvent() {
23100

24101
}
102+
103+
override fun onDestroy() {
104+
super.onDestroy()
105+
timer.cancel()
106+
}
107+
108+
//上下滚动消息动画扩展
109+
fun TextSwitcher.setAnimation() {
110+
val translateIn = TranslateAnimation(0f, 0f, 50f, 0f)
111+
val alphaIn = AlphaAnimation(0f, 1f)
112+
val animatorSetIn = AnimationSet(true)
113+
animatorSetIn.addAnimation(translateIn)
114+
animatorSetIn.addAnimation(alphaIn)
115+
animatorSetIn.duration = 1000
116+
this.inAnimation = animatorSetIn
117+
118+
val translateOut = TranslateAnimation(0f, 0f, 0f, -50f)
119+
val alphaOut = AlphaAnimation(1f, 0f)
120+
val animatorSetOut = AnimationSet(true)
121+
animatorSetOut.addAnimation(translateOut)
122+
animatorSetOut.addAnimation(alphaOut)
123+
animatorSetOut.duration = 1000
124+
this.outAnimation = animatorSetOut
125+
}
126+
127+
/**
128+
* 时间差-小时
129+
* */
130+
private fun String.diffCurrentTime(): Int {
131+
if (this.isBlank()) {
132+
return 0
133+
}
134+
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA)
135+
val date = simpleDateFormat.parse(this)
136+
val diff = abs(System.currentTimeMillis() - date.time)
137+
return (diff / (3600000)).toInt()
138+
}
139+
140+
private fun String.formatToDate(): String {
141+
if (this.isBlank()) {
142+
return this
143+
}
144+
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA)
145+
val date = simpleDateFormat.parse(this)
146+
147+
val dateFormat = SimpleDateFormat("MM-dd", Locale.CHINA)
148+
return dateFormat.format(date)
149+
}
25150
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.pengxh.kt.lib
2+
3+
class NoticeListModel {
4+
var code = 0
5+
lateinit var data: DataModel
6+
lateinit var message: String
7+
8+
class DataModel {
9+
lateinit var rows: MutableList<RowsModel>
10+
var total = 0
11+
12+
class RowsModel {
13+
lateinit var createTime: String
14+
lateinit var id: String
15+
lateinit var isDel: String
16+
lateinit var minioFileName: String
17+
lateinit var noticeCompany: String
18+
lateinit var noticeContent: String
19+
lateinit var noticeNo: String
20+
lateinit var noticePublisher: String
21+
lateinit var noticeSketch: String
22+
lateinit var noticeTime: String
23+
lateinit var noticeTitle: String
24+
lateinit var read: String
25+
lateinit var updateTime: String
26+
}
27+
}
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
5+
<solid android:color="@color/white" />
6+
7+
<corners android:radius="@dimen/dp_5" />
8+
</shape>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="48px"
3+
android:height="48px"
4+
android:viewportWidth="1024"
5+
android:viewportHeight="1024">
6+
<path
7+
android:fillColor="@color/hintColor"
8+
android:pathData="M300.59,895.7c9.6,0 19.33,-3.2 27.39,-9.6l423.81,-340.91a43.73,43.73 0,0 0,0 -68.1L329.81,137.98A43.69,43.69 0,0 0,275.11 206.08l379.61,305.11 -381.53,306.77a43.69,43.69 0,0 0,27.39 77.74z" />
9+
</vector>
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:app="http://schemas.android.com/apk/res-auto"
43
android:layout_width="match_parent"
54
android:layout_height="match_parent"
6-
android:background="@color/white"
5+
android:background="@color/mainBackground"
6+
android:gravity="center"
77
android:orientation="vertical">
88

9-
<androidx.recyclerview.widget.RecyclerView
10-
android:id="@+id/recyclerView"
9+
<LinearLayout
1110
android:layout_width="match_parent"
1211
android:layout_height="wrap_content"
13-
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
12+
android:layout_margin="@dimen/dp_10"
13+
android:background="@drawable/bg_solid_layout_white_radius_5"
14+
android:gravity="center_vertical"
15+
android:paddingHorizontal="@dimen/dp_7"
16+
android:paddingVertical="@dimen/dp_10">
17+
18+
<ImageView
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:src="@mipmap/notice" />
22+
23+
<LinearLayout
24+
android:layout_width="0dp"
25+
android:layout_height="wrap_content"
26+
android:layout_weight="1"
27+
android:orientation="horizontal">
28+
29+
<TextSwitcher
30+
android:id="@+id/noticeSwitcherView"
31+
android:layout_width="0dp"
32+
android:layout_height="wrap_content"
33+
android:layout_marginHorizontal="@dimen/dp_10"
34+
android:layout_weight="1"
35+
android:textSize="@dimen/sp_12" />
36+
37+
<TextSwitcher
38+
android:id="@+id/timeSwitcherView"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:textSize="@dimen/sp_12" />
42+
</LinearLayout>
43+
44+
<ImageView
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:src="@drawable/ic_right" />
48+
</LinearLayout>
1449
</LinearLayout>
5.1 KB
Loading
-1.66 MB
Binary file not shown.
-1.83 MB
Binary file not shown.
-3.28 MB
Binary file not shown.

0 commit comments

Comments
 (0)