-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
29 changed files
with
559 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FastAdapter contributors (sorted alphabeticaly) | ||
============================================ | ||
|
||
* **[Fabian Terhorst](https://github.com/FabianTerhorst)** | ||
|
||
* EndlessScroll-Listener (EndlessScroll Sample) | ||
|
||
* **[Mattias Isegran Bergander](https://github.com/mattiasbe)** | ||
|
||
* "Leave-Behind"-Pattern (SwipeList Sample) | ||
|
||
* **[Rainer Lang](https://github.com/Rainer-Lang)** | ||
|
||
* |
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
201 changes: 201 additions & 0 deletions
201
app/src/main/java/com/mikepenz/fastadapter/app/EndlessScrollListActivity.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,201 @@ | ||
package com.mikepenz.fastadapter.app; | ||
|
||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.DefaultItemAnimator; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.support.v7.widget.SearchView; | ||
import android.support.v7.widget.Toolbar; | ||
import android.support.v7.widget.helper.ItemTouchHelper; | ||
import android.text.TextUtils; | ||
import android.view.Menu; | ||
import android.view.MenuInflater; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.mikepenz.fastadapter.FastAdapter; | ||
import com.mikepenz.fastadapter.IAdapter; | ||
import com.mikepenz.fastadapter.IItemAdapter; | ||
import com.mikepenz.fastadapter.adapters.FastItemAdapter; | ||
import com.mikepenz.fastadapter.adapters.FooterAdapter; | ||
import com.mikepenz.fastadapter.adapters.ItemAdapter.ItemFilterListener; | ||
import com.mikepenz.fastadapter.app.items.SampleItem; | ||
import com.mikepenz.fastadapter_extensions.drag.ItemTouchCallback; | ||
import com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback; | ||
import com.mikepenz.fastadapter_extensions.items.ProgressItem; | ||
import com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener; | ||
import com.mikepenz.materialize.MaterializeBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class EndlessScrollListActivity extends AppCompatActivity implements ItemTouchCallback, ItemFilterListener { | ||
|
||
//save our FastAdapter | ||
private FastItemAdapter<SampleItem> fastItemAdapter; | ||
private FooterAdapter<ProgressItem> footerAdapter; | ||
|
||
//drag & drop | ||
private SimpleDragCallback touchCallback; | ||
private ItemTouchHelper touchHelper; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_sample); | ||
|
||
// Handle Toolbar | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
|
||
//style our ui | ||
new MaterializeBuilder().withActivity(this).build(); | ||
|
||
//create our FastAdapter which will manage everything | ||
fastItemAdapter = new FastItemAdapter<>(); | ||
|
||
//create our FooterAdapter which will manage the progress items | ||
footerAdapter = new FooterAdapter<>(); | ||
|
||
//configure our fastAdapter | ||
fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<SampleItem>() { | ||
@Override | ||
public boolean onClick(View v, IAdapter<SampleItem> adapter, SampleItem item, int position) { | ||
Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show(); | ||
return false; | ||
} | ||
}); | ||
|
||
//configure the itemAdapter | ||
fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate<SampleItem>() { | ||
@Override | ||
public boolean filter(SampleItem item, CharSequence constraint) { | ||
//return true if we should filter it out | ||
//return false to keep it | ||
return !item.name.getText().toLowerCase().contains(constraint.toString().toLowerCase()); | ||
} | ||
}); | ||
|
||
fastItemAdapter.getItemAdapter().withItemFilterListener(this); | ||
|
||
//get our recyclerView and do basic setup | ||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv); | ||
LinearLayoutManager manager = new LinearLayoutManager(this); | ||
recyclerView.setLayoutManager(manager); | ||
recyclerView.setItemAnimator(new DefaultItemAnimator()); | ||
recyclerView.setAdapter(footerAdapter.wrap(fastItemAdapter)); | ||
recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener(manager, 15) { | ||
@Override | ||
public void onLoadMore(final int currentPage) { | ||
new Handler().postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
footerAdapter.clear(); | ||
footerAdapter.add(new ProgressItem()); | ||
//simulate networking (2 seconds) | ||
Handler handler = new Handler(); | ||
handler.postDelayed(new Runnable() { | ||
@Override | ||
public void run() { | ||
footerAdapter.clear(); | ||
for (int i = 1; i < 16; i++) { | ||
fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new SampleItem().withName("Item " + i + " Page " + currentPage)); | ||
} | ||
} | ||
}, 2000); | ||
} | ||
}, 10); | ||
|
||
} | ||
}); | ||
|
||
//fill with some sample data (load the first page here) | ||
List<SampleItem> items = new ArrayList<>(); | ||
for (int i = 1; i < 16; i++) { | ||
items.add(new SampleItem().withName("Item " + i + " Page " + 1)); | ||
} | ||
fastItemAdapter.add(items); | ||
|
||
//add drag and drop for item | ||
touchCallback = new SimpleDragCallback(this); | ||
touchHelper = new ItemTouchHelper(touchCallback); // Create ItemTouchHelper and pass with parameter the SimpleDragCallback | ||
touchHelper.attachToRecyclerView(recyclerView); // Attach ItemTouchHelper to RecyclerView | ||
|
||
//restore selections (this has to be done after the items were added | ||
fastItemAdapter.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 = fastItemAdapter.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); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu items for use in the action bar | ||
MenuInflater inflater = getMenuInflater(); | ||
inflater.inflate(R.menu.search, menu); | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { | ||
final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); | ||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | ||
@Override | ||
public boolean onQueryTextSubmit(String s) { | ||
touchCallback.setIsDragEnabled(false); | ||
fastItemAdapter.filter(s); | ||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public boolean onQueryTextChange(String s) { | ||
fastItemAdapter.filter(s); | ||
touchCallback.setIsDragEnabled(TextUtils.isEmpty(s)); | ||
return true; | ||
} | ||
}); | ||
} else { | ||
menu.findItem(R.id.search).setVisible(false); | ||
} | ||
|
||
return super.onCreateOptionsMenu(menu); | ||
} | ||
|
||
@Override | ||
public boolean itemTouchOnMove(int oldPosition, int newPosition) { | ||
Collections.swap(fastItemAdapter.getAdapterItems(), oldPosition, newPosition); // change position | ||
fastItemAdapter.notifyAdapterItemMoved(oldPosition, newPosition); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void itemsFiltered() { | ||
Toast.makeText(EndlessScrollListActivity.this, "filtered items count: " + fastItemAdapter.getItemCount(), Toast.LENGTH_SHORT).show(); | ||
} | ||
} |
Oops, something went wrong.