Add status notification for followed account + fix crashes with photo editor

This commit is contained in:
Thomas 2021-01-23 09:39:39 +01:00
parent 790e53096b
commit 5d7bffcf3a
14 changed files with 537 additions and 929 deletions

View File

@ -453,6 +453,7 @@ public class ShowAccountActivity extends BaseActivity implements OnPostActionInt
}
});
mPager = findViewById(R.id.account_viewpager);
TabLayout.Tab tab = tabLayout.newTab();
if (!peertubeAccount) {
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.following)));

View File

@ -4913,6 +4913,7 @@ public class API {
apiResponse.setMax_id(httpsConnection.getMax_id());
notifications = parseNotificationResponse(new JSONArray(response));
} catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace();
setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
e.printStackTrace();

View File

@ -127,7 +127,6 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
private final List<Account> translators = new ArrayList<>();
private type type;
private Context context;
private AsyncTask asyncTask;
private int countTrans, countLanguage, notificationCount, ledCount, videoSpinnerCount, liveNotificationCount;
private AccountSearchDevAdapter translatorManager;
private TextView set_folder;
@ -136,11 +135,9 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
//From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
if (DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
@ -2570,10 +2567,6 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
public void onDestroy() {
super.onDestroy();
if (type == LANGUAGE) {
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
asyncTask.cancel(true);
}
}
public enum type {

View File

@ -127,10 +127,11 @@ public class TabLayoutNotificationsFragment extends Fragment {
tabLayout.addTab(tabFav);
if (tabBoost.getCustomView() != null)
tabLayout.addTab(tabBoost);
if (tabPoll.getCustomView() != null)
tabLayout.addTab(tabPoll);
if (tabStatus.getCustomView() != null)
tabLayout.addTab(tabStatus);
if (tabPoll.getCustomView() != null)
tabLayout.addTab(tabPoll);
tabLayout.addTab(tabFollow);
if (theme == Helper.THEME_BLACK)
@ -196,7 +197,7 @@ public class TabLayoutNotificationsFragment extends Fragment {
}
@Override
public void onAttach(Context context) {
public void onAttach(@NotNull Context context) {
super.onAttach(context);
this.context = context;
}

View File

@ -1139,8 +1139,8 @@ public class BaseHelper {
channelTitle = context.getString(R.string.channel_notif_media);
break;
case TOOT:
channelId = "channel_toot";
channelTitle = context.getString(R.string.channel_notif_toot);
channelId = "channel_status";
channelTitle = context.getString(R.string.channel_notif_status);
break;
default:
channelId = "channel_boost";
@ -3454,16 +3454,26 @@ public class BaseHelper {
ContentResolver resolver = context.getContentResolver();
Cursor returnCursor =
resolver.query(uri, null, null, null, null);
assert returnCursor != null;
try {
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
returnCursor.moveToFirst();
String name = returnCursor.getString(nameIndex);
returnCursor.close();
Random r = new Random();
int suf = r.nextInt(9999 - 1000) + 1000;
return suf + name;
} catch (Exception e) {
if (returnCursor != null) {
try {
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
returnCursor.moveToFirst();
String name = returnCursor.getString(nameIndex);
returnCursor.close();
Random r = new Random();
int suf = r.nextInt(9999 - 1000) + 1000;
return suf + name;
} catch (Exception e) {
Random r = new Random();
int suf = r.nextInt(9999 - 1000) + 1000;
ContentResolver cr = context.getContentResolver();
String mime = cr.getType(uri);
if (mime != null && mime.split("/").length > 1)
return "__" + suf + "." + mime.split("/")[1];
else
return "__" + suf + ".jpg";
}
} else {
Random r = new Random();
int suf = r.nextInt(9999 - 1000) + 1000;
ContentResolver cr = context.getContentResolver();

View File

@ -161,6 +161,7 @@ public class BaseNotificationsSyncJob extends Job {
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
boolean notif_status = sharedpreferences.getBoolean(Helper.SET_NOTIF_STATUS, true);
final String max_id = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + account.getId() + account.getInstance(), null);
final List<Notification> notifications = new ArrayList<>();
int pos = 0;
@ -178,6 +179,7 @@ public class BaseNotificationsSyncJob extends Job {
int newMentions = 0;
int newShare = 0;
int newPolls = 0;
int newStatus = 0;
String notificationUrl = null;
String title = null;
final String message;
@ -199,6 +201,19 @@ public class BaseNotificationsSyncJob extends Job {
}
}
break;
case "status":
notifType = Helper.NotifType.STATUS;
if (notif_status) {
newStatus++;
if (notificationUrl == null) {
notificationUrl = notification.getAccount().getAvatar();
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
title = String.format("%s %s", notification.getAccount().getDisplay_name(), getContext().getString(R.string.notif_mention));
else
title = String.format("@%s %s", notification.getAccount().getAcct(), getContext().getString(R.string.notif_mention));
}
}
break;
case "reblog":
notifType = Helper.NotifType.BOOST;
if (notif_share) {
@ -272,7 +287,7 @@ public class BaseNotificationsSyncJob extends Job {
}
}
int allNotifCount = newFollows + newAdds + newMentions + newShare + newPolls;
int allNotifCount = newFollows + newAdds + newMentions + newShare + newPolls + newStatus;
if (allNotifCount > 0) {
//Some others notification
int other = allNotifCount - 1;

View File

@ -67,12 +67,10 @@ public class BackupStatusService extends IntentService {
*
* @param name Used to name the worker thread, important only for debugging.
*/
@SuppressWarnings("unused")
public BackupStatusService(String name) {
super(name);
}
@SuppressWarnings("unused")
public BackupStatusService() {
super("BackupStatusService");
}

View File

@ -342,8 +342,9 @@ public abstract class BaseLiveNotificationService extends Service implements Net
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
boolean notif_status = sharedpreferences.getBoolean(Helper.SET_NOTIF_STATUS, true);
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll);
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll || notif_status);
String message = null;
if (somethingToPush) {
switch (notification.getType()) {
@ -373,7 +374,7 @@ public abstract class BaseLiveNotificationService extends Service implements Net
break;
case "status":
notifType = Helper.NotifType.STATUS;
if (notif_mention) {
if (notif_status) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_status));
else

View File

@ -60,12 +60,10 @@ public abstract class BaseStreamingFederatedTimelineService extends IntentServic
*
* @param name Used to name the worker thread, important only for debugging.
*/
@SuppressWarnings("unused")
public BaseStreamingFederatedTimelineService(String name) {
super(name);
}
@SuppressWarnings("unused")
public BaseStreamingFederatedTimelineService() {
super("StreamingFederatedTimelineService");
}

View File

@ -60,12 +60,10 @@ public abstract class BaseStreamingHomeTimelineService extends IntentService {
*
* @param name Used to name the worker thread, important only for debugging.
*/
@SuppressWarnings("unused")
public BaseStreamingHomeTimelineService(String name) {
super(name);
}
@SuppressWarnings("unused")
public BaseStreamingHomeTimelineService() {
super("StreamingHomeTimelineService");
}
@ -104,14 +102,6 @@ public abstract class BaseStreamingHomeTimelineService extends IntentService {
Uri url = Uri.parse("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + accountStream.getToken());
AsyncHttpRequest.setDefaultHeaders(headers, url);
Account finalAccountStream = accountStream;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
try {
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(new TLSSocketFactory(accountStream.getInstance()).getSSLContext());
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setConnectAllAddresses(true);
} catch (KeyManagementException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
AsyncHttpClient.getDefaultInstance().websocket("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + accountStream.getToken(), "wss", (ex, webSocket) -> {
if (ex != null) {
ex.printStackTrace();

View File

@ -104,14 +104,6 @@ public abstract class BaseStreamingLocalTimelineService extends IntentService {
Uri url = Uri.parse("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=public:local&access_token=" + accountStream.getToken());
AsyncHttpRequest.setDefaultHeaders(headers, url);
Account finalAccountStream = accountStream;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
try {
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(new TLSSocketFactory(accountStream.getInstance()).getSSLContext());
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setConnectAllAddresses(true);
} catch (KeyManagementException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
AsyncHttpClient.getDefaultInstance().websocket("wss://" + accountStream.getInstance() + "/api/v1/streaming/?stream=public:local&access_token=" + accountStream.getToken(), "wss", (ex, webSocket) -> {
if (ex != null) {
ex.printStackTrace();

View File

@ -214,11 +214,10 @@ public class LiveNotificationDelayedService extends Service {
private void startThread(Account accountStream, String key) {
Thread thread = new Thread() {
@SuppressWarnings("ConstantConditions")
@Override
public void run() {
while (fetch) {
taks(accountStream);
task(accountStream);
fetch = (Helper.liveNotifType(LiveNotificationDelayedService.this) == Helper.NOTIF_DELAYED);
if (sleeps.containsKey(key) && sleeps.get(key) != null) {
try {
@ -241,8 +240,7 @@ public class LiveNotificationDelayedService extends Service {
}
@SuppressWarnings("ConstantConditions")
private void taks(Account account) {
private void task(Account account) {
String key = account.getUsername() + "@" + account.getInstance();
APIResponse apiResponse;
@ -341,8 +339,9 @@ public class LiveNotificationDelayedService extends Service {
boolean notif_add = sharedpreferences.getBoolean(Helper.SET_NOTIF_ADD, true);
boolean notif_mention = sharedpreferences.getBoolean(Helper.SET_NOTIF_MENTION, true);
boolean notif_share = sharedpreferences.getBoolean(Helper.SET_NOTIF_SHARE, true);
boolean notif_status = sharedpreferences.getBoolean(Helper.SET_NOTIF_STATUS, true);
boolean notif_poll = sharedpreferences.getBoolean(Helper.SET_NOTIF_POLL, true);
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll);
boolean somethingToPush = (notif_follow || notif_add || notif_mention || notif_share || notif_poll || notif_status);
String message = null;
if (somethingToPush) {
@ -371,6 +370,30 @@ public class LiveNotificationDelayedService extends Service {
canSendBroadCast = false;
}
break;
case "status":
notifType = Helper.NotifType.STATUS;
if (notif_status) {
if (notification.getAccount().getDisplay_name() != null && notification.getAccount().getDisplay_name().length() > 0)
message = String.format("%s %s", notification.getAccount().getDisplay_name(), getString(R.string.notif_status));
else
message = String.format("@%s %s", notification.getAccount().getAcct(), getString(R.string.notif_status));
if (notification.getStatus() != null) {
if (notification.getStatus().getSpoiler_text() != null && notification.getStatus().getSpoiler_text().length() > 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text(), FROM_HTML_MODE_LEGACY));
else
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getSpoiler_text()));
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent(), FROM_HTML_MODE_LEGACY));
else
message = "\n" + new SpannableString(Html.fromHtml(notification.getStatus().getContent()));
}
}
} else {
canSendBroadCast = false;
}
break;
case "reblog":
notifType = Helper.NotifType.BOOST;
if (notif_share) {

View File

@ -591,7 +591,7 @@
<string name="channel_notif_poll">Poll Ended</string>
<string name="channel_notif_toot">New Toot</string>
<string name="channel_notif_backup">Toots Backup</string>
<string name="channel_notif_status">New post</string>
<string name="channel_notif_status">New posts</string>
<string name="channel_notif_media">Media Download</string>
<string name="set_notif_sound">Change notification sound</string>
<string name="select_sound">Select Tone</string>