diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/PushExt.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/PushExt.kt deleted file mode 100644 index fd9a95be..00000000 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/PushExt.kt +++ /dev/null @@ -1,2 +0,0 @@ -package im.vector.matrix.android.api.pushrules - diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushrulesResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/GetPushRulesResponse.kt similarity index 73% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushrulesResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/GetPushRulesResponse.kt index 75ac3aee..8d567f94 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushrulesResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/GetPushRulesResponse.kt @@ -15,16 +15,23 @@ */ package im.vector.matrix.android.api.pushrules.rest +import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.matrix.android.api.pushrules.rest.Ruleset /** * All push rulesets for a user. */ @JsonClass(generateAdapter = true) -data class PushrulesResponse( - //Global rules, account level applying to all devices +data class GetPushRulesResponse( + /** + * Global rules, account level applying to all devices + */ + @Json(name = "global") val global: Ruleset, - //Device specific rules, apply only to current device + + /** + * Device specific rules, apply only to current device + */ + @Json(name = "device") val device: Ruleset? = null ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt index fac0fc51..8e63e864 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushCondition.kt @@ -22,15 +22,26 @@ import timber.log.Timber @JsonClass(generateAdapter = true) data class PushCondition( - //Required. The kind of condition to apply. + /** + * Required. The kind of condition to apply. + */ val kind: String, - //Required for event_match conditions. The dot- separated field of the event to match. + + /** + * Required for event_match conditions. The dot- separated field of the event to match. + */ + val key: String? = null, - //Required for event_match conditions. + /** + *Required for event_match conditions. + */ + val pattern: String? = null, - //Required for room_member_count conditions. - // A decimal integer optionally prefixed by one of, ==, <, >, >= or <=. - // A prefix of < matches rooms where the member count is strictly less than the given number and so forth. If no prefix is present, this parameter defaults to ==. + /** + * Required for room_member_count conditions. + * A decimal integer optionally prefixed by one of, ==, <, >, >= or <=. + * A prefix of < matches rooms where the member count is strictly less than the given number and so forth. If no prefix is present, this parameter defaults to ==. + */ @Json(name = "is") val iz: String? = null ) { @@ -58,7 +69,7 @@ data class PushCondition( Condition.Kind.sender_notification_permission -> { this.key?.let { SenderNotificationPermissionCondition(it) } } - Condition.Kind.UNRECOGNIZE -> { + Condition.Kind.UNRECOGNIZE -> { Timber.e("Unknwon kind $kind") null } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushRule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushRule.kt index 2e090a24..1e36a0d8 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushRule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/pushrules/rest/PushRule.kt @@ -22,17 +22,29 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) data class PushRule( - //Required. The domainActions to perform when this rule is matched. + /** + * Required. The actions to perform when this rule is matched. + */ val actions: List, - //Required. Whether this is a default rule, or has been set explicitly. + /** + * Required. Whether this is a default rule, or has been set explicitly. + */ val default: Boolean? = false, - //Required. Whether the push rule is enabled or not. + /** + * Required. Whether the push rule is enabled or not. + */ val enabled: Boolean, - //Required. The ID of this rule. + /** + * Required. The ID of this rule. + */ @Json(name = "rule_id") val ruleId: String, - //The conditions that must hold true for an event in order for a rule to be applied to an event + /** + * The conditions that must hold true for an event in order for a rule to be applied to an event + */ val conditions: List? = null, - //The glob-style pattern to match against. Only applicable to content rules. + /** + * The glob-style pattern to match against. Only applicable to content rules. + */ val pattern: String? = null ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/pushers/Pusher.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/pushers/Pusher.kt index eb71b954..7b1fa3bb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/pushers/Pusher.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/pushers/Pusher.kt @@ -32,7 +32,7 @@ data class Pusher( ) enum class PusherState { - UNREGISTRED, + UNREGISTERED, REGISTERING, UNREGISTERING, REGISTERED, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PushRuleEntity.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PushRuleEntity.kt index 30ef90a8..dd6cc790 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PushRuleEntity.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PushRuleEntity.kt @@ -19,7 +19,7 @@ import io.realm.RealmList import io.realm.RealmObject internal open class PushRuleEntity( - //Required. The domainActions to perform when this rule is matched. + //Required. The actions to perform when this rule is matched. var actionsStr: String? = null, //Required. Whether this is a default rule, or has been set explicitly. var default: Boolean = false, diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt index 553a3e72..6e567c0a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/model/PusherEntity.kt @@ -38,7 +38,7 @@ internal open class PusherEntity( var lang: String? = null, var data: PusherDataEntity? = null ) : RealmObject() { - private var stateStr: String = PusherState.UNREGISTRED.name + private var stateStr: String = PusherState.UNREGISTERED.name var state: PusherState get() { @@ -46,7 +46,7 @@ internal open class PusherEntity( return PusherState.valueOf(stateStr) } catch (e: Exception) { //can this happen? - return PusherState.UNREGISTRED + return PusherState.UNREGISTERED } } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/PushersQueries.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/PushersQueries.kt index ff91665f..b7f54f17 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/PushersQueries.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/database/query/PushersQueries.kt @@ -15,15 +15,17 @@ */ package im.vector.matrix.android.internal.database.query -import im.vector.matrix.android.api.pushrules.rest.PushRule -import im.vector.matrix.android.internal.database.model.* import im.vector.matrix.android.internal.database.model.PushRulesEntity +import im.vector.matrix.android.internal.database.model.PushRulesEntityFields import im.vector.matrix.android.internal.database.model.PusherEntity +import im.vector.matrix.android.internal.database.model.PusherEntityFields import io.realm.Realm import io.realm.RealmQuery import io.realm.kotlin.where -internal fun PusherEntity.Companion.where(realm: Realm, userId: String, pushKey: String? = null): RealmQuery { +internal fun PusherEntity.Companion.where(realm: Realm, + userId: String, + pushKey: String? = null): RealmQuery { return realm.where() .equalTo(PusherEntityFields.USER_ID, userId) .apply { @@ -33,9 +35,12 @@ internal fun PusherEntity.Companion.where(realm: Realm, userId: String, pushKey: } } -internal fun PushRulesEntity.Companion.where(realm: Realm, userId: String, scope: String, rulesetKey: String) : RealmQuery { - return realm.where() - .equalTo(PushRulesEntityFields.USER_ID,userId) - .equalTo(PushRulesEntityFields.SCOPE,scope) - .equalTo(PushRulesEntityFields.RULESET_KEY,rulesetKey) +internal fun PushRulesEntity.Companion.where(realm: Realm, + userId: String, + scope: String, + ruleSetKey: String): RealmQuery { + return realm.where() + .equalTo(PushRulesEntityFields.USER_ID, userId) + .equalTo(PushRulesEntityFields.SCOPE, scope) + .equalTo(PushRulesEntityFields.RULESET_KEY, ruleSetKey) } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index a3a08976..ef2fe857 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -172,7 +172,7 @@ internal class SessionModule(private val sessionParams: SessionParams) { scope(DefaultSession.SCOPE) { val retrofit: Retrofit = get() - retrofit.create(PushrulesApi::class.java) + retrofit.create(PushRulesApi::class.java) } scope(DefaultSession.SCOPE) { @@ -184,7 +184,7 @@ internal class SessionModule(private val sessionParams: SessionParams) { } scope(DefaultSession.SCOPE) { - DefaultGetPushrulesTask(get()) as GetPushRulesTask + DefaultGetPushRulesTask(get()) as GetPushRulesTask } scope(DefaultSession.SCOPE) { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt index eb828de2..afaab486 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/DefaultPushRuleService.kt @@ -20,8 +20,8 @@ import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.auth.data.SessionParams import im.vector.matrix.android.api.pushrules.Action import im.vector.matrix.android.api.pushrules.PushRuleService +import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse import im.vector.matrix.android.api.pushrules.rest.PushRule -import im.vector.matrix.android.api.pushrules.rest.PushrulesResponse import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.internal.database.mapper.PushRulesMapper import im.vector.matrix.android.internal.database.model.PushRulesEntity @@ -47,8 +47,8 @@ internal class DefaultPushRuleService( override fun fetchPushRules(scope: String) { pushRulesTask .configureWith(Unit) - .dispatchTo(object : MatrixCallback { - override fun onSuccess(data: PushrulesResponse) { + .dispatchTo(object : MatrixCallback { + override fun onSuccess(data: GetPushRulesResponse) { monarchy.runTransactionSync { realm -> //clear existings? //TODO @@ -56,7 +56,7 @@ internal class DefaultPushRuleService( .equalTo(PusherEntityFields.USER_ID, sessionParams.credentials.userId) .findAll().deleteAllFromRealm() - var content = PushRulesEntity(sessionParams.credentials.userId, scope, "content") + val content = PushRulesEntity(sessionParams.credentials.userId, scope, "content") data.global.content?.forEach { rule -> PushRulesMapper.map(rule).also { content.pushRules.add(it) @@ -64,7 +64,7 @@ internal class DefaultPushRuleService( } realm.insertOrUpdate(content) - var override = PushRulesEntity(sessionParams.credentials.userId, scope, "override") + val override = PushRulesEntity(sessionParams.credentials.userId, scope, "override") data.global.override?.forEach { rule -> PushRulesMapper.map(rule).also { override.pushRules.add(it) @@ -72,7 +72,7 @@ internal class DefaultPushRuleService( } realm.insertOrUpdate(override) - var rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room") + val rooms = PushRulesEntity(sessionParams.credentials.userId, scope, "room") data.global.room?.forEach { rule -> PushRulesMapper.map(rule).also { rooms.pushRules.add(it) @@ -80,7 +80,7 @@ internal class DefaultPushRuleService( } realm.insertOrUpdate(rooms) - var senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender") + val senders = PushRulesEntity(sessionParams.credentials.userId, scope, "sender") data.global.sender?.forEach { rule -> PushRulesMapper.map(rule).also { senders.pushRules.add(it) @@ -88,7 +88,7 @@ internal class DefaultPushRuleService( } realm.insertOrUpdate(senders) - var underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride") + val underrides = PushRulesEntity(sessionParams.credentials.userId, scope, "underride") data.global.underride?.forEach { rule -> PushRulesMapper.map(rule).also { underrides.pushRules.add(it) @@ -106,35 +106,24 @@ internal class DefaultPushRuleService( override fun getPushrules(scope: String): List { var contentRules: List = emptyList() + var overrideRules: List = emptyList() + var roomRules: List = emptyList() + var senderRules: List = emptyList() + var underrideRules: List = emptyList() + monarchy.doWithRealm { realm -> PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "content").findFirst()?.let { re -> contentRules = re.pushRules.map { PushRulesMapper.mapContentRule(it) } } - } - - var overrideRules: List = emptyList() - monarchy.doWithRealm { realm -> PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "override").findFirst()?.let { re -> overrideRules = re.pushRules.map { PushRulesMapper.map(it) } } - } - - var roomRules: List = emptyList() - monarchy.doWithRealm { realm -> PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "room").findFirst()?.let { re -> roomRules = re.pushRules.map { PushRulesMapper.mapRoomRule(it) } } - } - - var senderRules: List = emptyList() - monarchy.doWithRealm { realm -> PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "sender").findFirst()?.let { re -> senderRules = re.pushRules.map { PushRulesMapper.mapSenderRule(it) } } - } - - var underrideRules: List = emptyList() - monarchy.doWithRealm { realm -> PushRulesEntity.where(realm, sessionParams.credentials.userId, scope, "underride").findFirst()?.let { re -> underrideRules = re.pushRules.map { PushRulesMapper.map(it) } } @@ -184,6 +173,4 @@ internal class DefaultPushRuleService( } } - - } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt index 40ddb1eb..52238775 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt @@ -47,8 +47,8 @@ internal class DefaultPusherService( override fun refreshPushers() { getPusherTask .configureWith(Unit) - .dispatchTo(object : MatrixCallback { - override fun onSuccess(data: PushersResponse) { + .dispatchTo(object : MatrixCallback { + override fun onSuccess(data: GetPushersResponse) { monarchy.runTransactionSync { realm -> //clear existings? realm.where(PusherEntity::class.java) @@ -66,9 +66,6 @@ internal class DefaultPusherService( .executeBy(taskExecutor) } - /** - * - */ override fun addHttpPusher(pushkey: String, appId: String, profileTag: String, lang: String, appDisplayName: String, deviceDisplayName: String, url: String, append: Boolean, withEventIdOnly: Boolean) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushersResponse.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersResponse.kt similarity index 87% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushersResponse.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersResponse.kt index 426b5c9e..4f4cac93 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushersResponse.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersResponse.kt @@ -20,6 +20,7 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) -internal class PushersResponse( - @Json(name = "pushers") val pushers: List? = null +internal class GetPushersResponse( + @Json(name = "pushers") + val pushers: List? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt index 5c730d14..8587ab85 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushersTask.kt @@ -19,11 +19,11 @@ import arrow.core.Try import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task -internal interface GetPushersTask : Task +internal interface GetPushersTask : Task internal class DefaultGetPusherTask(private val pushersAPI: PushersAPI) : GetPushersTask { - override suspend fun execute(params: Unit): Try { + override suspend fun execute(params: Unit): Try { return executeRequest { apiCall = pushersAPI.getPushers() } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushrulesTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushrulesTask.kt index 1ce8c21e..b2c04842 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushrulesTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/GetPushrulesTask.kt @@ -16,18 +16,18 @@ package im.vector.matrix.android.internal.session.pushers import arrow.core.Try -import im.vector.matrix.android.api.pushrules.rest.PushrulesResponse +import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse import im.vector.matrix.android.internal.network.executeRequest import im.vector.matrix.android.internal.task.Task -internal interface GetPushRulesTask : Task +internal interface GetPushRulesTask : Task -internal class DefaultGetPushrulesTask(private val pushrulesApi: PushrulesApi) : GetPushRulesTask { +internal class DefaultGetPushRulesTask(private val pushRulesApi: PushRulesApi) : GetPushRulesTask { - override suspend fun execute(params: Unit): Try { + override suspend fun execute(params: Unit): Try { return executeRequest { - apiCall = pushrulesApi.getAllRules() + apiCall = pushRulesApi.getAllRules() } } } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusher.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusher.kt index e16bd78e..d262eeb7 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusher.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusher.kt @@ -20,14 +20,7 @@ import com.squareup.moshi.JsonClass import im.vector.matrix.android.internal.di.SerializeNulls /** - * pushkey string Required. This is a unique identifier for this pusher. See /set for more detail. Max length, 512 bytes. - * kind string Required. The kind of pusher. "http" is a pusher that sends HTTP pokes. - * app_id string Required. This is a reverse-DNS style identifier for the application. Max length, 64 chars. - * app_display_name string Required. A string that will allow the user to identify what application owns this pusher. - * device_display_name string Required. A string that will allow the user to identify what device owns this pusher. - * profile_tag string This string determines which set of device specific rules this pusher executes. - * lang string Required. The preferred language for receiving notifications (e.g. 'en' or 'en-US') - * data PusherData Required. A dictionary of information for the pusher implementation itself. + * Example: * * * { @@ -50,20 +43,61 @@ import im.vector.matrix.android.internal.di.SerializeNulls @JsonClass(generateAdapter = true) internal data class JsonPusher( - @Json(name = "pushkey") val pushKey: String, - @Json(name = "kind") @SerializeNulls val kind: String?, - @Json(name = "app_id") val appId: String, - @Json(name = "app_display_name") val appDisplayName: String? = null, - @Json(name = "device_display_name") val deviceDisplayName: String? = null, - @Json(name = "profile_tag") val profileTag: String? = null, - @Json(name = "lang") val lang: String? = null, - @Json(name = "data") val data: JsonPusherData? = null, + /** + * Required. This is a unique identifier for this pusher. See /set for more detail. Max length, 512 bytes. + */ + @Json(name = "pushkey") + val pushKey: String, + + /** + * Required. The kind of pusher. "http" is a pusher that sends HTTP pokes. + */ + @SerializeNulls + @Json(name = "kind") + val kind: String?, + + /** + * Required. This is a reverse-DNS style identifier for the application. Max length, 64 chars. + */ + @Json(name = "app_id") + val appId: String, + + /** + * Required. A string that will allow the user to identify what application owns this pusher. + */ + @Json(name = "app_display_name") + val appDisplayName: String? = null, + + /** + * Required. A string that will allow the user to identify what device owns this pusher. + */ + @Json(name = "device_display_name") + val deviceDisplayName: String? = null, + + /** + * This string determines which set of device specific rules this pusher executes. + */ + @Json(name = "profile_tag") + val profileTag: String? = null, + + /** + * Required. The preferred language for receiving notifications (e.g. 'en' or 'en-US') + */ + @Json(name = "lang") + val lang: String? = null, + + /** + * Required. A dictionary of information for the pusher implementation itself. + */ + @Json(name = "data") + val data: JsonPusherData? = null, // Only used to update add Pusher (body of api request) // Used If true, the homeserver should add another pusher with the given pushkey and App ID in addition // to any others with different user IDs. // Otherwise, the homeserver must remove any other pushers with the same App ID and pushkey for different users. // The default is false. - @Json(name = "append") val append: Boolean? = false + @Json(name = "append") + val append: Boolean? = false ) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusherData.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusherData.kt index 0f0a55ee..95898aca 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusherData.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/JsonPusherData.kt @@ -20,8 +20,15 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) internal data class JsonPusherData( - //Required if kind is http. The URL to use to send notifications to. - @Json(name = "url") val url: String? = null, - //The format to use when sending notifications to the Push Gateway. - @Json(name = "format") val format: String? = null + /** + * Required if kind is http. The URL to use to send notifications to. + */ + @Json(name = "url") + val url: String? = null, + + /** + * The format to use when sending notifications to the Push Gateway. + */ + @Json(name = "format") + val format: String? = null ) \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushrulesApi.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushRulesApi.kt similarity index 69% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushrulesApi.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushRulesApi.kt index cdec3543..eed08622 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushrulesApi.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushRulesApi.kt @@ -16,18 +16,18 @@ package im.vector.matrix.android.internal.session.pushers import im.vector.matrix.android.api.pushrules.rest.PushRule -import im.vector.matrix.android.api.pushrules.rest.PushrulesResponse +import im.vector.matrix.android.api.pushrules.rest.GetPushRulesResponse import im.vector.matrix.android.internal.network.NetworkConstants import retrofit2.Call import retrofit2.http.* -internal interface PushrulesApi { +internal interface PushRulesApi { /** * Get all push rules */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/") - fun getAllRules(): Call + fun getAllRules(): Call /** * Update the ruleID enable status @@ -37,28 +37,36 @@ internal interface PushrulesApi { * @param enable the new enable status */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/enabled") - fun updateEnableRuleStatus(@Path("kind") kind: String, @Path("ruleId") ruleId: String, @Body enable: Boolean?): Call + fun updateEnableRuleStatus(@Path("kind") kind: String, + @Path("ruleId") ruleId: String, + @Body enable: Boolean?) + : Call /** - * Update the ruleID enable status + * Update the ruleID action * * @param kind the notification kind (sender, room...) * @param ruleId the ruleId * @param actions the actions */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}/actions") - fun updateRuleActions(@Path("kind") kind: String, @Path("ruleId") ruleId: String, @Body actions: Any): Call + fun updateRuleActions(@Path("kind") kind: String, + @Path("ruleId") ruleId: String, + @Body actions: Any) + : Call /** - * Update the ruleID enable status + * Delete a rule * * @param kind the notification kind (sender, room...) * @param ruleId the ruleId */ @DELETE(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}") - fun deleteRule(@Path("kind") kind: String, @Path("ruleId") ruleId: String): Call + fun deleteRule(@Path("kind") kind: String, + @Path("ruleId") ruleId: String) + : Call /** * Add the ruleID enable status @@ -68,5 +76,8 @@ internal interface PushrulesApi { * @param rule the rule to add. */ @PUT(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushrules/global/{kind}/{ruleId}") - fun addRule(@Path("kind") kind: String, @Path("ruleId") ruleId: String, @Body rule: PushRule): Call + fun addRule(@Path("kind") kind: String, + @Path("ruleId") ruleId: String, + @Body rule: PushRule) + : Call } \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushersAPI.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushersAPI.kt index 632b4ed7..7516e48a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushersAPI.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/PushersAPI.kt @@ -27,14 +27,16 @@ internal interface PushersAPI { /** * Get the pushers for this user. * - * Ref: https://matrix.org/docs/spec/client_server/r0.4.0.html#get-matrix-client-r0-thirdparty-protocols + * Ref: https://matrix.org/docs/spec/client_server/latest#get-matrix-client-r0-pushers */ @GET(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers") - fun getPushers(): Call + fun getPushers(): Call /** * This endpoint allows the creation, modification and deletion of pushers for this user ID. * The behaviour of this endpoint varies depending on the values in the JSON body. + * + * Ref: https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-pushers-set */ @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "pushers/set") fun setPusher(@Body jsonPusher: JsonPusher): Call diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/RemovePusherTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/RemovePusherTask.kt index edd2fdae..3548afb5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/RemovePusherTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/RemovePusherTask.kt @@ -12,7 +12,9 @@ import im.vector.matrix.android.internal.task.Task import im.vector.matrix.android.internal.util.tryTransactionSync internal interface RemovePusherTask : Task { - data class Params(val userId: String, val pushKey: String, val pushAppId: String) + data class Params(val userId: String, + val pushKey: String, + val pushAppId: String) } internal class DefaultRemovePusherTask( @@ -35,10 +37,11 @@ internal class DefaultRemovePusherTask( } }.flatMap { executeRequest { - val deleteRequest = JsonPusher( + val deleteBody = JsonPusher( pushKey = params.pushKey, appId = params.pushAppId, - kind = null, //null deletes the pusher + // kind null deletes the pusher + kind = null, appDisplayName = it.appDisplayName ?: "", deviceDisplayName = it.deviceDisplayName ?: "", profileTag = it.profileTag ?: "", @@ -46,7 +49,7 @@ internal class DefaultRemovePusherTask( data = JsonPusherData(it.data.url, it.data.format), append = false ) - apiCall = pushersAPI.setPusher(deleteRequest) + apiCall = pushersAPI.setPusher(deleteBody) } }.flatMap { monarchy.tryTransactionSync { diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt index 63bc3f43..01df2128 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/sync/SyncTask.kt @@ -29,7 +29,7 @@ import im.vector.matrix.android.internal.task.Task internal interface SyncTask : Task { - data class Params(val token: String?, var timeout: Long = 30_1000L) + data class Params(val token: String?, var timeout: Long = 30_000L) } diff --git a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt index eb337ab3..9c0e4e61 100644 --- a/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt +++ b/matrix-sdk-android/src/test/java/im/vector/matrix/android/api/pushrules/PushRuleActionsTest.kt @@ -50,7 +50,7 @@ class PushRuleActionsTest { val pushRule = MoshiProvider.providesMoshi().adapter(PushRule::class.java).fromJson(rawPushRule) Assert.assertNotNull("Should have parsed the rule", pushRule) - Assert.assertNotNull("Failed to parse domainActions", Action.mapFrom(pushRule!!)) + Assert.assertNotNull("Failed to parse actions", Action.mapFrom(pushRule!!)) val actions = Action.mapFrom(pushRule) Assert.assertEquals(3, actions!!.size) diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt index f6d93d78..25f380f4 100755 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt @@ -33,8 +33,6 @@ import timber.log.Timber * It has an alter ego in the fdroid variant. */ object FcmHelper { - private val LOG_TAG = FcmHelper::class.java.simpleName - private val PREFS_KEY_FCM_TOKEN = "FCM_TOKEN" @@ -51,6 +49,7 @@ object FcmHelper { /** * Store FCM token to the SharedPrefs + * TODO Store in realm * * @param context android context * @param token the token to store diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index ee63d806..b01d3891 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -54,7 +54,7 @@ import im.vector.riotredesign.features.workers.signout.SignOutViewModel class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { - // Supported navigation domainActions for this Activity + // Supported navigation actions for this Activity sealed class Navigation { object OpenDrawer : Navigation() } diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewState.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewState.kt index 2cf41349..927bbba1 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewState.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/RoomDetailViewState.kt @@ -30,7 +30,7 @@ import im.vector.matrix.android.api.session.user.model.User * QUOTE: User is currently quoting a message * EDIT: User is currently editing an existing message * - * Depending on the state the bottom toolbar will change (icons/preview/domainActions...) + * Depending on the state the bottom toolbar will change (icons/preview/actions...) */ enum class SendMode { REGULAR, diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt index 85b90129..84cfc40f 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/ActionsHandler.kt @@ -20,7 +20,7 @@ import androidx.lifecycle.ViewModel import im.vector.riotredesign.core.utils.LiveEvent /** - * Activity shared view model to handle message domainActions + * Activity shared view model to handle message actions */ class ActionsHandler : ViewModel() { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt index f80a62f8..95777b8d 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt @@ -38,8 +38,8 @@ import im.vector.riotredesign.features.home.room.detail.timeline.item.MessageInf import kotlinx.android.synthetic.main.bottom_sheet_message_actions.* /** - * Bottom sheet fragment that shows a message preview with list of contextual domainActions - * (Includes fragments for quick reactions and list of domainActions) + * Bottom sheet fragment that shows a message preview with list of contextual actions + * (Includes fragments for quick reactions and list of actions) */ class MessageActionsBottomSheet : BaseMvRxBottomSheetDialog() { diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt index f523a777..1d9c33f6 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/action/MessageMenuViewModel.kt @@ -37,7 +37,7 @@ data class SimpleAction(val uid: String, val titleRes: Int, val iconResId: Int?, data class MessageMenuState(val actions: List = emptyList()) : MvRxState /** - * Manages list domainActions for a given message (copy / paste / forward...) + * Manages list actions for a given message (copy / paste / forward...) */ class MessageMenuViewModel(initialState: MessageMenuState) : VectorViewModel(initialState) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt index 7ef7a720..1d7d5e21 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotifiableEventResolver.kt @@ -30,12 +30,6 @@ import im.vector.riotredesign.core.resources.StringProvider import im.vector.riotredesign.features.home.room.detail.timeline.format.NoticeEventFormatter import timber.log.Timber -// TODO Remove -class RoomState { - -} - - /** * The notifiable event resolver is able to create a NotifiableEvent (view model for notifications) from an sdk Event. * It is used as a bridge between the Event Thread and the NotificationDrawerManager. diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt index 574d2679..36692b7d 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationBroadcastReceiver.kt @@ -27,7 +27,7 @@ import org.koin.standalone.inject import timber.log.Timber /** - * Receives domainActions broadcast by notification (on click, on dismiss, inline replies, etc.) + * Receives actions broadcast by notification (on click, on dismiss, inline replies, etc.) */ class NotificationBroadcastReceiver : BroadcastReceiver(), KoinComponent { diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationUtils.kt index aed05d25..c8d478db 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationUtils.kt @@ -64,7 +64,7 @@ object NotificationUtils { const val NOTIFICATION_ID_FOREGROUND_SERVICE = 61 /* ========================================================================================== - * IDs for domainActions + * IDs for actions * ========================================================================================== */ private const val JOIN_ACTION = "${BuildConfig.APPLICATION_ID}.NotificationActions.JOIN_ACTION" @@ -426,7 +426,7 @@ object NotificationUtils { priority = NotificationCompat.PRIORITY_LOW } - //Add domainActions and notification intents + //Add actions and notification intents // Mark room as read val markRoomReadIntent = Intent(context, NotificationBroadcastReceiver::class.java) markRoomReadIntent.action = MARK_ROOM_READ_ACTION diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/OutdatedEventDetector.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/OutdatedEventDetector.kt index 067ab9e7..a93f5dfe 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/OutdatedEventDetector.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/OutdatedEventDetector.kt @@ -17,7 +17,7 @@ package im.vector.riotredesign.features.notifications import im.vector.matrix.android.api.Matrix -class OutdatedEventDetector() { +class OutdatedEventDetector { /** * Returns true if the given event is outdated. diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt index 458db906..a3927462 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 + * + * 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. + */ + package im.vector.riotredesign.features.notifications import im.vector.matrix.android.api.pushrules.Action diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt index 6cff9f2d..1a967db0 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 + * + * 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. + */ + package im.vector.riotredesign.features.settings import android.os.Bundle @@ -5,15 +21,13 @@ import androidx.preference.Preference import androidx.preference.SwitchPreference import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.MatrixCallback -import im.vector.matrix.android.api.session.pushers.PushersService import im.vector.riotredesign.R import im.vector.riotredesign.core.platform.VectorPreferenceFragment import im.vector.riotredesign.core.pushers.PushersManager import im.vector.riotredesign.push.fcm.FcmHelper -import org.koin.android.ext.android.get import org.koin.android.ext.android.inject - +// Referenced in vector_settings_preferences_root.xml class VectorSettingsNotificationPreferenceFragment : VectorPreferenceFragment() { override var titleRes: Int = R.string.settings_notifications diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragmentV2.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragmentV2.kt index 0ef9d93a..b29db440 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragmentV2.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragmentV2.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 + * + * 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. + */ + package im.vector.riotredesign.features.settings import android.os.Bundle diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewayItem.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewayItem.kt index f57d76b8..4e3e1166 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewayItem.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewayItem.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2019 New Vector Ltd + * + * 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 + * + * 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. + */ + package im.vector.riotredesign.features.settings.push import android.widget.TextView @@ -17,6 +33,7 @@ abstract class PushGatewayItem : EpoxyModelWithHolder() override fun bind(holder: Holder) { holder.kind.text = when (pusher.kind) { + // TODO Create const "http" -> "Http Pusher" "mail" -> "Email Pusher" else -> pusher.kind diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysFragment.kt index c468955f..1ea57264 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysFragment.kt @@ -30,6 +30,7 @@ import im.vector.riotredesign.core.resources.StringProvider import im.vector.riotredesign.core.ui.list.genericFooterItem import kotlinx.android.synthetic.main.fragment_generic_recycler_epoxy.* +// Referenced in vector_settings_notifications.xml class PushGatewaysFragment : VectorBaseFragment() { override fun getLayoutResId(): Int = R.layout.fragment_generic_recycler_epoxy @@ -50,16 +51,16 @@ class PushGatewaysFragment : VectorBaseFragment() { val dividerItemDecoration = DividerItemDecoration(epoxyRecyclerView.context, lmgr.orientation) epoxyRecyclerView.addItemDecoration(dividerItemDecoration) - epoxyRecyclerView.adapter = epoxyController.adapter + epoxyRecyclerView.setController(epoxyController) } - override fun invalidate() = withState(viewModel) { - epoxyController.setData(it) + override fun invalidate() = withState(viewModel) { state -> + epoxyController.setData(state) } class PushGateWayController(private val stringProvider: StringProvider) : TypedEpoxyController() { override fun buildModels(data: PushGatewayViewState?) { - data?.pushgateways?.invoke()?.let { pushers -> + data?.pushGateways?.invoke()?.let { pushers -> if (pushers.isEmpty()) { genericFooterItem { id("footer") diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysViewModel.kt index 69c0b9c4..edb032a0 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushGatewaysViewModel.kt @@ -25,12 +25,11 @@ import org.koin.android.ext.android.get data class PushGatewayViewState( - val pushgateways: Async> = Uninitialized) - : MvRxState + val pushGateways: Async> = Uninitialized +) : MvRxState class PushGatewaysViewModel(initialState: PushGatewayViewState) : VectorViewModel(initialState) { - companion object : MvRxViewModelFactory { override fun create(viewModelContext: ViewModelContext, state: PushGatewayViewState): PushGatewaysViewModel? { diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRuleItem.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRuleItem.kt index 47f41e91..c723f4ef 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRuleItem.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRuleItem.kt @@ -23,6 +23,7 @@ abstract class PushRuleItem : EpoxyModelWithHolder() { @EpoxyAttribute lateinit var pushRule: PushRule + // TODO i18n @SuppressLint("SetTextI18n") override fun bind(holder: Holder) { val context = holder.view.context @@ -48,7 +49,7 @@ abstract class PushRuleItem : EpoxyModelWithHolder() { holder.actionIcon.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_action_dont_notify)) } - var description = StringBuffer() + val description = StringBuffer() pushRule.conditions?.forEachIndexed { i, condition -> if (i > 0) description.append("\n") description.append(condition.asExecutableCondition()?.technicalDescription() diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesFragment.kt index 7f73f893..3d5881db 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesFragment.kt @@ -29,14 +29,14 @@ import im.vector.riotredesign.core.resources.StringProvider import im.vector.riotredesign.core.ui.list.genericFooterItem import kotlinx.android.synthetic.main.fragment_generic_recycler_epoxy.* - +// Referenced in vector_settings_notifications.xml class PushRulesFragment : VectorBaseFragment() { override fun getLayoutResId(): Int = R.layout.fragment_generic_recycler_epoxy private val viewModel: PushRulesViewModel by fragmentViewModel(PushRulesViewModel::class) - private val epoxyController by lazy { PushRulesFragment.PushRulesController(StringProvider(requireContext().resources)) } + private val epoxyController by lazy { PushRulesController(StringProvider(requireContext().resources)) } override fun onResume() { @@ -51,11 +51,11 @@ class PushRulesFragment : VectorBaseFragment() { val dividerItemDecoration = DividerItemDecoration(epoxyRecyclerView.context, lmgr.orientation) epoxyRecyclerView.addItemDecoration(dividerItemDecoration) - epoxyRecyclerView.adapter = epoxyController.adapter + epoxyRecyclerView.setController(epoxyController) } - override fun invalidate() = withState(viewModel) { - epoxyController.setData(it) + override fun invalidate() = withState(viewModel) { state -> + epoxyController.setData(state) } class PushRulesController(private val stringProvider: StringProvider) : TypedEpoxyController() { diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesViewModel.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesViewModel.kt index 05109d7e..f950d0ef 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesViewModel.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/push/PushRulesViewModel.kt @@ -24,8 +24,8 @@ import im.vector.riotredesign.core.platform.VectorViewModel import org.koin.android.ext.android.get data class PushRulesViewState( - val rules: List = emptyList()) - : MvRxState + val rules: List = emptyList() +) : MvRxState class PushRulesViewModel(initialState: PushRulesViewState) : VectorViewModel(initialState) { diff --git a/vector/src/main/res/layout/fragment_generic_recycler_epoxy.xml b/vector/src/main/res/layout/fragment_generic_recycler_epoxy.xml index 7e5c0137..c794e8a5 100644 --- a/vector/src/main/res/layout/fragment_generic_recycler_epoxy.xml +++ b/vector/src/main/res/layout/fragment_generic_recycler_epoxy.xml @@ -1,16 +1,9 @@ - - - - - \ No newline at end of file + app:itemSpacing="1dp" + tools:listitem="@layout/item_pushgateway" />