Skip to content

Commit

Permalink
Merge pull request #31 from banditAmit/amit
Browse files Browse the repository at this point in the history
Amit
  • Loading branch information
banditAmit authored Oct 17, 2023
2 parents 7dc69e1 + ce896b8 commit b8dc0d5
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 76 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
192 changes: 118 additions & 74 deletions app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +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 @@ -46,14 +47,46 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer_dashboard);


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



if (AppInitializationManager.isFirstRun(this)) {
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 Rs 200 voucher.Login to Redeem",pendingIntent);
AppInitializationManager.markFirstRunDone(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;

}


}


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






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

// Hide the keyboard and clear focus from the EditText
Expand Down Expand Up @@ -84,78 +117,36 @@ protected void onCreate(Bundle savedInstanceState) {
productList.add(new Product("Spy TWS", getString(R.string.desc_cycle), R.drawable.item_tws,4200));
productList.add(new Product("VR device", getString(R.string.desc_cycle), R.drawable.item_vr,8340));

// Pass the List<String> to Class B
//Intent intentB = new Intent(this, Deeplink.class);
//intentB.putStringArrayListExtra("productList", (ArrayList<String>) productList); // Need to convert productList to ArrayList<String> data type first

// Convert List<Product> to List<String> of product names in Class A
/* List<String> productNames = new ArrayList<>();
for (Product product : productList) {
productNames.add(product.getName()); // Assuming 'getName()' returns the product name as a String
}*/
//Get string extra from Class B
//intentB.putStringArrayListExtra("productNames", (ArrayList<String>) productNames);
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
}
}
//Check if deeplink_item is present in the product list
/* if (productNames == null) {
Log.d("Empty productNames list:", "productNames list is null");
isItemPresent = false;
}
else {
for (String product : productNames) {
if (product.equals(deeplink_item)) {
isItemPresent = true;
Log.d("Product name:", product);
break; // No need to continue searching if found
}
}
}
if (isItemPresent) {
Log.d("Condition pass:", "Item found");
} else {
Log.d("Condition fail:", "Item not found");
} */
}

//
// 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 @@ -261,6 +252,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 @@ -286,4 +298,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 @@ -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();
}
}
}
48 changes: 48 additions & 0 deletions app/src/main/java/com/BugBazaar/utils/NetworkUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.BugBazaar.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkUtils {
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
return false;
}

public static void showNoInternetDialog(Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("No Internet Access");
builder.setMessage("Open App with Network Access & get voucher on First Run!");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}

public static void showExeptionDialog(Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("!!");
builder.setMessage("Something Happened bad!");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}

}

Loading

0 comments on commit b8dc0d5

Please sign in to comment.