Browse Source

User's stars changed to TextView+FontAwesome. Post focus implementation.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
9b07f7e080
  1. 2
      app/build.gradle
  2. BIN
      app/src/main/assets/fonts/fontawesome-webfont.ttf
  3. 2
      app/src/main/assets/style.css
  4. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  5. 75
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  6. 40
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  7. 14
      app/src/main/java/gr/thmmy/mthmmy/data/Post.java
  8. 14
      app/src/main/java/gr/thmmy/mthmmy/utils/FontManager.java
  9. 11
      app/src/main/res/layout/activity_topic_post_row.xml
  10. 1
      app/src/main/res/values/dimens.xml
  11. 1
      app/src/main/res/values/strings.xml

2
app/build.gradle

@ -10,7 +10,7 @@ android {
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 25 targetSdkVersion 25
versionCode 4 versionCode 4
versionName "0.2" versionName "0.4"
archivesBaseName = "thmmyapp-v$versionName" archivesBaseName = "thmmyapp-v$versionName"
} }
buildTypes { buildTypes {

BIN
app/src/main/assets/fonts/fontawesome-webfont.ttf

Binary file not shown.

2
app/src/main/assets/style.css

@ -319,6 +319,8 @@ a img
width: 100%; width: 100%;
overflow: auto; overflow: auto;
line-height: 1.3em; 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 ;). */ /* All the signatures used in the forum. If your forum users use Mozilla, Opera, or Safari, you might add max-height here ;). */

12
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -48,8 +48,8 @@ public class TopicActivity extends BaseActivity {
/* --Posts-- */ /* --Posts-- */
private List<Post> postsList; private List<Post> postsList;
private static final int NO_POST_FOCUS = -1; static final int NO_POST_FOCUS = -1;
private int postFocus = NO_POST_FOCUS; static int postFocus = NO_POST_FOCUS;
//Quote //Quote
public static final ArrayList<Integer> toQuoteList = new ArrayList<>(); public static final ArrayList<Integer> toQuoteList = new ArrayList<>();
/* --Topic's pages-- */ /* --Topic's pages-- */
@ -424,10 +424,10 @@ public class TopicActivity extends BaseActivity {
//Set post focus //Set post focus
if (postFocus != NO_POST_FOCUS) { if (postFocus != NO_POST_FOCUS) {
for (int i = 0; i < postsList.size(); ++i) { for (int i = postsList.size() - 1; i >= 0; --i) {
Post currentPost = postsList.get(i); int currentPostIndex = postsList.get(i).getPostIndex();
if (currentPost.getPostIndex() == postFocus) { if (currentPostIndex == postFocus) {
//TODO layoutManager.scrollToPosition(i);
} }
} }
} }

75
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities.topic; package gr.thmmy.mthmmy.activities.topic;
import android.annotation.SuppressLint;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -33,10 +34,14 @@ import java.util.Objects;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.data.Post; import gr.thmmy.mthmmy.data.Post;
import gr.thmmy.mthmmy.utils.CircleTransform; import gr.thmmy.mthmmy.utils.CircleTransform;
import gr.thmmy.mthmmy.utils.FontManager;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; 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.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.activities.topic.TopicActivity.toQuoteList;
import static gr.thmmy.mthmmy.utils.FontManager.FONTAWESOME;
class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
private static final String TAG = "TopicAdapter"; private static final String TAG = "TopicAdapter";
@ -44,6 +49,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
private static int THUMBNAIL_SIZE; private static int THUMBNAIL_SIZE;
private final Context context; private final Context context;
private final List<Post> postsList; private final List<Post> postsList;
private boolean foundPostFocus = false;
class MyViewHolder extends RecyclerView.ViewHolder { class MyViewHolder extends RecyclerView.ViewHolder {
final CardView cardView; final CardView cardView;
@ -55,8 +61,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
final RelativeLayout header; final RelativeLayout header;
final LinearLayout userExtraInfo; final LinearLayout userExtraInfo;
final TextView specialRank, rank, gender, numberOfPosts, personalText; final TextView specialRank, rank, gender, numberOfPosts, personalText, stars;
final LinearLayout stars_holder;
MyViewHolder(View view) { MyViewHolder(View view) {
super(view); super(view);
@ -81,7 +86,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
gender = (TextView) view.findViewById(R.id.gender); gender = (TextView) view.findViewById(R.id.gender);
numberOfPosts = (TextView) view.findViewById(R.id.number_of_posts); numberOfPosts = (TextView) view.findViewById(R.id.number_of_posts);
personalText = (TextView) view.findViewById(R.id.personal_text); 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<TopicAdapter.MyViewHolder> {
return new MyViewHolder(itemView); return new MyViewHolder(itemView);
} }
@SuppressLint("SetJavaScriptEnabled")
@Override @Override
public void onBindViewHolder(final MyViewHolder holder, int position) { public void onBindViewHolder(final MyViewHolder holder, int position) {
final Post currentPost = postsList.get(position); final Post currentPost = postsList.get(position);
@ -173,54 +179,60 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
//If user is not deleted then we have more to do //If user is not deleted then we have more to do
if (!currentPost.isDeleted()) { //Set extra info if (!currentPost.isDeleted()) { //Set extra info
//Variables for content //Variables with 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(); String c_specialRank = currentPost.getSpecialRank()
int c_numberOfStars = currentPost.getNumberOfStars(); , 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) { if (!Objects.equals(c_specialRank, "") && c_specialRank != null) {
holder.specialRank.setText(c_specialRank); holder.specialRank.setText(c_specialRank);
holder.specialRank.setVisibility(View.VISIBLE); holder.specialRank.setVisibility(View.VISIBLE);
} }
else
holder.specialRank.setVisibility(View.GONE);
if (!Objects.equals(c_rank, "") && c_rank != null) { if (!Objects.equals(c_rank, "") && c_rank != null) {
holder.rank.setText(c_rank); holder.rank.setText(c_rank);
holder.rank.setVisibility(View.VISIBLE); holder.rank.setVisibility(View.VISIBLE);
} }
else
holder.rank.setVisibility(View.GONE);
if (!Objects.equals(c_gender, "") && c_gender != null) { if (!Objects.equals(c_gender, "") && c_gender != null) {
holder.gender.setText(c_gender); holder.gender.setText(c_gender);
holder.gender.setVisibility(View.VISIBLE); holder.gender.setVisibility(View.VISIBLE);
} }
else
holder.gender.setVisibility(View.GONE);
if (!Objects.equals(c_numberOfPosts, "") && c_numberOfPosts != null) { if (!Objects.equals(c_numberOfPosts, "") && c_numberOfPosts != null) {
holder.numberOfPosts.setText(c_numberOfPosts); holder.numberOfPosts.setText(c_numberOfPosts);
holder.numberOfPosts.setVisibility(View.VISIBLE); holder.numberOfPosts.setVisibility(View.VISIBLE);
} }
else
holder.numberOfPosts.setVisibility(View.GONE);
if (!Objects.equals(c_personalText, "") && c_personalText != null) { if (!Objects.equals(c_personalText, "") && c_personalText != null) {
holder.personalText.setText("\"" + c_personalText + "\""); holder.personalText.setText("\"" + c_personalText + "\"");
holder.personalText.setVisibility(View.VISIBLE); holder.personalText.setVisibility(View.VISIBLE);
} }
else
holder.personalText.setVisibility(View.GONE);
for (int i = 0; i < c_numberOfStars; ++i) { if(c_numberOfStars != 0) {
ImageView star = new ImageView(context); holder.stars.setTypeface(FontManager.getTypeface(context, FONTAWESOME));
Picasso.with(context) String aStar = context.getResources().getString(R.string.fa_icon_star);
.load(c_urlOfStars) String usersStars = "";
.into(star); for (int i = 0; i < c_numberOfStars; ++i) {
usersStars += aStar;
//Remove spacing between stars... }
//Don't know why this is happening in the first place holder.stars.setText(usersStars);
//TODO change layout? other solution? holder.stars.setTextColor(c_userColor);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( holder.stars.setVisibility(View.VISIBLE);
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);
} }
else
holder.stars.setVisibility(View.GONE);
/* --Header expand/collapse functionality-- */ /* --Header expand/collapse functionality-- */
@ -256,6 +268,13 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
//Also when post is clicked //Also when post is clicked
holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView, holder.quoteToggle)); 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 @Override

40
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java

@ -1,5 +1,7 @@
package gr.thmmy.mthmmy.activities.topic; package gr.thmmy.mthmmy.activities.topic;
import android.graphics.Color;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -26,6 +28,14 @@ class TopicParser {
private static String genderAltMale; private static String genderAltMale;
private static String genderAltFemale; 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") @SuppressWarnings("unused")
private static final String TAG = "TopicParser"; private static final String TAG = "TopicParser";
@ -78,8 +88,8 @@ class TopicParser {
for (Element item : rows) { //For every post for (Element item : rows) { //For every post
//Variables to pass //Variables to pass
String p_userName, p_thumbnailUrl, p_subject, p_post, p_postDate, p_rank, String p_userName, p_thumbnailUrl, p_subject, p_post, p_postDate, p_rank,
p_specialRank, p_gender, p_personalText, p_numberOfPosts, p_urlOfStars; p_specialRank, p_gender, p_personalText, p_numberOfPosts;
int p_postNum, p_postIndex, p_numberOfStars; int p_postNum, p_postIndex, p_numberOfStars, p_userColor;
boolean p_isDeleted = false; boolean p_isDeleted = false;
//Initialize variables //Initialize variables
@ -88,8 +98,8 @@ class TopicParser {
p_gender = ""; p_gender = "";
p_personalText = ""; p_personalText = "";
p_numberOfPosts = ""; p_numberOfPosts = "";
p_urlOfStars = "";
p_numberOfStars = 0; p_numberOfStars = 0;
p_userColor = USER_COLOR_YELLOW;
//Find the Username //Find the Username
Element userName = item.select("a[title^=" + userNameSelection + "]").first(); Element userName = item.select("a[title^=" + userNameSelection + "]").first();
@ -100,6 +110,7 @@ class TopicParser {
+ guestSelection + "))[style^=overflow]") + guestSelection + "))[style^=overflow]")
.first().text(); .first().text();
p_userName = p_userName.substring(0, p_userName.indexOf(" " + guestSelection)); p_userName = p_userName.substring(0, p_userName.indexOf(" " + guestSelection));
p_userColor = USER_COLOR_BLACK;
} else } else
p_userName = userName.html(); p_userName = userName.html();
@ -114,7 +125,7 @@ class TopicParser {
p_subject = item.select("div[id^=subject_]").first().select("a").first().text(); p_subject = item.select("div[id^=subject_]").first().select("a").first().text();
//Find post's 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"); Elements noembedTag = item.select("div").select(".post").first().select("noembed");
@ -193,7 +204,7 @@ class TopicParser {
starsLineIndex = infoList.indexOf(line); starsLineIndex = infoList.indexOf(line);
Document starsHtml = Jsoup.parse(line); Document starsHtml = Jsoup.parse(line);
p_numberOfStars = starsHtml.select("img[alt]").size(); 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 returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post
, p_postIndex, p_postNum, p_postDate, p_rank , p_postIndex, p_postNum, p_postDate, p_rank
, p_specialRank, p_gender, p_numberOfPosts, p_personalText , p_specialRank, p_gender, p_numberOfPosts, p_personalText
, p_urlOfStars, p_numberOfStars)); , p_numberOfStars, p_userColor));
} else { //Deleted user } else { //Deleted user
//Add new post in postsList, only standard information needed //Add new post in postsList, only standard information needed
returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject 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; return returnList;
@ -288,4 +299,19 @@ class TopicParser {
genderAltFemale = en_genderAltFemale; 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;
}
} }

14
app/src/main/java/gr/thmmy/mthmmy/data/Post.java

@ -17,13 +17,13 @@ public class Post {
private final String gender; private final String gender;
private final String numberOfPosts; private final String numberOfPosts;
private final String personalText; private final String personalText;
private final String urlOfStars;
private int numberOfStars; private int numberOfStars;
private final int userColor;
public Post(String thumbnailUrl, String author, String subject, String content public Post(String thumbnailUrl, String author, String subject, String content
, int postIndex, int postNumber, String postDate, String rank , int postIndex, int postNumber, String postDate, String rank
, String special_rank, String gender, String numberOfPosts , String special_rank, String gender, String numberOfPosts
, String personalText, String urlOfStars, int numberOfStars) { , String personalText, int numberOfStars, int userColor) {
this.thumbnailUrl = thumbnailUrl; this.thumbnailUrl = thumbnailUrl;
this.author = author; this.author = author;
this.subject = subject; this.subject = subject;
@ -37,12 +37,12 @@ public class Post {
this.gender = gender; this.gender = gender;
this.numberOfPosts = numberOfPosts; this.numberOfPosts = numberOfPosts;
this.personalText = personalText; this.personalText = personalText;
this.urlOfStars = urlOfStars;
this.numberOfStars = numberOfStars; this.numberOfStars = numberOfStars;
this.userColor = userColor;
} }
public Post(String thumbnailUrl, String author, String subject, String content 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.thumbnailUrl = thumbnailUrl;
this.author = author; this.author = author;
this.subject = subject; this.subject = subject;
@ -51,12 +51,12 @@ public class Post {
this.postNumber = postNumber; this.postNumber = postNumber;
this.postDate = postDate; this.postDate = postDate;
this.isDeleted = true; this.isDeleted = true;
this.userColor = userColor;
rank = "Rank"; rank = "Rank";
specialRank = "Special rank"; specialRank = "Special rank";
gender = "Gender"; gender = "Gender";
numberOfPosts = "Posts: 0"; numberOfPosts = "Posts: 0";
personalText = ""; personalText = "";
urlOfStars = "";
} }
//Getters //Getters
@ -106,7 +106,7 @@ public class Post {
return personalText; return personalText;
} }
public String getUrlOfStars() {return urlOfStars; }
public int getNumberOfStars() {return numberOfStars; } public int getNumberOfStars() {return numberOfStars; }
public int getUserColor() {return userColor; }
} }

14
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);
}
}

