Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor new UI and Solved Phone number picker issue #2864

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/res/layout/grid_header_top_banner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/cc_core_bg"
android:background="@color/white"
android:orientation="vertical"
tools:viewBindingIgnore="true"
>
Expand Down
78 changes: 44 additions & 34 deletions app/res/layout/screen_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@color/cc_core_bg"
android:background="@color/white"
android:orientation="vertical"
tools:viewBindingIgnore="true">

Expand All @@ -26,7 +26,7 @@
android:orientation="vertical"
android:visibility="gone">

<TextView
<org.commcare.views.connect.connecttextview.ConnectRegularTextView
android:id="@+id/str_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -47,10 +47,10 @@
android:id="@+id/screen_login_banner_pane"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingEnd="@dimen/standard_spacer_half"
android:paddingStart="@dimen/standard_spacer_half"
android:paddingLeft="@dimen/standard_spacer_half"
android:paddingRight="@dimen/standard_spacer_half"
android:paddingStart="@dimen/standard_spacer_half">
android:paddingEnd="@dimen/standard_spacer_half"
android:paddingRight="@dimen/standard_spacer_half">

<include layout="@layout/grid_header_top_banner" />
</FrameLayout>
Expand All @@ -67,13 +67,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/content_start"
android:paddingEnd="@dimen/login_box_margins"
android:paddingStart="@dimen/login_box_margins"
android:paddingLeft="@dimen/login_box_margins"
android:paddingEnd="@dimen/login_box_margins"
android:paddingRight="@dimen/login_box_margins"
android:paddingStart="@dimen/login_box_margins">
android:paddingBottom="@dimen/content_start">

<TextView
<org.commcare.views.connect.connecttextview.ConnectMediumTextView
android:id="@+id/welcome_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -82,25 +82,28 @@
android:textColor="@color/cc_neutral_color"
android:textSize="@dimen/text_medium" />

<Button
<org.commcare.views.connect.RoundedButton
android:id="@+id/connect_login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="45dp"
android:layout_gravity="bottom"
android:paddingBottom="@dimen/content_start"
android:paddingTop="@dimen/content_start"
android:paddingBottom="@dimen/content_start"
android:text="@string/connect_button_logged_in"
android:visibility="gone"
android:text="@string/connect_button_logged_in"/>
RectangleButtonWithText:roundButtonBackgroundColor="@color/connect_blue_color"
RectangleButtonWithText:roundButtonTextColor="@color/white"
RectangleButtonWithText:roundButtonTextSize="6.0sp" />

<TextView
<org.commcare.views.connect.connecttextview.ConnectMediumTextView
android:id="@+id/login_or"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/content_min_margin"
android:text="@string/choice_or"
android:textColor="@color/cc_neutral_color"
android:textSize="@dimen/text_medium"
android:text="@string/choice_or" />
android:textSize="@dimen/text_medium" />

<Spinner
android:id="@+id/app_selection_spinner"
Expand All @@ -116,50 +119,53 @@
android:id="@+id/edit_username"
style="@style/LoginEditTextV2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:layout_height="50dp"
android:background="@drawable/login_edit_text"
android:drawableLeft="@drawable/icon_user_neutral50"
android:drawableStart="@drawable/icon_user_neutral50"
android:hint="Username"
android:imeOptions="actionNext"
android:inputType="text"
android:fontFamily="@font/roboto_regular"
android:nextFocusDown="@+id/edit_password"
android:textAlignment="viewStart"
android:textSize="@dimen/text_medium"
android:textSize="18sp"
tools:ignore="RtlCompat">

<requestFocus />
</AutoCompleteTextView>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="50dp"
android:padding="0dp"
android:layout_marginTop="15dp"
android:background="@drawable/login_edit_text">

<EditText
android:id="@+id/edit_password"
style="@style/LoginEditTextV2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_start"
android:background="@drawable/login_edit_text"
android:drawableLeft="@drawable/icon_lock_neutral50"
android:layout_height="match_parent"
android:background="@null"
android:drawableStart="@drawable/icon_lock_neutral50"
android:hint="Password"
android:fontFamily="@font/roboto_regular"
android:textSize="18sp"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:nextFocusUp="@+id/edit_username"
android:textAlignment="viewStart"
android:textSize="@dimen/text_medium"
tools:ignore="RtlCompat" />

<Button
android:id="@+id/show_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/edit_password"
android:layout_alignTop="@+id/edit_password"
android:layout_alignEnd="@+id/edit_password"
android:layout_alignRight="@+id/edit_password"
android:layout_alignTop="@+id/edit_password"
android:layout_alignBottom="@+id/edit_password"
android:background="@android:color/transparent"
android:padding="@dimen/spacer_small"
android:src="@drawable/close_cross_icon"
Expand All @@ -178,33 +184,37 @@
android:textSize="16dp"
android:visibility="gone" />

<TextView
<org.commcare.views.connect.connecttextview.ConnectRegularTextView
android:id="@+id/primed_password_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_spacer"
android:textSize="@dimen/font_size_medium"
android:visibility="gone" />

