2019-01-18 10:12:08 +00:00
|
|
|
/*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Copyright 2019 New Vector Ltd
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2019-01-18 10:12:08 +00:00
|
|
|
*
|
2019-01-25 13:04:59 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2019-01-18 10:12:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-08 15:52:45 +00:00
|
|
|
package im.vector.matrix.android.api.session
|
|
|
|
|
2019-01-16 18:25:43 +00:00
|
|
|
import androidx.annotation.MainThread
|
2019-06-11 14:54:44 +00:00
|
|
|
import androidx.lifecycle.LiveData
|
2018-11-15 11:37:59 +00:00
|
|
|
import im.vector.matrix.android.api.auth.data.SessionParams
|
2019-06-19 08:46:59 +00:00
|
|
|
import im.vector.matrix.android.api.pushrules.PushRuleService
|
2019-04-17 13:48:59 +00:00
|
|
|
import im.vector.matrix.android.api.session.cache.CacheService
|
2019-04-05 16:21:45 +00:00
|
|
|
import im.vector.matrix.android.api.session.content.ContentUploadStateTracker
|
2019-01-23 15:25:24 +00:00
|
|
|
import im.vector.matrix.android.api.session.content.ContentUrlResolver
|
2019-04-02 16:08:43 +00:00
|
|
|
import im.vector.matrix.android.api.session.crypto.CryptoService
|
2019-07-08 17:06:17 +00:00
|
|
|
import im.vector.matrix.android.api.session.file.FileService
|
2018-11-05 16:39:07 +00:00
|
|
|
import im.vector.matrix.android.api.session.group.GroupService
|
2019-06-19 08:46:59 +00:00
|
|
|
import im.vector.matrix.android.api.session.pushers.PushersService
|
2019-05-24 09:35:46 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.RoomDirectoryService
|
2018-10-17 16:21:09 +00:00
|
|
|
import im.vector.matrix.android.api.session.room.RoomService
|
2019-04-03 14:36:45 +00:00
|
|
|
import im.vector.matrix.android.api.session.signout.SignOutService
|
2019-04-12 13:51:20 +00:00
|
|
|
import im.vector.matrix.android.api.session.sync.FilterService
|
2019-06-11 14:54:44 +00:00
|
|
|
import im.vector.matrix.android.api.session.sync.SyncState
|
2019-02-25 20:55:33 +00:00
|
|
|
import im.vector.matrix.android.api.session.user.UserService
|
2018-10-08 15:52:45 +00:00
|
|
|
|
2019-01-18 15:26:17 +00:00
|
|
|
/**
|
|
|
|
* This interface defines interactions with a session.
|
|
|
|
* An instance of a session will be provided by the SDK.
|
|
|
|
*/
|
2019-04-03 14:36:45 +00:00
|
|
|
interface Session :
|
|
|
|
RoomService,
|
2019-05-24 09:35:46 +00:00
|
|
|
RoomDirectoryService,
|
2019-04-03 14:36:45 +00:00
|
|
|
GroupService,
|
|
|
|
UserService,
|
|
|
|
CryptoService,
|
2019-04-17 13:48:59 +00:00
|
|
|
CacheService,
|
2019-04-12 13:51:20 +00:00
|
|
|
SignOutService,
|
2019-06-19 08:46:59 +00:00
|
|
|
FilterService,
|
2019-07-08 17:06:17 +00:00
|
|
|
FileService,
|
2019-06-19 08:46:59 +00:00
|
|
|
PushRuleService,
|
2019-07-04 08:53:46 +00:00
|
|
|
PushersService,
|
|
|
|
InitialSyncProgressService {
|
2018-10-08 15:52:45 +00:00
|
|
|
|
2019-01-18 15:26:17 +00:00
|
|
|
/**
|
|
|
|
* The params associated to the session
|
|
|
|
*/
|
2018-10-23 16:25:28 +00:00
|
|
|
val sessionParams: SessionParams
|
|
|
|
|
2019-07-16 13:50:07 +00:00
|
|
|
/**
|
|
|
|
* Useful shortcut to get access to the userId
|
|
|
|
*/
|
2019-07-04 08:53:46 +00:00
|
|
|
val myUserId: String
|
2019-06-27 13:25:01 +00:00
|
|
|
get() = sessionParams.credentials.userId
|
|
|
|
|
|
|
|
|
2019-01-18 15:26:17 +00:00
|
|
|
/**
|
|
|
|
* This method allow to open a session. It does start some service on the background.
|
|
|
|
*/
|
2018-10-16 13:52:30 +00:00
|
|
|
@MainThread
|
|
|
|
fun open()
|
|
|
|
|
2019-06-20 13:22:40 +00:00
|
|
|
/**
|
|
|
|
* Requires a one time background sync
|
|
|
|
*/
|
|
|
|
fun requireBackgroundSync()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Launches infinite periodic background syncs
|
|
|
|
* THis does not work in doze mode :/
|
|
|
|
* If battery optimization is on it can work in app standby but that's all :/
|
|
|
|
*/
|
|
|
|
fun startAutomaticBackgroundSync(repeatDelay: Long = 30_000L)
|
|
|
|
|
|
|
|
fun stopAnyBackgroundSync()
|
2019-04-12 13:51:20 +00:00
|
|
|
|
|
|
|
/**
|
2019-06-20 13:22:40 +00:00
|
|
|
* This method start the sync thread.
|
2019-04-12 13:51:20 +00:00
|
|
|
*/
|
2019-07-16 13:44:08 +00:00
|
|
|
fun startSync(fromForeground : Boolean)
|
2019-06-19 08:46:59 +00:00
|
|
|
|
2019-06-20 13:22:40 +00:00
|
|
|
/**
|
|
|
|
* This method stop the sync thread.
|
|
|
|
*/
|
|
|
|
fun stopSync()
|
2019-04-12 13:51:20 +00:00
|
|
|
|
2019-06-11 14:54:44 +00:00
|
|
|
/**
|
|
|
|
* This method allows to listen the sync state.
|
|
|
|
* @return a [LiveData] of [SyncState].
|
|
|
|
*/
|
|
|
|
fun syncState(): LiveData<SyncState>
|
|
|
|
|
2019-01-18 15:26:17 +00:00
|
|
|
/**
|
|
|
|
* This method allow to close a session. It does stop some services.
|
|
|
|
*/
|
2018-10-17 16:21:09 +00:00
|
|
|
fun close()
|
|
|
|
|
2019-01-25 13:04:59 +00:00
|
|
|
/**
|
|
|
|
* Returns the ContentUrlResolver associated to the session.
|
|
|
|
*/
|
2019-01-23 15:25:24 +00:00
|
|
|
fun contentUrlResolver(): ContentUrlResolver
|
|
|
|
|
2019-04-05 16:21:45 +00:00
|
|
|
/**
|
|
|
|
* Returns the ContentUploadProgressTracker associated with the session
|
|
|
|
*/
|
|
|
|
fun contentUploadProgressTracker(): ContentUploadStateTracker
|
|
|
|
|
2019-01-18 15:26:17 +00:00
|
|
|
/**
|
|
|
|
* Add a listener to the session.
|
|
|
|
* @param listener the listener to add.
|
|
|
|
*/
|
2019-01-14 15:18:39 +00:00
|
|
|
fun addListener(listener: Listener)
|
|
|
|
|
2019-01-18 15:26:17 +00:00
|
|
|
/**
|
|
|
|
* Remove a listener from the session.
|
|
|
|
* @param listener the listener to remove.
|
|
|
|
*/
|
2019-01-14 15:18:39 +00:00
|
|
|
fun removeListener(listener: Listener)
|
|
|
|
|
2019-01-18 15:26:17 +00:00
|
|
|
/**
|
|
|
|
* A global session listener to get notified for some events.
|
|
|
|
*/
|
2019-04-17 13:48:59 +00:00
|
|
|
interface Listener {
|
|
|
|
/**
|
|
|
|
* The access token is not valid anymore
|
|
|
|
*/
|
|
|
|
fun onInvalidToken()
|
2019-06-11 14:54:44 +00:00
|
|
|
|
2019-04-17 13:48:59 +00:00
|
|
|
}
|
2019-01-14 15:18:39 +00:00
|
|
|
|
2018-10-08 15:52:45 +00:00
|
|
|
}
|