11
app/src/main/res/layout/activity_topic_post_row.xml

@ -155,15 +155,14 @@
android:textSize="10sp" android:textSize="10sp"
android:visibility="gone"/> android:visibility="gone"/>
<LinearLayout <TextView
android:id="@+id/stars" android:id="@+id/stars"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="12dp" android:layout_height="wrap_content"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:orientation="horizontal" android:textSize="10sp"
android:visibility="gone" android:visibility="gone">
android:weightSum="0"> </TextView>
</LinearLayout>
<TextView <TextView
android:id="@+id/gender" android:id="@+id/gender"

1
app/src/main/res/values/dimens.xml

@ -4,6 +4,5 @@
<dimen name="activity_vertical_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen> <dimen name="appbar_padding_top">8dp</dimen>
<dimen name="thumbnail_size">44dp</dimen> <dimen name="thumbnail_size">44dp</dimen>
<dimen name="stars_margin">-15dp</dimen>
<dimen name="quote_button">36dp</dimen> <dimen name="quote_button">36dp</dimen>
</resources> </resources>

1
app/src/main/res/values/strings.xml

@ -25,6 +25,7 @@
<string name="text_next">next</string> <string name="text_next">next</string>
<string name="text_last">last</string> <string name="text_last">last</string>
<string name="home">Home</string> <string name="home">Home</string>
<string name="fa_icon_star">&#xf005;</string>
<string name="user_number_of_posts">#%1$d</string> <string name="user_number_of_posts">#%1$d</string>
</resources> </resources>

Loading…
Cancel
Save