Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
AloqaIM-Android
Commits
ad4bab2f
Commit
ad4bab2f
authored
Dec 08, 2017
by
Leonardo Aramaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement KeepAliveJob and initialized android-job
parent
3c2da86a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
0 deletions
+60
-0
RocketChatApplication.java
.../main/java/chat/rocket/android/RocketChatApplication.java
+2
-0
RocketChatJobCreator.kt
...src/main/java/chat/rocket/android/RocketChatJobCreator.kt
+14
-0
KeepAliveJob.kt
...src/main/java/chat/rocket/android/service/KeepAliveJob.kt
+44
-0
No files found.
app/src/main/java/chat/rocket/android/RocketChatApplication.java
View file @
ad4bab2f
...
...
@@ -5,6 +5,7 @@ import android.support.multidex.MultiDexApplication;
import
android.support.v7.app.AppCompatDelegate
;
import
com.crashlytics.android.Crashlytics
;
import
com.evernote.android.job.JobManager
;
import
java.util.List
;
...
...
@@ -34,6 +35,7 @@ public class RocketChatApplication extends MultiDexApplication {
@Override
public
void
onCreate
()
{
super
.
onCreate
();
JobManager
.
create
(
this
).
addJobCreator
(
new
RocketChatJobCreator
());
DDPClient
.
initialize
(
OkHttpHelper
.
INSTANCE
.
getClientForWebSocket
());
Fabric
.
with
(
this
,
new
Crashlytics
());
...
...
app/src/main/java/chat/rocket/android/RocketChatJobCreator.kt
0 → 100644
View file @
ad4bab2f
package
chat.rocket.android
import
chat.rocket.android.service.KeepAliveJob
import
com.evernote.android.job.Job
import
com.evernote.android.job.JobCreator
class
RocketChatJobCreator
:
JobCreator
{
override
fun
create
(
tag
:
String
):
Job
?
{
when
(
tag
)
{
KeepAliveJob
.
TAG
->
return
KeepAliveJob
()
else
->
return
null
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/service/KeepAliveJob.kt
0 → 100644
View file @
ad4bab2f
package
chat.rocket.android.service
import
chat.rocket.android.RocketChatApplication
import
chat.rocket.android.RocketChatCache
import
com.evernote.android.job.Job
import
com.evernote.android.job.JobManager
import
com.evernote.android.job.JobRequest
import
java.util.concurrent.TimeUnit
class
KeepAliveJob
:
Job
()
{
private
val
connectivityManager
:
ConnectivityManagerApi
private
val
rocketChatCache
:
RocketChatCache
companion
object
{
val
TAG
=
"chat.rocket.android.service.KeepAliveJob"
fun
schedule
()
{
JobRequest
.
Builder
(
TAG
)
.
setExecutionWindow
(
TimeUnit
.
SECONDS
.
toMillis
(
3L
),
TimeUnit
.
SECONDS
.
toMillis
(
10L
))
.
setBackoffCriteria
(
10L
,
JobRequest
.
BackoffPolicy
.
EXPONENTIAL
)
.
setUpdateCurrent
(
true
)
.
setRequiredNetworkType
(
JobRequest
.
NetworkType
.
CONNECTED
)
.
setRequiresCharging
(
false
)
.
setRequirementsEnforced
(
true
)
.
build
()
.
schedule
()
}
fun
cancel
()
{
JobManager
.
instance
().
cancelAllForTag
(
TAG
)
}
}
init
{
val
context
=
RocketChatApplication
.
getInstance
()
connectivityManager
=
ConnectivityManager
.
getInstance
(
context
)
rocketChatCache
=
RocketChatCache
(
context
)
}
override
fun
onRunJob
(
params
:
Params
):
Result
{
connectivityManager
.
keepAliveServer
()
return
Result
.
SUCCESS
}
}
\ No newline at end of file
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