Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
private lateinit var clipboardAdapter: ClipboardAdapter

lateinit var keyboardActionListener: KeyboardActionListener
private var clipboardHistoryManager: ClipboardHistoryManager? = null
private lateinit var clipboardHistoryManager: ClipboardHistoryManager

init {
val clipboardViewAttr = context.obtainStyledAttributes(attrs,
Expand Down Expand Up @@ -84,6 +84,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
@SuppressLint("ClickableViewAccessibility")
private fun initialize() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
if (this::clipboardAdapter.isInitialized) return
clipboardHistoryManager.sortHistoryEntries()
val colors = Settings.getValues().mColors
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
itemBackgroundId = keyBackgroundId
Expand Down Expand Up @@ -144,11 +145,11 @@ class ClipboardHistoryView @JvmOverloads constructor(
editorInfo: EditorInfo,
keyboardActionListener: KeyboardActionListener
) {
clipboardHistoryManager = historyManager
initialize()
setupToolbarKeys()
historyManager.prepareClipboardHistory()
historyManager.setHistoryChangeListener(this)
clipboardHistoryManager = historyManager
clipboardAdapter.clipboardHistoryManager = historyManager

val params = KeyDrawParams()
Expand Down Expand Up @@ -188,8 +189,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
fun stopClipboardHistory() {
if (!this::clipboardAdapter.isInitialized) return
clipboardRecyclerView.adapter = null
clipboardHistoryManager?.setHistoryChangeListener(null)
clipboardHistoryManager = null
clipboardHistoryManager.setHistoryChangeListener(null)
clipboardAdapter.clipboardHistoryManager = null
}

Expand Down Expand Up @@ -226,8 +226,8 @@ class ClipboardHistoryView @JvmOverloads constructor(
}

override fun onKeyUp(clipId: Long) {
val clipContent = clipboardHistoryManager?.getHistoryEntryContent(clipId)
keyboardActionListener.onTextInput(clipContent?.content.toString())
val clipContent = clipboardHistoryManager.getHistoryEntryContent(clipId)
keyboardActionListener.onTextInput(clipContent.content.toString())
keyboardActionListener.onReleaseKey(KeyCode.NOT_SPECIFIED, false)
if (Settings.getValues().mAlphaAfterClipHistoryEntry)
keyboardActionListener.onCodeInput(KeyCode.ALPHA, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE, false)
Expand All @@ -250,5 +250,13 @@ class ClipboardHistoryView @JvmOverloads constructor(

override fun onSharedPreferenceChanged(prefs: SharedPreferences?, key: String?) {
setToolbarButtonsActivatedStateOnPrefChange(KeyboardSwitcher.getInstance().clipboardStrip, key)

// The setting can only be changed from a settings screen, but adding it to this listener seems necessary: https://github.com/Helium314/HeliBoard/pull/1903#issuecomment-3478424606
if (::clipboardHistoryManager.isInitialized && key == Settings.PREF_CLIPBOARD_HISTORY_PINNED_FIRST) {
// Ensure settings are reloaded first
Settings.getInstance().onSharedPreferenceChanged(prefs, key)
clipboardHistoryManager.sortHistoryEntries()
clipboardAdapter.notifyDataSetChanged()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package helium314.keyboard.latin

import helium314.keyboard.latin.settings.Settings
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -12,6 +13,8 @@ data class ClipboardHistoryEntry (
) : Comparable<ClipboardHistoryEntry> {
override fun compareTo(other: ClipboardHistoryEntry): Int {
val result = other.isPinned.compareTo(isPinned)
return if (result != 0) result else other.timeStamp.compareTo(timeStamp)
if (result == 0) return other.timeStamp.compareTo(timeStamp)
if (Settings.getValues()?.mClipboardHistoryPinnedFirst == false) return -result
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ClipboardHistoryManager(
historyEntries.removeAt(index)
}

private fun sortHistoryEntries() {
fun sortHistoryEntries() {
historyEntries.sort()
}

Expand Down Expand Up @@ -157,7 +157,6 @@ class ClipboardHistoryManager(
if (pinnedClipString.isEmpty()) return
val pinnedClips: List<ClipboardHistoryEntry> = Json.decodeFromString(pinnedClipString)
historyEntries.addAll(pinnedClips)
sortHistoryEntries()
if (onHistoryChangeListener != null) {
pinnedClips.forEach {
onHistoryChangeListener?.onClipboardHistoryEntryAdded(historyEntries.indexOf(it))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ object Defaults {
const val PREF_LANGUAGE_SWIPE_DISTANCE = 5
const val PREF_ENABLE_CLIPBOARD_HISTORY = true
const val PREF_CLIPBOARD_HISTORY_RETENTION_TIME = 10 // minutes
const val PREF_CLIPBOARD_HISTORY_PINNED_FIRST = true
const val PREF_ADD_TO_PERSONAL_DICTIONARY = false
@JvmField
val PREF_NAVBAR_COLOR = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang

public static final String PREF_ENABLE_CLIPBOARD_HISTORY = "enable_clipboard_history";
public static final String PREF_CLIPBOARD_HISTORY_RETENTION_TIME = "clipboard_history_retention_time";
public static final String PREF_CLIPBOARD_HISTORY_PINNED_FIRST = "clipboard_history_pinned_first";

public static final String PREF_ADD_TO_PERSONAL_DICTIONARY = "add_to_personal_dictionary";
public static final String PREF_NAVBAR_COLOR = "navbar_color";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class SettingsValues {
public final boolean mShiftRemovesAutospace;
public final boolean mClipboardHistoryEnabled;
public final long mClipboardHistoryRetentionTime;
public final boolean mClipboardHistoryPinnedFirst;
public final boolean mOneHandedModeEnabled;
public final int mOneHandedModeGravity;
public final float mOneHandedModeScale;
Expand Down Expand Up @@ -258,6 +259,7 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
mShiftRemovesAutospace = prefs.getBoolean(Settings.PREF_SHIFT_REMOVES_AUTOSPACE, Defaults.PREF_SHIFT_REMOVES_AUTOSPACE);
mClipboardHistoryEnabled = prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY);
mClipboardHistoryRetentionTime = prefs.getInt(Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME, Defaults.PREF_CLIPBOARD_HISTORY_RETENTION_TIME);
mClipboardHistoryPinnedFirst = prefs.getBoolean(Settings.PREF_CLIPBOARD_HISTORY_PINNED_FIRST, Defaults.PREF_CLIPBOARD_HISTORY_PINNED_FIRST);

mOneHandedModeEnabled = Settings.readOneHandedModeEnabled(prefs, isLandscape, mIsSplitKeyboardEnabled);
mOneHandedModeGravity = Settings.readOneHandedModeGravity(prefs, isLandscape, mIsSplitKeyboardEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fun PreferencesScreen(
val b = (LocalContext.current.getActivity() as? SettingsActivity)?.prefChanged?.collectAsState()
if ((b?.value ?: 0) < 0)
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val clipboardHistoryEnabled = prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY)
val items = listOf(
R.string.settings_category_input,
Settings.PREF_SHOW_HINTS,
Expand Down Expand Up @@ -71,8 +72,8 @@ fun PreferencesScreen(
Settings.PREF_REMOVE_REDUNDANT_POPUPS,
R.string.settings_category_clipboard_history,
Settings.PREF_ENABLE_CLIPBOARD_HISTORY,
if (prefs.getBoolean(Settings.PREF_ENABLE_CLIPBOARD_HISTORY, Defaults.PREF_ENABLE_CLIPBOARD_HISTORY))
Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME else null
if (clipboardHistoryEnabled) Settings.PREF_CLIPBOARD_HISTORY_RETENTION_TIME else null,
if (clipboardHistoryEnabled) Settings.PREF_CLIPBOARD_HISTORY_PINNED_FIRST else null
)
SearchSettingsScreen(
onClickBack = onClickBack,
Expand Down Expand Up @@ -171,6 +172,9 @@ fun createPreferencesSettings(context: Context) = listOf(
range = 1f..121f,
)
},
Setting(context, Settings.PREF_CLIPBOARD_HISTORY_PINNED_FIRST, R.string.clipboard_history_pinned_first) {
SwitchPreference(it, Defaults.PREF_CLIPBOARD_HISTORY_PINNED_FIRST)
},
Setting(context, Settings.PREF_VIBRATION_DURATION_SETTINGS, R.string.prefs_keypress_vibration_duration_settings) { setting ->
SliderPreference(
name = setting.title,
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@
<string name="enable_clipboard_history">Enable clipboard history</string>
<!-- Description for enabling/disabling clipboard history mentioning that if disabled, clipboard content is pasted -->
<string name="enable_clipboard_history_summary">If disabled, clipboard key will paste clipboard content if any</string>
<!-- Preferences item for enabling clipboard history -->
<!-- Preferences item for controlling clipboard history retention time -->
<string name="clipboard_history_retention_time">History retention time</string>
<!-- Preferences item for showing pinned clipboard items first -->
<string name="clipboard_history_pinned_first">Show pinned items on top</string>
<!-- Preferences item for enabling swipe deletion -->
<string name="delete_swipe">Delete swipe</string>
<!-- Description for "delete_swipe" option. -->
Expand Down
Loading