Use thread instead of a service when no media attached when posting - avoid top notification
This commit is contained in:
parent
6803568af8
commit
5e58f8a481
|
@ -75,6 +75,7 @@ import app.fedilab.android.helper.SpannableHelper;
|
||||||
import app.fedilab.android.helper.ThemeHelper;
|
import app.fedilab.android.helper.ThemeHelper;
|
||||||
import app.fedilab.android.jobs.ScheduleThreadWorker;
|
import app.fedilab.android.jobs.ScheduleThreadWorker;
|
||||||
import app.fedilab.android.services.PostMessageService;
|
import app.fedilab.android.services.PostMessageService;
|
||||||
|
import app.fedilab.android.services.ThreadMessageService;
|
||||||
import app.fedilab.android.ui.drawer.AccountsReplyAdapter;
|
import app.fedilab.android.ui.drawer.AccountsReplyAdapter;
|
||||||
import app.fedilab.android.ui.drawer.ComposeAdapter;
|
import app.fedilab.android.ui.drawer.ComposeAdapter;
|
||||||
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
|
import app.fedilab.android.viewmodel.mastodon.AccountsVM;
|
||||||
|
@ -561,6 +562,11 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (sendMessage) {
|
} else if (sendMessage) {
|
||||||
|
int mediaCount = 0;
|
||||||
|
for (Status status : statusDraft.statusDraftList) {
|
||||||
|
mediaCount += status.media_attachments != null ? status.media_attachments.size() : 0;
|
||||||
|
}
|
||||||
|
if (mediaCount > 0) {
|
||||||
Intent intent = new Intent(ComposeActivity.this, PostMessageService.class);
|
Intent intent = new Intent(ComposeActivity.this, PostMessageService.class);
|
||||||
intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft);
|
intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft);
|
||||||
intent.putExtra(Helper.ARG_INSTANCE, instance);
|
intent.putExtra(Helper.ARG_INSTANCE, instance);
|
||||||
|
@ -571,6 +577,9 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
|
||||||
} else {
|
} else {
|
||||||
startService(intent);
|
startService(intent);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
new ThreadMessageService(ComposeActivity.this, instance, token, statusDraft, scheduledDate);
|
||||||
|
}
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,9 @@ public class PostMessageService extends IntentService {
|
||||||
|
|
||||||
private static final int NOTIFICATION_INT_CHANNEL_ID = 1;
|
private static final int NOTIFICATION_INT_CHANNEL_ID = 1;
|
||||||
public static String CHANNEL_ID = "post_messages";
|
public static String CHANNEL_ID = "post_messages";
|
||||||
private long totalMediaSize;
|
|
||||||
private long totalBitRead;
|
|
||||||
private NotificationCompat.Builder notificationBuilder;
|
private NotificationCompat.Builder notificationBuilder;
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private int messageToSend;
|
|
||||||
private int messageSent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name - String
|
* @param name - String
|
||||||
|
@ -97,83 +94,66 @@ public class PostMessageService extends IntentService {
|
||||||
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
|
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground))
|
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_foreground))
|
||||||
.setContentTitle(getString(R.string.post_message))
|
.setContentTitle(getString(R.string.post_message))
|
||||||
.setContentText(getString(R.string.post_message_text, messageSent, messageToSend))
|
|
||||||
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||||
.setPriority(Notification.PRIORITY_DEFAULT);
|
.setPriority(Notification.PRIORITY_DEFAULT);
|
||||||
startForeground(NOTIFICATION_INT_CHANNEL_ID, notificationBuilder.build());
|
startForeground(NOTIFICATION_INT_CHANNEL_ID, notificationBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private OkHttpClient getOkHttpClient() {
|
private static OkHttpClient getOkHttpClient(Context context) {
|
||||||
return new OkHttpClient.Builder()
|
return new OkHttpClient.Builder()
|
||||||
.readTimeout(120, TimeUnit.SECONDS)
|
.readTimeout(120, TimeUnit.SECONDS)
|
||||||
.connectTimeout(120, TimeUnit.SECONDS)
|
.connectTimeout(120, TimeUnit.SECONDS)
|
||||||
.proxy(Helper.getProxy(getApplication().getApplicationContext()))
|
.proxy(Helper.getProxy(context.getApplicationContext()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private MastodonStatusesService init(@NonNull String instance) {
|
private static MastodonStatusesService init(Context context, @NonNull String instance) {
|
||||||
Retrofit retrofit = new Retrofit.Builder()
|
Retrofit retrofit = new Retrofit.Builder()
|
||||||
.baseUrl("https://" + instance + "/api/v1/")
|
.baseUrl("https://" + instance + "/api/v1/")
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
.client(getOkHttpClient())
|
.client(getOkHttpClient(context))
|
||||||
.build();
|
.build();
|
||||||
return retrofit.create(MastodonStatusesService.class);
|
return retrofit.create(MastodonStatusesService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
static void publishMessage(Context context, DataPost dataPost) {
|
||||||
protected void onHandleIntent(@Nullable Intent intent) {
|
long totalMediaSize;
|
||||||
StatusDraft statusDraft = null;
|
long totalBitRead;
|
||||||
String token = null, instance = null;
|
MastodonStatusesService mastodonStatusesService = init(context, dataPost.instance);
|
||||||
String scheduledDate = null;
|
|
||||||
if (intent != null && intent.getExtras() != null) {
|
|
||||||
Bundle b = intent.getExtras();
|
|
||||||
statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT);
|
|
||||||
token = b.getString(Helper.ARG_TOKEN);
|
|
||||||
instance = b.getString(Helper.ARG_INSTANCE);
|
|
||||||
scheduledDate = b.getString(Helper.ARG_SCHEDULED_DATE);
|
|
||||||
}
|
|
||||||
//Should not be null, but a simple security
|
|
||||||
if (token == null) {
|
|
||||||
token = BaseMainActivity.currentToken;
|
|
||||||
}
|
|
||||||
if (instance == null) {
|
|
||||||
instance = BaseMainActivity.currentInstance;
|
|
||||||
}
|
|
||||||
MastodonStatusesService mastodonStatusesService = init(instance);
|
|
||||||
boolean error = false;
|
boolean error = false;
|
||||||
Status firstSendMessage = null;
|
Status firstSendMessage = null;
|
||||||
if (statusDraft != null && statusDraft.statusDraftList != null && statusDraft.statusDraftList.size() > 0) {
|
if (dataPost.statusDraft != null && dataPost.statusDraft.statusDraftList != null && dataPost.statusDraft.statusDraftList.size() > 0) {
|
||||||
//If state is null, it is created (typically when submitting the status the first time)
|
//If state is null, it is created (typically when submitting the status the first time)
|
||||||
if (statusDraft.state == null) {
|
if (dataPost.statusDraft.state == null) {
|
||||||
statusDraft.state = new PostState();
|
dataPost.statusDraft.state = new PostState();
|
||||||
statusDraft.state.posts = new ArrayList<>();
|
dataPost.statusDraft.state.posts = new ArrayList<>();
|
||||||
statusDraft.state.number_of_posts = statusDraft.statusDraftList.size();
|
dataPost.statusDraft.state.number_of_posts = dataPost.statusDraft.statusDraftList.size();
|
||||||
for (Status status : statusDraft.statusDraftList) {
|
for (Status status : dataPost.statusDraft.statusDraftList) {
|
||||||
PostState.Post post = new PostState.Post();
|
PostState.Post post = new PostState.Post();
|
||||||
post.number_of_media = status.media_attachments != null ? status.media_attachments.size() : 0;
|
post.number_of_media = status.media_attachments != null ? status.media_attachments.size() : 0;
|
||||||
statusDraft.state.posts.add(post);
|
dataPost.statusDraft.state.posts.add(post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Check if previous messages in thread have already been published (ie: when resending after a fail)
|
//Check if previous messages in thread have already been published (ie: when resending after a fail)
|
||||||
int startingPosition = 0;
|
int startingPosition = 0;
|
||||||
for (PostState.Post post : statusDraft.state.posts) {
|
for (PostState.Post post : dataPost.statusDraft.state.posts) {
|
||||||
if (post.id == null) {
|
if (post.id == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
startingPosition++;
|
startingPosition++;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Status> statuses = statusDraft.statusDraftList;
|
List<Status> statuses = dataPost.statusDraft.statusDraftList;
|
||||||
String in_reply_to_status = null;
|
String in_reply_to_status = null;
|
||||||
if (statusDraft.statusReplyList != null && statusDraft.statusReplyList.size() > 0) {
|
if (dataPost.statusDraft.statusReplyList != null && dataPost.statusDraft.statusReplyList.size() > 0) {
|
||||||
in_reply_to_status = statusDraft.statusReplyList.get(statusDraft.statusReplyList.size() - 1).id;
|
in_reply_to_status = dataPost.statusDraft.statusReplyList.get(dataPost.statusDraft.statusReplyList.size() - 1).id;
|
||||||
}
|
}
|
||||||
totalMediaSize = 0;
|
totalMediaSize = 0;
|
||||||
totalBitRead = 0;
|
totalBitRead = 0;
|
||||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(PostMessageService.this);
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
boolean watermark = sharedPreferences.getBoolean(getString(R.string.SET_WATERMARK), false);
|
boolean watermark = sharedPreferences.getBoolean(context.getString(R.string.SET_WATERMARK), false);
|
||||||
String watermarkText = sharedPreferences.getString(getString(R.string.SET_WATERMARK_TEXT) + MainActivity.currentUserID + MainActivity.currentInstance, null);
|
String watermarkText = sharedPreferences.getString(context.getString(R.string.SET_WATERMARK_TEXT) + MainActivity.currentUserID + MainActivity.currentInstance, null);
|
||||||
for (int i = startingPosition; i < statuses.size(); i++) {
|
for (int i = startingPosition; i < statuses.size(); i++) {
|
||||||
if (statuses.get(i).media_attachments != null && statuses.get(i).media_attachments.size() > 0) {
|
if (statuses.get(i).media_attachments != null && statuses.get(i).media_attachments.size() > 0) {
|
||||||
for (Attachment attachment : statuses.get(i).media_attachments) {
|
for (Attachment attachment : statuses.get(i).media_attachments) {
|
||||||
|
@ -183,20 +163,20 @@ public class PostMessageService extends IntentService {
|
||||||
}
|
}
|
||||||
if (watermarkText == null) {
|
if (watermarkText == null) {
|
||||||
try {
|
try {
|
||||||
Account account = new Account(PostMessageService.this).getAccountByToken(token);
|
Account account = new Account(context).getAccountByToken(dataPost.token);
|
||||||
watermarkText = account.mastodon_account.username + "@" + account.instance;
|
watermarkText = account.mastodon_account.username + "@" + account.instance;
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
messageToSend = statuses.size() - startingPosition;
|
dataPost.messageToSend = statuses.size() - startingPosition;
|
||||||
messageSent = 0;
|
dataPost.messageSent = 0;
|
||||||
for (int i = startingPosition; i < statuses.size(); i++) {
|
for (int i = startingPosition; i < statuses.size(); i++) {
|
||||||
if (notificationBuilder != null) {
|
if (dataPost.notificationBuilder != null) {
|
||||||
notificationBuilder.setProgress(100, messageSent * 100 / messageToSend, true);
|
dataPost.notificationBuilder.setProgress(100, dataPost.messageSent * 100 / dataPost.messageToSend, true);
|
||||||
notificationBuilder.setContentText(getString(R.string.post_message_text, messageSent, messageToSend));
|
dataPost.notificationBuilder.setContentText(context.getString(R.string.post_message_text, dataPost.messageSent, dataPost.messageToSend));
|
||||||
notificationManager.notify(NOTIFICATION_INT_CHANNEL_ID, notificationBuilder.build());
|
dataPost.notificationManager.notify(NOTIFICATION_INT_CHANNEL_ID, dataPost.notificationBuilder.build());
|
||||||
}
|
}
|
||||||
//post media first
|
//post media first
|
||||||
List<String> attachmentIds = null;
|
List<String> attachmentIds = null;
|
||||||
|
@ -208,11 +188,11 @@ public class PostMessageService extends IntentService {
|
||||||
} else {
|
} else {
|
||||||
MultipartBody.Part fileMultipartBody;
|
MultipartBody.Part fileMultipartBody;
|
||||||
if (watermark && attachment.mimeType != null && attachment.mimeType.contains("image")) {
|
if (watermark && attachment.mimeType != null && attachment.mimeType.contains("image")) {
|
||||||
fileMultipartBody = Helper.getMultipartBodyWithWM(PostMessageService.this, watermarkText, "file", attachment);
|
fileMultipartBody = Helper.getMultipartBodyWithWM(context, watermarkText, "file", attachment);
|
||||||
} else {
|
} else {
|
||||||
fileMultipartBody = Helper.getMultipartBody("file", attachment);
|
fileMultipartBody = Helper.getMultipartBody("file", attachment);
|
||||||
}
|
}
|
||||||
Call<Attachment> attachmentCall = mastodonStatusesService.postMedia(token, fileMultipartBody, null, attachment.description, null);
|
Call<Attachment> attachmentCall = mastodonStatusesService.postMedia(dataPost.token, fileMultipartBody, null, attachment.description, null);
|
||||||
|
|
||||||
if (attachmentCall != null) {
|
if (attachmentCall != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -246,8 +226,8 @@ public class PostMessageService extends IntentService {
|
||||||
poll_hide_totals = false;
|
poll_hide_totals = false;
|
||||||
}
|
}
|
||||||
Call<Status> statusCall;
|
Call<Status> statusCall;
|
||||||
if (scheduledDate == null) {
|
if (dataPost.scheduledDate == null) {
|
||||||
statusCall = mastodonStatusesService.createStatus(null, token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
||||||
poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoiler_text, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language);
|
poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoiler_text, statuses.get(i).visibility.toLowerCase(), statuses.get(i).language);
|
||||||
try {
|
try {
|
||||||
Response<Status> statusResponse = statusCall.execute();
|
Response<Status> statusResponse = statusCall.execute();
|
||||||
|
@ -255,28 +235,30 @@ public class PostMessageService extends IntentService {
|
||||||
if (statusResponse.isSuccessful()) {
|
if (statusResponse.isSuccessful()) {
|
||||||
Status statusReply = statusResponse.body();
|
Status statusReply = statusResponse.body();
|
||||||
if (statusReply != null) {
|
if (statusReply != null) {
|
||||||
StatusAdapter.sendAction(this, Helper.ARG_STATUS_POSTED, statusReply, null);
|
StatusAdapter.sendAction(context, Helper.ARG_STATUS_POSTED, statusReply, null);
|
||||||
}
|
}
|
||||||
if (firstSendMessage == null && statusReply != null) {
|
if (firstSendMessage == null && statusReply != null) {
|
||||||
firstSendMessage = statusReply;
|
firstSendMessage = statusReply;
|
||||||
}
|
}
|
||||||
if (statusReply != null) {
|
if (statusReply != null) {
|
||||||
in_reply_to_status = statusReply.id;
|
in_reply_to_status = statusReply.id;
|
||||||
statusDraft.state.posts_successfully_sent = i;
|
dataPost.statusDraft.state.posts_successfully_sent = i;
|
||||||
statusDraft.state.posts.get(i).id = statusReply.id;
|
dataPost.statusDraft.state.posts.get(i).id = statusReply.id;
|
||||||
statusDraft.state.posts.get(i).in_reply_to_id = statusReply.in_reply_to_id;
|
dataPost.statusDraft.state.posts.get(i).in_reply_to_id = statusReply.in_reply_to_id;
|
||||||
try {
|
try {
|
||||||
new StatusDraft(getApplicationContext()).updatePostState(statusDraft);
|
new StatusDraft(context.getApplicationContext()).updatePostState(dataPost.statusDraft);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (!error && i >= statusDraft.statusDraftList.size()) {
|
if (!error && i >= dataPost.statusDraft.statusDraftList.size()) {
|
||||||
try {
|
try {
|
||||||
new StatusDraft(PostMessageService.this).removeDraft(statusDraft);
|
new StatusDraft(context).removeDraft(dataPost.statusDraft);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
stopSelf();
|
if (dataPost.service != null) {
|
||||||
|
dataPost.service.stopSelf();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,8 +267,8 @@ public class PostMessageService extends IntentService {
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Call<ScheduledStatus> scheduledStatusCall = mastodonStatusesService.createScheduledStatus(null, token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
Call<ScheduledStatus> scheduledStatusCall = mastodonStatusesService.createScheduledStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in,
|
||||||
poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoiler_text, statuses.get(i).visibility.toLowerCase(), scheduledDate, statuses.get(i).language);
|
poll_multiple, poll_hide_totals, in_reply_to_status, statuses.get(i).sensitive, statuses.get(i).spoiler_text, statuses.get(i).visibility.toLowerCase(), dataPost.scheduledDate, statuses.get(i).language);
|
||||||
try {
|
try {
|
||||||
Response<ScheduledStatus> statusResponse = scheduledStatusCall.execute();
|
Response<ScheduledStatus> statusResponse = scheduledStatusCall.execute();
|
||||||
|
|
||||||
|
@ -294,21 +276,23 @@ public class PostMessageService extends IntentService {
|
||||||
ScheduledStatus statusReply = statusResponse.body();
|
ScheduledStatus statusReply = statusResponse.body();
|
||||||
if (statusReply != null) {
|
if (statusReply != null) {
|
||||||
in_reply_to_status = statusReply.id;
|
in_reply_to_status = statusReply.id;
|
||||||
statusDraft.state.posts_successfully_sent = i;
|
dataPost.statusDraft.state.posts_successfully_sent = i;
|
||||||
statusDraft.state.posts.get(i).id = statusReply.id;
|
dataPost.statusDraft.state.posts.get(i).id = statusReply.id;
|
||||||
statusDraft.state.posts.get(i).in_reply_to_id = statusReply.params.in_reply_to_id;
|
dataPost.statusDraft.state.posts.get(i).in_reply_to_id = statusReply.params.in_reply_to_id;
|
||||||
try {
|
try {
|
||||||
new StatusDraft(getApplicationContext()).updatePostState(statusDraft);
|
new StatusDraft(context.getApplicationContext()).updatePostState(dataPost.statusDraft);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (!error && i >= statusDraft.statusDraftList.size()) {
|
if (!error && i >= dataPost.statusDraft.statusDraftList.size()) {
|
||||||
try {
|
try {
|
||||||
new StatusDraft(PostMessageService.this).removeDraft(statusDraft);
|
new StatusDraft(context).removeDraft(dataPost.statusDraft);
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
stopSelf();
|
if (dataPost.service != null) {
|
||||||
|
dataPost.service.stopSelf();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,22 +301,63 @@ public class PostMessageService extends IntentService {
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messageSent++;
|
dataPost.messageSent++;
|
||||||
if (messageSent > messageToSend) {
|
if (dataPost.messageSent > dataPost.messageToSend) {
|
||||||
messageSent = messageToSend;
|
dataPost.messageSent = dataPost.messageToSend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scheduledDate == null && token != null && firstSendMessage != null) {
|
if (dataPost.scheduledDate == null && dataPost.token != null && firstSendMessage != null) {
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.putBoolean(Helper.RECEIVE_NEW_MESSAGE, true);
|
b.putBoolean(Helper.RECEIVE_NEW_MESSAGE, true);
|
||||||
Intent intentBD = new Intent(Helper.BROADCAST_DATA);
|
Intent intentBD = new Intent(Helper.BROADCAST_DATA);
|
||||||
b.putSerializable(Helper.RECEIVE_STATUS_ACTION, firstSendMessage);
|
b.putSerializable(Helper.RECEIVE_STATUS_ACTION, firstSendMessage);
|
||||||
intentBD.putExtras(b);
|
intentBD.putExtras(b);
|
||||||
LocalBroadcastManager.getInstance(PostMessageService.this).sendBroadcast(intentBD);
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBD);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onHandleIntent(@Nullable Intent intent) {
|
||||||
|
StatusDraft statusDraft = null;
|
||||||
|
String token = null, instance = null;
|
||||||
|
String scheduledDate = null;
|
||||||
|
if (intent != null && intent.getExtras() != null) {
|
||||||
|
Bundle b = intent.getExtras();
|
||||||
|
statusDraft = (StatusDraft) b.getSerializable(Helper.ARG_STATUS_DRAFT);
|
||||||
|
token = b.getString(Helper.ARG_TOKEN);
|
||||||
|
instance = b.getString(Helper.ARG_INSTANCE);
|
||||||
|
scheduledDate = b.getString(Helper.ARG_SCHEDULED_DATE);
|
||||||
|
}
|
||||||
|
//Should not be null, but a simple security
|
||||||
|
if (token == null) {
|
||||||
|
token = BaseMainActivity.currentToken;
|
||||||
|
}
|
||||||
|
if (instance == null) {
|
||||||
|
instance = BaseMainActivity.currentInstance;
|
||||||
|
}
|
||||||
|
DataPost dataPost = new DataPost();
|
||||||
|
dataPost.instance = instance;
|
||||||
|
dataPost.token = token;
|
||||||
|
dataPost.statusDraft = statusDraft;
|
||||||
|
dataPost.scheduledDate = scheduledDate;
|
||||||
|
dataPost.notificationBuilder = notificationBuilder;
|
||||||
|
dataPost.notificationManager = notificationManager;
|
||||||
|
publishMessage(PostMessageService.this, dataPost);
|
||||||
notificationManager.cancel(NOTIFICATION_INT_CHANNEL_ID);
|
notificationManager.cancel(NOTIFICATION_INT_CHANNEL_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class DataPost {
|
||||||
|
String instance;
|
||||||
|
String token;
|
||||||
|
StatusDraft statusDraft;
|
||||||
|
int messageToSend;
|
||||||
|
int messageSent;
|
||||||
|
NotificationCompat.Builder notificationBuilder;
|
||||||
|
String scheduledDate;
|
||||||
|
NotificationManager notificationManager;
|
||||||
|
IntentService service;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package app.fedilab.android.services;
|
||||||
|
/* Copyright 2022 Thomas Schneider
|
||||||
|
*
|
||||||
|
* This file is a part of Fedilab
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
|
* Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import static app.fedilab.android.services.PostMessageService.publishMessage;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import app.fedilab.android.client.entities.StatusDraft;
|
||||||
|
|
||||||
|
public class ThreadMessageService {
|
||||||
|
|
||||||
|
public ThreadMessageService(Context context, String instance, String token, StatusDraft statusDraft, String scheduledDate) {
|
||||||
|
PostMessageService.DataPost dataPost = new PostMessageService.DataPost();
|
||||||
|
dataPost.instance = instance;
|
||||||
|
dataPost.token = token;
|
||||||
|
dataPost.scheduledDate = scheduledDate;
|
||||||
|
dataPost.statusDraft = statusDraft;
|
||||||
|
publishMessage(context, dataPost);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue