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

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.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -66,6 +68,8 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
final ImageButton quoteToggle;
final RelativeLayout header;
final LinearLayout userExtraInfo;
final View bodyFooterDivider;
final LinearLayout postFooter;
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);
post = (WebView) view.findViewById(R.id.post);
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
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 (!currentPost.isDeleted()) { //Set extra info
//Variables with content
@ -239,8 +262,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
if (viewProperties.get(position)[isUserExtraInfoVisibile]) { //Expanded
holder.userExtraInfo.setVisibility(View.VISIBLE);
holder.userExtraInfo.setAlpha(1.0f);
}
else { //Collapsed
} else { //Collapsed
holder.userExtraInfo.setVisibility(View.GONE);
holder.userExtraInfo.setAlpha(0.0f);
}
@ -495,5 +517,4 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
}
}
//------------------------------------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;
import android.graphics.Color;
import android.util.Log;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@ -91,6 +92,7 @@ class TopicParser {
p_specialRank, p_gender, p_personalText, p_numberOfPosts;
int p_postNum, p_postIndex, p_numberOfStars, p_userColor;
boolean p_isDeleted = false;
ArrayList<String> p_attachedFiles;
//Initialize variables
p_rank = "Rank";
@ -100,6 +102,7 @@ class TopicParser {
p_numberOfPosts = "";
p_numberOfStars = 0;
p_userColor = USER_COLOR_YELLOW;
p_attachedFiles = new ArrayList<>();
//Find the Username
Element userName = item.select("a[title^=" + userNameSelection + "]").first();
@ -179,6 +182,23 @@ class TopicParser {
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
//Get extra info
int postsLineIndex = -1;
@ -238,12 +258,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_numberOfStars, p_userColor));
, p_numberOfStars, p_userColor, p_attachedFiles));
} 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_userColor));
returnList.add(new Post(p_thumbnailUrl, p_userName, p_subject, p_post
, p_postIndex, p_postNum, p_postDate, p_userColor, p_attachedFiles));
}
}
return returnList;

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

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

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

@ -28,7 +28,6 @@
<color name="primary_dark">#333333</color>
<color name="primary_light">#3C3F41</color>
<color name="accent">#BF4040</color>
<!--<color name="accent">#6797BB</color>-->
<color name="primary_text">#E7E7E7</color>
<color name="secondary_text">#757575</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="home">Home</string>
<string name="fa_icon_star">&#xf005;</string>
<string name="fa_file">&#xf15b;</string>
<string name="user_number_of_posts">#%1$d</string>
</resources>

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

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

Loading…
Cancel
Save