Исправления, автоклуб

This commit is contained in:
Ivan Murashov
2017-07-28 18:36:51 +03:00
parent e53ceb9ef0
commit 7207c6e247
16 changed files with 203 additions and 171 deletions

View File

@@ -0,0 +1,167 @@
package com.dinect.checker;
import android.os.Bundle;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import android.content.Context;
import android.content.SharedPreferences;
import com.dinect.checker.CameraActivity;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import java.util.Map;
import java.util.ArrayList;
import java.lang.System;
public class MainActivity extends FlutterActivity {
private static final int START_SCANNER_REQUEST_CODE = 2017;
private static final String PREF_POS_MERCHANT_ID = "pref_pos_merchant_id";
private static final String PREF_DOC_ID = "pref_doc_id";
private static final String PREF_POS_ID = "pref_pos_id";
static final String PREF_POS_TOKEN = "pref_pos_token";
private MethodChannel mChannel;
private SharedPreferences mPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
mPreferences = getPreferences(Context.MODE_PRIVATE);
mChannel = new MethodChannel(getFlutterView(), "com.dinect.checker/instance_id");
mChannel.setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
switch (call.method) {
case "saveToken":
Map tokenArguments = call.arguments();
mPreferences.edit().putString(PREF_POS_TOKEN, (String) tokenArguments.get("token")).apply();
break;
case "getToken":
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":
Map arguments = call.arguments();
Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class);
cameraIntent.putExtra(PREF_POS_TOKEN, (String) arguments.get("token"));
startActivityForResult(cameraIntent, START_SCANNER_REQUEST_CODE);
break;
case "removeKeys":
mPreferences.edit().remove(PREF_POS_TOKEN).apply();
mPreferences.edit().remove(PREF_POS_MERCHANT_ID).apply();
mPreferences.edit().remove(PREF_DOC_ID).apply();
mPreferences.edit().remove(PREF_POS_ID).apply();
result.success(null);
break;
case "getDocID":
int docId = mPreferences.getInt(PREF_DOC_ID, 0) + 1;
mPreferences.edit().putInt(PREF_DOC_ID, docId).apply();
result.success(String.valueOf(docId));
break;
case "isOnline":
boolean online = Utils.isOnline(MainActivity.this);
if (!online) {
Toast.makeText(MainActivity.this, "Проверьте интернет соединение", Toast.LENGTH_SHORT).show();
}
result.success(online);
break;
case "getPosID":
String posId = mPreferences.getString(PREF_POS_ID, null);
if (posId == null) {
posId = String.valueOf(System.currentTimeMillis());
}
mPreferences.edit().putString(PREF_POS_ID, posId).apply();
result.success(posId);
break;
default:
result.notImplemented();
break;
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_CANCELED) {
finish();
} else if (requestCode == START_SCANNER_REQUEST_CODE && resultCode == RESULT_OK) {
if (data != null) {
String user = data.getExtras().getString("user", null);
if (user != null) {
String card = data.getExtras().getString("card", null);
ArrayList<String> args = new ArrayList<>(2);
args.add(user);
args.add(card);
mChannel.invokeMethod("purchase", args);
} else {
String menuItem = data.getExtras().getString("item", null);
Log.d("item", menuItem);
if (menuItem != null) {
mChannel.invokeMethod(menuItem, null);
}
}
}
}
}
public void handleItemClick() {
}
public void getDocID() {
}
public void removeKeys() {
}
public void startScanner() {
}
public void getInstanceID() {
}
public void saveToken() {
}
public void getToken() {
}
public void getPosID() {
}
public void saveMerchantID() {
}
public void getMerchantID() {
}
public void isOnline() {
}
}