diff options
Diffstat (limited to '')
14 files changed, 88 insertions, 36 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 907caafe..b166996a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,14 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ml.docilealligator.infinityforreddit"> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission + android:name="android.permission.WRITE_EXTERNAL_STORAGE" + android:maxSdkVersion="22" /> + <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> + + <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + <application android:name=".Infinity" android:allowBackup="true" @@ -249,17 +257,9 @@ </provider> <service - android:name=".SubmitPostService" + android:name=".Service.SubmitPostService" android:enabled="true" android:exported="false" /> </application> - <uses-permission android:name="android.permission.INTERNET" /> - <uses-permission - android:name="android.permission.WRITE_EXTERNAL_STORAGE" - android:maxSdkVersion="22" /> - - <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> - - <uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </manifest>
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java index a9b138bb..b1ae72f3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java @@ -51,7 +51,7 @@ import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SubmitPostService; +import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java index 2c8f33b5..6abce5fb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java @@ -41,7 +41,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditUtils; -import ml.docilealligator.infinityforreddit.SubmitPostService; +import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java index 7c034945..216d2c3b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java @@ -41,7 +41,7 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditUtils; -import ml.docilealligator.infinityforreddit.SubmitPostService; +import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java index 68345423..f0a0aa99 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java @@ -53,7 +53,7 @@ import ml.docilealligator.infinityforreddit.Fragment.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SubmitPostService; +import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index 62d5277e..f59cfff5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -468,9 +468,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView break; case Post.TEXT_TYPE: ((DataViewHolder) holder).typeTextView.setText(R.string.text); - if (post.getSelfText() != null && !post.getSelfText().equals("")) { + if (post.getSelfTextPlainTrimmed() != null && !post.getSelfTextPlainTrimmed().equals("")) { ((DataViewHolder) holder).contentTextView.setVisibility(View.VISIBLE); - ((DataViewHolder) holder).contentTextView.setText(post.getSelfText()); + ((DataViewHolder) holder).contentTextView.setText(post.getSelfTextPlainTrimmed()); } break; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 4c10e9c2..4ca67f58 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -36,6 +36,7 @@ import ml.docilealligator.infinityforreddit.Fragment.PostFragment; import ml.docilealligator.infinityforreddit.Fragment.SubredditListingFragment; import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListingFragment; import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment; +import ml.docilealligator.infinityforreddit.Service.SubmitPostService; import ml.docilealligator.infinityforreddit.Settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragment; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java index 62322490..2c0ab119 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java @@ -14,6 +14,7 @@ public class JSONUtils { public static final String NAME_KEY = "name"; public static final String SUBREDDIT_NAME_PREFIX_KEY = "subreddit_name_prefixed"; public static final String SELFTEXT_KEY = "selftext"; + public static final String SELFTEXT_HTML_KEY = "selftext_html"; public static final String AUTHOR_KEY = "author"; public static final String LINK_AUTHOR_KEY = "link_author"; public static final String LINK_FLAIR_TEXT_KEY = "link_flair_text"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java index 4b985563..6a3b9acb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/NotificationUtils.java @@ -7,11 +7,11 @@ import android.content.Context; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; -class NotificationUtils { - static final String CHANNEL_SUBMIT_POST = "Submit Post"; +public class NotificationUtils { + public static final String CHANNEL_SUBMIT_POST = "Submit Post"; static final String CHANNEL_ID_NEW_MESSAGES = "new_messages"; static final String CHANNEL_NEW_MESSAGES = "New Messages"; - static final int SUBMIT_POST_SERVICE_NOTIFICATION_ID = 10000; + public static final int SUBMIT_POST_SERVICE_NOTIFICATION_ID = 10000; private static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0; private static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index 9ab9b097..ef79dc90 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -116,6 +116,16 @@ public class ParsePost { post.setSelfText(""); } else { post.setSelfText(Utils.addSubredditAndUserLink(data.getString(JSONUtils.SELFTEXT_KEY).trim())); + if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { + post.setSelfTextPlainTrimmed(""); + } else { + String selfTextPlain = Utils.trimTrailingWhitespace( + Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY))).toString(); + if (selfTextPlain.length() > 150) { + selfTextPlain = selfTextPlain.substring(150); + } + post.setSelfTextPlainTrimmed(selfTextPlain); + } } } else { //No preview link post @@ -202,6 +212,16 @@ public class ParsePost { post.setSelfText(""); } else { post.setSelfText(Utils.addSubredditAndUserLink(data.getString(JSONUtils.SELFTEXT_KEY).trim())); + if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { + post.setSelfTextPlainTrimmed(""); + } else { + String selfTextPlain = Utils.trimTrailingWhitespace( + Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY))).toString(); + if (selfTextPlain.length() > 150) { + selfTextPlain = selfTextPlain.substring(150); + } + post.setSelfTextPlainTrimmed(selfTextPlain); + } } } else { //Link post diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 2aee9455..1f2c3681 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -37,6 +37,7 @@ public class Post implements Parcelable { private String postTime; private String title; private String selfText; + private String selfTextPlainTrimmed; private String previewUrl; private String url; private String videoUrl; @@ -162,6 +163,7 @@ public class Post implements Parcelable { postTime = in.readString(); title = in.readString(); selfText = in.readString(); + selfTextPlainTrimmed = in.readString(); previewUrl = in.readString(); url = in.readString(); videoUrl = in.readString(); @@ -245,6 +247,14 @@ public class Post implements Parcelable { this.selfText = selfText; } + public String getSelfTextPlainTrimmed() { + return selfTextPlainTrimmed; + } + + public void setSelfTextPlainTrimmed(String selfTextPlainTrimmed) { + this.selfTextPlainTrimmed = selfTextPlainTrimmed; + } + public String getPreviewUrl() { return previewUrl; } @@ -395,6 +405,7 @@ public class Post implements Parcelable { parcel.writeString(postTime); parcel.writeString(title); parcel.writeString(selfText); + parcel.writeString(selfTextPlainTrimmed); parcel.writeString(previewUrl); parcel.writeString(url); parcel.writeString(videoUrl); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java index e065459c..2b6ad9ce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Service/SubmitPostService.java @@ -1,4 +1,4 @@ -package ml.docilealligator.infinityforreddit; +package ml.docilealligator.infinityforreddit.Service; import android.app.Notification; import android.app.NotificationChannel; @@ -33,6 +33,11 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Event.SubmitImagePostEvent; import ml.docilealligator.infinityforreddit.Event.SubmitTextOrLinkPostEvent; import ml.docilealligator.infinityforreddit.Event.SubmitVideoPostEvent; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.NotificationUtils; +import ml.docilealligator.infinityforreddit.Post; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.SubmitPost; import retrofit2.Retrofit; public class SubmitPostService extends Service { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java index d3ce5719..f5192823 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java @@ -28,19 +28,19 @@ import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; -class SubmitPost { - static void submitTextOrLinkPost(Retrofit oauthRetrofit, String accessToken, - Locale locale, String subredditName, String title, String content, - String flair, boolean isSpoiler, boolean isNSFW, String kind, - SubmitPostListener submitPostListener) { +public class SubmitPost { + public static void submitTextOrLinkPost(Retrofit oauthRetrofit, String accessToken, + Locale locale, String subredditName, String title, String content, + String flair, boolean isSpoiler, boolean isNSFW, String kind, + SubmitPostListener submitPostListener) { submitPost(oauthRetrofit, accessToken, locale, subredditName, title, content, flair, isSpoiler, isNSFW, kind, null, submitPostListener); } - static void submitImagePost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, - String accessToken, Locale locale, - String subredditName, String title, Bitmap image, String flair, - boolean isSpoiler, boolean isNSFW, SubmitPostListener submitPostListener) { + public static void submitImagePost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, + String accessToken, Locale locale, + String subredditName, String title, Bitmap image, String flair, + boolean isSpoiler, boolean isNSFW, SubmitPostListener submitPostListener) { uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image, new UploadImageListener() { @Override @@ -57,11 +57,11 @@ class SubmitPost { }); } - static void submitVideoPost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, - Retrofit uploadVideoRetrofit, String accessToken, - Locale locale, String subredditName, String title, byte[] buffer, String mimeType, - Bitmap posterBitmap, String flair, boolean isSpoiler, boolean isNSFW, - SubmitPostListener submitPostListener) { + public static void submitVideoPost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, + Retrofit uploadVideoRetrofit, String accessToken, + Locale locale, String subredditName, String title, byte[] buffer, String mimeType, + Bitmap posterBitmap, String flair, boolean isSpoiler, boolean isNSFW, + SubmitPostListener submitPostListener) { RedditAPI api = oauthRetrofit.create(RedditAPI.class); String fileType = mimeType.substring(mimeType.indexOf("/") + 1); @@ -341,7 +341,7 @@ class SubmitPost { } } - interface SubmitPostListener { + public interface SubmitPostListener { void submitSuccessful(Post post); void submitFailed(@Nullable String errorMessage); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils.java index 3e3d4e54..cebff4ea 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils.java @@ -2,7 +2,21 @@ package ml.docilealligator.infinityforreddit; public class Utils { public static String addSubredditAndUserLink(String markdown) { - return markdown.replaceAll("\n", " ") - .replaceAll("((?<=[\\s])|^)/{0,1}[ru]/\\w+/{0,1}", "[$0]($0)"); + return markdown.replaceAll("((?<=[\\s])|^)/{0,1}[rRuU]/\\w+/{0,1}", "[$0]($0)"); + } + + public static CharSequence trimTrailingWhitespace(CharSequence source) { + + if(source == null) + return ""; + + int i = source.length(); + + // loop back to the first non-whitespace character + do { + i--; + } while (i >= 0 && Character.isWhitespace(source.charAt(i))); + + return source.subSequence(0, i+1); } } |