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