(demo, recyclerview) Update demo.. see details ->
Demo now includes the most simple form or using a recycler view in the codebase currently. Next step would be to create a more simplified approach at a RecyclerViewSwipeAdapter that a user can extend from and only implement smaller methods instead of all the implementations.
This commit is contained in:
parent
25e38f34f3
commit
bd4749188c
|
|
@ -1,5 +1,9 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
repositories {
|
||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
|
||||
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
|
||||
|
|
@ -21,8 +25,10 @@ android {
|
|||
|
||||
dependencies {
|
||||
compile project(":library")
|
||||
compile 'com.nineoldandroids:library:2.4.0'
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
compile 'com.daimajia.easing:library:1.0.0@aar'
|
||||
compile 'com.daimajia.androidanimations:library:1.1.2@aar'
|
||||
compile 'com.nineoldandroids:library:2.4.0'
|
||||
compile 'org.lucasr.twowayview:core:1.0.0-SNAPSHOT@aar'
|
||||
compile 'org.lucasr.twowayview:layouts:1.0.0-SNAPSHOT@aar'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.daimajia.swipedemo" >
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.daimajia.swipedemo">
|
||||
|
||||
<uses-sdk tools:overrideLibrary="org.lucasr.twowayview, org.lucasr.twowayview.widget" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name="com.daimajia.swipedemo.MyActivity"
|
||||
android:label="@string/app_name" >
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.daimajia.swipedemo.ListViewExample"/>
|
||||
<activity android:name="com.daimajia.swipedemo.GridViewExample"/>
|
||||
<activity android:name=".NestedExample"/>
|
||||
<activity android:name="com.daimajia.swipedemo.ListViewExample" />
|
||||
<activity android:name="com.daimajia.swipedemo.GridViewExample" />
|
||||
<activity android:name="com.daimajia.swipedemo.RecyclerViewExample" />
|
||||
<activity android:name=".NestedExample" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.widget.AdapterView;
|
|||
import android.widget.GridView;
|
||||
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.GridViewAdapter;
|
||||
|
||||
public class GridViewExample extends Activity{
|
||||
|
|
@ -18,7 +19,7 @@ public class GridViewExample extends Activity{
|
|||
setContentView(R.layout.gridview);
|
||||
final GridView gridView = (GridView)findViewById(R.id.gridview);
|
||||
final GridViewAdapter adapter = new GridViewAdapter(this);
|
||||
adapter.setMode(SwipeItemMangerImpl.Mode.Multiple);
|
||||
adapter.setMode(Attributes.Mode.Multiple);
|
||||
gridView.setAdapter(adapter);
|
||||
gridView.setSelected(false);
|
||||
gridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import android.widget.ListView;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.ListViewAdapter;
|
||||
|
||||
public class ListViewExample extends Activity {
|
||||
|
|
@ -39,7 +40,7 @@ public class ListViewExample extends Activity {
|
|||
|
||||
mAdapter = new ListViewAdapter(this);
|
||||
mListView.setAdapter(mAdapter);
|
||||
mAdapter.setMode(SwipeItemMangerImpl.Mode.Single);
|
||||
mAdapter.setMode(Attributes.Mode.Single);
|
||||
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
|
|
|||
|
|
@ -113,11 +113,13 @@ public class MyActivity extends Activity {
|
|||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
return true;
|
||||
} else if(id == R.id.action_nexted){
|
||||
} else if (id == R.id.action_nested) {
|
||||
startActivity(new Intent(this, NestedExample.class));
|
||||
return true;
|
||||
} else if (id == R.id.action_recycler) {
|
||||
startActivity(new Intent(this, RecyclerViewExample.class));
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,151 @@
|
|||
package com.daimajia.swipedemo;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.adapter.RecyclerViewSimpleAdapter;
|
||||
|
||||
import org.lucasr.twowayview.ItemClickSupport;
|
||||
import org.lucasr.twowayview.TwoWayLayoutManager;
|
||||
import org.lucasr.twowayview.widget.DividerItemDecoration;
|
||||
import org.lucasr.twowayview.widget.ListLayoutManager;
|
||||
|
||||
public class RecyclerViewExample extends Activity {
|
||||
|
||||
private RecyclerView recyclerView;
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
// RecyclerView.LayoutManager: https://developer.android.com/reference/android/support/v7/widget/RecyclerView.LayoutManager.html
|
||||
// Our LayoutManager uses: https://github.com/lucasr/twoway-view to help with decoration and can be used for a more advanced config as well.
|
||||
// Read http://lucasr.org/2014/07/31/the-new-twowayview/ for a better understanding
|
||||
private RecyclerView.LayoutManager mLayoutManager;
|
||||
private Context mContext = this;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.recyclerview);
|
||||
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
|
||||
|
||||
/**
|
||||
* The following comment is the sample usage of ArraySwipeAdapter.
|
||||
*/
|
||||
String[] adapterData = new String[]{"Activity", "Service", "Content Provider", "Intent", "BroadcastReceiver", "ADT", "Sqlite3", "HttpClient",
|
||||
"DDMS", "Android Studio", "Fragment", "Loader", "Activity", "Service", "Content Provider", "Intent",
|
||||
"BroadcastReceiver", "ADT", "Sqlite3", "HttpClient", "Activity", "Service", "Content Provider", "Intent",
|
||||
"BroadcastReceiver", "ADT", "Sqlite3", "HttpClient"};
|
||||
|
||||
// Uses a ListLayout manager from TwoWayView Lib:
|
||||
mLayoutManager = new ListLayoutManager(this, TwoWayLayoutManager.Orientation.VERTICAL);
|
||||
recyclerView.setLayoutManager(mLayoutManager);
|
||||
final Drawable divider = getResources().getDrawable(R.drawable.divider);
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(divider));
|
||||
|
||||
mAdapter = new RecyclerViewSimpleAdapter(this, adapterData);
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
((RecyclerViewSimpleAdapter) mAdapter).setMode(Attributes.Mode.Single);
|
||||
|
||||
/* Listeners */
|
||||
ItemClickSupport itemClick = ItemClickSupport.addTo(recyclerView);
|
||||
itemClick.setOnItemClickListener(onItemClickListener);
|
||||
recyclerView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
Log.e("ListView", "OnTouch");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
recyclerView.setOnScrollListener(onScrollListener);
|
||||
|
||||
// TODO: Item Long Click is firing for every touch.
|
||||
// itemClick.setOnItemLongClickListener(onItemLongClickListener);
|
||||
|
||||
// TODO: Item Selection Support for RecyclerView
|
||||
// recyclerView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
// @Override
|
||||
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
// Log.e("ListView", "onItemSelected:" + position);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onNothingSelected(AdapterView<?> parent) {
|
||||
// Log.e("ListView", "onNothingSelected:");
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitute for our onItemClick listener for RecyclerView
|
||||
*/
|
||||
ItemClickSupport.OnItemClickListener onItemClickListener = new ItemClickSupport.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(RecyclerView parent, View child, int position, long id) {
|
||||
Toast.makeText(mContext, "Clicked:" + position, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Substitute for our onItemLongClick listener for RecyclerView
|
||||
*/
|
||||
ItemClickSupport.OnItemLongClickListener onItemLongClickListener = new ItemClickSupport.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(RecyclerView recyclerView, View view, int position, long id) {
|
||||
Toast.makeText(mContext, "OnItemLongClickListener:" + position, Toast.LENGTH_SHORT).show();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Substitute for our onScrollListener for RecyclerView
|
||||
*/
|
||||
RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
super.onScrollStateChanged(recyclerView, newState);
|
||||
Log.e("ListView", "onScrollStateChanged");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
super.onScrolled(recyclerView, dx, dy);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.my, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
if (id == R.id.action_listview) {
|
||||
startActivity(new Intent(this, ListViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
} else if (id == R.id.action_gridview) {
|
||||
startActivity(new Intent(this, GridViewExample.class));
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
package com.daimajia.swipedemo.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.daimajia.androidanimations.library.Techniques;
|
||||
import com.daimajia.androidanimations.library.YoYo;
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemRecyclerMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
import com.daimajia.swipedemo.R;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RecyclerViewSimpleAdapter extends RecyclerView.Adapter<RecyclerViewSimpleAdapter.ViewHolder> implements SwipeItemMangerInterface, SwipeAdapterInterface {
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
SwipeLayout swipeLayout;
|
||||
TextView textView;
|
||||
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipe);
|
||||
textView = (TextView) itemView.findViewById(R.id.position);
|
||||
}
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private String[] mDataset;
|
||||
|
||||
protected SwipeItemRecyclerMangerImpl mItemManger = new SwipeItemRecyclerMangerImpl(this);
|
||||
|
||||
|
||||
public RecyclerViewSimpleAdapter(Context context, String[] objects) {
|
||||
this.mContext = context;
|
||||
this.mDataset = objects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_item, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder viewHolder, int position) {
|
||||
viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
|
||||
}
|
||||
});
|
||||
viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
|
||||
@Override
|
||||
public void onDoubleClick(SwipeLayout layout, boolean surface) {
|
||||
Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
viewHolder.textView.setText((position + 1) + ".");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mDataset.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
mItemManger.openItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
mItemManger.closeItem(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
mItemManger.closeAllExcept(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
return mItemManger.getOpenItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return mItemManger.getOpenLayouts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mItemManger.removeShownLayouts(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
return mItemManger.isOpen(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSwipeLayoutResourceId(int position) {
|
||||
return R.id.swipe;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<!--
|
||||
~ Copyright (C) 2014 Lucas Rocha
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#cccccc"/>
|
||||
<size android:width="2dp"
|
||||
android:height="2dp" />
|
||||
|
||||
</shape>
|
||||
|
|
@ -2,58 +2,62 @@
|
|||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<com.daimajia.swipe.SwipeLayout
|
||||
xmlns:swipe="http://schemas.android.com/apk/res-auto"
|
||||
|
||||
<com.daimajia.swipe.SwipeLayout xmlns:swipe="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/swipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
swipe:horizontalSwipeOffset="25dp"
|
||||
>
|
||||
swipe:horizontalSwipeOffset="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:background="#FF5534"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10"
|
||||
android:gravity="center"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp">
|
||||
android:layout_height="80dp"
|
||||
android:background="#FF5534"
|
||||
android:gravity="center"
|
||||
android:tag="Bottom3"
|
||||
android:weightSum="10">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/trash"
|
||||
android:src="@drawable/trash"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="30dp" />
|
||||
android:layout_height="30dp"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/trash" />
|
||||
|
||||
<TextView
|
||||
android:text="Delete Item?"
|
||||
android:textSize="17sp"
|
||||
android:textColor="#fff"
|
||||
android:layout_weight="5"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="5"
|
||||
android:text="Delete Item?"
|
||||
android:textColor="#fff"
|
||||
android:textSize="17sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/delete"
|
||||
android:textColor="#FF5534"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_weight="4"
|
||||
android:background="#ffffff"
|
||||
android:text="Yes,Delete"
|
||||
android:layout_weight="4"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="40dp" />
|
||||
android:textColor="#FF5534" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:padding="10dp"
|
||||
android:background="@drawable/item_selector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/item_selector"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/position"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. "
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:tag="Hover"
|
||||
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. " />
|
||||
</LinearLayout>
|
||||
</com.daimajia.swipe.SwipeLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- A RecyclerView with some commonly used attributes -->
|
||||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical" />
|
||||
|
|
@ -1,14 +1,19 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".MyActivity" >
|
||||
<item android:id="@+id/action_listview"
|
||||
android:title="ListView"
|
||||
tools:context=".MyActivity">
|
||||
<item
|
||||
android:id="@+id/action_listview"
|
||||
android:orderInCategory="100"
|
||||
/>
|
||||
<item android:id="@+id/action_gridview"
|
||||
android:title="GridView"
|
||||
android:title="ListView" />
|
||||
<item
|
||||
android:id="@+id/action_gridview"
|
||||
android:orderInCategory="100"
|
||||
/>
|
||||
<item android:id="@+id/action_nexted"
|
||||
android:title="Complicate"/>
|
||||
android:title="GridView" />
|
||||
<item
|
||||
android:id="@+id/action_recycler"
|
||||
android:orderInCategory="100"
|
||||
android:title="RecyclerView" />
|
||||
<item
|
||||
android:id="@+id/action_nested"
|
||||
android:title="Complicate" />
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compile 'com.android.support:support-v4:20.+'
|
||||
compile 'com.android.support:recyclerview-v7:21.0.0'
|
||||
compile 'com.android.support:support-v4:21.0.3'
|
||||
}
|
||||
apply from: './gradle-mvn-push.gradle'
|
||||
|
|
@ -9,6 +9,7 @@ import com.daimajia.swipe.SwipeLayout;
|
|||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -88,12 +89,12 @@ public abstract class ArraySwipeAdapter<T> extends ArrayAdapter implements Swipe
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.daimajia.swipe.SwipeLayout;
|
|||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -90,12 +91,12 @@ public abstract class BaseSwipeAdapter extends BaseAdapter implements SwipeItemM
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.daimajia.swipe.SwipeLayout;
|
|||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -73,12 +74,12 @@ public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeI
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.daimajia.swipe.SwipeLayout;
|
|||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -73,12 +74,12 @@ public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter imple
|
|||
}
|
||||
|
||||
@Override
|
||||
public SwipeItemMangerImpl.Mode getMode() {
|
||||
public Attributes.Mode getMode() {
|
||||
return mItemManger.getMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode) {
|
||||
public void setMode(Attributes.Mode mode) {
|
||||
mItemManger.setMode(mode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.daimajia.swipe.SimpleSwipeListener;
|
|||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -19,7 +20,7 @@ import java.util.Set;
|
|||
*/
|
||||
public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
||||
|
||||
private Mode mode = Mode.Single;
|
||||
private Attributes.Mode mode = Attributes.Mode.Single;
|
||||
public final int INVALID_POSITION = -1;
|
||||
|
||||
protected int mOpenPosition = INVALID_POSITION;
|
||||
|
|
@ -39,15 +40,11 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
this.mAdapter = adapter;
|
||||
}
|
||||
|
||||
public enum Mode{
|
||||
Single, Multiple
|
||||
};
|
||||
|
||||
public Mode getMode(){
|
||||
public Attributes.Mode getMode(){
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(Mode mode){
|
||||
public void setMode(Attributes.Mode mode){
|
||||
this.mode = mode;
|
||||
mOpenPositions.clear();
|
||||
mShownLayouts.clear();
|
||||
|
|
@ -89,7 +86,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
if(!mOpenPositions.contains(position))
|
||||
mOpenPositions.add(position);
|
||||
}else{
|
||||
|
|
@ -100,7 +97,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
mOpenPositions.remove(position);
|
||||
}else{
|
||||
if(mOpenPosition == position)
|
||||
|
|
@ -124,7 +121,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
if(mode == Mode.Multiple){
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
return new ArrayList<Integer>(mOpenPositions);
|
||||
}else{
|
||||
return Arrays.asList(mOpenPosition);
|
||||
|
|
@ -138,7 +135,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
if(mode == Mode.Multiple){
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
return mOpenPositions.contains(position);
|
||||
}else{
|
||||
return mOpenPosition == position;
|
||||
|
|
@ -190,7 +187,7 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public void onClose(SwipeLayout layout) {
|
||||
if(mode == Mode.Multiple){
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
mOpenPositions.remove(position);
|
||||
}else{
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
|
|
@ -199,14 +196,14 @@ public class SwipeItemMangerImpl implements SwipeItemMangerInterface {
|
|||
|
||||
@Override
|
||||
public void onStartOpen(SwipeLayout layout) {
|
||||
if(mode == Mode.Single) {
|
||||
if(mode == Attributes.Mode.Single) {
|
||||
closeAllExcept(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
if (mode == Mode.Multiple)
|
||||
if (mode == Attributes.Mode.Multiple)
|
||||
mOpenPositions.add(position);
|
||||
else {
|
||||
closeAllExcept(layout);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,219 @@
|
|||
package com.daimajia.swipe.implments;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.daimajia.swipe.SimpleSwipeListener;
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.interfaces.SwipeAdapterInterface;
|
||||
import com.daimajia.swipe.interfaces.SwipeItemMangerInterface;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* SwipeItemMangerImpl is a helper class to help all the adapters to maintain open status.
|
||||
*/
|
||||
public class SwipeItemRecyclerMangerImpl implements SwipeItemMangerInterface {
|
||||
|
||||
private Attributes.Mode mode = Attributes.Mode.Single;
|
||||
public final int INVALID_POSITION = -1;
|
||||
|
||||
protected int mOpenPosition = INVALID_POSITION;
|
||||
|
||||
protected Set<Integer> mOpenPositions = new HashSet<Integer>();
|
||||
protected Set<SwipeLayout> mShownLayouts = new HashSet<SwipeLayout>();
|
||||
|
||||
protected RecyclerView.Adapter mAdapter;
|
||||
|
||||
public SwipeItemRecyclerMangerImpl(RecyclerView.Adapter adapter) {
|
||||
if(adapter == null)
|
||||
throw new IllegalArgumentException("Adapter can not be null");
|
||||
|
||||
if(!(adapter instanceof SwipeItemMangerInterface))
|
||||
throw new IllegalArgumentException("adapter should implement the SwipeAdapterInterface");
|
||||
|
||||
this.mAdapter = adapter;
|
||||
}
|
||||
|
||||
public Attributes.Mode getMode(){
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(Attributes.Mode mode){
|
||||
this.mode = mode;
|
||||
mOpenPositions.clear();
|
||||
mShownLayouts.clear();
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
|
||||
public void initialize(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
OnLayoutListener onLayoutListener = new OnLayoutListener(position);
|
||||
SwipeLayout swipeLayout = (SwipeLayout)target.findViewById(resId);
|
||||
if(swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
SwipeMemory swipeMemory = new SwipeMemory(position);
|
||||
swipeLayout.addSwipeListener(swipeMemory);
|
||||
swipeLayout.addOnLayoutListener(onLayoutListener);
|
||||
swipeLayout.setTag(resId, new ValueBox(position, swipeMemory, onLayoutListener));
|
||||
|
||||
mShownLayouts.add(swipeLayout);
|
||||
}
|
||||
|
||||
public void updateConvertView(View target, int position) {
|
||||
int resId = getSwipeLayoutId(position);
|
||||
|
||||
SwipeLayout swipeLayout = (SwipeLayout)target.findViewById(resId);
|
||||
if(swipeLayout == null)
|
||||
throw new IllegalStateException("can not find SwipeLayout in target view");
|
||||
|
||||
ValueBox valueBox = (ValueBox)swipeLayout.getTag(resId);
|
||||
valueBox.swipeMemory.setPosition(position);
|
||||
valueBox.onLayoutListener.setPosition(position);
|
||||
valueBox.position = position;
|
||||
}
|
||||
|
||||
private int getSwipeLayoutId(int position){
|
||||
return ((SwipeAdapterInterface)(mAdapter)).getSwipeLayoutResourceId(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openItem(int position) {
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
if(!mOpenPositions.contains(position))
|
||||
mOpenPositions.add(position);
|
||||
}else{
|
||||
mOpenPosition = position;
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeItem(int position) {
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
mOpenPositions.remove(position);
|
||||
}else{
|
||||
if(mOpenPosition == position)
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeAllExcept(SwipeLayout layout) {
|
||||
for(SwipeLayout s : mShownLayouts){
|
||||
if(s != layout)
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeShownLayouts(SwipeLayout layout) {
|
||||
mShownLayouts.remove(layout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getOpenItems() {
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
return new ArrayList<Integer>(mOpenPositions);
|
||||
}else{
|
||||
return Arrays.asList(mOpenPosition);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SwipeLayout> getOpenLayouts() {
|
||||
return new ArrayList<SwipeLayout>(mShownLayouts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen(int position) {
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
return mOpenPositions.contains(position);
|
||||
}else{
|
||||
return mOpenPosition == position;
|
||||
}
|
||||
}
|
||||
|
||||
class ValueBox {
|
||||
OnLayoutListener onLayoutListener;
|
||||
SwipeMemory swipeMemory;
|
||||
int position;
|
||||
|
||||
ValueBox(int position, SwipeMemory swipeMemory, OnLayoutListener onLayoutListener) {
|
||||
this.swipeMemory = swipeMemory;
|
||||
this.onLayoutListener = onLayoutListener;
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
class OnLayoutListener implements SwipeLayout.OnLayout{
|
||||
|
||||
private int position;
|
||||
|
||||
OnLayoutListener(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setPosition(int position){
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout(SwipeLayout v) {
|
||||
if(isOpen(position)){
|
||||
v.open(false, false);
|
||||
}else{
|
||||
v.close(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SwipeMemory extends SimpleSwipeListener {
|
||||
|
||||
private int position;
|
||||
|
||||
SwipeMemory(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(SwipeLayout layout) {
|
||||
if(mode == Attributes.Mode.Multiple){
|
||||
mOpenPositions.remove(position);
|
||||
}else{
|
||||
mOpenPosition = INVALID_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartOpen(SwipeLayout layout) {
|
||||
if(mode == Attributes.Mode.Single) {
|
||||
closeAllExcept(layout);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(SwipeLayout layout) {
|
||||
if (mode == Attributes.Mode.Multiple)
|
||||
mOpenPositions.add(position);
|
||||
else {
|
||||
closeAllExcept(layout);
|
||||
mOpenPosition = position;
|
||||
}
|
||||
}
|
||||
|
||||
public void setPosition(int position){
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.daimajia.swipe.interfaces;
|
|||
|
||||
import com.daimajia.swipe.SwipeLayout;
|
||||
import com.daimajia.swipe.implments.SwipeItemMangerImpl;
|
||||
import com.daimajia.swipe.util.Attributes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ public interface SwipeItemMangerInterface {
|
|||
|
||||
public boolean isOpen(int position);
|
||||
|
||||
public SwipeItemMangerImpl.Mode getMode();
|
||||
public Attributes.Mode getMode();
|
||||
|
||||
public void setMode(SwipeItemMangerImpl.Mode mode);
|
||||
public void setMode(Attributes.Mode mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
package com.daimajia.swipe.util;
|
||||
|
||||
|
||||
public class Attributes {
|
||||
|
||||
public enum Mode {
|
||||
Single, Multiple
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue