-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
29 changed files
with
1,057 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION_NAME=2.1.4 | ||
VERSION_NAME=2.5.2 | ||
GROUP=se.emilsjolander | ||
|
||
POM_DESCRIPTION=A small android library that makes it easy to make lists with section headers that stick to the top until a new section header comes along. | ||
|
@@ -11,3 +11,4 @@ POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt | |
POM_LICENCE_DIST=repo | ||
POM_DEVELOPER_ID=emilsjolander | ||
POM_DEVELOPER_NAME=Emil Sjolander | ||
POM_DEVELOPER_EMAIL[email protected] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>se.emilsjolander</groupId> | ||
<artifactId>StickylListHeaders</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>apk</packaging> | ||
<name>StickyListHeaders</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<platform.version>4.1.1.4 | ||
</platform.version> | ||
<android.plugin.version>3.6.0</android.plugin.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.android</groupId> | ||
<artifactId>android</artifactId> | ||
<version>${platform.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<sourceDirectory>${project.basedir}/src/se/emilsjolander/stickylistheaders</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<directory>${project.basedir}/res</directory> | ||
</resource> | ||
</resources> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.jayway.maven.plugins.android.generation2</groupId> | ||
<artifactId>android-maven-plugin</artifactId> | ||
<version>${android.plugin.version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.jayway.maven.plugins.android.generation2</groupId> | ||
<artifactId>android-maven-plugin</artifactId> | ||
|
||
<configuration> | ||
<sdk> | ||
<platform>16</platform> | ||
|
||
</sdk> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
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
11 changes: 0 additions & 11 deletions
11
library/src/se/emilsjolander/stickylistheaders/ApiLevelTooLowException.java
This file was deleted.
Oops, something went wrong.
147 changes: 147 additions & 0 deletions
147
library/src/se/emilsjolander/stickylistheaders/DistinctMultiHashMap.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,147 @@ | ||
package se.emilsjolander.stickylistheaders; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* a hash map can maintain an one-to-many relationship which the value only belongs to one “one” part | ||
* and the map also support getKey by value quickly | ||
* | ||
* @author lsjwzh | ||
*/ | ||
class DistinctMultiHashMap<TKey,TItemValue> { | ||
private IDMapper<TKey, TItemValue> mIDMapper; | ||
|
||
interface IDMapper<TKey,TItemValue>{ | ||
public Object keyToKeyId(TKey key); | ||
public TKey keyIdToKey(Object keyId); | ||
public Object valueToValueId(TItemValue value); | ||
public TItemValue valueIdToValue(Object valueId); | ||
} | ||
|
||
LinkedHashMap<Object,List<TItemValue>> mKeyToValuesMap = new LinkedHashMap<Object, List<TItemValue>>(); | ||
LinkedHashMap<Object,TKey> mValueToKeyIndexer = new LinkedHashMap<Object, TKey>(); | ||
|
||
DistinctMultiHashMap(){ | ||
this(new IDMapper<TKey, TItemValue>() { | ||
@Override | ||
public Object keyToKeyId(TKey key) { | ||
return key; | ||
} | ||
|
||
@Override | ||
public TKey keyIdToKey(Object keyId) { | ||
return (TKey) keyId; | ||
} | ||
|
||
@Override | ||
public Object valueToValueId(TItemValue value) { | ||
return value; | ||
} | ||
|
||
@Override | ||
public TItemValue valueIdToValue(Object valueId) { | ||
return (TItemValue) valueId; | ||
} | ||
}); | ||
} | ||
DistinctMultiHashMap(IDMapper<TKey, TItemValue> idMapper){ | ||
mIDMapper = idMapper; | ||
} | ||
|
||
public List<TItemValue> get(TKey key){ | ||
//todo immutable | ||
return mKeyToValuesMap.get(mIDMapper.keyToKeyId(key)); | ||
} | ||
public TKey getKey(TItemValue value){ | ||
return mValueToKeyIndexer.get(mIDMapper.valueToValueId(value)); | ||
} | ||
|
||
public void add(TKey key,TItemValue value){ | ||
Object keyId = mIDMapper.keyToKeyId(key); | ||
if(mKeyToValuesMap.get(keyId)==null){ | ||
mKeyToValuesMap.put(keyId,new ArrayList<TItemValue>()); | ||
} | ||
//remove old relationship | ||
TKey keyForValue = getKey(value); | ||
if(keyForValue !=null){ | ||
mKeyToValuesMap.get(mIDMapper.keyToKeyId(keyForValue)).remove(value); | ||
} | ||
mValueToKeyIndexer.put(mIDMapper.valueToValueId(value), key); | ||
if(!containsValue(mKeyToValuesMap.get(mIDMapper.keyToKeyId(key)),value)) { | ||
mKeyToValuesMap.get(mIDMapper.keyToKeyId(key)).add(value); | ||
} | ||
} | ||
|
||
public void removeKey(TKey key){ | ||
if(mKeyToValuesMap.get(mIDMapper.keyToKeyId(key))!=null){ | ||
for (TItemValue value : mKeyToValuesMap.get(mIDMapper.keyToKeyId(key))){ | ||
mValueToKeyIndexer.remove(mIDMapper.valueToValueId(value)); | ||
} | ||
mKeyToValuesMap.remove(mIDMapper.keyToKeyId(key)); | ||
} | ||
} | ||
public void removeValue(TItemValue value){ | ||
if(getKey(value)!=null){ | ||
List<TItemValue> itemValues = mKeyToValuesMap.get(mIDMapper.keyToKeyId(getKey(value))); | ||
if(itemValues!=null){ | ||
itemValues.remove(value); | ||
} | ||
} | ||
mValueToKeyIndexer.remove(mIDMapper.valueToValueId(value)); | ||
} | ||
|
||
public void clear(){ | ||
mValueToKeyIndexer.clear(); | ||
mKeyToValuesMap.clear(); | ||
} | ||
|
||
public void clearValues(){ | ||
for (Map.Entry<Object,List<TItemValue>> entry:entrySet()){ | ||
if(entry.getValue()!=null){ | ||
entry.getValue().clear(); | ||
} | ||
} | ||
mValueToKeyIndexer.clear(); | ||
} | ||
|
||
public Set<Map.Entry<Object,List<TItemValue>>> entrySet(){ | ||
return mKeyToValuesMap.entrySet(); | ||
} | ||
|
||
public Set<Map.Entry<Object,TKey>> reverseEntrySet(){ | ||
return mValueToKeyIndexer.entrySet(); | ||
} | ||
|
||
public int size(){ | ||
return mKeyToValuesMap.size(); | ||
} | ||
public int valuesSize(){ | ||
return mValueToKeyIndexer.size(); | ||
} | ||
|
||
protected boolean containsValue(List<TItemValue> list,TItemValue value){ | ||
for (TItemValue itemValue :list){ | ||
if(mIDMapper.valueToValueId(itemValue).equals(mIDMapper.valueToValueId(value))){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* @param position | ||
* @return | ||
*/ | ||
public TItemValue getValueByPosition(int position){ | ||
Object[] vauleIdArray = mValueToKeyIndexer.keySet().toArray(); | ||
if(position>vauleIdArray.length){ | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
Object valueId = vauleIdArray[position]; | ||
return mIDMapper.valueIdToValue(valueId); | ||
} | ||
} |
Oops, something went wrong.