-
Notifications
You must be signed in to change notification settings - Fork 45
SQ-166/Empty state(s) for favourites #188
Changes from all commits
9692cca
0fc70a3
b35fefc
34a6f2b
5128ba6
346dbac
a1a7b44
92459d2
855bddf
0b61006
4cfe216
4c71799
9e3857c
5b0599d
665e8cb
587834e
53a2a9a
095e7ec
0c30a32
dfdd48b
c293cd7
3e6478e
7bc837a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package net.squanchy.favorites.view; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.Nullable; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.design.widget.Snackbar; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
import android.widget.LinearLayout; | ||
|
||
import net.squanchy.R; | ||
|
||
public class NoFavoritesView extends LinearLayout { | ||
|
||
private static final int MAGIC_NUMBER_TO_TRIGGER_ACHIEVEMENT = 5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is magic as in... magical ~ 💖 |
||
private FloatingActionButton favoriteButton; | ||
|
||
public NoFavoritesView(Context context) { | ||
super(context); | ||
} | ||
|
||
public NoFavoritesView(Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public NoFavoritesView(Context context, @Nullable AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
} | ||
|
||
@Override | ||
protected void onFinishInflate() { | ||
super.onFinishInflate(); | ||
super.setOrientation(VERTICAL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to override There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually throw regardless in those cases (see any There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 💃 |
||
inflate(getContext(), R.layout.merge_no_favorites_view, this); | ||
|
||
favoriteButton = (FloatingActionButton) findViewById(R.id.favorite_fab_example); | ||
favoriteButton.setOnClickListener(new OnClickListener() { | ||
int counter = 0; | ||
|
||
@Override | ||
public void onClick(View view) { | ||
favoriteButton.setImageResource( | ||
counter % 2 == 0 ? | ||
R.drawable.ic_favorite_filled : | ||
R.drawable.ic_favorite_empty | ||
); | ||
|
||
counter++; | ||
if (counter == MAGIC_NUMBER_TO_TRIGGER_ACHIEVEMENT) { | ||
Snackbar.make(NoFavoritesView.this, R.string.achievement_unlocked, Snackbar.LENGTH_LONG).show(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void setOrientation(int orientation) { | ||
throw new UnsupportedOperationException("Changing orientation is not supported for " + NoFavoritesView.class.getSimpleName()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<merge xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:orientation="vertical" | ||
tools:parentTag="LinearLayout"> | ||
|
||
<android.support.design.widget.FloatingActionButton | ||
android:id="@+id/favorite_fab_example" | ||
style="@style/EventDetails.Fab" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" /> | ||
|
||
<TextView | ||
android:id="@+id/text" | ||
style="@style/Favorite.Empty.Text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_marginTop="20dp" | ||
android:layout_marginLeft="@dimen/card_horizontal_margin" | ||
android:layout_marginRight="@dimen/card_horizontal_margin" | ||
android:foreground="@drawable/primary_touch_feedback" | ||
android:text="@string/prompt_to_favorite" /> | ||
</merge> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<drawable name="illustration_prompt_to_sign_in">@drawable/illustration_lunch</drawable> | ||
</resources> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block was moved to the
!isInEditMode()
so that we can have a preview of this screen. As it turns out there is a specific kind of Context being used in the Preview mode andunwrapToActivityContext()
is crashing because it is unhandled. The specific Context is BridgeContext and looks like a Hidden API, so we cannot possibly handle it properly