Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first_run_check #27

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</queries>

<application

android:allowBackup="true"
android:allowTaskReparenting="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
39 changes: 27 additions & 12 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 @@ -24,6 +25,8 @@
import com.BugBazaar.ui.cart.CartActivity;
import com.BugBazaar.ui.cart.CartItem;
import com.BugBazaar.ui.cart.NotificationHelper;
import com.BugBazaar.utils.AppInitializationManager;
import com.BugBazaar.utils.CustomDialog;
import com.google.android.material.navigation.NavigationView;

import java.util.ArrayList;
Expand All @@ -42,21 +45,33 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer_dashboard);

Intent getLink = getIntent();
Uri data = getLink.getData();
if (AppInitializationManager.isFirstRun(this)) {
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,new Intent(),0);

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")

// 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.
}
// 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);
}



//
// 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")
//
// // 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.
// }
// }

// Rest of your activity initialization code

// Hide the keyboard and clear focus from the EditText
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.BugBazaar.utils;

import android.content.Context;
import android.content.SharedPreferences;

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

public static void markFirstRunDone(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isFirstRun", false);
editor.apply();
}

public static void showNotification(Context context) {
NotificationUtils.showCustomNotification(context.getApplicationContext());
// Implement your notification logic here
// This can be NotificationUtilsdone using local notifications or Firebase Cloud Messaging
}
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/BugBazaar/utils/CustomDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.BugBazaar.utils;

import android.app.AlertDialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;

public class CustomDialog {
public static void showCustomDialog(Context context, String title, String message, PendingIntent pendingIntent) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title)
.setMessage(message)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {

}
});

AlertDialog dialog = builder.create();
dialog.show();
}
}
52 changes: 52 additions & 0 deletions app/src/main/java/com/BugBazaar/utils/NotificationUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.BugBazaar.utils;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.BugBazaar.R;

public class NotificationUtils {

private static final String CHANNEL_ID = "YourChannelId";
private static final int NOTIFICATION_ID = 1;

public static void showCustomNotification(Context context) {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(com.razorpay.R.drawable.common_google_signin_btn_icon_dark)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setContentTitle("Your Title")
.setContentText("Your Notification Content")
.setContentIntent(pendingIntent);

createNotificationChannel(context);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}

private static void createNotificationChannel(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Your Channel Name";
String description = "Your Channel Description";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);

NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
}

Loading