Skip to content

Commit 5ff4ac3

Browse files
Merge pull request #16331 from nextcloud/settings-activity-m3-toggles
feat(settings-activity): m3 switch
2 parents d8b778d + 7ce0b11 commit 5ff4ac3

3 files changed

Lines changed: 68 additions & 67 deletions

File tree

app/src/main/java/com/owncloud/android/ui/ThemeableSwitchPreference.java

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Nextcloud - Android Client
4+
~
5+
~ SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
6+
~ SPDX-License-Identifier: AGPL-3.0-or-later
7+
-->
8+
<com.google.android.material.materialswitch.MaterialSwitch xmlns:android="http://schemas.android.com/apk/res/android"
9+
android:id="@+id/switch_widget"
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:background="@null"
13+
android:clickable="false"
14+
android:focusable="false" />

0 commit comments

Comments
 (0)