mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-07 00:20:08 +02:00
parent
73324a9ee4
commit
12e1360cc1
3 changed files with 52 additions and 49 deletions
|
@ -278,6 +278,34 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
mamageNewIntent(intent);
|
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")
|
@SuppressLint("ApplySharedPref")
|
||||||
private void mamageNewIntent(Intent intent) {
|
private void mamageNewIntent(Intent intent) {
|
||||||
if (intent == null)
|
if (intent == null)
|
||||||
|
@ -290,50 +318,30 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
||||||
userIdIntent = extras.getString(Helper.PREF_KEY_ID); //Id of the account in the intent
|
userIdIntent = extras.getString(Helper.PREF_KEY_ID); //Id of the account in the intent
|
||||||
instanceIntent = extras.getString(Helper.PREF_INSTANCE);
|
instanceIntent = extras.getString(Helper.PREF_INSTANCE);
|
||||||
if (extras.getInt(Helper.INTENT_ACTION) == Helper.NOTIFICATION_INTENT) {
|
if (extras.getInt(Helper.INTENT_ACTION) == Helper.NOTIFICATION_INTENT) {
|
||||||
try {
|
if (userIdIntent != null && instanceIntent != null && userIdIntent.equals(currentUserID) && instanceIntent.equals(currentInstance)) {
|
||||||
BaseAccount account = new Account(BaseMainActivity.this).getUniqAccount(userIdIntent, instanceIntent);
|
openNotifications(intent);
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
|
} else {
|
||||||
headerMenuOpen = false;
|
try {
|
||||||
Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + account.mastodon_account.acct + "@" + account.instance), Toasty.LENGTH_LONG).show();
|
BaseAccount account = new Account(BaseMainActivity.this).getUniqAccount(userIdIntent, instanceIntent);
|
||||||
BaseMainActivity.currentToken = account.token;
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(BaseMainActivity.this);
|
||||||
BaseMainActivity.currentUserID = account.user_id;
|
headerMenuOpen = false;
|
||||||
api = account.api;
|
Toasty.info(BaseMainActivity.this, getString(R.string.toast_account_changed, "@" + account.mastodon_account.acct + "@" + account.instance), Toasty.LENGTH_LONG).show();
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
BaseMainActivity.currentToken = account.token;
|
||||||
editor.putString(PREF_USER_TOKEN, account.token);
|
BaseMainActivity.currentUserID = account.user_id;
|
||||||
editor.commit();
|
api = account.api;
|
||||||
Intent mainActivity = new Intent(this, MainActivity.class);
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.OPEN_NOTIFICATION);
|
editor.putString(PREF_USER_TOKEN, account.token);
|
||||||
startActivity(mainActivity);
|
editor.commit();
|
||||||
finish();
|
Intent mainActivity = new Intent(this, MainActivity.class);
|
||||||
} catch (DBException e) {
|
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.OPEN_NOTIFICATION);
|
||||||
e.printStackTrace();
|
startActivity(mainActivity);
|
||||||
|
finish();
|
||||||
|
} catch (DBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_NOTIFICATION) {
|
} else if (extras.getInt(Helper.INTENT_ACTION) == Helper.OPEN_NOTIFICATION) {
|
||||||
final Handler handler = new Handler();
|
openNotifications(intent);
|
||||||
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 (Intent.ACTION_SEND.equals(action) && type != null) {
|
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||||
if ("text/plain".equals(type)) {
|
if ("text/plain".equals(type)) {
|
||||||
|
|
|
@ -1550,17 +1550,16 @@ public class Helper {
|
||||||
notificationBuilder.setLargeIcon(icon);
|
notificationBuilder.setLargeIcon(icon);
|
||||||
|
|
||||||
|
|
||||||
Notification summaryNotification = summaryNotification = new NotificationCompat.Builder(context, channelId)
|
Notification summaryNotification = new NotificationCompat.Builder(context, channelId)
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(channelTitle)
|
.setContentText(channelTitle)
|
||||||
.setContentIntent(pIntent)
|
.setContentIntent(pIntent)
|
||||||
.setLargeIcon(icon)
|
.setLargeIcon(icon)
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
|
.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)
|
.setGroupSummary(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
notificationManager.notify(notificationId++, notificationBuilder.build());
|
notificationManager.notify(notificationId++, notificationBuilder.build());
|
||||||
notificationManager.notify(0, summaryNotification);
|
notificationManager.notify(0, summaryNotification);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,6 @@ import com.bumptech.glide.request.RequestListener;
|
||||||
import com.bumptech.glide.request.target.CustomTarget;
|
import com.bumptech.glide.request.target.CustomTarget;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.bumptech.glide.request.transition.Transition;
|
import com.bumptech.glide.request.transition.Transition;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -137,7 +135,6 @@ public class NotificationsHelper {
|
||||||
.connectTimeout(60, TimeUnit.SECONDS)
|
.connectTimeout(60, TimeUnit.SECONDS)
|
||||||
.proxy(Helper.getProxy(context))
|
.proxy(Helper.getProxy(context))
|
||||||
.build();
|
.build();
|
||||||
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
|
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
.baseUrl("https://" + instance + "/api/v1/")
|
.baseUrl("https://" + instance + "/api/v1/")
|
||||||
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
|
.addConverterFactory(GsonConverterFactory.create(Helper.getDateBuilder()))
|
||||||
|
@ -180,7 +177,6 @@ public class NotificationsHelper {
|
||||||
Helper.NotifType notifType = Helper.NotifType.MENTION;
|
Helper.NotifType notifType = Helper.NotifType.MENTION;
|
||||||
switch (notification.type) {
|
switch (notification.type) {
|
||||||
case "mention":
|
case "mention":
|
||||||
notifType = Helper.NotifType.MENTION;
|
|
||||||
if (notif_mention) {
|
if (notif_mention) {
|
||||||
if (notification.account.display_name != null && notification.account.display_name.length() > 0)
|
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));
|
title = String.format("%s %s", notification.account.display_name, context.getString(R.string.notif_mention));
|
||||||
|
|
Loading…
Reference in a new issue