update for demo

This commit is contained in:
GME 2019-05-25 14:35:36 +02:00
parent a7fcd2dd47
commit 27eb364aa7
12 changed files with 526 additions and 12 deletions

View file

@ -43,7 +43,8 @@
<activity android:name="monnethic.mobile.search.SearchUser" /> <activity android:name="monnethic.mobile.search.SearchUser" />
<activity android:name="monnethic.mobile.search.DisplayWalletSearch" /> <activity android:name="monnethic.mobile.search.DisplayWalletSearch" />
<activity android:name="monnethic.mobile.history.HistoryActivity" /> <activity android:name="monnethic.mobile.history.HistoryActivity" />
<activity android:name="monnethic.mobile.history.HistoryDetailsActivity"></activity> <activity android:name="monnethic.mobile.history.HistoryDetailsActivity" />
<activity android:name="monnethic.mobile.demoConfig.DemoConfig"></activity>
</application> </application>
</manifest> </manifest>

View file

@ -0,0 +1,171 @@
package monnethic.mobile.demoConfig;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R;
import java.util.ArrayList;
import java.util.List;
import monnethic.mobile.history.HistoryActivity;
import monnethic.mobile.restApi.ConfigApiHandler;
public class DemoConfig extends AppCompatActivity {
private Spinner cSpinner;
private Switch cSwitch;
private Button btnValidateConf;
private Button btnCloseConf;
private Button btnCheckConf;
private String ENV;
private String CHAINCODE;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo_config);
initView();
}
private void initView(){
buttonInit();
switchInit();
spinnerInit();
}
public void switchInit(){
cSwitch = findViewById(R.id.switchEnv);
cSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(cSwitch.isChecked()){
ENV = "1";
}else{
ENV = "0";
}
}
});
}
public void spinnerInit(){
cSpinner = findViewById(R.id.spinnerConfig);
List<String> listOptions = new ArrayList<>();
listOptions.add("CHAINCODE - PROD");
listOptions.add("CHAINCODE - QA");
listOptions.add("CHAINCODE - TEST");
ArrayAdapter<String> adapterOptions = new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item,listOptions);
adapterOptions.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cSpinner.setAdapter(adapterOptions);
}
public void buttonInit(){
btnValidateConf = findViewById(R.id.buttonValidateConfig);
btnValidateConf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (String.valueOf(cSpinner.getSelectedItem())){
case "CHAINCODE - PROD":
CHAINCODE = "0";
break;
case "CHAINCODE - QA":
CHAINCODE = "1";
break;
case "CHAINCODE - TEST":
CHAINCODE = "2";
break;
}
new updateConfigTask().execute(ENV,CHAINCODE);
}
});
btnCheckConf = findViewById(R.id.buttonCheckConfig);
btnCheckConf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new checkConfigTask().execute();
}
});
btnCloseConf = findViewById(R.id.buttonCloseConfig);
btnCloseConf.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
private class updateConfigTask extends AsyncTask<String,String,String> {
ProgressDialog progDailog = new ProgressDialog(DemoConfig.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog.setMessage("Updating Config...");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(true);
progDailog.show();
}
@Override
protected String doInBackground(String... strings) {
try{
String e = strings[0];
String c = strings[1];
ConfigApiHandler configApiHandler = new ConfigApiHandler();
configApiHandler.updateEnvironment(e);
configApiHandler.updateChaincode(c);
}catch (Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
progDailog.dismiss();
}
}
private class checkConfigTask extends AsyncTask<String,String,String>{
ProgressDialog progDailog = new ProgressDialog(DemoConfig.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog.setMessage("Check Config...");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(true);
progDailog.show();
}
@Override
protected String doInBackground(String... strings) {
try{
ConfigApiHandler configApiHandler = new ConfigApiHandler();
String r = configApiHandler.getConfiguration();
return r;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
@Override
protected void onPostExecute(String result) {
progDailog.dismiss();
Toast.makeText(DemoConfig.this, result,Toast.LENGTH_SHORT).show();
}
}
}

View file

@ -11,6 +11,8 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
import monnethic.mobile.demoConfig.DemoConfig;
public class HomepageActivity extends AppCompatActivity { public class HomepageActivity extends AppCompatActivity {
@Override @Override
@ -19,6 +21,7 @@ public class HomepageActivity extends AppCompatActivity {
setContentView(R.layout.activity_homepage); setContentView(R.layout.activity_homepage);
Button bRegister = findViewById(R.id.register); Button bRegister = findViewById(R.id.register);
Button bLogin = findViewById(R.id.login); Button bLogin = findViewById(R.id.login);
Button bConfig = findViewById(R.id.buttonConfig);
bRegister.setOnClickListener(new View.OnClickListener() { bRegister.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -32,6 +35,12 @@ public class HomepageActivity extends AppCompatActivity {
launchLoginActivity(); launchLoginActivity();
} }
}); });
bConfig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
launchConfActivity();
}
});
} }
public void launchRegisterActivity(){ public void launchRegisterActivity(){
@ -50,4 +59,9 @@ public class HomepageActivity extends AppCompatActivity {
HomepageActivity.this.startActivity(loginIntent); HomepageActivity.this.startActivity(loginIntent);
} }
public void launchConfActivity(){
Intent confIntent = new Intent(HomepageActivity.this, DemoConfig.class);
HomepageActivity.this.startActivity(confIntent);
}
} }

