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

Commit 045a4b1

Browse files
committed
SettingsMain: Push server introduction
Signed-off-by: Fung <fython@163.com>
1 parent 6c86bd8 commit 045a4b1

8 files changed

Lines changed: 67 additions & 9 deletions

File tree

mobile/barcode_scan.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import kotlin.properties.Delegates
77
class PTSettings(context: Context): SharedPreferencesProvider(context, "settings") {
88

99
var enablePush by booleanValue(defValue = false)
10-
var pushApiHost by stringValue(defValue = "pt.api.rabi.coffee")
10+
var pushApiHost by stringValue()
1111
var pushApiPort by intValue(defValue = 3000)
1212

1313
var shouldShowTips by booleanValue(defValue = true)
14+
var clickedDonate by booleanValue(defValue = false)
1415

1516
}
1617

mobile/src/main/kotlin/info/papdt/express/helper/ui/fragment/settings/SettingsMain.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class SettingsMain : AbsPrefFragment(), Preference.OnPreferenceClickListener, Pr
4343
private val mPrefInstanceId: Preference by PreferenceProperty("firebase_instance_id")
4444
private val mPrefSync: Preference by PreferenceProperty("push_sync")
4545
private val mPrefReqPush: Preference by PreferenceProperty("request_push")
46+
private val mPrefWhatsThis: Preference by PreferenceProperty("push_intro")
4647

4748
// Auto detect
4849
private val mPrefFromClipboard: SwitchPreference by PreferenceProperty("from_clipboard")
@@ -59,6 +60,7 @@ class SettingsMain : AbsPrefFragment(), Preference.OnPreferenceClickListener, Pr
5960
private val mPrefContributors: Preference by PreferenceProperty("contributors")
6061

6162
private var needRegister = false
63+
private var needFreeServer = false
6264

6365
private val database by lazy { PackageDatabase.getInstance(activity) }
6466

@@ -136,6 +138,7 @@ class SettingsMain : AbsPrefFragment(), Preference.OnPreferenceClickListener, Pr
136138
mPrefEnable.onPreferenceChangeListener = this
137139
mPrefApiHost.onPreferenceChangeListener = this
138140
mPrefApiPort.onPreferenceChangeListener = this
141+
mPrefWhatsThis.onPreferenceClickListener = this
139142

140143
// Auto detect
141144
mPrefFromClipboard.onPreferenceChangeListener = this
@@ -167,6 +170,13 @@ class SettingsMain : AbsPrefFragment(), Preference.OnPreferenceClickListener, Pr
167170
)
168171
}
169172

