Implement nice material animation for done/clear buttons

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2018-03-08 20:39:32 +01:00
Родитель 8ae9ccc9af
Коммит 2087598db3
8 изменённых файлов: 105 добавлений и 192 удалений

Просмотреть файл

@ -1,5 +1,5 @@
<component name="CopyrightManager">
<settings>
<settings default="GPL3">
<module2copyright>
<element module="Project Files" copyright="GPL3" />
</module2copyright>

Просмотреть файл

@ -1,80 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.adapters.items;
import android.view.View;
import com.nextcloud.talk.R;
import java.util.List;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
import eu.davidea.flexibleadapter.items.IFlexible;
import eu.davidea.viewholders.FlexibleViewHolder;
public class EmptyFooterItem extends AbstractFlexibleItem<EmptyFooterItem.EmptyFooterItemViewHolder> {
int id;
public EmptyFooterItem(int id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
if (o instanceof EmptyFooterItem) {
EmptyFooterItem inItem = (EmptyFooterItem) o;
return id == inItem.getModel();
}
return false;
}
public int getModel() {
return id;
}
@Override
public int getLayoutRes() {
return R.layout.rv_item_empty_footer;
}
@Override
public void bindViewHolder(FlexibleAdapter<IFlexible> adapter, EmptyFooterItemViewHolder holder,
int position, List<Object> payloads) {
}
@Override
public EmptyFooterItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
return new EmptyFooterItemViewHolder(view, adapter);
}
static class EmptyFooterItemViewHolder extends FlexibleViewHolder {
/**
* Default constructor.
*/
EmptyFooterItemViewHolder(View view, FlexibleAdapter adapter) {
super(view, adapter);
}
}
}

Просмотреть файл

@ -29,6 +29,7 @@ import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.DividerItemDecoration;
@ -46,7 +47,6 @@ import android.view.ViewTreeObserver;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.LinearLayout;
import com.bluelinelabs.conductor.RouterTransaction;
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
@ -54,7 +54,6 @@ import com.bluelinelabs.conductor.changehandler.VerticalChangeHandler;
import com.kennyc.bottomsheet.BottomSheet;
import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.CallActivity;
import com.nextcloud.talk.adapters.items.EmptyFooterItem;
import com.nextcloud.talk.adapters.items.NewCallHeaderItem;
import com.nextcloud.talk.adapters.items.UserHeaderItem;
import com.nextcloud.talk.adapters.items.UserItem;
@ -72,6 +71,7 @@ import com.nextcloud.talk.models.json.sharees.Sharee;
import com.nextcloud.talk.models.json.sharees.ShareesOverall;
import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.KeyboardUtils;
import com.nextcloud.talk.utils.animations.ViewHidingBehaviourAnimation;
import com.nextcloud.talk.utils.bundle.BundleKeys;
import com.nextcloud.talk.utils.database.user.UserUtils;
@ -129,9 +129,8 @@ public class ContactsController extends BaseController implements SearchView.OnQ
@BindView(R.id.swipe_refresh_layout)
SwipeRefreshLayout swipeRefreshLayout;
@Nullable
@BindView(R.id.bottom_buttons_layout)
LinearLayout bottomButtonsLinearLayout;
CoordinatorLayout bottomButtonsLinearLayout;
@BindView(R.id.fast_scroller)
FastScroller fastScroller;
@ -546,6 +545,9 @@ public class ContactsController extends BaseController implements SearchView.OnQ
return ((UserHeaderItem) adapter.getItem(position)).getModel();
}
});
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) bottomButtonsLinearLayout.getLayoutParams();
layoutParams.setBehavior(new ViewHidingBehaviourAnimation());
}
private void dispose(@Nullable Disposable disposable) {
@ -634,17 +636,6 @@ public class ContactsController extends BaseController implements SearchView.OnQ
} else if (bottomButtonsLinearLayout != null) {
bottomButtonsLinearLayout.setVisibility(View.GONE);
}
if (bottomButtonsLinearLayout != null && bottomButtonsLinearLayout.getVisibility() == View.VISIBLE) {
if (adapter.getScrollableFooters().size() == 0) {
adapter.addScrollableFooterWithDelay(new EmptyFooterItem(999), 0, layoutManager
.findLastVisibleItemPosition() == adapter.getItemCount() - 1);
}
} else {
if (adapter != null) {
adapter.removeAllScrollableFooters();
}
}
}
@Override

Просмотреть файл

