Code review and cleanup

This commit is contained in:
Benoit Marty
2019-06-25 14:45:13 +02:00
parent ab0141a5c6
commit 71ae99012b
41 changed files with 283 additions and 158 deletions

View File

@ -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

View File

@ -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()
}

View File

@ -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,

View File

@ -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() {

View File

@ -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() {

View File

@ -37,7 +37,7 @@ data class SimpleAction(val uid: String, val titleRes: Int, val iconResId: Int?,
data class MessageMenuState(val actions: List<SimpleAction> = 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<MessageMenuState>(initialState) {

View File

@ -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.

View File

@ -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 {

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<PushGatewayItem.Holder>()
override fun bind(holder: Holder) {
holder.kind.text = when (pusher.kind) {
// TODO Create const
"http" -> "Http Pusher"
"mail" -> "Email Pusher"
else -> pusher.kind

View File

@ -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<PushGatewayViewState>() {
override fun buildModels(data: PushGatewayViewState?) {
data?.pushgateways?.invoke()?.let { pushers ->
data?.pushGateways?.invoke()?.let { pushers ->
if (pushers.isEmpty()) {
genericFooterItem {
id("footer")

View File

@ -25,12 +25,11 @@ import org.koin.android.ext.android.get
data class PushGatewayViewState(
val pushgateways: Async<List<Pusher>> = Uninitialized)
: MvRxState
val pushGateways: Async<List<Pusher>> = Uninitialized
) : MvRxState
class PushGatewaysViewModel(initialState: PushGatewayViewState) : VectorViewModel<PushGatewayViewState>(initialState) {
companion object : MvRxViewModelFactory<PushGatewaysViewModel, PushGatewayViewState> {
override fun create(viewModelContext: ViewModelContext, state: PushGatewayViewState): PushGatewaysViewModel? {

View File

@ -23,6 +23,7 @@ abstract class PushRuleItem : EpoxyModelWithHolder<PushRuleItem.Holder>() {
@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<PushRuleItem.Holder>() {
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()

View File

@ -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<PushRulesViewState>() {

View File

@ -24,8 +24,8 @@ import im.vector.riotredesign.core.platform.VectorViewModel
import org.koin.android.ext.android.get
data class PushRulesViewState(
val rules: List<PushRule> = emptyList())
: MvRxState
val rules: List<PushRule> = emptyList()
) : MvRxState
class PushRulesViewModel(initialState: PushRulesViewState) : VectorViewModel<PushRulesViewState>(initialState) {

View File

@ -1,16 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.airbnb.epoxy.EpoxyRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/epoxyRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/epoxyRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:itemSpacing="1dp"
tools:listitem="@layout/item_pushgateway" />
</FrameLayout>
app:itemSpacing="1dp"
tools:listitem="@layout/item_pushgateway" />