Browse Source

Post's attached files.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
656f867cdf
  1. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 27
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 26
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java
  4. 40
      app/src/main/java/gr/thmmy/mthmmy/data/Post.java
  5. 23
      app/src/main/res/layout/activity_topic_post_row.xml
  6. 1
      app/src/main/res/values/colors.xml
  7. 1
      app/src/main/res/values/strings.xml
  8. 2
      app/src/main/res/values/styles.xml

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

@ -431,6 +431,7 @@ public class TopicActivity extends BaseActivity {
} }
} }
} }
replyFAB.setEnabled(true);
} }
//--------------------------------------POPULATE UI METHOD END-------------------------------------- //--------------------------------------POPULATE UI METHOD END--------------------------------------

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

@ -11,7 +11,9 @@ import android.os.Handler;
import android.support.v4.content.res.ResourcesCompat; import android.support.v4.content.res.ResourcesCompat;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -66,6 +68,8 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
final ImageButton quoteToggle; final ImageButton quoteToggle;
final RelativeLayout header; final RelativeLayout header;
final LinearLayout userExtraInfo; final LinearLayout userExtraInfo;
final View bodyFooterDivider;
final LinearLayout postFooter;
final TextView specialRank, rank, gender, numberOfPosts, personalText, stars; final TextView specialRank, rank, gender, numberOfPosts, personalText, stars;
@ -83,6 +87,8 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
subject = (TextView) view.findViewById(R.id.subject); subject = (TextView) view.findViewById(R.id.subject);
post = (WebView) view.findViewById(R.id.post); post = (WebView) view.findViewById(R.id.post);
quoteToggle = (ImageButton) view.findViewById(R.id.toggle_quote_button); quoteToggle = (ImageButton) view.findViewById(R.id.toggle_quote_button);
bodyFooterDivider = view.findViewById(R.id.body_footer_divider);
postFooter = (LinearLayout) view.findViewById(R.id.post_footer);
//User's extra //User's extra
header = (RelativeLayout) view.findViewById(R.id.header); header = (RelativeLayout) view.findViewById(R.id.header);
@ -187,6 +193,23 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
} }
}); });
if (currentPost.getAttachedFiles().size() != 0) {
holder.bodyFooterDivider.setVisibility(View.VISIBLE);
for (String attachedFile : currentPost.getAttachedFiles()) {
TextView attached = new TextView(context);
attached.setTextSize(10f);
attached.setClickable(true);
attached.setMovementMethod(LinkMovementMethod.getInstance());
attached.setText(Html.fromHtml(attachedFile));
holder.postFooter.addView(attached);
}
} else {
holder.bodyFooterDivider.setVisibility(View.GONE);
holder.postFooter.removeAllViews();
}
//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 with content //Variables with content
@ -239,8 +262,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
if (viewProperties.get(position)[isUserExtraInfoVisibile]) { //Expanded if (viewProperties.get(position)[isUserExtraInfoVisibile]) { //Expanded
holder.userExtraInfo.setVisibility(View.VISIBLE); holder.userExtraInfo.setVisibility(View.VISIBLE);
holder.userExtraInfo.setAlpha(1.0f); holder.userExtraInfo.setAlpha(1.0f);
} } else { //Collapsed
else { //Collapsed
holder.userExtraInfo.setVisibility(View.GONE); holder.userExtraInfo.setVisibility(View.GONE);
holder.userExtraInfo.setAlpha(0.0f); holder.userExtraInfo.setAlpha(0.0f);
} }
@ -495,5 +517,4 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
} }
} }
//------------------------------------CUSTOM WEBVIEW CLIENT END------------------------------------- //------------------------------------CUSTOM WEBVIEW CLIENT END-------------------------------------
} }

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

@ -1,6 +1,7 @@
package gr.thmmy.mthmmy.activities.topic; package gr.thmmy.mthmmy.activities.topic;
import android.graphics.Color; import android.graphics.Color;
import android.util.Log;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -91,6 +92,7 @@ class TopicParser {
p_specialRank, p_gender, p_personalText, p_numberOfPosts; p_specialRank, p_gender, p_personalText, p_numberOfPosts;
int p_postNum, p_postIndex, p_numberOfStars, p_userColor; int p_postNum, p_postIndex, p_numberOfStars, p_userColor;
boolean p_isDeleted = false; boolean p_isDeleted = false;
ArrayList<String> p_attachedFiles;
//Initialize variables //Initialize variables
p_rank = "Rank"; p_rank = "Rank";
@ -100,6 +102,7 @@ class TopicParser {
p_numberOfPosts = ""; p_numberOfPosts = "";
p_numberOfStars = 0; p_numberOfStars = 0;
p_userColor = USER_COLOR_YELLOW; p_userColor = USER_COLOR_YELLOW;
p_attachedFiles = new ArrayList<>();
//Find the Username //Find the Username
Element userName = item.select("a[title^=" + userNameSelection + "]").first(); Element userName = item.select("a[title^=" + userNameSelection + "]").first();
@ -179,6 +182,23 @@ class TopicParser {
p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("msg") + 3)); p_postIndex = Integer.parseInt(tmp.substring(tmp.indexOf("msg") + 3));
} }
//Find attached file's urls, names and info, if present
Elements postAttachments = item.select("div:containsOwn(downloaded)");
if (postAttachments != null) {
for (Element attached : postAttachments) {
//Get file's url and filename
Element tmpAttachedFileUrlAndName = attached.select("a").first();
tmpAttachedFileUrlAndName.select("img").remove().first();
//Get file's info (size and download count)
String tmpAttachedFileInfo = attached.text().trim();
tmpAttachedFileInfo = tmpAttachedFileInfo.substring(
tmpAttachedFileInfo.indexOf("("));
p_attachedFiles.add(tmpAttachedFileUrlAndName + " " + tmpAttachedFileInfo);
}
}
if (!p_isDeleted) { //Active user if (!p_isDeleted) { //Active user
//Get extra info //Get extra info
int postsLineIndex = -1; int postsLineIndex = -1;
@ -238,12 +258,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_numberOfStars, p_userColor)); , p_numberOfStars, p_userColor, p_attachedFiles));
} 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_post, p_postIndex, p_postNum, p_postDate, p_userColor)); , p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles));
} }
} }
return returnList; return returnList;

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

