mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-14 14:02:44 +00:00
simplify loading pinned clips
we don't need to read a file any more also makes sure pinned clips are initially loaded before fetching the primary clip
This commit is contained in:
parent
a58a7cc932
commit
290944635f
2 changed files with 10 additions and 23 deletions
|
@ -9,6 +9,7 @@ import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import helium314.keyboard.compat.ClipboardManagerCompat
|
import helium314.keyboard.compat.ClipboardManagerCompat
|
||||||
import helium314.keyboard.latin.settings.Settings
|
import helium314.keyboard.latin.settings.Settings
|
||||||
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ClipboardHistoryManager(
|
class ClipboardHistoryManager(
|
||||||
|
@ -23,20 +24,10 @@ class ClipboardHistoryManager(
|
||||||
clipboardManager.addPrimaryClipChangedListener(this)
|
clipboardManager.addPrimaryClipChangedListener(this)
|
||||||
if (historyEntries.isEmpty())
|
if (historyEntries.isEmpty())
|
||||||
loadPinnedClips()
|
loadPinnedClips()
|
||||||
if (latinIME.mSettings.current?.mClipboardHistoryEnabled == true)
|
if (Settings.readClipboardHistoryEnabled(DeviceProtectedUtils.getSharedPreferences(latinIME)))
|
||||||
fetchPrimaryClip()
|
fetchPrimaryClip()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onPinnedClipsAvailable(pinnedClips: List<ClipboardHistoryEntry>) {
|
|
||||||
historyEntries.addAll(pinnedClips)
|
|
||||||
sortHistoryEntries()
|
|
||||||
if (onHistoryChangeListener != null) {
|
|
||||||
pinnedClips.forEach {
|
|
||||||
onHistoryChangeListener?.onClipboardHistoryEntryAdded(historyEntries.indexOf(it))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun onDestroy() {
|
fun onDestroy() {
|
||||||
clipboardManager.removePrimaryClipChangedListener(this)
|
clipboardManager.removePrimaryClipChangedListener(this)
|
||||||
}
|
}
|
||||||
|
@ -145,7 +136,13 @@ class ClipboardHistoryManager(
|
||||||
val pinnedClipString = Settings.readPinnedClipString(latinIME)
|
val pinnedClipString = Settings.readPinnedClipString(latinIME)
|
||||||
if (pinnedClipString.isEmpty()) return
|
if (pinnedClipString.isEmpty()) return
|
||||||
val pinnedClips: List<ClipboardHistoryEntry> = Json.decodeFromString(pinnedClipString)
|
val pinnedClips: List<ClipboardHistoryEntry> = Json.decodeFromString(pinnedClipString)
|
||||||
latinIME.mHandler.postUpdateClipboardPinnedClips(pinnedClips)
|
historyEntries.addAll(pinnedClips)
|
||||||
|
sortHistoryEntries()
|
||||||
|
if (onHistoryChangeListener != null) {
|
||||||
|
pinnedClips.forEach {
|
||||||
|
onHistoryChangeListener?.onClipboardHistoryEntryAdded(historyEntries.indexOf(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun savePinnedClips() {
|
private fun savePinnedClips() {
|
||||||
|
|
|
@ -199,9 +199,8 @@ public class LatinIME extends InputMethodService implements
|
||||||
private static final int MSG_WAIT_FOR_DICTIONARY_LOAD = 8;
|
private static final int MSG_WAIT_FOR_DICTIONARY_LOAD = 8;
|
||||||
private static final int MSG_DEALLOCATE_MEMORY = 9;
|
private static final int MSG_DEALLOCATE_MEMORY = 9;
|
||||||
private static final int MSG_SWITCH_LANGUAGE_AUTOMATICALLY = 10;
|
private static final int MSG_SWITCH_LANGUAGE_AUTOMATICALLY = 10;
|
||||||
private static final int MSG_UPDATE_CLIPBOARD_PINNED_CLIPS = 11;
|
|
||||||
// Update this when adding new messages
|
// Update this when adding new messages
|
||||||
private static final int MSG_LAST = MSG_UPDATE_CLIPBOARD_PINNED_CLIPS;
|
private static final int MSG_LAST = MSG_SWITCH_LANGUAGE_AUTOMATICALLY;
|
||||||
|
|
||||||
private static final int ARG1_NOT_GESTURE_INPUT = 0;
|
private static final int ARG1_NOT_GESTURE_INPUT = 0;
|
||||||
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
|
private static final int ARG1_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1;
|
||||||
|
@ -292,11 +291,6 @@ public class LatinIME extends InputMethodService implements
|
||||||
case MSG_SWITCH_LANGUAGE_AUTOMATICALLY:
|
case MSG_SWITCH_LANGUAGE_AUTOMATICALLY:
|
||||||
latinIme.switchToSubtype((InputMethodSubtype) msg.obj);
|
latinIme.switchToSubtype((InputMethodSubtype) msg.obj);
|
||||||
break;
|
break;
|
||||||
case MSG_UPDATE_CLIPBOARD_PINNED_CLIPS:
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
List<ClipboardHistoryEntry> entries = (List<ClipboardHistoryEntry>) msg.obj;
|
|
||||||
latinIme.mClipboardHistoryManager.onPinnedClipsAvailable(entries);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,10 +405,6 @@ public class LatinIME extends InputMethodService implements
|
||||||
obtainMessage(MSG_SWITCH_LANGUAGE_AUTOMATICALLY, subtype).sendToTarget();
|
obtainMessage(MSG_SWITCH_LANGUAGE_AUTOMATICALLY, subtype).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postUpdateClipboardPinnedClips(final List<ClipboardHistoryEntry> clips) {
|
|
||||||
obtainMessage(MSG_UPDATE_CLIPBOARD_PINNED_CLIPS, clips).sendToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Working variables for the following methods.
|
// Working variables for the following methods.
|
||||||
private boolean mIsOrientationChanging;
|
private boolean mIsOrientationChanging;
|
||||||
private boolean mPendingSuccessiveImsCallback;
|
private boolean mPendingSuccessiveImsCallback;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue