Replace Floating Action Button with a custom control (and on sub item for each task type)

This commit is contained in:
Negue 2015-10-09 23:13:28 +02:00
parent 4404933f20
commit 550ee32baa
7 changed files with 224 additions and 71 deletions

View file

@ -79,10 +79,11 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/beta/1.1.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics-core/2.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.crashlytics.sdk.android/crashlytics/2.3.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.clans/fab/1.6.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.mmin18.layoutcast/library/1.1.4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.porokoro.paperboy/paperboy/2.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.instabug.library/instabugcore/1.7/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.instabug.library/instabugsupport/1.7/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.instabug.library/instabugcore/1.8-SNAPSHOT/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.instabug.library/instabugsupport/1.8-SNAPSHOT/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.mikepenz/aboutlibraries/5.0.5/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.mikepenz/iconics/1.1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.mikepenz/materialdrawer/3.0.8/jars" />
@ -113,7 +114,6 @@
<orderEntry type="library" exported="" name="okhttp-2.3.0" level="project" />
<orderEntry type="library" exported="" name="rxjava-1.0.10" level="project" />
<orderEntry type="library" exported="" name="antlr4-4.5" level="project" />
<orderEntry type="library" exported="" name="instabugsupport-1.7" level="project" />
<orderEntry type="library" exported="" name="crashlytics-core-2.3.0" level="project" />
<orderEntry type="library" exported="" name="aboutlibraries-5.0.5" level="project" />
<orderEntry type="library" exported="" name="antlr4-runtime-4.5" level="project" />
@ -125,8 +125,8 @@
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
<orderEntry type="library" exported="" name="compilerCommon-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="compiler-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="mimecraft-1.1.1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
<orderEntry type="library" exported="" name="iconics-1.1.0" level="project" />
<orderEntry type="library" exported="" name="auto-service-1.0-rc2" level="project" />
@ -134,14 +134,16 @@
<orderEntry type="library" exported="" name="fabric-1.3.1" level="project" />
<orderEntry type="library" exported="" name="beta-1.1.2" level="project" />
<orderEntry type="library" exported="" name="gridlayout-v7-22.2.1" level="project" />
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
<orderEntry type="library" exported="" name="commons-codec-1.10" level="project" />
<orderEntry type="library" exported="" name="javawriter-2.5.0" level="project" />
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
<orderEntry type="library" exported="" name="kotlin-stdlib-0.12.613" level="project" />
<orderEntry type="library" exported="" name="design-22.2.1" level="project" />
<orderEntry type="library" exported="" name="fab-1.6.1" level="project" />
<orderEntry type="library" exported="" name="instabugcore-1.8-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.613" level="project" />
<orderEntry type="library" exported="" name="DBFlow-Compiler-2.2.1" level="project" />
<orderEntry type="library" exported="" name="kotlin-runtime-0.12.613" level="project" />
<orderEntry type="library" exported="" name="answers-1.2.0" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.1" level="project" />
@ -152,13 +154,13 @@
<orderEntry type="library" exported="" name="auto-common-0.3" level="project" />
<orderEntry type="library" exported="" name="antlr-runtime-3.5.2" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
<orderEntry type="library" exported="" name="instabugsupport-1.8-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="okio-1.3.0" level="project" />
<orderEntry type="library" exported="" name="adapters-1.0-rc1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
<orderEntry type="library" exported="" name="okhttp-urlconnection-2.3.0" level="project" />
<orderEntry type="library" exported="" name="eventbus-2.4.0" level="project" />
<orderEntry type="library" exported="" name="library-2.1.4" level="project" />
<orderEntry type="library" exported="" name="instabugcore-1.7" level="project" />
<orderEntry type="library" exported="" name="crashlytics-2.3.0" level="project" />
<orderEntry type="library" exported="" name="ST4-4.0.8" level="project" />
<orderEntry type="library" exported="" name="paperboy-2.0.1" level="project" />

View file

