Use colorProvider instead of context

This commit is contained in:
Benoit Marty 2020-10-22 22:25:14 +02:00 committed by Benoit Marty
parent 7bebd6151e
commit 1555c06b21
6 changed files with 27 additions and 16 deletions

View File

@ -87,6 +87,7 @@ import im.vector.app.features.roomprofile.uploads.RoomUploadsFragment
import im.vector.app.features.roomprofile.uploads.files.RoomUploadsFilesFragment
import im.vector.app.features.roomprofile.uploads.media.RoomUploadsMediaFragment
import im.vector.app.features.settings.VectorSettingsAdvancedNotificationPreferenceFragment
import im.vector.app.features.settings.VectorSettingsGeneralFragment
import im.vector.app.features.settings.VectorSettingsHelpAboutFragment
import im.vector.app.features.settings.VectorSettingsLabsFragment
import im.vector.app.features.settings.VectorSettingsNotificationPreferenceFragment
@ -292,6 +293,11 @@ interface FragmentModule {
@FragmentKey(VectorSettingsPinFragment::class)
fun bindVectorSettingsPinFragment(fragment: VectorSettingsPinFragment): Fragment
@Binds
@IntoMap
@FragmentKey(VectorSettingsGeneralFragment::class)
fun bindVectorSettingsGeneralFragment(fragment: VectorSettingsGeneralFragment): Fragment
@Binds
@IntoMap
@FragmentKey(PushRulesFragment::class)

View File

@ -187,7 +187,7 @@ class AttachmentsPreviewFragment @Inject constructor(
val currentAttachment = it.attachments.getOrNull(it.currentAttachmentIndex) ?: return@withState
val destinationFile = File(requireContext().cacheDir, "${currentAttachment.name}_edited_image_${System.currentTimeMillis()}")
val uri = currentAttachment.queryUri
createUCropWithDefaultSettings(requireContext(), uri, destinationFile.toUri(), currentAttachment.name)
createUCropWithDefaultSettings(colorProvider, uri, destinationFile.toUri(), currentAttachment.name)
.start(requireContext(), this)
}

View File

@ -24,7 +24,6 @@ import im.vector.app.R
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.platform.VectorBaseActivity
import im.vector.app.core.resources.ColorProvider
import kotlinx.android.synthetic.main.activity_big_image_viewer.*
import javax.inject.Inject
@ -33,7 +32,6 @@ import javax.inject.Inject
*/
class BigImageViewerActivity : VectorBaseActivity() {
@Inject lateinit var sessionHolder: ActiveSessionHolder
@Inject lateinit var colorProvider: ColorProvider
override fun injectWith(injector: ScreenComponent) {
injector.inject(this)

View File

@ -16,16 +16,17 @@
package im.vector.app.features.media
import android.content.Context
import android.graphics.Color
import android.net.Uri
import androidx.core.content.ContextCompat
import com.yalantis.ucrop.UCrop
import com.yalantis.ucrop.UCropActivity
import im.vector.app.R
import im.vector.app.features.themes.ThemeUtils
import im.vector.app.core.resources.ColorProvider
fun createUCropWithDefaultSettings(context: Context, source: Uri, destination: Uri, toolbarTitle: String?): UCrop {
fun createUCropWithDefaultSettings(colorProvider: ColorProvider,
source: Uri,
destination: Uri,
toolbarTitle: String?): UCrop {
return UCrop.of(source, destination)
.withOptions(
UCrop.Options()
@ -39,15 +40,15 @@ fun createUCropWithDefaultSettings(context: Context, source: Uri, destination: U
// Disable freestyle crop, usability was not easy
// setFreeStyleCropEnabled(true)
// Color used for toolbar icon and text
setToolbarColor(ThemeUtils.getColor(context, R.attr.riotx_background))
setToolbarWidgetColor(ThemeUtils.getColor(context, R.attr.vctr_toolbar_primary_text_color))
setToolbarColor(colorProvider.getColorFromAttribute(R.attr.riotx_background))
setToolbarWidgetColor(colorProvider.getColorFromAttribute(R.attr.vctr_toolbar_primary_text_color))
// Background
setRootViewBackgroundColor(ThemeUtils.getColor(context, R.attr.riotx_background))
setRootViewBackgroundColor(colorProvider.getColorFromAttribute(R.attr.riotx_background))
// Status bar color (pb in dark mode, icon of the status bar are dark)
setStatusBarColor(ThemeUtils.getColor(context, R.attr.riotx_header_panel_background))
setStatusBarColor(colorProvider.getColorFromAttribute(R.attr.riotx_header_panel_background))
// Known issue: there is still orange color used by the lib
// https://github.com/Yalantis/uCrop/issues/602
setActiveControlsWidgetColor(ContextCompat.getColor(context, R.color.riotx_accent))
setActiveControlsWidgetColor(colorProvider.getColor(R.color.riotx_accent))
// Hide the logo (does not work)
setLogoColor(Color.TRANSPARENT)
}

View File

@ -31,6 +31,7 @@ import im.vector.app.core.extensions.cleanup
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.OnBackPressed
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.resources.ColorProvider
import im.vector.app.features.media.createUCropWithDefaultSettings
import im.vector.app.features.roomdirectory.RoomDirectorySharedAction
import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel
@ -41,7 +42,8 @@ import java.io.File
import javax.inject.Inject
class CreateRoomFragment @Inject constructor(
private val createRoomController: CreateRoomController
private val createRoomController: CreateRoomController,
private val colorProvider: ColorProvider
) : VectorBaseFragment(),
CreateRoomController.Listener,
GalleryOrCameraDialogHelper.Listener,
@ -86,7 +88,7 @@ class CreateRoomFragment @Inject constructor(
override fun onImageReady(image: MultiPickerImageType) {
val destinationFile = File(requireContext().cacheDir, "${image.displayName}_edited_image_${System.currentTimeMillis()}")
val uri = image.contentUri
createUCropWithDefaultSettings(requireContext(), uri, destinationFile.toUri(), image.displayName)
createUCropWithDefaultSettings(colorProvider, uri, destinationFile.toUri(), image.displayName)
.withAspectRatio(1f, 1f)
.start(requireContext(), this)
}

View File

@ -48,6 +48,7 @@ import im.vector.app.core.platform.SimpleTextWatcher
import im.vector.app.core.preference.UserAvatarPreference
import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.preference.VectorSwitchPreference
import im.vector.app.core.resources.ColorProvider
import im.vector.app.core.utils.TextUtils
import im.vector.app.core.utils.getSizeOfFiles
import im.vector.app.core.utils.toast
@ -70,8 +71,11 @@ import org.matrix.android.sdk.rx.rx
import org.matrix.android.sdk.rx.unwrap
import java.io.File
import java.util.UUID
import javax.inject.Inject
class VectorSettingsGeneralFragment :
class VectorSettingsGeneralFragment @Inject constructor(
private val colorProvider: ColorProvider
):
VectorSettingsBaseFragment(),
GalleryOrCameraDialogHelper.Listener {
@ -311,7 +315,7 @@ class VectorSettingsGeneralFragment :
override fun onImageReady(image: MultiPickerImageType) {
val destinationFile = File(requireContext().cacheDir, "${image.displayName}_edited_image_${System.currentTimeMillis()}")
val uri = image.contentUri
createUCropWithDefaultSettings(requireContext(), uri, destinationFile.toUri(), image.displayName)
createUCropWithDefaultSettings(colorProvider, uri, destinationFile.toUri(), image.displayName)
.withAspectRatio(1f, 1f)
.start(requireContext(), this)
}