Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

Fix #79 and #82 Add phone number prefix #124

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ dependencies {
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'net.hockeyapp.android:HockeySDK:4.1.1'

implementation 'com.hbb20:ccp:2.2.6'

testImplementation 'junit:junit:' + rootProject.junitVersion
testImplementation 'org.mockito:mockito-core:' + rootProject.mockitoVersion
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="ro.code4.monitorizarevot"
xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand All @@ -23,7 +24,8 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:allowBackup="false">
android:allowBackup="false"
tools:replace="android:allowBackup">
<activity
android:name=".StartActivity"
android:noHistory="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.widget.TextView;
import android.widget.Toast;

import com.hbb20.CountryCodePicker;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
Expand All @@ -27,6 +29,10 @@

public class LoginActivity extends BaseActivity<LoginViewModel> {


@BindView(R.id.country_code)
CountryCodePicker countryCodePicker;

@BindView(R.id.phone)
EditText username;

Expand Down Expand Up @@ -92,10 +98,11 @@ boolean onDoneEditPassword(TextView textView, int i, KeyEvent keyEvent) {
}

private void login() {
String countryCode = countryCodePicker.getSelectedCountryCodeWithPlus();
String phoneNumber = username.getText().toString();
String pin = password.getText().toString();
String udid = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
viewModel.login(phoneNumber, pin, udid);
viewModel.login(countryCode + phoneNumber, pin, udid);
}

private void showErrorDialog(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package ro.code4.monitorizarevot.data.repository;

import android.telephony.PhoneNumberUtils;

import static android.text.TextUtils.isEmpty;

import javax.inject.Inject;
import javax.inject.Singleton;

import io.michaelrocks.libphonenumber.android.PhoneNumberUtil;
import ro.code4.monitorizarevot.data.datasource.ApiDataSource;
import ro.code4.monitorizarevot.data.datasource.DataSourceFactory;
import ro.code4.monitorizarevot.domain.exception.MessageType;
Expand All @@ -30,8 +33,12 @@ public Observable<Boolean> login(LoginDataParams params) {
return Observable.error(new VoteException(MessageType.EMPTY_CREDENTIALS));
}

if(!PhoneNumberUtils.isGlobalPhoneNumber(params.getPhoneNumber())) {
return Observable.error(new VoteException(MessageType.INVALID_PHONE_NUMBER));
}

ApiDataSource apiDataSource = mDataSourceFactory.dataSource(params.isLocal());
User user = new User(params.getPhoneNumber(), params.getPinNumber(), params.getUdid());
User user = new User(params.getPhoneNumber().replaceAll("[^+\\d.]", ""), params.getPinNumber(), params.getUdid());

return apiDataSource.login(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public enum MessageType {
EMPTY_CREDENTIALS,
INVALID_PHONE_NUMBER,
NO_INTERNET_CONNECTION,
SERVER_ERROR,
CUSTOM_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ private Message getMessage(MessageType type) {
message = mContext.getString(R.string.error_empty_credentials);
break;

case INVALID_PHONE_NUMBER:
message = mContext.getString(R.string.error_invalid_phone_number);
break;

case NO_INTERNET_CONNECTION:
message = mContext.getString(R.string.error_no_connection);
break;
Expand Down
114 changes: 75 additions & 39 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
<FrameLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="ro.code4.monitorizarevot.LoginActivity">

<FrameLayout
android:id="@+id/purple_background"
style="@style/SharedElementLoginBackground"
android:background="@drawable/ic_login_bkg"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:background="@drawable/ic_login_bkg">

<LinearLayout
android:id="@+id/login_organisation_link"
android:layout_width="match_parent"
android:layout_height="36dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:background="@color/backgroundLight"
android:gravity="bottom|end"
android:background="@color/backgroundLight">
android:paddingTop="2dp"
android:paddingBottom="2dp">

<TextView
style="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/developed_by"/>
android:text="@string/developed_by" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand All @@ -33,84 +36,117 @@
</FrameLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="36dp">
android:layout_marginTop="36dp"
android:orientation="vertical"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin">

<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
android:layout_weight="1"
android:orientation="horizontal">

<TextView
android:id="@+id/app_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
tools:text="V0.00"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:textColor="@color/textSecondary"
android:textSize="14sp" />
android:textSize="14sp"
tools:text="V0.00" />

<ImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="@drawable/logo_new"
android:id="@+id/logo"
tools:ignore="ContentDescription" />
</RelativeLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.design.widget.TextInputLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColorHint="@color/textPrimary"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin">
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="@dimen/input_height"
android:hint="@string/login_phone"
android:inputType="phone"
style="@style/InputLogin"/>
<com.hbb20.CountryCodePicker
android:id="@+id/country_code"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".3"
android:gravity="bottom"
app:ccp_autoDetectCountry="true"
app:ccp_countryAutoDetectionPref="SIM_ONLY"
app:ccp_defaultNameCode="RO"
app:ccp_showFlag="false" />

<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight=".7"
android:textColorHint="@color/textPrimary">

<EditText
android:id="@+id/phone"
style="@style/InputLogin"
android:layout_width="match_parent"
android:layout_height="@dimen/input_height"
android:background="@android:color/transparent"
android:hint="@string/login_phone"
android:includeFontPadding="false"
android:inputType="phone" />

</android.support.design.widget.TextInputLayout>

</android.support.design.widget.TextInputLayout>
</LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/accent" />

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColorHint="@color/textPrimary"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/login_margin_bottom">
android:textColorHint="@color/textPrimary">

<EditText
android:id="@+id/branch"
style="@style/InputLogin"
android:layout_width="match_parent"
android:layout_height="@dimen/input_height"
android:background="@android:color/transparent"
android:hint="@string/login_branch"
android:inputType="textPassword"
android:imeOptions="actionDone"
style="@style/InputLogin"/>
android:inputType="textPassword" />

</android.support.design.widget.TextInputLayout>

<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/login_margin_bottom"
android:background="@color/accent" />

<Button
android:id="@+id/login_button"
style="@style/buttonEmbedded"
android:layout_width="match_parent"
android:layout_height="@dimen/button_height"
android:text="@string/login"
android:layout_gravity="bottom"
style="@style/buttonEmbedded"/>
android:text="@string/login" />
</LinearLayout>

</LinearLayout>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ro/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="hint_time">hh:mm</string>
<string name="empty" />
<string name="error_empty_credentials">Introduceți numărul de telefon şi codul primit.</string>
<string name="error_invalid_phone_number">Numarul de telefon nu este valid.</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use diacritics

<string name="error_no_connection">Nu există conexiune la internet. Vă rugăm să vă conectați și să încercați din nou</string>
<string name="error_server">Eroare de server</string>
<string name="error_unknown">Eroare necunoscută</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<string name="hint_time">hh:mm</string>
<string name="empty" />
<string name="error_empty_credentials">Fill in your phone number and the code you received.</string>
<string name="error_invalid_phone_number">Invalid phone number.</string>
<string name="error_no_connection">No internet connection. Please connect and try again</string>
<string name="error_server">A server error has occurred</string>
<string name="error_unknown">An unknown error has occurred</string>
Expand Down