Open info dialog from notification
This commit is contained in:
parent
c056f7becc
commit
d65828f369
|
@ -38,6 +38,13 @@
|
||||||
android:label="@string/title_activity_reviews"
|
android:label="@string/title_activity_reviews"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".InfoDialogActivity"
|
||||||
|
android:autoRemoveFromRecents="true"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:noHistory="true"
|
||||||
|
android:theme="@style/DialogBackgroundTheme" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".CallReceiver"
|
android:name=".CallReceiver"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package dummydomain.yetanothercallblocker;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import dummydomain.yetanothercallblocker.data.DatabaseSingleton;
|
||||||
|
import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||||
|
|
||||||
|
public class InfoDialogActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
public static final String PARAM_NUMBER = "number";
|
||||||
|
|
||||||
|
public static Intent getIntent(Context context, String number) {
|
||||||
|
Intent intent = new Intent(context, InfoDialogActivity.class);
|
||||||
|
intent.putExtra(PARAM_NUMBER, number);
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
NumberInfo numberInfo = DatabaseSingleton.getNumberInfo(
|
||||||
|
getIntent().getStringExtra(PARAM_NUMBER));
|
||||||
|
|
||||||
|
InfoDialogHelper.showDialog(this, numberInfo, (d) -> finish());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package dummydomain.yetanothercallblocker;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
|
import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||||
|
|
||||||
|
public class InfoDialogHelper {
|
||||||
|
|
||||||
|
public static void showDialog(Context context, NumberInfo numberInfo,
|
||||||
|
DialogInterface.OnDismissListener onDismissListener) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
|
.setTitle(numberInfo.number);
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
|
View view = LayoutInflater.from(context).inflate(R.layout.info_dialog, null);
|
||||||
|
|
||||||
|
String name = "";
|
||||||
|
|
||||||
|
String contactName = numberInfo.contactItem != null
|
||||||
|
? numberInfo.contactItem.displayName : null;
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(contactName)) {
|
||||||
|
name += contactName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String featuredName = numberInfo.featuredDatabaseItem != null
|
||||||
|
? numberInfo.featuredDatabaseItem.getName() : null;
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(featuredName)) {
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
name = featuredName;
|
||||||
|
} else {
|
||||||
|
name += "\n(" + featuredName + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView nameView = view.findViewById(R.id.name);
|
||||||
|
if (!TextUtils.isEmpty(name)) {
|
||||||
|
nameView.setText(name);
|
||||||
|
} else {
|
||||||
|
nameView.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReviewsSummaryHelper.populateSummary(view.findViewById(R.id.reviews_summary),
|
||||||
|
numberInfo.communityDatabaseItem);
|
||||||
|
|
||||||
|
builder.setView(view);
|
||||||
|
|
||||||
|
builder.setNeutralButton(R.string.online_reviews, (d, w)
|
||||||
|
-> ReviewsActivity.startForNumber(context, numberInfo.number));
|
||||||
|
|
||||||
|
builder.setNegativeButton(R.string.back, null);
|
||||||
|
|
||||||
|
if (onDismissListener != null) builder.setOnDismissListener(onDismissListener);
|
||||||
|
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,11 +5,9 @@ import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
@ -201,50 +199,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCallLogItemClicked(CallLogItem item) {
|
private void onCallLogItemClicked(CallLogItem item) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
InfoDialogHelper.showDialog(this, item.numberInfo, null);
|
||||||
.setTitle(item.number);
|
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
|
||||||
View view = getLayoutInflater().inflate(R.layout.info_dialog, null);
|
|
||||||
|
|
||||||
String name = "";
|
|
||||||
|
|
||||||
String contactName = item.numberInfo.contactItem != null
|
|
||||||
? item.numberInfo.contactItem.displayName : null;
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(contactName)) {
|
|
||||||
name += contactName;
|
|
||||||
}
|
|
||||||
|
|
||||||
String featuredName = item.numberInfo.featuredDatabaseItem != null
|
|
||||||
? item.numberInfo.featuredDatabaseItem.getName() : null;
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(featuredName)) {
|
|
||||||
if (name.isEmpty()) {
|
|
||||||
name = featuredName;
|
|
||||||
} else {
|
|
||||||
name += "\n(" + featuredName + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView nameView = view.findViewById(R.id.name);
|
|
||||||
if (!TextUtils.isEmpty(name)) {
|
|
||||||
nameView.setText(name);
|
|
||||||
} else {
|
|
||||||
nameView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReviewsSummaryHelper.populateSummary(view.findViewById(R.id.reviews_summary),
|
|
||||||
item.numberInfo.communityDatabaseItem);
|
|
||||||
|
|
||||||
builder.setView(view);
|
|
||||||
|
|
||||||
builder.setNeutralButton(R.string.online_reviews, (d, w)
|
|
||||||
-> ReviewsActivity.startForNumber(this, item.number));
|
|
||||||
|
|
||||||
builder.setNegativeButton(R.string.back, null);
|
|
||||||
|
|
||||||
builder.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadCallLog() {
|
private void loadCallLog() {
|
||||||
|
|
|
@ -20,6 +20,8 @@ import dummydomain.yetanothercallblocker.data.NumberInfo;
|
||||||
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
import dummydomain.yetanothercallblocker.sia.model.NumberCategory;
|
||||||
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
import dummydomain.yetanothercallblocker.sia.model.database.CommunityDatabaseItem;
|
||||||
|
|
||||||
|
import static dummydomain.yetanothercallblocker.PendingIntentHelper.forActivity;
|
||||||
|
|
||||||
public class NotificationHelper {
|
public class NotificationHelper {
|
||||||
|
|
||||||
private static final String NOTIFICATION_TAG_INCOMING_CALL = "incomingCallNotification";
|
private static final String NOTIFICATION_TAG_INCOMING_CALL = "incomingCallNotification";
|
||||||
|
@ -129,7 +131,7 @@ public class NotificationHelper {
|
||||||
IconAndColor iconAndColor = IconAndColor.forNumberRating(
|
IconAndColor iconAndColor = IconAndColor.forNumberRating(
|
||||||
numberInfo.rating, numberInfo.contactItem != null);
|
numberInfo.rating, numberInfo.contactItem != null);
|
||||||
|
|
||||||
return new NotificationCompat.Builder(context, channelId)
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
|
||||||
.setSmallIcon(iconAndColor.iconResId)
|
.setSmallIcon(iconAndColor.iconResId)
|
||||||
.setColor(iconAndColor.getColorInt(context))
|
.setColor(iconAndColor.getColorInt(context))
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
|
@ -137,24 +139,29 @@ public class NotificationHelper {
|
||||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
||||||
.setShowWhen(false)
|
.setShowWhen(false)
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) // TODO: check
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); // TODO: check
|
||||||
.setContentIntent(createReviewsIntent(context, numberInfo))
|
|
||||||
.build();
|
addCallNotificationIntents(context, builder, numberInfo);
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Notification createBlockedCallNotification(Context context, NumberInfo numberInfo) {
|
private static Notification createBlockedCallNotification(Context context, NumberInfo numberInfo) {
|
||||||
String title = context.getString(R.string.notification_blocked_call);
|
String title = context.getString(R.string.notification_blocked_call);
|
||||||
String text = getDescription(context, numberInfo);
|
String text = getDescription(context, numberInfo);
|
||||||
|
|
||||||
return new NotificationCompat.Builder(context, CHANNEL_ID_BLOCKED_INFO)
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(
|
||||||
|
context, CHANNEL_ID_BLOCKED_INFO)
|
||||||
.setSmallIcon(R.drawable.ic_thumb_down_24dp)
|
.setSmallIcon(R.drawable.ic_thumb_down_24dp)
|
||||||
.setColor(0xffffff60)
|
.setColor(0xffffff60)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
.setCategory(NotificationCompat.CATEGORY_STATUS)
|
.setCategory(NotificationCompat.CATEGORY_STATUS);
|
||||||
.setContentIntent(createReviewsIntent(context, numberInfo))
|
|
||||||
.build();
|
addCallNotificationIntents(context, builder, numberInfo);
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getDescription(Context context, NumberInfo numberInfo) {
|
private static String getDescription(Context context, NumberInfo numberInfo) {
|
||||||
|
@ -178,10 +185,20 @@ public class NotificationHelper {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addCallNotificationIntents(Context context,
|
||||||
|
NotificationCompat.Builder builder,
|
||||||
|
NumberInfo numberInfo) {
|
||||||
|
builder.setContentIntent(createInfoIntent(context, numberInfo))
|
||||||
|
.addAction(0, context.getString(R.string.online_reviews),
|
||||||
|
createReviewsIntent(context, numberInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PendingIntent createInfoIntent(Context context, NumberInfo numberInfo) {
|
||||||
|
return forActivity(context, InfoDialogActivity.getIntent(context, numberInfo.number));
|
||||||
|
}
|
||||||
|
|
||||||
private static PendingIntent createReviewsIntent(Context context, NumberInfo numberInfo) {
|
private static PendingIntent createReviewsIntent(Context context, NumberInfo numberInfo) {
|
||||||
Intent intent = ReviewsActivity.getNumberIntent(context, numberInfo.number);
|
return forActivity(context, ReviewsActivity.getNumberIntent(context, numberInfo.number));
|
||||||
intent.setAction(Long.toString(System.currentTimeMillis())); // make the intent "unique"
|
|
||||||
return PendingIntent.getActivity(context, 0, intent, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createNotificationChannels(Context context) {
|
static void createNotificationChannels(Context context) {
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package dummydomain.yetanothercallblocker;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
public class PendingIntentHelper {
|
||||||
|
|
||||||
|
public static PendingIntent forActivity(Context context, Intent intent) {
|
||||||
|
// creates a new pending intent instead of returning an existing one
|
||||||
|
return PendingIntent.getActivity(context, getRandomInt(), intent, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getRandomInt() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
return ThreadLocalRandom.current().nextInt();
|
||||||
|
} else {
|
||||||
|
return new Random().nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,4 +17,12 @@
|
||||||
|
|
||||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||||
|
|
||||||
|
<style name="DialogBackgroundTheme" parent="AppTheme.NoActionBar">
|
||||||
|
<item name="android:windowIsTranslucent">true</item>
|
||||||
|
<item name="android:windowBackground">@android:color/transparent</item>
|
||||||
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
|
<item name="android:windowNoTitle">true</item>
|
||||||
|
<item name="android:windowIsFloating">true</item>
|
||||||
|
<item name="android:backgroundDimEnabled">false</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue