-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
257 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeGenericItemActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.mikepenz.fastadapter.app; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.GridLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
|
||
import com.mikepenz.fastadapter.FastAdapter; | ||
import com.mikepenz.fastadapter.adapters.GenericItemAdapter; | ||
import com.mikepenz.fastadapter.app.generic.GenericIconItem; | ||
import com.mikepenz.fastadapter.app.generic.IconModel; | ||
import com.mikepenz.fastadapter.app.generic.RightGenericIconItem; | ||
import com.mikepenz.fastadapter.utils.Function; | ||
import com.mikepenz.iconics.Iconics; | ||
import com.mikepenz.iconics.typeface.ITypeface; | ||
import com.mikepenz.itemanimators.SlideDownAlphaAnimator; | ||
import com.mikepenz.materialize.MaterializeBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class MultiTypeGenericItemActivity extends AppCompatActivity { | ||
//save our FastAdapter | ||
private FastAdapter fastAdapter; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_sample); | ||
|
||
//improve ui | ||
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | ||
|
||
// Handle Toolbar | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setTitle(R.string.sample_multi_generic_item); | ||
|
||
//style our ui | ||
new MaterializeBuilder().withActivity(this).build(); | ||
|
||
|
||
//create our FastAdapter which will manage everything | ||
fastAdapter = new FastAdapter(); | ||
|
||
//get our recyclerView and do basic setup | ||
RecyclerView rv = (RecyclerView) findViewById(R.id.rv); | ||
|
||
//init our gridLayoutManager and configure RV | ||
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3); | ||
|
||
//if you need multiple items for different models you can also do this be defining a Function which get's the model object and returns the item (extends IItem) | ||
GenericItemAdapter itemAdapter = new GenericItemAdapter(new Function() { | ||
@Override | ||
public Object apply(Object o) { | ||
//depending on your logic you can now decide which model maps to which item. | ||
if (o instanceof IconModel) { | ||
if (((IconModel) o).normal) { | ||
return new GenericIconItem((IconModel) o); | ||
} else { | ||
return new RightGenericIconItem((IconModel) o); | ||
} | ||
} else { | ||
throw new IllegalArgumentException("The passed model can't be created within this Factory"); | ||
} | ||
} | ||
}); | ||
|
||
rv.setLayoutManager(gridLayoutManager); | ||
rv.setItemAnimator(new SlideDownAlphaAnimator()); | ||
rv.setAdapter(itemAdapter.wrap(fastAdapter)); | ||
|
||
//order fonts by their name | ||
List<ITypeface> mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this)); | ||
Collections.sort(mFonts, new Comparator<ITypeface>() { | ||
@Override | ||
public int compare(final ITypeface object1, final ITypeface object2) { | ||
return object1.getFontName().compareTo(object2.getFontName()); | ||
} | ||
}); | ||
|
||
//add all icons of all registered Fonts to the list | ||
ArrayList<IconModel> models = new ArrayList<>(); | ||
int i = 0; | ||
for (ITypeface font : mFonts) { | ||
for (String icon : font.getIcons()) { | ||
if (i % 3 == 0) { | ||
models.add(new IconModel(font.getIcon(icon))); | ||
} else { | ||
models.add(new IconModel(font.getIcon(icon), false)); | ||
} | ||
i++; | ||
} | ||
} | ||
|
||
//fill with some sample data | ||
itemAdapter.addModel(models); | ||
|
||
//restore selections (this has to be done after the items were added | ||
fastAdapter.withSavedInstanceState(savedInstanceState); | ||
|
||
//set the back arrow in the toolbar | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
getSupportActionBar().setHomeButtonEnabled(false); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
//add the values which need to be saved from the adapter to the bundel | ||
outState = fastAdapter.saveInstanceState(outState); | ||
super.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
//handle the click on the back arrow click | ||
switch (item.getItemId()) { | ||
case android.R.id.home: | ||
onBackPressed(); | ||
return true; | ||
|
||
default: | ||
return super.onOptionsItemSelected(item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/mikepenz/fastadapter/app/generic/RightGenericIconItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.mikepenz.fastadapter.app.generic; | ||
|
||
import com.mikepenz.fastadapter.app.R; | ||
|
||
/** | ||
* Created by mikepenz on 28.12.15. | ||
*/ | ||
public class RightGenericIconItem extends GenericIconItem { | ||
public RightGenericIconItem(IconModel icon) { | ||
super(icon); | ||
} | ||
|
||
/** | ||
* defines the type defining this item. must be unique. preferably an id | ||
* | ||
* @return the type | ||
*/ | ||
@Override | ||
public int getType() { | ||
return R.id.fastadapter_right_generic_icon_item_id; | ||
} | ||
|
||
/** | ||
* defines the layout which will be used for this item in the list | ||
* | ||
* @return the layout for this item | ||
*/ | ||
@Override | ||
public int getLayoutRes() { | ||
return R.layout.right_icon_item; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ Copyright 2014 Mike Penz | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="5dp" | ||
android:clickable="true" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:id="@+id/name" | ||
android:layout_width="match_parent" | ||
android:layout_height="48dp" | ||
android:background="@drawable/button_rect_list_normal" | ||
android:clickable="false" | ||
android:gravity="center_vertical" | ||
android:paddingLeft="8dp" | ||
android:paddingRight="56dp" | ||
android:paddingStart="8dp" | ||
android:textColor="@color/md_light_primary_text" | ||
android:textSize="14sp" /> | ||
|
||
<com.mikepenz.iconics.view.IconicsImageView | ||
android:id="@+id/icon" | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:layout_gravity="right" | ||
android:clickable="false" | ||
android:padding="8dp" | ||
android:scaleType="fitXY" /> | ||
</android.support.v7.widget.CardView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.