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
targetSdkVersion 25
versionCode 4
versionName "0.2"
versionName "0.4"
archivesBaseName = "thmmyapp-v$versionName"
}
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%;
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 ;). */

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

@ -48,8 +48,8 @@ public class TopicActivity extends BaseActivity {
/* --Posts-- */
private List<Post> 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<Integer> 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);
}
}
}

75
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<TopicAdapter.MyViewHolder> {
private static final String TAG = "TopicAdapter";
@ -44,6 +49,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
private static int THUMBNAIL_SIZE;
private final Context context;
private final List<Post> postsList;
private boolean foundPostFocus = false;
class MyViewHolder extends RecyclerView.ViewHolder {
final CardView cardView;
@ -55,8 +61,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
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<TopicAdapter.MyViewHolder> {
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<TopicAdapter.MyViewHolder> {
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<TopicAdapter.MyViewHolder> {
//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<TopicAdapter.MyViewHolder> {
//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

40
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;
}
}

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

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:visibility="gone"/>
<LinearLayout
<TextView
android:id="@+id/stars"
android:layout_width="wrap_content"
android:layout_height="12dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="0">
</LinearLayout>
android:textSize="10sp"
android:visibility="gone">
</TextView>
<TextView
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="appbar_padding_top">8dp</dimen>
<dimen name="thumbnail_size">44dp</dimen>
<dimen name="stars_margin">-15dp</dimen>
<dimen name="quote_button">36dp</dimen>
</resources>

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

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

Loading…
Cancel
Save