@ -1,7 +1,9 @@
package gr.thmmy.mthmmy.data; package gr.thmmy.mthmmy.data;
import java.util.ArrayList;
public class Post { public class Post {
//Standard info //Standard info (exists in every post)
private final String thumbnailUrl; private final String thumbnailUrl;
private final String author; private final String author;
private final String subject; private final String subject;
@ -17,13 +19,15 @@ 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 int numberOfStars; private final int numberOfStars;
private final int userColor; private final int userColor;
private final ArrayList<String> attachedFiles;
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, int numberOfStars, int userColor) { , String personalText, int numberOfStars, int userColor
, ArrayList<String> attachedFiles) {
this.thumbnailUrl = thumbnailUrl; this.thumbnailUrl = thumbnailUrl;
this.author = author; this.author = author;
this.subject = subject; this.subject = subject;
@ -39,10 +43,12 @@ public class Post {
this.personalText = personalText; this.personalText = personalText;
this.numberOfStars = numberOfStars; this.numberOfStars = numberOfStars;
this.userColor = userColor; this.userColor = userColor;
this.attachedFiles = attachedFiles;
} }
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 userColor) { , int postIndex, int postNumber, String postDate, int userColor
, ArrayList<String> attachedFiles) {
this.thumbnailUrl = thumbnailUrl; this.thumbnailUrl = thumbnailUrl;
this.author = author; this.author = author;
this.subject = subject; this.subject = subject;
@ -57,6 +63,8 @@ public class Post {
gender = "Gender"; gender = "Gender";
numberOfPosts = "Posts: 0"; numberOfPosts = "Posts: 0";
personalText = ""; personalText = "";
numberOfStars = 0;
this.attachedFiles = attachedFiles;
} }
//Getters //Getters
@ -76,19 +84,25 @@ public class Post {
return subject; return subject;
} }
public String getPostDate() { return postDate;} public String getPostDate() {
return postDate;
}
public int getPostNumber() { public int getPostNumber() {
return postNumber; return postNumber;
} }
public int getPostIndex() { return postIndex;} public int getPostIndex() {
return postIndex;
}
public boolean isDeleted() { public boolean isDeleted() {
return isDeleted; return isDeleted;
} }
public String getRank() {return rank; } public String getRank() {
return rank;
}
public String getSpecialRank() { public String getSpecialRank() {
return specialRank; return specialRank;
@ -106,7 +120,15 @@ public class Post {
return personalText; return personalText;
} }
public int getNumberOfStars() {return numberOfStars; } public int getNumberOfStars() {
return numberOfStars;
}
public int getUserColor() {
return userColor;
}
public int getUserColor() {return userColor; } public ArrayList<String> getAttachedFiles() {
return attachedFiles;
}
} }

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

@ -191,7 +191,7 @@
</LinearLayout> </LinearLayout>
<View <View
android:id="@+id/divider" android:id="@+id/header_body_devider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_marginBottom="9dp" android:layout_marginBottom="9dp"
@ -217,6 +217,27 @@
android:text="@string/post" android:text="@string/post"
/> />
</FrameLayout> </FrameLayout>
<View
android:id="@+id/body_footer_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="9dp"
android:background="@color/divider"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/post_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingBottom="9dp">
</LinearLayout>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
</LinearLayout> </LinearLayout>

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

@ -28,7 +28,6 @@
<color name="primary_dark">#333333</color> <color name="primary_dark">#333333</color>
<color name="primary_light">#3C3F41</color> <color name="primary_light">#3C3F41</color>
<color name="accent">#BF4040</color> <color name="accent">#BF4040</color>
<!--<color name="accent">#6797BB</color>-->
<color name="primary_text">#E7E7E7</color> <color name="primary_text">#E7E7E7</color>
<color name="secondary_text">#757575</color> <color name="secondary_text">#757575</color>
<color name="background">#303234</color> <color name="background">#303234</color>

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

@ -26,6 +26,7 @@
<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="fa_icon_star">&#xf005;</string>
<string name="fa_file">&#xf15b;</string>
<string name="user_number_of_posts">#%1$d</string> <string name="user_number_of_posts">#%1$d</string>
</resources> </resources>

2
app/src/main/res/values/styles.xml

@ -1,6 +1,6 @@
<resources> <resources>
<!-- Base application theme. --> <!-- Dark application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item> <item name="colorPrimary">@color/primary</item>

Loading…
Cancel
Save