|
@ -1,18 +1,16 @@ |
|
|
package gr.thmmy.mthmmy.activities; |
|
|
package gr.thmmy.mthmmy.activities; |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context; |
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.AsyncTask; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.support.v7.app.ActionBar; |
|
|
import android.support.v7.app.ActionBar; |
|
|
import android.support.v7.widget.LinearLayoutManager; |
|
|
|
|
|
import android.support.v7.widget.RecyclerView; |
|
|
|
|
|
import android.util.Log; |
|
|
import android.util.Log; |
|
|
import android.util.SparseArray; |
|
|
import android.util.SparseArray; |
|
|
import android.view.Gravity; |
|
|
import android.view.Gravity; |
|
|
import android.view.KeyEvent; |
|
|
import android.view.KeyEvent; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.view.ViewGroup; |
|
|
|
|
|
import android.view.inputmethod.EditorInfo; |
|
|
import android.view.inputmethod.EditorInfo; |
|
|
import android.webkit.WebView; |
|
|
import android.webkit.WebView; |
|
|
import android.widget.EditText; |
|
|
import android.widget.EditText; |
|
@ -36,20 +34,19 @@ import javax.net.ssl.SSLHandshakeException; |
|
|
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.CircularNetworkImageView; |
|
|
import gr.thmmy.mthmmy.utils.CircularNetworkImageView; |
|
|
import gr.thmmy.mthmmy.utils.CustomRecyclerView; |
|
|
|
|
|
import gr.thmmy.mthmmy.utils.ImageController; |
|
|
import gr.thmmy.mthmmy.utils.ImageController; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Response; |
|
|
import okhttp3.Response; |
|
|
|
|
|
|
|
|
public class TopicActivity extends BaseActivity { |
|
|
public class TopicActivity extends BaseActivity { |
|
|
|
|
|
private static final int THUMBNAIL_SIZE = 80; |
|
|
|
|
|
private final SparseArray<String> pagesUrls = new SparseArray<>(); |
|
|
private ImageLoader imageLoader = ImageController.getInstance().getImageLoader(); |
|
|
private ImageLoader imageLoader = ImageController.getInstance().getImageLoader(); |
|
|
private TopicAdapter topicAdapter; |
|
|
|
|
|
private ProgressBar progressBar; |
|
|
private ProgressBar progressBar; |
|
|
private List<Post> postsList; |
|
|
private List<Post> postsList; |
|
|
private EditText pageSelect; |
|
|
private EditText pageSelect; |
|
|
|
|
|
private LinearLayout postsLinearLayout; |
|
|
private int thisPage = 1; |
|
|
private int thisPage = 1; |
|
|
private SparseArray<String> pagesUrls = new SparseArray<>(); |
|
|
|
|
|
private String base_url = ""; |
|
|
private String base_url = ""; |
|
|
private int numberOfPages = 1; |
|
|
private int numberOfPages = 1; |
|
|
|
|
|
|
|
@ -61,6 +58,8 @@ public class TopicActivity extends BaseActivity { |
|
|
Bundle extras = getIntent().getExtras(); |
|
|
Bundle extras = getIntent().getExtras(); |
|
|
final String topicTitle = getIntent().getExtras().getString("TOPIC_TITLE"); |
|
|
final String topicTitle = getIntent().getExtras().getString("TOPIC_TITLE"); |
|
|
|
|
|
|
|
|
|
|
|
postsLinearLayout = (LinearLayout) findViewById(R.id.posts_list); |
|
|
|
|
|
|
|
|
progressBar = (ProgressBar) findViewById(R.id.progressBar); |
|
|
progressBar = (ProgressBar) findViewById(R.id.progressBar); |
|
|
|
|
|
|
|
|
if (imageLoader == null) |
|
|
if (imageLoader == null) |
|
@ -103,76 +102,62 @@ public class TopicActivity extends BaseActivity { |
|
|
actionbar.setCustomView(customNav, lp); |
|
|
actionbar.setCustomView(customNav, lp); |
|
|
actionbar.setDisplayShowCustomEnabled(true); |
|
|
actionbar.setDisplayShowCustomEnabled(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
postsList = new ArrayList<>(); |
|
|
postsList = new ArrayList<>(); |
|
|
topicAdapter = new TopicAdapter(); |
|
|
|
|
|
|
|
|
|
|
|
CustomRecyclerView recyclerView = (CustomRecyclerView) findViewById(R.id.posts_list); |
|
|
|
|
|
recyclerView.setLayoutManager(new LinearLayoutManager(findViewById(R.id.posts_list).getContext())); |
|
|
|
|
|
recyclerView.setAdapter(topicAdapter); |
|
|
|
|
|
|
|
|
|
|
|
new TopicTask().execute(extras.getString("TOPIC_URL")); |
|
|
new TopicTask().execute(extras.getString("TOPIC_URL")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void onDestroy() { |
|
|
|
|
|
super.onDestroy(); |
|
|
|
|
|
ImageController.getInstance().cancelPendingRequests(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.ViewHolder> { |
|
|
//---------------------------------------TOPIC ASYNC TASK-------------------------------------------
|
|
|
@Override |
|
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
|
|
|
|
|
View view = LayoutInflater.from(parent.getContext()) |
|
|
|
|
|
.inflate(R.layout.activity_topic_post_row, parent, false); |
|
|
|
|
|
return new ViewHolder(view); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void onBindViewHolder(final ViewHolder holder, final int position) { |
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------- Holder behaves erratically -----------------------------------
|
|
|
|
|
|
if (postsList.get(position).getThumbnailUrl() != "") { |
|
|
|
|
|
holder.mThumbnailView.setImageUrl(postsList.get(position).getThumbnailUrl(), imageLoader); |
|
|
|
|
|
} |
|
|
|
|
|
holder.mAuthorView.setText(postsList.get(position).getAuthor()); |
|
|
|
|
|
holder.mSubjectView.setText(postsList.get(position).getDateTime()); |
|
|
|
|
|
holder.mContentView.loadDataWithBaseURL("file:///android_asset/" |
|
|
|
|
|
, postsList.get(position).getContent() |
|
|
|
|
|
, "text/html", "UTF-8", null); |
|
|
|
|
|
//----------------------------------- Holder behaves erratically -----------------------------------
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public int getItemCount() { |
|
|
|
|
|
return postsList.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class ViewHolder extends RecyclerView.ViewHolder { |
|
|
private void populateLayout() { |
|
|
final View mView; |
|
|
LayoutInflater inflater = (LayoutInflater) getApplicationContext() |
|
|
final CircularNetworkImageView mThumbnailView; |
|
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
|
final TextView mAuthorView; |
|
|
|
|
|
final TextView mSubjectView; |
|
|
for (Post item : postsList) { |
|
|
final WebView mContentView; |
|
|
View convertView = inflater.inflate(R.layout.activity_topic_post_row |
|
|
|
|
|
, postsLinearLayout, false); |
|
|
ViewHolder(View view) { |
|
|
|
|
|
super(view); |
|
|
if (imageLoader == null) |
|
|
mView = view; |
|
|
imageLoader = ImageController.getInstance().getImageLoader(); |
|
|
mThumbnailView = (CircularNetworkImageView) view.findViewById(R.id.thumbnail); |
|
|
|
|
|
mAuthorView = (TextView) view.findViewById(R.id.username); |
|
|
CircularNetworkImageView thumbnail = (CircularNetworkImageView) convertView.findViewById(R.id.thumbnail); |
|
|
mSubjectView = (TextView) view.findViewById(R.id.subject); |
|
|
TextView username = (TextView) convertView.findViewById(R.id.username); |
|
|
mContentView = (WebView) view.findViewById(R.id.post); |
|
|
TextView postNum = (TextView) convertView.findViewById(R.id.post_number); |
|
|
|
|
|
TextView subject = (TextView) convertView.findViewById(R.id.subject); |
|
|
|
|
|
WebView post = (WebView) convertView.findViewById(R.id.post); |
|
|
|
|
|
|
|
|
|
|
|
//Avoiding errors about layout having 0 width/height
|
|
|
|
|
|
thumbnail.setMinimumWidth(1); |
|
|
|
|
|
thumbnail.setMinimumHeight(1); |
|
|
|
|
|
//Set thumbnail size
|
|
|
|
|
|
thumbnail.setMaxWidth(THUMBNAIL_SIZE); |
|
|
|
|
|
thumbnail.setMaxHeight(THUMBNAIL_SIZE); |
|
|
|
|
|
|
|
|
|
|
|
// thumbnail image
|
|
|
|
|
|
if (item.getThumbnailUrl() != null) { |
|
|
|
|
|
thumbnail.setImageUrl(item.getThumbnailUrl(), imageLoader); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
username.setText(item.getAuthor()); |
|
|
|
|
|
if (item.getPostNumber() != 0) |
|
|
|
|
|
postNum.setText("#" + item.getPostNumber()); |
|
|
|
|
|
subject.setText(item.getSubject()); |
|
|
|
|
|
post.loadDataWithBaseURL("file:///android_asset/", item.getContent(), "text/html", "UTF-8", null); |
|
|
|
|
|
post.setEnabled(false); |
|
|
|
|
|
postsLinearLayout.addView(convertView); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------TOPIC ASYNC TASK-------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
public class TopicTask extends AsyncTask<String, Void, Boolean> { |
|
|
public class TopicTask extends AsyncTask<String, Void, Boolean> { |
|
|
private static final String TAG = "TopicTask"; |
|
|
private static final String TAG = "TopicTask"; |
|
|
private String pageLink; |
|
|
private String pageLink; |
|
|
|
|
|
|
|
|
private Document document; |
|
|
private Document document; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void onPreExecute() { |
|
|
protected void onPreExecute() { |
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
} |
|
|
} |
|
@ -200,10 +185,9 @@ public class TopicActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void onPostExecute(Boolean result) { |
|
|
protected void onPostExecute(Boolean result) { |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
topicAdapter.notifyDataSetChanged(); |
|
|
populateLayout(); |
|
|
pageSelect.setHint(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages)); |
|
|
pageSelect.setHint(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -232,37 +216,52 @@ public class TopicActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Elements form_quickModForm = document.select("form[id=quickModForm]"); |
|
|
//Each element is a post row
|
|
|
Elements nickNames = form_quickModForm.select("a[title^=View the profile of]"); |
|
|
Elements rows = document.select("form[id=quickModForm]>table>tbody>tr:matches(on)"); |
|
|
Elements topic_subjectS = form_quickModForm.select("div[id^=subject_]"); |
|
|
|
|
|
Elements postTextS = form_quickModForm.select("div").select(".post"); |
|
|
|
|
|
Elements img_smalltexts = form_quickModForm.select("div").select(":matches(Posts:)"); |
|
|
|
|
|
//Elements replies_smalltexts = form_quickModForm.select("div.smalltext:matches(Reply #)");
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nickNames.size(); i++) { |
|
|
|
|
|
|
|
|
|
|
|
String tmp_nickName = nickNames.get(i).html(); |
|
|
for (Element item: rows) { //For every post
|
|
|
Element thumbnail_urls = img_smalltexts.get(i).select("img").select(".avatar").first(); |
|
|
String p_userName, p_thumbnailUrl, p_subject, p_post; |
|
|
|
|
|
int p_postNum; |
|
|
|
|
|
|
|
|
String tmp_url = ""; |
|
|
//Find the Username
|
|
|
if (thumbnail_urls != null) { |
|
|
Element userName = item.select("a[title^=View the profile of]").first(); |
|
|
tmp_url = thumbnail_urls.attr("abs:src"); |
|
|
if(userName == null){ //Deleted profile
|
|
|
|
|
|
p_userName = item |
|
|
|
|
|
.select("td:has(div.smalltext:containsOwn(Guest))[style^=overflow]") |
|
|
|
|
|
.first().text(); |
|
|
|
|
|
p_userName = p_userName.substring(0, p_userName.indexOf(" Guest")); |
|
|
} |
|
|
} |
|
|
String tmp_topic_subject = topic_subjectS.get(i).select("a").first().text(); |
|
|
else |
|
|
String tmp_post_text = postTextS.get(i).html(); |
|
|
p_userName = userName.html(); |
|
|
tmp_post_text = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" + tmp_post_text); //style.css
|
|
|
|
|
|
|
|
|
//Find thumbnail url
|
|
|
|
|
|
Element thumbnailUrl = item.select("img.avatar").first(); |
|
|
|
|
|
p_thumbnailUrl = null; //In case user doesn't have an avatar
|
|
|
|
|
|
if(thumbnailUrl != null){ |
|
|
|
|
|
p_thumbnailUrl = thumbnailUrl.attr("abs:src"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Find subject
|
|
|
|
|
|
p_subject = item.select("div[id^=subject_]").first().select("a").first().text(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*int tmp_postNum = 0; //topic starter
|
|
|
//Find post's text
|
|
|
if (replies_smalltexts.size() == nickNames.size()) { |
|
|
p_post = item.select("div").select(".post").first().html(); |
|
|
String tmp_prep = replies_smalltexts.get(i).text().substring(9); |
|
|
p_post = ("<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />" |
|
|
tmp_postNum = Integer.parseInt(tmp_prep.substring(0, tmp_prep.indexOf(" on"))); |
|
|
+ p_post); //style.css
|
|
|
} else if (i != 0) { |
|
|
|
|
|
String tmp_prep = replies_smalltexts.get(i - 1).text().substring(9); |
|
|
//Find post's index number
|
|
|
tmp_postNum = Integer.parseInt(tmp_prep.substring(0, tmp_prep.indexOf(" on"))); |
|
|
Element postNum = item.select("div.smalltext:matches(Reply #)").first(); |
|
|
}*/ |
|
|
if(postNum == null){ //Topic starter
|
|
|
|
|
|
p_postNum = 0; |
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
String tmp_str = postNum.text().substring(9); |
|
|
|
|
|
p_postNum = Integer.parseInt(tmp_str.substring(0, tmp_str.indexOf(" on"))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
postsList.add(new Post(tmp_url, tmp_nickName, tmp_topic_subject, tmp_post_text)); |
|
|
postsList.add(new Post(p_thumbnailUrl, p_userName, p_subject |
|
|
|
|
|
, p_post, p_postNum)); |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|