Browse Source

Code cleanup and fixes.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
d46f441522
  1. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 55
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. BIN
      app/src/main/res/drawable-hdpi/ic_format_quote_checked.png
  4. BIN
      app/src/main/res/drawable-hdpi/ic_format_quote_unchecked.png
  5. BIN
      app/src/main/res/drawable-mdpi/ic_format_quote_checked.png
  6. BIN
      app/src/main/res/drawable-mdpi/ic_format_quote_unchecked.png
  7. BIN
      app/src/main/res/drawable-xhdpi/ic_format_quote_checked.png
  8. BIN
      app/src/main/res/drawable-xhdpi/ic_format_quote_unchecked.png
  9. BIN
      app/src/main/res/drawable-xxhdpi/ic_format_quote_checked.png
  10. BIN
      app/src/main/res/drawable-xxhdpi/ic_format_quote_unchecked.png
  11. BIN
      app/src/main/res/drawable-xxxhdpi/ic_format_quote_checked.png
  12. BIN
      app/src/main/res/drawable-xxxhdpi/ic_format_quote_unchecked.png
  13. BIN
      app/src/main/res/drawable/ic_format_quote_accent.png
  14. BIN
      app/src/main/res/drawable/ic_format_quote_grey.png
  15. 5
      app/src/main/res/drawable/ic_toggle_quote_bg.xml
  16. 8
      app/src/main/res/layout-v21/activity_topic_post_row.xml
  17. 6
      app/src/main/res/layout/activity_topic_post_row.xml

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

@ -214,8 +214,7 @@ public class TopicActivity extends BaseActivity {
topicTask.cancel(true); topicTask.cancel(true);
} }
//--------------------------------------BOTTOM NAV BAR METHODS--------------------------------------
//--------------------------------------BOTTOM NAV BAR METHODS--------------------------------------
private void initIncrementButton(ImageButton increment, final int step) { private void initIncrementButton(ImageButton increment, final int step) {
// Increment once for a click // Increment once for a click
increment.setOnClickListener(new View.OnClickListener() { increment.setOnClickListener(new View.OnClickListener() {
@ -361,6 +360,7 @@ public class TopicActivity extends BaseActivity {
} }
if (!loadedPageUrl.contains(base_url)) { if (!loadedPageUrl.contains(base_url)) {
loadedPageUrl = newPageUrl;
Request request = new Request.Builder() Request request = new Request.Builder()
.url(newPageUrl) .url(newPageUrl)
.build(); .build();

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

@ -10,13 +10,13 @@ import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
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.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -179,7 +179,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
@SuppressLint("SetJavaScriptEnabled") @SuppressLint("SetJavaScriptEnabled")
@Override @Override
public void onBindViewHolder(final MyViewHolder holder, int position) { public void onBindViewHolder(final MyViewHolder holder, final int position) {
final Post currentPost = postsList.get(position); final Post currentPost = postsList.get(position);
//Post's WebView parameters //Post's WebView parameters
@ -359,27 +359,38 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
holder.subject.setMaxLines(1); holder.subject.setMaxLines(1);
holder.subject.setEllipsize(TextUtils.TruncateAt.END); holder.subject.setEllipsize(TextUtils.TruncateAt.END);
} }
if(viewProperties.get(position)[isQuoteButtonChecked])
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked);
else
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked);
//Sets graphics behavior //Sets graphics behavior
holder.quoteToggle.setOnClickListener(new View.OnClickListener() { holder.quoteToggle.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (view.isSelected()) { boolean[] tmp = viewProperties.get(holder.getAdapterPosition());
Log.d(TAG, "GOT");
if (tmp[isQuoteButtonChecked]) {
if (toQuoteList.contains(currentPost.getPostNumber())) { if (toQuoteList.contains(currentPost.getPostNumber())) {
toQuoteList.remove(toQuoteList.indexOf(currentPost.getPostNumber())); toQuoteList.remove(toQuoteList.indexOf(currentPost.getPostNumber()));
view.setSelected(false); Log.d(TAG, "GOT1");
} else } else
Report.i(TAG, "An error occurred while trying to exclude post from" + Log.d(TAG, "GOT2");
"toQuoteList, post wasn't there!"); //Report.i(TAG, "An error occurred while trying to exclude post from" +
// "toQuoteList, post wasn't there!");
holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked);
} else { } else {
Log.d(TAG, "GOT3");
toQuoteList.add(currentPost.getPostNumber()); toQuoteList.add(currentPost.getPostNumber());
view.setSelected(true); holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked);
} }
tmp[isQuoteButtonChecked] = !tmp[isQuoteButtonChecked];
viewProperties.set(holder.getAdapterPosition(), tmp);
} }
}); });
//Card expand/collapse when card is touched //Card expand/collapse when card is touched
holder.cardView.setOnClickListener(new View.OnClickListener() { holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View view) {
//Change post's viewProperties accordingly //Change post's viewProperties accordingly
boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); boolean[] tmp = viewProperties.get(holder.getAdapterPosition());
tmp[isPostDateAndNumberVisibile] = !tmp[isPostDateAndNumberVisibile]; tmp[isPostDateAndNumberVisibile] = !tmp[isPostDateAndNumberVisibile];
@ -392,7 +403,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
} }
}); });
//Also when post is clicked //Also when post is clicked
holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView, holder.quoteToggle)); holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView));
} }
@Override @Override
@ -406,15 +417,11 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
*/ */
private class CustomTouchListener implements View.OnTouchListener { private class CustomTouchListener implements View.OnTouchListener {
//Long press handling //Long press handling
private final int LONG_PRESS_REQUIRED_DURATION = 650;
private final Handler webViewLongClickHandler = new Handler();
private boolean wasLongClick = false;
private float downCoordinateX; private float downCoordinateX;
private float downCoordinateY; private float downCoordinateY;
private final float SCROLL_THRESHOLD = 7; private final float SCROLL_THRESHOLD = 7;
final private WebView post; final private WebView post;
final private CardView cardView; final private CardView cardView;
final private ImageButton quoteToggle;
//Other variables //Other variables
final static int FINGER_RELEASED = 0; final static int FINGER_RELEASED = 0;
@ -424,19 +431,11 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
private int fingerState = FINGER_RELEASED; private int fingerState = FINGER_RELEASED;
CustomTouchListener(WebView pPost, CardView pCard, ImageButton pQuoteToggle) { CustomTouchListener(WebView pPost, CardView pCard) {
post = pPost; post = pPost;
cardView = pCard; cardView = pCard;
quoteToggle = pQuoteToggle;
} }
final Runnable WebViewLongClick = new Runnable() {
public void run() {
wasLongClick = true;
quoteToggle.performClick();
}
};
@Override @Override
public boolean onTouch(View view, MotionEvent motionEvent) { public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) { switch (motionEvent.getAction()) {
@ -449,14 +448,9 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
fingerState = FINGER_TOUCHED; fingerState = FINGER_TOUCHED;
else else
fingerState = FINGER_UNDEFINED; fingerState = FINGER_UNDEFINED;
webViewLongClickHandler.postDelayed(WebViewLongClick
, LONG_PRESS_REQUIRED_DURATION);
break; break;
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
webViewLongClickHandler.removeCallbacks(WebViewLongClick); if (fingerState != FINGER_DRAGGING) {
if (!wasLongClick && fingerState != FINGER_DRAGGING) {
//Doesn't expand the card if this was a link //Doesn't expand the card if this was a link
WebView.HitTestResult htResult = post.getHitTestResult(); WebView.HitTestResult htResult = post.getHitTestResult();
if (htResult.getExtra() != null if (htResult.getExtra() != null
@ -464,17 +458,14 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
fingerState = FINGER_RELEASED; fingerState = FINGER_RELEASED;
return false; return false;
} }
cardView.performClick(); cardView.performClick();
} else }
wasLongClick = false;
fingerState = FINGER_RELEASED; fingerState = FINGER_RELEASED;
break; break;
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
//Cancels long click if finger moved too much //Cancels long click if finger moved too much
if (((Math.abs(downCoordinateX - motionEvent.getX()) > SCROLL_THRESHOLD || if (((Math.abs(downCoordinateX - motionEvent.getX()) > SCROLL_THRESHOLD ||
Math.abs(downCoordinateY - motionEvent.getY()) > SCROLL_THRESHOLD))) { Math.abs(downCoordinateY - motionEvent.getY()) > SCROLL_THRESHOLD))) {
webViewLongClickHandler.removeCallbacks(WebViewLongClick);
fingerState = FINGER_DRAGGING; fingerState = FINGER_DRAGGING;
} else fingerState = FINGER_UNDEFINED; } else fingerState = FINGER_UNDEFINED;
break; break;

BIN
app/src/main/res/drawable-hdpi/ic_format_quote_checked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

BIN
app/src/main/res/drawable-hdpi/ic_format_quote_unchecked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

BIN
app/src/main/res/drawable-mdpi/ic_format_quote_checked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

BIN
app/src/main/res/drawable-mdpi/ic_format_quote_unchecked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

BIN
app/src/main/res/drawable-xhdpi/ic_format_quote_checked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 B

BIN
app/src/main/res/drawable-xhdpi/ic_format_quote_unchecked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 236 B

BIN
app/src/main/res/drawable-xxhdpi/ic_format_quote_checked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

BIN
app/src/main/res/drawable-xxhdpi/ic_format_quote_unchecked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_format_quote_checked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_format_quote_unchecked.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 502 B

BIN
app/src/main/res/drawable/ic_format_quote_accent.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 264 B

BIN
app/src/main/res/drawable/ic_format_quote_grey.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 B

5
app/src/main/res/drawable/ic_toggle_quote_bg.xml

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_format_quote_accent" android:state_selected="true"/>
<item android:drawable="@drawable/ic_format_quote_grey" android:state_selected="false"/>
</selector>

8
app/src/main/res/layout-v21/activity_topic_post_row.xml

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:orientation="vertical"
android:paddingEnd="4dp" android:paddingEnd="4dp"
android:paddingStart="4dp" android:paddingStart="4dp"
@ -125,8 +125,10 @@
android:layout_height="@dimen/quote_button" android:layout_height="@dimen/quote_button"
android:layout_marginEnd="9dp" android:layout_marginEnd="9dp"
android:layout_marginTop="9dp" android:layout_marginTop="9dp"
android:background="@drawable/ic_toggle_quote_bg" android:background="@color/card_background"
android:contentDescription="@string/quote"/> android:clickable="true"
android:contentDescription="@string/quote"
android:src="@drawable/ic_format_quote_unchecked"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

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

@ -123,8 +123,10 @@
android:layout_height="@dimen/quote_button" android:layout_height="@dimen/quote_button"
android:layout_marginEnd="9dp" android:layout_marginEnd="9dp"
android:layout_marginTop="9dp" android:layout_marginTop="9dp"
android:background="@drawable/ic_toggle_quote_bg" android:background="@color/card_background"
android:contentDescription="@string/quote"/> android:clickable="true"
android:contentDescription="@string/quote"
android:src="@drawable/ic_format_quote_unchecked"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

Loading…
Cancel
Save