From 9db1630b5032c8f3b79fd81b698d870092517226 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Fri, 20 Apr 2018 12:38:34 +0300 Subject: [PATCH] Minor improvements Added Share button on every post Added "sent from mTHMMY" when posting Github migration changes Changed Login/Logout messages Up Gradle --- .../mthmmy/activities/LoginActivity.java | 2 +- .../activities/topic/TopicActivity.java | 4 ++-- .../mthmmy/activities/topic/TopicAdapter.java | 22 ++++++++++++++----- .../mthmmy/activities/topic/TopicParser.java | 19 +++++++++------- .../gr/thmmy/mthmmy/base/BaseActivity.java | 1 - .../main/java/gr/thmmy/mthmmy/model/Post.java | 22 ++++++++++++++++--- .../layout-v21/activity_topic_post_row.xml | 17 ++++++++++---- .../res/layout/activity_topic_post_row.xml | 17 ++++++++++---- app/src/main/res/values-w820dp/dimens.xml | 2 +- app/src/main/res/values/dimens.xml | 2 +- app/src/main/res/values/strings.xml | 3 ++- build.gradle | 2 +- 12 files changed, 80 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java index dddd0158..89a1d8f8 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/LoginActivity.java @@ -157,7 +157,7 @@ public class LoginActivity extends BaseActivity { switch (result) { case SUCCESS: //Successful login Toast.makeText(getApplicationContext(), - "Login successful!", Toast.LENGTH_LONG) + "Welcome, " + sessionManager.getUsername() + "!", Toast.LENGTH_LONG) .show(); //Go to main Intent intent = new Intent(LoginActivity.this, MainActivity.class); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index f5f2c06e..25cab734 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -855,16 +855,16 @@ public class TopicActivity extends BaseActivity { @Override protected Boolean doInBackground(String... args) { + final String sentFrommTHMMY = "\n[right][size=7pt][i]sent from [url=https://play.google.com/store/apps/details?id=gr.thmmy.mthmmy]mTHMMY[/url][/i][/size][/right]"; RequestBody postBody = new MultipartBody.Builder() .setType(MultipartBody.FORM) - .addFormDataPart("message", args[1]) + .addFormDataPart("message", args[1] + sentFrommTHMMY) .addFormDataPart("num_replies", args[2]) .addFormDataPart("seqnum", args[3]) .addFormDataPart("sc", args[4]) .addFormDataPart("subject", args[0]) .addFormDataPart("topic", args[5]) .build(); - Request post = new Request.Builder() .url("https://www.thmmy.gr/smf/index.php?action=post2") .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36") diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 8cb33275..40bb41f1 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -192,7 +192,7 @@ class TopicAdapter extends RecyclerView.Adapter { //noinspection ConstantConditions Picasso.with(context) - .load(currentPost.getThumbnailUrl()) + .load(currentPost.getThumbnailURL()) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE) .centerCrop() .error(ResourcesCompat.getDrawable(context.getResources() @@ -369,10 +369,10 @@ class TopicAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, ProfileActivity.class); Bundle extras = new Bundle(); extras.putString(BUNDLE_PROFILE_URL, currentPost.getProfileURL()); - if (currentPost.getThumbnailUrl() == null) + if (currentPost.getThumbnailURL() == null) extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, ""); else - extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, currentPost.getThumbnailUrl()); + extras.putString(BUNDLE_PROFILE_THUMBNAIL_URL, currentPost.getThumbnailURL()); extras.putString(BUNDLE_PROFILE_USERNAME, currentPost.getAuthor()); intent.putExtras(extras); intent.setFlags(FLAG_ACTIVITY_NEW_TASK); @@ -409,6 +409,16 @@ class TopicAdapter extends RecyclerView.Adapter { holder.userExtraInfo.setOnClickListener(null); } + holder.sharePostButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); + sendIntent.setType("text/plain"); + sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, currentPost.getPostURL()); + context.startActivity(Intent.createChooser(sendIntent, "Share via")); + } + }); + //noinspection PointlessBooleanExpression,ConstantConditions if (!BaseActivity.getSessionManager().isLoggedIn() || !canReply) { holder.quoteToggle.setVisibility(View.GONE); @@ -426,8 +436,7 @@ class TopicAdapter extends RecyclerView.Adapter { if (toQuoteList.contains(postsList.indexOf(currentPost))) { toQuoteList.remove(toQuoteList.indexOf(postsList.indexOf(currentPost))); } else - Timber.i("An error occurred while trying to exclude post from" + - "toQuoteList, post wasn't there!"); + Timber.i("An error occurred while trying to exclude post fromtoQuoteList, post wasn't there!"); holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); } else { toQuoteList.add(postsList.indexOf(currentPost)); @@ -505,7 +514,7 @@ class TopicAdapter extends RecyclerView.Adapter { final TextView postDate, postNum, username, subject; final ImageView thumbnail; final public WebView post; - final ImageButton quoteToggle; + final ImageButton quoteToggle, sharePostButton; final RelativeLayout header; final LinearLayout userExtraInfo; final View bodyFooterDivider; @@ -526,6 +535,7 @@ class TopicAdapter extends RecyclerView.Adapter { post = view.findViewById(R.id.post); post.setBackgroundColor(Color.argb(1, 255, 255, 255)); quoteToggle = view.findViewById(R.id.toggle_quote_button); + sharePostButton = view.findViewById(R.id.post_share_button); bodyFooterDivider = view.findViewById(R.id.body_footer_divider); postFooter = view.findViewById(R.id.post_footer); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index b8811ed7..3589f4cf 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -155,8 +155,8 @@ class TopicParser { for (Element thisRow : postRows) { //Variables for Post constructor - String p_userName, p_thumbnailUrl, p_subject, p_post, p_postDate, p_profileURL, p_rank, - p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_postLastEditDate; + String p_userName, p_thumbnailURL, p_subject, p_post, p_postDate, p_profileURL, p_rank, + p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_postLastEditDate, p_postURL; int p_postNum, p_postIndex, p_numberOfStars, p_userColor; boolean p_isDeleted = false; ArrayList p_attachedFiles; @@ -176,14 +176,17 @@ class TopicParser { //Language independent parsing //Finds thumbnail url Element thumbnailUrl = thisRow.select("img.avatar").first(); - p_thumbnailUrl = null; //In case user doesn't have an avatar + p_thumbnailURL = null; //In case user doesn't have an avatar if (thumbnailUrl != null) { - p_thumbnailUrl = thumbnailUrl.attr("abs:src"); + p_thumbnailURL = thumbnailUrl.attr("abs:src"); } //Finds subject p_subject = thisRow.select("div[id^=subject_]").first().select("a").first().text(); + //Finds post's link + p_postURL = thisRow.select("div[id^=subject_]").first().select("a").first() .attr("href"); + //Finds post's text p_post = ParseHelpers.youtubeEmbeddedFix(thisRow.select("div").select(".post").first()); @@ -410,15 +413,15 @@ class TopicParser { } } //Add new post in postsList, extended information needed - parsedPostsList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post, p_postIndex + parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post, p_postIndex , p_postNum, p_postDate, p_profileURL, p_rank, p_specialRank, p_gender , p_numberOfPosts, p_personalText, p_numberOfStars, p_userColor - , p_attachedFiles, p_postLastEditDate)); + , p_attachedFiles, p_postLastEditDate, p_postURL)); } else { //Deleted user //Add new post in postsList, only standard information needed - parsedPostsList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post, p_postIndex - , p_postNum, p_postDate, p_userColor, p_attachedFiles, p_postLastEditDate)); + parsedPostsList.add(new Post(p_thumbnailURL, p_userName, p_subject, p_post, p_postIndex + , p_postNum, p_postDate, p_userColor, p_attachedFiles, p_postLastEditDate, p_postURL)); } } return parsedPostsList; diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 56cb7419..559b297a 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -406,7 +406,6 @@ public abstract class BaseActivity extends AppCompatActivity { } protected void onPostExecute(Integer result) { - Toast.makeText(getBaseContext(), "Logged out successfully!", Toast.LENGTH_LONG).show(); updateDrawer(); if (mainActivity != null) mainActivity.updateTabs(); diff --git a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java index baf8cc20..76a335fd 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/model/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/model/Post.java @@ -28,6 +28,7 @@ public class Post { private final int userColor; private final ArrayList attachedFiles; private final String lastEdit; + private final String postURL; //Extra info private final String profileURL; @@ -59,6 +60,7 @@ public class Post { numberOfStars = 0; attachedFiles = null; lastEdit = null; + postURL = null; } /** @@ -83,12 +85,13 @@ public class Post { * @param userColor author's user color * @param attachedFiles post's attached files * @param lastEdit post's last edit date + * @param postURL post's URL */ public Post(@Nullable String thumbnailUrl, String author, String subject, String content , int postIndex, int postNumber, String postDate, String profileURl, @Nullable String rank , @Nullable String special_rank, @Nullable String gender, @Nullable String numberOfPosts , @Nullable String personalText, int numberOfStars, int userColor - , @Nullable ArrayList attachedFiles, @Nullable String lastEdit) { + , @Nullable ArrayList attachedFiles, @Nullable String lastEdit, String postURL) { if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null; else this.thumbnailUrl = thumbnailUrl; this.author = author; @@ -108,6 +111,7 @@ public class Post { this.numberOfPosts = numberOfPosts; this.personalText = personalText; this.numberOfStars = numberOfStars; + this.postURL = postURL; } /** @@ -125,10 +129,11 @@ public class Post { * @param userColor author's user color * @param attachedFiles post's attached files * @param lastEdit post's last edit date + * @param postURL post's URL */ public Post(@Nullable String thumbnailUrl, String author, String subject, String content , int postIndex, int postNumber, String postDate, int userColor - , @Nullable ArrayList attachedFiles, @Nullable String lastEdit) { + , @Nullable ArrayList attachedFiles, @Nullable String lastEdit, String postURL) { if (Objects.equals(thumbnailUrl, "")) this.thumbnailUrl = null; else this.thumbnailUrl = thumbnailUrl; this.author = author; @@ -148,6 +153,7 @@ public class Post { numberOfPosts = "Posts: 0"; personalText = ""; numberOfStars = 0; + this.postURL = postURL; } //Getters @@ -158,7 +164,7 @@ public class Post { * @return author's thumbnail url */ @Nullable - public String getThumbnailUrl() { + public String getThumbnailURL() { return thumbnailUrl; } @@ -326,4 +332,14 @@ public class Post { public String getLastEdit() { return lastEdit; } + + /** + * Gets this post's url. + * + * @return post's url + */ + @Nullable + public String getPostURL() { + return postURL; + } } diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index 7f384f10..6f00298e 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -85,18 +85,27 @@ android:maxLines="1" android:text="@string/post_subject" /> - + - + 64dp 32dp 176dp - 144dp + 144dp 64dp 40dp 24sp diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 914c6e3d..20a265af 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,7 +4,7 @@ 16dp 8dp 44dp - 36dp + 36dp 16dp 10dp 24sp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 34d43367..73a8c8e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,6 +37,7 @@ Post Thumbnail Quote button + Share button #%1$d first previous @@ -66,7 +67,7 @@ Contact Do not hesitate to contact us for any matter either by email at thmmynolife@gmail.com, or by joining our discord server at https://discord.gg/CVt3yrn. Open Source - The source code of mTHMMY can be found on GitLab (https://gitlab.com/ThmmyNoLife/mTHMMY) along with further details of how one can contribute. + The source code of mTHMMY can be found on Github (https://github.com/ThmmyNoLife/mTHMMY) along with further details of how one can contribute. You should see a funny pic! diff --git a/build.gradle b/build.gradle index a748ded8..c7eceb56 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.0' + classpath 'com.android.tools.build:gradle:3.1.1' classpath 'com.google.gms:google-services:3.1.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files