-
Notifications
You must be signed in to change notification settings - Fork 676
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add capability to add and remove a room from the favorites (#1217)
- Loading branch information
Showing
25 changed files
with
395 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...x-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/tags/TagsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2020 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.matrix.android.api.session.room.tags | ||
|
||
import im.vector.matrix.android.api.MatrixCallback | ||
import im.vector.matrix.android.api.util.Cancelable | ||
|
||
/** | ||
* This interface defines methods to handle tags of a room. It's implemented at the room level. | ||
*/ | ||
interface TagsService { | ||
/** | ||
* Add a tag to a room | ||
*/ | ||
fun addTag(tag: String, order: Double?, callback: MatrixCallback<Unit>): Cancelable | ||
|
||
/** | ||
* Remove tag form a room | ||
*/ | ||
fun deleteTag(tag: String, callback: MatrixCallback<Unit>): Cancelable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...oid/src/main/java/im/vector/matrix/android/internal/session/room/tags/AddTagToRoomTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2020 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.matrix.android.internal.session.room.tags | ||
|
||
import im.vector.matrix.android.internal.di.UserId | ||
import im.vector.matrix.android.internal.network.executeRequest | ||
import im.vector.matrix.android.internal.session.room.RoomAPI | ||
import im.vector.matrix.android.internal.task.Task | ||
import org.greenrobot.eventbus.EventBus | ||
import javax.inject.Inject | ||
|
||
internal interface AddTagToRoomTask : Task<AddTagToRoomTask.Params, Unit> { | ||
|
||
data class Params( | ||
val roomId: String, | ||
val tag: String, | ||
val order: Double? | ||
) | ||
} | ||
|
||
internal class DefaultAddTagToRoomTask @Inject constructor( | ||
private val roomAPI: RoomAPI, | ||
@UserId private val userId: String, | ||
private val eventBus: EventBus | ||
) : AddTagToRoomTask { | ||
|
||
override suspend fun execute(params: AddTagToRoomTask.Params) { | ||
executeRequest<Unit>(eventBus) { | ||
apiCall = roomAPI.putTag( | ||
userId = userId, | ||
roomId = params.roomId, | ||
tag = params.tag, | ||
body = TagBody( | ||
order = params.order | ||
) | ||
) | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...d/src/main/java/im/vector/matrix/android/internal/session/room/tags/DefaultTagsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2020 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.matrix.android.internal.session.room.tags | ||
|
||
import com.squareup.inject.assisted.Assisted | ||
import com.squareup.inject.assisted.AssistedInject | ||
import im.vector.matrix.android.api.MatrixCallback | ||
import im.vector.matrix.android.api.session.room.tags.TagsService | ||
import im.vector.matrix.android.api.util.Cancelable | ||
import im.vector.matrix.android.internal.task.TaskExecutor | ||
import im.vector.matrix.android.internal.task.configureWith | ||
|
||
internal class DefaultTagsService @AssistedInject constructor( | ||
@Assisted private val roomId: String, | ||
private val taskExecutor: TaskExecutor, | ||
private val addTagToRoomTask: AddTagToRoomTask, | ||
private val deleteTagFromRoomTask: DeleteTagFromRoomTask | ||
) : TagsService { | ||
|
||
@AssistedInject.Factory | ||
interface Factory { | ||
fun create(roomId: String): TagsService | ||
} | ||
|
||
override fun addTag(tag: String, order: Double?, callback: MatrixCallback<Unit>): Cancelable { | ||
val params = AddTagToRoomTask.Params(roomId, tag, order) | ||
return addTagToRoomTask | ||
.configureWith(params) { | ||
this.callback = callback | ||
} | ||
.executeBy(taskExecutor) | ||
} | ||
|
||
override fun deleteTag(tag: String, callback: MatrixCallback<Unit>): Cancelable { | ||
val params = DeleteTagFromRoomTask.Params(roomId, tag) | ||
return deleteTagFromRoomTask | ||
.configureWith(params) { | ||
this.callback = callback | ||
} | ||
.executeBy(taskExecutor) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...rc/main/java/im/vector/matrix/android/internal/session/room/tags/DeleteTagFromRoomTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2020 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.matrix.android.internal.session.room.tags | ||
|
||
import im.vector.matrix.android.internal.di.UserId | ||
import im.vector.matrix.android.internal.network.executeRequest | ||
import im.vector.matrix.android.internal.session.room.RoomAPI | ||
import im.vector.matrix.android.internal.task.Task | ||
import org.greenrobot.eventbus.EventBus | ||
import javax.inject.Inject | ||
|
||
internal interface DeleteTagFromRoomTask : Task<DeleteTagFromRoomTask.Params, Unit> { | ||
|
||
data class Params( | ||
val roomId: String, | ||
val tag: String | ||
) | ||
} | ||
|
||
internal class DefaultDeleteTagFromRoomTask @Inject constructor( | ||
private val roomAPI: RoomAPI, | ||
@UserId private val userId: String, | ||
private val eventBus: EventBus | ||
) : DeleteTagFromRoomTask { | ||
|
||
override suspend fun execute(params: DeleteTagFromRoomTask.Params) { | ||
executeRequest<Unit>(eventBus) { | ||
apiCall = roomAPI.deleteTag( | ||
userId = userId, | ||
roomId = params.roomId, | ||
tag = params.tag | ||
) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/tags/TagBody.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2020 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.matrix.android.internal.session.room.tags | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
@JsonClass(generateAdapter = true) | ||
internal data class TagBody( | ||
/** | ||
* A number in a range [0,1] describing a relative position of the room under the given tag. | ||
*/ | ||
@Json(name = "order") | ||
val order: Double? | ||
) |
Oops, something went wrong.