Skip to content

Commit

Permalink
Bottom Navigation Changes, added Edit, Delete and Generate PDF Options
Browse files Browse the repository at this point in the history
  • Loading branch information
tauseefansari committed Jul 28, 2020
1 parent dea2a73 commit aa83164
Show file tree
Hide file tree
Showing 16 changed files with 585 additions and 108 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ android {
versionCode 1
versionName "1.0"

vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand All @@ -26,8 +27,10 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.3.0-alpha01'
testImplementation 'junit:junit:4.12'
implementation 'com.google.android.material:material:1.3.0-alpha02'
implementation 'com.etebarian:meow-bottom-navigation-java:1.2.0'
implementation 'com.itextpdf:itextg:5.5.10'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tauseef.mybills">

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
99 changes: 81 additions & 18 deletions app/src/main/java/com/tauseef/mybills/AddLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,32 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;

import com.etebarian.meowbottomnavigation.MeowBottomNavigation;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.textfield.TextInputLayout;

import java.util.Calendar;

public class AddLayout extends AppCompatActivity {

private final static int ID_ADD = 1;
private final static int ID_HOME = 2;
private final static int ID_VIEW = 3;

private TextInputLayout mDate, mStyle, mPrice, mStyleNo, mDescription;
private Button submit,cancel;
private Button submit,cancel, update;
private DatabaseHelper mHelper;
private BottomNavigationView mNavigationView;
private TextView mTitle;

private static final String MY_PREFS = "bill";
private static final String MY_DATE = "date";
SharedPreferences mPreferences;
Expand All @@ -34,32 +42,50 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_layout);

mPreferences = getSharedPreferences(MY_PREFS, Context.MODE_PRIVATE);
MeowBottomNavigation bottomNavigation = findViewById(R.id.bottom);
bottomNavigation.add(new MeowBottomNavigation.Model(ID_ADD, R.drawable.ic_add));
bottomNavigation.add(new MeowBottomNavigation.Model(ID_HOME, R.drawable.ic_home));
bottomNavigation.add(new MeowBottomNavigation.Model(ID_VIEW, R.drawable.ic_view));

bottomNavigation.setOnShowListener(new MeowBottomNavigation.ShowListener() {
@Override
public void onShowItem(MeowBottomNavigation.Model item) {

mNavigationView = findViewById(R.id.bottom_navigation);
mNavigationView.setSelectedItemId(R.id.add);
}
});

mNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
bottomNavigation.setOnClickMenuListener(new MeowBottomNavigation.ClickListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId())
public void onClickItem(MeowBottomNavigation.Model item) {
switch (item.getId())
{
case R.id.view:
startActivity(new Intent(AddLayout.this, DisplayLayout.class));
overridePendingTransition(0, 0);
return true;
case R.id.home:
case ID_ADD:
Toast.makeText(AddLayout.this, "Add Already Selected", Toast.LENGTH_SHORT).show();
//return;
//Intent intent = getIntent();
//finish();
//startActivity(intent);
case ID_HOME:
//Toast.makeText(AddLayout.this, "Home Selected", Toast.LENGTH_SHORT).show();
startActivity(new Intent(AddLayout.this, MainActivity.class));
overridePendingTransition(0, 0);
return true;
case R.id.add:
return true;
overridePendingTransition(0,0);
break;
case ID_VIEW:
//Toast.makeText(AddLayout.this, "View Selected", Toast.LENGTH_SHORT).show();
startActivity(new Intent(AddLayout.this, DisplayLayout.class));
overridePendingTransition(0,0);
break;
}
return false;
}
});

bottomNavigation.show(ID_ADD, true);

mPreferences = getSharedPreferences(MY_PREFS, Context.MODE_PRIVATE);


mHelper = new DatabaseHelper(this);
mTitle = findViewById(R.id.title);

mDate = findViewById(R.id.date);
mPrice = findViewById(R.id.price);
Expand All @@ -68,6 +94,42 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
mDescription = findViewById(R.id.description);
submit = findViewById(R.id.submit);
cancel = findViewById(R.id.cancel);
update = findViewById(R.id.update);

Bundle bundle = getIntent().getExtras();
if (bundle != null)
{
mTitle.setText("Edit Item");
final String id = bundle.getString("id");
Cursor row = mHelper.getOneRow(id);
mDate.getEditText().setText(row.getString(1));
mStyle.getEditText().setText(row.getString(2));
mStyleNo.getEditText().setText(row.getString(3));
mDescription.getEditText().setText(row.getString(4));
mPrice.getEditText().setText(""+row.getString(5));
submit.setVisibility(View.GONE);
update.setVisibility(View.VISIBLE);
update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean res = mHelper.updateRow(id, mDate.getEditText().getText().toString(), mStyle.getEditText().getText().toString(), mStyleNo.getEditText().getText().toString(), mDescription.getEditText().getText().toString(), Long.valueOf(mPrice.getEditText().getText().toString()));
if (res)
{
mDate.getEditText().setText("");
mStyle.getEditText().setText("");
mStyleNo.getEditText().setText("");
mPrice.getEditText().setText("");
mDescription.getEditText().setText("");
Toast.makeText(AddLayout.this, "Item updated", Toast.LENGTH_SHORT).show();
startActivity(new Intent(AddLayout.this, DisplayLayout.class));
}
else
{
Toast.makeText(AddLayout.this, "Item not updated", Toast.LENGTH_SHORT).show();
}
}
});
}

Calendar now = Calendar.getInstance();
final int day = now.get(Calendar.DAY_OF_MONTH);
Expand Down Expand Up @@ -121,6 +183,7 @@ public void onClick(View view) {
mPrice.getEditText().setText("");
mDescription.getEditText().setText("");
Toast.makeText(AddLayout.this, "Data Inserted", Toast.LENGTH_SHORT).show();
startActivity(new Intent(AddLayout.this, DisplayLayout.class));
}
else
Toast.makeText(AddLayout.this, "Data Not Inserted", Toast.LENGTH_SHORT).show();
Expand Down
29 changes: 28 additions & 1 deletion app/src/main/java/com/tauseef/mybills/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,37 @@ public boolean insertData(String date, String style, String styleno, String desc
return true;
}

public Cursor getAllItenms()
public Cursor getAllItems()
{
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM "+ TABLE_NAME, null);
return cursor;
}

public Cursor getOneRow(String id) {
SQLiteDatabase db = this.getReadableDatabase();
//Cursor cur = db.rawQuery("SELECT * FROM "+ TABLE_NAME, )
Cursor cursor = db.rawQuery("SELECT * FROM "+ TABLE_NAME+" WHERE ID = "+id, null);
cursor.moveToFirst();
return cursor;
}

public boolean updateRow(String id, String date, String style, String styleno, String description, long price)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, date);
contentValues.put(COL_3, style);
contentValues.put(COL_4, styleno);
contentValues.put(COL_5, description);
contentValues.put(COL_6, price);
db.update(TABLE_NAME,contentValues,"ID = ?", new String[] {id});
return true;
}

public int deleteData(String id)
{
SQLiteDatabase db = this.getWritableDatabase();
return db.delete(TABLE_NAME, "ID = ?", new String[] {id});
}
}
Loading

0 comments on commit aa83164

Please sign in to comment.