Skip to content

Commit aa70632

Browse files
author
Ira
committed
initial commit
0 parents  commit aa70632

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+3114
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
/build

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.1"
6+
7+
defaultConfig {
8+
applicationId "com.yalantis.fitfilter"
9+
minSdkVersion 18
10+
targetSdkVersion 24
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(include: ['*.jar'], dir: 'libs')
24+
compile 'com.android.support:appcompat-v7:24.2.0'
25+
compile 'com.facebook.fresco:fresco:0.13.0'
26+
compile 'com.android.support:design:24.2.0'
27+
compile project(':filter')
28+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/igalata/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

app/src/main/AndroidManifest.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.yalantis.fitfilter">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:largeHeap="true"
12+
android:supportsRtl="true"
13+
android:theme="@style/AppTheme">
14+
<activity android:name=".ExampleActivity">
15+
<intent-filter>
16+
<action android:name="android.intent.action.MAIN" />
17+
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
</activity>
21+
</application>
22+
23+
</manifest>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.yalantis.fitfilter;
2+
3+
import android.content.Context;
4+
import android.graphics.Canvas;
5+
import android.graphics.drawable.Drawable;
6+
import android.support.v4.content.ContextCompat;
7+
import android.support.v7.widget.RecyclerView;
8+
import android.view.View;
9+
10+
/**
11+
* Created by galata on 17.09.16.
12+
*/
13+
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
14+
private Drawable mDivider;
15+
16+
public DividerItemDecoration(Context context, int resId) {
17+
mDivider = ContextCompat.getDrawable(context, resId);
18+
}
19+
20+
@Override
21+
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
22+
int left = parent.getPaddingLeft();
23+
int right = parent.getWidth() - parent.getPaddingRight();
24+
25+
for (int i = 0; i < parent.getChildCount() - 1; i++) {
26+
View child = parent.getChildAt(i);
27+
28+
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
29+
30+
if (i == 0) {
31+
int top = child.getTop();
32+
int bottom = top + mDivider.getIntrinsicHeight();
33+
34+
mDivider.setBounds(left, top, right, bottom);
35+
mDivider.draw(c);
36+
}
37+
38+
int top = child.getBottom() + params.bottomMargin;
39+
int bottom = top + mDivider.getIntrinsicHeight();
40+
41+
mDivider.setBounds(left, top, right, bottom);
42+
mDivider.draw(c);
43+
}
44+
}
45+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
package com.yalantis.fitfilter;
2+
3+
import android.os.Bundle;
4+
import android.support.v4.content.ContextCompat;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.support.v7.util.DiffUtil;
7+
import android.support.v7.widget.LinearLayoutManager;
8+
import android.support.v7.widget.RecyclerView;
9+
10+
import com.facebook.drawee.backends.pipeline.Fresco;
11+
import com.facebook.imagepipeline.core.ImagePipelineConfig;
12+
import com.yalantis.filter.adapter.FilterAdapter;
13+
import com.yalantis.filter.animator.FiltersListItemAnimator;
14+
import com.yalantis.filter.listener.FilterListener;
15+
import com.yalantis.filter.widget.Filter;
16+
import com.yalantis.filter.widget.FilterItem;
17+
18+
import org.jetbrains.annotations.NotNull;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
public class ExampleActivity extends AppCompatActivity implements FilterListener<Tag> {
24+
25+
private RecyclerView mRecyclerView;
26+
27+
private int[] mColors;
28+
private String[] mTitles;
29+
private List<Question> mAllQuestions;
30+
private Filter<Tag> mFilter;
31+
private QuestionsAdapter mAdapter;
32+
33+
@Override
34+
protected void onCreate(Bundle savedInstanceState) {
35+
super.onCreate(savedInstanceState);
36+
setContentView(R.layout.activity_example);
37+
38+
ImagePipelineConfig config = ImagePipelineConfig
39+
.newBuilder(this)
40+
.setDownsampleEnabled(true)
41+
.build();
42+
Fresco.initialize(this, config);
43+
44+
mColors = getResources().getIntArray(R.array.colors);
45+
mTitles = getResources().getStringArray(R.array.job_titles);
46+
47+
mFilter = (Filter<Tag>) findViewById(R.id.filter);
48+
mFilter.setAdapter(new Adapter(getTags()));
49+
mFilter.setListener(this);
50+
mFilter.setNoSelectedItemText(getString(R.string.str_all_selected));
51+
mFilter.build();
52+
53+
mRecyclerView = (RecyclerView) findViewById(R.id.list);
54+
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
55+
mRecyclerView.setAdapter(mAdapter = new QuestionsAdapter(this, mAllQuestions = getQuestions()));
56+
mRecyclerView.setItemAnimator(new FiltersListItemAnimator());
57+
}
58+
59+
private void calculateDiff(final List<Question> oldList, final List<Question> newList) {
60+
DiffUtil.calculateDiff(new DiffUtil.Callback() {
61+
@Override
62+
public int getOldListSize() {
63+
return oldList.size();
64+
}
65+
66+
@Override
67+
public int getNewListSize() {
68+
return newList.size();
69+
}
70+
71+
@Override
72+
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
73+
return oldList.get(oldItemPosition).equals(newList.get(newItemPosition));
74+
}
75+
76+
@Override
77+
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
78+
return oldList.get(oldItemPosition).equals(newList.get(newItemPosition));
79+
}
80+
}).dispatchUpdatesTo(mAdapter);
81+
}
82+
83+
private List<Tag> getTags() {
84+
List<Tag> tags = new ArrayList<>();
85+
86+
for (int i = 0; i < mTitles.length; ++i) {
87+
tags.add(new Tag(mTitles[i], mColors[i]));
88+
}
89+
90+
return tags;
91+
}
92+
93+
@Override
94+
public void onNothingSelected() {
95+
if (mRecyclerView != null) {
96+
mAdapter.setQuestions(mAllQuestions);
97+
mAdapter.notifyDataSetChanged();
98+
}
99+
}
100+
101+
private List<Question> getQuestions() {
102+
return new ArrayList<Question>() {{
103+
add(new Question("Carol Bell", "Graphic Designer",
104+
"http://kingofwallpapers.com/girl/girl-011.jpg", "Nov 20, 6:12 PM",
105+
"What is the first step to transform an idea into an actual project?", new ArrayList<Tag>() {{
106+
add(new Tag(mTitles[2], mColors[2]));
107+
add(new Tag(mTitles[4], mColors[4]));
108+
}}));
109+
add(new Question("Melissa Morales", "Project Manager",
110+
"http://weknowyourdreams.com/images/girl/girl-03.jpg", "Nov 20, 3:48 AM",
111+
"What is your biggest frustration with taking your business/career (in a corporate) to the next level?", new ArrayList<Tag>() {{
112+
add(new Tag(mTitles[1], mColors[1]));
113+
add(new Tag(mTitles[5], mColors[5]));
114+
}}));
115+
add(new Question("Rochelle Yingst", "iOS Developer",
116+
"http://www.viraldoza.com/wp-content/uploads/2014/03/8876509-lily-pretty-girl.jpg", "Nov 20, 6:12 PM",
117+
"What is the first step to transform an idea into an actual project?", new ArrayList<Tag>() {{
118+
add(new Tag(mTitles[7], mColors[7]));
119+
add(new Tag(mTitles[8], mColors[8]));
120+
}}));
121+
add(new Question("Lacey Barbara", "QA Engineer",
122+
"http://kingofwallpapers.com/girl/girl-019.jpg", "Nov 20, 6:12 PM",
123+
"What is the first step to transform an idea into an actual project?", new ArrayList<Tag>() {{
124+
add(new Tag(mTitles[3], mColors[3]));
125+
add(new Tag(mTitles[9], mColors[9]));
126+
}}));
127+
add(new Question("Teena Allain", "Android Developer",
128+
"http://tribzap2it.files.wordpress.com/2014/09/hannah-simone-new-girl-season-4-cece.jpg", "Nov 20, 6:12 PM",
129+
"What is the first step to transform an idea into an actual project?", new ArrayList<Tag>() {{
130+
add(new Tag(mTitles[1], mColors[1]));
131+
add(new Tag(mTitles[6], mColors[6]));
132+
}}));
133+
}};
134+
}
135+
136+
private List<Question> findByTags(List<Tag> tags) {
137+
List<Question> questions = new ArrayList<>();
138+
139+
for (Question question : mAllQuestions) {
140+
for (Tag tag : tags) {
141+
if (question.hasTag(tag.getText()) && !questions.contains(question)) {
142+
questions.add(question);
143+
}
144+
}
145+
}
146+
147+
return questions;
148+
}
149+
150+
@Override
151+
public void onFiltersSelected(@NotNull ArrayList<Tag> filters) {
152+
List<Question> newQuestions = findByTags(filters);
153+
List<Question> oldQuestions = mAdapter.getQuestions();
154+
mAdapter.setQuestions(newQuestions);
155+
calculateDiff(oldQuestions, newQuestions);
156+
}
157+
158+
@Override
159+
public void onFilterSelected(Tag item) {
160+
if (item.getText().equals(mTitles[0])) {
161+
mFilter.deselectAll();
162+
mFilter.collapse();
163+
}
164+
}
165+
166+
@Override
167+
public void onFilterDeselected(Tag item) {
168+
169+
}
170+
171+
class Adapter extends FilterAdapter<Tag> {
172+
173+
Adapter(@NotNull List<? extends Tag> items) {
174+
super(items);
175+
}
176+
177+
@NotNull
178+
@Override
179+
public FilterItem createView(int position, Tag item) {
180+
FilterItem filterItem = new FilterItem(ExampleActivity.this);
181+
182+
filterItem.setStrokeColor(mColors[0]);
183+
filterItem.setTextColor(mColors[0]);
184+
filterItem.setCheckedTextColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));
185+
filterItem.setColor(ContextCompat.getColor(ExampleActivity.this, android.R.color.white));
186+
filterItem.setCheckedColor(mColors[position]);
187+
filterItem.setText(item.getText());
188+
filterItem.deselect();
189+
190+
return filterItem;
191+
}
192+
}
193+
}

0 commit comments

Comments
 (0)