Регистрация, проверка токена, обработка ошибок, сканирование

This commit is contained in:
Ivan Murashov
2017-07-21 22:35:28 +03:00
parent 013a75e464
commit 8cf5d4b028
10 changed files with 454 additions and 185 deletions

View File

@@ -2,6 +2,7 @@ package com.dinect.checker.activity;
import android.support.v7.app.AppCompatActivity;
import android.content.pm.ActivityInfo;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
@@ -69,7 +70,7 @@ public class CameraActivity extends AppCompatActivity {
if (actionBar != null) {
actionBar.setTitle(getString(R.string.scanner_title));
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
}
mCamera = getCameraInstance();
@@ -117,6 +118,12 @@ public class CameraActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
setResult(RESULT_CANCELED);
finish();
}
@Override
public void onDestroy() {
super.onDestroy();
@@ -193,6 +200,10 @@ public class CameraActivity extends AppCompatActivity {
SymbolSet syms = mScanner.getResults();
for (Symbol sym : syms) {
mBarcodeScanned = true;
Intent intent = new Intent();
intent.putExtra("code", sym.getData());
setResult(RESULT_OK, intent);
finish();
Toast.makeText(CameraActivity.this, sym.getData(), Toast.LENGTH_SHORT).show();
}
}

View File

@@ -19,8 +19,11 @@ import java.util.Map;
public class MainActivity extends FlutterActivity {
private static final int START_SCANNER_REQUEST_CODE = 2017;
private static final String PREF_POS_TOKEN = "pref_pos_token";
private static final String PREF_POS_MERCHANT_ID = "pref_pos_merchant_id";
private MethodChannel mChannel;
private SharedPreferences mPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -28,8 +31,7 @@ public class MainActivity extends FlutterActivity {
GeneratedPluginRegistrant.registerWith(this);
final String INSTANCE_ID_CHANNEL = "com.dinect.checker/instance_id";
final String PREF_POS_TOKEN = "pref_pos_token";
final SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
mPreferences = getPreferences(Context.MODE_PRIVATE);
mChannel = new MethodChannel(getFlutterView(), INSTANCE_ID_CHANNEL);
mChannel.setMethodCallHandler(
@@ -47,13 +49,18 @@ public class MainActivity extends FlutterActivity {
}
break;
case "saveToken":
Map arguments = call.arguments();
String token = (String) arguments.get("token");
Log.d("kifio", token);
preferences.edit().putString(PREF_POS_TOKEN, token).apply();
Map tokenArguments = call.arguments();
mPreferences.edit().putString(PREF_POS_TOKEN, (String) tokenArguments.get("token")).apply();
break;
case "getToken":
result.success(preferences.getString(PREF_POS_TOKEN, null));
result.success(mPreferences.getString(PREF_POS_TOKEN, null));
break;
case "saveMerchantID":
Map merchantIDArguments = call.arguments();
mPreferences.edit().putString(PREF_POS_MERCHANT_ID, (String) merchantIDArguments.get("merchantID")).apply();
break;
case "getMerchantID":
result.success(mPreferences.getString(PREF_POS_MERCHANT_ID, null));
break;
case "startScanner":
Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class);
@@ -69,11 +76,28 @@ public class MainActivity extends FlutterActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {
mChannel.invokeMethod("foo", null);
if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_CANCELED) {
finish();
} else if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {
if (data == null) {
logout();
} else {
String code = data.getExtras().getString("code", null);
if (code == null) {
logout();
} else {
mChannel.invokeMethod("purchase", code);
}
}
}
}
private void logout() {
mChannel.invokeMethod("foo", null);
mPreferences.edit().remove(PREF_POS_TOKEN).apply();
mPreferences.edit().remove(PREF_POS_MERCHANT_ID).apply();
}
public void startScanner() {
}
@@ -90,4 +114,12 @@ public class MainActivity extends FlutterActivity {
}
public void saveMerchantID() {
}
public void getMerchantID() {
}
}

View File

@@ -10,6 +10,39 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
<View android:layout_height="0dp"
android:layout_weight="0.42"
android:layout_width="match_parent"
android:background="#с0000000"/>
<FrameLayout android:layout_height="0dp"
android:layout_weight="0.16"
android:layout_width="match_parent">
<View android:layout_height="match_parent"
android:layout_width="24dp"
android:layout_gravity="left"
android:background="#с0000000"/>
<View android:layout_height="match_parent"
android:layout_width="24dp"
android:layout_gravity="right"
android:background="#с0000000"/>
</FrameLayout>
<View android:layout_height="0dp"
android:layout_weight="0.42"
android:layout_width="match_parent"
android:background="#с0000000"/>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"