├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── libraries │ ├── appcompat_v7_22_1_1.xml │ ├── gson_2_3.xml │ ├── support_annotations_22_1_1.xml │ └── support_v4_22_1_1.xml ├── misc.xml ├── modules.xml ├── vcs.xml └── workspace.xml ├── .travis.yml ├── README.md ├── Session.iml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── sample.iml └── src │ ├── androidTest │ └── java │ │ └── kappsmobile │ │ └── sessionsample │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── kevindjf │ │ └── session │ │ └── sample │ │ ├── MainActivity.java │ │ ├── model │ │ └── Book.java │ │ └── session │ │ └── CustomBookSession.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── menu │ └── menu_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── session ├── .gitignore ├── build.gradle ├── proguard-rules.pro ├── session.iml └── src │ ├── androidTest │ └── java │ │ └── kappsmobile │ │ └── session │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── github │ │ └── kevindjf │ │ └── session │ │ ├── ListJson.java │ │ └── Session.java │ └── res │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ └── values │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Session -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_22_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/gson_2_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_22_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_22_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | Android API 10 Platform 27 | 28 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 36 | 37 | 40 | 41 | 44 | 45 | 46 | 47 | 50 | 51 | 54 | 55 | 58 | 59 | 62 | 63 | 66 | 67 | 68 | 69 | 72 | 73 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 148 | 1014 | 1019 | 1374 | 1377 | 1378 | 1379 | 1384 | 1385 | 1386 | 1387 | 1388 | 1389 | 1394 | 1395 | 1396 | 1397 | 1398 | 1399 | 1400 | 1401 | 1402 | 1403 | 1404 | 1405 | 1406 | 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1414 | 1415 | 1416 | 1417 | 1418 | 1419 | 1420 | 1421 | 1424 | 1425 | 1426 | 1427 | 1430 | 1431 | 1434 | 1435 | 1436 | 1437 | 1440 | 1441 | 1444 | 1445 | 1448 | 1449 | 1450 | 1451 | 1454 | 1455 | 1458 | 1459 | 1462 | 1463 | 1466 | 1467 | 1470 | 1471 | 1472 | 1473 | 1476 | 1477 | 1480 | 1481 | 1484 | 1485 | 1488 | 1489 | 1492 | 1493 | 1496 | 1497 | 1500 | 1501 | 1502 | 1503 | 1506 | 1507 | 1510 | 1511 | 1514 | 1515 | 1518 | 1519 | 1520 | 1521 | 1524 | 1525 | 1528 | 1529 | 1532 | 1533 | 1534 | 1535 | 1536 | 1537 | 1538 | 1539 | 1540 | 1543 | 1544 | 1545 | 1546 | 1549 | 1550 | 1553 | 1554 | 1555 | 1556 | 1557 | 1558 | 1559 | 1560 | 1561 | 1562 | 1563 | 1564 | 1565 | 1566 | 1567 | 1568 | 1569 | 1570 | 1571 | 1572 | 1573 | 1574 | 1596 | 1597 | 1598 | 1611 | 1612 | 1613 | 1614 | 1628 | 1629 | 1630 | 1631 | 1634 | 1635 | 1636 | 1643 | 1644 | 1645 | 1646 | 1664 | 1671 | 1672 | 1673 | 1695 | 1696 | 1697 | 1698 | 1699 | 1701 | 1702 | localhost 1703 | 5050 1704 | 1705 | 1706 | 1707 | 1708 | 1709 | 1710 | 1431585219154 1711 | 1714 | 1715 | 1716 | 1717 | 1718 | 1719 | 1720 | 1721 | 1722 | 1723 | 1724 | 1725 | 1726 | 1727 | 1728 | 1729 | 1730 | 1731 | 1732 | 1733 | 1734 | 1735 | 1736 | 1737 | 1738 | 1739 | 1740 | 1741 | 1742 | 1743 | 1744 | 1745 | 1746 | 1747 | 1748 | 1749 | 1751 | 1752 | 1755 | 1756 | 1757 | 1758 | 1759 | 1760 | 1761 | 1762 | 1763 | 1764 | 1765 | 1766 | 1767 | 1768 | 1769 | 1770 | 1771 | 1772 | 1773 | 1774 | 1775 | 1776 | 1777 | 1778 | 1779 | 1780 | 1781 | 1782 | 1783 | 1784 | 1785 | 1786 | 1787 | 1788 | 1789 | 1790 | 1791 | 1792 | 1793 | 1794 | 1795 | 1796 | 1797 | 1798 | 1799 | 1800 | 1801 | 1802 | 1803 | 1804 | 1805 | 1806 | 1807 | 1808 | 1809 | 1810 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | 3 | jdk: 4 | - openjdk7 5 | 6 | android: 7 | components: 8 | 9 | - build-tools-21.1.1 10 | - android-21 11 | - extra-android-support 12 | - extra-google-google_play_services 13 | - extra-google-m2repository 14 | - extra-android-m2repository 15 | 16 | notifications: 17 | email: true 18 | 19 | # Turn off caching to avoid any caching problems 20 | cache: false 21 | # Use the Travis Container-Based Infrastructure (see #203) 22 | sudo: false 23 | 24 | install: 25 | # Ensure Gradle wrapper is executable, download wrapper and show version 26 | - chmod +x ./gradlew; ls -l gradlew; ./gradlew wrapper -v 27 | # Download and show android dependencies 28 | # - ./gradlew androidDependencies 29 | 30 | script: 31 | - ./gradlew clean assembleDebug -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Session 2 | ======= 3 | 4 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Session-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/1792) 5 | [![Build Status](https://travis-ci.org/kevindjf/Session.svg)](https://travis-ci.org/kevindjf/Session) 6 | 7 | 8 | Session is a easy to use Persistance Library which save datas into SharedPreference. 9 | 10 | **Session might not be used to save a huge models list, please use it only if you have to keep a small amount of datas** 11 | 12 | **for example : save local favorites** 13 | 14 | #Download 15 | 16 | ```groovy 17 | compile ('com.github.kevindjf:session:1.0.1@aar'){ 18 | transitive = true 19 | } 20 | ``` 21 | 22 | #Simple usage 23 | 24 | ##Create a Session 25 | ```java 26 | Session bookSession = new Session<>(this,Book.class); 27 | ``` 28 | 29 | Will create or retrieve the last saved Book session 30 | 31 | ##Add Objects 32 | ```java 33 | bookSession.add(new Book("Harry Potter",10)) 34 | .add(new Book("Hunger Games ",5)); 35 | ``` 36 | 37 | ##Retrieve saved objects 38 | This book will be saved, and when you use bookSession.getAll(), **even after restarting the activity** 39 | ```java 40 | bookSession.getAll(); 41 | //will return [Book{"Harry Potter",10},Book{"Hunger Games",5}] 42 | ``` 43 | 44 | ##Clear the session 45 | ```java 46 | bookSession.clear(); 47 | ``` 48 | 49 | #Capabilities 50 | 51 | ##Create multiple sessions 52 | To remove all session's objects 53 | ```java 54 | //will use sharedpreferences key "Book" 55 | Session bookSession = new Session<>(this,Book.class); 56 | 57 | //will use sharedpreferences key "favorites" 58 | Session bookSessionFavorites = new Session<>(this,Book.class,"favorites"); 59 | ``` 60 | 61 | ##Retrieve object by attribute 62 | ```java 63 | bookSession.getByAttribute("name","Harry Potter"); 64 | //will return Book{"Harry Potter",10} 65 | 66 | //you can also retrieve a list 67 | bookSession.getAllByAttribute("name","Harry Potter"); 68 | //will return [Book{"Harry Potter",10}] 69 | ``` 70 | 71 | ##Remove objects 72 | ```java 73 | bookSession.removeAtIndex(1); 74 | 75 | Book bookHarry = bookSession.getByAttribute("name","Harry Potter"); 76 | bookSession.remove(bookHarry); 77 | 78 | bookSession.removeAll(bookList); 79 | ``` 80 | 81 | #Customisation 82 | 83 | You can extend Session<> to add your own methods 84 | ```java 85 | public class CustomBookSession extends Session { 86 | 87 | public CustomBookSession(Context context) { 88 | super(context, Book.class); 89 | } 90 | 91 | public CustomBookSession(Context context, String nomSession) { 92 | super(context, Book.class, nomSession); 93 | } 94 | 95 | //and add your custom methods 96 | public List getBooksLessThan(int number){ 97 | List books = getAll(); 98 | 99 | List returnList = new ArrayList<>(); 100 | for (Book book : books){ 101 | if(book.getNumber() < number) 102 | returnList.add(book); 103 | } 104 | 105 | return returnList; 106 | } 107 | } 108 | ``` 109 | 110 | Usage 111 | ```java 112 | //will use sharedpreferences key "Book" 113 | CustomBookSession session = new CustomBookSession(getApplicationContext()); 114 | 115 | //will use sharedpreferences key "favorites" 116 | CustomBookSession sessionFavorites = new CustomBookSession(getApplicationContext(),"favorites"); 117 | 118 | session.getBooksLessThan(9); 119 | //will return [Book{"Hunger Games",5}] 120 | ``` 121 | 122 | Community 123 | -------- 124 | 125 | Looking for contributors, feel free to fork ! 126 | 127 | Dependencies 128 | -------- 129 | 130 | - GSON from Google : [https://github.com/google/gson][gson] 131 | 132 | Credits 133 | ------- 134 | 135 | Author: Kévin De Jesus Ferreira 136 | 137 | 138 | Follow me on Google+ 140 | 141 | 142 | Follow me on Twitter 144 | 145 | 146 | Follow me on LinkedIn 148 | 149 | 150 | 151 | License 152 | -------- 153 | 154 | Copyright 2015 kevindjf, Inc. 155 | 156 | Licensed under the Apache License, Version 2.0 (the "License"); 157 | you may not use this file except in compliance with the License. 158 | You may obtain a copy of the License at 159 | 160 | http://www.apache.org/licenses/LICENSE-2.0 161 | 162 | Unless required by applicable law or agreed to in writing, software 163 | distributed under the License is distributed on an "AS IS" BASIS, 164 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 165 | See the License for the specific language governing permissions and 166 | limitations under the License. 167 | 168 | [gson]: https://github.com/google/gson 169 | -------------------------------------------------------------------------------- /Session.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.0.1' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 21 5 | buildToolsVersion "21.1.1" 6 | 7 | defaultConfig { 8 | minSdkVersion 15 9 | targetSdkVersion 21 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | compile fileTree(dir: 'libs', include: ['*.jar']) 23 | compile 'com.android.support:appcompat-v7:22.1.1' 24 | compile project(':session') 25 | 26 | } 27 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/kevindejesusferreira/Documents/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 | #} 18 | -------------------------------------------------------------------------------- /sample/sample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/kappsmobile/sessionsample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package kappsmobile.sessionsample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/kevindjf/session/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.github.kevindjf.session.sample; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v7.app.ActionBarActivity; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.widget.TextView; 8 | import android.widget.Toast; 9 | 10 | import com.github.kevindjf.session.Session; 11 | 12 | import com.github.kevindjf.session.sample.R; 13 | import com.github.kevindjf.session.sample.model.Book; 14 | 15 | 16 | public class MainActivity extends ActionBarActivity { 17 | 18 | Session bookSession; 19 | TextView name_book; 20 | TextView number_book; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.activity_main); 26 | 27 | init(); 28 | 29 | Book book = bookSession.getByAttribute("name", "Harry Potter"); 30 | 31 | name_book.setText(book.getName()); 32 | number_book.setText(book.getNumber() + ""); 33 | } 34 | 35 | private void init() { 36 | 37 | bookSession = new Session<>(this,Book.class); 38 | 39 | bookSession.clear(); 40 | 41 | bookSession.add(new Book("Harry Potter",10)) 42 | .add(new Book("Hunger Games ",5)); 43 | 44 | name_book = (TextView) findViewById(R.id.name_book); 45 | number_book = (TextView) findViewById(R.id.number_book); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sample/src/main/java/com/github/kevindjf/session/sample/model/Book.java: -------------------------------------------------------------------------------- 1 | package com.github.kevindjf.session.sample.model; 2 | 3 | /** 4 | * Created by kevindejesusferreira on 05/05/15. 5 | */ 6 | public class Book { 7 | 8 | String name; 9 | int number; 10 | 11 | public Book(String name, int number) { 12 | this.name = name; 13 | this.number = number; 14 | } 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return "nameBook='" + name ; 27 | } 28 | 29 | public int getNumber() { 30 | return number; 31 | } 32 | 33 | public void setNumber(int number) { 34 | this.number = number; 35 | } 36 | 37 | 38 | @Override 39 | public boolean equals(Object o) { 40 | if (this == o) return true; 41 | if (!(o instanceof Book)) return false; 42 | 43 | Book book = (Book) o; 44 | return !(getName() != null ? !getName().equals(book.getName()) : book.getName() != null); 45 | 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | int result = getName() != null ? getName().hashCode() : 0; 51 | result = 31 * result + getNumber(); 52 | return result; 53 | } 54 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/github/kevindjf/session/sample/session/CustomBookSession.java: -------------------------------------------------------------------------------- 1 | package com.github.kevindjf.session.sample.session; 2 | 3 | import android.content.Context; 4 | 5 | import com.github.kevindjf.session.Session; 6 | import com.github.kevindjf.session.sample.model.Book; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by florentchampigny on 07/05/15. 13 | */ 14 | public class CustomBookSession extends Session { 15 | 16 | public CustomBookSession(Context context) { 17 | super(context, Book.class); 18 | } 19 | 20 | public CustomBookSession(Context context, String nomSession) { 21 | super(context, Book.class, nomSession); 22 | } 23 | 24 | //and add your custom methods 25 | 26 | public List getBooksLessThan(int number){ 27 | List books = getAll(); 28 | 29 | List returnList = new ArrayList<>(); 30 | for (Book book : books){ 31 | if(book.getNumber() < number) 32 | returnList.add(book); 33 | } 34 | 35 | return returnList; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 18 | 19 | 20 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SessionSample 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /session/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /session/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | 4 | // ext is a gradle closure allowing the declaration of global properties 5 | ext { 6 | PUBLISH_GROUP_ID = 'com.github.kevindjf' 7 | PUBLISH_ARTIFACT_ID = 'session' 8 | PUBLISH_VERSION = '1.0.1' 9 | } 10 | 11 | android { 12 | compileSdkVersion 21 13 | buildToolsVersion "21.1.1" 14 | 15 | defaultConfig { 16 | minSdkVersion 15 17 | targetSdkVersion 22 18 | versionCode 2 19 | versionName "1.0.1" 20 | } 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | } 28 | 29 | dependencies { 30 | compile fileTree(dir: 'libs', include: ['*.jar']) 31 | compile 'com.android.support:appcompat-v7:22.1.1' 32 | compile 'com.google.code.gson:gson:2.3' 33 | 34 | } 35 | 36 | 37 | apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle' 38 | -------------------------------------------------------------------------------- /session/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/kevindejesusferreira/Documents/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 | #} 18 | -------------------------------------------------------------------------------- /session/session.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /session/src/androidTest/java/kappsmobile/session/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package kappsmobile.session; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /session/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /session/src/main/java/com/github/kevindjf/session/ListJson.java: -------------------------------------------------------------------------------- 1 | package com.github.kevindjf.session; 2 | 3 | import java.lang.reflect.ParameterizedType; 4 | import java.lang.reflect.Type; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by kevindejesusferreira on 05/05/15. 9 | */ 10 | public class ListJson implements ParameterizedType 11 | { 12 | private Class wrapped; 13 | 14 | public ListJson(Class wrapper) 15 | { 16 | this.wrapped = wrapper; 17 | } 18 | 19 | @Override 20 | public Type[] getActualTypeArguments() 21 | { 22 | return new Type[] { wrapped }; 23 | } 24 | 25 | @Override 26 | public Type getRawType() 27 | { 28 | return List.class; 29 | } 30 | 31 | @Override 32 | public Type getOwnerType() 33 | { 34 | return null; 35 | } 36 | } -------------------------------------------------------------------------------- /session/src/main/java/com/github/kevindjf/session/Session.java: -------------------------------------------------------------------------------- 1 | package com.github.kevindjf.session; 2 | 3 | /** 4 | * Created by kevindejesusferreira on 05/05/15. 5 | */ 6 | import android.content.Context; 7 | import android.content.SharedPreferences; 8 | import android.preference.PreferenceManager; 9 | 10 | import com.google.gson.Gson; 11 | 12 | import java.lang.reflect.Field; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Arrays; 16 | import java.util.List; 17 | 18 | 19 | public class Session { 20 | 21 | protected final SharedPreferences sharedPreferences; 22 | protected final Class type; 23 | protected static final Gson gson = new Gson(); //improves performances to have only one Gson 24 | 25 | public Session(Context context, Class type) { 26 | sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); 27 | this.type = type; 28 | } 29 | 30 | public Session(Context context,Class type,String nomSession){ 31 | sharedPreferences = context.getSharedPreferences(nomSession, Context.MODE_PRIVATE); 32 | this.type = type; 33 | } 34 | 35 | protected void save(List objects){ 36 | sharedPreferences 37 | .edit() 38 | .putString(getNameType(), new Gson().toJson(objects)) 39 | .apply(); 40 | } 41 | 42 | public Session add(T object) { 43 | if (object == null) 44 | return this; 45 | 46 | List objects = this.getAll(); 47 | 48 | if (objects == null) 49 | objects = new ArrayList<>(); 50 | 51 | objects.add(object); 52 | 53 | this.save(objects); 54 | 55 | return this; 56 | } 57 | 58 | public Session add(int index,T object) { 59 | if (object == null) 60 | return this; 61 | 62 | List objects = getAll(); 63 | 64 | if (objects == null) 65 | objects = new ArrayList<>(); 66 | 67 | objects.add(index, object); 68 | 69 | this.save(objects); 70 | 71 | return this; 72 | } 73 | 74 | public Session addAll(ArrayList objects) { 75 | if (objects == null || objects.size() == 0) 76 | return this; 77 | 78 | List objectsBDD = getAll(); 79 | 80 | objectsBDD.addAll(objects); 81 | 82 | this.save(objectsBDD); 83 | 84 | return this; 85 | } 86 | 87 | public Session addAll(T[] objects) { 88 | if (objects == null || objects.length == 0) 89 | return this; 90 | 91 | List objectsBDD = getAll(); 92 | 93 | objectsBDD.addAll(Arrays.asList(objects)); 94 | 95 | this.save(objectsBDD); 96 | 97 | return this; 98 | } 99 | 100 | public List getAll() { 101 | String json = sharedPreferences.getString(getNameType(), null); 102 | if(json == null) 103 | return new ArrayList<>(); 104 | else 105 | return gson.fromJson(json, new ListJson(type)); 106 | } 107 | 108 | public T getFirst() { 109 | List objects = getAll(); 110 | 111 | if (objects == null || objects.size() == 0) 112 | return null; 113 | 114 | return objects.get(0); 115 | } 116 | 117 | public Session clear() { 118 | save(new ArrayList()); 119 | return this; 120 | } 121 | 122 | 123 | public Session update(T o){ 124 | List objects = getAll(); 125 | 126 | for(int i = 0; i < objects.size();i++){ 127 | if(objects.get(i).equals(o)) { 128 | removeAtIndex(i); 129 | add(i,o); 130 | } 131 | } 132 | 133 | return this; 134 | } 135 | 136 | public Session update (T o,String attributeName, Object value){ 137 | 138 | List objects = getAll(); 139 | 140 | if (objects == null || objects.size() == 0) 141 | return this; 142 | 143 | Field field = null; 144 | try { 145 | 146 | field = type.getDeclaredField(attributeName); 147 | 148 | field.setAccessible(true); 149 | 150 | 151 | Object objectReturn; 152 | 153 | for (int i = 0 ; i < objects.size() ;i++) { 154 | 155 | try { 156 | objectReturn = field.get(objects.get(i)); 157 | 158 | if ((value).equals(objectReturn)){ 159 | removeAtIndex(i); 160 | add(i,o); 161 | return this; 162 | } 163 | 164 | 165 | } catch (IllegalAccessException e) { 166 | e.printStackTrace(); 167 | } 168 | 169 | } 170 | } catch (NoSuchFieldException e) { 171 | e.printStackTrace(); 172 | } 173 | 174 | return this; 175 | } 176 | 177 | public T getByAttribute(String attributeName, Object value) { 178 | 179 | List objects = getAll(); 180 | 181 | if (objects == null || objects.size() == 0) 182 | return null; 183 | 184 | Field field = null; 185 | try { 186 | field = type.getDeclaredField(attributeName); 187 | field.setAccessible(true); 188 | 189 | Object objectReturn; 190 | 191 | for (T variable : objects) { 192 | try { 193 | objectReturn = field.get(variable); 194 | 195 | if ((value).equals(objectReturn)) 196 | return variable; 197 | } catch (IllegalAccessException e) { 198 | e.printStackTrace(); 199 | } 200 | } 201 | } catch (NoSuchFieldException e) { 202 | e.printStackTrace(); 203 | } 204 | 205 | return null; 206 | } 207 | 208 | public List getAllByAttribute(String attributeName, Object value) { 209 | 210 | List objects = getAll(); 211 | 212 | if (objects == null || objects.size() == 0) 213 | return null; 214 | 215 | List objectsReturn = new ArrayList<>(); 216 | 217 | Field field = null; 218 | try { 219 | field = type.getDeclaredField(attributeName); 220 | field.setAccessible(true); 221 | 222 | Object objectReturn; 223 | for (T variable : objects) { 224 | try { 225 | objectReturn = field.get(variable); 226 | if ((value).equals(objectReturn)) 227 | objectsReturn.add(variable); 228 | } catch (IllegalAccessException e) { 229 | e.printStackTrace(); 230 | } 231 | } 232 | } catch (NoSuchFieldException e) { 233 | e.printStackTrace(); 234 | } 235 | 236 | return objectsReturn; 237 | } 238 | 239 | 240 | public List between(int begin, int end) { 241 | List objects = getAll(); 242 | 243 | if (objects != null) 244 | return objects.subList(begin, end); 245 | 246 | return new ArrayList<>(); 247 | } 248 | 249 | public int count() { 250 | List objects = getAll(); 251 | 252 | if (objects == null || objects.size() == 0) 253 | return 0; 254 | 255 | return objects.size(); 256 | } 257 | 258 | public List subList(int begin, int count) { 259 | 260 | List objects = getAll(); 261 | 262 | if (objects == null || objects.size() < begin + count) 263 | return new ArrayList<>(); 264 | 265 | List objectsInteval = new ArrayList<>(); 266 | 267 | for (int i = begin; i < begin + count; i++) 268 | objectsInteval.add(objects.get(i)); 269 | 270 | 271 | return objectsInteval; 272 | } 273 | 274 | private String getNameType() { 275 | return this.type.getSimpleName(); 276 | } 277 | 278 | 279 | public boolean contains(T o){ 280 | return getAll().contains(o); 281 | } 282 | 283 | 284 | public boolean containsAll(List objects){ 285 | return getAll().contains(objects); 286 | } 287 | 288 | public boolean remove(T o){ 289 | List objects = getAll(); 290 | 291 | boolean removed = objects.remove(o); 292 | if(removed) { 293 | save(objects); 294 | } 295 | 296 | return removed; 297 | } 298 | 299 | public boolean removeAll(List objects){ 300 | List objectsSaved = getAll(); 301 | 302 | boolean removed = false; 303 | for(Object o : objects){ 304 | removed |= objectsSaved.remove(o); 305 | } 306 | 307 | if(removed) { 308 | save(objects); 309 | } 310 | 311 | return removed; 312 | } 313 | 314 | public boolean removeAll(T[] objects){ 315 | return this.removeAll(Arrays.asList(objects)); 316 | } 317 | 318 | 319 | public T removeAtIndex(int index){ 320 | List objects = getAll(); 321 | 322 | T remove = objects.remove(index); 323 | 324 | save(objects); 325 | 326 | return remove; 327 | } 328 | 329 | 330 | public T objectAtIndex(int index){ 331 | List objects = getAll(); 332 | 333 | if(objects == null || objects.size() < index) 334 | return null; 335 | 336 | return objects.get(index); 337 | } 338 | 339 | 340 | public boolean isEmpty(){ 341 | List objects = getAll(); 342 | 343 | return (objects == null || objects.isEmpty()); 344 | } 345 | } 346 | -------------------------------------------------------------------------------- /session/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/session/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /session/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/session/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /session/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/session/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /session/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevindjf/Session/2a984ce7ecc9ae3467541543245fbae5d817a8fe/session/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /session/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Session 3 | 4 | -------------------------------------------------------------------------------- /session/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':session', ':sample' 2 | --------------------------------------------------------------------------------