Clean code and add towncrier file.

This commit is contained in:
ganfra 2021-06-16 20:22:13 +02:00
parent 1ff0a0d435
commit 1bb32eff45
4 changed files with 23 additions and 31 deletions

1
newsfragment/3516.misc Normal file
View File

@ -0,0 +1 @@
Some improvements on DialPad (cursor edition, paste number, small fixes).

View File

@ -17,7 +17,6 @@
package im.vector.app.features.call.dialpad
import android.content.ClipboardManager
import android.content.Context
import android.content.res.ColorStateList
import android.os.Bundle
import android.telephony.PhoneNumberFormattingTextWatcher
@ -31,6 +30,7 @@ import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.getSystemService
import androidx.core.view.isVisible
import androidx.core.widget.ImageViewCompat
import androidx.fragment.app.Fragment
@ -59,6 +59,7 @@ class DialPadFragment : Fragment(), TextWatcher {
savedInstanceState: Bundle?): View {
initArgs(savedInstanceState)
val view = inflater.inflate(R.layout.dialpad_fragment, container, false)
view.setBackgroundColor(ThemeUtils.getColor(requireContext(), R.attr.backgroundColor))
val dialpadView = view.findViewById<View>(R.id.dialpad_view) as DialpadView
dialpadView.findViewById<View>(R.id.dialpad_key_voicemail).isVisible = false
digits = dialpadView.digits as DigitsEditText
@ -117,7 +118,7 @@ class DialPadFragment : Fragment(), TextWatcher {
private fun onOkClicked() {
val rawInput = getRawInput()
if (rawInput.isEmpty()) {
val clipboard = (requireContext().getSystemService(Context.CLIPBOARD_SERVICE)) as? ClipboardManager
val clipboard = requireContext().getSystemService<ClipboardManager>()
val textToPaste = clipboard?.primaryClip?.getItemAt(0)?.text ?: return
val formatted = formatNumber(textToPaste.toString())
digits.setText(formatted)
@ -174,19 +175,14 @@ class DialPadFragment : Fragment(), TextWatcher {
}
private fun formatNumber(dialString: String): String {
var number = PhoneNumberUtils.extractNetworkPortion(dialString)
// Also retrieve the post dial portion of the provided data, so that the entire dial
// string can be reconstituted later.
val postDial = PhoneNumberUtils.extractPostDialPortion(dialString)
if (TextUtils.isEmpty(number)) {
val networkPortion = PhoneNumberUtils.extractNetworkPortion(dialString)
if (TextUtils.isEmpty(networkPortion)) {
return ""
}
number = PhoneNumberUtils.formatNumber(number, null, regionCode) ?: number
return if (TextUtils.isEmpty(postDial)) {
number
} else {
number + postDial
}
val number = PhoneNumberUtils.formatNumber(networkPortion, null, regionCode) ?: networkPortion
// Also retrieve the post dial portion of the provided data, so that the entire dial string can be reconstituted
val postDial = PhoneNumberUtils.extractPostDialPortion(dialString)
return number + postDial
}
interface Callback {
@ -222,5 +218,4 @@ class DialPadFragment : Fragment(), TextWatcher {
digits.clearFocus()
}
}
}

View File

@ -21,7 +21,6 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import im.vector.app.core.extensions.toMvRxBundle
import im.vector.app.core.platform.Restorable
import im.vector.app.features.call.dialpad.DialPadFragment
import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.userdirectory.UserListFragment
@ -71,6 +70,4 @@ class CallTransferPagerAdapter(
private fun findFragmentAtPosition(position: Int): Fragment? {
return fragmentActivity.supportFragmentManager.findFragmentByTag("f$position")
}
}

View File

@ -140,7 +140,6 @@
android:id="@+id/roomListContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?vctr_list_separator_system"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintTop_toBottomOf="@+id/activeCallView" />