Skip to content

Commit

Permalink
refine offline data notification
Browse files Browse the repository at this point in the history
  • Loading branch information
xdtianyu committed Aug 11, 2019
1 parent baa2f73 commit fef06e1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
11 changes: 5 additions & 6 deletions app/src/main/java/org/xdty/callerinfo/worker/UpgradeWorker.kt
Expand Up @@ -6,7 +6,6 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.work.Worker
Expand Down Expand Up @@ -43,7 +42,6 @@ class UpgradeWorker(context: Context, workerParams: WorkerParameters) : Worker(c
}

override fun doWork(): Result {
Log.d(tag, "doWork")
return mPresenter.upgradeOfflineData(applicationContext)
}

Expand All @@ -54,21 +52,21 @@ class UpgradeWorker(context: Context, workerParams: WorkerParameters) : Worker(c
override fun showSucceedNotification(status: Status) {
val info = applicationContext.getString(R.string.offline_data_version_summary, status.version,
status.count, Utils.getDate(status.timestamp * 1000))
showNotification(applicationContext, applicationContext.getString(R.string.offline_data_upgrade_success, info))
showNotification(applicationContext, applicationContext.getString(R.string.offline_data_upgrade_success), info)
}

override fun showFailedNotification(error: Exception) {
showNotification(applicationContext, applicationContext.getString(R.string.offline_data_upgrade_failed, error.message))
showNotification(applicationContext, applicationContext.getString(R.string.offline_data_upgrade_failed), error.message)
}

private fun showNotification(context: Context, message: String) {
private fun showNotification(context: Context, title: String, message: String?) {
// Make a channel if necessary
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
val name = Constants.VERBOSE_NOTIFICATION_CHANNEL_NAME
val description = Constants.VERBOSE_NOTIFICATION_CHANNEL_DESCRIPTION
val importance = NotificationManager.IMPORTANCE_HIGH
val importance = NotificationManager.IMPORTANCE_LOW
val channel = NotificationChannel(Constants.CHANNEL_ID, name, importance)
channel.description = description

Expand All @@ -86,6 +84,7 @@ class UpgradeWorker(context: Context, workerParams: WorkerParameters) : Worker(c
.setSmallIcon(R.drawable.ic_call_disconnected_24dp)
.setContentIntent(intent)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentTitle(title)
.setStyle(NotificationCompat.BigTextStyle().bigText(message))
.setAutoCancel(true)
.setVibrate(LongArray(0))
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-zh/strings.xml
Expand Up @@ -206,8 +206,8 @@
<string name="hide_plugin_icon">隐藏插件桌面图标</string>
<string name="ignore_battery_optimizations">忽略电池优化</string>
<string name="ignore_battery_optimizations_description">您将跳转到系统电池优化选项,请在所有应用列表中找到应用并选择忽略</string>
<string name="offline_data_upgrade_success">离线数据已经更新到最新: %s</string>
<string name="offline_data_upgrade_failed">离线数据更新失败: %s</string>
<string name="offline_data_upgrade_success">离线数据已更新到最新版本</string>
<string name="offline_data_upgrade_failed">离线数据更新失败</string>
<string name="offline_data_check_now">立即更新离线数据</string>
<string name="offline_data_auto_upgrade">自动更新离线数据</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Expand Up @@ -193,8 +193,8 @@
<string name="offline_data_failed">Offline data update failed, please try again later.</string>
<string name="offline_data_success">Offline data has been updated to latest</string>
<string name="offline_data_version">Offline data status</string>
<string name="offline_data_upgrade_success">Offline data has been updated to latest: %s</string>
<string name="offline_data_upgrade_failed">Offline data upgrade failed: %s</string>
<string name="offline_data_upgrade_success">Offline data has been updated to latest version</string>
<string name="offline_data_upgrade_failed">Offline data upgrade failed</string>
<string name="offline_data_version_summary">Version %1$d, count %2$d, updated at %3$s</string>
<string name="offline_data_auto_upgrade">Automatic offline data update</string>
<string name="offline_data_check_now">Update offline data now</string>
Expand Down

1 comment on commit fef06e1

@xdtianyu
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close #173

Please sign in to comment.