Commit 12e1360c authored by Thomas's avatar Thomas
Browse files

Fix issue #339 #333 Notification issues

parent 73324a9e
Loading
Loading
Loading
Loading
+50 −42
Original line number Diff line number Diff line
@@ -278,6 +278,34 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
        mamageNewIntent(intent);
    }

    /**
     * Open notifications tab when coming from a notification device
     *
     * @param intent - Intent intent that will be cancelled
     */
    private void openNotifications(Intent intent) {
        final Handler handler = new Handler();
        handler.postDelayed(() -> {
            SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
            boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false);
            if (!singleBar) {
                binding.bottomNavView.setSelectedItemId(R.id.nav_notifications);
            } else {
                int position = 0;
                for (int i = 0; i < binding.tabLayout.getTabCount(); i++) {
                    TabLayout.Tab tab = binding.tabLayout.getTabAt(i);
                    if (tab != null && tab.getTag() != null && tab.getTag().equals(Timeline.TimeLineEnum.NOTIFICATION.getValue())) {
                        break;
                    }
                    position++;
                }
                binding.viewPager.setCurrentItem(position);
            }
        }, 1000);
        intent.removeExtra(Helper.INTENT_ACTION);
    }


    @SuppressLint("ApplySharedPref")
    private void mamageNewIntent(Intent intent) {
        if (intent == null)
@@ -290,6 +318,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
            userIdIntent = extras.getString(Helper.PREF_KEY_ID); //Id of the account in the intent
            instanceIntent = extras.getString(Helper.PREF_INSTANCE);
            if (extras.getInt(Helper.INTENT_ACTION) == Helper.NOTIFICATION_INTENT) {
                if (userIdIntent != null && instanceIntent != null && userIdIntent.equals(currentUserID) && instanceIntent.equals(currentInstance)) {
                    openNotifications(intent);
                } else {
                    try {
                        BaseAccount account = new Account(BaseMainActivity.this).getUniqAccount(userIdIntent, instanceIntent);
                        SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
@@ -308,32 +339,9 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
                    } catch (DBException e) {
                        e.printStackTrace();
                    }
            } else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_NOTIFICATION) {
                final Handler handler = new Handler();
                handler.postDelayed(() -> {
                    SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
                    boolean singleBar = sharedpreferences.getBoolean(getString(R.string.SET_USE_SINGLE_TOPBAR), false);
                    if (!singleBar) {
                        int position = BottomMenu.getPosition(bottomMenu, R.id.nav_notifications);
                        if (position > 0 && binding.bottomNavView.getMenu().size() < position) {
                            binding.bottomNavView.getMenu().getItem(position).setChecked(true);
                            binding.viewPager.setCurrentItem(position);
                }
                    } else {
                        int position = 0;
                        for (PinnedTimeline pinnedTimeline : pinned.pinnedTimelines) {
                            if (pinnedTimeline.type == Timeline.TimeLineEnum.NOTIFICATION && binding.bottomNavView.getMenu().size() < position) {
                                binding.bottomNavView.getMenu().getItem(position).setChecked(true);
                                binding.viewPager.setCurrentItem(position);
                                break;
                            }
                            position++;
                        }
                    }

                }, 2000);
                intent.removeExtra(Helper.INTENT_ACTION);

            } else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_NOTIFICATION) {
                openNotifications(intent);
            }
        } else if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
+2 −3
Original line number Diff line number Diff line
@@ -1550,17 +1550,16 @@ public class Helper {
        notificationBuilder.setLargeIcon(icon);


        Notification summaryNotification = summaryNotification = new NotificationCompat.Builder(context, channelId)
        Notification summaryNotification = new NotificationCompat.Builder(context, channelId)
                .setContentTitle(title)
                .setContentText(channelTitle)
                .setContentIntent(pIntent)
                .setLargeIcon(icon)
                .setSmallIcon(R.drawable.ic_notification)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setGroup(account.mastodon_account != null ? account.mastodon_account.acct : "" + "@" + account.instance)
                .setGroup(account.mastodon_account != null ? account.mastodon_account.username + "@" + account.instance : "" + "@" + account.instance)
                .setGroupSummary(true)
                .build();

        notificationManager.notify(notificationId++, notificationBuilder.build());
        notificationManager.notify(0, summaryNotification);
    }
+0 −4
Original line number Diff line number Diff line
@@ -40,8 +40,6 @@ import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;
import java.util.ArrayList;
@@ -137,7 +135,6 @@ public class NotificationsHelper {
                .connectTimeout(60, TimeUnit.SECONDS)
                .proxy(Helper.getProxy(context))
                .build();
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://" + instance + "/api/v1/")
                .addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
@@ -180,7 +177,6 @@ public class NotificationsHelper {
            Helper.NotifType notifType = Helper.NotifType.MENTION;
            switch (notification.type) {
                case "mention":
                    notifType = Helper.NotifType.MENTION;
                    if (notif_mention) {
                        if (notification.account.display_name != null && notification.account.display_name.length() > 0)
                            title = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_mention));