srctree

Robin Linden parent 9e9f21b4 fd4794e4
Make it possible to change your nospam

inlinesplit
atox/src/main/kotlin/ui/settings/SettingsFragment.kt added: 83, removed: 7, total 76
@@ -179,6 +179,18 @@ class SettingsFragment : BaseFragment<FragmentSettingsBinding>(FragmentSettingsB
}
}
 
nospam.setText("%08X".format(vm.getNospam()))
nospam.doAfterTextChanged {
saveNospam.isEnabled =
nospam.text.length == 8 && nospam.text.toString().toUInt(16).toInt() != vm.getNospam()
}
saveNospam.isEnabled = false
saveNospam.setOnClickListener {
vm.setNospam(nospam.text.toString().toUInt(16).toInt())
saveNospam.isEnabled = false
Toast.makeText(requireContext(), R.string.saved, Toast.LENGTH_LONG).show()
}
 
settingBootstrapNodes.adapter = ArrayAdapter.createFromResource(
requireContext(), R.array.pref_bootstrap_node_options,
android.R.layout.simple_spinner_item
 
atox/src/main/kotlin/ui/settings/SettingsViewModel.kt added: 83, removed: 7, total 76
@@ -51,6 +51,11 @@ class SettingsViewModel @Inject constructor(
private val _committed = MutableLiveData<Boolean>().apply { value = false }
val committed: LiveData<Boolean> get() = _committed
 
fun getNospam(): Int = tox.nospam
fun setNospam(value: Int) {
tox.nospam = value
}
 
fun getTheme(): Int = settings.theme
fun setTheme(theme: Int) {
settings.theme = theme
 
atox/src/main/res/layout/fragment_settings.xml added: 83, removed: 7, total 76
@@ -312,6 +312,54 @@
android:padding="16dp"
android:text="@string/pref_heading_advanced"
android:textSize="16sp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/dividerColor"/>
<androidx.constraintlayout.widget.ConstraintLayout
style="@style/OptionRow"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/OptionItemText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:labelFor="@id/nospam"
android:text="@string/pref_nospam"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/nospam"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<EditText
android:id="@+id/nospam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:digits="0123456789ABCDEF"
android:importantForAutofill="no"
android:inputType="textCapCharacters"
android:maxLength="8"
android:minWidth="96dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/save_nospam"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:id="@+id/save_nospam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
style="@style/OptionItemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="@string/pref_nospam_description"/>
 
<View
android:layout_width="match_parent"
android:layout_height="1dp"
 
atox/src/main/res/values/strings.xml added: 83, removed: 7, total 76
@@ -144,4 +144,8 @@
<string name="ongoing_call">Ongoing call</string>
<string name="in_call_with">In call with %1$s</string>
<string name="tox_id_error_self_add">You can\'t add yourself</string>
<string name="save">Save</string>
<string name="pref_nospam">Nospam</string>
<string name="pref_nospam_description">Changing your nospam means that your Tox ID changes, and that your current Tox ID can no longer be used to send you friend requests</string>
<string name="saved">Saved</string>
</resources>
No newline at end of file
 
domain/src/main/kotlin/tox/Tox.kt added: 83, removed: 7, total 76
@@ -31,8 +31,11 @@ class Tox @Inject constructor(
private val saveManager: SaveManager,
private val nodeRegistry: BootstrapNodeRegistry,
) : CoroutineScope by GlobalScope + newSingleThreadContext("Tox") {
val toxId: ToxID by lazy { tox.getToxId() }
val toxId: ToxID get() = tox.getToxId()
val publicKey: PublicKey by lazy { tox.getPublicKey() }
var nospam: Int
get() = tox.getNospam()
set(value) = tox.setNospam(value)
 
var started = false
var isBootstrapNeeded = true
 
domain/src/main/kotlin/tox/ToxWrapper.kt added: 83, removed: 7, total 76
@@ -64,6 +64,10 @@ class ToxWrapper(
 
fun getToxId() = ToxID.fromBytes(tox.address)
fun getPublicKey() = PublicKey.fromBytes(tox.publicKey)
fun getNospam(): Int = tox.nospam
fun setNospam(value: Int) {
tox.nospam = value
}
 
fun getSaveData() = tox.savedata