mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
hide toolbar and fab on doc list scroll
This commit is contained in:
parent
108d5ae830
commit
d4fe719a2c
@ -28,6 +28,7 @@
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:windowSoftInputMode="adjustNothing">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
@ -43,6 +44,9 @@
|
||||
<activity
|
||||
android:name=".activity.DocumentViewActivity"
|
||||
android:label="">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.DocumentEditActivity"
|
||||
|
@ -9,11 +9,13 @@ import android.provider.SearchRecentSuggestions;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.TextView;
|
||||
@ -61,7 +63,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.main_activity);
|
||||
|
||||
// Enable ActionBar app icon to behave as action to toggle nav drawer
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawerLayout = findViewById(R.id.drawer_layout);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
|
||||
setSupportActionBar(toolbar);
|
||||
if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
@ -75,15 +80,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// Fill the drawer user info
|
||||
JSONObject userInfo = ApplicationContext.getInstance().getUserInfo();
|
||||
TextView usernameTextView = (TextView) findViewById(R.id.usernameTextView);
|
||||
TextView usernameTextView = findViewById(R.id.usernameTextView);
|
||||
usernameTextView.setText(userInfo.optString("username"));
|
||||
TextView emailTextView = (TextView) findViewById(R.id.emailTextView);
|
||||
TextView emailTextView = findViewById(R.id.emailTextView);
|
||||
emailTextView.setText(userInfo.optString("email"));
|
||||
|
||||
// Get tag list to fill the drawer
|
||||
final ListView tagListView = (ListView) findViewById(R.id.tagListView);
|
||||
final ListView tagListView = findViewById(R.id.tagListView);
|
||||
final View tagProgressView = findViewById(R.id.tagProgressView);
|
||||
final TextView tagEmptyView = (TextView) findViewById(R.id.tagEmptyView);
|
||||
final TextView tagEmptyView = findViewById(R.id.tagEmptyView);
|
||||
tagListView.setEmptyView(tagProgressView);
|
||||
JSONObject cacheTags = PreferenceUtil.getCachedJson(this, PreferenceUtil.PREF_CACHED_TAGS_JSON);
|
||||
if (cacheTags != null) {
|
||||
@ -145,6 +150,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
// Add document button
|
||||
ImageButton addDocumentButton = findViewById(R.id.addDocumentButton);
|
||||
addDocumentButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(MainActivity.this, DocumentEditActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
handleIntent(getIntent());
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
@ -2,6 +2,7 @@ package com.sismics.docs.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
@ -9,12 +10,10 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.sismics.docs.R;
|
||||
import com.sismics.docs.activity.DocumentEditActivity;
|
||||
import com.sismics.docs.activity.DocumentViewActivity;
|
||||
import com.sismics.docs.adapter.DocListAdapter;
|
||||
import com.sismics.docs.event.DocumentAddEvent;
|
||||
@ -46,11 +45,6 @@ public class DocListFragment extends Fragment {
|
||||
*/
|
||||
private String query;
|
||||
|
||||
/**
|
||||
* Request code of adding document.
|
||||
*/
|
||||
private static final int REQUEST_CODE_ADD_DOCUMENT = 1;
|
||||
|
||||
// View cache
|
||||
private EmptyRecyclerView recyclerView;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
@ -60,11 +54,11 @@ public class DocListFragment extends Fragment {
|
||||
private int previousTotal = 0;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.doc_list_fragment, container, false);
|
||||
|
||||
// Configure the RecyclerView
|
||||
recyclerView = (EmptyRecyclerView) view.findViewById(R.id.docList);
|
||||
recyclerView = view.findViewById(R.id.docList);
|
||||
adapter = new DocListAdapter();
|
||||
recyclerView.setAdapter(adapter);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
@ -122,16 +116,6 @@ public class DocListFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
// Add document button
|
||||
ImageButton addDocumentButton = (ImageButton) view.findViewById(R.id.addDocumentButton);
|
||||
addDocumentButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(getActivity(), DocumentEditActivity.class);
|
||||
startActivityForResult(intent, REQUEST_CODE_ADD_DOCUMENT);
|
||||
}
|
||||
});
|
||||
|
||||
// Grab the documents
|
||||
loadDocuments(view, true);
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
package com.sismics.docs.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.sismics.docs.R;
|
||||
|
||||
public class ScrollingFABBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {
|
||||
private int toolbarHeight;
|
||||
|
||||
public ScrollingFABBehavior(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.toolbarHeight = getToolbarHeight(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean layoutDependsOn(@NonNull CoordinatorLayout parent, @NonNull FloatingActionButton fab, @NonNull View dependency) {
|
||||
return dependency instanceof AppBarLayout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDependentViewChanged(@NonNull CoordinatorLayout parent, @NonNull FloatingActionButton fab, @NonNull View dependency) {
|
||||
if (dependency instanceof AppBarLayout) {
|
||||
CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
|
||||
int fabBottomMargin = lp.bottomMargin;
|
||||
int distanceToScroll = fab.getHeight() + fabBottomMargin;
|
||||
float ratio = dependency.getY() /(float) toolbarHeight;
|
||||
fab.setTranslationY(- distanceToScroll * ratio);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getToolbarHeight(Context context) {
|
||||
final TypedArray styledAttributes = context.getTheme().obtainStyledAttributes(
|
||||
new int[] { R.attr.actionBarSize });
|
||||
int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
|
||||
styledAttributes.recycle();
|
||||
|
||||
return toolbarHeight;
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@ -37,17 +36,4 @@
|
||||
android:textSize="16sp"
|
||||
android:layout_centerInParent="true"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/addDocumentButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:src="@drawable/ic_add_white_24dp"
|
||||
app:fabSize="normal"/>
|
||||
|
||||
</RelativeLayout>
|
@ -6,11 +6,47 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/main_fragment"
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/overview_coordinator_layout"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
class="com.sismics.docs.fragment.DocListFragment"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
|
||||
app:layout_scrollFlags="enterAlways|scroll|snap" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/main_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
class="com.sismics.docs.fragment.DocListFragment"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/addDocumentButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="16dp"
|
||||
android:src="@drawable/ic_add_white_24dp"
|
||||
app:layout_anchor="@id/main_fragment"
|
||||
app:layout_behavior="com.sismics.docs.ui.ScrollingFABBehavior"
|
||||
app:layout_anchorGravity="bottom|right|end"
|
||||
app:fabSize="normal"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/left_drawer"
|
||||
|
@ -6,6 +6,14 @@
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
|
Loading…
Reference in New Issue
Block a user