173+
private fun setFreeApiServer() {
174+
mPrefApiHost.text = "pt.api.rabi.coffee"
175+
mPrefApiPort.text = "3000"
176+
SettingsInstance.pushApiHost = "pt.api.rabi.coffee"
177+
SettingsInstance.pushApiPort = 3000
178+
}
179+
170180
override fun onPreferenceClick(pref: Preference): Boolean {
171181
return when (pref) {
172182
// UI
@@ -220,6 +230,25 @@ class SettingsMain : AbsPrefFragment(), Preference.OnPreferenceClickListener, Pr
220230
} else PushApi.requestPush().subscribe { makeSnackbar(it.message, Snackbar.LENGTH_LONG).show() }
221231
true
222232
}
233+
mPrefWhatsThis -> {
234+
activity.buildAlertDialog {
235+
titleRes = R.string.fcm_push_intro_title
236+
messageRes = R.string.fcm_push_intro_msg
237+
okButton()
238+
neutralButton(R.string.fcm_push_no_server_button) { _, _ ->
239+
if (SettingsInstance.clickedDonate) {
240+
setFreeApiServer()
241+
} else {
242+
needFreeServer = true
243+
activity.buildAlertDialog {
244+
messageRes = R.string.no_server_message
245+
okButton()
246+
}.show()
247+
}
248+
}
249+
}.show()
250+
true
251+
}
223252
// Auto detect
224253
mPrefFromScreen -> {
225254
startActivity(Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS))
@@ -242,6 +271,8 @@ class SettingsMain : AbsPrefFragment(), Preference.OnPreferenceClickListener, Pr
242271
makeSnackbar(getString(R.string.toast_copied_successfully), Snackbar.LENGTH_SHORT)
243272
.show()
244273
}
274+
SettingsInstance.clickedDonate = true
275+
if (needFreeServer) setFreeApiServer()
245276
true
246277
}
247278
mPrefLicense -> {

mobile/src/main/res/values-zh-rCN/strings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@
140140
<string name="pref_api_host">服务器地址</string>
141141
<string name="pref_api_port">服务器端口</string>
142142
<string name="pref_request_push">立即请求推送</string>
143+
<string name="pref_whats_this">这是什么?</string>
144+
<string name="fcm_push_intro_title">基于 FCM 推送服务</string>
145+
<string name="fcm_push_intro_msg">我们通过 Firebase 云通知提供了一个更高效的途径来拉取包裹信息。
146+
你可以在自己的服务器上运行水表助手推送服务,然后设置到客户端中。
147+
\n\n客户端将会和服务器同步列表。当新的信息来临时,服务器会通过 FCM 推送通知(客户端需要 Google 服务框架)。
148+
\n\n推送服务源代码 (Node.js) 已经发布在 GitHub。你可以将它下载下来并运行在你的服务器中。
149+
\nGitHub: https://github.com/fython/PackageTracker-NodeServer
150+
</string>
151+
<string name="fcm_push_no_server_button">没有服务器?</string>
152+
<string name="no_server_message">点击 \"通过支付宝捐赠\" 设置后,你可以使用我的自建服务器。</string>
143153

144154
<string name="item_notification_do_not_disturb">勿扰模式</string>
145155
<string name="item_notification_do_not_disturb_desc">在 23:00 到次日 06:00 期间不发出通知。</string>

mobile/src/main/res/values-zh-rTW/strings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@
140140
<string name="pref_api_host">伺服器地址</string>
141141
<string name="pref_api_port">伺服器端口</string>
142142
<string name="pref_request_push">立即請求推送</string>
143+
<string name="pref_whats_this">這是什麼?</string>
144+
<string name="fcm_push_intro_title">基於 FCM 推送服務</string>
145+
<string name="fcm_push_intro_msg">我們通過 Firebase 雲通知提供了一個更高效的途徑來獲取包裹資料。
146+
你可以在自己的伺服器上運行水錶助手推送服務,然後設定到客戶端中。
147+
\n\n客戶端將會與伺服器同步清單。當新的訊息來臨時,伺服器会通過 FCM 推送通知(客戶端需要 Google 服務框架)。
148+
\n\n推送服務程式源代碼 (Node.js) 已經發佈在 GitHub。你可以將它下載下來並運行在你的伺服器中。
149+
\nGitHub: https://github.com/fython/PackageTracker-NodeServer
150+
</string>
151+
<string name="fcm_push_no_server_button">沒有伺服器?</string>
152+
<string name="no_server_message">點擊 \"通過支付寶捐贈\" 設定後,你可以使用我的自建伺服器。</string>
143153

144154
<string name="item_notification_do_not_disturb">勿擾模式</string>
145155
<string name="item_notification_do_not_disturb_desc">在 23:00 至次日 06:00 期間不發出通知。</string>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@
169169
<string name="pref_api_host">Server host</string>
170170
<string name="pref_api_port">Server port</string>
171171
<string name="pref_request_push">Request push now</string>
172+
<string name="pref_whats_this">What\'s this?</string>
173+
<string name="fcm_push_intro_title">FCM-Based Push Service</string>
174+
<string name="fcm_push_intro_msg">We provide a more effective way to pull the latest status of packages with Firebase Cloud Messaging.
175+
You can run Package Tracker Push Server in your own server and set up in client.
176+
\n\nClient will synchronize list to the server. When new status come up, server will push notification through FCM, which is more power-saving push service built in Google Service.
177+
\n\nPush Server source code (Node.js) has been published to GitHub. You can download it and run in your own server.
178+
\nGitHub: https://github.com/fython/PackageTracker-NodeServer
179+
</string>
180+
<string name="fcm_push_no_server_button">I don\'t have a server</string>
181+
<string name="no_server_message">After clicking \"Donate via Alipay\" in settings, you can use my server.</string>
172182

173183
<string name="item_notification_do_not_disturb">Do not disturb mode</string>
174184
<string name="item_notification_do_not_disturb_desc">Don\'t send notifications from 23:00 to 06:00.</string>

mobile/src/main/res/xml/settings_main.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
<Preference android:key="request_push" android:title="@string/pref_request_push"/>
6363

64+
<Preference android:key="push_intro" android:title="@string/pref_whats_this"/>
65+
6466
</PreferenceCategory>
6567

6668
<PreferenceCategory android:title="@string/category_auto_detect_services">

mobile/src/main/res/xml/settings_main_old.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161

6262
<Preference android:key="request_push" android:title="@string/pref_request_push"/>
6363

64+
<Preference android:key="push_intro" android:title="@string/pref_whats_this"/>
65+
6466
</PreferenceCategory>
6567

6668
<PreferenceCategory android:title="@string/category_auto_detect_services">

0 commit comments

Comments
 (0)