Skip to content

Commit

Permalink
Updates in Validation And making more userfriendly
Browse files Browse the repository at this point in the history
ARUNJOSE144 committed Jul 3, 2021
1 parent 0ef0119 commit 77c65dd
Showing 4 changed files with 149 additions and 84 deletions.
12 changes: 8 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -13,12 +13,16 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".PropertyActivity"></activity>
<activity android:name=".CreateCoin" />
<activity
android:name=".PropertyActivity"
android:screenOrientation="portrait" />
<activity
android:name=".CreateCoin"
android:screenOrientation="portrait" />
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="Cripto App">
android:label="Cripto App"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

131 changes: 110 additions & 21 deletions app/src/main/java/com/example/myapplication/CreateCoin.java
Original file line number Diff line number Diff line change
@@ -5,29 +5,72 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class CreateCoin extends AppCompatActivity {

Button cancel, add, update, delete;
EditText id, name, max, min;
DBHelper DB;
List<String> dropDownList = new ArrayList<>();
CoinTO selectedCoin;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_coin);

setDropDownList();
Spinner spinner = (Spinner) findViewById(R.id.coinSelect);
final ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item, dropDownList);
spinner.setAdapter(spinnerArrayAdapter);

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
selectedCoin = MainActivity.coinDetails.get(i);
TextView infoView = (TextView) findViewById(R.id.infoView);
infoView.setText(selectedCoin.toString());

add.setVisibility(View.GONE);
update.setVisibility(View.GONE);
delete.setVisibility(View.GONE);

if (selectedCoin.isMonitoringCoin()) {
update.setVisibility(View.VISIBLE);
delete.setVisibility(View.VISIBLE);
} else {
add.setVisibility(View.VISIBLE);
}
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});


add = (Button) findViewById(R.id.addButton);
add.setVisibility(View.INVISIBLE);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Create();
}
});


cancel = (Button) findViewById(R.id.cancelButton);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
@@ -36,6 +79,7 @@ public void onClick(View view) {
}
});


