From 696eb795b6f811ce6b92d9d1c95466610cdd4776 Mon Sep 17 00:00:00 2001 From: blackbbc <505968815@qq.com> Date: Sun, 9 Jul 2017 09:57:47 +0800 Subject: [PATCH] Release V1.0.8 --- GSYVideoPlayer | 2 +- app/build.gradle | 2 +- .../tucao/business/home/MainActivity.kt | 9 +++-- .../rxdownload/function/DownloadService.kt | 39 +++++++++++++++++-- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/GSYVideoPlayer b/GSYVideoPlayer index de75884..2677a1a 160000 --- a/GSYVideoPlayer +++ b/GSYVideoPlayer @@ -1 +1 @@ -Subproject commit de75884fc26faa6b52fafc3daf3ae6846f3660ab +Subproject commit 2677a1af1498649a362ea48077f5c79958563b28 diff --git a/app/build.gradle b/app/build.gradle index 99b643c..590483f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,7 +19,7 @@ android { vectorDrawables.useSupportLibrary = true ndk { - abiFilters 'armeabi-v7a' + abiFilters 'armeabi-v7a', 'x86' } } signingConfigs { diff --git a/app/src/main/kotlin/me/sweetll/tucao/business/home/MainActivity.kt b/app/src/main/kotlin/me/sweetll/tucao/business/home/MainActivity.kt index d719c16..3be04e8 100644 --- a/app/src/main/kotlin/me/sweetll/tucao/business/home/MainActivity.kt +++ b/app/src/main/kotlin/me/sweetll/tucao/business/home/MainActivity.kt @@ -55,7 +55,7 @@ import javax.inject.Inject class MainActivity : BaseActivity() { companion object { - const val NOTIFICATION_ID = 1 + const val NOTIFICATION_ID = 10 } lateinit var binding : ActivityMainBinding @@ -131,7 +131,8 @@ class MainActivity : BaseActivity() { .into(avatarImg) avatarImg.setOnClickListener { - LoginActivity.intentTo(this) + "放个入口在这里,下个版本做登陆系统(・∀・)".toast() +// LoginActivity.intentTo(this) } checkUpdate(true) @@ -275,7 +276,7 @@ class MainActivity : BaseActivity() { }) val builder = NotificationCompat.Builder(this) - .setSmallIcon(R.drawable.ic_file_download_white) + .setSmallIcon(R.mipmap.ic_launcher) val notifyMgr = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager processor.sample(500, TimeUnit.MILLISECONDS) @@ -370,7 +371,7 @@ class MainActivity : BaseActivity() { }) val builder = NotificationCompat.Builder(this) - .setSmallIcon(R.drawable.ic_file_download_white) + .setSmallIcon(R.mipmap.ic_launcher) val notifyMgr = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager processor.sample(500, TimeUnit.MILLISECONDS) diff --git a/app/src/main/kotlin/me/sweetll/tucao/rxdownload/function/DownloadService.kt b/app/src/main/kotlin/me/sweetll/tucao/rxdownload/function/DownloadService.kt index f1076fa..8ec12e8 100644 --- a/app/src/main/kotlin/me/sweetll/tucao/rxdownload/function/DownloadService.kt +++ b/app/src/main/kotlin/me/sweetll/tucao/rxdownload/function/DownloadService.kt @@ -42,6 +42,7 @@ class DownloadService: Service() { companion object { const val ONGOING_NOTIFICATION_ID = 1 const val COMPLETED_NOTIFICATION_ID = 2 + const val FAILED_NOTIFICATION_ID =3 const val ACTION_PAUSE = "pause" const val ACTION_CANCEL = "cancel" @@ -210,6 +211,7 @@ class DownloadService: Service() { file.close() } catch (error: Exception) { error.printStackTrace() + processor.onNext(DownloadEvent(DownloadStatus.FAILED)) } }, { error -> @@ -268,6 +270,10 @@ class DownloadService: Service() { mission.bean.save() stopForeground(true) } + DownloadStatus.FAILED -> { + mission.pause = true + mission.bean.save() + } DownloadStatus.COMPLETED -> { mission.bean.save() part.durls.find { @@ -285,6 +291,7 @@ class DownloadService: Service() { } private fun sendNotification(event: DownloadEvent, url: String) { + "Send Notification ${event.status}...".logD() when (event.status) { DownloadStatus.STARTED, DownloadStatus.READY -> { val nfIntent = Intent(this, DownloadActivity::class.java) @@ -308,7 +315,7 @@ class DownloadService: Service() { val piCancel = PendingIntent.getService(this, 0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT) val builder = NotificationCompat.Builder(this) - .setSmallIcon(R.drawable.ic_file_download_white) + .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(event.taskName) .setContentIntent(pendingIntent) .addAction(R.drawable.ic_action_pause, "暂停", piPause) @@ -322,7 +329,7 @@ class DownloadService: Service() { builder.setContentText("连接中...") } val notification = builder.build() - notification.flags = notification.flags or Notification.FLAG_NO_CLEAR or Notification.FLAG_ONGOING_EVENT + notification.flags = notification.flags or Notification.FLAG_NO_CLEAR startForeground(ONGOING_NOTIFICATION_ID, notification) } @@ -339,7 +346,7 @@ class DownloadService: Service() { val builder = NotificationCompat.Builder(this) .setProgress(0, 0, false) - .setSmallIcon(R.drawable.ic_file_download_white) + .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle(event.taskName) .setContentText("${event.totalSize.formatWithUnit()}/已完成") .setContentIntent(pendingIntent) @@ -352,6 +359,32 @@ class DownloadService: Service() { notifyMgr.notify(COMPLETED_NOTIFICATION_ID, notification) } + DownloadStatus.FAILED -> { + val nfIntent = Intent(this, DownloadActivity::class.java) + nfIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP + nfIntent.action = DownloadActivity.ACTION_DOWNLOADING + + val stackBuilder = TaskStackBuilder.create(this) + stackBuilder.addParentStack(DownloadActivity::class.java) + stackBuilder.addNextIntent(nfIntent) + + val pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT) + + val builder = NotificationCompat.Builder(this) + .setProgress(0, 0, false) + .setSmallIcon(R.mipmap.ic_launcher) + .setContentTitle(event.taskName) + .setContentText("下载失败") + .setContentIntent(pendingIntent) + val notification = builder.build() + notification.flags = notification.flags or Notification.FLAG_AUTO_CANCEL + + val notifyMgr = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager + + stopForeground(true) + + notifyMgr.notify(FAILED_NOTIFICATION_ID, notification) + } } }