@ -44,7 +44,7 @@ import com.bluelinelabs.conductor.changehandler.FadeChangeHandler;
import com.nextcloud.talk.R;
import com.nextcloud.talk.controllers.base.BaseController;
import com.nextcloud.talk.utils.BottomNavigationUtils;
import com.nextcloud.talk.utils.animations.BottomNavigationViewBehaviourAnimation;
import com.nextcloud.talk.utils.animations.ViewHidingBehaviourAnimation;
import com.nextcloud.talk.utils.bundle.BundleBuilder;
import butterknife.BindView;
@ -131,7 +131,7 @@ public abstract class BottomNavigationController extends BaseController {
});
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) bottomNavigationView.getLayoutParams();
layoutParams.setBehavior(new BottomNavigationViewBehaviourAnimation());
layoutParams.setBehavior(new ViewHidingBehaviourAnimation());
}
@Override

Просмотреть файл

@ -1,71 +0,0 @@
/*
* MIT License
*
* Copyright (c) 2016 Srijith Narayanan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.nextcloud.talk.utils.animations;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewCompat;
import android.view.View;
/**
* Created by Srijith on 22-12-2016.
* Copied for this project from https://github.com/sjthn/BottomNavigationViewBehavior/blob/master/app/src/main/java/com/example/srijith/bottomnavigationviewbehavior/BottomNavigationViewBehavior.java
*/
public class BottomNavigationViewBehaviourAnimation extends CoordinatorLayout.Behavior<BottomNavigationView> {
private int height;
@Override
public boolean onLayoutChild(CoordinatorLayout parent, BottomNavigationView child, int layoutDirection) {
height = child.getHeight();
return super.onLayoutChild(parent, child, layoutDirection);
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View directTargetChild, View target, int nestedScrollAxes) {
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, BottomNavigationView child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
if (dyConsumed > 0) {
slideDown(child);
} else if (dyConsumed < 0) {
slideUp(child);
}
}
private void slideUp(BottomNavigationView child) {
child.clearAnimation();
child.animate().translationY(0).setDuration(200);
}
private void slideDown(BottomNavigationView child) {
child.clearAnimation();
child.animate().translationY(height).setDuration(200);
}
}

Просмотреть файл

@ -0,0 +1,68 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* The original code is Copyright (c) 2016 Srijith Narayanan under MIT licence
* https://github.com/sjthn/BottomNavigationViewBehavior/blob/9558104a16a1276bd8a73fba6736d88cd25b5488/app/src/main/java/com/example/srijith/bottomnavigationviewbehavior/BottomNavigationViewBehavior.java
* and of course modified by yours truly.
*/
package com.nextcloud.talk.utils.animations;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewCompat;
import android.view.View;
public class ViewHidingBehaviourAnimation extends CoordinatorLayout.Behavior<View> {
private int height;
@Override
public boolean onLayoutChild(CoordinatorLayout parent, View child, int layoutDirection) {
height = child.getHeight();
return super.onLayoutChild(parent, child, layoutDirection);
}
@Override
public boolean onStartNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View directTargetChild, @NonNull View
target, int nestedScrollAxes) {
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}
@Override
public void onNestedScroll(@NonNull CoordinatorLayout coordinatorLayout, @NonNull View child, @NonNull View target, int dxConsumed, int
dyConsumed, int dxUnconsumed, int dyUnconsumed) {
if (dyConsumed > 0) {
slideDown(child);
} else if (dyConsumed < 0) {
slideUp(child);
}
}
private void slideUp(View child) {
child.clearAnimation();
child.animate().translationY(0).setDuration(200);
}
private void slideDown(View child) {
child.clearAnimation();
child.animate().translationY(height).setDuration(200);
}
}

Просмотреть файл

@ -19,7 +19,7 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_buttons_layout"
android:layout_width="match_parent"
android:layout_height="48dp"
@ -29,26 +29,31 @@
android:orientation="horizontal"
android:visibility="visible">
<Button
android:id="@+id/clear_button"
style="?android:attr/borderlessButtonStyle"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@color/nc_darkRed"
android:text="@string/nc_contacts_clear"
android:textAlignment="center"
android:textColor="@color/nc_white_color_complete"/>
android:layout_height="wrap_content">
<Button
android:id="@+id/done_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="@color/nc_darkGreen"
android:text="@string/nc_contacts_done"
android:textAlignment="center"
android:textColor="@color/nc_white_color_complete"/>
<Button
android:id="@+id/clear_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="@color/nc_darkRed"
android:text="@string/nc_contacts_clear"
android:textAlignment="center"
android:textColor="@color/nc_white_color_complete"/>
</LinearLayout>
<Button
android:id="@+id/done_button"
style="?android:attr/borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="@color/nc_darkGreen"
android:text="@string/nc_contacts_done"
android:textAlignment="center"
android:textColor="@color/nc_white_color_complete"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>

Просмотреть файл

@ -19,7 +19,7 @@
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -49,4 +49,4 @@
android:visibility="gone"/>
<include layout="@layout/fast_scroller"/>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>