update = (Button) findViewById(R.id.updateButton);
update.setOnClickListener(new View.OnClickListener() {
@Override
@@ -58,13 +102,19 @@ public void opentoMainPage() {
startActivity(intent);
}

public void setDropDownList() {
dropDownList = new ArrayList<>();
for (CoinTO coin : MainActivity.coinDetails) {
dropDownList.add(coin.getName());
}

}

public CoinTO getRequest() {
CoinTO to = new CoinTO();
id = (EditText) findViewById(R.id.coinId);
to.setId(Integer.parseInt(id.getText().toString()));

name = (EditText) findViewById(R.id.coinName);
to.setName(name.getText().toString());
to.setId(selectedCoin.getId());
to.setName(selectedCoin.getName());

min = (EditText) findViewById(R.id.coinMinValue);
to.setMinPrice(min.getText().toString());
@@ -78,37 +128,76 @@ public CoinTO getRequest() {
public void Create() {
DB = new DBHelper(this);

boolean stat = DB.inserCoinData(getRequest());
if (stat) {
/*Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);*/
Toast.makeText(getApplicationContext(), "Created", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Create Failed", Toast.LENGTH_LONG).show();
min = (EditText) findViewById(R.id.coinMinValue);
max = (EditText) findViewById(R.id.coinMaxValue);

try {
if (validate(min.getText().toString()) || validate(max.getText().toString())) {
if (validate(min.getText().toString())) {
Double minVal = Double.parseDouble(min.getText().toString());
}
if (validate(max.getText().toString())) {
Double maxVal = Double.parseDouble(max.getText().toString());
}
boolean stat = DB.inserCoinData(getRequest());
if (stat) {
Toast.makeText(getApplicationContext(), "Created", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Create Failed", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "Enter Atleast Min or Max", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Please check Min And Max Values", Toast.LENGTH_LONG).show();
e.printStackTrace();
}


}

public void Update() {
DB = new DBHelper(this);
boolean stat = DB.updateCoinData(getRequest());
if (stat) {
/* Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);*/
Toast.makeText(getApplicationContext(), "Updated", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Update Failed", Toast.LENGTH_LONG).show();
min = (EditText) findViewById(R.id.coinMinValue);
max = (EditText) findViewById(R.id.coinMaxValue);

try {
if (validate(min.getText().toString()) || validate(max.getText().toString())) {
if (validate(min.getText().toString())) {
Double minVal = Double.parseDouble(min.getText().toString());
}
if (validate(max.getText().toString())) {
Double maxVal = Double.parseDouble(max.getText().toString());
}
DB = new DBHelper(this);
boolean stat = DB.updateCoinData(getRequest());
if (stat) {
Toast.makeText(getApplicationContext(), "Updated", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Update Failed", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "Enter Atleast Min or Max", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Please check Min And Max Values", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}

public void Delete() {
DB = new DBHelper(this);
boolean stat = DB.deleteCoinData(getRequest());
if (stat) {
/* Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);*/
Toast.makeText(getApplicationContext(), "Deleted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Delete Failed", Toast.LENGTH_LONG).show();
}
}

boolean validate(String val) {
if (val != null && !val.equalsIgnoreCase("")) {
return true;
} else
return false;
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/example/myapplication/MainActivity.java
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public class MainActivity extends AppCompatActivity {

ExpandableListView expandableListView;
ExpandableListAdapter expandableListAdapter;
List<CoinTO> coinDetails;
static List<CoinTO> coinDetails;
Double DollerInINR = 74.14;
int refreshInSeconds = 100;
DBHelper DB;
@@ -199,7 +199,7 @@ void setResponseAfterApiCall(String response) {
expandableListView = findViewById(R.id.expanded_menu);
expandableListAdapter = new MyExpandableListAdapter(this, coinDetails);
expandableListView.setAdapter(expandableListAdapter);
/*expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
int lastExpandedPosition = -1;

@Override
@@ -209,7 +209,7 @@ public void onGroupExpand(int i) {
}
lastExpandedPosition = i;
}
});*/
});

expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
84 changes: 28 additions & 56 deletions app/src/main/res/layout/activity_create_coin.xml
Original file line number Diff line number Diff line change
@@ -7,59 +7,23 @@
tools:context=".CreateCoin">


<TextView
android:id="@+id/textView"
android:layout_width="134dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="24dp"
android:layout_marginTop="70dp"
android:layout_marginEnd="21dp"
android:layout_marginBottom="642dp"
android:layout_toStartOf="@+id/coinId"
android:text="Id"
android:textAlignment="center" />

<EditText
android:id="@+id/coinId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="50dp"
android:layout_marginEnd="14dp"
android:ems="10"
android:hint="Id"
android:inputType="textPersonName" />


<TextView
android:id="@+id/textView3"
android:layout_width="145dp"
android:layout_height="16dp"
android:layout_above="@+id/textView2"
android:layout_alignParentStart="true"
android:layout_marginStart="21dp"
android:layout_marginEnd="17dp"
android:layout_marginBottom="81dp"
android:layout_width="141dp"
android:layout_height="wrap_content"
android:layout_above="@+id/textView4"
android:layout_marginEnd="15dp"
android:layout_marginBottom="140dp"
android:layout_toStartOf="@+id/coinName"
android:text="Name"
android:text="Coin Name"
android:textAlignment="center" />

<EditText
android:id="@+id/coinName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/coinId"
<Spinner
android:id="@+id/coinSelect"
android:layout_width="272dp"
android:layout_height="37dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="61dp"
android:layout_marginEnd="15dp"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:text="" />
android:layout_marginEnd="15dp" />

<TextView
android:id="@+id/textView2"
@@ -143,22 +107,30 @@
android:id="@+id/updateButton"
android:layout_width="134dp"
android:layout_height="58dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="61dp"
android:layout_marginBottom="111dp"
android:layout_below="@+id/cancelButton"
android:layout_marginTop="158dp"
android:text="Update" />

<Button
android:id="@+id/deleteButton"
android:layout_width="wrap_content"
android:layout_height="59dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/addButton"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="234dp"
android:layout_marginEnd="38dp"
android:layout_marginBottom="114dp"
android:layout_marginStart="47dp"
android:layout_marginTop="52dp"
android:layout_marginEnd="31dp"
android:layout_toEndOf="@+id/updateButton"
android:text="Delete" />

<TextView
android:id="@+id/infoView"
android:layout_width="248dp"
android:layout_height="175dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="106dp"
android:layout_marginBottom="90dp"
android:text="TextView" />

</RelativeLayout>

0 comments on commit 77c65dd

Please sign in to comment.