├── .gitignore ├── README.md ├── adapper-example ├── build.gradle ├── proguard-rules.txt └── src │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── databases │ │ └── example.db │ ├── java │ └── com │ │ └── scopely │ │ └── adapper │ │ ├── example │ │ ├── AdaptersActivity.java │ │ ├── BaseActivity.java │ │ ├── BuckWildActivity.java │ │ ├── DeadSimpleActivity.java │ │ ├── SelectorsActivity.java │ │ ├── Utils.java │ │ ├── fragments │ │ │ ├── AbstractFragment.java │ │ │ ├── BuckWildFragment.java │ │ │ ├── CursorFragment.java │ │ │ ├── GroupableGridFragment.java │ │ │ ├── GroupableListFragment.java │ │ │ ├── HeterogeneousGroupableGridFragment.java │ │ │ ├── RecursiveFragment.java │ │ │ ├── SelectCursorFragment.java │ │ │ ├── SelectGroupableListFragment.java │ │ │ ├── SelectPopulateableListFragment.java │ │ │ ├── SelectRecursiveFragment.java │ │ │ └── SimpleListFragment.java │ │ ├── objects │ │ │ └── NameAndMood.java │ │ └── views │ │ │ └── NameAndMoodView.java │ │ ├── impls │ │ └── PopulatableProvider.java │ │ └── interfaces │ │ └── Populatable.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ ├── happy.png │ ├── ic_launcher.png │ ├── neutral.png │ └── sad.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ ├── activity_main.xml │ ├── fragment_list_view.xml │ ├── fragment_simple_list.xml │ ├── view_name_and_mood.xml │ ├── view_single.xml │ └── view_single_buck_wild.xml │ ├── menu │ ├── activity_base.xml │ ├── fragment_animated_adapter.xml │ ├── fragment_filterable.xml │ └── fragment_selector.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── adapper ├── build.gradle ├── gradle.properties ├── maven_push.gradle └── src │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── scopely │ │ └── adapper │ │ ├── adapters │ │ ├── BaseAdapper.java │ │ ├── CursorAdapper.java │ │ ├── GroupableAdapper.java │ │ ├── ListAdapper.java │ │ ├── RecursiveAdapper.java │ │ └── SingleViewAdapper.java │ │ ├── extras │ │ ├── GroupableSpanSizeLookup.java │ │ └── InvertedSpanSizeLookup.java │ │ ├── impls │ │ ├── BidentifierImpl.java │ │ ├── GroupComparatorImpl.java │ │ ├── HashCodeIdentifier.java │ │ ├── NaiveLookup.java │ │ ├── TypedViewHolder.java │ │ └── ViewProviderImpl.java │ │ ├── interfaces │ │ ├── Bidentifier.java │ │ ├── FilterFunction.java │ │ ├── GroupComparator.java │ │ ├── GroupPositionIdentifier.java │ │ ├── Identifier.java │ │ ├── Lookup.java │ │ ├── MiniOrm.java │ │ ├── Reorderable.java │ │ ├── SelectionManager.java │ │ └── ViewProvider.java │ │ ├── selection │ │ ├── MultiSelectManager.java │ │ └── RadioSelectManager.java │ │ └── utils │ │ ├── CompareUtils.java │ │ ├── CompositeFilter.java │ │ ├── FunctionList.java │ │ ├── ListUtils.java │ │ ├── SetUtils.java │ │ └── SparseArrayUtils.java │ └── test │ └── java │ └── com │ └── scopely │ └── adapper │ └── utils │ └── ListUtilsTest.java ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── 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 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | #Log Files 26 | *.log 27 | 28 | 29 | #OSX files 30 | .DS_Store 31 | .AppleDouble 32 | .LSOverride 33 | 34 | # Icon must end with two \r 35 | Icon 36 | 37 | 38 | # Thumbnails 39 | ._* 40 | 41 | # Files that might appear on external disk 42 | .Spotlight-V100 43 | .Trashes 44 | 45 | # Directories potentially created on remote AFP share 46 | .AppleDB 47 | .AppleDesktop 48 | Network Trash Folder 49 | Temporary Items 50 | .apdisk 51 | 52 | 53 | # IDEA 54 | .idea 55 | *.iml 56 | -------------------------------------------------------------------------------- /adapper-example/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | repositories { 19 | jcenter() 20 | } 21 | dependencies { 22 | classpath 'com.android.tools.build:gradle:3.0.0-alpha4' 23 | } 24 | } 25 | apply plugin: 'com.android.application' 26 | 27 | android { 28 | compileSdkVersion 25 29 | buildToolsVersion '25.0.2' 30 | 31 | defaultConfig { 32 | minSdkVersion 14 33 | targetSdkVersion 25 34 | versionCode 1 35 | versionName "1.0.0" 36 | } 37 | } 38 | 39 | dependencies { 40 | compile project(":adapper") 41 | compile 'com.android.support:support-v4:25.3.1' 42 | compile 'com.android.support:support-v13:25.3.1' 43 | compile 'com.viewpagerindicator:library:2.4.1' 44 | compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1' 45 | } 46 | -------------------------------------------------------------------------------- /adapper-example/proguard-rules.txt: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the ProGuard 5 | # include property in project.properties. 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 | #} -------------------------------------------------------------------------------- /adapper-example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 41 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /adapper-example/src/main/assets/databases/example.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/assets/databases/example.db -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/AdaptersActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example; 18 | 19 | import android.os.Bundle; 20 | 21 | import com.scopely.adapper.example.fragments.CursorFragment; 22 | import com.scopely.adapper.example.fragments.GroupableGridFragment; 23 | import com.scopely.adapper.example.fragments.GroupableListFragment; 24 | import com.scopely.adapper.example.fragments.HeterogeneousGroupableGridFragment; 25 | import com.scopely.adapper.example.fragments.RecursiveFragment; 26 | import com.scopely.adapper.example.fragments.SimpleListFragment; 27 | 28 | import java.util.Arrays; 29 | 30 | 31 | public class AdaptersActivity extends BaseActivity { 32 | 33 | @Override 34 | protected void onCreate(Bundle savedInstanceState) { 35 | fragments = Arrays.asList(new SimpleListFragment(), 36 | new GroupableListFragment(), 37 | new GroupableGridFragment(), 38 | new HeterogeneousGroupableGridFragment(), 39 | new RecursiveFragment(), 40 | new CursorFragment() 41 | ); 42 | titles = Arrays.asList( 43 | title(R.string.title_section_simple_list), 44 | title(R.string.title_section_groupable_list), 45 | title(R.string.title_section_groupable_grid), 46 | title(R.string.title_section_heterogenous), 47 | title(R.string.title_section_recursive_list), 48 | title(R.string.title_section_cursor) 49 | ); 50 | super.onCreate(savedInstanceState); 51 | } 52 | 53 | @Override 54 | protected int getNavigationItemId() { 55 | return R.id.menu_navigation_adapters; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/BaseActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example; 18 | 19 | import android.app.Activity; 20 | import android.app.Fragment; 21 | import android.app.FragmentManager; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | import android.support.annotation.NonNull; 25 | import android.support.v13.app.FragmentPagerAdapter; 26 | import android.support.v4.view.ViewPager; 27 | import android.view.Menu; 28 | import android.view.MenuInflater; 29 | import android.view.MenuItem; 30 | 31 | import com.viewpagerindicator.TitlePageIndicator; 32 | 33 | import java.util.List; 34 | 35 | public abstract class BaseActivity extends Activity { 36 | SectionsPagerAdapter mSectionsPagerAdapter; 37 | ViewPager mViewPager; 38 | List fragments; 39 | List titles; 40 | 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | getActionBar().setDisplayShowHomeEnabled(false); 45 | getActionBar().setDisplayShowTitleEnabled(false); 46 | setContentView(R.layout.activity_main); 47 | 48 | // Create the adapter that will return a fragment for each of the three 49 | // primary sections of the activity. 50 | mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); 51 | 52 | // Set up the ViewPager with the sections adapter. 53 | mViewPager = (ViewPager) findViewById(R.id.pager); 54 | mViewPager.setAdapter(mSectionsPagerAdapter); 55 | 56 | TitlePageIndicator mViewPagerIndicator = (TitlePageIndicator) findViewById(R.id.titles); 57 | mViewPagerIndicator.setViewPager(mViewPager); 58 | mViewPagerIndicator.setTextColor(getResources().getColor(android.R.color.holo_blue_bright)); 59 | mViewPagerIndicator.setSelectedColor(getResources().getColor(android.R.color.holo_blue_bright)); 60 | } 61 | 62 | 63 | /** 64 | * A {@link android.support.v13.app.FragmentPagerAdapter} that returns a fragment corresponding to 65 | * one of the sections/tabs/pages. 66 | */ 67 | public class SectionsPagerAdapter extends FragmentPagerAdapter { 68 | 69 | public SectionsPagerAdapter(FragmentManager fm) { 70 | super(fm); 71 | } 72 | 73 | @Override 74 | public Fragment getItem(int position) { 75 | return fragments.get(position); 76 | } 77 | 78 | @Override 79 | public int getCount() { 80 | return fragments.size(); 81 | } 82 | 83 | @Override 84 | public CharSequence getPageTitle(int position) { 85 | return titles.get(position); 86 | } 87 | } 88 | 89 | @Override 90 | public boolean onMenuItemSelected(int featureId, @NonNull MenuItem item) { 91 | if(item.getItemId() == R.id.menu_navigation_adapters) { 92 | startActivity(new Intent(this, AdaptersActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); 93 | return true; 94 | } else if (item.getItemId() == R.id.menu_navigation_selectors){ 95 | startActivity(new Intent(this, SelectorsActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); 96 | return true; 97 | } else if (item.getItemId() == R.id.menu_navigation_buck_wild){ 98 | startActivity(new Intent(this, BuckWildActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); 99 | return true; 100 | } else if (item.getItemId() == R.id.menu_navigation_dead_simple){ 101 | startActivity(new Intent(this, DeadSimpleActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); 102 | return true; 103 | } else 104 | return super.onMenuItemSelected(featureId, item); 105 | } 106 | 107 | @Override 108 | public boolean onCreateOptionsMenu(Menu menu) { 109 | MenuInflater inflater = getMenuInflater(); 110 | inflater.inflate(R.menu.activity_base, menu); 111 | menu.findItem(getNavigationItemId()).setVisible(false); 112 | return true; 113 | } 114 | 115 | protected CharSequence title(int id) { 116 | return getString(id); 117 | } 118 | 119 | protected abstract int getNavigationItemId(); 120 | } 121 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/BuckWildActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example; 18 | 19 | import android.os.Bundle; 20 | 21 | import com.scopely.adapper.example.fragments.BuckWildFragment; 22 | 23 | import java.util.Arrays; 24 | 25 | 26 | public class BuckWildActivity extends BaseActivity { 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | fragments = Arrays.asList( 31 | new BuckWildFragment() 32 | ); 33 | titles = Arrays.asList( 34 | title(R.string.title_section_buck_wild) 35 | ); 36 | super.onCreate(savedInstanceState); 37 | } 38 | 39 | @Override 40 | protected int getNavigationItemId() { 41 | return R.id.menu_navigation_buck_wild; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/DeadSimpleActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.os.Bundle; 22 | import android.support.annotation.NonNull; 23 | import android.support.annotation.Nullable; 24 | import android.support.v7.widget.LinearLayoutManager; 25 | import android.support.v7.widget.RecyclerView; 26 | import android.view.Menu; 27 | import android.view.MenuInflater; 28 | import android.view.MenuItem; 29 | import android.widget.TextView; 30 | 31 | import com.scopely.adapper.adapters.ListAdapper; 32 | import com.scopely.adapper.impls.ViewProviderImpl; 33 | import com.scopely.adapper.interfaces.SelectionManager; 34 | import com.scopely.adapper.interfaces.ViewProvider; 35 | 36 | import java.util.Arrays; 37 | import java.util.List; 38 | 39 | 40 | public class DeadSimpleActivity extends Activity { 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | 45 | List list = Arrays.asList("First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth", 46 | "Eleventh", "Twelfth", "Thirteenth", "Fourteenth", "Fifteenth", "Sixteenth", "Seventeenth", "Eighteenth", "Nineteenth", "Twentieth"); 47 | 48 | RecyclerView view = new RecyclerView(this); 49 | view.setLayoutManager(new LinearLayoutManager(this)); 50 | setContentView(view); 51 | 52 | ViewProvider provider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 53 | @Override 54 | protected void bind(TextView view, String s, int position, @Nullable SelectionManager selectionManager) { 55 | view.setText(s); 56 | } 57 | 58 | @Override 59 | public int getViewType(String s) { 60 | return android.R.layout.simple_list_item_1; 61 | } 62 | }; 63 | 64 | RecyclerView.Adapter adapter = new ListAdapper<>(list, provider); 65 | view.setAdapter(adapter); 66 | } 67 | 68 | 69 | 70 | 71 | //-----------------------------------------Navigation----------------------------------------- 72 | @Override 73 | public boolean onCreateOptionsMenu(Menu menu) { 74 | MenuInflater inflater = getMenuInflater(); 75 | inflater.inflate(R.menu.activity_base, menu); 76 | menu.findItem(R.id.menu_navigation_dead_simple).setVisible(false); 77 | return true; 78 | } 79 | 80 | @Override 81 | public boolean onMenuItemSelected(int featureId, @NonNull MenuItem item) { 82 | if(item.getItemId() == R.id.menu_navigation_adapters) { 83 | startActivity(new Intent(this, AdaptersActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); 84 | return true; 85 | } else if (item.getItemId() == R.id.menu_navigation_selectors){ 86 | startActivity(new Intent(this, SelectorsActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); 87 | return true; 88 | } else if (item.getItemId() == R.id.menu_navigation_buck_wild){ 89 | startActivity(new Intent(this, BuckWildActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)); 90 | return true; 91 | } else 92 | return super.onMenuItemSelected(featureId, item); 93 | } 94 | //---------------------------------------End Navigation--------------------------------------- 95 | } 96 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/SelectorsActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example; 18 | 19 | import android.os.Bundle; 20 | 21 | import com.scopely.adapper.example.fragments.SelectCursorFragment; 22 | import com.scopely.adapper.example.fragments.SelectGroupableListFragment; 23 | import com.scopely.adapper.example.fragments.SelectPopulateableListFragment; 24 | import com.scopely.adapper.example.fragments.SelectRecursiveFragment; 25 | 26 | import java.util.Arrays; 27 | 28 | 29 | public class SelectorsActivity extends BaseActivity { 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | fragments = Arrays.asList( 34 | new SelectPopulateableListFragment(), 35 | new SelectGroupableListFragment(), 36 | new SelectRecursiveFragment(), 37 | new SelectCursorFragment() 38 | ); 39 | titles = Arrays.asList( 40 | title(R.string.title_section_radio_selection), 41 | title(R.string.title_section_multi_selection), 42 | title(R.string.title_section_limited_selection), 43 | title(R.string.title_section_cursor) 44 | ); 45 | super.onCreate(savedInstanceState); 46 | } 47 | 48 | @Override 49 | protected int getNavigationItemId() { 50 | return R.id.menu_navigation_selectors; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example; 18 | 19 | import com.scopely.adapper.example.objects.NameAndMood; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public class Utils { 25 | public static List generateNameAndMoodList(int size) { 26 | List list = new ArrayList<>(); 27 | for(int i = 0; i < size; i++) { 28 | String name = "Unique Name #" + i; 29 | NameAndMood.Mood[] moods = NameAndMood.Mood.values(); 30 | NameAndMood.Mood mood = moods[i % moods.length]; 31 | list.add(new NameAndMood(mood, name)); 32 | } 33 | return list; 34 | } 35 | 36 | public static List generateStringList(int size) { 37 | List list = new ArrayList<>(); 38 | for(int i = 0; i < size; i++) { 39 | list.add("Item #" + i); 40 | } 41 | return list; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/AbstractFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | 20 | import android.app.Fragment; 21 | import android.os.Bundle; 22 | import android.support.v7.widget.LinearLayoutManager; 23 | import android.support.v7.widget.RecyclerView; 24 | import android.view.LayoutInflater; 25 | import android.view.Menu; 26 | import android.view.MenuInflater; 27 | import android.view.MenuItem; 28 | import android.view.View; 29 | import android.view.ViewGroup; 30 | import android.widget.Filterable; 31 | import android.widget.SearchView; 32 | import android.widget.Toast; 33 | 34 | import com.scopely.adapper.adapters.BaseAdapper; 35 | import com.scopely.adapper.example.R; 36 | 37 | import java.util.Arrays; 38 | import java.util.HashSet; 39 | import java.util.Set; 40 | 41 | /** 42 | * A simple {@link Fragment} subclass. 43 | * 44 | */ 45 | public abstract class AbstractFragment extends Fragment { 46 | protected final static Set MENU_ITEMS_ANIMATION = new HashSet<>(Arrays.asList(R.id.menu_add, R.id.menu_subtract, R.id.menu_reorder)); 47 | protected final static Set MENU_ITEMS_SELECT = new HashSet<>(Arrays.asList(R.id.action_clear, R.id.action_describe)); 48 | protected final static Set MENU_ITEMS_SEARCH = new HashSet<>(Arrays.asList(R.id.action_search)); 49 | private final Set MENU_ITEMS = new HashSet<>(combine(getActionSets())); 50 | 51 | protected abstract Set[] getActionSets(); 52 | 53 | protected RecyclerView recyclerView; 54 | protected T adapter; 55 | 56 | public AbstractFragment() { 57 | // Required empty public constructor 58 | } 59 | 60 | @Override 61 | public void onCreate(Bundle savedInstanceState) { 62 | super.onCreate(savedInstanceState); 63 | setHasOptionsMenu(true); 64 | } 65 | 66 | 67 | @Override 68 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 69 | Bundle savedInstanceState) { 70 | View root = inflater.inflate(R.layout.fragment_simple_list, container, false); 71 | recyclerView = (RecyclerView) root.findViewById(R.id.listView); 72 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 73 | adapter = createAdapter(); 74 | recyclerView.setAdapter(adapter); 75 | return root; 76 | } 77 | 78 | protected abstract T createAdapter(); 79 | 80 | @Override 81 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 82 | super.onCreateOptionsMenu(menu, inflater); 83 | inflater.inflate(R.menu.fragment_filterable, menu); 84 | final MenuItem item = menu.findItem(R.id.action_search); 85 | final SearchView searchItem = (SearchView) item.getActionView(); 86 | searchItem.setQueryHint(getActivity().getString(R.string.filter)); 87 | searchItem.setOnQueryTextListener(new SearchView.OnQueryTextListener() { 88 | @Override 89 | public boolean onQueryTextSubmit(String s) { 90 | return false; 91 | } 92 | 93 | @Override 94 | public boolean onQueryTextChange(String s) { 95 | if(adapter != null && adapter instanceof Filterable){ 96 | ((Filterable) adapter).getFilter().filter(s); 97 | } 98 | return true; 99 | } 100 | }); 101 | 102 | inflater.inflate(R.menu.fragment_selector, menu); 103 | inflater.inflate(R.menu.fragment_animated_adapter, menu); 104 | 105 | for(Set set : new Set[]{MENU_ITEMS_ANIMATION, MENU_ITEMS_SEARCH, MENU_ITEMS_SELECT}) { 106 | for (int integer : set) { 107 | if (!MENU_ITEMS.contains(integer)) { 108 | menu.findItem(integer).setVisible(false); 109 | } 110 | } 111 | } 112 | } 113 | 114 | @Override 115 | public boolean onOptionsItemSelected(MenuItem item) { 116 | if(item.getItemId() == R.id.action_clear){ 117 | clear(); 118 | return true; 119 | } 120 | if(item.getItemId() == R.id.action_describe){ 121 | describe(); 122 | return true; 123 | } 124 | if(item.getItemId() == R.id.menu_add){ 125 | add(); 126 | adapter.update(); 127 | return true; 128 | } 129 | if(item.getItemId() == R.id.menu_subtract){ 130 | remove(); 131 | adapter.update(); 132 | return true; 133 | } 134 | if(item.getItemId() == R.id.menu_reorder){ 135 | reorder(); 136 | adapter.update(); 137 | return true; 138 | } 139 | return super.onOptionsItemSelected(item); 140 | } 141 | 142 | protected void describe(){ 143 | Set set = adapter.getSelections(); 144 | StringBuilder builder = new StringBuilder(); 145 | if(!set.isEmpty()) { 146 | builder.append("Currently selected: \n"); 147 | boolean first = true; 148 | for (Object object : set) { 149 | if (!first) { 150 | builder.append(",\n"); 151 | } 152 | first = false; 153 | builder.append(object.toString()); 154 | } 155 | } else { 156 | builder.append("None selected"); 157 | } 158 | Toast.makeText(getActivity(), builder, Toast.LENGTH_LONG).show(); 159 | } 160 | 161 | private void clear() { 162 | adapter.clearSelections(); 163 | adapter.notifyDataSetChanged(); 164 | } 165 | 166 | private Set combine(Set... sets) { 167 | HashSet combined = new HashSet<>(); 168 | for(Set set : sets) { 169 | combined.addAll(set); 170 | } 171 | return combined; 172 | } 173 | 174 | protected void reorder(){}; 175 | 176 | protected void add(){}; 177 | 178 | protected void remove(){}; 179 | 180 | } 181 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/CursorFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | import android.database.Cursor; 20 | import android.database.sqlite.SQLiteDatabase; 21 | import android.os.Bundle; 22 | import android.support.annotation.Nullable; 23 | import android.widget.FilterQueryProvider; 24 | 25 | import com.readystatesoftware.sqliteasset.SQLiteAssetHelper; 26 | import com.scopely.adapper.adapters.CursorAdapper; 27 | import com.scopely.adapper.example.R; 28 | import com.scopely.adapper.example.objects.NameAndMood; 29 | import com.scopely.adapper.example.views.NameAndMoodView; 30 | import com.scopely.adapper.impls.PopulatableProvider; 31 | import com.scopely.adapper.interfaces.MiniOrm; 32 | import com.scopely.adapper.interfaces.ViewProvider; 33 | 34 | import java.util.Set; 35 | 36 | public class CursorFragment extends AbstractFragment { 37 | 38 | public static final String TABLE_NAME = "name"; 39 | public static final String COLUMN_NAME_ID = "_id"; 40 | private SQLiteDatabase db; 41 | 42 | @Override 43 | public void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | db = new SQLiteAssetHelper(getActivity(), "example.db", null, 1) {} 46 | .getReadableDatabase(); 47 | } 48 | 49 | @Override 50 | public void onDestroy() { 51 | db.close(); 52 | super.onDestroy(); 53 | } 54 | 55 | @Override 56 | protected CursorAdapper createAdapter() { 57 | ViewProvider provider = new PopulatableProvider(R.layout.view_name_and_mood) { 58 | @Override 59 | public int getViewType(NameAndMood s) { 60 | return R.layout.view_name_and_mood; 61 | } 62 | }; 63 | 64 | final Cursor cursor = query(db, null); 65 | 66 | MiniOrm miniOrm = new MiniOrm() { 67 | @Override 68 | public NameAndMood getObject(Cursor c) { 69 | NameAndMood.Mood mood = NameAndMood.Mood.valueOf(c.getString(c.getColumnIndex("mood"))); 70 | String name = c.getString(c.getColumnIndex("name")); 71 | return new NameAndMood(mood, name); 72 | } 73 | }; 74 | CursorAdapper.CursorIdentifier identifier = new CursorAdapper.ColumnIdentifier(COLUMN_NAME_ID); 75 | CursorAdapper.CursorLookup lookup = new CursorAdapper.ColumnLookup<>(db, TABLE_NAME, COLUMN_NAME_ID); 76 | final CursorAdapper adapter = new CursorAdapper<>(cursor, identifier, lookup, miniOrm, provider); 77 | adapter.setFilterQueryProvider(new FilterQueryProvider() { 78 | @Override 79 | public Cursor runQuery(CharSequence constraint) { 80 | return query(db, constraint); 81 | } 82 | }); 83 | return adapter; 84 | } 85 | 86 | private Cursor query(SQLiteDatabase db, @Nullable CharSequence constraint) { 87 | String selection = constraint != null && constraint.length() > 0 ? "name LIKE '%" + constraint.toString() + "%'" : null; 88 | return db.query(TABLE_NAME, null, selection, null, null, null, null); 89 | } 90 | 91 | @Override 92 | protected Set[] getActionSets() { 93 | return new Set[]{MENU_ITEMS_SEARCH}; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/GroupableGridFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | 20 | import android.app.Fragment; 21 | import android.os.Bundle; 22 | import android.support.annotation.Nullable; 23 | import android.support.v7.widget.GridLayoutManager; 24 | import android.view.Gravity; 25 | import android.view.LayoutInflater; 26 | import android.view.View; 27 | import android.view.ViewGroup; 28 | import android.widget.TextView; 29 | import android.widget.Toast; 30 | 31 | import com.scopely.adapper.adapters.GroupableAdapper; 32 | import com.scopely.adapper.example.R; 33 | import com.scopely.adapper.example.Utils; 34 | import com.scopely.adapper.example.objects.NameAndMood; 35 | import com.scopely.adapper.example.views.NameAndMoodView; 36 | import com.scopely.adapper.extras.GroupableSpanSizeLookup; 37 | import com.scopely.adapper.impls.GroupComparatorImpl; 38 | import com.scopely.adapper.impls.PopulatableProvider; 39 | import com.scopely.adapper.impls.ViewProviderImpl; 40 | import com.scopely.adapper.interfaces.FilterFunction; 41 | import com.scopely.adapper.interfaces.GroupComparator; 42 | import com.scopely.adapper.interfaces.ViewProvider; 43 | import com.scopely.adapper.interfaces.SelectionManager; 44 | 45 | import java.util.List; 46 | import java.util.Set; 47 | 48 | /** 49 | * A simple {@link Fragment} subclass. 50 | * 51 | */ 52 | public class GroupableGridFragment extends AbstractFragment { 53 | public static final int ITEMS_PER_ROW = 3; 54 | private int count = 21; 55 | private List list = Utils.generateNameAndMoodList(count); 56 | 57 | @Override 58 | protected GroupableAdapper createAdapter() { 59 | ViewProvider provider = new PopulatableProvider(R.layout.view_name_and_mood) { 60 | @Override 61 | public int getViewType(NameAndMood s) { 62 | return R.layout.view_name_and_mood; 63 | } 64 | 65 | }; 66 | 67 | GroupComparator comparator = new GroupComparatorImpl() { 68 | @Override 69 | public NameAndMood.Mood getGroup(NameAndMood nameAndMood) { 70 | return nameAndMood.mood; 71 | } 72 | 73 | @Override 74 | protected int groupCompare(NameAndMood.Mood lhs, NameAndMood.Mood rhs) { 75 | return lhs.compareTo(rhs); 76 | } 77 | 78 | @Override 79 | protected int itemCompare(NameAndMood lhs, NameAndMood rhs) { 80 | return lhs.name.compareTo(rhs.name); 81 | } 82 | }; 83 | 84 | ViewProvider groupProvider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 85 | @Override 86 | public int getViewType(NameAndMood.Mood mood) { 87 | return android.R.layout.simple_list_item_1; 88 | } 89 | 90 | @Override 91 | protected void bind(TextView view, NameAndMood.Mood mood, int position, @Nullable SelectionManager selectionManager) { 92 | view.setGravity(Gravity.CENTER_HORIZONTAL); 93 | view.setText(mood.toString()); 94 | } 95 | }; 96 | 97 | 98 | GroupableAdapper groupableAdapter = new GroupableAdapper<>(list, provider, comparator, groupProvider); 99 | groupableAdapter.setFilterFunction(new FilterFunction() { 100 | @Override 101 | public boolean filter(NameAndMood item, @Nullable CharSequence constraint) { 102 | return constraint != null && item.name.contains(constraint); 103 | } 104 | }); 105 | return groupableAdapter; 106 | } 107 | 108 | @Override 109 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 110 | View view = super.onCreateView(inflater, container, savedInstanceState); 111 | GroupableSpanSizeLookup spanSizeLookup = new GroupableSpanSizeLookup(adapter, ITEMS_PER_ROW); 112 | GridLayoutManager manager = new GridLayoutManager(inflater.getContext(), spanSizeLookup.getRequiredSpans()); 113 | manager.setSpanSizeLookup(spanSizeLookup); 114 | recyclerView.setLayoutManager(manager); 115 | return view; 116 | } 117 | 118 | @Override 119 | protected void reorder() { 120 | Toast.makeText(getActivity(), "Groupables are naturally sorted, reordering is not possible", Toast.LENGTH_LONG).show(); 121 | } 122 | 123 | @Override 124 | protected void add() { 125 | list.add(getFirstVisibleItemPosition(), new NameAndMood(NameAndMood.Mood.random(), "Just added #" + count)); 126 | count++; 127 | } 128 | 129 | @Override 130 | protected void remove() { 131 | if(list.isEmpty()){ 132 | Toast.makeText(getActivity(), "List is empty", Toast.LENGTH_SHORT).show(); 133 | return; 134 | } 135 | list.remove(getFirstVisibleItemPosition()); 136 | } 137 | 138 | private int getFirstVisibleItemPosition() { 139 | return ((GridLayoutManager)recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition(); 140 | } 141 | 142 | private int getLastVisibleItemPosition() { 143 | return ((GridLayoutManager)recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition(); 144 | } 145 | 146 | @Override 147 | protected Set[] getActionSets() { 148 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_ANIMATION}; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/GroupableListFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | 20 | import android.app.Fragment; 21 | import android.support.annotation.Nullable; 22 | import android.support.v7.widget.LinearLayoutManager; 23 | import android.widget.TextView; 24 | import android.widget.Toast; 25 | 26 | import com.scopely.adapper.adapters.GroupableAdapper; 27 | import com.scopely.adapper.example.R; 28 | import com.scopely.adapper.example.Utils; 29 | import com.scopely.adapper.example.objects.NameAndMood; 30 | import com.scopely.adapper.example.views.NameAndMoodView; 31 | import com.scopely.adapper.impls.GroupComparatorImpl; 32 | import com.scopely.adapper.impls.PopulatableProvider; 33 | import com.scopely.adapper.impls.ViewProviderImpl; 34 | import com.scopely.adapper.interfaces.FilterFunction; 35 | import com.scopely.adapper.interfaces.GroupComparator; 36 | import com.scopely.adapper.interfaces.ViewProvider; 37 | import com.scopely.adapper.interfaces.SelectionManager; 38 | 39 | import java.util.List; 40 | import java.util.Set; 41 | 42 | /** 43 | * A simple {@link Fragment} subclass. 44 | * 45 | */ 46 | public class GroupableListFragment extends AbstractFragment { 47 | 48 | private int count = 9; 49 | private List list = Utils.generateNameAndMoodList(count); 50 | 51 | @Override 52 | protected GroupableAdapper createAdapter() { 53 | ViewProvider provider = new PopulatableProvider(R.layout.view_name_and_mood) { 54 | @Override 55 | public int getViewType(NameAndMood s) { 56 | return R.layout.view_name_and_mood; 57 | } 58 | 59 | }; 60 | 61 | GroupComparator comparator = new GroupComparatorImpl() { 62 | @Override 63 | public NameAndMood.Mood getGroup(NameAndMood nameAndMood) { 64 | return nameAndMood.mood; 65 | } 66 | 67 | @Override 68 | protected int groupCompare(NameAndMood.Mood lhs, NameAndMood.Mood rhs) { 69 | return lhs.compareTo(rhs); 70 | } 71 | 72 | @Override 73 | protected int itemCompare(NameAndMood lhs, NameAndMood rhs) { 74 | return lhs.name.compareTo(rhs.name); 75 | } 76 | }; 77 | 78 | ViewProvider groupProvider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 79 | @Override 80 | public int getViewType(NameAndMood.Mood mood) { 81 | return android.R.layout.simple_list_item_1; 82 | } 83 | 84 | @Override 85 | protected void bind(TextView view, NameAndMood.Mood mood, int position, SelectionManager selectionManager) { 86 | view.setText(mood.toString()); 87 | } 88 | }; 89 | 90 | 91 | GroupableAdapper groupableAdapter = new GroupableAdapper<>(list, provider, comparator, groupProvider); 92 | groupableAdapter.setFilterFunction(new FilterFunction() { 93 | @Override 94 | public boolean filter(NameAndMood item, @Nullable CharSequence constraint) { 95 | return constraint != null && item.name.contains(constraint); 96 | } 97 | }); 98 | return groupableAdapter; 99 | } 100 | 101 | @Override 102 | protected void reorder() { 103 | Toast.makeText(getActivity(), "Groupables are naturally sorted, reordering is not possible", Toast.LENGTH_LONG).show(); 104 | } 105 | 106 | @Override 107 | protected void add() { 108 | list.add(getFirstVisibleItemPosition(), new NameAndMood(NameAndMood.Mood.random(), "Just added #" + count)); 109 | count++; 110 | } 111 | 112 | @Override 113 | protected void remove() { 114 | if(list.isEmpty()){ 115 | Toast.makeText(getActivity(), "List is empty", Toast.LENGTH_SHORT).show(); 116 | return; 117 | } 118 | list.remove(getFirstVisibleItemPosition()); 119 | } 120 | 121 | private int getFirstVisibleItemPosition() { 122 | return Math.max(0, ((LinearLayoutManager)recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition()); 123 | } 124 | 125 | private int getLastVisibleItemPosition() { 126 | return Math.max(((LinearLayoutManager)recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition(), 0); 127 | } 128 | 129 | @Override 130 | protected Set[] getActionSets() { 131 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_ANIMATION}; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/HeterogeneousGroupableGridFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | 20 | import android.app.Fragment; 21 | import android.os.Bundle; 22 | import android.support.annotation.Nullable; 23 | import android.support.v7.widget.GridLayoutManager; 24 | import android.view.Gravity; 25 | import android.view.LayoutInflater; 26 | import android.view.View; 27 | import android.view.ViewGroup; 28 | import android.widget.ImageView; 29 | import android.widget.LinearLayout; 30 | import android.widget.TextView; 31 | import android.widget.Toast; 32 | 33 | import com.scopely.adapper.impls.TypedViewHolder; 34 | import com.scopely.adapper.adapters.GroupableAdapper; 35 | import com.scopely.adapper.example.R; 36 | import com.scopely.adapper.example.Utils; 37 | import com.scopely.adapper.example.objects.NameAndMood; 38 | import com.scopely.adapper.example.views.NameAndMoodView; 39 | import com.scopely.adapper.extras.InvertedSpanSizeLookup; 40 | import com.scopely.adapper.impls.GroupComparatorImpl; 41 | import com.scopely.adapper.impls.PopulatableProvider; 42 | import com.scopely.adapper.impls.ViewProviderImpl; 43 | import com.scopely.adapper.interfaces.FilterFunction; 44 | import com.scopely.adapper.interfaces.GroupComparator; 45 | import com.scopely.adapper.interfaces.ViewProvider; 46 | import com.scopely.adapper.interfaces.SelectionManager; 47 | 48 | import java.util.List; 49 | import java.util.Set; 50 | 51 | /** 52 | * A simple {@link Fragment} subclass. 53 | * 54 | */ 55 | public class HeterogeneousGroupableGridFragment extends AbstractFragment> { 56 | private List list = Utils.generateNameAndMoodList(12); 57 | private GridLayoutManager manager; 58 | 59 | @Override 60 | protected GroupableAdapper createAdapter() { 61 | ViewProvider provider = new PopulatableProvider(R.layout.view_name_and_mood) { 62 | @Override 63 | public int getViewType(NameAndMood s) { 64 | return R.layout.view_name_and_mood; 65 | } 66 | 67 | @Override 68 | public TypedViewHolder create(LayoutInflater inflater, ViewGroup parent, int viewType) { 69 | TypedViewHolder holder = super.create(inflater, parent, viewType); 70 | holder.getView().textView.setVisibility(View.GONE); 71 | ImageView imageView = holder.getView().imageView; 72 | imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 73 | imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 74 | imageView.setAdjustViewBounds(true); 75 | return holder; 76 | } 77 | }; 78 | 79 | GroupComparator comparator = new GroupComparatorImpl() { 80 | @Override 81 | public NameAndMood.Mood getGroup(NameAndMood nameAndMood) { 82 | return nameAndMood.mood; 83 | } 84 | 85 | @Override 86 | protected int groupCompare(NameAndMood.Mood lhs, NameAndMood.Mood rhs) { 87 | return lhs.compareTo(rhs); 88 | } 89 | 90 | @Override 91 | protected int itemCompare(NameAndMood lhs, NameAndMood rhs) { 92 | return lhs.name.compareTo(rhs.name); 93 | } 94 | }; 95 | 96 | ViewProvider groupProvider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 97 | @Override 98 | public int getViewType(NameAndMood.Mood mood) { 99 | return android.R.layout.simple_list_item_1; 100 | } 101 | 102 | @Override 103 | protected void bind(TextView view, NameAndMood.Mood mood, int position, SelectionManager selectionManager) { 104 | view.setGravity(Gravity.CENTER_HORIZONTAL); 105 | view.setText(mood.toString()); 106 | } 107 | }; 108 | 109 | FilterFunction filterFunction = new FilterFunction() { 110 | @Override 111 | public boolean filter(NameAndMood item, @Nullable CharSequence constraint) { 112 | return constraint != null && item.name.contains(constraint); 113 | } 114 | }; 115 | 116 | GroupableAdapper groupableAdapter = new GroupableAdapper<>(list, provider, comparator, groupProvider); 117 | groupableAdapter.setFilterFunction(filterFunction); 118 | return groupableAdapter; 119 | } 120 | 121 | @Override 122 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 123 | View view = super.onCreateView(inflater, container, savedInstanceState); 124 | 125 | InvertedSpanSizeLookup spanSizeLookup = new InvertedSpanSizeLookup(1, 5, 10) { 126 | @Override 127 | public int getItemsPerRow(int position) { 128 | if (adapter.isGroup(position)) { 129 | return 1; 130 | } else { 131 | NameAndMood nameAndMood = adapter.getModel(position); 132 | if (nameAndMood.mood == NameAndMood.Mood.HAPPY) { 133 | return 5; 134 | } else { 135 | return 10; 136 | } 137 | } 138 | } 139 | }; 140 | manager = new GridLayoutManager(inflater.getContext(), spanSizeLookup.getRequiredSpans()); 141 | manager.setSpanSizeLookup(spanSizeLookup); 142 | recyclerView.setLayoutManager(manager); 143 | return view; 144 | } 145 | 146 | @Override 147 | protected void reorder() { 148 | Toast.makeText(getActivity(), "Groupables are naturally sorted, reordering is not possible", Toast.LENGTH_LONG).show(); 149 | } 150 | 151 | @Override 152 | protected void add() { 153 | list.add(getFirstVisibleItemPosition(), new NameAndMood(NameAndMood.Mood.random(), "Just added")); 154 | } 155 | 156 | @Override 157 | protected void remove() { 158 | if(list.isEmpty()){ 159 | Toast.makeText(getActivity(), "List is empty", Toast.LENGTH_SHORT).show(); 160 | return; 161 | } 162 | list.remove(getFirstVisibleItemPosition()); 163 | } 164 | 165 | private int getFirstVisibleItemPosition() { 166 | return manager.findFirstCompletelyVisibleItemPosition(); 167 | } 168 | 169 | private int getLastVisibleItemPosition() { 170 | return manager.findLastCompletelyVisibleItemPosition(); 171 | } 172 | 173 | @Override 174 | protected Set[] getActionSets() { 175 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_ANIMATION}; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/RecursiveFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | import android.support.annotation.Nullable; 20 | import android.view.LayoutInflater; 21 | import android.widget.TextView; 22 | 23 | import com.scopely.adapper.adapters.BaseAdapper; 24 | import com.scopely.adapper.adapters.ListAdapper; 25 | import com.scopely.adapper.adapters.RecursiveAdapper; 26 | import com.scopely.adapper.adapters.SingleViewAdapper; 27 | import com.scopely.adapper.example.R; 28 | import com.scopely.adapper.example.Utils; 29 | import com.scopely.adapper.example.objects.NameAndMood; 30 | import com.scopely.adapper.example.views.NameAndMoodView; 31 | import com.scopely.adapper.impls.PopulatableProvider; 32 | import com.scopely.adapper.impls.ViewProviderImpl; 33 | import com.scopely.adapper.interfaces.FilterFunction; 34 | import com.scopely.adapper.interfaces.ViewProvider; 35 | import com.scopely.adapper.interfaces.SelectionManager; 36 | 37 | import java.util.List; 38 | import java.util.Set; 39 | 40 | public class RecursiveFragment extends AbstractFragment { 41 | 42 | private List list = Utils.generateStringList(5); 43 | private List list2 = Utils.generateNameAndMoodList(5); 44 | 45 | @Override 46 | protected BaseAdapper createAdapter() { 47 | ViewProvider provider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 48 | @Override 49 | public int getViewType(String s) { 50 | return android.R.layout.simple_list_item_1; 51 | } 52 | 53 | @Override 54 | protected void bind(TextView view, String s, int position, SelectionManager selectionManager) { 55 | view.setText(s); 56 | } 57 | }; 58 | 59 | ListAdapper adapter1 = new ListAdapper<>(list, provider); 60 | adapter1.setFilterFunction(new FilterFunction() { 61 | @Override 62 | public boolean filter(String item, @Nullable CharSequence constraint) { 63 | return constraint == null || item.contains(constraint); 64 | } 65 | }); 66 | 67 | ViewProvider provider2 = new PopulatableProvider(R.layout.view_name_and_mood) { 68 | @Override 69 | public int getViewType(NameAndMood s) { 70 | return R.layout.view_name_and_mood; 71 | } 72 | 73 | }; 74 | 75 | ListAdapper adapter2 = new ListAdapper<>(list2, provider2); 76 | adapter2.setFilterFunction(new FilterFunction() { 77 | @Override 78 | public boolean filter(NameAndMood item, @Nullable CharSequence constraint) { 79 | return constraint == null || item.name.contains(constraint); 80 | } 81 | }); 82 | 83 | SingleViewAdapper adapter3 = new SingleViewAdapper(LayoutInflater.from(getActivity()).inflate(R.layout.view_single, null)); 84 | 85 | return new RecursiveAdapper<>(adapter1, adapter3, adapter2); 86 | } 87 | 88 | @Override 89 | protected Set[] getActionSets() { 90 | return new Set[]{MENU_ITEMS_SEARCH}; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/SelectCursorFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | import android.database.Cursor; 20 | import android.database.sqlite.SQLiteDatabase; 21 | import android.os.Bundle; 22 | import android.support.annotation.Nullable; 23 | import android.view.View; 24 | import android.widget.FilterQueryProvider; 25 | 26 | import com.readystatesoftware.sqliteasset.SQLiteAssetHelper; 27 | import com.scopely.adapper.adapters.CursorAdapper; 28 | import com.scopely.adapper.example.R; 29 | import com.scopely.adapper.example.objects.NameAndMood; 30 | import com.scopely.adapper.example.views.NameAndMoodView; 31 | import com.scopely.adapper.impls.PopulatableProvider; 32 | import com.scopely.adapper.interfaces.MiniOrm; 33 | import com.scopely.adapper.interfaces.SelectionManager; 34 | import com.scopely.adapper.interfaces.ViewProvider; 35 | import com.scopely.adapper.selection.MultiSelectManager; 36 | 37 | import java.util.Set; 38 | 39 | public class SelectCursorFragment extends AbstractFragment { 40 | 41 | public static final String TABLE_NAME = "name"; 42 | public static final String COLUMN_NAME_ID = "_id"; 43 | private SQLiteDatabase db; 44 | 45 | @Override 46 | public void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | db = new SQLiteAssetHelper(getActivity(), "example.db", null, 1) {} 49 | .getReadableDatabase(); 50 | } 51 | 52 | @Override 53 | public void onDestroy() { 54 | db.close(); 55 | super.onDestroy(); 56 | } 57 | 58 | @Override 59 | protected CursorAdapper createAdapter() { 60 | ViewProvider provider = new PopulatableProvider(R.layout.view_name_and_mood) { 61 | @Override 62 | public int getViewType(NameAndMood s) { 63 | return R.layout.view_name_and_mood; 64 | } 65 | 66 | @Override 67 | protected void bind(NameAndMoodView view, NameAndMood nameAndMood, final int position, @Nullable final SelectionManager selectionManager) { 68 | super.bind(view, nameAndMood, position, selectionManager); 69 | if(selectionManager != null) { 70 | final boolean itemSelected = selectionManager.isItemSelected(position); 71 | view.setChecked(itemSelected); 72 | view.setOnClickListener(new View.OnClickListener() { 73 | @Override 74 | public void onClick(View v) { 75 | selectionManager.selectItem(position, !itemSelected); 76 | } 77 | }); 78 | } 79 | 80 | } 81 | }; 82 | 83 | final Cursor cursor = query(db, null); 84 | 85 | MiniOrm miniOrm = new MiniOrm() { 86 | @Override 87 | public NameAndMood getObject(Cursor c) { 88 | NameAndMood.Mood mood = NameAndMood.Mood.valueOf(c.getString(c.getColumnIndex("mood"))); 89 | String name = c.getString(c.getColumnIndex("name")); 90 | return new NameAndMood(mood, name); 91 | } 92 | }; 93 | CursorAdapper.CursorIdentifier identifier = new CursorAdapper.ColumnIdentifier(COLUMN_NAME_ID); 94 | CursorAdapper.CursorLookup lookup = new CursorAdapper.ColumnLookup<>(db, TABLE_NAME, COLUMN_NAME_ID); 95 | final CursorAdapper adapter = new CursorAdapper<>(cursor, identifier, lookup, miniOrm, provider); 96 | adapter.setFilterQueryProvider(new FilterQueryProvider() { 97 | @Override 98 | public Cursor runQuery(CharSequence constraint) { 99 | return query(db, constraint); 100 | } 101 | }); 102 | adapter.setSelectionManager(new MultiSelectManager<>(adapter)); 103 | return adapter; 104 | } 105 | 106 | private Cursor query(SQLiteDatabase db, @Nullable CharSequence constraint) { 107 | return db.query(TABLE_NAME, null, constraint != null && constraint.length() > 0 ? "name LIKE '%"+constraint.toString()+"%'" : null, null, null, null, null); 108 | } 109 | 110 | @Override 111 | protected Set[] getActionSets() { 112 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_SELECT}; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/SelectGroupableListFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | 20 | import android.app.Fragment; 21 | import android.support.annotation.Nullable; 22 | import android.view.View; 23 | import android.widget.TextView; 24 | 25 | import com.scopely.adapper.adapters.GroupableAdapper; 26 | import com.scopely.adapper.example.R; 27 | import com.scopely.adapper.example.Utils; 28 | import com.scopely.adapper.example.objects.NameAndMood; 29 | import com.scopely.adapper.example.views.NameAndMoodView; 30 | import com.scopely.adapper.impls.GroupComparatorImpl; 31 | import com.scopely.adapper.impls.PopulatableProvider; 32 | import com.scopely.adapper.impls.ViewProviderImpl; 33 | import com.scopely.adapper.interfaces.FilterFunction; 34 | import com.scopely.adapper.interfaces.GroupComparator; 35 | import com.scopely.adapper.interfaces.ViewProvider; 36 | import com.scopely.adapper.interfaces.SelectionManager; 37 | import com.scopely.adapper.selection.MultiSelectManager; 38 | 39 | import java.util.List; 40 | import java.util.Set; 41 | 42 | /** 43 | * A simple {@link Fragment} subclass. 44 | * 45 | */ 46 | public class SelectGroupableListFragment extends AbstractFragment { 47 | 48 | private int count = 9; 49 | private List list = Utils.generateNameAndMoodList(count); 50 | 51 | @Override 52 | protected GroupableAdapper createAdapter() { 53 | ViewProvider provider = new PopulatableProvider(R.layout.view_name_and_mood) { 54 | @Override 55 | public int getViewType(NameAndMood s) { 56 | return R.layout.view_name_and_mood; 57 | } 58 | 59 | @Override 60 | protected void bind(NameAndMoodView view, NameAndMood nameAndMood, final int position, @Nullable final SelectionManager selectionManager) { 61 | super.bind(view, nameAndMood, position, selectionManager); 62 | if (selectionManager != null) { 63 | view.setChecked(selectionManager.isItemSelected(position)); 64 | view.setOnClickListener(new View.OnClickListener() { 65 | @Override 66 | public void onClick(View v) { 67 | selectionManager.selectItem(position, !selectionManager.isItemSelected(position)); 68 | } 69 | }); 70 | } 71 | } 72 | }; 73 | 74 | GroupComparator comparator = new GroupComparatorImpl() { 75 | @Override 76 | public NameAndMood.Mood getGroup(NameAndMood nameAndMood) { 77 | return nameAndMood.mood; 78 | } 79 | 80 | @Override 81 | protected int groupCompare(NameAndMood.Mood lhs, NameAndMood.Mood rhs) { 82 | return lhs.compareTo(rhs); 83 | } 84 | 85 | @Override 86 | protected int itemCompare(NameAndMood lhs, NameAndMood rhs) { 87 | return lhs.name.compareTo(rhs.name); 88 | } 89 | }; 90 | 91 | ViewProvider groupProvider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 92 | @Override 93 | public int getViewType(NameAndMood.Mood mood) { 94 | return android.R.layout.simple_list_item_1; 95 | } 96 | 97 | @Override 98 | protected void bind(TextView view, NameAndMood.Mood mood, int position, SelectionManager selectionManager) { 99 | view.setText(mood.toString()); 100 | } 101 | }; 102 | 103 | 104 | GroupableAdapper groupableAdapter = new GroupableAdapper<>(list, provider, comparator, groupProvider); 105 | groupableAdapter.setFilterFunction(new FilterFunction() { 106 | @Override 107 | public boolean filter(NameAndMood item, @Nullable CharSequence constraint) { 108 | return constraint != null && item.name.contains(constraint); 109 | } 110 | }); 111 | groupableAdapter.setSelectionManager(new MultiSelectManager<>(groupableAdapter)); 112 | return groupableAdapter; 113 | } 114 | 115 | @Override 116 | protected Set[] getActionSets() { 117 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_SELECT}; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/SelectPopulateableListFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | import android.support.annotation.Nullable; 20 | import android.view.View; 21 | 22 | import com.scopely.adapper.adapters.ListAdapper; 23 | import com.scopely.adapper.example.R; 24 | import com.scopely.adapper.example.Utils; 25 | import com.scopely.adapper.example.objects.NameAndMood; 26 | import com.scopely.adapper.example.views.NameAndMoodView; 27 | import com.scopely.adapper.impls.PopulatableProvider; 28 | import com.scopely.adapper.interfaces.FilterFunction; 29 | import com.scopely.adapper.interfaces.ViewProvider; 30 | import com.scopely.adapper.interfaces.SelectionManager; 31 | import com.scopely.adapper.selection.RadioSelectManager; 32 | 33 | import java.util.List; 34 | import java.util.Set; 35 | 36 | public class SelectPopulateableListFragment extends AbstractFragment { 37 | private int count = 100; 38 | private List list = Utils.generateNameAndMoodList(count); 39 | 40 | protected ListAdapper createAdapter() { 41 | ViewProvider provider = new PopulatableProvider(R.layout.view_name_and_mood) { 42 | @Override 43 | public int getViewType(NameAndMood s) { 44 | return R.layout.view_name_and_mood; 45 | } 46 | 47 | @Override 48 | protected void bind(NameAndMoodView view, NameAndMood nameAndMood, final int position, @Nullable final SelectionManager selectionManager) { 49 | super.bind(view, nameAndMood, position, selectionManager); 50 | if (selectionManager != null) { 51 | view.setChecked(selectionManager.isItemSelected(position)); 52 | view.setOnClickListener(new View.OnClickListener() { 53 | @Override 54 | public void onClick(View v) { 55 | selectionManager.selectItem(position, !selectionManager.isItemSelected(position)); 56 | } 57 | }); 58 | } else { 59 | view.setChecked(false); 60 | view.setOnClickListener(null); 61 | } 62 | } 63 | }; 64 | 65 | ListAdapper adapper = new ListAdapper<>(list, provider).setFilterFunction(new FilterFunction() { 66 | @Override 67 | public boolean filter(NameAndMood item, @Nullable CharSequence constraint) { 68 | return constraint == null || item.name.contains(constraint); 69 | } 70 | }); 71 | adapper.setSelectionManager(new RadioSelectManager<>(adapper)); 72 | return adapper; 73 | } 74 | 75 | @Override 76 | protected Set[] getActionSets() { 77 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_SELECT}; 78 | } 79 | } -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/SelectRecursiveFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | import android.graphics.Rect; 20 | import android.support.annotation.Nullable; 21 | import android.text.method.TransformationMethod; 22 | import android.view.LayoutInflater; 23 | import android.view.View; 24 | import android.widget.TextView; 25 | import android.widget.Toast; 26 | 27 | import com.scopely.adapper.adapters.BaseAdapper; 28 | import com.scopely.adapper.adapters.ListAdapper; 29 | import com.scopely.adapper.adapters.RecursiveAdapper; 30 | import com.scopely.adapper.adapters.SingleViewAdapper; 31 | import com.scopely.adapper.example.R; 32 | import com.scopely.adapper.example.Utils; 33 | import com.scopely.adapper.example.objects.NameAndMood; 34 | import com.scopely.adapper.example.views.NameAndMoodView; 35 | import com.scopely.adapper.impls.PopulatableProvider; 36 | import com.scopely.adapper.impls.ViewProviderImpl; 37 | import com.scopely.adapper.interfaces.FilterFunction; 38 | import com.scopely.adapper.interfaces.ViewProvider; 39 | import com.scopely.adapper.interfaces.SelectionManager; 40 | import com.scopely.adapper.selection.MultiSelectManager; 41 | 42 | import java.util.List; 43 | import java.util.Set; 44 | 45 | public class SelectRecursiveFragment extends AbstractFragment { 46 | 47 | private List list = Utils.generateStringList(5); 48 | private List list2 = Utils.generateNameAndMoodList(5); 49 | 50 | @Override 51 | protected BaseAdapper createAdapter() { 52 | ViewProvider provider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 53 | @Override 54 | public int getViewType(String s) { 55 | return android.R.layout.simple_list_item_1; 56 | } 57 | 58 | @Override 59 | protected void bind(TextView view, String s, final int position, final SelectionManager selectionManager) { 60 | view.setText(s); 61 | if (selectionManager != null) { 62 | view.setTransformationMethod(new TransformationMethod() { 63 | @Override 64 | public CharSequence getTransformation(CharSequence source, View view) { 65 | return selectionManager.isItemSelected(position) ? source + " (selected)" : source; 66 | } 67 | 68 | @Override 69 | public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, Rect previouslyFocusedRect) { 70 | 71 | } 72 | }); 73 | view.setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View v) { 76 | selectionManager.selectItem(position, !selectionManager.isItemSelected(position)); 77 | } 78 | }); 79 | } 80 | } 81 | }; 82 | 83 | ListAdapper adapter1 = new ListAdapper<>(list, provider); 84 | adapter1.setFilterFunction(new FilterFunction() { 85 | @Override 86 | public boolean filter(String item, @Nullable CharSequence constraint) { 87 | return constraint == null || item.contains(constraint); 88 | } 89 | }); 90 | 91 | ViewProvider provider2 = new PopulatableProvider(R.layout.view_name_and_mood) { 92 | @Override 93 | public int getViewType(NameAndMood s) { 94 | return R.layout.view_name_and_mood; 95 | } 96 | 97 | @Override 98 | protected void bind(NameAndMoodView view, NameAndMood nameAndMood, final int position, @Nullable final SelectionManager selectionManager) { 99 | super.bind(view, nameAndMood, position, selectionManager); 100 | if (selectionManager != null) { 101 | view.setChecked(selectionManager.isItemSelected(position)); 102 | view.setOnClickListener(new View.OnClickListener() { 103 | @Override 104 | public void onClick(View v) { 105 | selectionManager.selectItem(position, !selectionManager.isItemSelected(position)); 106 | } 107 | }); 108 | } 109 | } 110 | }; 111 | 112 | ListAdapper adapter2 = new ListAdapper<>(list2, provider2); 113 | adapter2.setFilterFunction(new FilterFunction() { 114 | @Override 115 | public boolean filter(NameAndMood item, @Nullable CharSequence constraint) { 116 | return constraint == null || item.name.contains(constraint); 117 | } 118 | }); 119 | 120 | SingleViewAdapper adapter3 = new SingleViewAdapper(LayoutInflater.from(getActivity()).inflate(R.layout.view_single, null)); 121 | 122 | RecursiveAdapper adapper = new RecursiveAdapper(adapter1, adapter3, adapter2); 123 | adapper.setSelectionManager(new MultiSelectManager(adapper, 3){ 124 | @Override 125 | protected void onMaximumExceeded(int maximumSelectable) { 126 | Toast.makeText(getActivity(), "You may only select 3 concurrent items", Toast.LENGTH_LONG).show(); 127 | } 128 | }); 129 | return adapper; 130 | } 131 | 132 | @Override 133 | protected Set[] getActionSets() { 134 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_SELECT}; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/fragments/SimpleListFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.fragments; 18 | 19 | 20 | import android.support.annotation.Nullable; 21 | import android.support.v7.widget.LinearLayoutManager; 22 | import android.widget.TextView; 23 | import android.widget.Toast; 24 | 25 | import com.scopely.adapper.impls.TypedViewHolder; 26 | import com.scopely.adapper.adapters.BaseAdapper; 27 | import com.scopely.adapper.adapters.ListAdapper; 28 | import com.scopely.adapper.example.Utils; 29 | import com.scopely.adapper.impls.ViewProviderImpl; 30 | import com.scopely.adapper.interfaces.FilterFunction; 31 | import com.scopely.adapper.interfaces.ViewProvider; 32 | import com.scopely.adapper.interfaces.SelectionManager; 33 | 34 | import java.util.List; 35 | import java.util.Set; 36 | 37 | public class SimpleListFragment extends AbstractFragment { 38 | 39 | private int count = 100; 40 | private List list = Utils.generateStringList(count); 41 | 42 | protected BaseAdapper> createAdapter() { 43 | ViewProvider provider = new ViewProviderImpl(android.R.layout.simple_list_item_1) { 44 | @Override 45 | public int getViewType(String s) { 46 | return android.R.layout.simple_list_item_1; 47 | } 48 | 49 | @Override 50 | protected void bind(TextView view, String s, int position, SelectionManager selectionManager) { 51 | view.setText(s); 52 | } 53 | }; 54 | 55 | ListAdapper adapter = new ListAdapper<>(list, provider); 56 | adapter.setFilterFunction(new FilterFunction() { 57 | @Override 58 | public boolean filter(String item, @Nullable CharSequence constraint) { 59 | return constraint == null || item.contains(constraint); 60 | } 61 | }); 62 | return adapter; 63 | } 64 | 65 | @Override 66 | protected void reorder() { 67 | if(list.isEmpty()){ 68 | Toast.makeText(getActivity(), "List is empty", Toast.LENGTH_SHORT).show(); 69 | return; 70 | } 71 | list.add(getLastVisibleItemPosition(), list.remove(getFirstVisibleItemPosition())); 72 | } 73 | 74 | private int getFirstVisibleItemPosition() { 75 | return ((LinearLayoutManager)recyclerView.getLayoutManager()).findFirstCompletelyVisibleItemPosition(); 76 | } 77 | 78 | private int getLastVisibleItemPosition() { 79 | return ((LinearLayoutManager)recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition(); 80 | } 81 | 82 | @Override 83 | protected void add() { 84 | list.add(getFirstVisibleItemPosition(), "Just added #" + count); 85 | count++; 86 | } 87 | 88 | @Override 89 | protected void remove() { 90 | if(list.isEmpty()){ 91 | Toast.makeText(getActivity(), "List is empty", Toast.LENGTH_SHORT).show(); 92 | return; 93 | } 94 | list.remove(getFirstVisibleItemPosition()); 95 | } 96 | 97 | @Override 98 | protected Set[] getActionSets() { 99 | return new Set[]{MENU_ITEMS_SEARCH, MENU_ITEMS_ANIMATION}; 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/objects/NameAndMood.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.objects; 18 | 19 | import android.support.annotation.DrawableRes; 20 | 21 | import com.scopely.adapper.example.R; 22 | 23 | import java.util.Random; 24 | 25 | public class NameAndMood { 26 | public final Mood mood; 27 | public final String name; 28 | 29 | public NameAndMood(Mood mood, String name) { 30 | this.mood = mood; 31 | this.name = name; 32 | } 33 | 34 | public enum Mood { 35 | HAPPY(R.drawable.happy), 36 | NEUTRAL(R.drawable.neutral), 37 | SAD(R.drawable.sad) 38 | ; 39 | 40 | public int imageId; 41 | 42 | Mood(@DrawableRes int resId) { 43 | this.imageId = resId; 44 | } 45 | 46 | public static Mood random() { 47 | return Mood.values()[new Random().nextInt(3)]; 48 | } 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return mood.toString() + " " + name; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/example/views/NameAndMoodView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.example.views; 18 | 19 | import android.content.Context; 20 | import android.graphics.Color; 21 | import android.util.AttributeSet; 22 | import android.widget.Checkable; 23 | import android.widget.ImageView; 24 | import android.widget.LinearLayout; 25 | import android.widget.TextView; 26 | 27 | import com.scopely.adapper.example.R; 28 | import com.scopely.adapper.example.objects.NameAndMood; 29 | import com.scopely.adapper.interfaces.Populatable; 30 | 31 | 32 | public class NameAndMoodView extends LinearLayout implements Populatable, Checkable { 33 | 34 | public static final int COLOR = Color.parseColor("#8A57AB"); 35 | public TextView textView; 36 | public ImageView imageView; 37 | private ImageView checkMark; 38 | private boolean checked; 39 | private boolean gridMode; 40 | 41 | public NameAndMoodView(Context context) { 42 | super(context); 43 | } 44 | 45 | public NameAndMoodView(Context context, AttributeSet attrs) { 46 | super(context, attrs); 47 | } 48 | 49 | public NameAndMoodView(Context context, AttributeSet attrs, int defStyle) { 50 | super(context, attrs, defStyle); 51 | } 52 | 53 | @Override 54 | protected void onFinishInflate() { 55 | super.onFinishInflate(); 56 | this.textView = (TextView) findViewById(R.id.textView); 57 | this.imageView = (ImageView) findViewById(R.id.imageView); 58 | this.checkMark = (ImageView) findViewById(R.id.checkMark); 59 | } 60 | 61 | public void setGridMode(boolean gridMode) { 62 | this.gridMode = gridMode; 63 | setChecked(checked); 64 | if(gridMode) { 65 | textView.setVisibility(GONE); 66 | } else { 67 | textView.setVisibility(VISIBLE); 68 | } 69 | } 70 | 71 | @Override 72 | public void setModel(NameAndMood model) { 73 | textView.setText(model.name); 74 | imageView.setImageResource(model.mood.imageId); 75 | } 76 | 77 | @Override 78 | public void setChecked(boolean checked) { 79 | this.checked = checked; 80 | if(!gridMode){ 81 | checkMark.setVisibility(checked ? VISIBLE : INVISIBLE); 82 | setBackgroundColor(0); 83 | } else { 84 | checkMark.setVisibility(GONE); 85 | setBackgroundColor(checked ? COLOR : 0); 86 | } 87 | } 88 | 89 | @Override 90 | public boolean isChecked() { 91 | return checked; 92 | } 93 | 94 | @Override 95 | public void toggle() { 96 | setChecked(!checked); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/impls/PopulatableProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.impls; 18 | 19 | import android.support.annotation.Nullable; 20 | import android.view.View; 21 | 22 | import com.scopely.adapper.interfaces.Populatable; 23 | import com.scopely.adapper.interfaces.SelectionManager; 24 | 25 | public abstract class PopulatableProvider> 26 | extends ViewProviderImpl { 27 | public PopulatableProvider(int... layouts) { 28 | super(layouts); 29 | } 30 | 31 | @Override 32 | protected void bind(GenericView view, Item item, int position, @Nullable SelectionManager selectionManager) { 33 | view.setModel(item); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /adapper-example/src/main/java/com/scopely/adapper/interfaces/Populatable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | /** 20 | * An interface to be implemented by custom views to indicate that they can be populated by an item of type T 21 | * 22 | * @param the class of the item provided for view population 23 | */ 24 | public interface Populatable { 25 | public void setModel(T model); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /adapper-example/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /adapper-example/src/main/res/drawable-xhdpi/happy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/res/drawable-xhdpi/happy.png -------------------------------------------------------------------------------- /adapper-example/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /adapper-example/src/main/res/drawable-xhdpi/neutral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/res/drawable-xhdpi/neutral.png -------------------------------------------------------------------------------- /adapper-example/src/main/res/drawable-xhdpi/sad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/res/drawable-xhdpi/sad.png -------------------------------------------------------------------------------- /adapper-example/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/adapper-example/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /adapper-example/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 26 | 27 | 33 | 34 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/layout/fragment_list_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 27 | 31 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/layout/fragment_simple_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 28 | 29 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/layout/view_name_and_mood.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 25 | 26 | 30 | 35 | 42 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/layout/view_single.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 22 | 23 | 28 | 29 | 34 | 35 | 40 | 41 | 42 | 47 | 48 | 53 | 54 | 59 | 60 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/layout/view_single_buck_wild.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 23 | 24 | 30 | 31 | 37 | 38 | 43 | 44 | 45 | 46 | 52 | 53 | 58 | 59 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/menu/activity_base.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 23 | 27 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/menu/fragment_animated_adapter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 25 | 30 | 35 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/menu/fragment_filterable.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 27 | 28 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/menu/fragment_selector.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 26 | 27 | 32 | 33 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 21 | 64dp 22 | 23 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 16dp 20 | 16dp 21 | 22 | 23 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | Adapper 21 | Simple List 22 | Populateable List 23 | Groupable List 24 | Settings 25 | Hello blank fragment 26 | Recursive List 27 | Animated Simple List 28 | Animated Groupable List 29 | Animated Recursive List 30 | Cursor 31 | Item Aware Click Listeners 32 | search 33 | filter 34 | Adapters 35 | Selectors 36 | Animations 37 | List Views 38 | Click Listeners 39 | Groupable Grid 40 | Heterogeneous 41 | Cursor 42 | Radio Selection 43 | Multi-Selection 44 | Capped Selection 45 | Buck Wild 46 | Dead Simple 47 | add 48 | remove 49 | swap 50 | 51 | 52 | -------------------------------------------------------------------------------- /adapper-example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 23 | 28 | 29 | -------------------------------------------------------------------------------- /adapper/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | buildscript { 18 | repositories { 19 | jcenter() 20 | maven { 21 | url 'https://oss.sonatype.org/content/repositories/snapshots/' 22 | } 23 | } 24 | 25 | dependencies { 26 | classpath 'com.android.tools.build:gradle:3.0.0-alpha4' 27 | } 28 | } 29 | 30 | apply plugin: 'com.android.library' 31 | apply plugin: 'maven' 32 | apply plugin: 'de.mobilej.unmock' 33 | 34 | version = VERSION_NAME 35 | group = GROUP 36 | 37 | android { 38 | compileSdkVersion 25 39 | buildToolsVersion '25.0.2' 40 | 41 | defaultConfig { 42 | minSdkVersion 14 43 | targetSdkVersion 25 44 | } 45 | 46 | dexOptions { 47 | javaMaxHeapSize "4g" 48 | } 49 | 50 | lintOptions { 51 | abortOnError false 52 | } 53 | 54 | packagingOptions { 55 | exclude 'LICENSE.txt' 56 | } 57 | } 58 | 59 | dependencies { 60 | compile 'com.android.support:recyclerview-v7:25.3.1' 61 | compile 'com.android.support:support-annotations:25.3.1' 62 | compile 'junit:junit:4.12' 63 | } 64 | 65 | apply from: 'maven_push.gradle' 66 | -------------------------------------------------------------------------------- /adapper/gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Scopely, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | VERSION_NAME=1.0.0 18 | VERSION_CODE=1 19 | GROUP=com.scopely 20 | 21 | POM_DESCRIPTION=Dapper adapters for Android 22 | POM_URL=https://github.com/scopely/adapper 23 | POM_SCM_URL=https://github.com/scopely/adapper 24 | POM_SCM_CONNECTION=scm:git@github.com:scopely/adapper.git 25 | POM_SCM_DEV_CONNECTION=scm:git@github.com:scopely/adapper.git 26 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 27 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 28 | POM_LICENCE_DIST=repo 29 | POM_DEVELOPER_ID=PeterAttardo 30 | POM_DEVELOPER_NAME=Peter Attardo 31 | POM_NAME=Adapper 32 | POM_ARTIFACT_ID=adapper 33 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /adapper/maven_push.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'maven' 18 | apply plugin: 'signing' 19 | 20 | def isReleaseBuild() { 21 | return version.contains("SNAPSHOT") == false 22 | } 23 | 24 | def sonatypeRepositoryUrl 25 | if (isReleaseBuild()) { 26 | println 'RELEASE BUILD' 27 | sonatypeRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 28 | } else { 29 | println 'DEBUG BUILD' 30 | sonatypeRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/" 31 | } 32 | 33 | afterEvaluate { project -> 34 | uploadArchives { 35 | repositories { 36 | mavenDeployer { 37 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 38 | 39 | pom.artifactId = POM_ARTIFACT_ID 40 | 41 | repository(url: sonatypeRepositoryUrl) { 42 | authentication(userName: nexusUsername, password: nexusPassword) 43 | } 44 | 45 | pom.project { 46 | artifactId POM_ARTIFACT_ID 47 | name POM_NAME 48 | packaging POM_PACKAGING 49 | description POM_DESCRIPTION 50 | url POM_URL 51 | 52 | scm { 53 | url POM_SCM_URL 54 | connection POM_SCM_CONNECTION 55 | developerConnection POM_SCM_DEV_CONNECTION 56 | } 57 | 58 | licenses { 59 | license { 60 | name POM_LICENCE_NAME 61 | url POM_LICENCE_URL 62 | distribution POM_LICENCE_DIST 63 | } 64 | } 65 | 66 | developers { 67 | developer { 68 | id POM_DEVELOPER_ID 69 | name POM_DEVELOPER_NAME 70 | } 71 | } 72 | } 73 | } 74 | } 75 | } 76 | 77 | signing { 78 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 79 | sign configurations.archives 80 | } 81 | 82 | task androidJavadocs(type: Javadoc) { 83 | source = android.sourceSets.main.java 84 | } 85 | 86 | task androidJavadocsJar(type: Jar) { 87 | classifier = 'javadoc' 88 | //basename = artifact_id 89 | from androidJavadocs.destinationDir 90 | } 91 | 92 | task androidSourcesJar(type: Jar) { 93 | classifier = 'sources' 94 | //basename = artifact_id 95 | from android.sourceSets.main.java.srcDirs, 96 | android.sourceSets.main.res.srcDirs 97 | } 98 | 99 | artifacts { 100 | //archives packageReleaseJar 101 | archives androidSourcesJar 102 | archives androidJavadocsJar 103 | } 104 | } -------------------------------------------------------------------------------- /adapper/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/adapters/BaseAdapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.adapters; 18 | 19 | import android.support.annotation.Nullable; 20 | import android.support.v7.widget.RecyclerView; 21 | 22 | import com.scopely.adapper.interfaces.Bidentifier; 23 | import com.scopely.adapper.interfaces.SelectionManager; 24 | 25 | import java.util.Collections; 26 | import java.util.Set; 27 | 28 | public abstract class BaseAdapper extends RecyclerView.Adapter { 29 | @Nullable 30 | private SelectionManager selectionManager; 31 | @Nullable 32 | private Bidentifier bidentifier; 33 | 34 | public BaseAdapper() { 35 | super(); 36 | registerAdapterDataObserver(adapterDatasetObserver); 37 | } 38 | 39 | @Override 40 | public void onAttachedToRecyclerView(RecyclerView recyclerView) { 41 | //Unregistering and reregistering the adapterDatasetObserver ensures that it is the last DatasetObserver in the list, 42 | // and thus gets called first when the list is iterated over in reverse order. 43 | unregisterAdapterDataObserver(adapterDatasetObserver); 44 | registerAdapterDataObserver(adapterDatasetObserver); 45 | } 46 | 47 | protected abstract Set getViewTypes(); 48 | public abstract Object getItem(int position); 49 | public abstract boolean isModel(int position); 50 | 51 | @Nullable 52 | @SuppressWarnings("unchecked") 53 | public Model getModel(int position) { 54 | return isModel(position) ? (Model) getItem(position) : null; 55 | } 56 | 57 | @SuppressWarnings("unchecked") 58 | public void onBindViewHolderCast(RecyclerView.ViewHolder holder, int position) { 59 | onBindViewHolder((Holder) holder, position); 60 | } 61 | 62 | /** 63 | * In older versions of Adapper, several of the Adappers overrode {@link #notifyDataSetChanged()} in order to do some processing on dataset changes. 64 | * {@link android.support.v7.widget.RecyclerView.Adapter} has made that method final, so we hook in here to get the appropriate callbacks. 65 | */ 66 | private final RecyclerView.AdapterDataObserver adapterDatasetObserver = new RecyclerView.AdapterDataObserver() { 67 | @Override 68 | public void onChanged() { 69 | BaseAdapper.this.onChanged(); 70 | } 71 | 72 | @Override 73 | public void onItemRangeChanged(int positionStart, int itemCount) { 74 | BaseAdapper.this.onItemRangeChanged(positionStart, itemCount); 75 | } 76 | 77 | @Override 78 | public void onItemRangeChanged(int positionStart, int itemCount, Object payload) { 79 | BaseAdapper.this.onItemRangeChanged(positionStart, itemCount, payload); 80 | } 81 | 82 | @Override 83 | public void onItemRangeInserted(int positionStart, int itemCount) { 84 | BaseAdapper.this.onItemRangeInserted(positionStart, itemCount); 85 | } 86 | 87 | @Override 88 | public void onItemRangeRemoved(int positionStart, int itemCount) { 89 | BaseAdapper.this.onItemRangeRemoved(positionStart, itemCount); 90 | } 91 | 92 | @Override 93 | public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { 94 | BaseAdapper.this.onItemRangeMoved(fromPosition, toPosition, itemCount); 95 | } 96 | }; 97 | 98 | protected void onItemRangeChanged(int positionStart, int itemCount, Object payload) {} 99 | 100 | protected void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { 101 | onChanged(); 102 | } 103 | 104 | protected void onItemRangeRemoved(int positionStart, int itemCount) { 105 | onChanged(); 106 | } 107 | 108 | protected void onItemRangeInserted(int positionStart, int itemCount) { 109 | onChanged(); 110 | } 111 | 112 | protected void onItemRangeChanged(int positionStart, int itemCount) {} 113 | 114 | protected void onChanged() {} 115 | 116 | /** 117 | * The update() method defaults to a simple delegation to {@link #notifyDataSetChanged()}, 118 | * but in subclasses that implement {@link com.scopely.adapper.interfaces.Reorderable} 119 | * it often computes position changes and delegates to the appropriate notify method: 120 | * {@link #notifyItemInserted(int)}, {@link #notifyItemRemoved(int)}, etc 121 | */ 122 | public void update() { 123 | notifyDataSetChanged(); 124 | } 125 | 126 | @Nullable 127 | protected SelectionManager getSelectionManager(int position) { 128 | return selectionManager; 129 | } 130 | 131 | public BaseAdapper setSelectionManager(@Nullable SelectionManager selectionManager) { 132 | this.selectionManager = selectionManager; 133 | return this; 134 | } 135 | 136 | public BaseAdapper setBidentifier(@Nullable Bidentifier bidentifier) { 137 | this.bidentifier = bidentifier; 138 | unregisterAdapterDataObserver(adapterDatasetObserver); 139 | if(!hasObservers()) { 140 | setHasStableIds(bidentifier != null); 141 | } 142 | registerAdapterDataObserver(adapterDatasetObserver); 143 | return this; 144 | } 145 | 146 | @SuppressWarnings("unchecked") 147 | public Set getItems(Set ids) { 148 | return bidentifier != null ? bidentifier.getModels(ids) : Collections.EMPTY_SET; 149 | } 150 | 151 | @Override 152 | public long getItemId(int position) { 153 | return bidentifier != null ? bidentifier.getId(position) : super.getItemId(position); 154 | } 155 | 156 | @SuppressWarnings("unchecked") 157 | public Set getSelections() { 158 | return selectionManager != null ? selectionManager.getSelections() : Collections.EMPTY_SET; 159 | } 160 | 161 | public void clearSelections() { 162 | if (selectionManager != null) { 163 | selectionManager.clearSelections(); 164 | } 165 | } 166 | 167 | /** 168 | * A {@link SelectionManager} that delegates to an existing SelectionManager, but passes any inputted position through a conversion function before delegating it to the child SelectionManager. 169 | * Generally useful in Adappers that are composed of other Adappers, such as {@link RecursiveAdapper} or {@link GroupableAdapper} 170 | */ 171 | protected abstract static class ConversionSelectManager implements SelectionManager { 172 | private final SelectionManager selectionManager; 173 | 174 | protected ConversionSelectManager(SelectionManager selectionManager) { 175 | this.selectionManager = selectionManager; 176 | } 177 | 178 | @Override 179 | public boolean selectItem(int position, boolean selected) { 180 | return selectionManager.selectItem(convertPosition(position), selected); 181 | } 182 | 183 | protected abstract int convertPosition(int position); 184 | 185 | @Override 186 | public boolean isItemSelected(int position) { 187 | return selectionManager.isItemSelected(convertPosition(position)); 188 | } 189 | 190 | @Override 191 | public void clearSelections() { 192 | selectionManager.clearSelections(); 193 | } 194 | 195 | @Override 196 | public Set getSelections() { 197 | return selectionManager.getSelections(); 198 | } 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/adapters/ListAdapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.adapters; 18 | 19 | import android.support.annotation.NonNull; 20 | import android.support.annotation.Nullable; 21 | import android.util.Pair; 22 | import android.util.SparseBooleanArray; 23 | import android.util.SparseIntArray; 24 | import android.view.LayoutInflater; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.widget.Filter; 28 | import android.widget.Filterable; 29 | 30 | import com.scopely.adapper.impls.HashCodeIdentifier; 31 | import com.scopely.adapper.impls.BidentifierImpl; 32 | import com.scopely.adapper.impls.NaiveLookup; 33 | import com.scopely.adapper.impls.TypedViewHolder; 34 | import com.scopely.adapper.interfaces.FilterFunction; 35 | import com.scopely.adapper.interfaces.Reorderable; 36 | import com.scopely.adapper.interfaces.ViewProvider; 37 | import com.scopely.adapper.utils.ListUtils; 38 | import com.scopely.adapper.utils.SparseArrayUtils; 39 | 40 | import java.util.ArrayList; 41 | import java.util.List; 42 | import java.util.Set; 43 | 44 | /** 45 | * An Adapper that displays a {@link List} of items 46 | * @param The class of the items in the list 47 | * @param The {@link View} class used to display the items in the list 48 | */ 49 | public class ListAdapper extends BaseAdapper> implements Filterable, Reorderable { 50 | 51 | protected List source; 52 | protected List list; 53 | protected List visibleList; 54 | 55 | protected final ViewProvider provider; 56 | @Nullable 57 | private FilterFunction filterFunction; 58 | @Nullable 59 | public CharSequence constraint; 60 | 61 | public ListAdapper(List source, ViewProvider provider) { 62 | this.source = source; 63 | this.provider = provider; 64 | this.list = new ArrayList<>(source); 65 | this.visibleList = list; 66 | setBidentifier(new BidentifierImpl<>(new HashCodeIdentifier(this), new NaiveLookup<>(this))); 67 | notifyDataSetChanged(); 68 | } 69 | 70 | @Override 71 | public void onBindViewHolder(TypedViewHolder holder, int position) { 72 | holder.bind(getModel(position), position, getSelectionManager(position)); 73 | } 74 | 75 | 76 | @NonNull 77 | @Override 78 | public Set getViewTypes() { 79 | return provider.getViewTypes(); 80 | } 81 | 82 | @Override 83 | public Model getModel(int position) { 84 | return (Model) getItem(position); 85 | } 86 | 87 | @Override 88 | public int getItemViewType(int position) { 89 | return provider.getViewType(getModel(position)); 90 | } 91 | 92 | 93 | @Override 94 | public boolean isModel(int position) { 95 | return true; 96 | } 97 | 98 | @Override 99 | public Object getItem(int position) { 100 | return position < visibleList.size() ? visibleList.get(position) : null; 101 | } 102 | 103 | @Override 104 | public TypedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 105 | return provider.create(LayoutInflater.from(parent.getContext()), parent, viewType); 106 | } 107 | 108 | @Override 109 | public int getItemCount() { 110 | return visibleList.size(); 111 | } 112 | 113 | public ListAdapper setFilterFunction(@Nullable FilterFunction filterFunction) { 114 | this.filterFunction = filterFunction; 115 | return this; 116 | } 117 | 118 | @Override 119 | public Filter getFilter() { 120 | return filter; 121 | } 122 | 123 | private final Filter filter = new Filter() { 124 | @Override 125 | public FilterResults performFiltering(CharSequence constraint) { 126 | ListAdapper.this.constraint = constraint; 127 | FilterResults results = new FilterResults(); 128 | if (filterFunction == null) { 129 | results.values = list; 130 | results.count = list.size(); 131 | } else { 132 | List filteredList = new ArrayList<>(); 133 | for (Model model : list) { 134 | if (filterFunction.filter(model, constraint)) { 135 | filteredList.add(model); 136 | } 137 | } 138 | results.values = filteredList; 139 | results.count = filteredList.size(); 140 | } 141 | return results; 142 | } 143 | 144 | @Override 145 | public void publishResults(CharSequence constraint, FilterResults results) { 146 | if (results == null) { 147 | notifyDataSetChanged(); 148 | } else { 149 | visibleList = (List) results.values; 150 | ListAdapper.super.notifyDataSetChanged(); 151 | } 152 | } 153 | }; 154 | 155 | @Override 156 | protected void onChanged() { 157 | list = new ArrayList<>(source); 158 | if(constraint == null || constraint.length() == 0){ 159 | visibleList = list; 160 | } 161 | } 162 | 163 | @Override 164 | public SparseBooleanArray getInsertions() { 165 | List oldList = visibleList; 166 | List newList = getNextVisibleList(); 167 | 168 | return ListUtils.getInsertions(oldList, newList); 169 | } 170 | 171 | @Override 172 | public SparseBooleanArray getDeletions() { 173 | List oldList = visibleList; 174 | List newList = getNextVisibleList(); 175 | 176 | return ListUtils.getDeletions(oldList, newList); 177 | } 178 | 179 | @Override 180 | public SparseIntArray getReorderings() { 181 | List oldList = visibleList; 182 | List newList = getNextVisibleList(); 183 | 184 | return ListUtils.getReorderings(oldList, newList); 185 | } 186 | 187 | public List getVisibleList() { 188 | return visibleList; 189 | } 190 | 191 | public List getNextVisibleList() { 192 | if(constraint == null || constraint.length() == 0){ 193 | return new ArrayList<>(source); 194 | } else { 195 | return visibleList; 196 | } 197 | } 198 | 199 | @Override 200 | public void update() { 201 | SparseBooleanArray deletions = getDeletions(); 202 | if(deletions.size() > 0) { 203 | Pair startEnd = SparseArrayUtils.getRange(deletions); 204 | if(startEnd != null){ 205 | notifyItemRangeRemoved(startEnd.first, startEnd.second - startEnd.first + 1); 206 | } else { 207 | notifyDataSetChanged(); 208 | return; 209 | } 210 | } 211 | SparseBooleanArray insertions = getInsertions(); 212 | if(insertions.size() > 0) { 213 | Pair startEnd = SparseArrayUtils.getRange(insertions); 214 | if(startEnd != null){ 215 | notifyItemRangeInserted(startEnd.first, startEnd.second - startEnd.first + 1); 216 | } else { 217 | notifyDataSetChanged(); 218 | return; 219 | } 220 | } 221 | for (Pair pair : SparseArrayUtils.iterable(getReorderings())) { 222 | notifyItemMoved(pair.first, pair.second); 223 | } 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/adapters/SingleViewAdapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.adapters; 18 | 19 | import android.support.annotation.LayoutRes; 20 | import android.support.annotation.Nullable; 21 | import android.support.v7.widget.RecyclerView; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | import android.widget.Filter; 25 | import android.widget.Filterable; 26 | 27 | import com.android.internal.util.Predicate; 28 | import com.scopely.adapper.utils.SetUtils; 29 | 30 | import java.util.Set; 31 | 32 | /** 33 | * An Adapper that wraps a single {@link View} in the trappings of a {@link BaseAdapper}. 34 | * Generally used in order to include a {@link View} within a {@link RecursiveAdapper} 35 | */ 36 | public class SingleViewAdapper extends BaseAdapper implements Filterable { 37 | 38 | private final View view; 39 | private final int viewType; 40 | private final Set viewTypes; 41 | private boolean visible = true; 42 | @Nullable Predicate filterFunction; 43 | 44 | public SingleViewAdapper(View view) { 45 | this(view, null); 46 | } 47 | 48 | public SingleViewAdapper(View view, @Nullable @LayoutRes Integer viewType) { 49 | this.view = view; 50 | this.viewType = viewType != null ? viewType : view.hashCode(); 51 | viewTypes = SetUtils.initSet(this.viewType); 52 | } 53 | 54 | @Override 55 | protected Set getViewTypes() { 56 | return viewTypes; 57 | } 58 | 59 | @Override 60 | public int getItemViewType(int position) { 61 | return viewType; 62 | } 63 | 64 | @Override 65 | public Object getItem(int position) { 66 | return null; 67 | } 68 | 69 | @Override 70 | public boolean isModel(int position) { 71 | return false; 72 | } 73 | 74 | @Override 75 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 76 | return new RecyclerView.ViewHolder(view) {}; 77 | } 78 | 79 | @Override 80 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 81 | //no op; 82 | } 83 | 84 | @Override 85 | public int getItemCount() { 86 | return visible ? 1 : 0; 87 | } 88 | 89 | private final Filter filter = new Filter() { 90 | @Override 91 | public FilterResults performFiltering(CharSequence constraint) { 92 | FilterResults results = new FilterResults(); 93 | if (filterFunction == null) { 94 | results.values = true; 95 | results.count = 1; 96 | } else { 97 | boolean visible = filterFunction.apply(constraint); 98 | results.values = visible; 99 | results.count = visible ? 1 : 0; 100 | } 101 | return results; 102 | } 103 | 104 | @Override 105 | public void publishResults(CharSequence constraint, FilterResults results) { 106 | if (results == null) { 107 | notifyDataSetChanged(); 108 | } else { 109 | visible = (boolean) results.values; 110 | notifyDataSetChanged(); 111 | } 112 | } 113 | }; 114 | 115 | public void setFilterFunction(@Nullable Predicate filterFunction) { 116 | this.filterFunction = filterFunction; 117 | } 118 | 119 | @Override 120 | public Filter getFilter() { 121 | return filter; 122 | } 123 | } -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/extras/GroupableSpanSizeLookup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.extras; 18 | 19 | import com.scopely.adapper.interfaces.GroupPositionIdentifier; 20 | 21 | public class GroupableSpanSizeLookup extends InvertedSpanSizeLookup { 22 | 23 | private final GroupPositionIdentifier groupPositionIdentifier; 24 | private final int spanCount; 25 | 26 | public GroupableSpanSizeLookup(GroupPositionIdentifier groupPositionIdentifier, int spanCount) { 27 | super(1, spanCount); 28 | this.groupPositionIdentifier = groupPositionIdentifier; 29 | this.spanCount = spanCount; 30 | } 31 | 32 | @Override 33 | public int getItemsPerRow(int position) { 34 | return groupPositionIdentifier.isGroup(position) ? 1 : spanCount; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/extras/InvertedSpanSizeLookup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.extras; 18 | 19 | import android.support.v7.widget.GridLayoutManager; 20 | import android.util.SparseIntArray; 21 | 22 | /** 23 | * A SpanSizeLookup that describes width of elements not by how many spans they take up, but by how many of said element would fill a row. 24 | */ 25 | public abstract class InvertedSpanSizeLookup extends GridLayoutManager.SpanSizeLookup { 26 | 27 | public final int total; 28 | public final SparseIntArray sparseIntArray; 29 | 30 | public InvertedSpanSizeLookup(int... possibleItemsPerRow) { 31 | sparseIntArray = new SparseIntArray(possibleItemsPerRow.length); 32 | total = lcm(possibleItemsPerRow); 33 | for(int i : possibleItemsPerRow) { 34 | sparseIntArray.put(i, total/i); 35 | } 36 | 37 | } 38 | 39 | @Override 40 | public int getSpanSize(int position) { 41 | return sparseIntArray.get(getItemsPerRow(position)); 42 | } 43 | 44 | public abstract int getItemsPerRow(int position); 45 | 46 | private static int gcd(int a, int b) { 47 | while (b > 0) { 48 | int temp = b; 49 | b = a % b; 50 | a = temp; 51 | } 52 | return a; 53 | } 54 | 55 | private static int gcd(int[] input) { 56 | int result = input[0]; 57 | for(int i = 1; i < input.length; i++) result = gcd(result, input[i]); 58 | return result; 59 | } 60 | 61 | private static int lcm(int a, int b) { 62 | return a * (b / gcd(a, b)); 63 | } 64 | 65 | private static int lcm(int[] input) { 66 | int result = input[0]; 67 | for(int i = 1; i < input.length; i++) result = lcm(result, input[i]); 68 | return result; 69 | } 70 | 71 | public int getRequiredSpans() { 72 | return total; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/impls/BidentifierImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.impls; 18 | 19 | import com.scopely.adapper.interfaces.Bidentifier; 20 | import com.scopely.adapper.interfaces.Identifier; 21 | import com.scopely.adapper.interfaces.Lookup; 22 | 23 | import java.util.Set; 24 | 25 | public class BidentifierImpl implements Bidentifier { 26 | private final Identifier identifier; 27 | private final Lookup lookup; 28 | 29 | public BidentifierImpl(Identifier identifier, Lookup lookup) { 30 | this.identifier = identifier; 31 | this.lookup = lookup; 32 | } 33 | 34 | @Override 35 | public long getId(int position) { 36 | return identifier.getId(position); 37 | } 38 | 39 | @Override 40 | public Set getModels(Set ids) { 41 | return lookup.getModels(ids); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/impls/GroupComparatorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.impls; 18 | 19 | import com.scopely.adapper.interfaces.GroupComparator; 20 | 21 | import java.util.Comparator; 22 | 23 | public abstract class GroupComparatorImpl implements GroupComparator { 24 | 25 | private final Comparator intraGroupComparator = new Comparator() { 26 | @Override 27 | public int compare(Model lhs, Model rhs) { 28 | return itemCompare(lhs, rhs); 29 | } 30 | }; 31 | private final Comparator groupComparator = new Comparator() { 32 | @Override 33 | public int compare(Group lhs, Group rhs) { 34 | return groupCompare(lhs, rhs); 35 | } 36 | }; 37 | 38 | protected abstract int groupCompare(Group lhs, Group rhs); 39 | 40 | protected abstract int itemCompare(Model lhs, Model rhs); 41 | 42 | @Override 43 | public Comparator getIntraGroupComparator() { 44 | return intraGroupComparator; 45 | } 46 | 47 | @Override 48 | public Comparator getGroupComparator() { 49 | return groupComparator; 50 | } 51 | 52 | @Override 53 | public int compare(Model lhs, Model rhs) { 54 | int categoryResult = groupCompare(getGroup(lhs), getGroup(rhs)); 55 | return categoryResult != 0 ? categoryResult : itemCompare(lhs, rhs); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/impls/HashCodeIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.impls; 18 | 19 | import android.support.v7.widget.RecyclerView; 20 | 21 | import com.scopely.adapper.adapters.BaseAdapper; 22 | import com.scopely.adapper.interfaces.Identifier; 23 | 24 | /** 25 | * An Identifier that returns the hashcode of the object at a position within an Adapper as its ID 26 | */ 27 | public class HashCodeIdentifier implements Identifier { 28 | private final BaseAdapper adapper; 29 | 30 | public HashCodeIdentifier(BaseAdapper adapper) { 31 | this.adapper = adapper; 32 | } 33 | 34 | @Override 35 | public long getId(int position) { 36 | Object obj = adapper.getItem(position); 37 | return obj != null ? obj.hashCode() : RecyclerView.NO_ID; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/impls/NaiveLookup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.impls; 18 | 19 | import android.support.v7.widget.RecyclerView; 20 | 21 | import com.scopely.adapper.adapters.BaseAdapper; 22 | import com.scopely.adapper.interfaces.Lookup; 23 | import com.scopely.adapper.utils.SetUtils; 24 | 25 | import java.util.Set; 26 | 27 | /** 28 | * A Lookup class that iterates over the elements in an Adapper and compares the IDs until it finds a match 29 | * @param 30 | */ 31 | public class NaiveLookup implements Lookup { 32 | private final BaseAdapper adapper; 33 | 34 | public NaiveLookup(BaseAdapper adapper) { 35 | this.adapper = adapper; 36 | } 37 | 38 | @Override 39 | public Set getModels(Set ids) { 40 | Set list = SetUtils.newSet(); 41 | for(int i = 0; i < adapper.getItemCount(); i++) { 42 | if(ids.contains(adapper.getItemId(i))) { 43 | list.add(adapper.getModel(i)); 44 | } 45 | } 46 | return list; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/impls/TypedViewHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.impls; 18 | 19 | import android.support.annotation.Nullable; 20 | import android.support.v7.widget.RecyclerView; 21 | import android.view.View; 22 | 23 | import com.scopely.adapper.interfaces.SelectionManager; 24 | 25 | public abstract class TypedViewHolder extends RecyclerView.ViewHolder { 26 | public TypedViewHolder(GenericView itemView) { 27 | super(itemView); 28 | } 29 | 30 | @SuppressWarnings("unchecked") 31 | public GenericView getView() { 32 | return (GenericView) itemView; 33 | } 34 | 35 | public void bind(Model model, int position, SelectionManager selectionManager) { 36 | bind(getView(), model, position, selectionManager); 37 | } 38 | 39 | protected abstract void bind(GenericView view, Model model, int position, @Nullable SelectionManager selectionManager); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/impls/ViewProviderImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.impls; 18 | 19 | import android.support.annotation.LayoutRes; 20 | import android.support.annotation.Nullable; 21 | import android.view.LayoutInflater; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | 25 | import com.scopely.adapper.interfaces.SelectionManager; 26 | import com.scopely.adapper.interfaces.ViewProvider; 27 | import com.scopely.adapper.utils.SetUtils; 28 | 29 | import java.util.Set; 30 | 31 | public abstract class ViewProviderImpl implements ViewProvider { 32 | protected final Set layouts; 33 | 34 | protected ViewProviderImpl(@LayoutRes int... layouts) { 35 | this.layouts = SetUtils.newSet(); 36 | for (int i : layouts) { 37 | this.layouts.add(i); 38 | } 39 | } 40 | 41 | @Override 42 | public Set getViewTypes() { 43 | return layouts; 44 | } 45 | 46 | @Override 47 | public TypedViewHolder create(LayoutInflater inflater, ViewGroup parent, int viewType) { 48 | return new TypedViewHolder((GenericView) inflater.inflate(viewType, parent, false)) { 49 | @Override 50 | protected void bind(GenericView view, Model model, int position, SelectionManager selectionManager) { 51 | ViewProviderImpl.this.bind(view, model, position, selectionManager); 52 | } 53 | }; 54 | } 55 | 56 | protected abstract void bind(GenericView view, Model model, int position, @Nullable SelectionManager selectionManager); 57 | 58 | @Override 59 | @LayoutRes 60 | public abstract int getViewType(Model model); 61 | } 62 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/Bidentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | /** 20 | * A Bidirectional Identifier. A simple combination of the Identifier and Lookup interfaces. 21 | */ 22 | public interface Bidentifier extends Identifier, Lookup {} 23 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/FilterFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | 20 | import android.support.annotation.Nullable; 21 | 22 | public interface FilterFunction { 23 | /** 24 | * 25 | * @param item the item on which this function is acting 26 | * @param constraint the constraint on which the function filters. Usually provided by user input into a text input field. 27 | * @return true iff item belongs in a list filtered by the given constraint, false otherwise. 28 | */ 29 | public boolean filter(T item, @Nullable CharSequence constraint); 30 | } 31 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/GroupComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | import java.util.Comparator; 20 | 21 | /** 22 | * An augmented {@link java.util.Comparator} that identifies a containing for each item in the list, and then sorts the list based on the each item belongs to. 23 | * @param The type of the objects in the list being sorted and grouped 24 | * @param The type of the groups each object belongs to 25 | */ 26 | public interface GroupComparator extends Comparator { 27 | Group getGroup(Model item); 28 | Comparator getIntraGroupComparator(); 29 | Comparator getGroupComparator(); 30 | } 31 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/GroupPositionIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | public interface GroupPositionIdentifier { 20 | boolean isGroup(int position); 21 | } 22 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/Identifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | public interface Identifier { 20 | /** 21 | * @param position a position within an adapper 22 | * @return the ID of the item at {@param position} 23 | */ 24 | long getId(int position); 25 | } 26 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/Lookup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | import java.util.Set; 20 | 21 | public interface Lookup { 22 | /** 23 | * @param ids 24 | * @return A Set of objects, of type T, for which {@param ids} is the set of their IDs. 25 | */ 26 | Set getModels(Set ids); 27 | } 28 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/MiniOrm.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | import android.database.Cursor; 20 | 21 | /** 22 | * A super simplified Object-Relational-Mapper 23 | * @param the type of Object being mapped to 24 | */ 25 | public interface MiniOrm { 26 | /** 27 | * @param c A Cursor positioned at the entry for which you wish to return an object of type Model 28 | * @return 29 | */ 30 | public Model getObject(Cursor c); 31 | } 32 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/Reorderable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | import android.util.SparseBooleanArray; 20 | import android.util.SparseIntArray; 21 | 22 | /** 23 | * 24 | * An interface to be implemented by Adapters to indicate that they keep track of insertions, deletions and reorderings between dataset changes. 25 | * 26 | */ 27 | public interface Reorderable { 28 | int NOT_PRESENT = -1; 29 | 30 | SparseBooleanArray getInsertions(); 31 | 32 | SparseBooleanArray getDeletions(); 33 | 34 | SparseIntArray getReorderings(); 35 | } 36 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/SelectionManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | import java.util.Set; 20 | 21 | /** 22 | * A selection manager tracks selections made within a list. 23 | * Its primary use is by Adappers to enable selection behavior within the RecyclerView 24 | * @param the type of objects backing the list 25 | */ 26 | public interface SelectionManager { 27 | /** 28 | * User has indicated they wish to select or unselect the item at {@param position} 29 | * @return true if selection was accepted 30 | */ 31 | boolean selectItem(int position, boolean selected); 32 | 33 | /** 34 | * @return true iff the item at {@param position} has been marked as selected 35 | */ 36 | boolean isItemSelected(int position); 37 | 38 | /** 39 | * @return the Set of items within the list that have been marked as selected 40 | */ 41 | Set getSelections(); 42 | 43 | void clearSelections(); 44 | } 45 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/interfaces/ViewProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.interfaces; 18 | 19 | import android.view.LayoutInflater; 20 | import android.view.View; 21 | import android.view.ViewGroup; 22 | 23 | import com.scopely.adapper.impls.TypedViewHolder; 24 | 25 | import java.util.Set; 26 | 27 | public interface ViewProvider { 28 | /** 29 | * Return the id of the layout to use for the provided item. 30 | * Items that return the same id can have their views recycled between them. 31 | * It is recommended that you use the R value of the layout resource from which the view is inflated 32 | */ 33 | int getViewType(Model model); 34 | 35 | /** 36 | * Return a set of all the layout ids this provider is capable of providing. 37 | */ 38 | Set getViewTypes(); 39 | 40 | /** 41 | * 42 | * Returns an instance of GenericView appropriate for the provided Item. 43 | * 44 | * @param inflater a layout inflater for the current context. Generally provided by the adapter. 45 | * @param parent the parent view into which the provided view will be placed. Generally a ListView or similar. 46 | * @return an instance of {@link TypedViewHolder} 47 | */ 48 | TypedViewHolder create(LayoutInflater inflater, ViewGroup parent, int viewType); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/selection/MultiSelectManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.selection; 18 | 19 | import android.support.v7.widget.RecyclerView; 20 | 21 | import com.scopely.adapper.adapters.BaseAdapper; 22 | import com.scopely.adapper.interfaces.SelectionManager; 23 | import com.scopely.adapper.utils.SetUtils; 24 | 25 | import java.util.Set; 26 | 27 | /** 28 | * An implementation of SelectionManager that allows multiple items to be selected at a time. 29 | * Selecting a new item will add it to the set of selections, up to a defined maximum number of selected items. 30 | */ 31 | public class MultiSelectManager implements SelectionManager { 32 | private final Set selected; //Set of IDs of selected items 33 | private final BaseAdapper adapper; 34 | private final int maximumSelectable; 35 | 36 | public MultiSelectManager(BaseAdapper adapper) { 37 | this(adapper, Integer.MAX_VALUE); 38 | } 39 | 40 | public MultiSelectManager(BaseAdapper adapper, int maximumSelectable) { 41 | this.maximumSelectable = maximumSelectable; 42 | selected = SetUtils.newSet(); 43 | this.adapper = adapper; 44 | if(!adapper.hasStableIds()) { 45 | throw new RuntimeException("You cannot use SelectionManager with an Adapper that does not have stable ids"); 46 | } 47 | } 48 | 49 | @Override 50 | public boolean selectItem(int position, boolean selected) { 51 | if(selected) { 52 | if(this.selected.size() == maximumSelectable) { 53 | onMaximumExceeded(maximumSelectable); 54 | return false; 55 | } 56 | this.selected.add(adapper.getItemId(position)); 57 | } else { 58 | this.selected.remove(adapper.getItemId(position)); 59 | } 60 | adapper.notifyItemChanged(position); 61 | return true; 62 | } 63 | 64 | protected void onMaximumExceeded(int maximumSelectable) { 65 | //Override in order to process events when the user attempts to select more than the maximum number allowed. 66 | } 67 | 68 | @Override 69 | public boolean isItemSelected(int position) { 70 | return selected.contains(adapper.getItemId(position)); 71 | } 72 | 73 | @Override 74 | public void clearSelections() { 75 | selected.clear(); 76 | adapper.notifyDataSetChanged(); 77 | } 78 | 79 | @Override 80 | @SuppressWarnings("unchecked") 81 | public Set getSelections() { 82 | return adapper.getItems(selected); 83 | } 84 | 85 | public int getCount() { 86 | return selected.size(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/selection/RadioSelectManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.selection; 18 | 19 | import android.support.annotation.Nullable; 20 | import android.support.v7.widget.RecyclerView; 21 | 22 | import com.scopely.adapper.adapters.BaseAdapper; 23 | import com.scopely.adapper.interfaces.SelectionManager; 24 | 25 | import java.util.Collections; 26 | import java.util.Set; 27 | 28 | /** 29 | * An implementation of SelectionManager that allows a single item to be selected at a time. 30 | * Selecting a new item will clear the existing selection. 31 | */ 32 | public class RadioSelectManager implements SelectionManager { 33 | @Nullable 34 | private Long selected; //the ID of the selected item, as returned by adapper.getItemId(position) 35 | private final BaseAdapper adapper; 36 | 37 | public RadioSelectManager(BaseAdapper adapper) { 38 | this.adapper = adapper; 39 | if(!adapper.hasStableIds()) { 40 | throw new RuntimeException("You cannot use SelectionManager with an Adapper that does not have stable ids"); 41 | } 42 | } 43 | 44 | @Override 45 | public boolean selectItem(int position, boolean selected) { 46 | this.selected = selected ? adapper.getItemId(position) : null; 47 | adapper.notifyDataSetChanged(); 48 | return true; 49 | } 50 | 51 | @Override 52 | public boolean isItemSelected(int position) { 53 | return selected != null && selected == adapper.getItemId(position); 54 | } 55 | 56 | @Override 57 | @SuppressWarnings("unchecked") 58 | public Set getSelections() { 59 | return adapper.getItems(Collections.singleton(selected)); 60 | } 61 | 62 | @Override 63 | public void clearSelections() { 64 | selected = null; 65 | adapper.notifyDataSetChanged(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/utils/CompareUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.utils; 18 | 19 | 20 | import android.support.annotation.Nullable; 21 | 22 | import java.util.Comparator; 23 | 24 | public class CompareUtils { 25 | 26 | /** 27 | * Merges multiple Comparators into a single Comparator. 28 | * @param comparators A list of Comparators, in the order they will be given priority in the comparison. 29 | * @return a Comparator that merges the provided Comparators. 30 | * During a comparison, it will move through the provided Comparators 31 | * until it finds the first one that evaluates to a non-zero value. 32 | * If it exhausts all the provided Comparators, it will return zero for the whole comparison. 33 | */ 34 | @SafeVarargs 35 | public static Comparator mergeComparators(final Comparator... comparators){ 36 | return new Comparator() { 37 | @Override 38 | public int compare(T lhs, T rhs) { 39 | return multiDimensionalCompare(lhs, rhs, comparators); 40 | } 41 | }; 42 | } 43 | 44 | /** 45 | * Compares two items using a provided list of Comparators. 46 | * Moves through the provided Comparators until it finds the first one that evaluates to a non-zero value. 47 | * If it exhausts all the provided Comparators, it will return zero for the whole comparison. 48 | */ 49 | @SafeVarargs 50 | public static int multiDimensionalCompare(T lhs, T rhs, Comparator... comparators){ 51 | for(Comparator comparator : comparators){ 52 | int result = comparator.compare(lhs, rhs); 53 | if(result != 0){ 54 | return result; 55 | } 56 | } 57 | return 0; 58 | } 59 | 60 | /** 61 | * Takes a Comparator that is not null safe, and returns a version of the same Comparator that is 62 | * @param nullsLessThan true iff null values come before non-null values in the comparison, false otherwise 63 | */ 64 | public static Comparator getNullSafeComparator(final Comparator comparator, final boolean nullsLessThan) { 65 | return new Comparator() { 66 | @Override 67 | public int compare(T lhs, T rhs) { 68 | return nullableCompare(lhs, rhs, comparator, nullsLessThan); 69 | } 70 | }; 71 | } 72 | 73 | /** 74 | * Compares two items using the provided Comparator in a way that accepts nulls, even if the Comparator itself does not safely accept them 75 | * @param nullsLessThan true iff null values come before non-null values in the comparison, false otherwise 76 | */ 77 | public static int nullableCompare(@Nullable T lhs, @Nullable T rhs, Comparator comparator, boolean nullsLessThan) { 78 | if(lhs != null && rhs != null) { 79 | return comparator.compare(lhs, rhs); 80 | } else if (lhs == null && rhs == null) { 81 | return 0; 82 | } else if (lhs == null) { 83 | return nullsLessThan ? -1 : 1; 84 | } else { 85 | return nullsLessThan ? 1 : -1; 86 | } 87 | } 88 | 89 | /** 90 | * Takes a Comparator that is not null safe, and returns a version of the same Comparator that is 91 | * @param nullsLessThan true iff null values come before non-null values in the comparison, false otherwise 92 | */ 93 | public static > Comparator getNullSafeComparator(Class clazz, final boolean nullsLessThan) { 94 | return new Comparator() { 95 | @Override 96 | public int compare(T lhs, T rhs) { 97 | return nullableCompare(lhs, rhs, nullsLessThan); 98 | } 99 | }; 100 | } 101 | 102 | /** 103 | * Compares two Comparable items in a null safe way 104 | * @param nullsLessThan true iff null values come before non-null values in the comparison, false otherwise 105 | */ 106 | public static > int nullableCompare(@Nullable T lhs, @Nullable T rhs, boolean nullsLessThan) { 107 | if(lhs != null && rhs != null) { 108 | return lhs.compareTo(rhs); 109 | } else if (lhs == null && rhs == null) { 110 | return 0; 111 | } else if (lhs == null) { 112 | return nullsLessThan ? -1 : 1; 113 | } else { 114 | return nullsLessThan ? 1 : -1; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/utils/CompositeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.utils; 18 | 19 | import android.util.Log; 20 | import android.widget.Filter; 21 | 22 | import java.lang.reflect.InvocationTargetException; 23 | import java.lang.reflect.Method; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | 28 | /** 29 | * Filter that is composed of multiple other filters. Only completes when all of its children have completed. 30 | */ 31 | public class CompositeFilter extends Filter { 32 | 33 | Filter[] filters; 34 | private Method performFiltering; 35 | private Method publishResults; 36 | 37 | public CompositeFilter(Filter... filters) { 38 | this.filters = filters; 39 | try { 40 | //Reflection is unfortuante. Seemingly no other way to access a filter's logic synchronously. 41 | performFiltering = Filter.class.getDeclaredMethod("performFiltering", CharSequence.class); 42 | performFiltering.setAccessible(true); 43 | 44 | publishResults = Filter.class.getDeclaredMethod("publishResults", CharSequence.class, FilterResults.class); 45 | publishResults.setAccessible(true); 46 | 47 | } catch (NoSuchMethodException e) { 48 | Log.e("adapper", "FilterUtils error", e); 49 | } 50 | } 51 | 52 | @Override 53 | protected FilterResults performFiltering(CharSequence constraint) { 54 | if(performFiltering != null){ 55 | try { 56 | int count = 0; 57 | Map map = new HashMap<>(); 58 | 59 | for (Filter filter : filters) { 60 | if(filter != null) { 61 | FilterResults results = (FilterResults) performFiltering.invoke(filter, constraint); 62 | count += results.count; 63 | map.put(filter, results); 64 | } 65 | } 66 | 67 | FilterResults results = new FilterResults(); 68 | results.count = count; 69 | results.values = map; 70 | return results; 71 | } catch (IllegalAccessException e) { 72 | Log.e("adapper", "FilterUtils error", e); 73 | return new FilterResults(); 74 | } catch (InvocationTargetException e) { 75 | Log.e("adapper", "FilterUtils error", e); 76 | return new FilterResults(); 77 | } 78 | } else { 79 | return new FilterResults(); 80 | } 81 | } 82 | 83 | @Override 84 | protected void publishResults(CharSequence constraint, FilterResults results) { 85 | @SuppressWarnings("unchecked") 86 | Map map = (Map) results.values; 87 | if(map != null && publishResults != null) { 88 | try { 89 | for (Filter filter : filters) { 90 | if(filter != null){ 91 | publishResults.invoke(filter, constraint, map.get(filter)); 92 | } 93 | } 94 | } catch (IllegalAccessException e) { 95 | Log.e("adapper", "FilterUtils error", e); 96 | } catch (InvocationTargetException e) { 97 | Log.e("adapper", "FilterUtils error", e); 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/utils/FunctionList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.utils; 18 | 19 | import android.support.annotation.NonNull; 20 | 21 | import java.lang.reflect.Array; 22 | import java.util.Collection; 23 | import java.util.Iterator; 24 | import java.util.List; 25 | import java.util.ListIterator; 26 | 27 | /** 28 | * A List wherein each object of type U at index i is the output of a function that evaluates the object of type T at index i in an underlying List. 29 | */ 30 | public class FunctionList implements List { 31 | 32 | Function function; 33 | List list; 34 | 35 | public FunctionList(List list, Function function) { 36 | this.function = function; 37 | this.list = list; 38 | } 39 | 40 | @Override 41 | public void add(int location, Output object) { 42 | throw new FunctionException(); 43 | } 44 | 45 | @Override 46 | public boolean add(Output object) { 47 | throw new FunctionException(); 48 | } 49 | 50 | @Override 51 | public boolean addAll(int location, @NonNull Collection collection) { 52 | throw new FunctionException(); 53 | } 54 | 55 | @Override 56 | public boolean addAll(@NonNull Collection collection) { 57 | throw new FunctionException(); 58 | } 59 | 60 | @Override 61 | public void clear() { 62 | getList().clear(); 63 | } 64 | 65 | @Override 66 | public boolean contains(Object object) { 67 | return indexOf(object) >= 0; 68 | } 69 | 70 | @Override 71 | public boolean containsAll(@NonNull Collection collection) { 72 | for(Object obj : collection) { 73 | if(!contains(obj)) return false; 74 | } 75 | return true; 76 | } 77 | 78 | @Override 79 | public Output get(int location) { 80 | return function.evaluate(getList().get(location)); 81 | } 82 | 83 | @Override 84 | public int indexOf(Object object) { 85 | for(int i = 0; i < size(); i++) { 86 | if(object.equals(get(i))) { 87 | return i; 88 | } 89 | } 90 | return -1; 91 | } 92 | 93 | @Override 94 | public boolean isEmpty() { 95 | return getList().isEmpty(); 96 | } 97 | 98 | @NonNull 99 | @Override 100 | public Iterator iterator() { 101 | final Iterator internalIterator = getList().iterator(); 102 | return new Iterator() { 103 | @Override 104 | public boolean hasNext() { 105 | return internalIterator.hasNext(); 106 | } 107 | 108 | @Override 109 | public Output next() { 110 | return function.evaluate(internalIterator.next()); 111 | } 112 | 113 | @Override 114 | public void remove() { 115 | internalIterator.remove(); 116 | } 117 | }; 118 | } 119 | 120 | @Override 121 | public int lastIndexOf(Object object) { 122 | for(int i = size() - 1; i > 0; i--) { 123 | if(object.equals(get(i))) { 124 | return i; 125 | } 126 | } 127 | return -1; 128 | } 129 | 130 | @NonNull 131 | @Override 132 | public ListIterator listIterator() { 133 | return listIterator(0); 134 | } 135 | 136 | @NonNull 137 | @Override 138 | public ListIterator listIterator(int location) { 139 | final ListIterator internalIterator = getList().listIterator(location); 140 | return new ListIterator() { 141 | @Override 142 | public void add(Output object) { 143 | throw new FunctionException(); 144 | } 145 | 146 | @Override 147 | public boolean hasNext() { 148 | return internalIterator.hasNext(); 149 | } 150 | 151 | @Override 152 | public boolean hasPrevious() { 153 | return internalIterator.hasPrevious(); 154 | } 155 | 156 | @Override 157 | public Output next() { 158 | return function.evaluate(internalIterator.next()); 159 | } 160 | 161 | @Override 162 | public int nextIndex() { 163 | return internalIterator.nextIndex(); 164 | } 165 | 166 | @Override 167 | public Output previous() { 168 | return function.evaluate(internalIterator.previous()); 169 | } 170 | 171 | @Override 172 | public int previousIndex() { 173 | return internalIterator.previousIndex(); 174 | } 175 | 176 | @Override 177 | public void remove() { 178 | internalIterator.remove(); 179 | } 180 | 181 | @Override 182 | public void set(Output object) { 183 | throw new FunctionException(); 184 | } 185 | }; 186 | } 187 | 188 | @Override 189 | public Output remove(int location) { 190 | return function.evaluate(getList().remove(location)); 191 | } 192 | 193 | @Override 194 | public boolean remove(Object object) { 195 | return false; 196 | } 197 | 198 | @Override 199 | public boolean removeAll(@NonNull Collection collection) { 200 | return false; 201 | } 202 | 203 | @Override 204 | public boolean retainAll(@NonNull Collection collection) { 205 | return false; 206 | } 207 | 208 | @Override 209 | public Output set(int location, Output object) { 210 | throw new FunctionException(); 211 | } 212 | 213 | @Override 214 | public int size() { 215 | return getList().size(); 216 | } 217 | 218 | @NonNull 219 | @Override 220 | public List subList(int start, int end) { 221 | return new FunctionList<>(getList().subList(start, end), function); 222 | } 223 | 224 | @NonNull 225 | @Override 226 | public Object[] toArray() { 227 | return toArray(new Object[size()]); 228 | } 229 | 230 | @NonNull 231 | @Override 232 | public T[] toArray(@NonNull T[] contents) { 233 | int s = size(); 234 | if (contents.length < s) { 235 | @SuppressWarnings("unchecked") T[] newArray 236 | = (T[]) Array.newInstance(contents.getClass().getComponentType(), s); 237 | contents = newArray; 238 | } 239 | for(int i = 0; i < s; i++) { 240 | contents[i] = (T) get(i); 241 | } 242 | if (contents.length > s) { 243 | contents[s] = null; 244 | } 245 | return contents; 246 | } 247 | 248 | protected List getList() { 249 | return list; 250 | } 251 | 252 | public interface Function { 253 | U evaluate(T input); 254 | } 255 | 256 | private static class FunctionException extends UnsupportedOperationException { 257 | private FunctionException() { 258 | super("Operation requires determining the input of a function from the output, which is not defined"); 259 | } 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/utils/SetUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.utils; 18 | 19 | import android.os.Build; 20 | import android.util.ArraySet; 21 | 22 | import java.util.Arrays; 23 | import java.util.Collection; 24 | import java.util.Collections; 25 | import java.util.HashSet; 26 | import java.util.Set; 27 | 28 | /** 29 | * Util class for generating {@link Set Set} instances. 30 | * Uses ArraySet on versions of Android M and up, falls back to HashSet for older version. 31 | */ 32 | public class SetUtils { 33 | public static Set newSet() { 34 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 35 | return new ArraySet<>(); 36 | } else { 37 | return new HashSet<>(); 38 | } 39 | } 40 | 41 | public static Set newSet(int capacity) { 42 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 43 | return new ArraySet<>(capacity); 44 | } else { 45 | return new HashSet<>(capacity); 46 | } 47 | } 48 | 49 | @SafeVarargs 50 | public static Set initSet(T... elements) { 51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 52 | Set set = new ArraySet<>(elements.length); 53 | Collections.addAll(set, elements); 54 | return set; 55 | } else { 56 | return new HashSet<>(Arrays.asList(elements)); 57 | } 58 | } 59 | 60 | public static Set newSet(Collection collection) { 61 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 62 | Set set = new ArraySet<>(collection.size()); 63 | set.addAll(collection); 64 | return set; 65 | } else { 66 | return new HashSet<>(collection); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /adapper/src/main/java/com/scopely/adapper/utils/SparseArrayUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.utils; 18 | 19 | import android.support.annotation.Nullable; 20 | import android.util.Pair; 21 | import android.util.SparseArray; 22 | import android.util.SparseBooleanArray; 23 | import android.util.SparseIntArray; 24 | 25 | import java.util.Iterator; 26 | 27 | /** 28 | * Util class for working with SparseArrays. 29 | * Contains methods for combining, iterating over, and determining range of keys. 30 | */ 31 | public class SparseArrayUtils { 32 | 33 | public static SparseBooleanArray combine(SparseBooleanArray... arrays) { 34 | SparseBooleanArray combined = new SparseBooleanArray(); 35 | for(SparseBooleanArray array : arrays) { 36 | for(int i = 0; i < array.size(); i++) { 37 | combined.append(array.keyAt(i), array.valueAt(i)); 38 | } 39 | } 40 | return combined; 41 | } 42 | 43 | public static SparseIntArray combine(SparseIntArray... arrays) { 44 | SparseIntArray combined = new SparseIntArray(); 45 | for(SparseIntArray array : arrays) { 46 | for(int i = 0; i < array.size(); i++) { 47 | combined.append(array.keyAt(i), array.valueAt(i)); 48 | } 49 | } 50 | return combined; 51 | } 52 | 53 | public static Iterable> iterable(final SparseBooleanArray array) { 54 | return new Iterable>() { 55 | @Override 56 | public Iterator> iterator() { 57 | return new Iterator>() { 58 | int i = -1; 59 | 60 | @Override 61 | public boolean hasNext() { 62 | return i + 1 < array.size(); 63 | } 64 | 65 | @Override 66 | public Pair next() { 67 | i++; 68 | return new Pair(array.keyAt(i), array.valueAt(i)); 69 | } 70 | 71 | @Override 72 | public void remove() { 73 | array.delete(array.keyAt(i)); 74 | } 75 | }; 76 | } 77 | }; 78 | } 79 | 80 | public static Iterable> iterable(final SparseIntArray array) { 81 | return new Iterable>() { 82 | @Override 83 | public Iterator> iterator() { 84 | return new Iterator>() { 85 | int i = -1; 86 | 87 | @Override 88 | public boolean hasNext() { 89 | return i + 1 < array.size(); 90 | } 91 | 92 | @Override 93 | public Pair next() { 94 | i++; 95 | return new Pair(array.keyAt(i), array.valueAt(i)); 96 | } 97 | 98 | @Override 99 | public void remove() { 100 | array.delete(array.keyAt(i)); 101 | } 102 | }; 103 | } 104 | }; 105 | } 106 | 107 | public static Iterable> iterable(final SparseArray array) { 108 | return new Iterable>() { 109 | @Override 110 | public Iterator> iterator() { 111 | return new Iterator>() { 112 | int i = -1; 113 | 114 | @Override 115 | public boolean hasNext() { 116 | return i + 1 < array.size(); 117 | } 118 | 119 | @Override 120 | public Pair next() { 121 | i++; 122 | return new Pair(array.keyAt(i), array.valueAt(i)); 123 | } 124 | 125 | @Override 126 | public void remove() { 127 | array.delete(array.keyAt(i)); 128 | } 129 | }; 130 | } 131 | }; 132 | } 133 | 134 | /** 135 | * Calculates the start and end of a contiguous range of keys in a sparse array. 136 | * 137 | * @param array A {@link SparseBooleanArray SparseBooleanArray} 138 | * @return a {@link Pair Pair} where the first element in the smallest key in {@param array} and the second element is the largest key in {@param array}. Returns null if the array is empty, or the array contains non-contiguous values. 139 | */ 140 | @Nullable 141 | public static Pair getRange(SparseBooleanArray array) { 142 | if(array.size() == 0) return null; 143 | if(array.size() == 1) return new Pair<>(array.keyAt(0), array.keyAt(0)); 144 | int largest = 0; 145 | int smallest = 0; 146 | for(int i = 0; i < array.size(); i++){ 147 | int val = array.keyAt(i); 148 | if(i > 0 && val - 1 != array.keyAt(i -1)) { 149 | return null; 150 | } 151 | if(val > largest) largest = val; 152 | if(val < smallest) smallest = val; 153 | } 154 | return new Pair<>(smallest, largest); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /adapper/src/test/java/com/scopely/adapper/utils/ListUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.scopely.adapper.utils; 18 | 19 | import android.util.SparseBooleanArray; 20 | import android.util.SparseIntArray; 21 | 22 | import org.junit.Test; 23 | 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | import static org.hamcrest.core.Is.is; 28 | import static org.junit.Assert.assertThat; 29 | 30 | public class ListUtilsTest { 31 | private static final List list05 = Arrays.asList(0,1,2,3,4,5); 32 | private static final List list15 = Arrays.asList(1,2,3,4,5); 33 | private static final List list06 = Arrays.asList(0,1,2,3,4,5,6); 34 | 35 | private static final List listFlip = Arrays.asList(0,1,2,3,5,4); 36 | private static final List listGap = Arrays.asList(5,0,1,2,3,4); 37 | private static final List listMultiReorder = Arrays.asList(5,0,4,1,2,3); 38 | private static final List listSwap = Arrays.asList(5,1,2,3,4,0); 39 | 40 | 41 | 42 | @Test 43 | public void testSingleInsert() { 44 | SparseBooleanArray insertions = ListUtils.getInsertions(list05, list06); 45 | assertThat(insertions.size(), is(1)); 46 | assertThat(insertions.get(6), is(true)); 47 | } 48 | 49 | @Test 50 | public void testSingleInsertHead() { 51 | SparseBooleanArray insertions = ListUtils.getInsertions(list15, list05); 52 | assertThat(insertions.size(), is(1)); 53 | assertThat(insertions.get(0), is(true)); 54 | } 55 | 56 | @Test 57 | public void testMultiInsert() { 58 | SparseBooleanArray insertions = ListUtils.getInsertions(list15, list06); 59 | assertThat(insertions.size(), is(2)); 60 | assertThat(insertions.get(6), is(true)); 61 | assertThat(insertions.get(0), is(true)); 62 | } 63 | 64 | @Test 65 | public void testSingleDeletion() { 66 | SparseBooleanArray deletions = ListUtils.getDeletions(list06, list05); 67 | assertThat(deletions.size(), is(1)); 68 | assertThat(deletions.get(6), is(true)); 69 | } 70 | 71 | @Test 72 | public void testSingleDeletionHead() { 73 | SparseBooleanArray deletions = ListUtils.getDeletions(list05, list15); 74 | assertThat(deletions.size(), is(1)); 75 | assertThat(deletions.get(0), is(true)); 76 | } 77 | 78 | @Test 79 | public void testMultiDelete() { 80 | SparseBooleanArray deletions = ListUtils.getDeletions(list06, list15); 81 | assertThat(deletions.size(), is(2)); 82 | assertThat(deletions.get(6), is(true)); 83 | assertThat(deletions.get(0), is(true)); 84 | } 85 | 86 | @Test 87 | public void testSingleReorderDown() { 88 | SparseIntArray reorderings = ListUtils.getReorderings(list05, listFlip); 89 | assertThat(reorderings.size(), is(1)); 90 | assertThat(reorderings.get(4), is(5)); 91 | } 92 | 93 | @Test 94 | public void testSingleReorderGapDown() { 95 | SparseIntArray reorderings = ListUtils.getReorderings(list05, listGap); 96 | assertThat(reorderings.size(), is(1)); 97 | assertThat(reorderings.get(0), is(5)); 98 | } 99 | 100 | @Test 101 | public void testMultiReorderDown() { 102 | SparseIntArray reorderings = ListUtils.getReorderings(list05, listMultiReorder); 103 | assertThat(reorderings.size(), is(2)); 104 | assertThat(reorderings.get(0), is(5)); 105 | assertThat(reorderings.get(2), is(4)); 106 | } 107 | 108 | @Test 109 | public void testSingleReorderUp() { 110 | SparseIntArray reorderings = ListUtils.getReorderings(listFlip, list05); 111 | assertThat(reorderings.size(), is(1)); 112 | assertThat(reorderings.get(4), is(5)); 113 | } 114 | 115 | @Test 116 | public void testSingleReorderGapUp() { 117 | SparseIntArray reorderings = ListUtils.getReorderings(listGap, list05); 118 | assertThat(reorderings.size(), is(1)); 119 | assertThat(reorderings.get(5), is(0)); 120 | } 121 | 122 | @Test 123 | public void testMultiReorderUp() { 124 | SparseIntArray reorderings = ListUtils.getReorderings(listMultiReorder, list05); 125 | assertThat(reorderings.size(), is(2)); 126 | assertThat(reorderings.get(5), is(0)); 127 | assertThat(reorderings.get(4), is(2)); 128 | } 129 | 130 | @Test 131 | public void testReorderSwap() { 132 | SparseIntArray reorderings = ListUtils.getReorderings(list05, listSwap); 133 | assertThat(reorderings.size(), is(2)); 134 | assertThat(reorderings.get(5), is(0)); 135 | assertThat(reorderings.get(0), is(5)); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 18 | 19 | buildscript { 20 | repositories { 21 | jcenter() 22 | } 23 | 24 | dependencies { 25 | classpath 'de.mobilej.unmock:UnMockPlugin:0.6.2' 26 | } 27 | } 28 | 29 | allprojects { 30 | repositories { 31 | maven { url "http://dl.bintray.com/populov/maven" } 32 | jcenter() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scopely/adapper/edc85882549f1884fcbfa2117c41a698991c243a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2017 Scopely, Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | #Tue Jun 27 17:53:51 PDT 2017 18 | distributionBase=GRADLE_USER_HOME 19 | distributionPath=wrapper/dists 20 | zipStoreBase=GRADLE_USER_HOME 21 | zipStorePath=wrapper/dists 22 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-rc-1-all.zip 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Scopely, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | include ':adapper' 18 | include ':adapper-example' 19 | --------------------------------------------------------------------------------