|
| 1 | +/* |
| 2 | + * Nextcloud - Android Client |
| 3 | + * |
| 4 | + * SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com> |
| 5 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 6 | + */ |
| 7 | + |
| 8 | +package com.owncloud.android.ui |
| 9 | + |
| 10 | +import android.content.Context |
| 11 | +import android.preference.SwitchPreference |
| 12 | +import android.util.AttributeSet |
| 13 | +import android.view.View |
| 14 | +import com.google.android.material.materialswitch.MaterialSwitch |
| 15 | +import com.owncloud.android.MainApp |
| 16 | +import com.owncloud.android.R |
| 17 | +import com.owncloud.android.utils.theme.ViewThemeUtils |
| 18 | +import javax.inject.Inject |
| 19 | + |
| 20 | +@Suppress("DEPRECATION") |
| 21 | +class ThemeableSwitchPreference : SwitchPreference { |
| 22 | + @Inject |
| 23 | + lateinit var viewThemeUtils: ViewThemeUtils |
| 24 | + |
| 25 | + /** |
| 26 | + * Do not delete constructor. These are used. |
| 27 | + */ |
| 28 | + constructor(context: Context) : super(context) { |
| 29 | + init() |
| 30 | + } |
| 31 | + |
| 32 | + constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { |
| 33 | + init() |
| 34 | + } |
| 35 | + |
| 36 | + constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
| 37 | + init() |
| 38 | + } |
| 39 | + |
| 40 | + private fun init() { |
| 41 | + MainApp.getAppComponent().inject(this) |
| 42 | + setWidgetLayoutResource(R.layout.themeable_switch) |
| 43 | + } |
| 44 | + |
| 45 | + @Deprecated("Deprecated in Java") |
| 46 | + override fun onBindView(view: View) { |
| 47 | + super.onBindView(view) |
| 48 | + val checkable = view.findViewById<View>(R.id.switch_widget) |
| 49 | + if (checkable is MaterialSwitch) { |
| 50 | + checkable.setChecked(isChecked) |
| 51 | + viewThemeUtils.material.colorMaterialSwitch(checkable) |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments