diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
index 37735c1..74a7bb1 100644
Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 98d711f..a5b58a7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -40,7 +40,9 @@
-
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/monnethic/mobile/restApi/Config.java b/app/src/main/java/monnethic/mobile/restApi/Config.java
index e42ba06..0dc49fa 100644
--- a/app/src/main/java/monnethic/mobile/restApi/Config.java
+++ b/app/src/main/java/monnethic/mobile/restApi/Config.java
@@ -2,8 +2,8 @@ package monnethic.mobile.restApi;
public class Config {
//BASE
- static private String BASE_URL = "http://37.187.101.44:10053/";
- //static private String BASE_URL = "http://10.0.2.2:10053/";
+ //static private String BASE_URL = "http://37.187.101.44:10053/";
+ static private String BASE_URL = "http://10.0.2.2:10053/";
//static private String BASE_URL = "http://localhost:10053/";
static private String BASE_URL_USER = BASE_URL+"api/rest/user/";
static private String BASE_URL_TRANSACTION = BASE_URL+"api/rest/transaction/";
@@ -13,6 +13,10 @@ public class Config {
static public String USER_LOGIN = BASE_URL_USER+"login";
static public String USER_REGISTER = BASE_URL_USER+"register";
static public String USER_GET = BASE_URL_USER+"get";
+ //Search
+ 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_EMAIL_AND_PHONE = BASE_URL_USER+"findByEmailAndPhone";
//TRANSACTION
static public String TRANSACTION_SEND = BASE_URL_TRANSACTION+"send";
diff --git a/app/src/main/java/monnethic/mobile/restApi/UserApiHandler.java b/app/src/main/java/monnethic/mobile/restApi/UserApiHandler.java
index 9265754..2a3f4c5 100644
--- a/app/src/main/java/monnethic/mobile/restApi/UserApiHandler.java
+++ b/app/src/main/java/monnethic/mobile/restApi/UserApiHandler.java
@@ -85,4 +85,37 @@ public class UserApiHandler {
return response;
}
+
+ public User getUser(int method, String email, String phone){
+ HttpCallHandler httpCallHandler = new HttpCallHandler();
+ User returnUser = new User();
+ try{
+ String responseCall="";
+ if(method==1){
+ String url = Config.FIND_BY_EMAIL+"?email="+email;
+ responseCall = httpCallHandler.getHttp(new URL(url));
+ }else if(method==2){
+ String url = Config.FIND_BY_PHONE+"?phone="+phone;
+ responseCall = httpCallHandler.getHttp(new URL(url));
+ } else {
+ String url = Config.FIND_BY_EMAIL_AND_PHONE+"?email="+email+"&phone="+phone;
+ responseCall = httpCallHandler.getHttp(new URL(url));
+ }
+
+ if(responseCall!=""){
+ JSONObject jsonObject = new JSONObject(responseCall);
+ returnUser.setName(jsonObject.getString("name"));
+ returnUser.setFirstname(jsonObject.getString("firstname"));
+ returnUser.setUser_hash(jsonObject.getString("user_hash"));
+
+ return returnUser;
+ }else{
+ return null;
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return null;
+ }
+
}
diff --git a/app/src/main/java/monnethic/mobile/search/DisplayWallet.java b/app/src/main/java/monnethic/mobile/search/DisplayWallet.java
new file mode 100644
index 0000000..8413c8b
--- /dev/null
+++ b/app/src/main/java/monnethic/mobile/search/DisplayWallet.java
@@ -0,0 +1,40 @@
+package monnethic.mobile.search;
+
+public class DisplayWallet {
+ private String user_name;
+ private String user_firstname;
+ private String wallet_hash;
+
+ public DisplayWallet() {
+ }
+
+ public DisplayWallet(String user_name, String user_firstname, String wallet_hash) {
+ this.user_name = user_name;
+ this.user_firstname = user_firstname;
+ this.wallet_hash = wallet_hash;
+ }
+
+ public String getUser_name() {
+ return user_name;
+ }
+
+ public void setUser_name(String user_name) {
+ this.user_name = user_name;
+ }
+
+ public String getUser_firstname() {
+ return user_firstname;
+ }
+
+ public void setUser_firstname(String user_firstname) {
+ this.user_firstname = user_firstname;
+ }
+
+ public String getWallet_hash() {
+ return wallet_hash;
+ }
+
+ public void setWallet_hash(String wallet_hash) {
+ this.wallet_hash = wallet_hash;
+ }
+}
diff --git a/app/src/main/java/monnethic/mobile/search/DisplayWalletAdapter.java b/app/src/main/java/monnethic/mobile/search/DisplayWalletAdapter.java
new file mode 100644
index 0000000..141b7c5
--- /dev/null
+++ b/app/src/main/java/monnethic/mobile/search/DisplayWalletAdapter.java
@@ -0,0 +1,40 @@
+package monnethic.mobile.search;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import com.example.monnthic.monnethicmobile.R;
+
+import java.util.ArrayList;
+
+public class DisplayWalletAdapter extends ArrayAdapter {
+ public DisplayWalletAdapter(Context context, ArrayList dWallets){
+ super(context,0,dWallets);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ DisplayWallet dWallet = getItem(position);
+
+ if(convertView == null){
+ convertView = LayoutInflater.from(getContext()).inflate(R.layout.wallet_search_template, parent, false);
+ }
+
+ TextView user_name = convertView.findViewById(R.id.userNameSearch);
+ TextView wallet_hash = convertView.findViewById(R.id.walletHashSearch);
+
+ ViewGroup.LayoutParams params = convertView.getLayoutParams();
+ params.height = 300;
+ convertView.setLayoutParams(params);
+
+ String userFullName = dWallet.getUser_name()+" "+dWallet.getUser_firstname();
+ user_name.setText(userFullName);
+ wallet_hash.setText(dWallet.getWallet_hash());
+
+ return convertView;
+ }
+}
diff --git a/app/src/main/java/monnethic/mobile/search/DisplayWalletSearch.java b/app/src/main/java/monnethic/mobile/search/DisplayWalletSearch.java
new file mode 100644
index 0000000..d7f2d8d
--- /dev/null
+++ b/app/src/main/java/monnethic/mobile/search/DisplayWalletSearch.java
@@ -0,0 +1,69 @@
+package monnethic.mobile.search;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListView;
+
+import com.example.monnthic.monnethicmobile.R;
+import java.util.ArrayList;
+import monnethic.mobile.restApi.WalletApiHandler;
+import monnethic.mobile.wallet.Wallet;
+
+public class DisplayWalletSearch extends AppCompatActivity {
+ private ArrayList userWallets;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_display_wallet_search);
+
+ ListView listView = (ListView) findViewById(R.id.listViewWalletSearch);
+ Intent intent = getIntent();
+ String user_name = intent.getStringExtra("user_name");
+ String user_firstname = intent.getStringExtra("user_firstname");
+ String user_hash = intent.getStringExtra("user_hash");
+
+ try {
+ userWallets = new SearchWalletTask().execute(user_hash).get();
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+
+ ArrayList displayWallets = new ArrayList<>();
+ for(Wallet w : userWallets){
+ displayWallets.add(new DisplayWallet(user_name,user_firstname,w.getWallet_hash()));
+ }
+ DisplayWalletAdapter adapter = new DisplayWalletAdapter(this,displayWallets);
+ listView.setAdapter(adapter);
+
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
+ DisplayWallet dW = (DisplayWallet) listView.getItemAtPosition(i);
+ Intent intent1 = new Intent();
+ intent1.putExtra("walletHash",dW.getWallet_hash());
+ setResult(1,intent1);
+ finish();
+ }
+ });
+ }
+
+
+ private class SearchWalletTask extends AsyncTask> {
+ @Override
+ protected ArrayList doInBackground(String... strings) {
+ ArrayList walletsList = new ArrayList<>();
+ try{
+ WalletApiHandler walletApiHandler = new WalletApiHandler();
+ walletsList = walletApiHandler.getUserWallets(strings);
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return walletsList;
+ }
+ }
+
+}
diff --git a/app/src/main/java/monnethic/mobile/search/SearchUser.java b/app/src/main/java/monnethic/mobile/search/SearchUser.java
new file mode 100644
index 0000000..aff746a
--- /dev/null
+++ b/app/src/main/java/monnethic/mobile/search/SearchUser.java
@@ -0,0 +1,118 @@
+package monnethic.mobile.search;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.example.monnthic.monnethicmobile.R;
+import com.google.gson.JsonObject;
+import com.j256.ormlite.stmt.query.In;
+
+import org.json.JSONObject;
+
+import java.util.ArrayList;
+
+import monnethic.mobile.database.User;
+import monnethic.mobile.homepage.InputController;
+import monnethic.mobile.restApi.UserApiHandler;
+import monnethic.mobile.restApi.WalletApiHandler;
+import monnethic.mobile.wallet.Wallet;
+
+public class SearchUser extends AppCompatActivity {
+ EditText emailAddress;
+ EditText phoneNumber;
+ Button buttonCancel;
+ Button buttonOk;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_search_user);
+
+ initView();
+ }
+
+ private void initView(){
+ emailAddress = findViewById(R.id.inputEmailSearch);
+ phoneNumber = findViewById(R.id.inputPhoneSearch);
+ buttonCancel = findViewById(R.id.buttonCancelSearch);
+ buttonOk = findViewById(R.id.buttonOkSearch);
+
+ buttonCancel.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ setResult(2);
+ finish();
+ }
+ });
+
+ buttonOk.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ search();
+ }
+ });
+ }
+
+ private void search(){
+ String uEmail = emailAddress.getText().toString();
+ String uPhone = phoneNumber.getText().toString();
+
+ if(InputController.isEmptyEdit(emailAddress) && InputController.isEmptyEdit(phoneNumber)){
+ Toast.makeText(this, "Enter an email or phone number", Toast.LENGTH_SHORT).show();
+ } else if(InputController.isEmptyEdit(emailAddress)){
+ new SearchUserTask(this).execute(null,uPhone);
+ } else if(InputController.isEmptyEdit(phoneNumber)){
+ new SearchUserTask(this).execute(uEmail,null);
+ } else {
+ new SearchUserTask(this).execute(uEmail,uPhone);
+ }
+ }
+
+ private class SearchUserTask extends AsyncTask {
+ Context mContext;
+ private SearchUserTask(final Context context){mContext=context;}
+
+ @Override
+ protected void onPostExecute(User user) {
+ try{
+ Intent displayWalletIntent = new Intent(SearchUser.this, DisplayWalletSearch.class);
+ displayWalletIntent.putExtra("user_name",user.getName());
+ displayWalletIntent.putExtra("user_firstname",user.getFirstname());
+ displayWalletIntent.putExtra("user_hash",user.getUser_hash());
+ displayWalletIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+ SearchUser.this.startActivity(displayWalletIntent);
+ finish();
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected User doInBackground(String... strings) {
+ try {
+ UserApiHandler userApiHandler = new UserApiHandler();
+ User u = new User();
+ if(strings[0]!=null && strings[1]==null){
+ u = userApiHandler.getUser(1,strings[0],null);
+ } else if(strings[0]==null && strings[1]!=null){
+ u = userApiHandler.getUser(2,null,strings[1]);
+ } else {
+ u = userApiHandler.getUser(3,strings[0],strings[1]);
+ }
+ return u;
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ }
+}
diff --git a/app/src/main/java/monnethic/mobile/transaction/TransactionActivity.java b/app/src/main/java/monnethic/mobile/transaction/TransactionActivity.java
index 14440ac..88061ab 100644
--- a/app/src/main/java/monnethic/mobile/transaction/TransactionActivity.java
+++ b/app/src/main/java/monnethic/mobile/transaction/TransactionActivity.java
@@ -13,6 +13,7 @@ import com.example.monnthic.monnethicmobile.R;
import monnethic.mobile.homepage.InputController;
import monnethic.mobile.restApi.TransactionApiHandler;
+import monnethic.mobile.search.SearchUser;
public class TransactionActivity extends AppCompatActivity {
private String wallet_hash;
@@ -30,6 +31,7 @@ public class TransactionActivity extends AppCompatActivity {
amountEditText = findViewById(R.id.amount);
Button buttonCancel = findViewById(R.id.btn_cancel);
Button buttonOk = findViewById(R.id.btn_send);
+ Button buttonSearch = findViewById(R.id.buttonSearch);
Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH");
@@ -55,6 +57,14 @@ public class TransactionActivity extends AppCompatActivity {
sendTransaction();
}
});
+
+ buttonSearch.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ launchSearchActivity();
+ }
+ });
+
}
public void sendTransaction(){
@@ -86,6 +96,20 @@ public class TransactionActivity extends AppCompatActivity {
}
}
+ public void launchSearchActivity(){
+ Intent searchIntent = new Intent(TransactionActivity.this, SearchUser.class);
+ startActivityForResult(searchIntent,1);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data){
+ super.onActivityResult(requestCode, resultCode, data);
+ if(requestCode==1){
+ String walletHash = data.getStringExtra("walletHash");
+ addressDestination.setText(walletHash);
+ }
+ }
+
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
diff --git a/app/src/main/res/layout/activity_display_wallet_search.xml b/app/src/main/res/layout/activity_display_wallet_search.xml
new file mode 100644
index 0000000..57764bb
--- /dev/null
+++ b/app/src/main/res/layout/activity_display_wallet_search.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_search_user.xml b/app/src/main/res/layout/activity_search_user.xml
new file mode 100644
index 0000000..a64a49b
--- /dev/null
+++ b/app/src/main/res/layout/activity_search_user.xml
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_transaction.xml b/app/src/main/res/layout/activity_transaction.xml
index bd7fc5c..5cb59c6 100644
--- a/app/src/main/res/layout/activity_transaction.xml
+++ b/app/src/main/res/layout/activity_transaction.xml
@@ -1,66 +1,83 @@
-
-
+ android:layout_height="match_parent"
+ android:layout_alignParentStart="true"
+ android:layout_alignParentTop="true"
+ android:fillViewport="true">
-
+ android:orientation="vertical"
+ android:gravity="center">
-
+
-
+
-
-
+
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/wallet_search_template.xml b/app/src/main/res/layout/wallet_search_template.xml
new file mode 100644
index 0000000..3169646
--- /dev/null
+++ b/app/src/main/res/layout/wallet_search_template.xml
@@ -0,0 +1,69 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file