mirror of
https://github.com/Docile-Alligator/Infinity-For-Reddit.git
synced 2026-03-04 06:49:51 +00:00
Continue migrating SubmitPostService to JobService. Estimate network bytes.
This commit is contained in:
@ -619,10 +619,12 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee
|
||||
binding.postTitleEditTextPostGalleryActivity.getText().toString(),
|
||||
binding.postContentEditTextPostGalleryActivity.getText().toString(), isSpoiler, isNSFW,
|
||||
binding.receivePostReplyNotificationsSwitchMaterialPostGalleryActivity.isChecked(), flair, items);
|
||||
extras.putString(SubmitPostService.EXTRA_REDDIT_GALLERY_PAYLOAD, new Gson().toJson(payload));
|
||||
|
||||
String payloadJSON = new Gson().toJson(payload);
|
||||
extras.putString(SubmitPostService.EXTRA_REDDIT_GALLERY_PAYLOAD, payloadJSON);
|
||||
|
||||
// TODO: jobId and uploadBytes
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, 1, 100, extras);
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, payloadJSON.length() * 2L, extras);
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
|
||||
return true;
|
||||
|
||||
@ -553,12 +553,21 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
|
||||
ContextCompat.startForegroundService(this, intent);*/
|
||||
|
||||
int contentEstimatedBytes = 0;
|
||||
PersistableBundle extras = new PersistableBundle();
|
||||
//TODO estimate image size
|
||||
extras.putString(SubmitPostService.EXTRA_MEDIA_URI, imageUri.toString());
|
||||
extras.putString(SubmitPostService.EXTRA_ACCOUNT, selectedAccount.getJSONModel());
|
||||
extras.putString(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, binding.postTitleEditTextPostImageActivity.getText().toString());
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, binding.postContentEditTextPostImageActivity.getText().toString());
|
||||
|
||||
String title = binding.postTitleEditTextPostImageActivity.getText().toString();
|
||||
contentEstimatedBytes += title.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, title);
|
||||
|
||||
String content = binding.postContentEditTextPostImageActivity.getText().toString();
|
||||
contentEstimatedBytes += content.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, content);
|
||||
|
||||
if (flair != null) {
|
||||
extras.putString(SubmitPostService.EXTRA_FLAIR, flair.getJSONModel());
|
||||
}
|
||||
@ -573,7 +582,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF
|
||||
}
|
||||
|
||||
// TODO: jobId and uploadBytes
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, 1, 100, extras);
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, contentEstimatedBytes, extras);
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
|
||||
return true;
|
||||
|
||||
@ -543,12 +543,23 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
|
||||
ContextCompat.startForegroundService(this, intent);*/
|
||||
|
||||
int contentEstimatedBytes = 0;
|
||||
PersistableBundle extras = new PersistableBundle();
|
||||
extras.putString(SubmitPostService.EXTRA_ACCOUNT, selectedAccount.getJSONModel());
|
||||
extras.putString(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, binding.postTitleEditTextPostLinkActivity.getText().toString());
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, binding.postContentEditTextPostLinkActivity.getText().toString());
|
||||
extras.putString(SubmitPostService.EXTRA_URL, binding.postLinkEditTextPostLinkActivity.getText().toString());
|
||||
|
||||
String title = binding.postTitleEditTextPostLinkActivity.getText().toString();
|
||||
contentEstimatedBytes += title.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, title);
|
||||
|
||||
String content = binding.postContentEditTextPostLinkActivity.getText().toString();
|
||||
contentEstimatedBytes += content.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, content);
|
||||
|
||||
String link = binding.postLinkEditTextPostLinkActivity.getText().toString();
|
||||
contentEstimatedBytes += link.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_URL, link);
|
||||
|
||||
extras.putString(SubmitPostService.EXTRA_KIND, APIUtils.KIND_LINK);
|
||||
if (flair != null) {
|
||||
extras.putString(SubmitPostService.EXTRA_FLAIR, flair.getJSONModel());
|
||||
@ -559,7 +570,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
extras.putInt(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
|
||||
|
||||
// TODO: jobId and uploadBytes
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, 1, 100, extras);
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, contentEstimatedBytes, extras);
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
|
||||
return true;
|
||||
|
||||
@ -671,7 +671,8 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
try {
|
||||
payload = new PollPayload(subredditName, binding.postTitleEditTextPostPollActivity.getText().toString(),
|
||||
optionList.toArray(new String[0]), (int) binding.votingLengthSliderPostPollActivity.getValue(), isNSFW, isSpoiler, flair,
|
||||
new RichTextJSONConverter().constructRichTextJSON(this, binding.postContentEditTextPostPollActivity.getText().toString(), uploadedImages),
|
||||
new RichTextJSONConverter().constructRichTextJSON(this,
|
||||
binding.postContentEditTextPostPollActivity.getText().toString(), uploadedImages),
|
||||
null, binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.isChecked(),
|
||||
subredditIsUser ? "profile" : "subreddit");
|
||||
} catch (JSONException e) {
|
||||
@ -685,10 +686,11 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.isChecked(),
|
||||
subredditIsUser ? "profile" : "subreddit");
|
||||
}
|
||||
extras.putString(SubmitPostService.EXTRA_POLL_PAYLOAD, new Gson().toJson(payload));
|
||||
String payloadJSON = new Gson().toJson(payload);
|
||||
extras.putString(SubmitPostService.EXTRA_POLL_PAYLOAD, payloadJSON);
|
||||
|
||||
// TODO: jobId and uploadBytes
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, 1, 100, extras);
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, payloadJSON.length() * 2L, extras);
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
}
|
||||
|
||||
|
||||
@ -535,14 +535,24 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
|
||||
ContextCompat.startForegroundService(this, intent);*/
|
||||
|
||||
int contentEstimatedBytes = 0;
|
||||
PersistableBundle extras = new PersistableBundle();
|
||||
extras.putString(SubmitPostService.EXTRA_ACCOUNT, selectedAccount.getJSONModel());
|
||||
extras.putString(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, binding.postTitleEditTextPostTextActivity.getText().toString());
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, binding.postTextContentEditTextPostTextActivity.getText().toString());
|
||||
|
||||
String title = binding.postTitleEditTextPostTextActivity.getText().toString();
|
||||
contentEstimatedBytes += title.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, title);
|
||||
|
||||
String content = binding.postTextContentEditTextPostTextActivity.getText().toString();
|
||||
contentEstimatedBytes += content.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, content);
|
||||
|
||||
if (!uploadedImages.isEmpty()) {
|
||||
extras.putInt(SubmitPostService.EXTRA_IS_RICHTEXT_JSON, 1);
|
||||
extras.putString(SubmitPostService.EXTRA_UPLOADED_IMAGES, UploadedImage.getArrayListJSONModel(uploadedImages));
|
||||
String uploadedImagesJSON = UploadedImage.getArrayListJSONModel(uploadedImages);
|
||||
contentEstimatedBytes += uploadedImagesJSON.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_UPLOADED_IMAGES, uploadedImagesJSON);
|
||||
}
|
||||
|
||||
extras.putString(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
|
||||
@ -555,7 +565,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
|
||||
extras.putInt(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
|
||||
|
||||
// TODO: jobId and uploadBytes
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, 1, 100, extras);
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, contentEstimatedBytes, extras);
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,6 @@ import android.widget.Toast;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
@ -570,12 +569,21 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
|
||||
ContextCompat.startForegroundService(this, intent);*/
|
||||
|
||||
int contentEstimatedBytes = 0;
|
||||
PersistableBundle extras = new PersistableBundle();
|
||||
//TODO estimate video size
|
||||
extras.putString(SubmitPostService.EXTRA_MEDIA_URI, videoUri.toString());
|
||||
extras.putString(SubmitPostService.EXTRA_ACCOUNT, selectedAccount.getJSONModel());
|
||||
extras.putString(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, binding.postTitleEditTextPostVideoActivity.getText().toString());
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, binding.postContentEditTextPostVideoActivity.getText().toString());
|
||||
|
||||
String title = binding.postTitleEditTextPostVideoActivity.getText().toString();
|
||||
contentEstimatedBytes += title.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_TITLE, title);
|
||||
|
||||
String content = binding.postContentEditTextPostVideoActivity.getText().toString();
|
||||
contentEstimatedBytes += content.length() * 2;
|
||||
extras.putString(SubmitPostService.EXTRA_CONTENT, content);
|
||||
|
||||
if (flair != null) {
|
||||
extras.putString(SubmitPostService.EXTRA_FLAIR, flair.getJSONModel());
|
||||
}
|
||||
@ -585,7 +593,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF
|
||||
extras.putInt(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_VIDEO);
|
||||
|
||||
// TODO: jobId and uploadBytes
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, 1, 100, extras);
|
||||
JobInfo jobInfo = SubmitPostService.constructJobInfo(this, contentEstimatedBytes, extras);
|
||||
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
|
||||
|
||||
return true;
|
||||
|
||||
@ -90,6 +90,8 @@ public class SubmitPostService extends JobService {
|
||||
public static final int EXTRA_POST_TYPE_GALLERY = 3;
|
||||
public static final int EXTRA_POST_TYPE_POLL = 4;
|
||||
public static final int EXTRA_POST_TYPE_CROSSPOST = 5;
|
||||
private static int JOB_ID = 1000;
|
||||
|
||||
@Inject
|
||||
@Named("no_oauth")
|
||||
Retrofit mRetrofit;
|
||||
@ -116,16 +118,16 @@ public class SubmitPostService extends JobService {
|
||||
public SubmitPostService() {
|
||||
}
|
||||
|
||||
public static JobInfo constructJobInfo(Context context, int jobId, long uploadBytes, PersistableBundle extras) {
|
||||
public static JobInfo constructJobInfo(Context context, long contentEstimatedBytes, PersistableBundle extras) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
return new JobInfo.Builder(jobId, new ComponentName(context, SubmitPostService.class))
|
||||
return new JobInfo.Builder(JOB_ID++, new ComponentName(context, SubmitPostService.class))
|
||||
.setUserInitiated(true)
|
||||
.setRequiredNetwork(new NetworkRequest.Builder().build())
|
||||
.setEstimatedNetworkBytes(0, uploadBytes)
|
||||
.setEstimatedNetworkBytes(0, contentEstimatedBytes + 500)
|
||||
.setExtras(extras)
|
||||
.build();
|
||||
} else {
|
||||
return new JobInfo.Builder(jobId, new ComponentName(context, SubmitPostService.class))
|
||||
return new JobInfo.Builder(JOB_ID++, new ComponentName(context, SubmitPostService.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user