Browse Source

activity_topic.xml and FAB tweaks, TopicActivity bug fix

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
2c8f3d79a6
  1. 31
      app/src/main/java/gr/thmmy/mthmmy/activities/TopicActivity.java
  2. 32
      app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java
  3. 125
      app/src/main/res/layout/activity_topic.xml

31
app/src/main/java/gr/thmmy/mthmmy/activities/TopicActivity.java

@ -60,9 +60,10 @@ public class TopicActivity extends BaseActivity {
private LinearLayout postsLinearLayout; private LinearLayout postsLinearLayout;
private static final int NO_POST_FOCUS = -1; private static final int NO_POST_FOCUS = -1;
private int postFocus = NO_POST_FOCUS; private int postFocus = NO_POST_FOCUS;
//Quote //Quote
//TODO //TODO
/* --Posts end-- */
/* --Topic's pages-- */ /* --Topic's pages-- */
private int thisPage = 1; private int thisPage = 1;
private String base_url = ""; private String base_url = "";
@ -77,11 +78,14 @@ public class TopicActivity extends BaseActivity {
private static final int SMALL_STEP = 1; private static final int SMALL_STEP = 1;
private static final int LARGE_STEP = 10; private static final int LARGE_STEP = 10;
private Integer pageValue; private Integer pageValue;
/* --Topic's pages end-- */ private ImageButton firstPage;
private ImageButton previousPage;
private ImageButton nextPage;
private ImageButton lastPage;
/* --Thumbnail-- */ /* --Thumbnail-- */
private static final int THUMBNAIL_SIZE = 80; private static final int THUMBNAIL_SIZE = 80;
private ImageLoader imageLoader = ImageController.getInstance().getImageLoader(); private ImageLoader imageLoader = ImageController.getInstance().getImageLoader();
/* --Thumbnail end-- */
//Other variables //Other variables
private ProgressBar progressBar; private ProgressBar progressBar;
@ -113,17 +117,20 @@ public class TopicActivity extends BaseActivity {
if(!Objects.equals(topicTitle, "")) if(!Objects.equals(topicTitle, ""))
actionbar.setTitle(topicTitle); actionbar.setTitle(topicTitle);
firstPage = (ImageButton) findViewById(R.id.page_first_button);
ImageButton firstPage = (ImageButton) findViewById(R.id.page_first_button); previousPage = (ImageButton) findViewById(R.id.page_previous_button);
ImageButton previousPage = (ImageButton) findViewById(R.id.page_previous_button);
pageIndicator = (TextView) findViewById(R.id.page_indicator); pageIndicator = (TextView) findViewById(R.id.page_indicator);
ImageButton nextPage = (ImageButton) findViewById(R.id.page_next_button); nextPage = (ImageButton) findViewById(R.id.page_next_button);
ImageButton lastPage = (ImageButton) findViewById(R.id.page_last_button); lastPage = (ImageButton) findViewById(R.id.page_last_button);
initDecrementButton(firstPage, LARGE_STEP); initDecrementButton(firstPage, LARGE_STEP);
initDecrementButton(previousPage, SMALL_STEP); initDecrementButton(previousPage, SMALL_STEP);
initIncrementButton(nextPage, SMALL_STEP); initIncrementButton(nextPage, SMALL_STEP);
initIncrementButton(lastPage, LARGE_STEP); initIncrementButton(lastPage, LARGE_STEP);
firstPage.setEnabled(false);
previousPage.setEnabled(false);
nextPage.setEnabled(false);
lastPage.setEnabled(false);
new TopicTask().execute(extras.getString("TOPIC_URL")); //Attempt data parsing new TopicTask().execute(extras.getString("TOPIC_URL")); //Attempt data parsing
} }
@ -501,6 +508,12 @@ public class TopicActivity extends BaseActivity {
} }
} }
//Now that parsing is complete and we have the url for every page enable page nav buttons
firstPage.setEnabled(true);
previousPage.setEnabled(true);
nextPage.setEnabled(true);
lastPage.setEnabled(true);
//Initialize an inflater //Initialize an inflater
LayoutInflater inflater = (LayoutInflater) getApplicationContext() LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@ -662,7 +675,7 @@ public class TopicActivity extends BaseActivity {
private float downCoordinateY; private float downCoordinateY;
private final float SCROLL_THRESHOLD = 7; private final float SCROLL_THRESHOLD = 7;
Runnable WebViewLongClick = new Runnable() { final Runnable WebViewLongClick = new Runnable() {
public void run() { public void run() {
wasLongClick = true; wasLongClick = true;
//TODO //TODO

32
app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareFABBehavior.java

@ -0,0 +1,32 @@
package gr.thmmy.mthmmy.utils;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.util.AttributeSet;
import android.view.View;
public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {
public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
super();
}
@Override
public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child,
final View directTargetChild, final View target, final int nestedScrollAxes) {
return true;
}
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout,
final FloatingActionButton child,
final View target, final int dxConsumed, final int dyConsumed,
final int dxUnconsumed, final int dyUnconsumed) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed,dxUnconsumed, dyUnconsumed);
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
child.hide();
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
child.show();
}
}
}

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

