From a761a0dbd2edb94e4198a70ead84d8d5fa46b7de Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 9 Dec 2019 21:56:03 +0100 Subject: [PATCH] Cleanup --- .../debug/sas/DebugSasEmojiActivity.kt | 1 - .../riotx/features/home/HomeDetailFragment.kt | 5 +- .../timeline/action/MessageActionsAnimator.kt | 34 +++++++++++++ .../action/MessageActionsBottomSheet.kt | 7 ++- .../room/filtered/FilteredRoomsActivity.kt | 4 +- .../reactions/EmojiReactionPickerActivity.kt | 6 +-- .../reactions/EmojiSearchResultFragment.kt | 2 +- .../settings/push/PushGateWayController.kt | 51 +++++++++++++++++++ .../settings/push/PushGatewaysFragment.kt | 35 ++----------- .../settings/push/PushRulesFragment.kt | 2 +- .../features/share/IncomingShareActivity.kt | 4 +- 11 files changed, 101 insertions(+), 50 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsAnimator.kt create mode 100644 vector/src/main/java/im/vector/riotx/features/settings/push/PushGateWayController.kt diff --git a/vector/src/debug/java/im/vector/riotx/features/debug/sas/DebugSasEmojiActivity.kt b/vector/src/debug/java/im/vector/riotx/features/debug/sas/DebugSasEmojiActivity.kt index acca04d09f..170c156858 100644 --- a/vector/src/debug/java/im/vector/riotx/features/debug/sas/DebugSasEmojiActivity.kt +++ b/vector/src/debug/java/im/vector/riotx/features/debug/sas/DebugSasEmojiActivity.kt @@ -29,7 +29,6 @@ class DebugSasEmojiActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.fragment_generic_recycler) - // TODO Inject val controller = SasEmojiController() recyclerView.configureWith(controller) controller.setData(SasState(getAllVerificationEmojis())) diff --git a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt index fe98501e73..f60db12459 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/HomeDetailFragment.kt @@ -46,7 +46,6 @@ private const val INDEX_PEOPLE = 1 private const val INDEX_ROOMS = 2 class HomeDetailFragment @Inject constructor( - private val session: Session, val homeDetailViewModelFactory: HomeDetailViewModel.Factory, private val avatarRenderer: AvatarRenderer ) : VectorBaseFragment(), KeysBackupBanner.Delegate { @@ -56,9 +55,7 @@ class HomeDetailFragment @Inject constructor( private val viewModel: HomeDetailViewModel by fragmentViewModel() private lateinit var sharedActionViewModel: HomeSharedActionViewModel - override fun getLayoutResId(): Int { - return R.layout.fragment_home_detail - } + override fun getLayoutResId() = R.layout.fragment_home_detail override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsAnimator.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsAnimator.kt new file mode 100644 index 0000000000..fbe32e0e2b --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsAnimator.kt @@ -0,0 +1,34 @@ +/* + * 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.riotx.features.home.room.detail.timeline.action + +import androidx.recyclerview.widget.DefaultItemAnimator + +private const val ANIM_DURATION_IN_MILLIS = 300L + +/** + * We only want to animate the expand of the "Report content" submenu + */ +class MessageActionsAnimator : DefaultItemAnimator() { + + init { + addDuration = ANIM_DURATION_IN_MILLIS + removeDuration = 0 + moveDuration = 0 + changeDuration = 0 + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt index 23729734cb..63e3be908d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/action/MessageActionsBottomSheet.kt @@ -30,7 +30,6 @@ import im.vector.riotx.core.extensions.cleanup import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment import im.vector.riotx.features.home.room.detail.timeline.item.MessageInformationData -import kotlinx.android.synthetic.main.activity_image_media_viewer.* import javax.inject.Inject /** @@ -88,7 +87,11 @@ class MessageActionsBottomSheet : VectorBaseBottomSheetDialogFragment(), Message override fun didSelectMenuAction(eventAction: EventSharedAction) { if (eventAction is EventSharedAction.ReportContent) { - // Toggle report menu // TODO Reanable item animation? + // Toggle report menu + // Enable item animation + if (recyclerView.itemAnimator == null) { + recyclerView.itemAnimator = MessageActionsAnimator() + } viewModel.handle(MessageActionsAction.ToggleReportMenu) } else { sharedActionViewModel.post(eventAction) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt b/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt index c4bb0d9b15..04e738cec8 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/filtered/FilteredRoomsActivity.kt @@ -36,9 +36,7 @@ class FilteredRoomsActivity : VectorBaseActivity() { return supportFragmentManager.findFragmentByTag(FRAGMENT_TAG) as? RoomListFragment } - override fun getLayoutRes(): Int { - return R.layout.activity_filtered_rooms - } + override fun getLayoutRes() = R.layout.activity_filtered_rooms override fun injectWith(injector: ScreenComponent) { injector.inject(this) diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiReactionPickerActivity.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiReactionPickerActivity.kt index 85e4eecf21..02f564ba72 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiReactionPickerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiReactionPickerActivity.kt @@ -54,11 +54,11 @@ class EmojiReactionPickerActivity : VectorBaseActivity(), lateinit var viewModel: EmojiChooserViewModel - override fun getMenuRes(): Int = R.menu.menu_emoji_reaction_picker + override fun getMenuRes() = R.menu.menu_emoji_reaction_picker - override fun getLayoutRes(): Int = R.layout.activity_emoji_reaction_picker + override fun getLayoutRes() = R.layout.activity_emoji_reaction_picker - override fun getTitleRes(): Int = R.string.title_activity_emoji_reaction_picker + override fun getTitleRes() = R.string.title_activity_emoji_reaction_picker @Inject lateinit var emojiCompatFontProvider: EmojiCompatFontProvider diff --git a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt index 976d5e984e..d87b7d7946 100644 --- a/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/reactions/EmojiSearchResultFragment.kt @@ -32,7 +32,7 @@ class EmojiSearchResultFragment @Inject constructor( private val epoxyController: EmojiSearchResultController ) : VectorBaseFragment() { - override fun getLayoutResId(): Int = R.layout.fragment_generic_recycler + override fun getLayoutResId() = R.layout.fragment_generic_recycler val viewModel: EmojiSearchResultViewModel by activityViewModel() diff --git a/vector/src/main/java/im/vector/riotx/features/settings/push/PushGateWayController.kt b/vector/src/main/java/im/vector/riotx/features/settings/push/PushGateWayController.kt new file mode 100644 index 0000000000..d8d23fbaf4 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/settings/push/PushGateWayController.kt @@ -0,0 +1,51 @@ +/* + * 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.riotx.features.settings.push + +import com.airbnb.epoxy.TypedEpoxyController +import im.vector.riotx.R +import im.vector.riotx.core.resources.StringProvider +import im.vector.riotx.core.ui.list.genericFooterItem +import javax.inject.Inject + +class PushGateWayController @Inject constructor( + private val stringProvider: StringProvider +) : TypedEpoxyController() { + + override fun buildModels(data: PushGatewayViewState?) { + data?.pushGateways?.invoke()?.let { pushers -> + if (pushers.isEmpty()) { + genericFooterItem { + id("footer") + text(stringProvider.getString(R.string.settings_push_gateway_no_pushers)) + } + } else { + pushers.forEach { + pushGatewayItem { + id("${it.pushKey}_${it.appId}") + pusher(it) + } + } + } + } ?: run { + genericFooterItem { + id("loading") + text(stringProvider.getString(R.string.loading)) + } + } + } +} diff --git a/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt index 816e76c4c4..c4d2118a77 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/push/PushGatewaysFragment.kt @@ -19,7 +19,6 @@ package im.vector.riotx.features.settings.push import android.os.Bundle import android.view.View import androidx.recyclerview.widget.DividerItemDecoration -import com.airbnb.epoxy.TypedEpoxyController import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotx.R @@ -27,20 +26,18 @@ import im.vector.riotx.core.extensions.cleanup import im.vector.riotx.core.extensions.configureWith import im.vector.riotx.core.platform.VectorBaseActivity import im.vector.riotx.core.platform.VectorBaseFragment -import im.vector.riotx.core.resources.StringProvider -import im.vector.riotx.core.ui.list.genericFooterItem import kotlinx.android.synthetic.main.fragment_generic_recycler.* import javax.inject.Inject // Referenced in vector_settings_notifications.xml class PushGatewaysFragment @Inject constructor( - val pushGatewaysViewModelFactory: PushGatewaysViewModel.Factory + val pushGatewaysViewModelFactory: PushGatewaysViewModel.Factory, + private val epoxyController: PushGateWayController ) : VectorBaseFragment() { - override fun getLayoutResId(): Int = R.layout.fragment_generic_recycler + override fun getLayoutResId() = R.layout.fragment_generic_recycler private val viewModel: PushGatewaysViewModel by fragmentViewModel(PushGatewaysViewModel::class) - private val epoxyController by lazy { PushGateWayController(StringProvider(requireContext().resources)) } override fun onResume() { super.onResume() @@ -60,30 +57,4 @@ class PushGatewaysFragment @Inject constructor( override fun invalidate() = withState(viewModel) { state -> epoxyController.setData(state) } - - // TODO Move to a proper file - class PushGateWayController(private val stringProvider: StringProvider) : TypedEpoxyController() { - override fun buildModels(data: PushGatewayViewState?) { - data?.pushGateways?.invoke()?.let { pushers -> - if (pushers.isEmpty()) { - genericFooterItem { - id("footer") - text(stringProvider.getString(R.string.settings_push_gateway_no_pushers)) - } - } else { - pushers.forEach { - pushGatewayItem { - id("${it.pushKey}_${it.appId}") - pusher(it) - } - } - } - } ?: run { - genericFooterItem { - id("footer") - text(stringProvider.getString(R.string.loading)) - } - } - } - } } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/push/PushRulesFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/push/PushRulesFragment.kt index 62ac49e738..4deb410d03 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/push/PushRulesFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/push/PushRulesFragment.kt @@ -33,7 +33,7 @@ import kotlinx.android.synthetic.main.fragment_generic_recycler.* // Referenced in vector_settings_notifications.xml class PushRulesFragment : VectorBaseFragment() { - override fun getLayoutResId(): Int = R.layout.fragment_generic_recycler + override fun getLayoutResId() = R.layout.fragment_generic_recycler private val viewModel: PushRulesViewModel by fragmentViewModel(PushRulesViewModel::class) diff --git a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt index 33b0744d4f..e48c8246d2 100644 --- a/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/share/IncomingShareActivity.kt @@ -50,9 +50,7 @@ class IncomingShareActivity : return supportFragmentManager.findFragmentById(R.id.shareRoomListFragmentContainer) as? RoomListFragment } - override fun getLayoutRes(): Int { - return R.layout.activity_incoming_share - } + override fun getLayoutRes() = R.layout.activity_incoming_share override fun injectWith(injector: ScreenComponent) { injector.inject(this)