-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
adguard_cb/src/main/java/com/adguard/android/contentblocker/receiver/StarsCountReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.adguard.android.contentblocker.receiver; | ||
|
||
import android.app.NotificationManager; | ||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
import com.adguard.android.contentblocker.ServiceLocator; | ||
import com.adguard.android.contentblocker.service.NotificationServiceImpl; | ||
import com.adguard.android.contentblocker.ui.MainActivity; | ||
import com.adguard.android.contentblocker.ui.utils.NavigationHelper; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import static android.content.Context.NOTIFICATION_SERVICE; | ||
|
||
public class StarsCountReceiver extends BroadcastReceiver { | ||
|
||
private static final long REDIRECTION_DELAY = 300; | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
String action = intent.getAction(); | ||
if (StringUtils.isEmpty(action)) { | ||
return; | ||
} | ||
|
||
int count = ServiceLocator.getInstance(context).getNotificationService().showRateAppNotification(action); | ||
// If something wrong with action, the user can rate us anyway. | ||
if (count == 0) { | ||
NavigationHelper.redirectToPlayMarket(context); | ||
} else { | ||
redirectWithDelay(context, count); | ||
} | ||
} | ||
|
||
/** | ||
* Redirects to Google Play market or to feedback dialog. | ||
* {@link Handler#postDelayed} used to fill selected stars count explicit before redirection | ||
* | ||
* @param count Selected stars count | ||
*/ | ||
private void redirectWithDelay(Context context, final int count) { | ||
new Handler(Looper.getMainLooper()).postDelayed(() -> { | ||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); | ||
if (notificationManager != null) { | ||
// Cancel current 'rate app' notification and close notification bar before redirection | ||
notificationManager.cancel(NotificationServiceImpl.RATE_NOTIFICATION_ID); | ||
Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); | ||
context.sendBroadcast(closeIntent); | ||
} | ||
|
||
if (count > 3) { | ||
NavigationHelper.redirectToPlayMarket(context); | ||
} else { | ||
Bundle bundle = new Bundle(); | ||
bundle.putInt(MainActivity.STARS_COUNT, count); | ||
NavigationHelper.redirectToActivity(context, MainActivity.class, bundle); | ||
} | ||
}, REDIRECTION_DELAY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters