Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Room Park Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav Bogdashkin
Room Park Android
Commits
ce1a143c
Commit
ce1a143c
authored
Apr 29, 2020
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add cancel downloading notification button
parent
78fe02f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
15 deletions
+80
-15
RetrofitModule.kt
...oompark/data/repository/api/retrofit/di/RetrofitModule.kt
+1
-1
TourDownloadService.kt
...ual/roompark/data/service/download/TourDownloadService.kt
+19
-0
NotificationCenter.kt
.../roompark/data/service/notification/NotificationCenter.kt
+60
-14
No files found.
app/src/main/java/com/biganto/visual/roompark/data/repository/api/retrofit/di/RetrofitModule.kt
View file @
ce1a143c
...
@@ -36,7 +36,7 @@ private const val TIMEOUT_SECONDS=120L
...
@@ -36,7 +36,7 @@ private const val TIMEOUT_SECONDS=120L
private
const
val
WRITE_SECONDS
=
120L
private
const
val
WRITE_SECONDS
=
120L
private
const
val
READ_SECONDS
=
120L
private
const
val
READ_SECONDS
=
120L
val
INTERCEPT_LOG_LEVEL
=
HttpLoggingInterceptor
.
Level
.
BODY
val
INTERCEPT_LOG_LEVEL
=
HttpLoggingInterceptor
.
Level
.
NONE
@Module
@Module
class
RetrofitModule
{
class
RetrofitModule
{
...
...
app/src/main/java/com/biganto/visual/roompark/data/service/download/TourDownloadService.kt
View file @
ce1a143c
...
@@ -47,6 +47,8 @@ private const val META_PREDICTION="/tourMeta_"
...
@@ -47,6 +47,8 @@ private const val META_PREDICTION="/tourMeta_"
private
const
val
META_FILE_TYPE
=
".json"
private
const
val
META_FILE_TYPE
=
".json"
const
val
DOWNLOAD_MANAGER_COMMAND_KEY
=
"TOURS_DOWNLOAD_MANAGER_COMMAND"
const
val
DOWNLOAD_MANAGER_COMMAND_KEY
=
"TOURS_DOWNLOAD_MANAGER_COMMAND"
const
val
DOWNLOAD_MANAGER_ADD_IDS_TO_LOAD_COMMAND
=
"ADD_TOUR_IDS_TO_QUEUE"
const
val
DOWNLOAD_MANAGER_ADD_IDS_TO_LOAD_COMMAND
=
"ADD_TOUR_IDS_TO_QUEUE"
const
val
DOWNLOAD_MANAGER_STOP_COMMAND
=
"STOP_SERVICE"
@Singleton
@Singleton
class
DownloadManagerService
@Inject
constructor
(
class
DownloadManagerService
@Inject
constructor
(
...
@@ -117,7 +119,24 @@ class DownloadManagerService @Inject constructor(
...
@@ -117,7 +119,24 @@ class DownloadManagerService @Inject constructor(
return
null
return
null
}
}
override
fun
onStart
(
intent
:
Intent
?,
startId
:
Int
)
{
Timber
.
d
(
"Got intent: $intent"
)
val
v
=
intent
?.
extras
?.
getString
(
DOWNLOAD_MANAGER_COMMAND_KEY
)
Timber
.
d
(
"Got intent: $v"
)
if
(
v
==
DOWNLOAD_MANAGER_STOP_COMMAND
){
Timber
.
d
(
"Got DOWNLOAD_MANAGER_STOP_COMMAND"
)
disposable
.
clear
()
stopSelf
()
}
super
.
onStart
(
intent
,
startId
)
}
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
override
fun
onStartCommand
(
intent
:
Intent
?,
flags
:
Int
,
startId
:
Int
):
Int
{
val
v
=
intent
?.
extras
?.
getString
(
DOWNLOAD_MANAGER_COMMAND_KEY
)
if
(
v
==
DOWNLOAD_MANAGER_STOP_COMMAND
){
disposable
.
clear
()
stopSelf
()
}
// Timber.d(" GOT INTENT $intent with action ${intent?.action}")
// Timber.d(" GOT INTENT $intent with action ${intent?.action}")
// if (intent?.action == NOTIFICATION_INTENT_STOP_SERVICE_ACTION)
// if (intent?.action == NOTIFICATION_INTENT_STOP_SERVICE_ACTION)
// {
// {
...
...
app/src/main/java/com/biganto/visual/roompark/data/service/notification/NotificationCenter.kt
View file @
ce1a143c
...
@@ -2,6 +2,8 @@ package com.biganto.visual.roompark.data.service.notification
...
@@ -2,6 +2,8 @@ package com.biganto.visual.roompark.data.service.notification
import
android.annotation.TargetApi
import
android.annotation.TargetApi
import
android.app.*
import
android.app.*
import
android.app.PendingIntent.FLAG_ONE_SHOT
import
android.app.PendingIntent.FLAG_UPDATE_CURRENT
import
android.content.Context
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.graphics.BitmapFactory
import
android.graphics.BitmapFactory
...
@@ -11,6 +13,9 @@ import androidx.core.app.NotificationCompat
...
@@ -11,6 +13,9 @@ import androidx.core.app.NotificationCompat
import
androidx.core.content.ContextCompat
import
androidx.core.content.ContextCompat
import
com.biganto.visual.roompark.R
import
com.biganto.visual.roompark.R
import
com.biganto.visual.roompark.base.RoomParkMainActivity
import
com.biganto.visual.roompark.base.RoomParkMainActivity
import
com.biganto.visual.roompark.data.service.download.DOWNLOAD_MANAGER_COMMAND_KEY
import
com.biganto.visual.roompark.data.service.download.DOWNLOAD_MANAGER_STOP_COMMAND
import
com.biganto.visual.roompark.data.service.download.DownloadManagerService
import
com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState
import
com.biganto.visual.roomparkvr.data.repository.db.requery.model.DownloadState
import
javax.inject.Inject
import
javax.inject.Inject
import
javax.inject.Singleton
import
javax.inject.Singleton
...
@@ -135,7 +140,7 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
...
@@ -135,7 +140,7 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
val
pendingIntent
=
PendingIntent
.
getActivity
(
context
val
pendingIntent
=
PendingIntent
.
getActivity
(
context
,
PENDING_REQUEST_CODE
,
PENDING_REQUEST_CODE
,
toDownloadsIntent
,
toDownloadsIntent
,
PendingIntent
.
FLAG_ONE_SHOT
,
FLAG_ONE_SHOT
)
)
...
@@ -160,36 +165,77 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
...
@@ -160,36 +165,77 @@ class NotificationCenter @Inject constructor(val context: Application) : INotif
,
noty
)
,
noty
)
}
}
private
val
cancelServicePendingIntent
:
NotificationCompat
.
Action
by
lazy
{
val
stopServiceIntent
=
Intent
(
context
,
DownloadManagerService
::
class
.
java
)
stopServiceIntent
.
putExtra
(
DOWNLOAD_MANAGER_COMMAND_KEY
,
DOWNLOAD_MANAGER_STOP_COMMAND
)
val
pendingStopServiceIntent
=
PendingIntent
.
getService
(
context
,
546
,
stopServiceIntent
,
FLAG_UPDATE_CURRENT
)
NotificationCompat
.
Action
.
Builder
(
R
.
drawable
.
ic_back
,
"Отмена"
,
pendingStopServiceIntent
).
build
()
}
override
fun
donwloadServiceProgressNotfication
(
progress
:
Int
override
fun
donwloadServiceProgressNotfication
(
progress
:
Int
,
progressMax
:
Int
,
progressMax
:
Int
,
indeterminate
:
Boolean
,
indeterminate
:
Boolean
,
message
:
String
){
,
message
:
String
){
val
pendingIntent
=
PendingIntent
.
getActivity
(
context
val
b
=
(
if
(
indeterminate
)
updateProgressNotificationIndeterminate
else
updateProgressNotification
)
b
.
setContentText
(
message
)
b
.
setProgress
(
progress
,
progressMax
,
indeterminate
)
actualNotifyManager
.
notify
(
(
if
(
indeterminate
)
DOWNLOAD_SERVICE_ID
else
TOUR_INFO_SERVICE_ID
)
,
b
.
build
()
)
}
private
val
defPendingIntent
by
lazy
{
PendingIntent
.
getActivity
(
context
,
PENDING_REQUEST_CODE
,
PENDING_REQUEST_CODE
,
toDownloadsIntent
,
toDownloadsIntent
,
PendingIntent
.
FLAG_ONE_SHO
T
,
FLAG_UPDATE_CURREN
T
)
)
}
private
val
updateProgressNotificationIndeterminate
by
lazy
{
val
notification
=
builder
(
if
(
indeterminate
)
builder
else
toursNotyBuilder
)
// builder
.
setOnlyAlertOnce
(
true
)
.
setOnlyAlertOnce
(
true
)
.
setContentTitle
(
context
.
getString
(
R
.
string
.
notification_content_title
))
.
setContentTitle
(
context
.
getString
(
R
.
string
.
notification_content_title
))
.
setContentText
(
message
)
.
setProgress
(
progress
,
progressMax
,
indeterminate
)
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
.
setBadgeIconType
(
NotificationCompat
.
BADGE_ICON_LARGE
)
.
setBadgeIconType
(
NotificationCompat
.
BADGE_ICON_LARGE
)
.
setColor
(
notificationSystemColor
)
.
setColor
(
notificationSystemColor
)
.
setLargeIcon
(
icon
)
.
setLargeIcon
(
icon
)
.
setContentIntent
(
pendingIntent
)
.
setContentIntent
(
defPendingIntent
)
.
addAction
(
cancelServicePendingIntent
)
.
setAutoCancel
(
true
)
.
setAutoCancel
(
true
)
.
build
()
}
actualNotifyManager
.
notify
(
private
val
updateProgressNotification
by
lazy
{
(
if
(
indeterminate
)
DOWNLOAD_SERVICE_ID
else
TOUR_INFO_SERVICE_ID
)
toursNotyBuilder
,
notification
)
.
setOnlyAlertOnce
(
true
)
.
setContentTitle
(
context
.
getString
(
R
.
string
.
notification_content_title
))
.
setSmallIcon
(
R
.
mipmap
.
ic_launcher
)
.
setBadgeIconType
(
NotificationCompat
.
BADGE_ICON_LARGE
)
.
setColor
(
notificationSystemColor
)
.
setLargeIcon
(
icon
)
.
setContentIntent
(
defPendingIntent
)
.
addAction
(
cancelServicePendingIntent
)
.
setAutoCancel
(
true
)
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
O
)
@TargetApi
(
Build
.
VERSION_CODES
.
O
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment