Browse Source

Topic scrollable title and auto scroll, extra info.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
5914ab0b7b
  1. 10
      app/build.gradle
  2. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  3. 98
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  4. 50
      app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java
  5. 20
      app/src/main/res/layout/activity_topic.xml
  6. 33
      app/src/main/res/layout/dialog_topic_info.xml
  7. 16
      app/src/main/res/menu/topic_menu.xml
  8. 1
      app/src/main/res/values/colors.xml

10
app/build.gradle

@ -28,11 +28,11 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.google.firebase:firebase-crash:10.0.1'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.squareup.picasso:picasso:2.5.2'

3
app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java

@ -92,8 +92,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
}
thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl));
thisPageBookmarkButton = (ImageButton) findViewById(R.id.bookmark);
setBoardBookmark();
setBoardBookmark((ImageButton) findViewById(R.id.bookmark));
createDrawer();
progressBar = (MaterialProgressBar) findViewById(R.id.progressBar);

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

@ -6,10 +6,21 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
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.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
@ -92,6 +103,9 @@ public class TopicActivity extends BaseActivity {
private TextView pageIndicator;
private ImageButton nextPage;
private ImageButton lastPage;
//Topic's info
SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."),
topicViewers = new SpannableStringBuilder("Loading...");
//Other variables
private MaterialProgressBar progressBar;
private static String base_url = "";
@ -117,18 +131,22 @@ public class TopicActivity extends BaseActivity {
finish();
}
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl));
//Initializes graphics
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle(topicTitle);
TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
toolbarTitle.setText(topicTitle);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl));
thisPageBookmarkButton = (ImageButton) findViewById(R.id.bookmark);
setTopicBookmark();
//Makes title scrollable
toolbarTitle.setHorizontallyScrolling(true);
toolbarTitle.setMovementMethod(new ScrollingMovementMethod());
createDrawer();
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
}
@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
public void onBackPressed() {
if (drawer.isDrawerOpen()) {
@ -476,7 +531,8 @@ public class TopicActivity extends BaseActivity {
case SUCCESS:
if (topicTitle == null || Objects.equals(topicTitle, "")) {
thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl));
setTopicBookmark();
invalidateOptionsMenu();
//setTopicBookmark(menu.getItem(0));
}
progressBar.setVisibility(ProgressBar.INVISIBLE);
@ -522,7 +578,13 @@ public class TopicActivity extends BaseActivity {
private void parse(Document 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();
if (replyButton == null)
@ -558,6 +620,30 @@ public class TopicActivity extends BaseActivity {
postsList.clear();
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> {

50
app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java

@ -14,6 +14,7 @@ import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
@ -63,7 +64,8 @@ public abstract class BaseActivity extends AppCompatActivity {
private static final String BOOKMARKED_TOPICS_KEY = "bookmarkedTopicsKey";
private static final String BOOKMARKED_BOARDS_KEY = "bookmarkedBoardsKey";
protected Bookmark thisPageBookmark;
protected ImageButton thisPageBookmarkButton;
protected MenuItem thisPageBookmarkMenuButton;
protected ImageButton thisPageBookmarkImageButton;
private SharedPreferences bookmarksFile;
private ArrayList<Bookmark> topicsBookmarked;
private ArrayList<Bookmark> boardsBookmarked;
@ -408,42 +410,42 @@ public abstract class BaseActivity extends AppCompatActivity {
return topicsBookmarked;
}
protected void setTopicBookmark() {
protected void setTopicBookmark(MenuItem thisPageBookmarkMenuButton) {
this.thisPageBookmarkMenuButton = thisPageBookmarkMenuButton;
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkButton.setImageDrawable(bookmarked);
thisPageBookmarkMenuButton.setIcon(bookmarked);
} else {
thisPageBookmarkButton.setImageDrawable(notBookmarked);
thisPageBookmarkMenuButton.setIcon(notBookmarked);
}
}
protected void topicMenuBookmarkClick(){
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkMenuButton.setIcon(notBookmarked);
toggleTopicToBookmarks(thisPageBookmark);
Toast.makeText(BaseActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show();
} else {
thisPageBookmarkMenuButton.setIcon(bookmarked);
toggleTopicToBookmarks(thisPageBookmark);
Toast.makeText(BaseActivity.this, "Bookmark added", Toast.LENGTH_SHORT).show();
}
thisPageBookmarkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (thisPageBookmark.matchExists(topicsBookmarked)) {
thisPageBookmarkButton.setImageDrawable(notBookmarked);
toggleTopicToBookmarks(thisPageBookmark);
Toast.makeText(BaseActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show();
} else {
thisPageBookmarkButton.setImageDrawable(bookmarked);
toggleTopicToBookmarks(thisPageBookmark);
Toast.makeText(BaseActivity.this, "Bookmark added", Toast.LENGTH_SHORT).show();
}
}
});
}
protected void setBoardBookmark() {
protected void setBoardBookmark(final ImageButton thisPageBookmarkImageButton) {
this.thisPageBookmarkImageButton = thisPageBookmarkImageButton;
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkButton.setImageDrawable(bookmarked);
thisPageBookmarkImageButton.setImageDrawable(bookmarked);
} else {
thisPageBookmarkButton.setImageDrawable(notBookmarked);
thisPageBookmarkImageButton.setImageDrawable(notBookmarked);
}
thisPageBookmarkButton.setOnClickListener(new View.OnClickListener() {
thisPageBookmarkImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (thisPageBookmark.matchExists(boardsBookmarked)) {
thisPageBookmarkButton.setImageDrawable(notBookmarked);
thisPageBookmarkImageButton.setImageDrawable(notBookmarked);
Toast.makeText(BaseActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show();
} else {
thisPageBookmarkButton.setImageDrawable(bookmarked);
thisPageBookmarkImageButton.setImageDrawable(bookmarked);
Toast.makeText(BaseActivity.this, "Bookmark added", Toast.LENGTH_SHORT).show();
}
toggleBoardToBookmarks(thisPageBookmark);

20
app/src/main/res/layout/activity_topic.xml

@ -23,15 +23,19 @@
android:background="?attr/colorPrimary"
app:popupTheme="@style/ToolbarTheme">
<ImageButton
android:id="@+id/bookmark"
android:layout_width="wrap_content"
<TextView
android:id="@+id/toolbar_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|end"
android:layout_marginEnd="4dp"
android:background="@null"
android:contentDescription="@string/bookmark"
android:src="@drawable/ic_bookmark_false"/>
android:ellipsize="marquee"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxLines="1"
android:scrollHorizontally="true"
android:textColor="@color/white"
/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

33
app/src/main/res/layout/dialog_topic_info.xml

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingEnd="24dp"
android:paddingStart="24dp">
<TextView
android:id="@+id/dialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="24dp"
android:textColor="@color/white"
android:textSize="20sp"/>
<TextView
android:id="@+id/topic_tree_and_mods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:textColor="@color/white"
android:textColorLink="@color/link_color"/>
<TextView
android:id="@+id/users_viewing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textColor="@color/white"
android:textColorLink="@color/link_color"/>
</LinearLayout>

16
app/src/main/res/menu/topic_menu.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_bookmark"
android:icon="@drawable/ic_bookmark_false"
app:showAsAction="ifRoom"
android:title="Bookmark">
</item>
<item
android:id="@+id/menu_info"
android:icon="@drawable/ic_info"
app:showAsAction="ifRoom|withText"
android:title="Info">
</item>
</menu>

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

@ -16,6 +16,7 @@
<color name="background">#323232</color>
<color name="card_background">#3C3F41</color>
<color name="divider">#8B8B8B</color>
<color name="link_color">#4B0082</color>
<color name="white">#FFFFFF</color>
<color name="iron">#CCCCCC</color>

Loading…
Cancel
Save