-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Android library for settings activity
Use external library for lead and follow colorization.
- Loading branch information
Showing
9 changed files
with
260 additions
and
261 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
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/yacgroup/yacguide/PreferenceFragment.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,41 @@ | ||
/* | ||
* Copyright (C) 2024 Christian Sommer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.yacgroup.yacguide | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import androidx.preference.PreferenceFragmentCompat | ||
import com.skydoves.colorpickerpreference.ColorPickerPreference | ||
import com.yacgroup.yacguide.extensions.getSharedPreferenceManager | ||
import com.yacgroup.yacguide.extensions.setSharedPreferences | ||
|
||
class PreferenceFragment : PreferenceFragmentCompat() { | ||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
preferenceManager.sharedPreferencesName = getString(R.string.preferences_filename) | ||
setPreferencesFromResource(R.xml.preferences, rootKey) | ||
for (stringResource in listOf(R.string.lead, R.string.follow)) { | ||
findPreference<ColorPickerPreference>(getString(stringResource))?.getColorPickerView()?.let { view -> | ||
context?.let { context -> | ||
view.getSharedPreferenceManager().setSharedPreferences( | ||
context.getSharedPreferences(getString(R.string.preferences_filename), Context.MODE_PRIVATE) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/yacgroup/yacguide/extensions/ColorPickerPreferenceManager.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,33 @@ | ||
/* | ||
* Copyright (C) 2024 Christian Sommer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.yacgroup.yacguide.extensions | ||
|
||
import android.content.SharedPreferences | ||
import com.skydoves.colorpickerview.preference.ColorPickerPreferenceManager | ||
|
||
/* | ||
* See https://stackoverflow.com/questions/45131683/kotlin-extension-function-access-java-private-field | ||
* | ||
* TODO: Remove, if the following feature request is implemented: https://github.com/skydoves/ColorPickerView/issues/145 | ||
*/ | ||
fun ColorPickerPreferenceManager.setSharedPreferences(sharedPreferences: SharedPreferences) { | ||
ColorPickerPreferenceManager::class.java.getDeclaredField("sharedPreferences").let { field -> | ||
field.isAccessible = true | ||
field.set(this, sharedPreferences) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/yacgroup/yacguide/extensions/ColorPickerView.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,33 @@ | ||
/* | ||
* Copyright (C) 2024 Christian Sommer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.yacgroup.yacguide.extensions | ||
|
||
import com.skydoves.colorpickerview.ColorPickerView | ||
import com.skydoves.colorpickerview.preference.ColorPickerPreferenceManager | ||
|
||
/* | ||
* See https://stackoverflow.com/questions/45131683/kotlin-extension-function-access-java-private-field | ||
* | ||
* TODO: Remove, if the following feature request is implemented: https://github.com/skydoves/ColorPickerView/issues/145 | ||
*/ | ||
fun ColorPickerView.getSharedPreferenceManager(): ColorPickerPreferenceManager { | ||
return ColorPickerView::class.java.getDeclaredField("preferenceManager").let { field -> | ||
field.isAccessible = true | ||
return@let field.get(this) as ColorPickerPreferenceManager | ||
} | ||
} |
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
Oops, something went wrong.