View file

@ -143,6 +143,7 @@ public class RegisterActivity extends AppCompatActivity {
walletHomeIntent.putExtra("USER_HASH", jsonObject.getString("user_hash")); walletHomeIntent.putExtra("USER_HASH", jsonObject.getString("user_hash"));
walletHomeIntent.putExtra("USER_PWD",password.getText().toString()); walletHomeIntent.putExtra("USER_PWD",password.getText().toString());
walletHomeIntent.putExtra("SESSION_ID",jsonObject.getString("session_id")); walletHomeIntent.putExtra("SESSION_ID",jsonObject.getString("session_id"));
walletHomeIntent.putExtra("email",email.getText().toString());
RegisterActivity.this.startActivity(walletHomeIntent); RegisterActivity.this.startActivity(walletHomeIntent);
finish(); finish();
}else{ }else{

View file

@ -14,6 +14,8 @@ public class Config {
static public String USER_LOGIN = BASE_URL_USER+"login"; static public String USER_LOGIN = BASE_URL_USER+"login";
static public String USER_REGISTER = BASE_URL_USER+"register"; static public String USER_REGISTER = BASE_URL_USER+"register";
static public String USER_GET = BASE_URL_USER+"get"; static public String USER_GET = BASE_URL_USER+"get";
static public String USER_APPROVAL = BASE_URL_USER+"getApproval";
static public String USER_APPROVE = BASE_URL_USER+"approve";
//Search //Search
static public String FIND_BY_EMAIL= BASE_URL_USER+"findByEmail"; static public String FIND_BY_EMAIL= BASE_URL_USER+"findByEmail";
static public String FIND_BY_PHONE = BASE_URL_USER+"findByPhone"; static public String FIND_BY_PHONE = BASE_URL_USER+"findByPhone";
@ -22,6 +24,13 @@ public class Config {
static public String START_SESSION = BASE_URL_SESSION+"start"; static public String START_SESSION = BASE_URL_SESSION+"start";
static public String END_SESSION = BASE_URL_SESSION+"end"; static public String END_SESSION = BASE_URL_SESSION+"end";
//Config
static private String CONFIG_BASE_URL = BASE_URL+"/api/rest/demo/conf";
static public String CONFIG_ENVIRONMENT = CONFIG_BASE_URL+"/env";
static public String CONFIG_CHAINCODE = CONFIG_BASE_URL+"/chaincode";
static public String CONFIG_DB = CONFIG_BASE_URL+"/db";
//TRANSACTION //TRANSACTION
static public String TRANSACTION_SEND = BASE_URL_TRANSACTION+"send"; static public String TRANSACTION_SEND = BASE_URL_TRANSACTION+"send";
static public String TRANSACTION_GET = BASE_URL_TRANSACTION+"get"; static public String TRANSACTION_GET = BASE_URL_TRANSACTION+"get";

View file

@ -0,0 +1,48 @@
package monnethic.mobile.restApi;
import org.json.JSONObject;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class ConfigApiHandler {
public void updateEnvironment(String environment){
HttpCallHandler httpCallHandler = new HttpCallHandler();
try{
String url = Config.CONFIG_ENVIRONMENT;
Map<String, String> map = new HashMap<>();
map.put("env",environment);
httpCallHandler.postHttp(new URL(url), map);
}catch (Exception e){
e.printStackTrace();
}
}
public void updateChaincode(String chaincode){
HttpCallHandler httpCallHandler = new HttpCallHandler();
try{
String url = Config.CONFIG_CHAINCODE;
Map<String, String> map = new HashMap<>();
map.put("chaincode",chaincode);
httpCallHandler.postHttp(new URL(url), map);
}catch (Exception e){
e.printStackTrace();
}
}
public String getConfiguration(){
HttpCallHandler httpCallHandler = new HttpCallHandler();
String result="";
try{
String chaincode = new JSONObject(httpCallHandler.getHttp(new URL(Config.CONFIG_CHAINCODE))).getString("chaincode");
String environment = new JSONObject(httpCallHandler.getHttp(new URL(Config.CONFIG_ENVIRONMENT))).getString("env");
String db = new JSONObject(httpCallHandler.getHttp(new URL(Config.CONFIG_DB))).getString("db");
result = environment+" - "+chaincode+" - "+db;
}catch (Exception e){
e.printStackTrace();
}
return result;
}
}

View file

@ -92,6 +92,29 @@ public class UserApiHandler {
} }
public Boolean checkApproval(String user_hash, String email){
HttpCallHandler httpCallHandler = new HttpCallHandler();
try{
String responseCall = httpCallHandler.getHttp(new URL(Config.USER_APPROVAL+"?user_hash="+user_hash+"&user_email="+email));
return new JSONObject(responseCall).getBoolean("approval");
}catch (Exception e){
e.printStackTrace();
return null;
}
}
public void approveUser(String user_hash, String email){
HttpCallHandler httpCallHandler = new HttpCallHandler();
try{
Map<String, String> map = new HashMap<>();
map.put("user_hash",user_hash);
map.put("email",email);
httpCallHandler.postHttp(new URL(Config.USER_APPROVE),map);
}catch (Exception e){
e.printStackTrace();
}
}
public User getUser(int method, String email, String phone){ public User getUser(int method, String email, String phone){
HttpCallHandler httpCallHandler = new HttpCallHandler(); HttpCallHandler httpCallHandler = new HttpCallHandler();
User returnUser = new User(); User returnUser = new User();
@ -113,6 +136,7 @@ public class UserApiHandler {
returnUser.setName(jsonObject.getString("name")); returnUser.setName(jsonObject.getString("name"));
returnUser.setFirstname(jsonObject.getString("firstname")); returnUser.setFirstname(jsonObject.getString("firstname"));
returnUser.setUser_hash(jsonObject.getString("user_hash")); returnUser.setUser_hash(jsonObject.getString("user_hash"));
returnUser.setApproved(jsonObject.getBoolean("approved"));
return returnUser; return returnUser;
}else{ }else{

View file

@ -1,18 +1,27 @@
package monnethic.mobile.wallet; package monnethic.mobile.wallet;
import android.app.ProgressDialog;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast;
import com.example.monnthic.monnethicmobile.R; import com.example.monnthic.monnethicmobile.R;
import org.json.JSONObject;
import monnethic.mobile.database.User;
import monnethic.mobile.restApi.SessionApiHandler; import monnethic.mobile.restApi.SessionApiHandler;
import monnethic.mobile.restApi.UserApiHandler;
public class HomeWalletActivity extends AppCompatActivity { public class HomeWalletActivity extends AppCompatActivity {
private String user_hash; private String user_hash;
private String user_password; private String user_password;
private String session_id; private String session_id;
private String email;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -20,11 +29,13 @@ public class HomeWalletActivity extends AppCompatActivity {
setContentView(R.layout.activity_home_wallet); setContentView(R.layout.activity_home_wallet);
Button buttonCreateWallet = findViewById(R.id.buttonCreateWallet); Button buttonCreateWallet = findViewById(R.id.buttonCreateWallet);
Button buttonSelectWallet = findViewById(R.id.buttonSelectWallet); Button buttonSelectWallet = findViewById(R.id.buttonSelectWallet);
Button buttonApproveUser = findViewById(R.id.buttonApproveUser);
Intent intent = getIntent(); Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH"); user_hash = intent.getStringExtra("USER_HASH");
user_password = intent.getStringExtra("USER_PWD"); user_password = intent.getStringExtra("USER_PWD");
session_id = intent.getStringExtra("SESSION_ID"); session_id = intent.getStringExtra("SESSION_ID");
email = intent.getStringExtra("email");
buttonCreateWallet.setOnClickListener(new View.OnClickListener() { buttonCreateWallet.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -39,22 +50,52 @@ public class HomeWalletActivity extends AppCompatActivity {
launchSelectWalletActivity(); launchSelectWalletActivity();
} }
}); });
buttonApproveUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
approveUser();
}
});
} }
public void launchCreateWalletActivity() { public void launchCreateWalletActivity() {
Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class); try{
createWalletIntent.putExtra("USER_HASH",user_hash); Boolean approved = new CheckApprovalTask().execute(user_hash,email).get();
createWalletIntent.putExtra("USER_PWD",user_password);
createWalletIntent.putExtra("SESSION_ID",session_id); if(approved){
HomeWalletActivity.this.startActivity(createWalletIntent); Intent createWalletIntent = new Intent(HomeWalletActivity.this, CreateWalletActivity.class);
createWalletIntent.putExtra("USER_HASH",user_hash);
createWalletIntent.putExtra("USER_PWD",user_password);
createWalletIntent.putExtra("SESSION_ID",session_id);
HomeWalletActivity.this.startActivity(createWalletIntent);
}else{
Toast.makeText(HomeWalletActivity.this,"You are not approved",Toast.LENGTH_SHORT).show();
}
} catch (Exception e){
e.printStackTrace();
}
} }
public void launchSelectWalletActivity() { public void launchSelectWalletActivity() {
Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class); try{
selectWalletIntent.putExtra("USER_HASH",user_hash); Boolean approved = new CheckApprovalTask().execute(user_hash,email).get();
selectWalletIntent.putExtra("USER_PWD",user_password); if(approved){
selectWalletIntent.putExtra("SESSION_ID",session_id); Intent selectWalletIntent = new Intent(HomeWalletActivity.this, SelectWalletActivity.class);
HomeWalletActivity.this.startActivity(selectWalletIntent); selectWalletIntent.putExtra("USER_HASH",user_hash);
selectWalletIntent.putExtra("USER_PWD",user_password);
selectWalletIntent.putExtra("SESSION_ID",session_id);
HomeWalletActivity.this.startActivity(selectWalletIntent);
}else {
Toast.makeText(HomeWalletActivity.this,"You are not approved",Toast.LENGTH_SHORT).show();
}
}catch (Exception e){
e.printStackTrace();
}
}
public void approveUser(){
new ApproveTask().execute(user_hash,email);
} }
@Override @Override
@ -75,4 +116,62 @@ public class HomeWalletActivity extends AppCompatActivity {
return null; return null;
} }
} }
private class CheckApprovalTask extends AsyncTask<String,Boolean,Boolean>{
ProgressDialog progDailog = new ProgressDialog(HomeWalletActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog.setMessage("Loading...");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(true);
progDailog.show();
}
@Override
protected Boolean doInBackground(String... strings) {
try{
UserApiHandler userApiHandler = new UserApiHandler();
return userApiHandler.checkApproval(strings[0],strings[1]);
}catch (Exception e){
return null;
}
}
@Override
protected void onPostExecute(Boolean result) {
progDailog.dismiss();
}
}
private class ApproveTask extends AsyncTask<String,String,String>{
ProgressDialog progDailog = new ProgressDialog(HomeWalletActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog.setMessage("Loading...");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(true);
progDailog.show();
}
@Override
protected void onPostExecute(String result) {
progDailog.dismiss();
}
@Override
protected String doInBackground(String... strings) {
try{
UserApiHandler userApiHandler = new UserApiHandler();
userApiHandler.approveUser(strings[0],strings[1]);
return null;
}catch (Exception e){
e.printStackTrace();
return null;
}
}
}
} }

