aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-07-24 15:07:03 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-07-24 15:07:03 +0000
commit549a66d997bf32550271bdcd4d8e85e17353d3da (patch)
tree826938ddef4a59fef975c5b0f6614b3a257e4be6 /app/src/main
parent40152c8376e6bcd05e59d6dac674804c8073afcb (diff)
downloadinfinity-for-reddit-549a66d997bf32550271bdcd4d8e85e17353d3da.tar
infinity-for-reddit-549a66d997bf32550271bdcd4d8e85e17353d3da.tar.gz
infinity-for-reddit-549a66d997bf32550271bdcd4d8e85e17353d3da.tar.bz2
infinity-for-reddit-549a66d997bf32550271bdcd4d8e85e17353d3da.tar.lz
infinity-for-reddit-549a66d997bf32550271bdcd4d8e85e17353d3da.tar.xz
infinity-for-reddit-549a66d997bf32550271bdcd4d8e85e17353d3da.tar.zst
infinity-for-reddit-549a66d997bf32550271bdcd4d8e85e17353d3da.zip
Modify SubmitCrosspostActivity to use SubmitPostService as a JobService. Add RECEIVER_NOT_EXPORTED in registerReceiver on Android 13+. Remove startForeground in DownloadRedditVideoService.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java33
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java5
4 files changed, 41 insertions, 12 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
index 3a603442..b6fe501a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
@@ -7,6 +7,7 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
+import android.os.Build;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.Toast;
@@ -157,9 +158,13 @@ public class Infinity extends Application implements LifecycleObserver {
mNetworkWifiStatusReceiver =
new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext()))));
- registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
-
- registerReceiver(new WallpaperChangeReceiver(mSharedPreferences), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+ registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION), RECEIVER_NOT_EXPORTED);
+ registerReceiver(new WallpaperChangeReceiver(mSharedPreferences), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED), RECEIVER_NOT_EXPORTED);
+ } else {
+ registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
+ registerReceiver(new WallpaperChangeReceiver(mSharedPreferences), new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
+ }
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java
index 1c10c2ed..6825c311 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditProfileActivity.java
@@ -239,7 +239,7 @@ public class EditProfileActivity extends BaseActivity {
extras.putInt(EditProfileService.EXTRA_POST_TYPE, EditProfileService.EXTRA_POST_TYPE_CHANGE_BANNER);
//TODO: contentEstimatedBytes
- JobInfo jobInfo = EditProfileService.constructJobInfo(this, 100, extras);
+ JobInfo jobInfo = EditProfileService.constructJobInfo(this, 500000, extras);
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
break;
}
@@ -247,7 +247,7 @@ public class EditProfileActivity extends BaseActivity {
extras.putInt(EditProfileService.EXTRA_POST_TYPE, EditProfileService.EXTRA_POST_TYPE_CHANGE_AVATAR);
//TODO: contentEstimatedBytes
- JobInfo jobInfo = EditProfileService.constructJobInfo(this, 100, extras);
+ JobInfo jobInfo = EditProfileService.constructJobInfo(this, 500000, extras);
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
break;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
index c53356ed..9ad08b40 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
@@ -1,5 +1,8 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.app.job.JobInfo;
+import android.app.job.JobScheduler;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
@@ -10,6 +13,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
+import android.os.PersistableBundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -508,7 +512,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
subredditName = binding.subredditNameTextViewSubmitCrosspostActivity.getText().toString();
}
- Intent intent = new Intent(this, SubmitPostService.class);
+ /*Intent intent = new Intent(this, SubmitPostService.class);
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
intent.putExtra(SubmitPostService.EXTRA_TITLE, binding.postTitleEditTextSubmitCrosspostActivity.getText().toString());
@@ -524,7 +528,32 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS,
binding.receivePostReplyNotificationsSwitchMaterialSubmitCrosspostActivity.isChecked());
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_CROSSPOST);
- ContextCompat.startForegroundService(this, intent);
+ ContextCompat.startForegroundService(this, intent);*/
+
+
+ PersistableBundle extras = new PersistableBundle();
+ extras.putString(SubmitPostService.EXTRA_ACCOUNT, selectedAccount.getJSONModel());
+ extras.putString(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
+ String title = binding.postTitleEditTextSubmitCrosspostActivity.getText().toString();
+ extras.putString(SubmitPostService.EXTRA_TITLE, title);
+ if (post.isCrosspost()) {
+ extras.putString(SubmitPostService.EXTRA_CONTENT, "t3_" + post.getCrosspostParentId());
+ } else {
+ extras.putString(SubmitPostService.EXTRA_CONTENT, post.getFullName());
+ }
+ extras.putString(SubmitPostService.EXTRA_KIND, APIUtils.KIND_CROSSPOST);
+ if (flair != null) {
+ extras.putString(SubmitPostService.EXTRA_FLAIR, flair.getJSONModel());
+ }
+ extras.putInt(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler ? 1 : 0);
+ extras.putInt(SubmitPostService.EXTRA_IS_NSFW, isNSFW ? 1 : 0);
+ extras.putInt(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS,
+ binding.receivePostReplyNotificationsSwitchMaterialSubmitCrosspostActivity.isChecked() ? 1 : 0);
+ extras.putInt(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_CROSSPOST);
+
+ // TODO: contentEstimatedBytes
+ JobInfo jobInfo = SubmitPostService.constructJobInfo(this, title.length() * 2L + 20000, extras);
+ ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
return true;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
index 456b4efe..6fa3e22d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
@@ -130,11 +130,6 @@ public class DownloadRedditVideoService extends JobService {
notificationManager.createNotificationChannel(serviceChannel);
int randomNotificationIdOffset = new Random().nextInt(10000);
- startForeground(
- NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID + randomNotificationIdOffset,
- createNotification(builder, fileNameWithoutExtension + ".mp4")
- );
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
setNotification(params,
NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID + randomNotificationIdOffset,