<Button
<org.commcare.views.connect.RoundedButton
android:id="@+id/login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="45dp"
android:layout_gravity="bottom"
android:layout_marginTop="30dp"
android:nextFocusUp="@+id/edit_password"
android:paddingTop="@dimen/content_start"
android:paddingBottom="@dimen/content_start"
android:paddingTop="@dimen/content_start" />
RectangleButtonWithText:roundButtonBackgroundColor="@color/connect_blue_color"
RectangleButtonWithText:roundButtonTextColor="@color/white"
RectangleButtonWithText:roundButtonTextSize="6.0sp" />

<LinearLayout
android:id="@+id/screen_login_error_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginTop="@dimen/content_min_margin"
android:layout_marginBottom="24dp"
android:orientation="vertical"
android:visibility="gone">

<TextView
<org.commcare.views.connect.connecttextview.ConnectRegularTextView
android:id="@+id/screen_login_bad_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Expand Down
15 changes: 9 additions & 6 deletions app/src/org/commcare/activities/LoginActivityUiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import org.commcare.views.PasswordShow;
import org.commcare.views.RectangleButtonWithText;
import org.commcare.views.UiElement;
import org.commcare.views.connect.RoundedButton;
import org.commcare.views.connect.connecttextview.ConnectMediumTextView;
import org.commcare.views.connect.connecttextview.ConnectRegularTextView;
import org.javarosa.core.services.locale.Localization;

import java.util.ArrayList;
Expand All @@ -61,16 +64,16 @@ public class LoginActivityUiController implements CommCareActivityUIController {
private View notificationButtonView;

@UiElement(value = R.id.screen_login_bad_password)
private TextView errorTextView;
private ConnectRegularTextView errorTextView;

@UiElement(value = R.id.btn_view_notifications)
private RectangleButtonWithText notificationButton;

@UiElement(value = R.id.connect_login_button)
private Button connectLoginButton;
private RoundedButton connectLoginButton;

@UiElement(value = R.id.login_or)
private TextView orLabel;
private ConnectMediumTextView orLabel;

@UiElement(value = R.id.edit_username, locale = "login.username")
private AutoCompleteTextView username;
Expand All @@ -85,7 +88,7 @@ public class LoginActivityUiController implements CommCareActivityUIController {
private View banner;

@UiElement(value = R.id.login_button)
private Button loginButton;
private RoundedButton loginButton;

@UiElement(value = R.id.restore_session_checkbox)
private CheckBox restoreSessionCheckbox;
Expand All @@ -94,10 +97,10 @@ public class LoginActivityUiController implements CommCareActivityUIController {
private Spinner spinner;

@UiElement(R.id.welcome_msg)
private TextView welcomeMessage;
private ConnectMediumTextView welcomeMessage;

@UiElement(value = R.id.primed_password_message, locale = "login.primed.prompt")
private TextView loginPrimedMessage;
private ConnectRegularTextView loginPrimedMessage;

protected final LoginActivity activity;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
package org.commcare.fragments.connectId;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.activity.result.contract.ActivityResultContracts;
import androidx.databinding.adapters.TextViewBindingAdapter;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavDirections;
import androidx.navigation.Navigation;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;


import com.google.android.gms.auth.api.identity.GetPhoneNumberHintIntentRequest;
import com.google.android.gms.auth.api.identity.Identity;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnSuccessListener;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavDirections;
Expand Down Expand Up @@ -82,6 +96,24 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
}
};

PhoneNumberHelper.phoneNumberHintLauncher = registerForActivityResult(
new ActivityResultContracts.StartIntentSenderForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
Intent data = result.getData();
String phoneNumber;
try {
phoneNumber = Identity.getSignInClient(requireActivity()).getPhoneNumberFromIntent(data);
displayNumber(phoneNumber);
} catch (ApiException e) {
Toast.makeText(getContext(), R.string.error_occured, Toast.LENGTH_SHORT).show();
throw new RuntimeException(e);
}

}
}
);

binding.connectPrimaryPhoneInput.setOnFocusChangeListener(listener);
binding.countryCode.setOnFocusChangeListener(listener);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.commcare.fragments.connectId;

import android.app.Activity;
import android.app.PendingIntent;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
Expand All @@ -9,6 +12,12 @@
import android.view.ViewGroup;
import android.widget.Toast;


import com.google.android.gms.auth.api.identity.GetPhoneNumberHintIntentRequest;
import com.google.android.gms.auth.api.identity.Identity;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.OnSuccessListener;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
Expand All @@ -33,6 +42,14 @@
import java.io.InputStream;
import java.util.Locale;


import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavDirections;
import androidx.navigation.Navigation;

/**
* A simple {@link Fragment} subclass.
* Use the {@link ConnectIdPhoneFragment#newInstance} factory method to
Expand Down Expand Up @@ -89,6 +106,24 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}
};

PhoneNumberHelper.phoneNumberHintLauncher = registerForActivityResult(
new ActivityResultContracts.StartIntentSenderForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
Intent data = result.getData();
String phoneNumber;
try {
phoneNumber = Identity.getSignInClient(requireActivity()).getPhoneNumberFromIntent(data);
displayNumber(phoneNumber);
} catch (ApiException e) {
Toast.makeText(getContext(), R.string.error_occured, Toast.LENGTH_SHORT).show();
throw new RuntimeException(e);
}

}
}
);

binding.countryCode.setOnFocusChangeListener(listener);
binding.connectPrimaryPhoneInput.setOnFocusChangeListener(listener);
binding.connectPrimaryPhoneInput.addTextChangedListener(watcher);
Expand Down
Loading