Skip to content

Commit

Permalink
Updates in Coin DB integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ARUNJOSE144 committed Jun 27, 2021
1 parent 2b9208b commit 0e96e47
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 38 deletions.
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package="com.example.myapplication">

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.VIBRATE" />

<application
Expand All @@ -14,12 +13,12 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".CreateCoin"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>
</activity>
</application>
Expand Down
110 changes: 110 additions & 0 deletions app/src/main/java/com/example/myapplication/CreateCoin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class CreateCoin extends AppCompatActivity {

Button cancel, add, update, delete;
EditText id, name, max, min;
DBHelper DB;

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

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

cancel = (Button) findViewById(R.id.cancelButton);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
opentoMainPage();
}
});

update = (Button) findViewById(R.id.updateButton);
update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Update();
}
});

delete = (Button) findViewById(R.id.deleteButton);
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Delete();
}
});
}

public void opentoMainPage() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}

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());

min = (EditText) findViewById(R.id.coinMinValue);
to.setMinPrice(min.getText().toString());

max = (EditText) findViewById(R.id.coinMaxValue);
to.setMaxPrice(max.getText().toString());

return to;
}

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

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

public void Delete() {
DB = new DBHelper(this);
boolean stat = DB.deleteCoinData(getRequest());
if (stat) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "Delete Failed", Toast.LENGTH_LONG).show();
}
}
}
17 changes: 15 additions & 2 deletions app/src/main/java/com/example/myapplication/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import androidx.annotation.Nullable;

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

public class DBHelper extends SQLiteOpenHelper {
public DBHelper(Context context) {
super(context, "Coin.db", null, 1);
Expand Down Expand Up @@ -74,10 +77,20 @@ public boolean deleteCoinData(CoinTO coinTO) {
}


public Cursor getCoinData(CoinTO coinTO) {
public List<CoinTO> getCoinData() {
List<CoinTO> list = new ArrayList<>();
SQLiteDatabase DB = this.getWritableDatabase();
Cursor cursor = DB.rawQuery("Select * from CoinDetails", null);
return cursor;
while (cursor.moveToNext()) {
CoinTO coin = new CoinTO();
coin.setId(Integer.parseInt(cursor.getString(0)));
coin.setName(cursor.getString(1));
coin.setMinPrice(cursor.getString(2));
coin.setMaxPrice(cursor.getString(3));
list.add(coin);
}

return list;
}

}
36 changes: 23 additions & 13 deletions app/src/main/java/com/example/myapplication/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.example.myapplication;

import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
Expand Down Expand Up @@ -40,10 +42,12 @@ public class MainActivity extends AppCompatActivity {
ExpandableListAdapter expandableListAdapter;
List<CoinTO> coinDetails;
Double DollerInINR = 74.14;
int refreshInSeconds = 300;
int refreshInSeconds = 100;
DBHelper DB;

List<CoinTO> monitoringCoins;

Button goToCreateCoinButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -56,7 +60,6 @@ protected void onCreate(Bundle savedInstanceState) {
final Runnable r = new Runnable() {
public void run() {
getDataFromApi();
last_refresed = 0;
handler.postDelayed(this, refreshInSeconds * 1000);
}
};
Expand All @@ -71,8 +74,23 @@ public void run() {
}
};

goToCreateCoinButton = (Button) findViewById(R.id.goToCreateCoin);
goToCreateCoinButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openCreateCoinPage();
}
});

handler.postDelayed(lastUpdatedTime, 1000);
handler.postDelayed(r, 1);


}

public void openCreateCoinPage() {
Intent intent = new Intent(this, CreateCoin.class);
startActivity(intent);
}

void getDataFromApi() {
Expand All @@ -86,6 +104,7 @@ void getDataFromApi() {
@Override
public void onResponse(JSONObject response) {
try {
last_refresed = 0;
Toast.makeText(getApplicationContext(), "Api Sucess", Toast.LENGTH_LONG).show();
System.out.println("Succwssssssssssssssssssssssssss : " + response.toString());
JSONObject reader = new JSONObject(response.toString());
Expand Down Expand Up @@ -224,18 +243,9 @@ List<CoinTO> sortList(List<CoinTO> list) {

void setMonitoringCoinDetails() {
monitoringCoins = new ArrayList<>();
DB = new DBHelper(this);
monitoringCoins = DB.getCoinData();

CoinTO coinTO1 = new CoinTO();
coinTO1.setId(74);
coinTO1.setMinPrice("15");
coinTO1.setMaxPrice("20");
monitoringCoins.add(coinTO1);

CoinTO coinTO2 = new CoinTO();
coinTO2.setId(1);
coinTO2.setMinPrice("20000");
coinTO2.setMaxPrice("3000000");
monitoringCoins.add(coinTO2);
}
}

Expand Down
Loading

0 comments on commit 0e96e47

Please sign in to comment.