Skip to content
This repository was archived by the owner on Jun 8, 2024. It is now read-only.

Commit 0a42a0e

Browse files
committed
UI: Update a lot (New palette, Search dialog)
Signed-off-by: Fung Gwo <[email protected]>
1 parent f02076c commit 0a42a0e

23 files changed

+518
-108
lines changed

build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
ext {
22
minSdkVersion = 23
33
targetSdkVersion = 28
4-
buildToolsVersion = "28.0.2"
5-
versionCode = 60
4+
versionCode = 61
65
versionName = '5.0.0'
76
kotlinyanVersion = '0.3.0'
87
ankoVersion = '0.10.8'

mobile/src/main/kotlin/info/papdt/express/helper/Application.kt

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.tencent.bugly.crashreport.CrashReport
1313
import info.papdt.express.helper.model.MaterialIcon
1414

1515
import info.papdt.express.helper.services.ClipboardDetectService
16+
import info.papdt.express.helper.support.MaterialColorGenerator
1617
import info.papdt.express.helper.support.Settings
1718
import info.papdt.express.helper.support.SettingsInstance
1819
import io.alterac.blurkit.BlurKit
@@ -42,6 +43,7 @@ class Application : MultiDexApplication() {
4243

4344
// Init Widget components
4445
MaterialIcon.init(this)
46+
MaterialColorGenerator.init(this)
4547
BlurKit.init(this)
4648

4749
// Init CrashReport

mobile/src/main/kotlin/info/papdt/express/helper/api/Kuaidi100PackageApi.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import java.util.ArrayList
1414

1515
import info.papdt.express.helper.model.BaseMessage
1616
import info.papdt.express.helper.model.Kuaidi100Package
17+
import info.papdt.express.helper.model.MaterialPalette
1718
import info.papdt.express.helper.support.HttpUtils
19+
import info.papdt.express.helper.support.MaterialColorGenerator
1820
import kotlinx.coroutines.CoroutineScope
1921
import kotlinx.coroutines.Dispatchers
2022
import kotlinx.coroutines.launch
@@ -213,7 +215,16 @@ object Kuaidi100PackageApi {
213215
lateinit var names: Array<String>
214216
lateinit var pinyin: Array<String>
215217

216-
class Company(var name: String, var code: String, var phone: String?, var website: String?)
218+
class Company(var name: String,
219+
var code: String,
220+
var phone: String?,
221+
var website: String?) {
222+
223+
fun getPalette(): MaterialPalette {
224+
return MaterialColorGenerator.getPalette(name)
225+
}
226+
227+
}
217228

218229
fun findCompanyByCode(code: String?): Int {
219230
return if (code == null) -1 else (info!!.indices.firstOrNull { info!![it].code == code } ?: -1)

mobile/src/main/kotlin/info/papdt/express/helper/model/Kuaidi100Package.kt

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import java.util.regex.Pattern
1111

1212
import info.papdt.express.helper.api.Kuaidi100PackageApi
1313
import info.papdt.express.helper.support.DateHelper
14+
import info.papdt.express.helper.support.MaterialColorGenerator
1415
import java.text.SimpleDateFormat
1516
import java.util.*
1617

@@ -124,6 +125,10 @@ class Kuaidi100Package() : Parcelable {
124125
return (this.codeNumber ?: this.number) == (other.codeNumber ?: other.number)
125126
}
126127

128+
fun getPaletteFromId(): MaterialPalette {
129+
return MaterialColorGenerator.getPalette(id)
130+
}
131+
127132
class Status {
128133

129134
@Expose var time: String? = null
@@ -172,8 +177,18 @@ class Kuaidi100Package() : Parcelable {
172177
return _phone ?: Status.findContact(context).apply { _phone = this }
173178
}
174179

180+
fun getTimeDate(): Date? {
181+
try {
182+
return ftimeDateFormat.parse(ftime)
183+
} catch (e: Exception) {
184+
return null
185+
}
186+
}
187+
175188
companion object {
176189

190+
private val ftimeDateFormat = SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
191+
177192
fun findContact(s: String?): String? {
178193
var number: String? = checkNum(s)
179194
if (number == null || number.length < 8) return null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package info.papdt.express.helper.model
2+
3+
import android.content.Context
4+
import androidx.annotation.ColorInt
5+
import info.papdt.express.helper.R
6+
7+
data class MaterialPalette(
8+
val colorName: String,
9+
private val colorMap: Map<String, Int>
10+
) {
11+
12+
companion object {
13+
14+
fun make(colorName: String, vararg colors: Pair<String, Int>): MaterialPalette {
15+
return MaterialPalette(colorName, mapOf(*colors))
16+
}
17+
18+
fun makeFromResources(
19+
context: Context,
20+
colorName: String,
21+
vararg colorsRes: Pair<String, Int>
22+
): MaterialPalette {
23+
return MaterialPalette(colorName, mapOf(*colorsRes.map {
24+
it.first to context.resources.getColor(it.second)
25+
}.toTypedArray()))
26+
}
27+
28+
}
29+
30+
@ColorInt
31+
operator fun get(key: String): Int {
32+
return colorMap.getValue(key)
33+
}
34+
35+
@ColorInt
36+
fun getPackageIconBackground(context: Context): Int {
37+
return get(context.getString(R.string.packageIconBackgroundColorKey))
38+
}
39+
40+
@ColorInt
41+
fun getPackageIconForeground(context: Context): Int {
42+
return get(context.getString(R.string.packageIconForegroundColorKey))
43+
}
44+
45+
@ColorInt
46+
fun getStatusIconTint(context: Context): Int {
47+
return get(context.getString(R.string.packageStatusIconColorKey))
48+
}
49+
50+
}

mobile/src/main/kotlin/info/papdt/express/helper/support/ColorGenerator.kt

-54
This file was deleted.

mobile/src/main/kotlin/info/papdt/express/helper/support/DateHelper.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object DateHelper {
3030
diffDays <= 30 -> 30
3131
diffDays <= 30 * 6 -> (diffDays / 30) * 30
3232
diffDays <= 365 -> 365
33-
else -> (diffDays / 365) * 365
33+
else -> (diffDays.toFloat() / 365f).toLong() * 365 + 1
3434
}
3535
}
3636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package info.papdt.express.helper.support
2+
3+
import android.content.Context
4+
import info.papdt.express.helper.model.MaterialPalette
5+
import kotlin.random.Random
6+
7+
object MaterialColorGenerator {
8+
9+
lateinit var Red: MaterialPalette
10+
lateinit var Pink: MaterialPalette
11+
lateinit var Purple: MaterialPalette
12+
lateinit var DeepPurple: MaterialPalette
13+
lateinit var Indigo: MaterialPalette
14+
lateinit var Blue: MaterialPalette
15+
lateinit var LightBlue: MaterialPalette
16+
lateinit var Cyan: MaterialPalette
17+
lateinit var Teal: MaterialPalette
18+
lateinit var Green: MaterialPalette
19+
lateinit var LightGreen: MaterialPalette
20+
lateinit var Lime: MaterialPalette
21+
lateinit var Yellow: MaterialPalette
22+
lateinit var Amber: MaterialPalette
23+
lateinit var Orange: MaterialPalette
24+
lateinit var DeepOrange: MaterialPalette
25+
lateinit var Brown: MaterialPalette
26+
lateinit var BlueGrey: MaterialPalette
27+
28+
val AllPalettes: List<MaterialPalette> by lazy {
29+
listOf(Red, Pink, Purple, DeepPurple, Indigo, Blue, LightBlue,
30+
Cyan, Teal, Green, LightGreen, Lime, Amber, Orange,
31+
DeepOrange, Brown, BlueGrey)
32+
}
33+
34+
private val random: Random = Random(System.currentTimeMillis())
35+
36+
private val RedProducer = PaletteProducer("red",
37+
"50", "100", "200", "300", "400", "500",
38+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
39+
private val PinkProducer = PaletteProducer("pink",
40+
"50", "100", "200", "300", "400", "500",
41+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
42+
private val PurpleProducer = PaletteProducer("purple",
43+
"50", "100", "200", "300", "400", "500",
44+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
45+
private val DeepPurpleProducer = PaletteProducer("deep_purple",
46+
"50", "100", "200", "300", "400", "500",
47+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
48+
private val IndigoProducer = PaletteProducer("indigo",
49+
"50", "100", "200", "300", "400", "500",
50+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
51+
private val BlueProducer = PaletteProducer("blue",
52+
"50", "100", "200", "300", "400", "500",
53+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
54+
private val LightBlueProducer = PaletteProducer("light_blue",
55+
"50", "100", "200", "300", "400", "500",
56+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
57+
private val CyanProducer = PaletteProducer("cyan",
58+
"50", "100", "200", "300", "400", "500",
59+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
60+
private val TealProducer = PaletteProducer("teal",
61+
"50", "100", "200", "300", "400", "500",
62+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
63+
private val GreenProducer = PaletteProducer("green",
64+
"50", "100", "200", "300", "400", "500",
65+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
66+
private val LightGreenProducer = PaletteProducer("light_green",
67+
"50", "100", "200", "300", "400", "500",
68+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
69+
private val LimeProducer = PaletteProducer("lime",
70+
"50", "100", "200", "300", "400", "500",
71+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
72+
private val YellowProducer = PaletteProducer("yellow",
73+
"50", "100", "200", "300", "400", "500",
74+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
75+
private val AmberProducer = PaletteProducer("amber",
76+
"50", "100", "200", "300", "400", "500",
77+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
78+
private val OrangeProducer = PaletteProducer("orange",
79+
"50", "100", "200", "300", "400", "500",
80+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
81+
private val DeepOrangeProducer = PaletteProducer("deep_orange",
82+
"50", "100", "200", "300", "400", "500",
83+
"600", "700", "800", "900", "A100", "A200", "A400", "A700")
84+
private val BrownProducer = PaletteProducer("brown",
85+
"50", "100", "200", "300", "400", "500",
86+
"600", "700", "800", "900")
87+
private val BlueGreyProducer = PaletteProducer("blue_grey",
88+
"50", "100", "200", "300", "400", "500",
89+
"600", "700", "800", "900")
90+
91+
fun init(context: Context) {
92+
Red = RedProducer.make(context)
93+
Pink = PinkProducer.make(context)
94+
Purple = PurpleProducer.make(context)
95+
DeepPurple = DeepPurpleProducer.make(context)
96+
Indigo = IndigoProducer.make(context)
97+
Blue = BlueProducer.make(context)
98+
LightBlue = LightBlueProducer.make(context)
99+
Cyan = CyanProducer.make(context)
100+
Teal = TealProducer.make(context)
101+
Green = GreenProducer.make(context)
102+
LightGreen = LightGreenProducer.make(context)
103+
Lime = LimeProducer.make(context)
104+
Yellow = YellowProducer.make(context)
105+
Amber = AmberProducer.make(context)
106+
Orange = OrangeProducer.make(context)
107+
DeepOrange = DeepOrangeProducer.make(context)
108+
Brown = BrownProducer.make(context)
109+
BlueGrey = BlueGreyProducer.make(context)
110+
}
111+
112+
fun getPalette(key: Any): MaterialPalette {
113+
return AllPalettes[Math.abs(key.hashCode()) % AllPalettes.size]
114+
}
115+
116+
private class PaletteProducer(
117+
val colorName: String,
118+
vararg val colorKeys: String
119+
) {
120+
121+
fun make(context: Context): MaterialPalette {
122+
val res = context.resources
123+
val ids = colorKeys.map {
124+
it to res.getIdentifier("${colorName}_$it",
125+
"color", context.packageName)
126+
}.toTypedArray()
127+
return MaterialPalette.makeFromResources(context, colorName, *ids)
128+
}
129+
130+
}
131+
132+
}

mobile/src/main/kotlin/info/papdt/express/helper/ui/CompanyChooserActivity.kt

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package info.papdt.express.helper.ui
22

3-
import android.annotation.SuppressLint
43
import android.app.Activity
54
import android.content.Intent
65
import android.graphics.Color
@@ -25,7 +24,6 @@ import info.papdt.express.helper.RESULT_EXTRA_COMPANY_CODE
2524
import info.papdt.express.helper.api.Kuaidi100PackageApi
2625
import info.papdt.express.helper.api.KtPackageApi
2726
import info.papdt.express.helper.support.ResourcesUtils
28-
import info.papdt.express.helper.support.Settings
2927
import info.papdt.express.helper.ui.adapter.CompanyListAdapter
3028
import info.papdt.express.helper.ui.common.AbsActivity
3129
import info.papdt.express.helper.ui.common.SimpleRecyclerViewAdapter
@@ -67,10 +65,9 @@ class CompanyChooserActivity : AbsActivity() {
6765
private lateinit var mAdapter: CompanyListAdapter
6866
private var data: ArrayList<Kuaidi100PackageApi.CompanyInfo.Company>? = null
6967

70-
@SuppressLint("NewApi")
7168
override fun onCreate(savedInstanceState: Bundle?) {
7269
var flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
73-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !isNightMode) {
70+
if (!isNightMode) {
7471
flag = flag or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
7572
}
7673
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 && !isNightMode) {
@@ -88,15 +85,15 @@ class CompanyChooserActivity : AbsActivity() {
8885
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
8986
if (!isNightMode) {
9087
window.navigationBarColor = Color.WHITE
91-
ifSupportSDK (Build.VERSION_CODES.P) {
92-
window.navigationBarDividerColor = Color.argb(30, 0, 0, 0)
93-
}
88+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
89+
window.navigationBarDividerColor = Color.argb(30, 0, 0, 0)
90+
}
9491
} else {
9592
window.navigationBarColor = ResourcesUtils.getColorIntFromAttr(
9693
theme, android.R.attr.windowBackground)
97-
ifSupportSDK (Build.VERSION_CODES.P) {
98-
window.navigationBarDividerColor = Color.argb(60, 255, 255, 255)
99-
}
94+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
95+
window.navigationBarDividerColor = Color.argb(60, 255, 255, 255)
96+
}
10097
}
10198
}
10299

0 commit comments

Comments
 (0)