Skip to content
Snippets Groups Projects
Commit 436cdc9d authored by Pierre Nicolas's avatar Pierre Nicolas :joy: Committed by Adrien Béraud
Browse files

linkdevice: fix connect from backup feature

Regression included in apk383
GitLab: #1393

Change-Id: I094055167d7ee993b0cec3cad8044c9860821545
parent 923f83a5
No related branches found
No related tags found
No related merge requests found
......@@ -25,13 +25,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.ViewModelProvider
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import cx.ring.R
import cx.ring.account.pinInput.EditTextPinInputFragment
import cx.ring.account.pinInput.EditTextPinInputViewModel
......@@ -64,12 +63,23 @@ class JamiLinkAccountPasswordFragment :
savedInstanceState: Bundle?
): View =
FragAccJamiLinkPasswordBinding.inflate(inflater, container, false).apply {
viewPager.adapter = SectionsPagerAdapter(
root.context,
childFragmentManager
val adapter = SectionsPagerAdapter(this@JamiLinkAccountPasswordFragment)
adapter.addFragment(
QrCodePinInputFragment(),
getString(R.string.connect_device_scanqr)
)
adapter.addFragment(
EditTextPinInputFragment(),
getString(R.string.connect_device_enterPIN)
)
tabs.setupWithViewPager(viewPager)
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
pager.adapter = adapter
pager.currentItem = 0
TabLayoutMediator(tabLayout, pager) { tab, position ->
tab.text = adapter.getTabTitle(position)
}.attach()
tabLayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
presenter.resetPin()
// emit the pin again when switching tabs
......@@ -84,6 +94,7 @@ class JamiLinkAccountPasswordFragment :
override fun onTabReselected(tab: TabLayout.Tab?) {}
})
linkButton.setOnClickListener { presenter.linkClicked() }
ringExistingPassword.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(
......@@ -105,12 +116,8 @@ class JamiLinkAccountPasswordFragment :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// init the 2 view models
qrCodePinInputViewModel.init({
presenter.pinChanged(it)
}, { presenter.resetPin() })
editTextPinInputViewModel.init({
presenter.pinChanged(it)
}, { presenter.resetPin() })
qrCodePinInputViewModel.init({ presenter.pinChanged(it) }, { presenter.resetPin() })
editTextPinInputViewModel.init({ presenter.pinChanged(it) }, { presenter.resetPin() })
}
override fun onDestroyView() {
......@@ -128,8 +135,9 @@ class JamiLinkAccountPasswordFragment :
override fun showPin(show: Boolean) {
val binding = binding ?: return
binding.passwordBox.visibility = if (show) View.VISIBLE else View.GONE
binding.linkButton.setText(if (show) R.string.account_link_device_button else R.string.account_link_archive_button)
binding.pager.visibility = if (show) View.VISIBLE else View.GONE
binding.tabLayout.visibility = if (show) View.VISIBLE else View.GONE
binding.linkButton.setText(if (show) R.string.account_link_device else R.string.account_link_archive_button)
}
override fun createAccount() {
......@@ -143,30 +151,30 @@ class JamiLinkAccountPasswordFragment :
activity?.onBackPressedDispatcher?.onBackPressed()
}
companion object {
val TAG = JamiLinkAccountPasswordFragment::class.simpleName!!
}
internal class SectionsPagerAdapter(private val mContext: Context, fm: FragmentManager) :
FragmentPagerAdapter(fm) {
@StringRes
private val TAB_TITLES =
intArrayOf(R.string.connect_device_scanqr, R.string.connect_device_enterPIN)
override fun getItem(position: Int): Fragment {
return when (position) {
0 -> QrCodePinInputFragment() // scan qr code
1 -> EditTextPinInputFragment() // or enter pin
else -> throw IllegalArgumentException()
}
internal class SectionsPagerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
private val mFragmentList: MutableList<Fragment> = ArrayList()
private val mFragmentTitleList: MutableList<String> = ArrayList()
fun getTabTitle(position: Int): String {
return mFragmentTitleList[position]
}
fun addFragment(fragment: Fragment, title: String) {
mFragmentList.add(fragment)
mFragmentTitleList.add(title)
}
override fun getPageTitle(position: Int): CharSequence {
return mContext.resources.getString(TAB_TITLES[position])
override fun getItemCount(): Int {
return mFragmentList.size
}
override fun getCount(): Int {
return TAB_TITLES.size
override fun createFragment(position: Int): Fragment {
return mFragmentList[position]
}
}
companion object {
val TAG = JamiLinkAccountPasswordFragment::class.simpleName!!
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_primary_dark"
tools:context="cx.ring.account.AccountWizardActivity">
android:gravity="center_vertical"
android:orientation="vertical">
<cx.ring.views.BoundedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:ignore="UselessParent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp">
android:orientation="vertical">
<cx.ring.views.BoundedRelativeLayout
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
app:bounded_height="690dp"
app:bounded_width="580dp">
<ImageView
android:id="@+id/background"
android:layout_width="170dp"
android:layout_height="170dp"
android:layout_alignTop="@id/card"
android:layout_centerHorizontal="true"
android:layout_marginTop="-30dp"
android:alpha="0.1"
android:contentDescription="@string/account_link_device"
android:src="@drawable/baseline_devices_24"
app:tint="@color/white" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="@dimen/text_margin"
android:gravity="center"
android:text="@string/account_link_device"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline6"
android:textColor="@color/color_primary_light"
android:textStyle="bold" />
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="@string/account_link_device"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
android:textColor="@color/color_primary_light"
android:textStyle="bold" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/title"
android:layout_marginTop="44dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:text="@string/account_link_device_info"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/white" />
</LinearLayout>
<cx.ring.views.WizardViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="600dp"
android:layout_below="@+id/info"
android:layout_centerHorizontal="true"
android:clipChildren="false"
android:clipToPadding="false"
tools:background="@color/grey_400" />
</cx.ring.views.BoundedRelativeLayout>
<ImageView
android:id="@+id/background"
android:layout_width="@dimen/wizard_image_background"
android:layout_height="@dimen/wizard_image_background"
android:layout_centerHorizontal="true"
android:alpha="0.1"
android:contentDescription="@null"
android:src="@drawable/baseline_devices_24"
app:tint="@color/white" />
</RelativeLayout>
<cx.ring.views.WizardViewPager
android:id="@+id/pager"
android:layout_width="@dimen/wizard_card_width"
android:layout_height="500dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="22dp"
tools:background="@color/grey_400"
tools:layout_height="500dp" />
</LinearLayout>
</LinearLayout>
</cx.ring.views.BoundedScrollView>
</RelativeLayout>
......@@ -15,89 +15,94 @@
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="cx.ring.account.AccountWizardActivity">
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="@dimen/wizard_card_radius"
tools:context="cx.ring.account.AccountWizardActivity">
android:background="@color/white"
app:cardCornerRadius="12dp">
<LinearLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">
android:layout_height="wrap_content">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@null"
app:tabIndicatorColor="@color/color_primary_dark"
app:tabSelectedTextColor="@color/black"
app:tabTextColor="@color/black">
android:orientation="vertical"
android:padding="@dimen/wizard_card_padding">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connect_device_scanqr" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connect_device_enterPIN" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connect_device_scanqr" />
</com.google.android.material.tabs.TabLayout>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connect_device_enterPIN" />
</com.google.android.material.tabs.TabLayout>
<!--pager display the scan view or the pin input-->
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="300dp" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="300dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="15dp"
android:text="@string/help_pin_info" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/help_password_enter"
android:textStyle="bold" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_box"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/password_txt_box"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_existing_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/baseline_lock_24"
android:drawablePadding="5dp"
android:hint="@string/prompt_password"
android:imeOptions="actionNext"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/ring_existing_password"
<com.google.android.material.button.MaterialButton
android:id="@+id/link_button"
style="@style/WizardButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/baseline_lock_24"
android:drawablePadding="5dp"
android:hint="@string/prompt_password"
android:imeOptions="actionNext"
android:inputType="textPassword"
app:passwordToggleEnabled="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/link_button"
style="@style/WizardButton"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="18dp"
android:enabled="false"
android:text="@string/account_link_device_button"
android:textSize="12sp"
android:theme="@style/ButtonColoredInverse" />
android:layout_gravity="center_horizontal"
android:layout_marginTop="18dp"
android:enabled="false"
android:text="@string/account_link_button"
android:textSize="12sp"
android:theme="@style/ButtonColoredInverse" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.cardview.widget.CardView>
\ No newline at end of file
</FrameLayout>
\ No newline at end of file
......@@ -92,7 +92,7 @@ along with this program; if not, write to the Free Software
<dimen name="wizard_button_padding">@dimen/button_padding</dimen>
<dimen name="wizard_card_width">330dp</dimen>
<dimen name="wizard_card_height">420dp</dimen>
<dimen name="wizard_image_background">300dp</dimen>
<dimen name="wizard_image_background">180dp</dimen>
<dimen name="wizard_card_radius">@dimen/button_corner_radius</dimen>
<dimen name="wizard_card_padding">22dp</dimen>
<dimen name="wizard_text_size">14sp</dimen>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment