Skip to content

Commit

Permalink
Release V1.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbbc committed Jul 9, 2017
1 parent b84f5d8 commit 696eb79
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion GSYVideoPlayer
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
vectorDrawables.useSupportLibrary = true

ndk {
abiFilters 'armeabi-v7a'
abiFilters 'armeabi-v7a', 'x86'
}
}
signingConfigs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,7 +131,8 @@ class MainActivity : BaseActivity() {
.into(avatarImg)

avatarImg.setOnClickListener {
LoginActivity.intentTo(this)
"放个入口在这里,下个版本做登陆系统(・∀・)".toast()
// LoginActivity.intentTo(this)
}

checkUpdate(true)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -210,6 +211,7 @@ class DownloadService: Service() {
file.close()
} catch (error: Exception) {
error.printStackTrace()
processor.onNext(DownloadEvent(DownloadStatus.FAILED))
}
}, {
error ->
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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)
}
}
}

Expand Down

0 comments on commit 696eb79

Please sign in to comment.