Setup search user for transaction

This commit is contained in:
GME 2019-04-16 21:30:27 +02:00
parent bbdea83fe9
commit 62d6818dea
13 changed files with 575 additions and 56 deletions

View file

@ -40,7 +40,9 @@
<activity android:name="monnethic.mobile.transaction.ApprovePayementActivity" /> <activity android:name="monnethic.mobile.transaction.ApprovePayementActivity" />
<activity android:name="monnethic.mobile.wallet.HomeWalletActivity" /> <activity android:name="monnethic.mobile.wallet.HomeWalletActivity" />
<activity android:name="monnethic.mobile.wallet.CreateWalletActivity" /> <activity android:name="monnethic.mobile.wallet.CreateWalletActivity" />
<activity android:name="monnethic.mobile.wallet.SelectWalletActivity"></activity> <activity android:name="monnethic.mobile.wallet.SelectWalletActivity" />
<activity android:name="monnethic.mobile.search.SearchUser" />
<activity android:name="monnethic.mobile.search.DisplayWalletSearch"></activity>
</application> </application>
</manifest> </manifest>

View file

@ -2,8 +2,8 @@ package monnethic.mobile.restApi;
public class Config { public class Config {
//BASE //BASE
static private String BASE_URL = "http://37.187.101.44: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://10.0.2.2:10053/";
//static private String BASE_URL = "http://localhost: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_USER = BASE_URL+"api/rest/user/";
static private String BASE_URL_TRANSACTION = BASE_URL+"api/rest/transaction/"; 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_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";
//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 //TRANSACTION
static public String TRANSACTION_SEND = BASE_URL_TRANSACTION+"send"; static public String TRANSACTION_SEND = BASE_URL_TRANSACTION+"send";

View file

@ -85,4 +85,37 @@ public class UserApiHandler {
return response; 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;
}
} }

View file

@ -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;
}
}

View file

@ -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<DisplayWallet> {
public DisplayWalletAdapter(Context context, ArrayList<DisplayWallet> 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;
}
}

View file

@ -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<Wallet> 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<DisplayWallet> 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<String,String,ArrayList<Wallet>> {
@Override
protected ArrayList<Wallet> doInBackground(String... strings) {
ArrayList<Wallet> walletsList = new ArrayList<>();
try{
WalletApiHandler walletApiHandler = new WalletApiHandler();
walletsList = walletApiHandler.getUserWallets(strings);
}catch (Exception e){
e.printStackTrace();
}
return walletsList;
}
}
}

View file

@ -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<String,Void,User> {
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;
}
}
}

View file

@ -13,6 +13,7 @@ import com.example.monnthic.monnethicmobile.R;
import monnethic.mobile.homepage.InputController; import monnethic.mobile.homepage.InputController;
import monnethic.mobile.restApi.TransactionApiHandler; import monnethic.mobile.restApi.TransactionApiHandler;
import monnethic.mobile.search.SearchUser;
public class TransactionActivity extends AppCompatActivity { public class TransactionActivity extends AppCompatActivity {
private String wallet_hash; private String wallet_hash;
@ -30,6 +31,7 @@ public class TransactionActivity extends AppCompatActivity {
amountEditText = findViewById(R.id.amount); amountEditText = findViewById(R.id.amount);
Button buttonCancel = findViewById(R.id.btn_cancel); Button buttonCancel = findViewById(R.id.btn_cancel);
Button buttonOk = findViewById(R.id.btn_send); Button buttonOk = findViewById(R.id.btn_send);
Button buttonSearch = findViewById(R.id.buttonSearch);
Intent intent = getIntent(); Intent intent = getIntent();
user_hash = intent.getStringExtra("USER_HASH"); user_hash = intent.getStringExtra("USER_HASH");
@ -55,6 +57,14 @@ public class TransactionActivity extends AppCompatActivity {
sendTransaction(); sendTransaction();
} }
}); });
buttonSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
launchSearchActivity();
}
});
} }
public void sendTransaction(){ 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 @Override
protected void onStop() { protected void onStop() {
super.onStop(); // Always call the superclass method first super.onStop(); // Always call the superclass method first

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="monnethic.mobile.search.DisplayWalletSearch">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:fillViewport="true">
<ListView
android:id="@+id/listViewWalletSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="5dp" />
</ScrollView>
</android.support.constraint.ConstraintLayout>

View file

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SEARCH"
android:textAlignment="center"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/inputEmailSearch"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/textView9"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
android:singleLine="false" />
<EditText
android:id="@+id/inputPhoneSearch"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_below="@+id/inputEmailSearch"
android:layout_alignStart="@+id/inputEmailSearch"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="Phone"
android:inputType="phone" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginBottom="40dp">
<Button
android:id="@+id/buttonOkSearch"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="0dp"
android:layout_marginEnd="65dp"
android:text="OK" />
<Button
android:id="@+id/buttonCancelSearch"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginStart="65dp"
android:layout_marginTop="0dp"
android:text="Cancel" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>

View file

@ -1,66 +1,83 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<RelativeLayout <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:fillViewport="true">
<Button <LinearLayout
android:id="@+id/btn_send" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignEnd="@+id/amount" android:orientation="vertical"
android:layout_below="@+id/amount" android:gravity="center">
android:layout_marginTop="77dp"
android:text="SEND"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/btn_cancel"
app:layout_constraintHorizontal_bias="0.543"
app:layout_constraintStart_toStartOf="parent" />
<Button <EditText
android:id="@+id/btn_cancel" android:id="@+id/destination_address"
android:layout_width="wrap_content" android:layout_width="350dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_send" android:layout_above="@+id/buttonSearch"
android:layout_alignBottom="@+id/btn_send" android:layout_centerHorizontal="true"
android:layout_alignStart="@+id/amount" android:ems="10"
android:text="CANCEL" android:hint="Destination address"
app:layout_constraintBottom_toBottomOf="parent" android:singleLine="false"
app:layout_constraintEnd_toEndOf="parent" /> android:inputType="text" />
<EditText <Button
android:id="@+id/amount" android:id="@+id/buttonSearch"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_marginTop="10dp"
android:layout_centerVertical="true" android:layout_above="@+id/amount"
android:ems="10" android:layout_centerHorizontal="true"
android:hint="Amount" android:text="Search" />
android:inputType="numberDecimal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/destination_address" />
<EditText <EditText
android:id="@+id/destination_address" android:id="@+id/amount"
android:layout_width="250dp" android:layout_width="250dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_above="@+id/amount" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_marginBottom="67dp" android:layout_marginTop="20dp"
android:ems="10" android:ems="10"
android:hint="Destination address" android:hint="Amount"
android:inputType="text" android:inputType="numberDecimal" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="40dp">
<Button
android:id="@+id/btn_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="67dp"
android:text="SEND" />
<Button
android:id="@+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="67dp"
android:text="CANCEL" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>

View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/userNameSearch"
android:layout_marginEnd="-85dp"
android:layout_toStartOf="@+id/walletHashSearch"
android:text="User :"
android:textSize="12sp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/textView"
android:layout_alignTop="@+id/walletHashSearch"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:text="Wallet :"
android:textSize="12sp" />
<TextView
android:id="@+id/userNameSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/walletHashSearch"
android:layout_marginStart="0dp"
android:layout_marginTop="9dp"
android:text="u_n"
android:textSize="12sp" />
<TextView
android:id="@+id/walletHashSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="100dp"
android:layout_marginTop="39dp"
android:singleLine="false"
android:text="w_h"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>