-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for links in the rich text editor
- Loading branch information
1 parent
de18f37
commit 994dddf
Showing
18 changed files
with
824 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Rich text editor] Add support for links |
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
155 changes: 155 additions & 0 deletions
155
vector/src/main/java/im/vector/app/core/platform/VectorBaseDialogFragment.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,155 @@ | ||
/* | ||
* 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.app.core.platform | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.os.Parcelable | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.CallSuper | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.viewbinding.ViewBinding | ||
import com.airbnb.mvrx.MavericksView | ||
import dagger.hilt.android.EntryPointAccessors | ||
import im.vector.app.R | ||
import im.vector.app.core.di.ActivityEntryPoint | ||
import im.vector.app.core.extensions.singletonEntryPoint | ||
import im.vector.app.core.extensions.toMvRxBundle | ||
import im.vector.app.features.analytics.AnalyticsTracker | ||
import im.vector.app.features.analytics.plan.MobileScreen | ||
import im.vector.app.features.themes.ThemeUtils | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import reactivecircus.flowbinding.android.view.clicks | ||
import timber.log.Timber | ||
|
||
/** | ||
* Add Mavericks capabilities, handle DI and bindings. | ||
*/ | ||
abstract class VectorBaseDialogFragment<VB : ViewBinding> : DialogFragment(), MavericksView { | ||
/* ========================================================================================== | ||
* Analytics | ||
* ========================================================================================== */ | ||
|
||
protected var analyticsScreenName: MobileScreen.ScreenName? = null | ||
|
||
protected lateinit var analyticsTracker: AnalyticsTracker | ||
|
||
/* ========================================================================================== | ||
* View | ||
* ========================================================================================== */ | ||
|
||
private var _binding: VB? = null | ||
|
||
// This property is only valid between onCreateView and onDestroyView. | ||
protected val views: VB | ||
get() = _binding!! | ||
|
||
abstract fun getBinding(inflater: LayoutInflater, container: ViewGroup?): VB | ||
|
||
/* ========================================================================================== | ||
* View model | ||
* ========================================================================================== */ | ||
|
||
private lateinit var viewModelFactory: ViewModelProvider.Factory | ||
|
||
protected val activityViewModelProvider | ||
get() = ViewModelProvider(requireActivity(), viewModelFactory) | ||
|
||
protected val fragmentViewModelProvider | ||
get() = ViewModelProvider(this, viewModelFactory) | ||
|
||
val vectorBaseActivity: VectorBaseActivity<*> by lazy { | ||
activity as VectorBaseActivity<*> | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setStyle(STYLE_NORMAL, ThemeUtils.getApplicationThemeRes(requireContext())) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
_binding = getBinding(inflater, container) | ||
return views.root | ||
} | ||
|
||
@CallSuper | ||
override fun onDestroyView() { | ||
_binding = null | ||
super.onDestroyView() | ||
} | ||
|
||
@CallSuper | ||
override fun onDestroy() { | ||
super.onDestroy() | ||
} | ||
|
||
override fun onAttach(context: Context) { | ||
val activityEntryPoint = EntryPointAccessors.fromActivity(vectorBaseActivity, ActivityEntryPoint::class.java) | ||
viewModelFactory = activityEntryPoint.viewModelFactory() | ||
val singletonEntryPoint = context.singletonEntryPoint() | ||
analyticsTracker = singletonEntryPoint.analyticsTracker() | ||
super.onAttach(context) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
Timber.i("onResume BottomSheet ${javaClass.simpleName}") | ||
analyticsScreenName?.let { | ||
analyticsTracker.screen(MobileScreen(screenName = it)) | ||
} | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
// This ensures that invalidate() is called for static screens that don't | ||
// subscribe to a ViewModel. | ||
postInvalidate() | ||
requireDialog().window?.setWindowAnimations(R.style.Animation_AppCompat_Dialog) | ||
} | ||
|
||
protected fun setArguments(args: Parcelable? = null) { | ||
arguments = args.toMvRxBundle() | ||
} | ||
|
||
/* ========================================================================================== | ||
* Views | ||
* ========================================================================================== */ | ||
|
||
protected fun View.debouncedClicks(onClicked: () -> Unit) { | ||
clicks() | ||
.onEach { onClicked() } | ||
.launchIn(viewLifecycleOwner.lifecycleScope) | ||
} | ||
|
||
/* ========================================================================================== | ||
* ViewEvents | ||
* ========================================================================================== */ | ||
|
||
protected fun <T : VectorViewEvents> VectorViewModel<*, *, T>.observeViewEvents(observer: (T) -> Unit) { | ||
viewEvents | ||
.stream() | ||
.onEach { | ||
observer(it) | ||
} | ||
.launchIn(viewLifecycleOwner.lifecycleScope) | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
vector/src/main/java/im/vector/app/features/home/room/detail/composer/link/SetLinkAction.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,30 @@ | ||
/* | ||
* Copyright (c) 2022 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.app.features.home.room.detail.composer.link | ||
|
||
import im.vector.app.core.platform.VectorViewModelAction | ||
|
||
sealed class SetLinkAction : VectorViewModelAction { | ||
data class LinkChanged( | ||
val newLink: String | ||
) : SetLinkAction() | ||
|
||
data class Save( | ||
val link: String, | ||
val text: String, | ||
) : SetLinkAction() | ||
} |
Oops, something went wrong.