|
@ -6,10 +6,21 @@ import android.os.AsyncTask; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.os.Handler; |
|
|
import android.os.Handler; |
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
import android.support.design.widget.FloatingActionButton; |
|
|
|
|
|
import android.support.v7.app.AlertDialog; |
|
|
import android.support.v7.widget.LinearLayoutManager; |
|
|
import android.support.v7.widget.LinearLayoutManager; |
|
|
import android.support.v7.widget.RecyclerView; |
|
|
import android.support.v7.widget.RecyclerView; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
|
|
|
import android.text.Html; |
|
|
|
|
|
import android.text.SpannableString; |
|
|
|
|
|
import android.text.SpannableStringBuilder; |
|
|
|
|
|
import android.text.method.LinkMovementMethod; |
|
|
|
|
|
import android.text.method.ScrollingMovementMethod; |
|
|
|
|
|
import android.text.style.ClickableSpan; |
|
|
|
|
|
import android.text.style.URLSpan; |
|
|
import android.util.SparseArray; |
|
|
import android.util.SparseArray; |
|
|
|
|
|
import android.view.LayoutInflater; |
|
|
|
|
|
import android.view.Menu; |
|
|
|
|
|
import android.view.MenuItem; |
|
|
import android.view.MotionEvent; |
|
|
import android.view.MotionEvent; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.widget.ImageButton; |
|
|
import android.widget.ImageButton; |
|
@ -92,6 +103,9 @@ public class TopicActivity extends BaseActivity { |
|
|
private TextView pageIndicator; |
|
|
private TextView pageIndicator; |
|
|
private ImageButton nextPage; |
|
|
private ImageButton nextPage; |
|
|
private ImageButton lastPage; |
|
|
private ImageButton lastPage; |
|
|
|
|
|
//Topic's info
|
|
|
|
|
|
SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."), |
|
|
|
|
|
topicViewers = new SpannableStringBuilder("Loading..."); |
|
|
//Other variables
|
|
|
//Other variables
|
|
|
private MaterialProgressBar progressBar; |
|
|
private MaterialProgressBar progressBar; |
|
|
private static String base_url = ""; |
|
|
private static String base_url = ""; |
|
@ -117,18 +131,22 @@ public class TopicActivity extends BaseActivity { |
|
|
finish(); |
|
|
finish(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl)); |
|
|
|
|
|
|
|
|
//Initializes graphics
|
|
|
//Initializes graphics
|
|
|
toolbar = (Toolbar) findViewById(R.id.toolbar); |
|
|
toolbar = (Toolbar) findViewById(R.id.toolbar); |
|
|
toolbar.setTitle(topicTitle); |
|
|
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title); |
|
|
|
|
|
toolbarTitle.setText(topicTitle); |
|
|
setSupportActionBar(toolbar); |
|
|
setSupportActionBar(toolbar); |
|
|
if (getSupportActionBar() != null) { |
|
|
if (getSupportActionBar() != null) { |
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
|
|
getSupportActionBar().setDisplayShowHomeEnabled(true); |
|
|
getSupportActionBar().setDisplayShowHomeEnabled(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl)); |
|
|
//Makes title scrollable
|
|
|
thisPageBookmarkButton = (ImageButton) findViewById(R.id.bookmark); |
|
|
toolbarTitle.setHorizontallyScrolling(true); |
|
|
setTopicBookmark(); |
|
|
toolbarTitle.setMovementMethod(new ScrollingMovementMethod()); |
|
|
|
|
|
|
|
|
createDrawer(); |
|
|
createDrawer(); |
|
|
|
|
|
|
|
|
progressBar = (MaterialProgressBar) findViewById(R.id.progressBar); |
|
|
progressBar = (MaterialProgressBar) findViewById(R.id.progressBar); |
|
@ -179,6 +197,43 @@ public class TopicActivity extends BaseActivity { |
|
|
topicTask.execute(extras.getString(BUNDLE_TOPIC_URL)); //Attempt data parsing
|
|
|
topicTask.execute(extras.getString(BUNDLE_TOPIC_URL)); //Attempt data parsing
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
|
|
// Inflates the menu; this adds items to the action bar if it is present.
|
|
|
|
|
|
getMenuInflater().inflate(R.menu.topic_menu, menu); |
|
|
|
|
|
setTopicBookmark(menu.getItem(0)); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) { |
|
|
|
|
|
// Handle presses on the action bar items
|
|
|
|
|
|
switch (item.getItemId()) { |
|
|
|
|
|
case R.id.menu_bookmark: |
|
|
|
|
|
topicMenuBookmarkClick(); |
|
|
|
|
|
return true; |
|
|
|
|
|
case R.id.menu_info: |
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
|
|
|
|
|
LayoutInflater inflater = this.getLayoutInflater(); |
|
|
|
|
|
LinearLayout infoDialog = (LinearLayout) inflater.inflate(R.layout.dialog_topic_info |
|
|
|
|
|
, null); |
|
|
|
|
|
((TextView) infoDialog.findViewById(R.id.dialog_title)).setText("Info"); |
|
|
|
|
|
TextView treeAndMods = (TextView) infoDialog.findViewById(R.id.topic_tree_and_mods); |
|
|
|
|
|
treeAndMods.setText(topicTreeAndMods); |
|
|
|
|
|
treeAndMods.setMovementMethod(LinkMovementMethod.getInstance()); |
|
|
|
|
|
TextView usersViewing = (TextView) infoDialog.findViewById(R.id.users_viewing); |
|
|
|
|
|
usersViewing.setText(topicViewers); |
|
|
|
|
|
usersViewing.setMovementMethod(LinkMovementMethod.getInstance()); |
|
|
|
|
|
|
|
|
|
|
|
builder.setView(infoDialog); |
|
|
|
|
|
AlertDialog dialog = builder.create(); |
|
|
|
|
|
dialog.show(); |
|
|
|
|
|
return true; |
|
|
|
|
|
default: |
|
|
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onBackPressed() { |
|
|
public void onBackPressed() { |
|
|
if (drawer.isDrawerOpen()) { |
|
|
if (drawer.isDrawerOpen()) { |
|
@ -476,7 +531,8 @@ public class TopicActivity extends BaseActivity { |
|
|
case SUCCESS: |
|
|
case SUCCESS: |
|
|
if (topicTitle == null || Objects.equals(topicTitle, "")) { |
|
|
if (topicTitle == null || Objects.equals(topicTitle, "")) { |
|
|
thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl)); |
|
|
thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl)); |
|
|
setTopicBookmark(); |
|
|
invalidateOptionsMenu(); |
|
|
|
|
|
//setTopicBookmark(menu.getItem(0));
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
@ -522,7 +578,13 @@ public class TopicActivity extends BaseActivity { |
|
|
private void parse(Document topic) { |
|
|
private void parse(Document topic) { |
|
|
ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); |
|
|
ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); |
|
|
|
|
|
|
|
|
//Find reply page url
|
|
|
//Finds topic's tree, mods and users viewing
|
|
|
|
|
|
{ |
|
|
|
|
|
topicTreeAndMods = getSpannableFromHtml(topic.select("div.nav").first().html()); |
|
|
|
|
|
topicViewers = getSpannableFromHtml(TopicParser.parseUsersViewingThisTopic(topic, language)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Finds reply page url
|
|
|
{ |
|
|
{ |
|
|
Element replyButton = topic.select("a:has(img[alt=Reply])").first(); |
|
|
Element replyButton = topic.select("a:has(img[alt=Reply])").first(); |
|
|
if (replyButton == null) |
|
|
if (replyButton == null) |
|
@ -558,6 +620,30 @@ public class TopicActivity extends BaseActivity { |
|
|
postsList.clear(); |
|
|
postsList.clear(); |
|
|
postsList.addAll(TopicParser.parseTopic(topic, language)); |
|
|
postsList.addAll(TopicParser.parseTopic(topic, language)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) |
|
|
|
|
|
{ |
|
|
|
|
|
int start = strBuilder.getSpanStart(span); |
|
|
|
|
|
int end = strBuilder.getSpanEnd(span); |
|
|
|
|
|
int flags = strBuilder.getSpanFlags(span); |
|
|
|
|
|
ClickableSpan clickable = new ClickableSpan() { |
|
|
|
|
|
public void onClick(View view) { |
|
|
|
|
|
//TODO
|
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
strBuilder.setSpan(clickable, start, end, flags); |
|
|
|
|
|
strBuilder.removeSpan(span); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private SpannableStringBuilder getSpannableFromHtml(String html) { |
|
|
|
|
|
CharSequence sequence = Html.fromHtml(html); |
|
|
|
|
|
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence); |
|
|
|
|
|
URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class); |
|
|
|
|
|
for(URLSpan span : urls) { |
|
|
|
|
|
makeLinkClickable(strBuilder, span); |
|
|
|
|
|
} |
|
|
|
|
|
return strBuilder; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class ReplyTask extends AsyncTask<String, Void, Boolean> { |
|
|
class ReplyTask extends AsyncTask<String, Void, Boolean> { |
|
|