search user by phone number
BIN
android/app/src/main/ic_card-web.png
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
android/app/src/main/ic_phone-web.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
@@ -41,8 +41,6 @@ import android.widget.FrameLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.dinect.checker.net.ApiClient;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
@@ -54,12 +52,17 @@ import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import com.dinect.checker.net.ApiClient;
|
||||
import com.dinect.checker.StatedImageButton;
|
||||
import com.dinect.checker.SearchType;
|
||||
import com.dinect.checker.StatedImageButton.StatedImageButtonInteractorListener;
|
||||
|
||||
|
||||
/**
|
||||
* Created by anonymous
|
||||
*/
|
||||
|
||||
public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
public abstract class AbstractScannerActivity extends AppCompatActivity implements StatedImageButtonInteractorListener{
|
||||
|
||||
private final static String TAG = "Checker.ScannerActivity";
|
||||
|
||||
@@ -70,11 +73,13 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
|
||||
protected LogoutDialogFragment logoutDialog;
|
||||
private ApiClient mClient;
|
||||
private StatedImageButton statedImageButton;
|
||||
|
||||
boolean isCameraAvailable() {
|
||||
Log.d(TAG, "isCameraAvailable");
|
||||
PackageManager pm = getPackageManager();
|
||||
return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
|
||||
|
||||
}
|
||||
|
||||
void cancelRequest(final @NonNull String message) {
|
||||
@@ -93,6 +98,8 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
mClient = new ApiClient(url, appToken, token);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* initialize activity
|
||||
* - removes windows title
|
||||
@@ -122,6 +129,8 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
toolbar.setBackgroundColor((int) intent.getLongExtra(MainActivity.PREF_APP_BAR_COLOR, 0xffffff));
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
|
||||
//
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
@@ -130,9 +139,30 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
initManualInput();
|
||||
initSwitchButton();
|
||||
setupSecretClickHandler(toolbar);
|
||||
}
|
||||
|
||||
private void initSwitchButton() {
|
||||
statedImageButton = (StatedImageButton) findViewById(R.id.cardPhoneButton);
|
||||
statedImageButton.setButtonState(SearchType.CARD);
|
||||
statedImageButton.setStatedImageButtonInteractorListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChanged(SearchType searchType) {
|
||||
Log.d(TAG, searchType.toString());
|
||||
EditText manualInput = (EditText) findViewById(R.id.manual_input);
|
||||
switch (searchType) {
|
||||
case CARD:
|
||||
manualInput.setHint(getResources().getString(R.string.enter_manual));
|
||||
break;
|
||||
case PHONE_NUMBER:
|
||||
manualInput.setHint(getResources().getString(R.string.enter_phone));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void initManualInput() {
|
||||
EditText manualInput = (EditText) findViewById(R.id.manual_input);
|
||||
|
||||
@@ -192,11 +222,11 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
|
||||
protected abstract View initScanner();
|
||||
|
||||
public void handleBarcode(final @NonNull String card) {
|
||||
mClient.findUser(card, new Callback() {
|
||||
public void handleBarcode(final @NonNull String searchString) {
|
||||
mClient.findUser(searchString, statedImageButton.getCurrentState(), new Callback() {
|
||||
@Override
|
||||
public void onFailure(Call call, IOException e) {
|
||||
handleFail(card);
|
||||
handleFail(searchString);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
@@ -207,19 +237,19 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
case 200:
|
||||
final JSONArray users = new JSONArray(body.string());
|
||||
if (users.length() > 0) {
|
||||
handleSuccess(card, users.get(0).toString());
|
||||
handleSuccess(searchString, users.get(0).toString());
|
||||
} else {
|
||||
handleFail(card);
|
||||
handleFail(searchString);
|
||||
}
|
||||
break;
|
||||
case 204:
|
||||
handleFail(card);
|
||||
handleFail(searchString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (final IOException | JSONException e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
handleFail(card);
|
||||
handleFail(searchString);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -235,11 +265,11 @@ public abstract class AbstractScannerActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
protected final void handleFail(final String card) {
|
||||
protected final void handleFail(final String searchString) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String message = String.format(getString(R.string.identifier_not_found), card)
|
||||
String message = String.format(getString(R.string.identifier_not_found), searchString)
|
||||
+ ".\n"
|
||||
+ String.format(getString(R.string.error_contact_support), BuildConfig.supportPhone);
|
||||
Toast.makeText(AbstractScannerActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.dinect.checker;
|
||||
|
||||
public enum SearchType {
|
||||
CARD,
|
||||
PHONE_NUMBER
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.dinect.checker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.dinect.checker.R;
|
||||
import com.dinect.checker.SearchType;
|
||||
|
||||
public class StatedImageButton extends LinearLayout {
|
||||
private Context mContext;
|
||||
private View mRootView;
|
||||
|
||||
private ImageButton mBtnImageState;
|
||||
private SearchType mCurrentButtonState = SearchType.CARD;
|
||||
private StatedImageButtonInteractorListener statedImageButtonInteractorListener;
|
||||
|
||||
public StatedImageButton(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public SearchType getCurrentState() {
|
||||
return mCurrentButtonState;
|
||||
}
|
||||
|
||||
public StatedImageButton(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public StatedImageButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mContext = context;
|
||||
mRootView = inflate(mContext, R.layout.partial_buttons_layout, this);
|
||||
mBtnImageState = (ImageButton) mRootView.findViewById(R.id.btn_image_state);
|
||||
mBtnImageState.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mCurrentButtonState == SearchType.CARD) {
|
||||
mCurrentButtonState = SearchType.PHONE_NUMBER;
|
||||
} else {
|
||||
mCurrentButtonState = SearchType.CARD;
|
||||
}
|
||||
setButtonState(mCurrentButtonState);
|
||||
if (statedImageButtonInteractorListener != null) {
|
||||
statedImageButtonInteractorListener.onStateChanged(mCurrentButtonState);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setButtonState(SearchType searchType) {
|
||||
mCurrentButtonState = searchType;
|
||||
|
||||
switch (mCurrentButtonState) {
|
||||
case CARD:
|
||||
mBtnImageState.setBackground(getResources().getDrawable(R.drawable.ic_card));
|
||||
break;
|
||||
case PHONE_NUMBER:
|
||||
mBtnImageState.setBackground(getResources().getDrawable(R.drawable.ic_phone));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setStatedImageButtonInteractorListener(StatedImageButtonInteractorListener statedImageButtonInteractorListener) {
|
||||
this.statedImageButtonInteractorListener = statedImageButtonInteractorListener;
|
||||
}
|
||||
|
||||
public interface StatedImageButtonInteractorListener {
|
||||
void onStateChanged(SearchType searchType);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
import com.dinect.checker.SearchType;
|
||||
|
||||
/**
|
||||
* Created by anonymous
|
||||
*/
|
||||
@@ -47,11 +49,19 @@ public final class ApiClient {
|
||||
.build();
|
||||
}
|
||||
|
||||
public void findUser(String card, Callback callback) {
|
||||
public void findUser(String searchString, SearchType searchType, Callback callback) {
|
||||
final Request.Builder requestBuilder = new Request.Builder();
|
||||
final HttpUrl url = HttpUrl.parse(mEndpoint);
|
||||
if (url != null) {
|
||||
HttpUrl.Builder httpBuilder = url.newBuilder().addQueryParameter("auto", card);
|
||||
HttpUrl.Builder httpBuilder = url.newBuilder();
|
||||
switch (searchType) {
|
||||
case CARD:
|
||||
httpBuilder.addQueryParameter("auto", searchString);
|
||||
break;
|
||||
case PHONE_NUMBER:
|
||||
httpBuilder.addQueryParameter("phone", searchString);
|
||||
break;
|
||||
}
|
||||
mHttp.newCall(requestBuilder.url(httpBuilder.build()).build()).enqueue(callback);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
android/app/src/main/res/drawable-xxxhdpi/ic_card.png
Normal file
|
After Width: | Height: | Size: 597 B |
BIN
android/app/src/main/res/drawable-xxxhdpi/ic_phone.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
15
android/app/src/main/res/layout/partial_buttons_layout.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btn_image_state"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</merge>
|
||||
@@ -1,21 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/toolbar"
|
||||
<android.support.v7.widget.Toolbar
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fitsSystemWindows="true"
|
||||
android:orientation="vertical"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
app:titleTextColor="@android:color/white">
|
||||
|
||||
<com.dinect.checker.StatedImageButton
|
||||
android:id="@+id/cardPhoneButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/manual_input"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:titleTextColor="@android:color/white">
|
||||
android:hint="@string/enter_manual"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:textColor="@android:color/white"
|
||||
android:textColorHint="@android:color/white"/>
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:id="@+id/manual_input"
|
||||
android:hint="@string/enter_manual"
|
||||
android:maxLines="1"
|
||||
android:inputType="text"
|
||||
android:imeOptions="actionDone"
|
||||
android:layout_marginLeft="72dp"
|
||||
android:textColor="@android:color/white"
|
||||
android:textColorHint="@android:color/white"/>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
BIN
android/app/src/main/res/mipmap-hdpi/ic_card.png
Normal file
|
After Width: | Height: | Size: 946 B |
BIN
android/app/src/main/res/mipmap-hdpi/ic_phone.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_card.png
Normal file
|
After Width: | Height: | Size: 676 B |
BIN
android/app/src/main/res/mipmap-mdpi/ic_phone.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_card.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_phone.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_card.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_phone.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_card.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_phone.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
@@ -11,5 +11,6 @@
|
||||
<string name="logout_no">Нет</string>
|
||||
<string name="identifier_not_found">"Идентификатор %s не найден"</string>
|
||||
<string name="enter_manual">Введите штрихкод вручную</string>
|
||||
<string name="enter_phone">Введите номер телефона</string>
|
||||
<string name="error_contact_support">Можете воспользоваться ручным вводом или позвонить на номер:%s</string>
|
||||
</resources>
|
||||
|
||||
@@ -11,5 +11,6 @@
|
||||
<string name="logout_no">Ні</string>
|
||||
<string name="identifier_not_found">"Ідентифікатор %s не знайден"</string>
|
||||
<string name="enter_manual">Введіть штрихкод вручну</string>
|
||||
<string name="enter_phone">Введіть номер телефону</string>
|
||||
<string name="error_contact_support">Можете скористатися ручним введенням або зателефонувати на номер:\n%s</string>
|
||||
</resources>
|
||||
|
||||
@@ -11,5 +11,6 @@
|
||||
<string name="logout_no">No</string>
|
||||
<string name="identifier_not_found">"Identifier %s is not found"</string>
|
||||
<string name="enter_manual">Enter the barcode manually</string>
|
||||
<string name="enter_phone">Enter the phone number</string>
|
||||
<string name="error_contact_support">You can use manual input or call the number:\n%s</string>
|
||||
</resources>
|
||||
|
||||