Merge branch 'master'
This commit is contained in:
parent
529c1e2b07
commit
00ffe9c41e
|
@ -7,10 +7,14 @@ import android.content.pm.PackageManager;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.joinmastodon.android.api.ObjectValidationException;
|
||||
import org.joinmastodon.android.api.requests.accounts.SetPrivateNote;
|
||||
import org.joinmastodon.android.api.requests.statuses.SetStatusFavorited;
|
||||
import org.joinmastodon.android.api.session.AccountSession;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.events.StatusCountersUpdatedEvent;
|
||||
import org.joinmastodon.android.fragments.ComposeFragment;
|
||||
import org.joinmastodon.android.fragments.HomeFragment;
|
||||
import org.joinmastodon.android.fragments.ProfileFragment;
|
||||
|
@ -19,12 +23,17 @@ import org.joinmastodon.android.fragments.onboarding.AccountActivationFragment;
|
|||
import org.joinmastodon.android.fragments.onboarding.CustomWelcomeFragment;
|
||||
import org.joinmastodon.android.fragments.onboarding.CustomWelcomeFragment;
|
||||
import org.joinmastodon.android.model.Notification;
|
||||
import org.joinmastodon.android.model.NotificationAction;
|
||||
import org.joinmastodon.android.model.Relationship;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
import org.joinmastodon.android.updater.GithubSelfUpdater;
|
||||
import org.parceler.Parcels;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import me.grishka.appkit.FragmentStackActivity;
|
||||
import me.grishka.appkit.api.Callback;
|
||||
import me.grishka.appkit.api.ErrorResponse;
|
||||
|
||||
public class MainActivity extends FragmentStackActivity{
|
||||
@Override
|
||||
|
@ -98,6 +107,26 @@ public class MainActivity extends FragmentStackActivity{
|
|||
}
|
||||
}else if(intent.getBooleanExtra("compose", false)){
|
||||
showCompose();
|
||||
}else if(intent.getStringExtra("notificationAction") != null) {
|
||||
switch (NotificationAction.values()[intent.getIntExtra("notificationAction", 0)]) {
|
||||
case FAVORITE -> {
|
||||
String accountID=intent.getStringExtra("accountID");
|
||||
new SetStatusFavorited(intent.getStringExtra("status"), true)
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(Status result){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
}
|
||||
})
|
||||
.exec(accountID);
|
||||
}
|
||||
case REBLOG -> {
|
||||
}
|
||||
}
|
||||
|
||||
}/*else if(intent.hasExtra(PackageInstaller.EXTRA_STATUS) && GithubSelfUpdater.needSelfUpdating()){
|
||||
GithubSelfUpdater.getInstance().handleIntentFromInstaller(intent, this);
|
||||
}*/
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.BroadcastReceiver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
@ -19,6 +20,7 @@ import org.joinmastodon.android.api.requests.notifications.GetNotificationByID;
|
|||
import org.joinmastodon.android.api.session.AccountSession;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.model.NotificationAction;
|
||||
import org.joinmastodon.android.model.PushNotification;
|
||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||
import org.parceler.Parcels;
|
||||
|
@ -99,6 +101,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||
Account self=AccountSessionManager.getInstance().getAccount(accountID).self;
|
||||
String accountName="@"+self.username+"@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
|
||||
Notification.Builder builder;
|
||||
Notification.Builder summaryNotification;
|
||||
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
|
||||
boolean hasGroup=false;
|
||||
List<NotificationChannelGroup> channelGroups=nm.getNotificationChannelGroups();
|
||||
|
@ -121,21 +124,28 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||
nm.createNotificationChannels(channels);
|
||||
}
|
||||
builder=new Notification.Builder(context, accountID+"_"+pn.notificationType);
|
||||
// summaryNotification=new Notification.Builder(context, accountID);
|
||||
}else{
|
||||
builder=new Notification.Builder(context)
|
||||
.setPriority(Notification.PRIORITY_DEFAULT)
|
||||
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
|
||||
summaryNotification=new Notification.Builder(context)
|
||||
.setPriority(Notification.PRIORITY_DEFAULT)
|
||||
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
|
||||
}
|
||||
Drawable avatar=ImageCache.getInstance(context).get(new UrlImageLoaderRequest(pn.icon, V.dp(50), V.dp(50)));
|
||||
Intent contentIntent=new Intent(context, MainActivity.class);
|
||||
contentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
contentIntent.putExtra("fromNotification", true);
|
||||
contentIntent.putExtra("accountID", accountID);
|
||||
contentIntent.putExtra("notificationID", notificationId);
|
||||
if(notification!=null){
|
||||
contentIntent.putExtra("notification", Parcels.wrap(notification));
|
||||
}
|
||||
|
||||
builder.setContentTitle(pn.title)
|
||||
.setContentText(pn.body)
|
||||
.setContentTitle(pn.title)
|
||||
.setStyle(new Notification.BigTextStyle().bigText(pn.body))
|
||||
.setSmallIcon(R.drawable.ic_ntf_logo)
|
||||
.setContentIntent(PendingIntent.getActivity(context, notificationId, contentIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
|
@ -143,7 +153,8 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||
.setShowWhen(true)
|
||||
.setCategory(Notification.CATEGORY_SOCIAL)
|
||||
.setAutoCancel(true)
|
||||
.setColor(context.getColor(R.color.shortcut_icon_background));
|
||||
.setColor(context.getColor(R.color.shortcut_icon_background))
|
||||
.setGroup(accountID);
|
||||
|
||||
if (!GlobalUserPreferences.uniformNotificationIcon) {
|
||||
builder.setSmallIcon(switch (pn.notificationType) {
|
||||
|
@ -165,6 +176,35 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||
if(AccountSessionManager.getInstance().getLoggedInAccounts().size()>1){
|
||||
builder.setSubText(accountName);
|
||||
}
|
||||
nm.notify(accountID, GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : notificationId++, builder.build());
|
||||
|
||||
|
||||
Intent actionIntent = new Intent(context, MainActivity.class);
|
||||
actionIntent.putExtra("fromNotification", true);
|
||||
actionIntent.putExtra("accountID", accountID);
|
||||
actionIntent.putExtra("notificationID", notificationId);
|
||||
if(notification!=null){
|
||||
actionIntent.putExtra("status", notification.status.id);
|
||||
// actionIntent.putExtra("notification", Parcels.wrap(notification));
|
||||
}
|
||||
PendingIntent actionPendingIntent =
|
||||
PendingIntent.getBroadcast(context, 0, actionIntent, 0);
|
||||
|
||||
switch (pn.notificationType) {
|
||||
case FAVORITE -> builder.setSmallIcon(R.drawable.ic_fluent_star_24_filled);
|
||||
case REBLOG -> builder.setSmallIcon(R.drawable.ic_fluent_arrow_repeat_all_24_filled);
|
||||
case FOLLOW -> builder.setSmallIcon(R.drawable.ic_fluent_person_add_24_filled);
|
||||
case MENTION -> builder.setSmallIcon(R.drawable.ic_fluent_mention_24_filled);
|
||||
case POLL -> builder.setSmallIcon(R.drawable.ic_fluent_poll_24_filled);
|
||||
default -> builder.setSmallIcon(R.drawable.ic_ntf_logo);
|
||||
}
|
||||
|
||||
if (pn.notificationType == PushNotification.Type.MENTION) {
|
||||
actionIntent.putExtra("notificationAction", NotificationAction.REBLOG.ordinal());
|
||||
builder.addAction(new Notification.Action.Builder(null, "Favorite", actionPendingIntent).build());
|
||||
}
|
||||
|
||||
notificationId++;
|
||||
nm.notify(accountID, GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : notificationId, builder.build());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package org.joinmastodon.android.model;
|
||||
|
||||
public enum NotificationAction {
|
||||
FAVORITE,
|
||||
REBLOG
|
||||
}
|
Loading…
Reference in New Issue