-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement roles for volume buttons: do nothing, change text size, navigate sent history #554
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/ubergeek42/WeechatAndroid/utils/History.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,54 @@ | ||
package com.ubergeek42.WeechatAndroid.utils | ||
|
||
import android.os.Bundle | ||
import android.text.Editable | ||
import android.widget.EditText | ||
import androidx.core.os.bundleOf | ||
import com.ubergeek42.WeechatAndroid.service.P | ||
|
||
class History { | ||
private var index = -1 | ||
zopieux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private var userInput: Editable? = null | ||
private var selectionStart: Int? = null | ||
private var selectionEnd: Int? = null | ||
|
||
fun navigateOffset(editText: EditText, offset: Int) { | ||
zopieux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (index == -1) { | ||
userInput = editText.text | ||
selectionStart = editText.selectionStart | ||
selectionEnd = editText.selectionEnd | ||
} | ||
val newIndex = index + offset | ||
messageAt(newIndex)?.let { | ||
editText.text = it | ||
editText.post { | ||
zopieux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (newIndex == -1) { | ||
// Restore user selection. | ||
editText.setSelection(selectionStart ?: 0, selectionEnd ?: editText.length()) | ||
zopieux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
// Go to end for sent messages. | ||
editText.setSelection(editText.length()) | ||
} | ||
} | ||
index = newIndex | ||
} | ||
} | ||
|
||
fun save(): Bundle = bundleOf( | ||
Pair("index", index), | ||
Pair("userInput", userInput), | ||
Pair("selStart", selectionStart), | ||
Pair("selEnd", selectionEnd), | ||
) | ||
|
||
fun restore(bundle: Bundle) { | ||
index = bundle.getInt("index", -1) | ||
userInput = bundle.get("userInput") as Editable? | ||
selectionStart = bundle.getInt("selStart", -1).let { if (it == -1) null else it } | ||
selectionEnd = bundle.getInt("selEnd", -1).let { if (it == -1) null else it } | ||
} | ||
|
||
private fun messageAt(index: Int): Editable? = | ||
if (index == -1) userInput else P.sentMessages.getOrNull(P.sentMessages.size - 1 - index) | ||
?.let { Editable.Factory.getInstance().newEditable(it) } | ||
zopieux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -703,11 +703,9 @@ | |
wenn der Büroklammer-Taste versteckt wurde, | ||
um mehr Platz für das Eingabefeld zu schaffen.</string> | ||
|
||
<string name="pref__buttons__volume_buttons_change_text_size"> | ||
Lautstärketasten ändern die Textgröße</string> | ||
<string name="pref__buttons__volume_buttons_change_text_size_summary"> | ||
Wenn diese Option aktiviert ist, | ||
ändern die Lautstärketasten die Textgröße, anstelle der Lautstärke</string> | ||
<string name="pref_buttons_volume__actions__none">Nichts tun</string> | ||
<string name="pref_buttons_volume__actions__text_size">Lautstärketasten ändern die Textgröße</string> | ||
<string name="pref_buttons_volume__actions__history">Navigieren im Sendeverlauf</string> | ||
Comment on lines
+706
to
+708
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Machine-translated, probably wrong. |
||
|
||
<!-- ####################################################################################### --> | ||
<!-- #################################### notifications #################################### --> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -699,10 +699,9 @@ | |
Когда кнопка «Скрепка» скрыта, чтобы оставить больше места для поля ввода, | ||
выбирать файлы можно через меню.</string> | ||
|
||
<string name="pref__buttons__volume_buttons_change_text_size"> | ||
Кнопки громкости меняют размер текста</string> | ||
<string name="pref__buttons__volume_buttons_change_text_size_summary"> | ||
Если настройка включена, кнопки громкости будут менять размер текста вместо громкости</string> | ||
<string name="pref_buttons_volume__actions__none">Ничего не делать</string> | ||
<string name="pref_buttons_volume__actions__text_size">Кнопки громкости меняют размер текста</string> | ||
<string name="pref_buttons_volume__actions__history">Навигация по истории отправлений</string> | ||
Comment on lines
+702
to
+704
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Machine-translated, probably wrong. |
||
|
||
<!-- ####################################################################################### --> | ||
<!-- #################################### notifications #################################### --> | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: not a fan of wildcard imports, would rather prefer smaller diff