Browse Source

Bottom navigation bar behavior. Code cleanup and fixes.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
db4d36003a
  1. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java
  2. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  3. 2
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  4. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  5. 21
      app/src/main/java/gr/thmmy/mthmmy/utils/FileManager/ThmmyFile.java
  6. 122
      app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java
  7. BIN
      app/src/main/res/drawable/fun.gif
  8. BIN
      app/src/main/res/drawable/fun.jpg
  9. 24
      app/src/main/res/layout-v21/activity_profile.xml
  10. 8
      app/src/main/res/layout/activity_about.xml
  11. 15
      app/src/main/res/layout/activity_topic.xml
  12. 20
      app/src/main/res/values/colors.xml
  13. 2
      app/src/main/res/values/strings.xml
  14. 4
      app/src/main/res/values/styles.xml

2
app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java

@ -44,7 +44,7 @@ public class AboutActivity extends BaseActivity {
drawer.setSelection(ABOUT_ID); drawer.setSelection(ABOUT_ID);
final ScrollView mainContent = (ScrollView) findViewById(R.id.scrollview); final ScrollView mainContent = (ScrollView) findViewById(R.id.scrollview);
trollGif = (FrameLayout) findViewById(R.id.trollGifFrame); trollGif = (FrameLayout) findViewById(R.id.trollPicFrame);
TextView tv = (TextView) findViewById(R.id.version); TextView tv = (TextView) findViewById(R.id.version);
if (tv != null) if (tv != null)

2
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -89,7 +89,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF
@Override @Override
public void onRecentFragmentInteraction(TopicSummary topicSummary) { public void onRecentFragmentInteraction(TopicSummary topicSummary) {
Intent i = new Intent(MainActivity.this, TopicActivity.class); Intent i = new Intent(MainActivity.this, TopicActivity.class);
i.putExtra(EXTRAS_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic=67565.0"); i.putExtra(EXTRAS_TOPIC_URL, topicSummary.getTopicUrl());
i.putExtra(EXTRAS_TOPIC_TITLE, topicSummary.getTitle()); i.putExtra(EXTRAS_TOPIC_TITLE, topicSummary.getTitle());
startActivity(i); startActivity(i);
} }

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

@ -312,7 +312,7 @@ public class TopicActivity extends BaseActivity {
if (topicTask != null && topicTask.getStatus() != AsyncTask.Status.RUNNING) if (topicTask != null && topicTask.getStatus() != AsyncTask.Status.RUNNING)
topicTask.cancel(true); topicTask.cancel(true);
//topicTask = new TopicTask(); topicTask = new TopicTask();
topicTask.execute(pagesUrls.get(pageRequested)); //Attempt data parsing topicTask.execute(pagesUrls.get(pageRequested)); //Attempt data parsing
} }

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

@ -29,7 +29,6 @@ import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -612,7 +611,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> {
@Override @Override
protected String doInBackground(ThmmyFile... files) { protected String doInBackground(ThmmyFile... files) {
try { try {
File tempFile = files[0].download(PACKAGE_NAME); File tempFile = files[0].download();
if (tempFile != null) { if (tempFile != null) {
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension( String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
files[0].getExtension()); files[0].getExtension());

21
app/src/main/java/gr/thmmy/mthmmy/utils/FileManager/ThmmyFile.java

@ -104,26 +104,11 @@ public class ThmmyFile {
this.filePath = filePath; this.filePath = filePath;
} }
/**
* Used to download the file. If download is successful file's extension and path will be assigned
* to object's fields and can be accessed using getter methods.
* <p>File is stored in sdcard1/Android/data/Downloads/{@link #NO_PACKAGE_FOLDER_NAME}</p>
*
* @return the {@link File} if successful, null otherwise
* @throws IOException
* @throws SecurityException
*/
@Nullable
public File download() throws IOException, SecurityException {
return download(NO_PACKAGE_FOLDER_NAME);
}
/** /**
* Used to download the file. If download is successful file's extension and path will be assigned * Used to download the file. If download is successful file's extension and path will be assigned
* to object's fields and can be accessed using getter methods. * to object's fields and can be accessed using getter methods.
* <p>File is stored in sdcard1/Android/data/Downloads/packageName</p> * <p>File is stored in sdcard1/Android/data/Downloads/packageName</p>
* *
* @param packageName package's name to use as folder name for file's path
* @return the {@link File} if successful, null otherwise * @return the {@link File} if successful, null otherwise
* @throws IOException if the request could not be executed due to cancellation, a connectivity * @throws IOException if the request could not be executed due to cancellation, a connectivity
* problem or timeout. Because networks can fail during an exchange, it is possible that the * problem or timeout. Because networks can fail during an exchange, it is possible that the
@ -131,7 +116,7 @@ public class ThmmyFile {
* @throws SecurityException if the requested file is not hosted by the forum. * @throws SecurityException if the requested file is not hosted by the forum.
*/ */
@Nullable @Nullable
public File download(final String packageName) throws IOException, SecurityException { public File download() throws IOException, SecurityException {
if (!Objects.equals(fileUrl.getHost(), "www.thmmy.gr")) if (!Objects.equals(fileUrl.getHost(), "www.thmmy.gr"))
throw new SecurityException("Downloading files from other sources is not supported"); throw new SecurityException("Downloading files from other sources is not supported");
@ -141,7 +126,7 @@ public class ThmmyFile {
if (!response.isSuccessful()) { if (!response.isSuccessful()) {
throw new IOException("Failed to download file: " + response); throw new IOException("Failed to download file: " + response);
} }
file = getOutputMediaFile(packageName, filename); file = getOutputMediaFile(filename);
if (file == null) { if (file == null) {
Report.d(TAG, "Error creating media file, check storage permissions!"); Report.d(TAG, "Error creating media file, check storage permissions!");
} else { } else {
@ -157,7 +142,7 @@ public class ThmmyFile {
} }
@Nullable @Nullable
private static File getOutputMediaFile(String packageName, String fileName) { private static File getOutputMediaFile(String fileName) {
// To be safe, you should check that the SDCard is mounted // To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this. // using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStorageDirectory() File mediaStorageDir = new File(Environment.getExternalStorageDirectory()

122
app/src/main/java/gr/thmmy/mthmmy/utils/ScrollAwareLinearBehavior.java

@ -0,0 +1,122 @@
package gr.thmmy.mthmmy.utils;
import android.animation.Animator;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewPropertyAnimator;
/**
* CoordinatorLayout Behavior for bottom navigation bar.
* <p>When a nested ScrollView is scrolled down, the view will disappear.
* When the ScrollView is scrolled back up, the view will reappear.</p>
*/
public class ScrollAwareLinearBehavior extends CoordinatorLayout.Behavior<View> {
private int mDySinceDirectionChange;
private boolean mIsShowing;
private boolean mIsHiding;
public ScrollAwareLinearBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {
return (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0;
}
@Override
public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dx, int dy, int[] consumed) {
if (dy > 0 && mDySinceDirectionChange < 0
|| dy < 0 && mDySinceDirectionChange > 0) {
child.animate().cancel();
mDySinceDirectionChange = 0;
}
mDySinceDirectionChange += dy;
if (mDySinceDirectionChange > child.getHeight()
&& child.getVisibility() == View.VISIBLE
&& !mIsHiding) {
hide(child);
} else if (mDySinceDirectionChange < 0
&& child.getVisibility() == View.INVISIBLE
&& !mIsShowing) {
show(child);
}
}
private void hide(final View view) {
mIsHiding = true;
ViewPropertyAnimator animator = view.animate()
.translationY(view.getHeight())
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(100);
animator.setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
// Prevent drawing the View after it is gone
mIsHiding = false;
view.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationCancel(Animator animator) {
// Canceling a hide should show the view
mIsHiding = false;
if (!mIsShowing) {
show(view);
}
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.start();
}
private void show(final View view) {
mIsShowing = true;
ViewPropertyAnimator animator = view.animate()
.translationY(0)
.setInterpolator(new FastOutSlowInInterpolator())
.setDuration(100);
animator.setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
view.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animator animator) {
mIsShowing = false;
}
@Override
public void onAnimationCancel(Animator animator) {
// Canceling a show should hide the view
mIsShowing = false;
if (!mIsHiding) {
hide(view);
}
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.start();
}
}

BIN
app/src/main/res/drawable/fun.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 MiB

BIN
app/src/main/res/drawable/fun.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

24
app/src/main/res/layout-v21/activity_profile.xml

@ -73,18 +73,8 @@
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:theme="@style/AppTheme"
android:visibility="invisible"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|center"/>
<android.support.v4.widget.NestedScrollView <android.support.v4.widget.NestedScrollView
android:id="@+id/nested_scroll"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="top|start" android:layout_gravity="top|start"
@ -105,6 +95,18 @@
</LinearLayout> </LinearLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="@+id/progressBar"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal.NoPadding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:visibility="invisible"
app:layout_anchor="@id/nested_scroll"
app:layout_anchorGravity="top|center"
app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal"/>
<android.support.design.widget.FloatingActionButton <android.support.design.widget.FloatingActionButton
android:id="@+id/profile_fab" android:id="@+id/profile_fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"

8
app/src/main/res/layout/activity_about.xml

@ -86,18 +86,18 @@
</ScrollView> </ScrollView>
<FrameLayout <FrameLayout
android:id="@+id/trollGifFrame" android:id="@+id/trollPicFrame"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center" android:layout_gravity="center"
android:visibility="gone"> android:visibility="gone">
<pl.droidsonroids.gif.GifImageView <ImageView
android:id="@+id/trollGif" android:id="@+id/trollPic"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:contentDescription="@string/trollGif" android:contentDescription="@string/trollPic"
android:foregroundGravity="center" android:foregroundGravity="center"
android:src="@drawable/fun" android:src="@drawable/fun"
/> />

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

@ -30,20 +30,20 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="top|start" android:layout_gravity="top|start"
android:layout_marginBottom="50dp"
android:layout_marginTop="64dp" android:layout_marginTop="64dp"
android:background="@color/background" android:background="@color/background"
android:scrollbars="none" android:scrollbars="none"
tools:context="gr.thmmy.mthmmy.activities.topic.TopicActivity"> tools:context="gr.thmmy.mthmmy.activities.topic.TopicActivity">
</android.support.v7.widget.RecyclerView> </android.support.v7.widget.RecyclerView>
<android.support.v7.widget.FitWindowsLinearLayout <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_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginTop="-2dp" android:background="@color/primary"
app:elevation="8dp"> app:elevation="8dp"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareLinearBehavior">
<ImageButton <ImageButton
android:id="@+id/page_first_button" android:id="@+id/page_first_button"
@ -88,7 +88,7 @@
android:layout_weight="0.8" android:layout_weight="0.8"
android:contentDescription="@string/text_last" android:contentDescription="@string/text_last"
app:srcCompat="@drawable/page_last"/> app:srcCompat="@drawable/page_last"/>
</android.support.v7.widget.FitWindowsLinearLayout> </LinearLayout>
<me.zhanghai.android.materialprogressbar.MaterialProgressBar <me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="@+id/progressBar" android:id="@+id/progressBar"
@ -107,11 +107,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginBottom="54dp" android:layout_marginBottom="50dp"
android:layout_marginEnd="@dimen/fab_margins" android:layout_marginEnd="@dimen/fab_margins"
app:borderWidth="0dp"
app:layout_anchor="@id/topic_recycler_view"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior" app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareFABBehavior"
app:srcCompat="@drawable/ic_add_fab"/> app:srcCompat="@drawable/ic_add_fab"/>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

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

@ -5,24 +5,6 @@
in the style.css file! in the style.css file!
--> -->
<!--Indigo-->
<!--<color name="primary">#3F51B5</color>
<color name="primary_dark">#303F9F</color>
<color name="primary_light">#C5CAE9</color>
<color name="accent">#009688</color>
<color name="primary_text">#000000</color>
<color name="secondary_text">#757575</color>
<color name="card_background">#FFFFFF</color>
<color name="divider">#8B8B8B</color>
<color name="transparent">#00000000</color>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="iron">#CCCCCC</color>
<color name="card_expand_text_color">#464646</color>
<color name="background">#D3D3D3</color>
<color name="dialog_bg_semi_transparent">#80212c6f</color>-->
<!--Dark--> <!--Dark-->
<color name="primary">#2B2B2B</color> <color name="primary">#2B2B2B</color>
<color name="primary_dark">#333333</color> <color name="primary_dark">#333333</color>
@ -38,5 +20,5 @@
<color name="white">#FFFFFF</color> <color name="white">#FFFFFF</color>
<color name="iron">#CCCCCC</color> <color name="iron">#CCCCCC</color>
<color name="card_expand_text_color">#E7E7E7</color> <color name="card_expand_text_color">#E7E7E7</color>
<color name="dialog_bg_semi_transparent">#8026A69A</color> <color name="dialog_bg_semi_transparent">#D926A69A</color>
</resources> </resources>

2
app/src/main/res/values/strings.xml

@ -10,7 +10,7 @@
<string name="about">About</string> <string name="about">About</string>
<string name="version">v%1$s</string> <string name="version">v%1$s</string>
<string name="logo">Logo</string> <string name="logo">Logo</string>
<string name="trollGif">You should watch a funny gif!</string> <string name="trollPic">You should watch a funny pic!</string>
<string name="login">Login</string> <string name="login">Login</string>
<string name="login_spinner">Authenticating&#8230;</string> <string name="login_spinner">Authenticating&#8230;</string>
<string name="logout">Logout</string> <string name="logout">Logout</string>

4
app/src/main/res/values/styles.xml

@ -38,9 +38,9 @@
</style> </style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> <style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/accent</item> <item name="colorAccent">@color/iron</item>
<item name="android:textColorPrimary">@color/primary_text</item> <item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:background">@color/dialog_bg_semi_transparent</item> <item name="android:colorBackground">@color/dialog_bg_semi_transparent</item>
</style> </style>
</resources> </resources>

Loading…
Cancel
Save