Skip to content

Commit

Permalink
fix filled in country code
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszKataMobitouch authored and skustra committed Feb 23, 2023
1 parent 881e0a4 commit 3d6824f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.ArrayList;
import java.util.Map;
import static pigeon.extensions.BuildExtensionsKt.isSignalVersion;

public final class CountryPickerFragment extends ListFragment implements LoaderManager.LoaderCallbacks<ArrayList<Map<String, String>>> {

Expand All @@ -49,6 +50,10 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
resultKey = arguments.getResultKey();
}

if (!isSignalVersion()){
getListView().setItemsCanFocus(true);
}

if (resultKey == null) {
model = new ViewModelProvider(requireActivity()).get(RegistrationViewModel.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@

import static org.thoughtcrime.securesms.registration.fragments.RegistrationViewDelegate.setDebugLogSubmitMultiTapView;
import static org.thoughtcrime.securesms.registration.fragments.RegistrationViewDelegate.showConfirmNumberDialogIfTranslated;
import static pigeon.extensions.BuildExtensionsKt.isSignalVersion;

public final class EnterPhoneNumberFragment extends LoggingFragment implements RegistrationNumberInputController.Callbacks {

private static final String NUMBER_COUNTRY_SELECT = "number_country";

private static final String TAG = Log.tag(EnterPhoneNumberFragment.class);

private TextInputLayout countryCode;
Expand Down Expand Up @@ -107,6 +110,22 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
countryCode);
register.setOnClickListener(v -> handleRegister(requireContext()));

if (!isSignalVersion()) {
CountryPickerFragmentArgs arguments = new CountryPickerFragmentArgs.Builder().setResultKey(NUMBER_COUNTRY_SELECT).build();

countryCode.setOnClickListener(v -> SafeNavigation.safeNavigate(
Navigation.findNavController(v), R.id.action_pickCountry, arguments.toBundle()
));

getParentFragmentManager().setFragmentResultListener(
NUMBER_COUNTRY_SELECT, this, (requestKey, result) -> {
int resultCountry = result.getInt(CountryPickerFragment.KEY_COUNTRY_CODE);
setCountry(resultCountry);
countryCode.getEditText().setText(String.valueOf(resultCountry));
}
);
}

disposables.bindTo(getViewLifecycleOwner().getLifecycle());
viewModel = new ViewModelProvider(requireActivity()).get(RegistrationViewModel.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.google.i18n.phonenumbers.AsYouTypeFormatter
import com.google.i18n.phonenumbers.PhoneNumberUtil
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.registration.viewmodel.NumberViewState
import pigeon.extensions.isSignalVersion

/**
* Handle the logic and formatting of phone number input specifically for registration number the flow.
Expand Down Expand Up @@ -46,7 +47,7 @@ class RegistrationNumberInputController(
}

fun prepopulateCountryCode() {
if (spinnerView.editableText.isBlank()) {
if (isSignalVersion() && spinnerView.editableText.isBlank()) {
spinnerView.setText(supportedCountryPrefixes[0].toString())
}
}
Expand Down Expand Up @@ -81,8 +82,16 @@ class RegistrationNumberInputController(

isUpdating = true
phoneNumberInputLayout.setText(numberViewState.nationalNumber)
if (numberViewState.countryCode != 0) {
spinnerView.setText(supportedCountryPrefixes.first { it.digits == numberViewState.countryCode }.toString())
if (isSignalVersion()) {
if (numberViewState.countryCode != 0) {
spinnerView.setText(supportedCountryPrefixes.first { it.digits == numberViewState.countryCode }.toString())
}
} else {
if (numberViewState.countryCode == 0) {
spinnerView.setText(supportedCountryPrefixes.first().digits.toString())
} else {
spinnerView.setText(countryCode.toString())
}
}
val regionCode = PhoneNumberUtil.getInstance().getRegionCodeForCountryCode(countryCode)
setCountryFormatter(regionCode)
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/res/layout-small/country_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
tools:background="@color/black"
tools:viewBindingIgnore="true">

<TextView
android:id="@+id/country_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:textAlignment="viewStart"
android:focusable="true"
android:textColor="@color/mp02_common_text_button"
android:textSize="18sp"
tools:text="Canada" />

<TextView
android:id="@+id/country_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="5dp"
android:focusable="true"
android:textColor="@color/mp02_common_text_button"
android:textSize="18sp"
tools:text="+1" />

</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
style="@style/Mp02.Signal.Background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/sim_background"
android:orientation="vertical">

<EditText
android:id="@+id/country_search"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:drawableStart="@drawable/ic_menu_search_holo_light"
android:hint="@string/country_selection_fragment__search"
android:textColor="@color/white"
android:textCursorDrawable="@null" />
android:textColor="@color/mp02_common_text_button"
android:textCursorDrawable="@null"
android:visibility="visible"
app:drawableTint="@color/mp02_common_text_button" />

<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:divider="#ffdddddd"
android:dividerHeight="1.0px" />
android:divider="@color/white_not_focus"
android:dividerHeight="1sp"
android:descendantFocusability="afterDescendants"
android:focusable="true"
tools:listitem="@layout/country_list_item" />

<TextView
android:id="@android:id/empty"
style="@style/Mp02.Signal.Text.Title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="@string/country_selection_fragment__loading_countries" />
android:text="@string/country_selection_fragment__loading_countries" />
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@
android:id="@+id/country_code"
style="@style/Mp02.Signal.TextInputLayout.Registration.Dropdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dp"
android:layout_height="match_parent"
app:errorEnabled="false"
app:hintEnabled="false">

<com.google.android.material.textfield.MaterialAutoCompleteTextView
style="@style/Mp02.Signal.Text.CommonTextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:digits="+1234567890"
android:inputType="numberSigned"
android:drawablePadding="-34dp"
android:inputType="none"
android:hint="@string/Registration_country_code_entry_hint"
android:drawablePadding="-50dp"
android:gravity="bottom"
android:cursorVisible="false"
android:focusableInTouchMode="false"
android:focusable="false"
android:clickable="false"
android:imeOptions="actionNext"
android:maxLength="4"
android:maxLines="1"
android:padding="0dp"
android:singleLine="true"
tools:text="+125" />

Expand All @@ -74,6 +77,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
tools:text="@tools:sample/lorem"
android:gravity="bottom"
android:inputType="phone" />

Expand Down
10 changes: 4 additions & 6 deletions app/src/main/res/values/pigeon_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
</style>

<style name="Mp02.Signal.ListTextView" >
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_vertical</item>
<item name="android:defaultFocusHighlightEnabled" tools:targetApi="o">false</item>
<item name="android:textSize">24sp</item>
<item name="android:textColor">@color/white_not_focus</item>
<item name="android:focusable">true</item>
<item name="android:paddingStart">30px</item>
<item name="android:textSize">24sp</item>
<item name="android:textColor">@color/mp02_common_text_button</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style>
Expand Down Expand Up @@ -91,8 +90,7 @@
<style name="Mp02.Signal.Text.BigCommonTextButton">
<item name="android:textSize">36sp</item>
<item name="android:includeFontPadding">false</item>
<item name="android:textColor">@color/mp02_common_text_button</item>
<item name="android:textAlignment">textStart</item>
c <item name="android:textAlignment">textStart</item>
<item name="android:singleLine">true</item>
<item name="android:defaultFocusHighlightEnabled" tools:ignore="NewApi">false</item>
</style>
Expand Down

0 comments on commit 3d6824f

Please sign in to comment.