├── .gitignore ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── io │ │ └── github │ │ └── erikjhordanrey │ │ └── recyclerview_sample │ │ ├── activity │ │ └── MainActivity.java │ │ ├── adapter │ │ ├── AdapterExample.java │ │ └── AdapterExampleTypes.java │ │ ├── drawer │ │ ├── DrawerInteractor.java │ │ ├── DrawerInteractorImpl.java │ │ ├── DrawerListener.java │ │ ├── DrawerPresenter.java │ │ └── DrawerPresenterImpl.java │ │ ├── fragment │ │ ├── BaseFragment.java │ │ ├── GridHorizontalFragment.java │ │ ├── GridQualifiersVerticalFragment.java │ │ ├── GridSpanSizeVerticalFragment.java │ │ ├── GridVerticalFragment.java │ │ ├── ItemTypesVerticalFragment.java │ │ ├── LinearHorizontalFragment.java │ │ ├── LinearVerticalFragment.java │ │ ├── ResponsiveLinearVerticalFragment.java │ │ ├── StaggeredHorizontalFragment.java │ │ └── StaggeredVerticalFragment.java │ │ ├── model │ │ ├── Interactor.java │ │ ├── LoaderListener.java │ │ ├── Picture.java │ │ └── PictureInteractor.java │ │ ├── presenter │ │ ├── PicturePresenter.java │ │ ├── Presenter.java │ │ └── RecyclerItemClickListener.java │ │ ├── view │ │ └── PictureMvpView.java │ │ └── widget │ │ ├── DividerDecoration.java │ │ ├── ItemOffsetDecoration.java │ │ └── ResponsiveRecyclerView.java │ └── res │ ├── drawable-hdpi │ ├── ic_action_action_favorite.png │ ├── ic_action_action_turned_in.png │ ├── ic_action_social_share.png │ ├── ic_github.png │ └── ic_menu.png │ ├── drawable-mdpi │ ├── ic_action_action_favorite.png │ ├── ic_action_action_turned_in.png │ ├── ic_action_social_share.png │ ├── ic_github.png │ └── ic_menu.png │ ├── drawable-nodpi │ ├── cohete_flat.png │ ├── london_flat.png │ ├── material_flat.png │ ├── moon_flat.jpg │ ├── mountain_flat.png │ ├── mountain_mo_flat.png │ ├── moutain_go_flat.jpg │ ├── pine_flat.jpg │ ├── towers_flat.png │ └── vulcan_flat.png │ ├── drawable-v21 │ ├── item_selector.xml │ └── shape_background_default.xml │ ├── drawable-xhdpi │ ├── ic_action_action_favorite.png │ ├── ic_action_action_turned_in.png │ ├── ic_action_social_share.png │ ├── ic_github.png │ └── ic_menu.png │ ├── drawable-xxhdpi │ ├── ic_action_action_favorite.png │ ├── ic_action_action_turned_in.png │ ├── ic_action_social_share.png │ ├── ic_github.png │ └── ic_menu.png │ ├── drawable-xxxhdpi │ ├── ic_action_action_favorite.png │ ├── ic_action_action_turned_in.png │ ├── ic_action_social_share.png │ ├── ic_github.png │ └── ic_menu.png │ ├── drawable │ ├── item_selector.xml │ └── side_nav_bar.xml │ ├── layout │ ├── activity_main.xml │ ├── app_bar_main.xml │ ├── content_main.xml │ ├── fragment_base.xml │ ├── fragment_responsive.xml │ ├── item_type_five.xml │ ├── item_type_four.xml │ ├── item_type_one.xml │ ├── item_type_three.xml │ ├── item_type_two.xml │ └── nav_header_main.xml │ ├── menu │ ├── activity_main_drawer.xml │ └── main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-sw600dp-land │ └── integers.xml │ ├── values-sw600dp │ └── integers.xml │ ├── values-v21 │ └── styles.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── integers.xml │ ├── strings.xml │ └── styles.xml ├── art └── Telecine_2015-10-18-21-56-43.gif ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | .DS_Store 4 | /build 5 | /captures 6 | **.iml 7 | /.idea 8 | sdcard 9 | sdcard.lock 10 | libs/ 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RecyclerView-Examples 2 | 3 | Sample created to support an article explanation [Learn Android RecyclerView - Spanish](https://erikjhordan-rey.github.io/blog/2015/10/04/ANDROID-recyclerview.html) 4 | 5 | # Features 6 | 7 | * **LayoutManagers** 8 | * **ItemDecorators** 9 | * **RecyclerView.Adapter** 10 | * **RecyclerView.ItemDecoration** 11 | * **ItemTypes** 12 | * **MVP design pattern** 13 | * **Responsive design techniques** 14 | 15 | 16 | # Demo 17 | ![](./art/Telecine_2015-10-18-21-56-43.gif) 18 | 19 | 20 | # Bonus 21 | 22 | #### RecyclerView ConcatAdapter 23 | 24 | The main goal is to practice RecyclerView ConcatAdapter a new RecyclerView Adapter that can combine multiple adapters linearly. 25 | 26 | 27 | 28 | [Source Code](https://github.com/erikjhordan-rey/RecyclerView-ConcatAdapter) 29 | 30 | 31 | Do you want to contribute? 32 | -------------------------- 33 | 34 | Feel free to report or add any useful feature. 35 | 36 | Developed By 37 | ------------ 38 | 39 | * Erik Jhordan Rey - 40 | 41 | License 42 | ------- 43 | 44 | Copyright 2015 Erik Jhordan Rey 45 | 46 | Licensed under the Apache License, Version 2.0 (the "License"); 47 | you may not use this file except in compliance with the License. 48 | You may obtain a copy of the License at 49 | 50 | http://www.apache.org/licenses/LICENSE-2.0 51 | 52 | Unless required by applicable law or agreed to in writing, software 53 | distributed under the License is distributed on an "AS IS" BASIS, 54 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 55 | See the License for the specific language governing permissions and 56 | limitations under the License. 57 | 58 | 59 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | 6 | defaultConfig { 7 | applicationId "io.github.erikjhordanrey.recyclerview_sample" 8 | minSdkVersion 17 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | 20 | compileOptions { 21 | sourceCompatibility JavaVersion.VERSION_1_8 22 | targetCompatibility JavaVersion.VERSION_1_8 23 | } 24 | 25 | buildFeatures { 26 | viewBinding = true 27 | } 28 | } 29 | 30 | dependencies { 31 | 32 | implementation 'androidx.appcompat:appcompat:1.1.0' 33 | implementation 'androidx.recyclerview:recyclerview:1.1.0' 34 | implementation 'androidx.cardview:cardview:1.0.0' 35 | implementation 'com.google.android.material:material:1.1.0' 36 | 37 | implementation 'com.jakewharton:butterknife:10.1.0' 38 | annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0' 39 | } 40 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Applications/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.activity; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.Bundle; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import androidx.annotation.NonNull; 9 | import androidx.appcompat.app.ActionBarDrawerToggle; 10 | import androidx.appcompat.app.AppCompatActivity; 11 | import androidx.core.view.GravityCompat; 12 | import androidx.fragment.app.Fragment; 13 | import com.google.android.material.navigation.NavigationView; 14 | import io.github.erikjhordanrey.recyclerview_sample.R; 15 | import io.github.erikjhordanrey.recyclerview_sample.databinding.ActivityMainBinding; 16 | import io.github.erikjhordanrey.recyclerview_sample.drawer.DrawerPresenterImpl; 17 | 18 | public class MainActivity extends AppCompatActivity implements DrawerPresenterImpl.DrawerView, NavigationView.OnNavigationItemSelectedListener { 19 | 20 | private ActivityMainBinding binding; 21 | private DrawerPresenterImpl drawerPresenter; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | binding = ActivityMainBinding.inflate(getLayoutInflater()); 27 | setContentView(binding.getRoot()); 28 | setupViews(); 29 | drawerPresenter = new DrawerPresenterImpl(this); 30 | binding.navView.getMenu().performIdentifierAction(R.id.nav_linear_v, 0); 31 | } 32 | 33 | @Override 34 | public boolean onCreateOptionsMenu(Menu menu) { 35 | getMenuInflater().inflate(R.menu.main, menu); 36 | return true; 37 | } 38 | 39 | @Override 40 | public boolean onOptionsItemSelected(MenuItem item) { 41 | int id = item.getItemId(); 42 | if (id == R.id.action_settings) 43 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://erikjhordan-rey.github.io/blog/2015/10/04/ANDROID-recyclerview.html"))); 44 | 45 | return super.onOptionsItemSelected(item); 46 | } 47 | 48 | @Override 49 | public void onBackPressed() { 50 | setBackPressed(); 51 | } 52 | 53 | @Override 54 | public boolean onNavigationItemSelected(@NonNull MenuItem item) { 55 | drawerPresenter.navigationItemSelected(item, binding.drawerLayout); 56 | return true; 57 | } 58 | 59 | @Override 60 | public void navigateUsingTo(Fragment fragment) { 61 | getSupportFragmentManager().beginTransaction() 62 | .replace(R.id.container, fragment).commit(); 63 | } 64 | 65 | private void setupViews() { 66 | setSupportActionBar(binding.contentMain.toolbar); 67 | setUpActionBarDrawerToggle(); 68 | binding.navView.setNavigationItemSelectedListener(this); 69 | } 70 | 71 | private void setUpActionBarDrawerToggle() { 72 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 73 | this, 74 | binding.drawerLayout, 75 | binding.contentMain.toolbar, 76 | R.string.navigation_drawer_open, 77 | R.string.navigation_drawer_close); 78 | binding.drawerLayout.addDrawerListener(toggle); 79 | toggle.syncState(); 80 | } 81 | 82 | private void setBackPressed() { 83 | if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) 84 | binding.drawerLayout.closeDrawer(GravityCompat.START); 85 | else 86 | super.onBackPressed(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/adapter/AdapterExample.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.adapter; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.recyclerview.widget.RecyclerView; 11 | import io.github.erikjhordanrey.recyclerview_sample.R; 12 | import java.util.ArrayList; 13 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 14 | import io.github.erikjhordanrey.recyclerview_sample.presenter.RecyclerItemClickListener; 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | 18 | public class AdapterExample extends RecyclerView.Adapter { 19 | 20 | private ArrayList pictureArrayList; 21 | private int itemLayout; 22 | private RecyclerItemClickListener recyclerItemClickListener; 23 | 24 | public void setRecyclerItemClickListener(RecyclerItemClickListener recyclerItemClickListener) { 25 | this.recyclerItemClickListener = recyclerItemClickListener; 26 | } 27 | 28 | public AdapterExample(ArrayList pictureArrayList, int itemLayout) { 29 | this.pictureArrayList = pictureArrayList; 30 | this.itemLayout = itemLayout; 31 | } 32 | 33 | @NonNull 34 | @Override 35 | public ExampleHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 36 | View view = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false); 37 | return new ExampleHolder(view); 38 | } 39 | 40 | @Override 41 | public void onBindViewHolder(@NonNull final ExampleHolder holder, final int position) { 42 | final Picture picture = pictureArrayList.get(position); 43 | holder.title.setText(picture.getName()); 44 | holder.imageView.setImageResource(picture.getImage()); 45 | } 46 | 47 | 48 | @Override 49 | public int getItemCount() { 50 | return pictureArrayList.size(); 51 | } 52 | 53 | 54 | public class ExampleHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 55 | @BindView(R.id.txt_title) 56 | TextView title; 57 | @BindView(R.id.imageView) 58 | ImageView imageView; 59 | 60 | ExampleHolder(View itemView) { 61 | super(itemView); 62 | ButterKnife.bind(this, itemView); 63 | itemView.setOnClickListener(this); 64 | 65 | } 66 | 67 | @Override 68 | public void onClick(View view) { 69 | if (recyclerItemClickListener != null) 70 | recyclerItemClickListener.onItemClickListener(getAdapterPosition()); 71 | } 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/adapter/AdapterExampleTypes.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.adapter; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import androidx.annotation.NonNull; 10 | import androidx.recyclerview.widget.RecyclerView; 11 | import io.github.erikjhordanrey.recyclerview_sample.R; 12 | import java.util.ArrayList; 13 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 14 | import io.github.erikjhordanrey.recyclerview_sample.presenter.RecyclerItemClickListener; 15 | import butterknife.BindView; 16 | import butterknife.ButterKnife; 17 | 18 | public class AdapterExampleTypes extends RecyclerView.Adapter { 19 | 20 | private ArrayList pictureArrayList; 21 | private int itemLayout; 22 | 23 | private static final int TYPE_ITEM_1 = 0; 24 | private static final int TYPE_ITEM_2 = 1; 25 | private static final int TYPE_ITEM_3 = 2; 26 | private RecyclerItemClickListener recyclerItemClickListener; 27 | 28 | public void setRecyclerItemClickListener(RecyclerItemClickListener recyclerItemClickListener) { 29 | this.recyclerItemClickListener = recyclerItemClickListener; 30 | } 31 | 32 | public AdapterExampleTypes(ArrayList pictureArrayList, int itemLayout) { 33 | this.pictureArrayList = pictureArrayList; 34 | this.itemLayout = itemLayout; 35 | } 36 | 37 | @NonNull 38 | @Override 39 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 40 | 41 | RecyclerView.ViewHolder viewHolderType = null; 42 | LayoutInflater inflater = LayoutInflater.from(parent.getContext()); 43 | 44 | switch (viewType) { 45 | case TYPE_ITEM_1: 46 | View view = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false); 47 | viewHolderType = new ExampleHolder(view); 48 | break; 49 | case TYPE_ITEM_2: 50 | viewHolderType = new ExampleHolderTypeTwo(inflater.inflate(R.layout.item_type_four, parent, false)); 51 | break; 52 | case TYPE_ITEM_3: 53 | viewHolderType = new ExampleHolderTypeThree(inflater.inflate(R.layout.item_type_five, parent, false)); 54 | break; 55 | } 56 | 57 | assert viewHolderType != null; 58 | return viewHolderType; 59 | } 60 | 61 | @Override 62 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) { 63 | Picture picture = pictureArrayList.get(position); 64 | 65 | 66 | switch (holder.getItemViewType()) { 67 | case TYPE_ITEM_1: 68 | setTypeItem1(((ExampleHolder) holder), picture); 69 | break; 70 | 71 | case TYPE_ITEM_2: 72 | setTypeItem2(((ExampleHolderTypeTwo) holder), picture); 73 | break; 74 | 75 | case TYPE_ITEM_3: 76 | setTypeItem3(((ExampleHolderTypeThree) holder), picture); 77 | break; 78 | 79 | } 80 | 81 | holder.itemView.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View view) { 84 | if (recyclerItemClickListener != null) 85 | recyclerItemClickListener.onItemClickListener(position); 86 | } 87 | }); 88 | 89 | 90 | } 91 | 92 | @Override 93 | public int getItemCount() { 94 | return pictureArrayList.size(); 95 | } 96 | 97 | 98 | @Override 99 | public int getItemViewType(int position) { 100 | 101 | if (position % 3 == 0) 102 | return TYPE_ITEM_2; 103 | else if (position % 2 == 0) 104 | return TYPE_ITEM_3; 105 | 106 | 107 | return TYPE_ITEM_1; 108 | } 109 | 110 | 111 | public static class ExampleHolder extends RecyclerView.ViewHolder { 112 | 113 | @BindView(R.id.txt_title) 114 | TextView title; 115 | @BindView(R.id.imageView) 116 | ImageView imageView; 117 | View view; 118 | 119 | ExampleHolder(View itemView) { 120 | super(itemView); 121 | view = itemView; 122 | ButterKnife.bind(this, itemView); 123 | } 124 | 125 | } 126 | 127 | public static class ExampleHolderTypeTwo extends RecyclerView.ViewHolder { 128 | 129 | @BindView(R.id.txt_title) 130 | TextView title; 131 | @BindView(R.id.imageView) 132 | ImageView imageView; 133 | View view; 134 | 135 | ExampleHolderTypeTwo(View itemView) { 136 | super(itemView); 137 | view = itemView; 138 | ButterKnife.bind(this, itemView); 139 | } 140 | 141 | } 142 | 143 | public static class ExampleHolderTypeThree extends RecyclerView.ViewHolder { 144 | 145 | @BindView(R.id.txt_title) 146 | TextView title; 147 | @BindView(R.id.imageView) 148 | ImageView imageView; 149 | View view; 150 | 151 | ExampleHolderTypeThree(View itemView) { 152 | super(itemView); 153 | view = itemView; 154 | ButterKnife.bind(this, itemView); 155 | } 156 | 157 | } 158 | 159 | private void setTypeItem1(ExampleHolder holder, Picture picture) { 160 | holder.title.setText(picture.getName()); 161 | holder.imageView.setImageResource(picture.getImage()); 162 | } 163 | 164 | private void setTypeItem2(ExampleHolderTypeTwo holder, Picture picture) { 165 | holder.title.setText(picture.getName()); 166 | holder.imageView.setImageResource(picture.getImage()); 167 | } 168 | 169 | private void setTypeItem3(ExampleHolderTypeThree holder, Picture picture) { 170 | holder.title.setText(picture.getName()); 171 | holder.imageView.setImageResource(picture.getImage()); 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/drawer/DrawerInteractor.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.drawer; 2 | 3 | import android.view.MenuItem; 4 | 5 | import androidx.drawerlayout.widget.DrawerLayout; 6 | 7 | public interface DrawerInteractor { 8 | void navigateTo(MenuItem item, DrawerLayout drawerLayout, DrawerListener listener); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/drawer/DrawerInteractorImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.drawer; 2 | 3 | import android.view.MenuItem; 4 | import androidx.core.view.GravityCompat; 5 | import androidx.drawerlayout.widget.DrawerLayout; 6 | import io.github.erikjhordanrey.recyclerview_sample.R; 7 | import io.github.erikjhordanrey.recyclerview_sample.fragment.GridHorizontalFragment; 8 | import io.github.erikjhordanrey.recyclerview_sample.fragment.GridQualifiersVerticalFragment; 9 | import io.github.erikjhordanrey.recyclerview_sample.fragment.GridSpanSizeVerticalFragment; 10 | import io.github.erikjhordanrey.recyclerview_sample.fragment.GridVerticalFragment; 11 | import io.github.erikjhordanrey.recyclerview_sample.fragment.ItemTypesVerticalFragment; 12 | import io.github.erikjhordanrey.recyclerview_sample.fragment.LinearHorizontalFragment; 13 | import io.github.erikjhordanrey.recyclerview_sample.fragment.LinearVerticalFragment; 14 | import io.github.erikjhordanrey.recyclerview_sample.fragment.ResponsiveLinearVerticalFragment; 15 | import io.github.erikjhordanrey.recyclerview_sample.fragment.StaggeredHorizontalFragment; 16 | import io.github.erikjhordanrey.recyclerview_sample.fragment.StaggeredVerticalFragment; 17 | 18 | public class DrawerInteractorImpl implements DrawerInteractor { 19 | 20 | @Override 21 | public void navigateTo(MenuItem item, DrawerLayout drawerLayout, DrawerListener listener) { 22 | 23 | switch (item.getItemId()) { 24 | case R.id.nav_linear_v: 25 | listener.replaceFragment(LinearVerticalFragment.newInstance()); 26 | break; 27 | case R.id.nav_linear_h: 28 | listener.replaceFragment(LinearHorizontalFragment.newInstance()); 29 | break; 30 | case R.id.nav_grid_v: 31 | listener.replaceFragment(GridVerticalFragment.newInstance()); 32 | break; 33 | case R.id.nav_grid_h: 34 | listener.replaceFragment(GridHorizontalFragment.newInstance()); 35 | break; 36 | case R.id.nav_grid_span: 37 | listener.replaceFragment(GridSpanSizeVerticalFragment.newInstance()); 38 | break; 39 | case R.id.nav_staggered_v: 40 | listener.replaceFragment(StaggeredVerticalFragment.newInstance()); 41 | break; 42 | case R.id.nav_staggered_h: 43 | listener.replaceFragment(StaggeredHorizontalFragment.newInstance()); 44 | break; 45 | 46 | case R.id.nav_item_types: 47 | listener.replaceFragment(ItemTypesVerticalFragment.newInstance()); 48 | break; 49 | case R.id.nav_item_responsive: 50 | listener.replaceFragment(ResponsiveLinearVerticalFragment.newInstance()); 51 | break; 52 | case R.id.nav_item_qualifiers: 53 | listener.replaceFragment(GridQualifiersVerticalFragment.newInstance()); 54 | break; 55 | 56 | } 57 | drawerLayout.closeDrawer(GravityCompat.START); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/drawer/DrawerListener.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.drawer; 2 | 3 | import androidx.fragment.app.Fragment; 4 | 5 | public interface DrawerListener { 6 | void replaceFragment(Fragment fragment); 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/drawer/DrawerPresenter.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.drawer; 2 | 3 | import android.view.MenuItem; 4 | 5 | import androidx.drawerlayout.widget.DrawerLayout; 6 | 7 | public interface DrawerPresenter { 8 | void navigationItemSelected(MenuItem item, DrawerLayout drawerLayout); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/drawer/DrawerPresenterImpl.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.drawer; 2 | 3 | import android.view.MenuItem; 4 | 5 | import androidx.drawerlayout.widget.DrawerLayout; 6 | import androidx.fragment.app.Fragment; 7 | 8 | public class DrawerPresenterImpl implements DrawerPresenter, DrawerListener { 9 | 10 | private final DrawerInteractorImpl drawerInteractor; 11 | private final DrawerView drawerView; 12 | 13 | public DrawerPresenterImpl(DrawerView drawerView) { 14 | this.drawerView = drawerView; 15 | drawerInteractor = new DrawerInteractorImpl(); 16 | } 17 | 18 | @Override 19 | public void navigationItemSelected(MenuItem item, DrawerLayout drawerLayout) { 20 | drawerInteractor.navigateTo(item, drawerLayout, this); 21 | } 22 | 23 | @Override 24 | public void replaceFragment(Fragment fragment) { 25 | drawerView.navigateUsingTo(fragment); 26 | } 27 | 28 | public interface DrawerView { 29 | void navigateUsingTo(Fragment fragment); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.Toast; 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import androidx.fragment.app.Fragment; 11 | import androidx.recyclerview.widget.DefaultItemAnimator; 12 | import androidx.recyclerview.widget.RecyclerView; 13 | import io.github.erikjhordanrey.recyclerview_sample.R; 14 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 15 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExampleTypes; 16 | import io.github.erikjhordanrey.recyclerview_sample.databinding.FragmentBaseBinding; 17 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 18 | import io.github.erikjhordanrey.recyclerview_sample.presenter.PicturePresenter; 19 | import io.github.erikjhordanrey.recyclerview_sample.presenter.RecyclerItemClickListener; 20 | import io.github.erikjhordanrey.recyclerview_sample.view.PictureMvpView; 21 | import io.github.erikjhordanrey.recyclerview_sample.widget.ItemOffsetDecoration; 22 | import java.util.ArrayList; 23 | 24 | public abstract class BaseFragment extends Fragment implements PictureMvpView, RecyclerItemClickListener { 25 | 26 | private PicturePresenter picturePresenter; 27 | RecyclerView.Adapter adapter; 28 | 29 | private FragmentBaseBinding binding; 30 | 31 | @Nullable 32 | @Override 33 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 34 | binding = FragmentBaseBinding.inflate(inflater, container, false); 35 | return binding.getRoot(); 36 | } 37 | 38 | @Override 39 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 40 | super.onViewCreated(view, savedInstanceState); 41 | picturePresenter = new PicturePresenter(); 42 | picturePresenter.attachedView(this); 43 | setupRecyclerView(); 44 | } 45 | 46 | @Override 47 | public void onResume() { 48 | super.onResume(); 49 | picturePresenter.onResume(); 50 | } 51 | 52 | @Override 53 | public void setItems(ArrayList pictureList) { 54 | adapter = getAdapter(pictureList); 55 | binding.recyclerView.setAdapter(adapter); 56 | 57 | if (adapter instanceof AdapterExample) 58 | ((AdapterExample) adapter).setRecyclerItemClickListener(this); 59 | else if (adapter instanceof AdapterExampleTypes) 60 | ((AdapterExampleTypes) adapter).setRecyclerItemClickListener(this); 61 | 62 | } 63 | 64 | @Override 65 | public void showProgress() { 66 | binding.progressBar.setVisibility(View.VISIBLE); 67 | binding.recyclerView.setVisibility(View.INVISIBLE); 68 | } 69 | 70 | @Override 71 | public void hideProgress() { 72 | binding.progressBar.setVisibility(View.INVISIBLE); 73 | binding.recyclerView.setVisibility(View.VISIBLE); 74 | } 75 | 76 | @Override 77 | public void showMessage(String message) { 78 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); 79 | } 80 | 81 | @Override 82 | public void onDestroy() { 83 | picturePresenter.detachView(); 84 | super.onDestroy(); 85 | } 86 | 87 | @Override 88 | public void onItemClickListener(int position) { 89 | picturePresenter.onItemSelected(position); 90 | } 91 | 92 | private void setupRecyclerView() { 93 | 94 | if (getLayoutManager() != null) 95 | binding.recyclerView.setLayoutManager(getLayoutManager()); 96 | 97 | binding.recyclerView.addItemDecoration(new ItemOffsetDecoration(binding.recyclerView.getContext(), R.dimen.item_decoration)); 98 | binding.recyclerView.setItemAnimator(new DefaultItemAnimator()); 99 | 100 | } 101 | 102 | protected abstract RecyclerView.LayoutManager getLayoutManager(); 103 | 104 | protected abstract RecyclerView.Adapter getAdapter(ArrayList pictureList); 105 | 106 | //protected abstract RecyclerView.ItemDecoration getItemDecoration(); 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/GridHorizontalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.GridLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class GridHorizontalFragment extends BaseFragment { 11 | 12 | public static GridHorizontalFragment newInstance() { 13 | return new GridHorizontalFragment(); 14 | } 15 | 16 | @Override protected RecyclerView.LayoutManager getLayoutManager() { 17 | return getGridLayoutManager(); 18 | } 19 | 20 | @Override protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 21 | return new AdapterExample(pictureList,R.layout.item_type_two); 22 | } 23 | 24 | private GridLayoutManager getGridLayoutManager() { 25 | return new GridLayoutManager( 26 | getActivity(), 27 | 2, 28 | GridLayoutManager.HORIZONTAL, 29 | false); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/GridQualifiersVerticalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.GridLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class GridQualifiersVerticalFragment extends BaseFragment { 11 | 12 | public static GridQualifiersVerticalFragment newInstance() { 13 | return new GridQualifiersVerticalFragment(); 14 | } 15 | 16 | @Override protected RecyclerView.LayoutManager getLayoutManager() { 17 | return getGridLayoutManager(); 18 | } 19 | 20 | @Override protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 21 | return new AdapterExample(pictureList, R.layout.item_type_two); 22 | } 23 | 24 | private GridLayoutManager getGridLayoutManager() { 25 | 26 | final int spans = getResources().getInteger(R.integer.number_of_columns); 27 | return new GridLayoutManager( 28 | getActivity(), 29 | spans, 30 | RecyclerView.VERTICAL, 31 | false); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/GridSpanSizeVerticalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.GridLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class GridSpanSizeVerticalFragment extends BaseFragment { 11 | 12 | public static GridSpanSizeVerticalFragment newInstance() { 13 | return new GridSpanSizeVerticalFragment(); 14 | } 15 | 16 | @Override protected RecyclerView.LayoutManager getLayoutManager() { 17 | return getGridLayoutManager(); 18 | } 19 | 20 | 21 | @Override protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 22 | return new AdapterExample(pictureList,R.layout.item_type_two); 23 | } 24 | 25 | private GridLayoutManager getGridLayoutManager() { 26 | GridLayoutManager gridLayoutManager = new GridLayoutManager( 27 | getActivity(), 28 | 2, 29 | RecyclerView.VERTICAL, 30 | false); 31 | 32 | gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 33 | @Override 34 | public int getSpanSize(int position) { 35 | //stagger rows custom 36 | return (position % 3 == 0 ? 2 : 1); 37 | } 38 | }); 39 | return gridLayoutManager; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/GridVerticalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.GridLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class GridVerticalFragment extends BaseFragment { 11 | 12 | public static GridVerticalFragment newInstance() { 13 | return new GridVerticalFragment(); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | return getGridLayoutManager(); 19 | } 20 | 21 | @Override 22 | protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 23 | return new AdapterExample(pictureList, R.layout.item_type_two); 24 | } 25 | 26 | private GridLayoutManager getGridLayoutManager() { 27 | return new GridLayoutManager( 28 | getActivity(), 29 | 2, 30 | RecyclerView.VERTICAL, 31 | false); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/ItemTypesVerticalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.GridLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExampleTypes; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class ItemTypesVerticalFragment extends BaseFragment { 11 | 12 | public static ItemTypesVerticalFragment newInstance() { 13 | return new ItemTypesVerticalFragment(); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | return getGridLayoutManager(); 19 | } 20 | 21 | @Override 22 | protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 23 | return new AdapterExampleTypes(pictureList, R.layout.item_type_two); 24 | } 25 | 26 | 27 | private GridLayoutManager getGridLayoutManager() { 28 | return new GridLayoutManager( 29 | getActivity(), 30 | 2, 31 | RecyclerView.VERTICAL, 32 | false); 33 | 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/LinearHorizontalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.LinearLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class LinearHorizontalFragment extends BaseFragment { 11 | 12 | public static LinearHorizontalFragment newInstance() { 13 | return new LinearHorizontalFragment(); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | return getLinearLayoutManager(); 19 | } 20 | 21 | @Override 22 | protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 23 | return new AdapterExample(pictureList, R.layout.item_type_two); 24 | } 25 | 26 | private LinearLayoutManager getLinearLayoutManager() { 27 | return new LinearLayoutManager( 28 | getActivity(), 29 | LinearLayoutManager.HORIZONTAL, 30 | false); 31 | 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/LinearVerticalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.LinearLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class LinearVerticalFragment extends BaseFragment { 11 | 12 | public static LinearVerticalFragment newInstance() { 13 | return new LinearVerticalFragment(); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | return getLinearLayoutManager(); 19 | } 20 | 21 | @Override 22 | protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 23 | return new AdapterExample(pictureList, R.layout.item_type_one); 24 | } 25 | 26 | private LinearLayoutManager getLinearLayoutManager() { 27 | return new LinearLayoutManager( 28 | getActivity(), 29 | RecyclerView.VERTICAL, 30 | false); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/ResponsiveLinearVerticalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.LinearLayoutManager; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class ResponsiveLinearVerticalFragment extends BaseFragment { 11 | 12 | public static ResponsiveLinearVerticalFragment newInstance() { 13 | return new ResponsiveLinearVerticalFragment(); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | return null; 19 | } 20 | 21 | 22 | @Override 23 | protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 24 | return new AdapterExample(pictureList, R.layout.item_type_one); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/StaggeredHorizontalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.RecyclerView; 4 | import androidx.recyclerview.widget.StaggeredGridLayoutManager; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class StaggeredHorizontalFragment extends BaseFragment { 11 | 12 | public static StaggeredHorizontalFragment newInstance() { 13 | return new StaggeredHorizontalFragment(); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | return getStaggeredLayoutManager(); 19 | } 20 | 21 | @Override 22 | protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 23 | return new AdapterExample(pictureList, R.layout.item_type_three); 24 | } 25 | 26 | private StaggeredGridLayoutManager getStaggeredLayoutManager() { 27 | 28 | StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager( 29 | 2, //number of grid columns 30 | StaggeredGridLayoutManager.HORIZONTAL); 31 | //Sets the gap handling strategy for StaggeredGridLayoutManager 32 | staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); 33 | 34 | return staggeredGridLayoutManager; 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/fragment/StaggeredVerticalFragment.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.fragment; 2 | 3 | import androidx.recyclerview.widget.RecyclerView; 4 | import androidx.recyclerview.widget.StaggeredGridLayoutManager; 5 | import io.github.erikjhordanrey.recyclerview_sample.R; 6 | import java.util.ArrayList; 7 | import io.github.erikjhordanrey.recyclerview_sample.adapter.AdapterExample; 8 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 9 | 10 | public class StaggeredVerticalFragment extends BaseFragment { 11 | 12 | public static StaggeredVerticalFragment newInstance() { 13 | return new StaggeredVerticalFragment(); 14 | } 15 | 16 | @Override 17 | protected RecyclerView.LayoutManager getLayoutManager() { 18 | return getStaggeredLayoutManager(); 19 | } 20 | 21 | @Override 22 | protected RecyclerView.Adapter getAdapter(ArrayList pictureList) { 23 | return new AdapterExample(pictureList, R.layout.item_type_three); 24 | } 25 | 26 | private StaggeredGridLayoutManager getStaggeredLayoutManager() { 27 | 28 | StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager( 29 | 2, //number of grid columns 30 | StaggeredGridLayoutManager.VERTICAL); 31 | //Sets the gap handling strategy for StaggeredGridLayoutManager 32 | staggeredGridLayoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); 33 | return staggeredGridLayoutManager; 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/model/Interactor.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.model; 2 | 3 | public interface Interactor { 4 | 5 | void loadItems(LoaderListener loaderListener); 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/model/LoaderListener.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.model; 2 | 3 | import java.util.ArrayList; 4 | 5 | public interface LoaderListener { 6 | 7 | void onFinished(ArrayList pictureList); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/model/Picture.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.model; 2 | 3 | public class Picture { 4 | 5 | private int image; 6 | private String name; 7 | 8 | public Picture(String name, int image) { 9 | this.name = name; 10 | this.image = image; 11 | } 12 | 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public int getImage() { 19 | return image; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/model/PictureInteractor.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.model; 2 | 3 | import android.os.Handler; 4 | import io.github.erikjhordanrey.recyclerview_sample.R; 5 | import java.util.ArrayList; 6 | 7 | public class PictureInteractor implements Interactor { 8 | 9 | private final static String[] pictureNames = { 10 | "Rocket in the universe", 11 | "A scene in London", 12 | "Moon over mountains", 13 | "A simple moon", 14 | "Sun and volcano", 15 | "A collection of mountains", 16 | "River between mountains", 17 | "Some pine trees", 18 | "On Small Town", 19 | "Volcanos reflection" 20 | }; 21 | 22 | private final static int pictureImages[] = { 23 | R.drawable.cohete_flat, 24 | R.drawable.london_flat, 25 | R.drawable.material_flat, 26 | R.drawable.moon_flat, 27 | R.drawable.mountain_flat, 28 | R.drawable.mountain_mo_flat, 29 | R.drawable.moutain_go_flat, 30 | R.drawable.pine_flat, 31 | R.drawable.towers_flat, 32 | R.drawable.vulcan_flat 33 | }; 34 | 35 | @Override 36 | public void loadItems(final LoaderListener loaderListener) { 37 | 38 | new Handler().postDelayed(new Runnable() { 39 | @Override 40 | public void run() { 41 | loaderListener.onFinished(createCollectionPictures()); 42 | } 43 | }, 2000); 44 | } 45 | 46 | private ArrayList createCollectionPictures() { 47 | ArrayList pictures = new ArrayList<>(); 48 | for (int i = 0; i < 10; i++) { 49 | Picture picture = new Picture(pictureNames[i], pictureImages[i]); 50 | pictures.add(picture); 51 | } 52 | return pictures; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/presenter/PicturePresenter.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.presenter; 2 | 3 | import java.util.ArrayList; 4 | 5 | import io.github.erikjhordanrey.recyclerview_sample.model.LoaderListener; 6 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 7 | import io.github.erikjhordanrey.recyclerview_sample.model.PictureInteractor; 8 | import io.github.erikjhordanrey.recyclerview_sample.view.PictureMvpView; 9 | 10 | public class PicturePresenter implements Presenter, LoaderListener { 11 | 12 | private PictureMvpView pictureMvpView; 13 | private final PictureInteractor pictureInteractor; 14 | 15 | public PicturePresenter() { 16 | pictureInteractor = new PictureInteractor(); 17 | } 18 | 19 | @Override 20 | public void attachedView(PictureMvpView view) { 21 | if (view == null) 22 | throw new IllegalArgumentException("You can't set a null view"); 23 | pictureMvpView = view; 24 | } 25 | 26 | @Override public void detachView() { 27 | pictureMvpView = null; 28 | } 29 | 30 | @Override public void onResume() { 31 | pictureMvpView.showProgress(); 32 | pictureInteractor.loadItems(this); 33 | } 34 | 35 | @Override public void onItemSelected(int position) { 36 | pictureMvpView.showMessage(Integer.toString(position)); 37 | 38 | } 39 | 40 | @Override public void onFinished(ArrayList pictureList) { 41 | pictureMvpView.setItems(pictureList); 42 | pictureMvpView.hideProgress(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/presenter/Presenter.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.presenter; 2 | 3 | public interface Presenter { 4 | 5 | void attachedView(V view); 6 | 7 | void detachView(); 8 | 9 | void onResume(); 10 | 11 | void onItemSelected(int position); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/presenter/RecyclerItemClickListener.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.presenter; 2 | 3 | public interface RecyclerItemClickListener { 4 | void onItemClickListener(int position); 5 | } 6 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/view/PictureMvpView.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.view; 2 | 3 | import java.util.ArrayList; 4 | 5 | import io.github.erikjhordanrey.recyclerview_sample.model.Picture; 6 | 7 | public interface PictureMvpView { 8 | 9 | void setItems(ArrayList pictureList); 10 | 11 | void showProgress(); 12 | 13 | void hideProgress(); 14 | 15 | void showMessage(String message); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/widget/DividerDecoration.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | import android.graphics.drawable.Drawable; 8 | import android.view.View; 9 | import androidx.annotation.NonNull; 10 | import androidx.recyclerview.widget.RecyclerView; 11 | import io.github.erikjhordanrey.recyclerview_sample.R; 12 | 13 | public class DividerDecoration extends RecyclerView.ItemDecoration { 14 | 15 | private static final int[] ATTRS = { android.R.attr.listDivider }; 16 | 17 | private Drawable mDivider; 18 | private int mInsets; 19 | 20 | public DividerDecoration(Context context) { 21 | TypedArray a = context.obtainStyledAttributes(ATTRS); 22 | mDivider = a.getDrawable(0); 23 | a.recycle(); 24 | 25 | mInsets = context.getResources().getDimensionPixelSize(R.dimen.card_insets); 26 | } 27 | 28 | @Override 29 | public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { 30 | drawVertical(c, parent); 31 | } 32 | 33 | /** Draw dividers underneath each child view */ 34 | private void drawVertical(Canvas c, RecyclerView parent) { 35 | final int left = parent.getPaddingLeft(); 36 | final int right = parent.getWidth() - parent.getPaddingRight(); 37 | 38 | final int childCount = parent.getChildCount(); 39 | for (int i = 0; i < childCount; i++) { 40 | final View child = parent.getChildAt(i); 41 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 42 | .getLayoutParams(); 43 | final int top = child.getBottom() + params.bottomMargin + mInsets; 44 | final int bottom = top + mDivider.getIntrinsicHeight(); 45 | mDivider.setBounds(left, top, right, bottom); 46 | mDivider.draw(c); 47 | } 48 | } 49 | 50 | @Override 51 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 52 | //We can supply forced insets for each item view here in the Rect 53 | outRect.set(mInsets, mInsets, mInsets, mInsets); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/widget/ItemOffsetDecoration.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.view.View; 6 | 7 | import androidx.annotation.DimenRes; 8 | import androidx.annotation.NonNull; 9 | import androidx.recyclerview.widget.RecyclerView; 10 | 11 | public class ItemOffsetDecoration extends RecyclerView.ItemDecoration { 12 | 13 | private int mItemOffset; 14 | 15 | private ItemOffsetDecoration(int itemOffset) { 16 | mItemOffset = itemOffset; 17 | } 18 | 19 | public ItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) { 20 | this(context.getResources().getDimensionPixelSize(itemOffsetId)); 21 | } 22 | 23 | @Override 24 | public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { 25 | super.getItemOffsets(outRect, view, parent, state); 26 | outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/erikjhordanrey/recyclerview_sample/widget/ResponsiveRecyclerView.java: -------------------------------------------------------------------------------- 1 | package io.github.erikjhordanrey.recyclerview_sample.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | 7 | import androidx.recyclerview.widget.GridLayoutManager; 8 | import androidx.recyclerview.widget.RecyclerView; 9 | 10 | public class ResponsiveRecyclerView extends RecyclerView { 11 | 12 | private GridLayoutManager manager; 13 | private int columnWidth = -1; 14 | 15 | public ResponsiveRecyclerView(Context context) { 16 | super(context); 17 | initialize(context, null); 18 | } 19 | 20 | public ResponsiveRecyclerView(Context context, AttributeSet attrs) { 21 | super(context, attrs); 22 | initialize(context, attrs); 23 | } 24 | 25 | public ResponsiveRecyclerView(Context context, AttributeSet attrs, int defStyle) { 26 | super(context, attrs, defStyle); 27 | initialize(context, attrs); 28 | } 29 | 30 | private void initialize(Context context, AttributeSet attrs) { 31 | if (attrs != null) { 32 | int[] attrsArray = {android.R.attr.columnWidth}; 33 | TypedArray array = context.obtainStyledAttributes(attrs, attrsArray); 34 | columnWidth = array.getDimensionPixelSize(0, -1); 35 | array.recycle(); 36 | } 37 | manager = new GridLayoutManager(getContext(), 1); 38 | setLayoutManager(manager); 39 | } 40 | 41 | @Override 42 | protected void onMeasure(int widthSpec, int heightSpec) { 43 | super.onMeasure(widthSpec, heightSpec); 44 | if (columnWidth > 0) { 45 | int spanCount = Math.max(1, getMeasuredWidth() / columnWidth); 46 | manager.setSpanCount(spanCount); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_action_favorite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-hdpi/ic_action_action_favorite.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_action_turned_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-hdpi/ic_action_action_turned_in.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_social_share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-hdpi/ic_action_social_share.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-hdpi/ic_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-hdpi/ic_menu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_action_favorite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-mdpi/ic_action_action_favorite.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_action_turned_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-mdpi/ic_action_action_turned_in.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_social_share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-mdpi/ic_action_social_share.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-mdpi/ic_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-mdpi/ic_menu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/cohete_flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/cohete_flat.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/london_flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/london_flat.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/material_flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/material_flat.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/moon_flat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/moon_flat.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/mountain_flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/mountain_flat.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/mountain_mo_flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/mountain_mo_flat.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/moutain_go_flat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/moutain_go_flat.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/pine_flat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/pine_flat.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/towers_flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/towers_flat.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/vulcan_flat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-nodpi/vulcan_flat.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/item_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/shape_background_default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_action_favorite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xhdpi/ic_action_action_favorite.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_action_turned_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xhdpi/ic_action_action_turned_in.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_social_share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xhdpi/ic_action_social_share.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xhdpi/ic_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xhdpi/ic_menu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_action_favorite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxhdpi/ic_action_action_favorite.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_action_turned_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxhdpi/ic_action_action_turned_in.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_social_share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxhdpi/ic_action_social_share.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxhdpi/ic_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxhdpi/ic_menu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_action_action_favorite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxxhdpi/ic_action_action_favorite.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_action_action_turned_in.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxxhdpi/ic_action_action_turned_in.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_action_social_share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxxhdpi/ic_action_social_share.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxxhdpi/ic_github.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/drawable-xxxhdpi/ic_menu.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/item_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 19 | 20 | 21 | 22 | 23 | 24 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_base.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 15 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_responsive.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_type_five.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 16 | 22 | 23 | 24 | 28 | 29 | 30 | 40 | 41 | 54 | 55 | 69 | 70 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_type_four.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 17 | 18 | 25 | 26 | 37 | 38 | 39 | 42 | 43 | 51 | 52 | 61 | 62 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_type_one.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_type_three.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 20 | 21 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_type_two.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 13 | 14 | 21 | 22 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/nav_header_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 20 | 21 | 27 | 28 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_main_drawer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 12 | 15 | 16 | 19 | 20 | 23 | 26 | 29 | 30 | 33 | 34 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 5 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-sw600dp-land/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3 4 | -------------------------------------------------------------------------------- /app/src/main/res/values-sw600dp/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2 4 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | > 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #D81B60 4 | #AD1457 5 | #18FFFF 6 | #212121 7 | #727272 8 | #ffffff 9 | #FFF5F5F5 10 | #99BDBDBD 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 160dp 5 | 6 | 8dp 7 | 2dp 8 | 16dp 9 | 10 | 240dp 11 | 8dp 12 | 6dp 13 | 250dp 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | "RecyclerView-Examples " 3 | 4 | Open navigation drawer 5 | Close navigation drawer 6 | 7 | Settings 8 | Lorem ipsum dolor sit amet 9 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 17 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /art/Telecine_2015-10-18-21-56-43.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/art/Telecine_2015-10-18-21-56-43.gif -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:4.0.1' 8 | } 9 | } 10 | 11 | allprojects { 12 | repositories { 13 | google() 14 | jcenter() 15 | } 16 | } 17 | 18 | task clean(type: Delete) { 19 | delete rootProject.buildDir 20 | } 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.enableJetifier=true 20 | android.useAndroidX=true 21 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/erikjhordan-rey/RecyclerView-Examples/3d7e7ed0fe0c8b9895b608eaf2e448e5cee2a76b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jul 16 00:57:21 CDT 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------