@ -72,11 +72,15 @@ dependencies {
// Changelog Fragment, minSDK 17
compile 'com.github.porokoro.paperboy:paperboy:2.0.1'
// About View for all dependent Libraries, where are using
// About View for all dependent Libraries, we are using
compile('com.mikepenz:aboutlibraries:5.0.5@aar') {
transitive = true
}
// a better fab alternative
compile 'com.github.clans:fab:1.6.1'
// ORM
provided 'com.raizlabs.android:DBFlow-Compiler:2.2.1'
compile "com.raizlabs.android:DBFlow-Core:2.2.1"
compile "com.raizlabs.android:DBFlow:2.2.1"

View file

@ -1,6 +1,7 @@
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -8,9 +9,7 @@
android:gravity="center"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -79,5 +78,95 @@
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/fab.menu"
app:layout_behavior="com.habitrpg.android.habitica.ui.helpers.FloatingActionMenuBehavior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="8dp"
fab:menu_fab_size="normal"
fab:menu_labels_paddingTop="8dp"
fab:menu_labels_paddingRight="8dp"
fab:menu_labels_paddingBottom="8dp"
fab:menu_labels_paddingLeft="8dp"
fab:menu_colorNormal="@color/brand"
fab:menu_colorPressed="@color/brand_400"
fab:menu_colorRipple="#FFFFFF"
fab:menu_animationDelayPerItem="50"
fab:menu_icon="@drawable/fab_add"
fab:menu_buttonSpacing="2dp">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab.new.habit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/brand"
fab:fab_colorPressed="@color/brand_400"
fab:fab_colorRipple="#FFFFFF"
fab:fab_shadowColor="#000"
fab:fab_elevationCompat="6dp"
android:src="@drawable/fab_add"
fab:fab_size="mini"
fab:fab_label="New Habit" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab.new.daily"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/brand"
fab:fab_colorPressed="@color/brand_400"
fab:fab_colorRipple="#FFFFFF"
fab:fab_shadowColor="#000"
fab:fab_elevationCompat="6dp"
android:src="@drawable/ic_menu_edit"
fab:fab_size="mini"
fab:fab_label="New Daily" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab.new.todo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/brand"
fab:fab_colorPressed="@color/brand_400"
fab:fab_colorRipple="#FFFFFF"
fab:fab_shadowColor="#000"
fab:fab_elevationCompat="6dp"
android:src="@drawable/ic_menu_edit"
fab:fab_size="mini"
fab:fab_label="New Todo" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab.new.reward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/brand"
fab:fab_colorPressed="@color/brand_400"
fab:fab_colorRipple="#FFFFFF"
fab:fab_shadowColor="#000"
fab:fab_elevationCompat="6dp"
android:src="@drawable/ic_menu_edit"
fab:fab_size="mini"
fab:fab_label="New Reward" />
</com.github.clans.fab.FloatingActionMenu>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>

View file

@ -2,7 +2,6 @@
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -16,16 +15,4 @@
android:scrollbars="vertical" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:backgroundTint="@color/brand"
app:fabSize="normal"
app:layout_anchor="@id/coordinatorLayout"
app:layout_anchorGravity="bottom|right|end"
android:layout_gravity="bottom|right" />
</android.support.design.widget.CoordinatorLayout>

View file

@ -4,6 +4,7 @@ import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.Gravity;
@ -12,12 +13,11 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import com.github.clans.fab.FloatingActionMenu;
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
import com.habitrpg.android.habitica.callbacks.TaskCreationCallback;
import com.habitrpg.android.habitica.callbacks.TaskScoringCallback;
import com.habitrpg.android.habitica.callbacks.TaskUpdateCallback;
import com.habitrpg.android.habitica.events.TaskCreatedEvent;
import com.habitrpg.android.habitica.events.commands.AddNewTaskCommand;
import com.habitrpg.android.habitica.events.BuyRewardTappedEvent;
import com.habitrpg.android.habitica.events.HabitScoreEvent;
import com.habitrpg.android.habitica.events.TaskCheckedEvent;
@ -25,6 +25,7 @@ import com.habitrpg.android.habitica.events.TaskLongPressedEvent;
import com.habitrpg.android.habitica.events.TaskSaveEvent;
import com.habitrpg.android.habitica.events.TaskTappedEvent;
import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
import com.habitrpg.android.habitica.events.commands.AddNewTaskCommand;
import com.habitrpg.android.habitica.events.commands.CreateTagCommand;
import com.habitrpg.android.habitica.events.commands.FilterTasksByTagsCommand;
import com.habitrpg.android.habitica.prefs.PrefsActivity;
@ -56,6 +57,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import retrofit.Callback;
import retrofit.RetrofitError;
@ -74,6 +77,9 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
APIHelper mAPIHelper;
@InjectView(R.id.fab_menu)
FloatingActionMenu floatingMenu;
FlowContentObserver observer;
@Override
@ -134,14 +140,48 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
super.onDestroy();
}
// region onClick for the FAB Menu
@OnClick(R.id.fab_new_habit)
public void onNewHabit(View view) {
openNewTaskActivity("habit");
}
@OnClick(R.id.fab_new_daily)
public void onNewDaily(View view) {
openNewTaskActivity("daily");
}
@OnClick(R.id.fab_new_todo)
public void onNewTodo(View view) {
openNewTaskActivity("todo");
}
@OnClick(R.id.fab_new_reward)
public void onNewReward(View view) {
openNewTaskActivity("reward");
}
private void openNewTaskActivity(String type) {
Bundle bundle = new Bundle();
bundle.putString("type", type);
Intent intent = new Intent(this, TaskFormActivity.class);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityForResult(intent, TASK_CREATED_RESULT);
}
// endregion
private void showSnackbar(String content) {
showSnackbar(content, false);
}
private void showSnackbar(String content, boolean negative) {
Fragment f = ViewFragmentsDictionary.get(viewPager.getCurrentItem());
Snackbar snackbar = Snackbar.make(f.getView().findViewById(R.id.fab), content, Snackbar.LENGTH_LONG);
Snackbar snackbar = Snackbar.make(floatingMenu, content, Snackbar.LENGTH_LONG);
if (negative) {
View snackbarView = snackbar.getView();
@ -200,14 +240,7 @@ public class MainActivity extends AvatarActivityBase implements HabitRPGUserCall
}
public void onEvent(AddNewTaskCommand event) {
Bundle bundle = new Bundle();
bundle.putString("type", event.ClassType.toLowerCase());
Intent intent = new Intent(this, TaskFormActivity.class);
intent.putExtras(bundle);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityForResult(intent, TASK_CREATED_RESULT);
openNewTaskActivity(event.ClassType.toLowerCase());
}
public void onEvent(final BuyRewardTappedEvent event) {

View file

@ -1,9 +1,7 @@
package com.habitrpg.android.habitica.ui.fragments;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -14,8 +12,6 @@ import android.view.ViewGroup;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.events.commands.AddNewTaskCommand;
import com.habitrpg.android.habitica.ui.adapter.HabitItemRecyclerViewAdapter;
import com.mikepenz.iconics.IconicsDrawable;
import com.mikepenz.iconics.typeface.FontAwesome;
import de.greenrobot.event.EventBus;
@ -29,12 +25,10 @@ public class TaskRecyclerViewFragment extends Fragment implements View.OnClickLi
public RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private String classType;
private boolean showFloatingButton;
// TODO needs a bit of cleanup
public void SetInnerAdapter(HabitItemRecyclerViewAdapter adapter, String classType, boolean showFloatingButton) {
public void SetInnerAdapter(HabitItemRecyclerViewAdapter adapter, String classType) {
this.classType = classType;
this.showFloatingButton = showFloatingButton;
mAdapter = adapter;
}
@ -48,32 +42,14 @@ public class TaskRecyclerViewFragment extends Fragment implements View.OnClickLi
return view;
}
private boolean alreadyCreated;
LinearLayoutManager layoutManager = null;
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
//if (alreadyCreated)
// return;
mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
android.support.v4.app.FragmentActivity context = getActivity();
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
if (fab.getDrawable() == null) {
IconicsDrawable icon = new IconicsDrawable(context, FontAwesome.Icon.faw_plus).color(Color.WHITE).sizeDp(24);
fab.setImageDrawable(icon);
fab.setOnClickListener(this);
fab.setClickable(true);
}
fab.setVisibility(showFloatingButton ? View.VISIBLE : View.INVISIBLE);
layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
if (layoutManager == null) {
@ -82,21 +58,13 @@ public class TaskRecyclerViewFragment extends Fragment implements View.OnClickLi
mRecyclerView.setLayoutManager(layoutManager);
}
//layoutManager.setSmoothScrollbarEnabled(true);
mRecyclerView.setAdapter(mAdapter);
alreadyCreated = true;
}
public static TaskRecyclerViewFragment newInstance(HabitItemRecyclerViewAdapter adapter, String classType) {
return newInstance(adapter, classType, true);
}
public static TaskRecyclerViewFragment newInstance(HabitItemRecyclerViewAdapter adapter, String classType, boolean showFloatingButton) {
TaskRecyclerViewFragment fragment = new TaskRecyclerViewFragment();
fragment.SetInnerAdapter(adapter, classType,showFloatingButton);
fragment.SetInnerAdapter(adapter, classType);
return fragment;
}

View file

@ -0,0 +1,70 @@
package com.habitrpg.android.habitica.ui.helpers;
// https://gist.github.com/lodlock/e3cd12130bad70a098db
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.util.AttributeSet;
import android.view.View;
import com.github.clans.fab.FloatingActionMenu;
import java.util.List;
public class FloatingActionMenuBehavior extends CoordinatorLayout.Behavior {
private float mTranslationY;
public FloatingActionMenuBehavior(Context context, AttributeSet attrs) {
super();
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child, View dependency) {
if (child instanceof FloatingActionMenu && dependency instanceof Snackbar.SnackbarLayout) {
this.updateTranslation(parent, child, dependency);
}
return false;
}
private void updateTranslation(CoordinatorLayout parent, View child, View dependency) {
float translationY = this.getTranslationY(parent, child);
if (translationY != this.mTranslationY) {
ViewCompat.animate(child)
.cancel();
if (Math.abs(translationY - this.mTranslationY) == (float) dependency.getHeight()) {
ViewCompat.animate(child)
.translationY(translationY)
.setListener((ViewPropertyAnimatorListener) null);
} else {
ViewCompat.setTranslationY(child, translationY);
}
this.mTranslationY = translationY;
}
}
private float getTranslationY(CoordinatorLayout parent, View child) {
float minOffset = 0.0F;
List dependencies = parent.getDependencies(child);
int i = 0;
for (int z = dependencies.size(); i < z; ++i) {
View view = (View) dependencies.get(i);
if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(child, view)) {
minOffset = Math.min(minOffset, ViewCompat.getTranslationY(view) - (float) view.getHeight());
}
}
return minOffset;
}
}