Skip to content

Commit 1b0454e

Browse files
committed
Added github sponsor dialog
1 parent 8e13600 commit 1b0454e

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

app/src/main/java/com/noti/main/ui/SettingsActivity.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import androidx.annotation.NonNull;
2323
import androidx.annotation.Nullable;
2424
import androidx.appcompat.app.ActionBar;
25+
import androidx.appcompat.view.ContextThemeWrapper;
2526

2627
import com.google.android.material.card.MaterialCardView;
2728
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@@ -87,12 +88,13 @@ public interface onPurchasedListener {
8788
MaterialCardView InfoPreferences;
8889

8990
SharedPreferences.OnSharedPreferenceChangeListener prefsListener = (p, k) -> {
90-
if (k.equals("serviceToggle")) {
91-
ServiceToggle.setChecked(prefs.getBoolean("serviceToggle", false));
92-
} else if (k.equals("UID")) {
93-
updateProfileImage();
94-
} else if (k.equals("NewCardRadius") && !Application.isTablet()) {
95-
setCardViewRadius();
91+
if (k != null) switch (k) {
92+
case "serviceToggle" ->
93+
ServiceToggle.setChecked(prefs.getBoolean("serviceToggle", false));
94+
case "UID" -> updateProfileImage();
95+
case "NewCardRadius" -> {
96+
if (!Application.isTablet()) setCardViewRadius();
97+
}
9698
}
9799
};
98100

@@ -293,7 +295,7 @@ protected void onCreate(Bundle savedInstanceState) {
293295
}
294296
}
295297

296-
if(!prefs.getBoolean("IsFcmTopicSubscribed", false) && !(mAuth.getUid() == null ? "" : mAuth.getUid()).isEmpty()) {
298+
if (!prefs.getBoolean("IsFcmTopicSubscribed", false) && !(mAuth.getUid() == null ? "" : mAuth.getUid()).isEmpty()) {
297299
FirebaseMessaging.getInstance().subscribeToTopic(Objects.requireNonNull(mAuth.getUid()));
298300
}
299301

@@ -317,6 +319,27 @@ protected void onCreate(Bundle savedInstanceState) {
317319
if (mBillingHelper.isSubscribed()) {
318320
new RegisterForPushNotificationsAsync(this).execute();
319321
}
322+
323+
showSupportDialog();
324+
}
325+
326+
protected void showSupportDialog() {
327+
long dismissTime = prefs.getLong("SupportMessageDismiss", 0);
328+
if (BuildConfig.DEBUG || (dismissTime != 0 && System.currentTimeMillis() - dismissTime <= (259200000 /* 3 Days */))) {
329+
return;
330+
}
331+
332+
new MaterialAlertDialogBuilder(new ContextThemeWrapper(SettingsActivity.this, R.style.Theme_App_Palette_Dialog))
333+
.setTitle("Please Support Us!")
334+
.setMessage("NotiSender is currently running at a loss to maintain its servers, despite virtually no revenue." +
335+
"\nPlease help us maintain this open source project!")
336+
.setPositiveButton("Support", (dialog, which) ->
337+
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/sponsors/choiman1559"))))
338+
.setNegativeButton("Close", (dialog, which) -> {
339+
})
340+
.setNeutralButton("Do not show for 3 days", (dialog, which) -> prefs.edit().putLong("SupportMessageDismiss", System.currentTimeMillis()).apply())
341+
.setCancelable(false)
342+
.show();
320343
}
321344

322345
public static void getAPIKeyFromCloud(Activity mContext) {
@@ -334,7 +357,7 @@ public static void getAPIKeyFromCloud(Activity mContext) {
334357
.apply();
335358
}
336359

337-
if(mBillingHelper != null) mBillingHelper.Destroy();
360+
if (mBillingHelper != null) mBillingHelper.Destroy();
338361
mBillingHelper = BillingHelper.initialize(mContext);
339362
} else {
340363
new MaterialAlertDialogBuilder(mContext)

0 commit comments

Comments
 (0)