-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Experimental preference to reverse home timeline (#867)
Add a new set of preferences, "Lab experiments", to control features that are under investigation and may never make it into the mainstream. Add the first experimental feature, which reverses the order of the home timeline, so posts are shown oldest first instead of newest first.
- Loading branch information
1 parent
7c32a07
commit c919f86
Showing
10 changed files
with
142 additions
and
84 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
70 changes: 70 additions & 0 deletions
70
app/src/main/java/app/pachli/components/preference/LabPreferencesFragment.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,70 @@ | ||
/* | ||
* Copyright 2024 Pachli Association | ||
* | ||
* This file is a part of Pachli. | ||
* | ||
* 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. | ||
* | ||
* Pachli 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 Pachli; if not, | ||
* see <http://www.gnu.org/licenses>. | ||
*/ | ||
|
||
package app.pachli.components.preference | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.SwitchPreferenceCompat | ||
import app.pachli.R | ||
import app.pachli.core.preferences.PrefKeys | ||
import app.pachli.databinding.FragmentLabPreferencesWarningBinding | ||
import app.pachli.settings.makePreferenceScreen | ||
import app.pachli.settings.switchPreference | ||
|
||
class LabPreferencesFragment : PreferenceFragmentCompat() { | ||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
val defaultView = super.onCreateView(inflater, container, savedInstanceState) | ||
|
||
// Insert a warning message as the first child in the layout. | ||
val warningBinding = FragmentLabPreferencesWarningBinding.inflate(inflater, null, false) | ||
(defaultView as? ViewGroup)?.addView(warningBinding.root, 0) | ||
|
||
return defaultView | ||
} | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
val context = requireContext() | ||
|
||
makePreferenceScreen { | ||
switchPreference { | ||
key = PrefKeys.LAB_REVERSE_TIMELINE | ||
setTitle(R.string.pref_labs_reverse_home_timeline_title) | ||
setSummaryProvider { | ||
if ((it as SwitchPreferenceCompat).isChecked) { | ||
context.getString(R.string.pref_labs_reverse_home_timeline_on_summary) | ||
} else { | ||
context.getString(R.string.pref_labs_reverse_home_timeline_off_summary) | ||
} | ||
} | ||
isIconSpaceReserved = false | ||
} | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
requireActivity().setTitle(R.string.pref_title_labs) | ||
} | ||
|
||
companion object { | ||
fun newInstance() = LabPreferencesFragment() | ||
} | ||
} |
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
app/src/main/res/layout/fragment_lab_preferences_warning.xml
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ Copyright 2024 Pachli Association | ||
~ | ||
~ This file is a part of Pachli. | ||
~ | ||
~ 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. | ||
~ | ||
~ Pachli 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 Pachli; if not, | ||
~ see <http://www.gnu.org/licenses>. | ||
--> | ||
|
||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
style="@style/TextSizeMedium" | ||
android:textColor="?colorError" | ||
android:background="?colorErrorContainer" | ||
android:paddingStart="?listPreferredItemPaddingStart" | ||
android:paddingEnd="?listPreferredItemPaddingEnd" | ||
android:paddingTop="8dp" | ||
android:paddingBottom="8dp" | ||
android:text="@string/pref_labs_warning" | ||
tools:ignore="Overdraw" /> |
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
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