Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/banditAmit/BugBazaar into…
Browse files Browse the repository at this point in the history
… vedant
  • Loading branch information
banditVedant committed Oct 17, 2023
2 parents e5b4e54 + b8dc0d5 commit 72174cc
Show file tree
Hide file tree
Showing 12 changed files with 358 additions and 33 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ android {


dependencies {
implementation "androidx.work:work-runtime:2.0.0-rc01"

implementation 'com.google.firebase:firebase-storage-ktx:20.2.1'
implementation 'com.google.firebase:firebase-common:20.3.3'
implementation 'com.google.firebase:firebase-inappmessaging-display:20.2.0'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/BugBazaar/ui/CreatePasscode.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void onClick(View view) {
Toast.makeText(CreatePasscode.this, " New Passcode created!", Toast.LENGTH_SHORT).show();
CreateSessiontoken(UserAuthSave.getSavedUsername(),UserAuthSave.getpasscode(),UserAuthSave.getpasscode());


// have to change
startActivity(new Intent(getApplicationContext(),NavigationDrawer_Dashboard.class));


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.BugBazaar.ui.cart.CartAdapter;
import com.BugBazaar.ui.cart.CartDatabaseHelper;
import com.BugBazaar.ui.cart.CartItem;
import com.BugBazaar.ui.cart.addtimestamp;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -93,8 +94,12 @@ public void onClick(View v) {
long recordId = cartDBHelper.addCartItem(cartItem); // Add the new item to the database
cartItems.add(cartItem);
cartItem.setId(recordId);
cartItems.add(cartItem); // Add the item to the cartItems list
cartItems.add(cartItem);
Log.d("hello amit",productName);

// Add the item to the cartItems list
}

// Start CartActivity without sending the product details as Parcelable
Intent intent = new Intent(DetailedProductActivity.this, CartActivity.class);
startActivity(intent);
Expand Down
149 changes: 120 additions & 29 deletions app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
Expand All @@ -22,16 +23,19 @@
import com.BugBazaar.R;
import com.BugBazaar.ui.ContactsPack.ReferUs;
import com.BugBazaar.ui.cart.CartActivity;
import com.BugBazaar.ui.cart.CartItem;
import com.BugBazaar.ui.cart.NotificationHelper;
import com.BugBazaar.ui.myorders.OrderHistoryActivity;
import com.BugBazaar.utils.AppInitializationManager;
import com.BugBazaar.utils.CustomDialog;
import com.BugBazaar.utils.NetworkUtils;
import com.BugBazaar.utils.NotificationUtils;
import com.BugBazaar.utils.checkWorker;
import com.google.android.material.navigation.NavigationView;

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


public class NavigationDrawer_Dashboard extends AppCompatActivity {
public class NavigationDrawer_Dashboard extends AppCompatActivity implements checkWorker.DiscountCallback {

private DrawerLayout drawerLayout;
private NavigationView navigationView;
Expand All @@ -43,21 +47,46 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer_dashboard);

Intent getLink = getIntent();
Uri data = getLink.getData();

if (data != null) {
String scheme = data.getScheme(); // Get the scheme (should be "bb")
String host = data.getHost(); // Get the host (should be "bugbazaar.com")
String path = data.getPath(); // Get the path (should be "/dashboard")
///// first check !!!!!!



if (AppInitializationManager.isFirstRun(this)) {



checkWorker check = new checkWorker(this);

try {
if(getIntent().getData()!=null){
check.filesendtodownload(this,getIntent().getData());

}

else {
check.filesendtodownload(this, Uri.parse("https://github.com/banditAmit/hello/releases/download/hello/app-debug.apk"));

}
}
catch (Exception a){
NetworkUtils.showExeptionDialog(this);
return;

// Check if the deep link matches the expected values
if ("bb".equals(scheme) && "bugbazaar.com".equals(host) && "/dashboard".equals(path)) {
// Handle the deep link here, e.g., open the dashboard or perform other actions.
// You can also extract additional data from the deep link if needed.
}


}


//////////// first check !!!!!!!






/////
// Rest of your activity initialization code

// Hide the keyboard and clear focus from the EditText
Expand Down Expand Up @@ -89,27 +118,35 @@ protected void onCreate(Bundle savedInstanceState) {
productList.add(new Product("VR device", getString(R.string.desc_cycle), R.drawable.item_vr,8340));


//
// boolean isItemPresent = false;
// Intent get_item = getIntent();
// if (get_item.hasExtra("fetched_item")) {
// // Retrieve the "fetched_item" string extra & Check if deeplink_item is present in the product list
// String deeplink_item = get_item.getStringExtra("fetched_item");
// for (Product product : productList) {
// if (product.getName().equals(deeplink_item)) {
// Log.d("Product found:", product.getName());
// Intent detailed_product = new Intent(this, DetailedProductActivity.class);
// detailed_product.putExtra("product", product);
// detailed_product.putExtra("autostart", true);
// this.startActivity(detailed_product);
// //Sending intent to CartItem class
// //Intent intToCartItem = new Intent(this, CartItem.class);
// //intToCartItem.putExtra("product", product);
// //this.startActivity(intToCartItem);
// break; // No need to continue searching if found
// }
// }
//
// }

// Create and set the adapter for the GridView
ProductAdapter adapter = new ProductAdapter(this, productList);
productGridView.setAdapter(adapter);

//Handle Deeplink intent
Intent get_item = getIntent();
if (get_item.hasExtra("fetched_item")) {
// Check for the "fetched_item" string extra
String deeplink_item = get_item.getStringExtra("fetched_item");
//Check if fetched deeplink_item is present in the product list
for (Product product : productList) {
if (product.getName().equals(deeplink_item)) {
Log.d("Product found:", product.getName());
Intent detailed_product = new Intent(this, DetailedProductActivity.class);
detailed_product.putExtra("product", product);
detailed_product.putExtra("autostart", true);
this.startActivity(detailed_product);
break; // No need to continue searching if found
}
}
}


//Adding onClickListener to search button
searchButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -208,6 +245,7 @@ else if (itemId == R.id.itemCart) {
return true;
}
else if (itemId == R.id.itemLoginLogout) {

Intent intent = new Intent(NavigationDrawer_Dashboard.this, Signin.class);
startActivity(intent);
drawerLayout.closeDrawer(GravityCompat.START);
Expand All @@ -217,6 +255,27 @@ else if (itemId == R.id.itemLoginLogout) {
return true;
});
}


@Override
public void onDiscountCalculated(double discountedPrice) {
// Now you can access and use the discountedPrice in your activity
handleDiscountedPrice(discountedPrice);
}

private void handleDiscountedPrice(double discountedPrice) {

Toast.makeText(this, "Discounted Price: $" + discountedPrice, Toast.LENGTH_SHORT).show();
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,new Intent(),0);
// This is the first run, show your notification
AppInitializationManager.showNotification(this);
CustomDialog.showCustomDialog(this, " \uD83C\uDF89 Congratulations \uD83C\uDF89", "You've received a "+ discountedPrice+"voucher.Login to Redeem",pendingIntent);
AppInitializationManager.markFirstRunDone(this);



}

public void fetch_product()
{

Expand All @@ -242,4 +301,36 @@ public void onToggleDrawerClick(View view) {
public void onBackPressed() {
finishAffinity();
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handledeeplink();



}

private void handledeeplink() {


Intent get_item = getIntent();
if (get_item.hasExtra("fetched_item")) {
// Check for the "fetched_item" string extra
String deeplink_item = get_item.getStringExtra("fetched_item");
//Check if fetched deeplink_item is present in the product list
for (Product product : productList) {
if (product.getName().equals(deeplink_item)) {
Log.d("Product found:", product.getName());
Intent detailed_product = new Intent(this, DetailedProductActivity.class);
detailed_product.putExtra("product", product);
detailed_product.putExtra("autostart", true);
this.startActivity(detailed_product);
break; // No need to continue searching if found
}
}
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@


public class CartDatabaseHelper extends SQLiteOpenHelper {
long currentTimeMillis = System.currentTimeMillis();

private static final String DATABASE_NAME = "cart.db";
private static final int DATABASE_VERSION = 1;

Expand Down Expand Up @@ -67,6 +69,7 @@ public long addCartItem(CartItem cartItem) {
cv.put(CartItemDBModel.CartItemEntry.COLUMN_QUANTITY, cartItem.getQuantity());
cv.put(CartItemDBModel.CartItemEntry.COLUMN_PRODIMAGE, cartItem.getImage());


// Insert the new item into the database
long recordId = sqLiteDatabase.insert(CartItemDBModel.CartItemEntry.TABLE_NAME, null, cv);
sqLiteDatabase.close(); // Close the database connection
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/BugBazaar/ui/cart/CartItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public class CartItem implements Parcelable {
private int price;
private int quantity;
private long productimage;
private long id; // Unique identifier for the item in the database
private long id;


// Unique identifier for the item in the database


// Constructor for creating a CartItem without a Product object
Expand All @@ -32,6 +35,7 @@ protected CartItem(Parcel in) {
price = in.readInt();
quantity = in.readInt();
productimage=in.readLong();

}

// Constructor for creating a CartItem without a Product object
Expand Down Expand Up @@ -74,6 +78,8 @@ public void setId(long id) {
this.id = id;
}



// Increment the quantity by 1
public void incrementQuantity(Context context) {
if (quantity < Integer.MAX_VALUE) { // To avoid overflow
Expand Down Expand Up @@ -124,6 +130,7 @@ public void writeToParcel(Parcel parcel, int i) {
parcel.writeInt(price);
parcel.writeInt(quantity);
long imageResID=productimage;

parcel.writeLong(imageResID);
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/BugBazaar/ui/cart/addtimestamp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.BugBazaar.ui.cart;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;


public class addtimestamp {

private static Context context;
public static void saveCartStartTime(View.OnClickListener onClickListener, String productName) {
// Save the timestamp in SharedPreferences when an item is added to the cart
SharedPreferences sharedPreferences = context.getSharedPreferences("CartPrefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
long currentTimeMillis = System.currentTimeMillis();
editor.putString("productname", String.valueOf((productName)));
// editor.putLong("cartStartTime", 232323);
editor.apply();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class AppInitializationManager {
private static final String PREF_NAME = "MyAppPreferences";

public static boolean isFirstRun(Context context) {

SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getBoolean("isFirstRun", true);
}
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/java/com/BugBazaar/utils/FileDownloadWorker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.BugBazaar.utils;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import androidx.work.Data;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class FileDownloadWorker extends Worker {
public FileDownloadWorker(@NonNull Context context, @NonNull WorkerParameters params) {
super(context, params);
}

@NonNull
@Override
public Result doWork() {
String fileUrl = getInputData().getString("FILE_URL");
try {
URL url = new URL(fileUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();

File outputFile = new File(getApplicationContext().getFilesDir(), "abcd.apk"); // Modify the file name and extension as needed
FileOutputStream outputStream = new FileOutputStream(outputFile);
InputStream inputStream = connection.getInputStream();

byte[] data = new byte[1024];
int count;
while ((count = inputStream.read(data)) != -1) {
outputStream.write(data, 0, count);
}

outputStream.flush();
outputStream.close();
inputStream.close();

return Result.success();
} catch (Exception e) {
Log.d("hello", String.valueOf(e));

e.printStackTrace();
return Result.failure();
}
}
}
Loading

0 comments on commit 72174cc

Please sign in to comment.