@ -1,17 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent" android:id="@+id/main_content"
android:background="@color/background" android:layout_width="match_parent"
tools:context="gr.thmmy.mthmmy.activities.TopicActivity"> android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activities.MainActivity">
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentTop="true" android:layout_gravity="top|start"
android:layout_marginBottom="50dp" android:layout_marginBottom="50dp"
android:background="@color/background"
android:scrollbars="none" android:scrollbars="none"
tools:context="gr.thmmy.mthmmy.activities.TopicActivity"> tools:context="gr.thmmy.mthmmy.activities.TopicActivity">
@ -27,77 +30,75 @@
</ScrollView> </ScrollView>
<FrameLayout <LinearLayout
android:id="@+id/bottom_navigation_bar" android:id="@+id/bottom_navigation_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="50dp"
android:layout_alignParentBottom="true" android:layout_gravity="bottom|end"
android:layout_marginTop="-2dp" android:layout_marginTop="-2dp"
android:elevation="8dp" app:elevation="8dp">
android:outlineProvider="bounds">
<LinearLayout <ImageButton
android:id="@+id/bottom_navigation_bar_content" android:id="@+id/page_first_button"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primary_dark" android:layout_weight="0.8"
android:orientation="horizontal"> android:background="@color/primary"
android:contentDescription="@string/text_first"
app:srcCompat="@drawable/page_first"/>
<ImageButton <ImageButton
android:id="@+id/page_first_button" android:id="@+id/page_previous_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@string/text_first" android:layout_weight="0.8"
app:srcCompat="@drawable/page_first"/> android:background="@color/primary"
android:contentDescription="@string/text_previous"
<ImageButton app:srcCompat="@drawable/page_previous"/>
android:id="@+id/page_previous_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/text_previous"
app:srcCompat="@drawable/page_previous"/>
<TextView <TextView
android:id="@+id/page_indicator" android:id="@+id/page_indicator"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center" android:gravity="center"
android:hint="@string/text_page" android:hint="@string/text_page"
android:maxLines="1" android:maxLines="1"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="22sp"/> android:textSize="22sp"/>
<ImageButton <ImageButton
android:id="@+id/page_next_button" android:id="@+id/page_next_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@string/text_next" android:layout_weight="0.8"
app:srcCompat="@drawable/page_next"/> android:background="@color/primary"
android:contentDescription="@string/text_next"
app:srcCompat="@drawable/page_next"/>
<ImageButton <ImageButton
android:id="@+id/page_last_button" android:id="@+id/page_last_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:contentDescription="@string/text_last" android:layout_weight="0.8"
app:srcCompat="@drawable/page_last"/> android:background="@color/primary"
android:contentDescription="@string/text_last"
app:srcCompat="@drawable/page_last"/>
<Space <Space
android:layout_width="80dp" android:layout_width="80dp"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
</LinearLayout> </LinearLayout>
</FrameLayout>
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/fab" android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin" android:layout_margin="@dimen/fab_margin"
android:elevation="12dp" app:elevation="12dp"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior"
app:srcCompat="@drawable/ic_add_fab"/> app:srcCompat="@drawable/ic_add_fab"/>
<ProgressBar <ProgressBar
@ -107,6 +108,6 @@
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:visibility="invisible"/> android:visibility="invisible"/>
</RelativeLayout> </android.support.design.widget.CoordinatorLayout>

Loading…
Cancel
Save