View file

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:context="monnethic.mobile.demoConfig.DemoConfig">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:layout_marginRight="3dp">
<TextView
android:id="@+id/prodEnv"
android:layout_width="130dp"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:layout_marginStart="25dp"
android:layout_marginTop="0dp"
android:clickable="true"
android:editable="false"
android:ems="10"
android:hint="From"
android:inputType="none"
android:text="PROD ENVIRONMENT"
android:textSize="14sp" />
<Switch
android:id="@+id/switchEnv"
android:layout_width="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="match_parent"
android:layout_toEndOf="@+id/prodEnv" />
<TextView
android:id="@+id/bckpEnv"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="0dp"
android:layout_marginEnd="25dp"
android:layout_toEndOf="@+id/switchEnv"
android:clickable="true"
android:editable="false"
android:ems="10"
android:hint="To"
android:inputType="none"
android:text="BACKPUP ENVIRONMENT"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp">
<Spinner
android:id="@+id/spinnerConfig"
android:layout_width="match_parent"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_height="40dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp">
<Button
android:id="@+id/buttonValidateConfig"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="VALIDATE"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp">
<Button
android:id="@+id/buttonCheckConfig"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="CHECK"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp">
<Button
android:id="@+id/buttonCloseConfig"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="CLOSE"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>

View file

@ -6,9 +6,23 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="monnethic.mobile.wallet.HomeWalletActivity"> tools:context="monnethic.mobile.wallet.HomeWalletActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/buttonApproveUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Approve"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:gravity="center" android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"

View file

@ -44,4 +44,12 @@
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginTop="51dp" android:layout_marginTop="51dp"
app:srcCompat="@drawable/newlogo" /> app:srcCompat="@drawable/newlogo" />
<Button
android:id="@+id/buttonConfig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="CONF" />
</RelativeLayout> </RelativeLayout>