diff --git a/app/build.gradle b/app/build.gradle index 65bfd3b2..546db31d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { minSdkVersion 19 targetSdkVersion 25 versionCode 4 - versionName "0.2" + versionName "0.4" archivesBaseName = "thmmyapp-v$versionName" } buildTypes { diff --git a/app/src/main/assets/fonts/fontawesome-webfont.ttf b/app/src/main/assets/fonts/fontawesome-webfont.ttf new file mode 100644 index 00000000..35acda2f Binary files /dev/null and b/app/src/main/assets/fonts/fontawesome-webfont.ttf differ diff --git a/app/src/main/assets/style.css b/app/src/main/assets/style.css index cb42044f..9681d64c 100644 --- a/app/src/main/assets/style.css +++ b/app/src/main/assets/style.css @@ -319,6 +319,8 @@ a img width: 100%; overflow: auto; line-height: 1.3em; + /*color: white; + background: #333333 !important;*/ } /* All the signatures used in the forum. If your forum users use Mozilla, Opera, or Safari, you might add max-height here ;). */ 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 e2a27d8b..f324913d 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 @@ -48,8 +48,8 @@ public class TopicActivity extends BaseActivity { /* --Posts-- */ private List postsList; - private static final int NO_POST_FOCUS = -1; - private int postFocus = NO_POST_FOCUS; + static final int NO_POST_FOCUS = -1; + static int postFocus = NO_POST_FOCUS; //Quote public static final ArrayList toQuoteList = new ArrayList<>(); /* --Topic's pages-- */ @@ -424,10 +424,10 @@ public class TopicActivity extends BaseActivity { //Set post focus if (postFocus != NO_POST_FOCUS) { - for (int i = 0; i < postsList.size(); ++i) { - Post currentPost = postsList.get(i); - if (currentPost.getPostIndex() == postFocus) { - //TODO + for (int i = postsList.size() - 1; i >= 0; --i) { + int currentPostIndex = postsList.get(i).getPostIndex(); + if (currentPostIndex == postFocus) { + layoutManager.scrollToPosition(i); } } } 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 938225c4..327fa266 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 @@ -1,5 +1,6 @@ package gr.thmmy.mthmmy.activities.topic; +import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; import android.content.Intent; @@ -33,10 +34,14 @@ import java.util.Objects; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.data.Post; import gr.thmmy.mthmmy.utils.CircleTransform; +import gr.thmmy.mthmmy.utils.FontManager; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.NO_POST_FOCUS; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.base_url; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.postFocus; import static gr.thmmy.mthmmy.activities.topic.TopicActivity.toQuoteList; +import static gr.thmmy.mthmmy.utils.FontManager.FONTAWESOME; class TopicAdapter extends RecyclerView.Adapter { private static final String TAG = "TopicAdapter"; @@ -44,6 +49,7 @@ class TopicAdapter extends RecyclerView.Adapter { private static int THUMBNAIL_SIZE; private final Context context; private final List postsList; + private boolean foundPostFocus = false; class MyViewHolder extends RecyclerView.ViewHolder { final CardView cardView; @@ -55,8 +61,7 @@ class TopicAdapter extends RecyclerView.Adapter { final RelativeLayout header; final LinearLayout userExtraInfo; - final TextView specialRank, rank, gender, numberOfPosts, personalText; - final LinearLayout stars_holder; + final TextView specialRank, rank, gender, numberOfPosts, personalText, stars; MyViewHolder(View view) { super(view); @@ -81,7 +86,7 @@ class TopicAdapter extends RecyclerView.Adapter { gender = (TextView) view.findViewById(R.id.gender); numberOfPosts = (TextView) view.findViewById(R.id.number_of_posts); personalText = (TextView) view.findViewById(R.id.personal_text); - stars_holder = (LinearLayout) view.findViewById(R.id.stars); + stars = (TextView) view.findViewById(R.id.stars); } /** @@ -107,6 +112,7 @@ class TopicAdapter extends RecyclerView.Adapter { return new MyViewHolder(itemView); } + @SuppressLint("SetJavaScriptEnabled") @Override public void onBindViewHolder(final MyViewHolder holder, int position) { final Post currentPost = postsList.get(position); @@ -173,54 +179,60 @@ class TopicAdapter extends RecyclerView.Adapter { //If user is not deleted then we have more to do if (!currentPost.isDeleted()) { //Set extra info - //Variables for content - String c_specialRank = currentPost.getSpecialRank(), c_rank = currentPost.getRank(), c_gender = currentPost.getGender(), c_numberOfPosts = currentPost.getNumberOfPosts(), c_personalText = currentPost.getPersonalText(), c_urlOfStars = currentPost.getUrlOfStars(); - int c_numberOfStars = currentPost.getNumberOfStars(); + //Variables with content + String c_specialRank = currentPost.getSpecialRank() + , c_rank = currentPost.getRank() + , c_gender = currentPost.getGender() + , c_numberOfPosts = currentPost.getNumberOfPosts() + , c_personalText = currentPost.getPersonalText(); + int c_numberOfStars = currentPost.getNumberOfStars() + ,c_userColor = currentPost.getUserColor(); if (!Objects.equals(c_specialRank, "") && c_specialRank != null) { holder.specialRank.setText(c_specialRank); holder.specialRank.setVisibility(View.VISIBLE); } + else + holder.specialRank.setVisibility(View.GONE); if (!Objects.equals(c_rank, "") && c_rank != null) { holder.rank.setText(c_rank); holder.rank.setVisibility(View.VISIBLE); } + else + holder.rank.setVisibility(View.GONE); if (!Objects.equals(c_gender, "") && c_gender != null) { holder.gender.setText(c_gender); holder.gender.setVisibility(View.VISIBLE); } + else + holder.gender.setVisibility(View.GONE); if (!Objects.equals(c_numberOfPosts, "") && c_numberOfPosts != null) { holder.numberOfPosts.setText(c_numberOfPosts); holder.numberOfPosts.setVisibility(View.VISIBLE); } + else + holder.numberOfPosts.setVisibility(View.GONE); if (!Objects.equals(c_personalText, "") && c_personalText != null) { holder.personalText.setText("\"" + c_personalText + "\""); holder.personalText.setVisibility(View.VISIBLE); } + else + holder.personalText.setVisibility(View.GONE); - for (int i = 0; i < c_numberOfStars; ++i) { - ImageView star = new ImageView(context); - - Picasso.with(context) - .load(c_urlOfStars) - .into(star); - - //Remove spacing between stars... - //Don't know why this is happening in the first place - //TODO change layout? other solution? - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.WRAP_CONTENT, - LinearLayout.LayoutParams.WRAP_CONTENT - ); - params.setMargins((int) context.getResources().getDimension(R.dimen.stars_margin) - , 0 - , (int) context.getResources().getDimension(R.dimen.stars_margin) - , 0); - star.setLayoutParams(params); - - holder.stars_holder.addView(star, 0); - holder.stars_holder.setVisibility(View.VISIBLE); + if(c_numberOfStars != 0) { + holder.stars.setTypeface(FontManager.getTypeface(context, FONTAWESOME)); + + String aStar = context.getResources().getString(R.string.fa_icon_star); + String usersStars = ""; + for (int i = 0; i < c_numberOfStars; ++i) { + usersStars += aStar; + } + holder.stars.setText(usersStars); + holder.stars.setTextColor(c_userColor); + holder.stars.setVisibility(View.VISIBLE); } + else + holder.stars.setVisibility(View.GONE); /* --Header expand/collapse functionality-- */ @@ -256,6 +268,13 @@ class TopicAdapter extends RecyclerView.Adapter { //Also when post is clicked holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView, holder.quoteToggle)); + + if (postFocus != NO_POST_FOCUS && !foundPostFocus) { + if (currentPost.getPostIndex() == postFocus) { + holder.cardView.requestFocus(); + foundPostFocus = true; + } + } } @Override 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 5b49cf65..20bbfe57 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 @@ -1,5 +1,7 @@ package gr.thmmy.mthmmy.activities.topic; +import android.graphics.Color; + import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -26,6 +28,14 @@ class TopicParser { private static String genderAltMale; private static String genderAltFemale; + //User colors variables + private static final int USER_COLOR_BLACK = Color.parseColor("#000000"); + private static final int USER_COLOR_RED = Color.parseColor("#F44336"); + private static final int USER_COLOR_GREEN = Color.parseColor("#4CAF50"); + private static final int USER_COLOR_BLUE = Color.parseColor("#536DFE"); + private static final int USER_COLOR_PINK = Color.parseColor("#FF4081"); + private static final int USER_COLOR_YELLOW = Color.parseColor("#FFEB3B"); + @SuppressWarnings("unused") private static final String TAG = "TopicParser"; @@ -78,8 +88,8 @@ class TopicParser { for (Element item : rows) { //For every post //Variables to pass String p_userName, p_thumbnailUrl, p_subject, p_post, p_postDate, p_rank, - p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_urlOfStars; - int p_postNum, p_postIndex, p_numberOfStars; + p_specialRank, p_gender, p_personalText, p_numberOfPosts; + int p_postNum, p_postIndex, p_numberOfStars, p_userColor; boolean p_isDeleted = false; //Initialize variables @@ -88,8 +98,8 @@ class TopicParser { p_gender = ""; p_personalText = ""; p_numberOfPosts = ""; - p_urlOfStars = ""; p_numberOfStars = 0; + p_userColor = USER_COLOR_YELLOW; //Find the Username Element userName = item.select("a[title^=" + userNameSelection + "]").first(); @@ -100,6 +110,7 @@ class TopicParser { + guestSelection + "))[style^=overflow]") .first().text(); p_userName = p_userName.substring(0, p_userName.indexOf(" " + guestSelection)); + p_userColor = USER_COLOR_BLACK; } else p_userName = userName.html(); @@ -114,7 +125,7 @@ class TopicParser { p_subject = item.select("div[id^=subject_]").first().select("a").first().text(); //Find post's text - p_post = item.select("div").select(".post").first().html(); + p_post = item.select("div").select(".post").first().outerHtml(); { Elements noembedTag = item.select("div").select(".post").first().select("noembed"); @@ -193,7 +204,7 @@ class TopicParser { starsLineIndex = infoList.indexOf(line); Document starsHtml = Jsoup.parse(line); p_numberOfStars = starsHtml.select("img[alt]").size(); - p_urlOfStars = starsHtml.select("img[alt]").first().attr("abs:src"); + p_userColor = colorPicker(starsHtml.select("img[alt]").first().attr("abs:src")); } } @@ -227,12 +238,12 @@ class TopicParser { returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post , p_postIndex, p_postNum, p_postDate, p_rank , p_specialRank, p_gender, p_numberOfPosts, p_personalText - , p_urlOfStars, p_numberOfStars)); + , p_numberOfStars, p_userColor)); } else { //Deleted user //Add new post in postsList, only standard information needed returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject - , p_post, p_postIndex, p_postNum, p_postDate)); + , p_post, p_postIndex, p_postNum, p_postDate, p_userColor)); } } return returnList; @@ -288,4 +299,19 @@ class TopicParser { genderAltFemale = en_genderAltFemale; } } + private static int colorPicker(String starsUrl){ + if(starsUrl.contains("/star.gif")) + return USER_COLOR_YELLOW; + else if(starsUrl.contains("/starmod.gif")) + return USER_COLOR_GREEN; + else if(starsUrl.contains("/stargmod.gif")) + return USER_COLOR_BLUE; + else if(starsUrl.contains("/staradmin.gif")) + return USER_COLOR_RED; + else if(starsUrl.contains("/starweb.gif")) + return USER_COLOR_BLACK; + else if(starsUrl.contains("/oscar.gif")) + return USER_COLOR_PINK; + return USER_COLOR_YELLOW; + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/data/Post.java b/app/src/main/java/gr/thmmy/mthmmy/data/Post.java index ef9aab49..c4c631d0 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/data/Post.java +++ b/app/src/main/java/gr/thmmy/mthmmy/data/Post.java @@ -17,13 +17,13 @@ public class Post { private final String gender; private final String numberOfPosts; private final String personalText; - private final String urlOfStars; private int numberOfStars; + private final int userColor; public Post(String thumbnailUrl, String author, String subject, String content , int postIndex, int postNumber, String postDate, String rank , String special_rank, String gender, String numberOfPosts - , String personalText, String urlOfStars, int numberOfStars) { + , String personalText, int numberOfStars, int userColor) { this.thumbnailUrl = thumbnailUrl; this.author = author; this.subject = subject; @@ -37,12 +37,12 @@ public class Post { this.gender = gender; this.numberOfPosts = numberOfPosts; this.personalText = personalText; - this.urlOfStars = urlOfStars; this.numberOfStars = numberOfStars; + this.userColor = userColor; } public Post(String thumbnailUrl, String author, String subject, String content - , int postIndex, int postNumber, String postDate) { + , int postIndex, int postNumber, String postDate, int userColor) { this.thumbnailUrl = thumbnailUrl; this.author = author; this.subject = subject; @@ -51,12 +51,12 @@ public class Post { this.postNumber = postNumber; this.postDate = postDate; this.isDeleted = true; + this.userColor = userColor; rank = "Rank"; specialRank = "Special rank"; gender = "Gender"; numberOfPosts = "Posts: 0"; personalText = ""; - urlOfStars = ""; } //Getters @@ -106,7 +106,7 @@ public class Post { return personalText; } - public String getUrlOfStars() {return urlOfStars; } - public int getNumberOfStars() {return numberOfStars; } + + public int getUserColor() {return userColor; } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/FontManager.java b/app/src/main/java/gr/thmmy/mthmmy/utils/FontManager.java new file mode 100644 index 00000000..72286ca3 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/FontManager.java @@ -0,0 +1,14 @@ +package gr.thmmy.mthmmy.utils; + +import android.content.Context; +import android.graphics.Typeface; + +public class FontManager { + + public static final String ROOT = "fonts/", + FONTAWESOME = ROOT + "fontawesome-webfont.ttf"; + + public static Typeface getTypeface(Context context, String font) { + return Typeface.createFromAsset(context.getAssets(), font); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_topic_post_row.xml b/app/src/main/res/layout/activity_topic_post_row.xml index e9e069b1..16413efe 100644 --- a/app/src/main/res/layout/activity_topic_post_row.xml +++ b/app/src/main/res/layout/activity_topic_post_row.xml @@ -155,15 +155,14 @@ android:textSize="10sp" android:visibility="gone"/> - - + android:textSize="10sp" + android:visibility="gone"> + 16dp 8dp 44dp - -15dp 36dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c5904f0..17b2d004 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -25,6 +25,7 @@ next last Home + #%1$d