├── .gitignore ├── NestedRecycler.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── libs │ ├── AmazonInsights-android-sdk-2.1.26.jar │ └── YouTubeAndroidPlayerApi.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── android │ │ └── msahakyan │ │ └── nestedrecycler │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── amazon.properties │ ├── java │ │ └── com │ │ │ └── android │ │ │ └── msahakyan │ │ │ └── nestedrecycler │ │ │ ├── PushService.java │ │ │ ├── activity │ │ │ ├── MainActivity.java │ │ │ ├── MovieDetailActivity.java │ │ │ └── TrailerActivity.java │ │ │ ├── adapter │ │ │ ├── BackdropPagerAdapter.java │ │ │ ├── ItemDetailPagerAdapter.java │ │ │ ├── MovieAdapter.java │ │ │ ├── RelatedMoviesAdapter.java │ │ │ ├── SmartFragmentStatePagerAdapter.java │ │ │ └── TrailerAdapter.java │ │ │ ├── application │ │ │ └── AppController.java │ │ │ ├── cache │ │ │ └── BitmapLruCache.java │ │ │ ├── common │ │ │ ├── BundleKey.java │ │ │ ├── DepthPageTransformer.java │ │ │ ├── Helper.java │ │ │ ├── HorizontalItemDecorator.java │ │ │ ├── ItemClickListener.java │ │ │ ├── PushNotification.java │ │ │ ├── VerticalItemDecorator.java │ │ │ ├── ViewAnimator.java │ │ │ ├── ZoomOutPageTransformer.java │ │ │ └── abtest │ │ │ │ └── ABTestConfig.java │ │ │ ├── config │ │ │ └── Config.java │ │ │ ├── fragment │ │ │ └── MovieDetailFragment.java │ │ │ ├── model │ │ │ ├── Backdrop.java │ │ │ ├── ImageListParser.java │ │ │ ├── Movie.java │ │ │ ├── MovieListParser.java │ │ │ ├── RecyclerItem.java │ │ │ ├── RecyclerListItem.java │ │ │ ├── RelatedMoviesItem.java │ │ │ ├── Trailer.java │ │ │ └── TrailerListParser.java │ │ │ ├── net │ │ │ ├── CustomRetryPolicy.java │ │ │ ├── Endpoint.java │ │ │ ├── INetworkUtils.java │ │ │ ├── NetworkRequestListener.java │ │ │ └── NetworkUtilsImpl.java │ │ │ ├── provider │ │ │ └── SearchSuggestionsProvider.java │ │ │ └── view │ │ │ └── FadeInNetworkImageView.java │ └── res │ │ ├── drawable-hdpi-v11 │ │ └── ic_stat_movies.png │ │ ├── drawable-hdpi │ │ ├── ic_arrow.png │ │ ├── ic_arrow_down.png │ │ ├── ic_arrow_up.png │ │ └── ic_stat_movies.png │ │ ├── drawable-mdpi-v11 │ │ └── ic_stat_movies.png │ │ ├── drawable-mdpi │ │ ├── ic_arrow.png │ │ ├── ic_arrow_down.png │ │ ├── ic_arrow_up.png │ │ └── ic_stat_movies.png │ │ ├── drawable-xhdpi-v11 │ │ └── ic_stat_movies.png │ │ ├── drawable-xhdpi │ │ ├── ic_arrow.png │ │ ├── ic_arrow_down.png │ │ ├── ic_arrow_up.png │ │ └── ic_stat_movies.png │ │ ├── drawable-xxhdpi-v11 │ │ └── ic_stat_movies.png │ │ ├── drawable-xxhdpi │ │ ├── ic_arrow.png │ │ ├── ic_arrow_down.png │ │ ├── ic_arrow_up.png │ │ └── ic_stat_movies.png │ │ ├── drawable-xxxhdpi-v11 │ │ └── ic_stat_movies.png │ │ ├── drawable-xxxhdpi │ │ ├── ic_arrow.png │ │ ├── ic_arrow_down.png │ │ ├── ic_arrow_up.png │ │ └── ic_stat_movies.png │ │ ├── drawable │ │ ├── error.png │ │ └── loading.png │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_movie_detail.xml │ │ ├── activity_trailer.xml │ │ ├── backdrop_pager_item.xml │ │ ├── fragment_movie_detail.xml │ │ ├── layout_movie_item.xml │ │ ├── layout_movie_recycler.xml │ │ ├── layout_movie_related_item.xml │ │ ├── layout_movie_related_items.xml │ │ └── layout_trailer_item.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── raw │ │ ├── movie_detail_framed.png │ │ ├── movie_list_framed.png │ │ ├── search_results_framed.png │ │ ├── similar_movies_framed.png │ │ └── youtube_player_framed.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── searchable.xml │ └── test │ └── java │ └── com │ └── android │ └── msahakyan │ └── nestedrecycler │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /NestedRecycler.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nested-recycler-view 2 | 3 |

4 | Implemented a vertical recylcer view with nested horizontal recycler view.
5 | User can scroll vertically and horizontally through the grid of views. 6 |

7 | 8 | # Application description 9 |

10 | Simple application which shows movies list on recyclerView (parent recycler) and related movies inside another nested recyclerView (child recycler). 11 |

12 | 13 |

14 | When user clicks on movie item it loads the details page for that movie and simultaneously tries to load related movie list (for the same genre(s), on which a click happen). After that if user clicks back button and related movies for that movie were loaded successfully a new horizontal recyclerView will be created for related items and dynamically will be added to parent recyclerView below the item on which click event happened. 15 |

16 |

17 | If user clicks on some other movie item the detail view for that movie will be loaded and simultaneously (in background) previously created child recyclerView (if there was one) will be removed and new child recyclerView will be created (which contains related movies to the newly clicked movie item) on the new position. 18 |

19 | 20 | # Screenshots from movies app 21 | 22 | `movie list page`
23 | main feed page 24 | 25 | `similar movies page`
26 | main feed page with loaded similar movies 27 | 28 | `movie detail page`
29 | detail page view 30 | 31 | `search results view`
32 | main feed page with active search view 33 | 34 | `integrated youtube player`
35 | integrated youtube player 36 | 37 | 38 | # Used Libraries 39 | 48 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 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 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | 7 | defaultConfig { 8 | applicationId "com.android.msahakyan.nestedrecycler" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | lintOptions { 21 | disable 'InvalidPackage' 22 | } 23 | packagingOptions { 24 | exclude 'META-INF/services/javax.annotation.processing.Processor' 25 | } 26 | } 27 | 28 | dependencies { 29 | compile fileTree(dir: 'libs', include: ['*.jar']) 30 | testCompile 'junit:junit:4.12' 31 | compile 'com.android.support:appcompat-v7:23.1.1' 32 | // Support recyclerView 33 | compile 'com.android.support:recyclerview-v7:23.1.1' 34 | // Support cardView 35 | compile 'com.android.support:cardview-v7:23.1.1' 36 | // Support android volley networking library 37 | compile 'com.github.erd:android-volley:1.0.0' 38 | // Support gson library 39 | compile 'com.google.code.gson:gson:2.4' 40 | // Support view injections and bindings 41 | compile 'com.jakewharton:butterknife:7.0.1' 42 | // Support material design circle progress bar 43 | compile 'com.github.rahatarmanahmed:circularprogressview:2.4.0' 44 | // Support viewpager indicator 45 | compile 'com.mcxiaoke.viewpagerindicator:library:2.4.1' 46 | compile files('libs/AmazonInsights-android-sdk-2.1.26.jar') 47 | compile files('libs/YouTubeAndroidPlayerApi.jar') 48 | } 49 | -------------------------------------------------------------------------------- /app/libs/AmazonInsights-android-sdk-2.1.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/libs/AmazonInsights-android-sdk-2.1.26.jar -------------------------------------------------------------------------------- /app/libs/YouTubeAndroidPlayerApi.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/libs/YouTubeAndroidPlayerApi.jar -------------------------------------------------------------------------------- /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 /Users/msahakan/development/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/androidTest/java/com/android/msahakyan/nestedrecycler/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 40 | 41 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/assets/amazon.properties: -------------------------------------------------------------------------------- 1 | public_key=00f238e04c0c446f952c7c8817d63030 2 | private_key=l22CvJ/nfYPKodq9u9q5kSyZWRD1zhh8jox5q8Ito/Q= -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/PushService.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler; 2 | 3 | import android.app.IntentService; 4 | import android.app.Notification; 5 | import android.app.NotificationManager; 6 | import android.app.PendingIntent; 7 | import android.content.Context; 8 | import android.content.Intent; 9 | import android.graphics.Bitmap; 10 | import android.graphics.BitmapFactory; 11 | import android.support.v4.app.NotificationCompat; 12 | 13 | import com.android.msahakyan.nestedrecycler.activity.MainActivity; 14 | import com.android.msahakyan.nestedrecycler.application.AppController; 15 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 16 | import com.android.msahakyan.nestedrecycler.common.PushNotification; 17 | import com.android.msahakyan.nestedrecycler.net.Endpoint; 18 | import com.android.volley.Response; 19 | import com.android.volley.VolleyError; 20 | import com.android.volley.toolbox.ImageRequest; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * @author msahakyan 27 | */ 28 | public class PushService extends IntentService { 29 | 30 | private static final String TAG = PushService.class.getSimpleName(); 31 | public static final int NOTIFICATION_ID = 555; 32 | private static final int MAX_WIDTH = 1024; 33 | private static final int MAX_HEIGHT = 1024; 34 | 35 | public PushService() { 36 | super(TAG); 37 | } 38 | 39 | @Override 40 | protected void onHandleIntent(Intent intent) { 41 | if (intent != null) { 42 | PushNotification notification = getNotificationFromIntent(intent); 43 | intent = new Intent(this, MainActivity.class); 44 | intent.putExtra(BundleKey.EXTRA_MOVIE_ID, notification.getId()); 45 | getNotificationImagesAndShow(intent, notification, new HashMap(2)); 46 | } 47 | } 48 | 49 | private PushNotification getNotificationFromIntent(Intent intent) { 50 | PushNotification pn = intent.getParcelableExtra(BundleKey.EXTRA_NOTIFICATION); 51 | pn.setIconUrl(Endpoint.IMAGE + "/w185/" + pn.getIconUrl()); 52 | pn.setImageUrl(Endpoint.IMAGE + "/w500/" + pn.getImageUrl()); 53 | 54 | return pn; 55 | } 56 | 57 | private void getNotificationImage(final String imageUrl, final HashMap images, final Runnable runnable) { 58 | if (imageUrl != null) { 59 | ImageRequest request = new ImageRequest(imageUrl, new Response.Listener() { 60 | @Override 61 | public void onResponse(Bitmap response) { 62 | images.put(imageUrl, response); 63 | runnable.run(); 64 | } 65 | }, MAX_WIDTH, MAX_HEIGHT, Bitmap.Config.RGB_565, new Response.ErrorListener() { 66 | @Override 67 | public void onErrorResponse(VolleyError error) { 68 | runnable.run(); 69 | } 70 | }); 71 | AppController.getInstance().addToRequestQueue(request); 72 | 73 | } else { 74 | runnable.run(); 75 | } 76 | } 77 | 78 | private void getNotificationImagesAndShow(final Intent intent, final PushNotification notification, final HashMap images) { 79 | getNotificationImage(notification.getImageUrl(), images, new Runnable() { 80 | @Override 81 | public void run() { 82 | getNotificationImage(notification.getIconUrl(), images, new Runnable() { 83 | @Override 84 | public void run() { 85 | showNotification(intent, notification, images); 86 | } 87 | }); 88 | } 89 | }); 90 | } 91 | 92 | public void showNotification(Intent intent, PushNotification notification, Map images) { 93 | NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 94 | 95 | NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 96 | builder.setSmallIcon(R.drawable.ic_stat_movies) 97 | .setContentTitle(getString(R.string.app_name)) 98 | .setContentText(notification.getMessage()) 99 | .setAutoCancel(true) 100 | .setDefaults(Notification.DEFAULT_ALL); 101 | 102 | PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 103 | builder.setContentIntent(pIntent); 104 | if (images != null) { 105 | Bitmap icon = images.get(notification.getIconUrl()); 106 | if (icon != null) { 107 | builder.setLargeIcon(icon); 108 | } 109 | 110 | Bitmap image = images.get(notification.getImageUrl()); 111 | if (image != null) { 112 | builder.setStyle(new NotificationCompat.BigPictureStyle() 113 | .setBigContentTitle(getString(R.string.app_name)) 114 | .bigLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) 115 | .bigPicture(image) 116 | .setSummaryText(notification.getMessage())); 117 | } 118 | } 119 | 120 | if (notification.getPriority() == PushNotification.PRIORITY_HIGH) { 121 | builder.setPriority(NotificationCompat.PRIORITY_HIGH); 122 | } else { 123 | builder.setPriority(NotificationCompat.PRIORITY_DEFAULT); 124 | } 125 | 126 | notificationManager.notify(NOTIFICATION_ID, builder.build()); 127 | } 128 | } 129 | 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.activity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.app.SearchManager; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.os.Bundle; 8 | import android.provider.SearchRecentSuggestions; 9 | import android.support.v4.view.MenuItemCompat; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.support.v7.widget.GridLayoutManager; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.util.Log; 14 | import android.view.Gravity; 15 | import android.view.Menu; 16 | import android.view.MenuInflater; 17 | import android.view.MenuItem; 18 | import android.widget.SearchView; 19 | import android.widget.Toast; 20 | 21 | import com.android.msahakyan.nestedrecycler.R; 22 | import com.android.msahakyan.nestedrecycler.adapter.MovieAdapter; 23 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 24 | import com.android.msahakyan.nestedrecycler.config.Config; 25 | import com.android.msahakyan.nestedrecycler.model.Movie; 26 | import com.android.msahakyan.nestedrecycler.model.MovieListParser; 27 | import com.android.msahakyan.nestedrecycler.model.RecyclerItem; 28 | import com.android.msahakyan.nestedrecycler.net.Endpoint; 29 | import com.android.msahakyan.nestedrecycler.net.NetworkRequestListener; 30 | import com.android.msahakyan.nestedrecycler.net.NetworkUtilsImpl; 31 | import com.android.msahakyan.nestedrecycler.provider.SearchSuggestionsProvider; 32 | import com.android.volley.Request; 33 | import com.android.volley.VolleyError; 34 | import com.google.gson.Gson; 35 | 36 | import org.json.JSONObject; 37 | 38 | import java.io.UnsupportedEncodingException; 39 | import java.net.URLEncoder; 40 | import java.util.ArrayList; 41 | import java.util.HashMap; 42 | import java.util.List; 43 | import java.util.Map; 44 | 45 | import butterknife.Bind; 46 | import butterknife.ButterKnife; 47 | 48 | public class MainActivity extends AppCompatActivity { 49 | 50 | private static final String TAG = MainActivity.class.getName(); 51 | private List mItems; 52 | private ProgressDialog mDialog; 53 | private GridLayoutManager mLayoutManager; 54 | private Map mUrlParams; 55 | private String mEndpoint; 56 | private int mCurrentPage; 57 | private int mTotalPageSize; 58 | private SearchView mSearchView; 59 | private long mMovieId; 60 | private boolean mShouldLoadSimilarItems; 61 | 62 | @Bind(R.id.movie_recycler_view) 63 | protected RecyclerView mRecyclerView; 64 | 65 | private MovieAdapter mAdapter; 66 | 67 | private boolean mLoading = false; 68 | 69 | @Override 70 | protected void onCreate(Bundle savedInstanceState) { 71 | super.onCreate(savedInstanceState); 72 | setContentView(R.layout.activity_main); 73 | 74 | ButterKnife.bind(this); 75 | handleIntent(getIntent()); 76 | 77 | mCurrentPage = 1; 78 | mTotalPageSize = 1; 79 | mDialog = new ProgressDialog(MainActivity.this); 80 | mItems = new ArrayList<>(); 81 | 82 | setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); 83 | 84 | mLayoutManager = new GridLayoutManager(this, 2); 85 | mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { 86 | @Override 87 | public int getSpanSize(int position) { 88 | return mItems.get(position) instanceof Movie ? 1 : 2; 89 | } 90 | }); 91 | 92 | // Set layout manager to recyclerView 93 | mRecyclerView.setLayoutManager(mLayoutManager); 94 | mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 95 | @Override 96 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 97 | if (dy > 0) { 98 | //check for scroll down 99 | loadMoreItems(); 100 | } 101 | } 102 | }); 103 | 104 | Intent intent = getIntent(); 105 | if (intent != null && intent.hasExtra(BundleKey.EXTRA_MOVIE_ID)) { 106 | mTotalPageSize = 1; 107 | mShouldLoadSimilarItems = true; 108 | initSimilarMoviesEndpointAndUrlParams(mMovieId = intent.getLongExtra(BundleKey.EXTRA_MOVIE_ID, -1), mCurrentPage = 1); 109 | } else { 110 | initEndpointAndUrlParams(mCurrentPage); 111 | } 112 | 113 | mDialog.setMessage(getString(R.string.loading_data)); 114 | mDialog.getWindow().setGravity(Gravity.CENTER); 115 | mDialog.show(); 116 | mAdapter = new MovieAdapter(MainActivity.this, mItems); 117 | mRecyclerView.setAdapter(mAdapter); 118 | loadMovieList(false); 119 | } 120 | 121 | private void initEndpointAndUrlParams(int page) { 122 | mEndpoint = Endpoint.DISCOVER; 123 | mUrlParams = new HashMap<>(); 124 | mUrlParams.put("api_key", Config.API_KEY); 125 | mUrlParams.put("page", String.valueOf(page)); 126 | } 127 | 128 | private void initSearchEndpointAndUrlParams(String query) { 129 | mEndpoint = Endpoint.SEARCH; 130 | mUrlParams = new HashMap<>(); 131 | mUrlParams.put("query", query.trim()); 132 | mUrlParams.put("api_key", Config.API_KEY); 133 | } 134 | 135 | private void initSimilarMoviesEndpointAndUrlParams(long movieId, int page) { 136 | mEndpoint = "https://api.themoviedb.org/3/movie/" + movieId + "/similar"; 137 | mUrlParams = new HashMap<>(); 138 | mUrlParams.put("page", String.valueOf(page)); 139 | mUrlParams.put("api_key", Config.API_KEY); 140 | } 141 | 142 | private void loadMoreItems() { 143 | if (mTotalPageSize > mCurrentPage) { 144 | int visibleItemCount = mLayoutManager.getChildCount(); 145 | int totalItemCount = mLayoutManager.getItemCount(); 146 | int pastVisibleItems = mLayoutManager.findFirstVisibleItemPosition(); 147 | 148 | if (!mLoading) { 149 | if ((visibleItemCount + pastVisibleItems) >= totalItemCount) { 150 | mLoading = true; 151 | Log.v(TAG, "Reached last Item!"); 152 | 153 | // Fetching new data... 154 | if (mShouldLoadSimilarItems) { 155 | initSimilarMoviesEndpointAndUrlParams(mMovieId, ++mCurrentPage); 156 | } else { 157 | initEndpointAndUrlParams(++mCurrentPage); 158 | } 159 | 160 | mDialog.setMessage(getString(R.string.loading_more_data)); 161 | mDialog.getWindow().setGravity(Gravity.BOTTOM); 162 | mDialog.show(); 163 | 164 | loadMovieList(true); 165 | } 166 | } 167 | } 168 | } 169 | 170 | private void loadMovieList(final boolean shouldInsertResults) { 171 | new NetworkUtilsImpl().executeJsonRequest(Request.Method.GET, new StringBuilder(mEndpoint), 172 | mUrlParams, new NetworkRequestListener() { 173 | @Override 174 | public void onSuccess(JSONObject jsonResponse) { 175 | if (mDialog.isShowing()) { 176 | mDialog.dismiss(); 177 | } 178 | final int startPosition = mItems.size(); 179 | MovieListParser movieListParser = new Gson().fromJson(jsonResponse.toString(), MovieListParser.class); 180 | mTotalPageSize = movieListParser.getTotalPages(); 181 | List movieList = movieListParser.getResults(); 182 | if (shouldInsertResults) { 183 | mItems.addAll(movieList); 184 | mAdapter.notifyItemRangeInserted(startPosition, movieList.size()); 185 | } else { 186 | mItems.clear(); 187 | mItems.addAll(movieList); 188 | mAdapter.setRelatedItemsPosition(RecyclerView.NO_POSITION); 189 | mAdapter.notifyDataSetChanged(); 190 | } 191 | 192 | mLoading = false; 193 | } 194 | 195 | @Override 196 | public void onError(VolleyError error) { 197 | if (mDialog.isShowing()) { 198 | mDialog.dismiss(); 199 | } 200 | Toast.makeText(MainActivity.this, "Error: " + error.getMessage(), Toast.LENGTH_SHORT).show(); 201 | } 202 | }); 203 | } 204 | 205 | private void loadSearchResults() { 206 | new NetworkUtilsImpl().executeJsonRequest(Request.Method.GET, new StringBuilder(mEndpoint), 207 | mUrlParams, new NetworkRequestListener() { 208 | @Override 209 | public void onSuccess(JSONObject jsonResponse) { 210 | if (mDialog.isShowing()) { 211 | mDialog.dismiss(); 212 | } 213 | List movieList = new Gson().fromJson(jsonResponse.toString(), MovieListParser.class).getResults(); 214 | mItems.clear(); 215 | mCurrentPage = 1; 216 | mTotalPageSize = 1; 217 | for (Movie movie : movieList) { 218 | mItems.add(movie); 219 | } 220 | mAdapter.notifyDataSetChanged(); 221 | mAdapter.setRelatedItemsPosition(RecyclerView.NO_POSITION); 222 | mLoading = false; 223 | } 224 | 225 | @Override 226 | public void onError(VolleyError error) { 227 | if (mDialog.isShowing()) { 228 | mDialog.dismiss(); 229 | } 230 | Toast.makeText(MainActivity.this, "Error: " + error.getMessage(), Toast.LENGTH_SHORT).show(); 231 | } 232 | }); 233 | } 234 | 235 | @Override 236 | protected void onNewIntent(Intent intent) { 237 | // Set layout manager to recyclerView 238 | mRecyclerView.setLayoutManager(mLayoutManager); 239 | handleIntent(intent); 240 | } 241 | 242 | private void handleIntent(Intent intent) { 243 | 244 | if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 245 | String query = intent.getStringExtra(SearchManager.QUERY); 246 | 247 | // Saving the query during of on handle intent 248 | SearchRecentSuggestions suggestions = new SearchRecentSuggestions(this, 249 | SearchSuggestionsProvider.AUTHORITY, SearchSuggestionsProvider.MODE); 250 | suggestions.saveRecentQuery(query, null); 251 | 252 | try { 253 | query = URLEncoder.encode(query, "utf-8"); 254 | } catch (UnsupportedEncodingException e) { 255 | Log.w(TAG, "Can't encode search query", e); 256 | } 257 | initSearchEndpointAndUrlParams(query); 258 | mDialog.setMessage(getString(R.string.loading_more_data)); 259 | mDialog.getWindow().setGravity(Gravity.CENTER); 260 | mDialog.show(); 261 | loadSearchResults(); 262 | mSearchView.clearFocus(); 263 | } 264 | } 265 | 266 | @Override 267 | public boolean onCreateOptionsMenu(Menu menu) { 268 | // Inflate the options menu from XML 269 | MenuInflater inflater = getMenuInflater(); 270 | inflater.inflate(R.menu.menu_main, menu); 271 | 272 | // Get the SearchView and set the searchable configuration 273 | SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 274 | MenuItem menuItem = menu.findItem(R.id.menu_search); 275 | mSearchView = (SearchView) menuItem.getActionView(); 276 | 277 | mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 278 | mSearchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default 279 | 280 | MenuItemCompat.setOnActionExpandListener(menuItem, new MenuItemCompat.OnActionExpandListener() { 281 | @Override 282 | public boolean onMenuItemActionExpand(MenuItem item) { 283 | return true; 284 | } 285 | 286 | @Override 287 | public boolean onMenuItemActionCollapse(MenuItem item) { 288 | // Show list of movies again 289 | initEndpointAndUrlParams(mCurrentPage = 1); 290 | loadMovieList(false); 291 | 292 | return true; 293 | } 294 | }); 295 | 296 | return true; 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/activity/MovieDetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.support.v7.app.AppCompatActivity; 6 | 7 | import com.android.msahakyan.nestedrecycler.R; 8 | import com.android.msahakyan.nestedrecycler.adapter.ItemDetailPagerAdapter; 9 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 10 | import com.android.msahakyan.nestedrecycler.common.ZoomOutPageTransformer; 11 | import com.android.msahakyan.nestedrecycler.model.RecyclerItem; 12 | import com.android.msahakyan.nestedrecycler.model.RecyclerListItem; 13 | 14 | import java.util.List; 15 | 16 | import butterknife.Bind; 17 | import butterknife.ButterKnife; 18 | 19 | public class MovieDetailActivity extends AppCompatActivity { 20 | 21 | private static final String TAG = MovieDetailActivity.class.getSimpleName(); 22 | 23 | @Bind(R.id.vpPager) 24 | ViewPager mViewPager; 25 | 26 | private ItemDetailPagerAdapter mAdapterViewPager; 27 | 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_movie_detail); 33 | 34 | // Initialization ButterKnife 35 | ButterKnife.bind(this); 36 | 37 | List movieList = getMoviesFromIntent(); 38 | 39 | mAdapterViewPager = new ItemDetailPagerAdapter(getSupportFragmentManager(), movieList); 40 | mViewPager.setAdapter(mAdapterViewPager); 41 | 42 | // Attach the page change listener inside the activity 43 | mViewPager.addOnPageChangeListener(mPageChangeListener); 44 | 45 | // Attach page transformer 46 | mViewPager.setPageTransformer(false, new ZoomOutPageTransformer()); 47 | } 48 | 49 | private ViewPager.OnPageChangeListener mPageChangeListener = new ViewPager.OnPageChangeListener() { 50 | @Override 51 | public void onPageSelected(int position) { 52 | // Code goes here 53 | } 54 | 55 | @Override 56 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 57 | // Code goes here 58 | } 59 | 60 | @Override 61 | public void onPageScrollStateChanged(int state) { 62 | // Code goes here 63 | } 64 | }; 65 | 66 | private List getMoviesFromIntent() { 67 | return ((RecyclerListItem) getIntent().getSerializableExtra(BundleKey.EXTRA_MOVIE_LIST)).getItems(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/activity/TrailerActivity.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.view.Window; 6 | import android.view.WindowManager; 7 | import android.widget.Toast; 8 | 9 | import com.android.msahakyan.nestedrecycler.R; 10 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 11 | import com.android.msahakyan.nestedrecycler.config.Config; 12 | import com.google.android.youtube.player.YouTubeBaseActivity; 13 | import com.google.android.youtube.player.YouTubeInitializationResult; 14 | import com.google.android.youtube.player.YouTubePlayer; 15 | import com.google.android.youtube.player.YouTubePlayer.PlayerStyle; 16 | import com.google.android.youtube.player.YouTubePlayerView; 17 | 18 | import butterknife.Bind; 19 | import butterknife.ButterKnife; 20 | 21 | public class TrailerActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener { 22 | 23 | private static final int RECOVERY_DIALOG_REQUEST = 1; 24 | private String mTrailerPath; 25 | 26 | @Bind(R.id.youtube_view) 27 | protected YouTubePlayerView youTubeView; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | requestWindowFeature(Window.FEATURE_NO_TITLE); 33 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 34 | WindowManager.LayoutParams.FLAG_FULLSCREEN); 35 | setContentView(R.layout.activity_trailer); 36 | ButterKnife.bind(this); 37 | initTrailerIdFromIntent(); 38 | 39 | // Initializing video player with developer key 40 | youTubeView.initialize(Config.DEVELOPER_KEY, this); 41 | } 42 | 43 | @Override 44 | public void onInitializationFailure(YouTubePlayer.Provider provider, 45 | YouTubeInitializationResult errorReason) { 46 | if (errorReason.isUserRecoverableError()) { 47 | errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show(); 48 | } else { 49 | String errorMessage = String.format( 50 | getString(R.string.error_player), errorReason.toString()); 51 | Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show(); 52 | } 53 | } 54 | 55 | @Override 56 | public void onInitializationSuccess(YouTubePlayer.Provider provider, 57 | YouTubePlayer player, boolean wasRestored) { 58 | if (mTrailerPath == null) { 59 | finish(); 60 | } 61 | 62 | if (!wasRestored) { 63 | // if you want to play it automatically 64 | player.loadVideo(mTrailerPath); 65 | 66 | // if you don't want to play it automatically 67 | // player.cueVideo(Config.YOUTUBE_VIDEO_CODE); 68 | 69 | // Showing player controls 70 | player.setPlayerStyle(PlayerStyle.DEFAULT); 71 | } 72 | } 73 | 74 | @Override 75 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 76 | if (requestCode == RECOVERY_DIALOG_REQUEST) { 77 | // Retry initialization if user performed a recovery action 78 | getYouTubePlayerProvider().initialize(Config.DEVELOPER_KEY, this); 79 | } 80 | } 81 | 82 | private YouTubePlayer.Provider getYouTubePlayerProvider() { 83 | return (YouTubePlayerView) findViewById(R.id.youtube_view); 84 | } 85 | 86 | private void initTrailerIdFromIntent() { 87 | if (getIntent().getExtras().containsKey(BundleKey.EXTRA_TRAILER_ID)) { 88 | mTrailerPath = getIntent().getStringExtra(BundleKey.EXTRA_TRAILER_ID); 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/adapter/BackdropPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.android.msahakyan.nestedrecycler.R; 10 | import com.android.msahakyan.nestedrecycler.application.AppController; 11 | import com.android.msahakyan.nestedrecycler.model.Backdrop; 12 | import com.android.msahakyan.nestedrecycler.net.Endpoint; 13 | import com.android.msahakyan.nestedrecycler.view.FadeInNetworkImageView; 14 | import com.android.volley.toolbox.ImageLoader; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * @author msahakyan 20 | */ 21 | public class BackdropPagerAdapter extends PagerAdapter { 22 | 23 | private LayoutInflater mLayoutInflater; 24 | private List mBackdropList; 25 | 26 | public BackdropPagerAdapter(Context context, List backdropList) { 27 | mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 28 | mBackdropList = backdropList; 29 | } 30 | 31 | @Override 32 | public int getCount() { 33 | return mBackdropList.size(); 34 | } 35 | 36 | @Override 37 | public boolean isViewFromObject(View view, Object object) { 38 | return view == object; 39 | } 40 | 41 | @Override 42 | public Object instantiateItem(ViewGroup container, int position) { 43 | View itemView = mLayoutInflater.inflate(R.layout.backdrop_pager_item, container, false); 44 | 45 | FadeInNetworkImageView backdropImageView = (FadeInNetworkImageView) itemView.findViewById(R.id.backdrop_image); 46 | ImageLoader imageLoader = AppController.getInstance().getImageLoader(); 47 | backdropImageView.setImageUrl(Endpoint.IMAGE + "/w500/" + mBackdropList.get(position).getFilePath(), imageLoader); 48 | 49 | container.addView(itemView); 50 | 51 | return itemView; 52 | } 53 | 54 | @Override 55 | public void destroyItem(ViewGroup container, int position, Object object) { 56 | container.removeView((FadeInNetworkImageView) object); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/adapter/ItemDetailPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.adapter; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentManager; 6 | 7 | import com.android.msahakyan.nestedrecycler.fragment.MovieDetailFragment; 8 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 9 | import com.android.msahakyan.nestedrecycler.model.Movie; 10 | import com.android.msahakyan.nestedrecycler.model.RecyclerItem; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * @author msahakyan 16 | */ 17 | public class ItemDetailPagerAdapter extends SmartFragmentStatePagerAdapter { 18 | 19 | private List mItems; 20 | 21 | public ItemDetailPagerAdapter(FragmentManager fragmentManager, List items) { 22 | super(fragmentManager); 23 | mItems = items; 24 | } 25 | 26 | // Returns total number of pages 27 | @Override 28 | public int getCount() { 29 | return mItems.size(); 30 | } 31 | 32 | // Returns the fragment to display for that page 33 | @Override 34 | public Fragment getItem(int position) { 35 | MovieDetailFragment fragment = MovieDetailFragment.newInstance(); 36 | Bundle bundle = new Bundle(); 37 | bundle.putSerializable(BundleKey.EXTRA_MOVIE, mItems.get(position)); 38 | bundle.putBoolean(BundleKey.HAS_NEXT, hasNext(position)); 39 | bundle.putBoolean(BundleKey.HAS_PREVIOUS, hasPrevious(position)); 40 | fragment.setArguments(bundle); 41 | return fragment; 42 | } 43 | 44 | // Returns the page title for the top indicator 45 | @Override 46 | public CharSequence getPageTitle(int position) { 47 | return ((Movie) mItems.get(position)).getTitle(); 48 | } 49 | 50 | private boolean hasNext(int position) { 51 | return (mItems.size() > 1) && (position < mItems.size() - 1); 52 | } 53 | 54 | private boolean hasPrevious(int position) { 55 | return position > 0; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/adapter/MovieAdapter.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.adapter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.util.Log; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 15 | import com.android.msahakyan.nestedrecycler.PushService; 16 | import com.android.msahakyan.nestedrecycler.R; 17 | import com.android.msahakyan.nestedrecycler.activity.MovieDetailActivity; 18 | import com.android.msahakyan.nestedrecycler.application.AppController; 19 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 20 | import com.android.msahakyan.nestedrecycler.common.HorizontalItemDecorator; 21 | import com.android.msahakyan.nestedrecycler.common.Helper; 22 | import com.android.msahakyan.nestedrecycler.common.ItemClickListener; 23 | import com.android.msahakyan.nestedrecycler.common.PushNotification; 24 | import com.android.msahakyan.nestedrecycler.config.Config; 25 | import com.android.msahakyan.nestedrecycler.model.Movie; 26 | import com.android.msahakyan.nestedrecycler.model.MovieListParser; 27 | import com.android.msahakyan.nestedrecycler.model.RecyclerItem; 28 | import com.android.msahakyan.nestedrecycler.model.RecyclerListItem; 29 | import com.android.msahakyan.nestedrecycler.model.RelatedMoviesItem; 30 | import com.android.msahakyan.nestedrecycler.net.Endpoint; 31 | import com.android.msahakyan.nestedrecycler.net.NetworkRequestListener; 32 | import com.android.msahakyan.nestedrecycler.net.NetworkUtilsImpl; 33 | import com.android.msahakyan.nestedrecycler.view.FadeInNetworkImageView; 34 | import com.android.volley.Request; 35 | import com.android.volley.VolleyError; 36 | import com.android.volley.toolbox.ImageLoader; 37 | import com.github.rahatarmanahmed.cpv.CircularProgressView; 38 | import com.google.gson.Gson; 39 | 40 | import org.json.JSONObject; 41 | 42 | import java.util.ArrayList; 43 | import java.util.HashMap; 44 | import java.util.List; 45 | import java.util.Map; 46 | 47 | import butterknife.Bind; 48 | import butterknife.ButterKnife; 49 | 50 | /** 51 | * @author msahakyan 52 | *

53 | * Movie adapter which actually is adapter of parent recycler view's 54 | */ 55 | public class MovieAdapter extends RecyclerView.Adapter { 56 | 57 | private static final int TYPE_MOVIE = 1001; 58 | private static final int TYPE_RELATED_ITEMS = 1002; 59 | private static final String TAG = MovieAdapter.class.getSimpleName(); 60 | 61 | private Context mContext; 62 | private List mItemList; 63 | private int relatedItemsPosition = RecyclerView.NO_POSITION; 64 | private List mLastItemGenreIds; 65 | private RecyclerView mRecyclerView; 66 | private String mEndpoint; 67 | private Map mUrlParams; 68 | private ImageLoader mImageLoader = AppController.getInstance().getImageLoader(); 69 | private boolean mRelatedItemsLoading; 70 | private int mRelatedItemsCurrentPage; 71 | private List mRelatedItemList; 72 | 73 | public MovieAdapter(Context context, List itemList) { 74 | mContext = context; 75 | mItemList = itemList; 76 | mRelatedItemList = new ArrayList<>(); 77 | } 78 | 79 | @Override 80 | public GenericViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 81 | 82 | View view; 83 | GenericViewHolder customItemViewHolder = null; 84 | switch (viewType) { 85 | case TYPE_MOVIE: 86 | view = LayoutInflater.from(mContext).inflate(R.layout.layout_movie_item, parent, false); 87 | customItemViewHolder = new MovieViewHolder(view); 88 | break; 89 | case TYPE_RELATED_ITEMS: 90 | view = LayoutInflater.from(mContext).inflate(R.layout.layout_movie_related_items, parent, false); 91 | customItemViewHolder = new RelatedMoviesViewHolder(view); 92 | break; 93 | default: 94 | break; 95 | } 96 | 97 | return customItemViewHolder; 98 | } 99 | 100 | @Override 101 | public void onBindViewHolder(GenericViewHolder holder, int position) { 102 | if (holder instanceof MovieViewHolder) { 103 | bindMovieViewHolder((MovieViewHolder) holder, (Movie) mItemList.get(position)); 104 | } else if (holder instanceof RelatedMoviesViewHolder) { 105 | bindRelatedItemsViewHolder((RelatedMoviesViewHolder) holder); 106 | } 107 | } 108 | 109 | private void bindMovieViewHolder(MovieViewHolder holder, final Movie movie) { 110 | // holder.name.setText(movie.getTitle()); 111 | // holder.voteAvrg.setText(String.valueOf(movie.getVoteAverage())); 112 | if (movie.getPosterPath() != null) { 113 | String fullPosterPath = Endpoint.IMAGE + "/w185/" + movie.getPosterPath(); 114 | holder.thumbnail.setImageUrl(fullPosterPath, mImageLoader); 115 | holder.thumbnail.setErrorImageResId(R.drawable.error); 116 | } 117 | // holder.date.setText(movie.getReleaseDate()); 118 | holder.setClickListener(new ItemClickListener() { 119 | @Override 120 | public void onClick(View view, int position) { 121 | startDetailsActivity(position); 122 | insertRelatedMoviesItem(position, movie); 123 | } 124 | }); 125 | } 126 | 127 | private void startDetailsActivity(int position) { 128 | List movieList = new ArrayList<>(mItemList.subList(position, mItemList.size())); 129 | List filteredItems = filterRelatedItems(movieList); 130 | Intent intent = new Intent(mContext, MovieDetailActivity.class); 131 | RecyclerListItem recyclerListItem = new RecyclerListItem(); 132 | recyclerListItem.setItems(filteredItems); 133 | intent.putExtra(BundleKey.EXTRA_MOVIE_LIST, recyclerListItem); 134 | mContext.startActivity(intent); 135 | } 136 | 137 | private List filterRelatedItems(List movies) { 138 | List filteredItems = new ArrayList<>(); 139 | if (movies != null) { 140 | for (RecyclerItem item : movies) { 141 | if (item instanceof Movie) { 142 | filteredItems.add(item); 143 | } 144 | } 145 | } 146 | return filteredItems; 147 | } 148 | 149 | private void insertRelatedMoviesItem(int position, Movie movie) { 150 | final RelatedMoviesItem relatedMoviesItem = new RelatedMoviesItem(); 151 | mLastItemGenreIds = movie.getGenreIds(); 152 | mRelatedItemList.clear(); 153 | // If related item was added before, we have to remove it and add a new one 154 | if (relatedItemsPosition != -1) { 155 | if (position > relatedItemsPosition) { 156 | position--; 157 | } 158 | 159 | mItemList.remove(relatedItemsPosition); 160 | notifyItemRemoved(relatedItemsPosition); 161 | notifyItemRangeChanged(relatedItemsPosition, mItemList.size()); 162 | } 163 | 164 | if (Helper.isEmpty(mLastItemGenreIds)) { 165 | Toast.makeText(mContext, R.string.no_related_movies_available, Toast.LENGTH_SHORT).show(); 166 | relatedItemsPosition = RecyclerView.NO_POSITION; 167 | return; 168 | } 169 | 170 | if (position < mItemList.size() - 1) { 171 | relatedItemsPosition = position % 2 == 0 ? position + 2 : position + 1; 172 | } else { 173 | relatedItemsPosition = position + 1; 174 | } 175 | 176 | mItemList.add(relatedItemsPosition, relatedMoviesItem); 177 | notifyItemInserted(relatedItemsPosition); 178 | notifyItemRangeChanged(relatedItemsPosition, mItemList.size()); 179 | if (mRecyclerView != null && relatedItemsPosition > 1) { 180 | ((GridLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(relatedItemsPosition - 1, 0); 181 | } 182 | createNotification(movie); 183 | } 184 | 185 | private void createNotification(Movie movie) { 186 | Intent i = new Intent(); 187 | PushNotification notification = new PushNotification(); 188 | notification.setId(movie.getId()); 189 | notification.setMessage("Similar movies for \"" + movie.getTitle() + "\""); 190 | notification.setTitle(mContext.getString(R.string.app_name)); 191 | notification.setBigTitle("Similar Movies"); 192 | notification.setIconUrl(movie.getPosterPath()); 193 | notification.setImageUrl(movie.getBackdropPath()); 194 | i.putExtra(BundleKey.EXTRA_NOTIFICATION, notification); 195 | 196 | sendPushNotification(mContext, i); 197 | } 198 | 199 | private static void sendPushNotification(Context context, Intent i) { 200 | i.setClass(context, PushService.class); 201 | context.startService(i); 202 | } 203 | 204 | private void bindRelatedItemsViewHolder(final RelatedMoviesViewHolder holder) { 205 | final LinearLayoutManager layoutManager 206 | = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false); 207 | RelatedMoviesAdapter adapter = new RelatedMoviesAdapter(mContext, mRelatedItemList); 208 | holder.relatedItemsRecyclerView.setAdapter(adapter); 209 | holder.relatedItemsRecyclerView.addItemDecoration(new HorizontalItemDecorator((int) mContext.getResources().getDimension(R.dimen.padding_size_small))); 210 | holder.relatedMoviesHeader.setText(mContext.getString(R.string.loading_data)); 211 | holder.relatedItemsRecyclerView.setLayoutManager(layoutManager); 212 | holder.relatedItemsRecyclerView.setHasFixedSize(true); 213 | 214 | holder.relatedItemsRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 215 | @Override 216 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 217 | if (dx > 0) { 218 | //check for scroll right 219 | loadMoreItems(holder); 220 | } 221 | } 222 | }); 223 | 224 | holder.progressView.setVisibility(View.VISIBLE); 225 | holder.progressView.startAnimation(); 226 | 227 | // Loading similar products 228 | initEndpointAndUrlParams(mRelatedItemsCurrentPage = 1); 229 | loadRelatedMovies(holder); 230 | } 231 | 232 | private void loadRelatedMovies(final RelatedMoviesViewHolder holder) { 233 | new NetworkUtilsImpl().executeJsonRequest(Request.Method.GET, new StringBuilder(mEndpoint), 234 | mUrlParams, new NetworkRequestListener() { 235 | @Override 236 | public void onSuccess(JSONObject jsonResponse) { 237 | holder.progressView.clearAnimation(); 238 | holder.progressView.setVisibility(View.GONE); 239 | List freshLoadedList = new Gson().fromJson(jsonResponse.toString(), MovieListParser.class).getResults(); 240 | mRelatedItemList.addAll(freshLoadedList); 241 | holder.relatedItemsRecyclerView.getAdapter().notifyItemRangeInserted(mRelatedItemList.size(), freshLoadedList.size()); 242 | holder.relatedMoviesHeader.setText(mContext.getString(R.string.related_movies)); 243 | mRelatedItemsLoading = false; 244 | } 245 | 246 | @Override 247 | public void onError(VolleyError error) { 248 | holder.progressView.clearAnimation(); 249 | holder.progressView.setVisibility(View.GONE); 250 | Toast.makeText(mContext, "Error: " + error.getMessage(), Toast.LENGTH_SHORT).show(); 251 | } 252 | }); 253 | } 254 | 255 | private void loadMoreItems(final RelatedMoviesViewHolder holder) { 256 | 257 | LinearLayoutManager layoutManager = (LinearLayoutManager) holder.relatedItemsRecyclerView.getLayoutManager(); 258 | int visibleItemCount = layoutManager.getChildCount(); 259 | int totalItemCount = layoutManager.getItemCount(); 260 | int pastVisibleItems = layoutManager.findFirstVisibleItemPosition(); 261 | 262 | if (!mRelatedItemsLoading) { 263 | if ((visibleItemCount + pastVisibleItems) >= totalItemCount) { 264 | mRelatedItemsLoading = true; 265 | Log.v(TAG, "Reached last Item!"); 266 | 267 | // Fetching new data... 268 | initEndpointAndUrlParams(++mRelatedItemsCurrentPage); 269 | holder.progressView.setVisibility(View.VISIBLE); 270 | holder.progressView.startAnimation(); 271 | loadRelatedMovies(holder); 272 | } 273 | } 274 | } 275 | 276 | private void initEndpointAndUrlParams(int page) { 277 | mEndpoint = "http://api.themoviedb.org/3/discover/movie"; 278 | mUrlParams = new HashMap<>(); 279 | mUrlParams.put("api_key", Config.API_KEY); 280 | mUrlParams.put("sort_by", "vote_average.desc"); 281 | mUrlParams.put("with_genres", Helper.getCsvGenreIds(mLastItemGenreIds)); 282 | mUrlParams.put("page", String.valueOf(page)); 283 | } 284 | 285 | @Override 286 | public int getItemCount() { 287 | return mItemList.size(); 288 | } 289 | 290 | @Override 291 | public int getItemViewType(int position) { 292 | 293 | int type = super.getItemViewType(position); 294 | 295 | if (mItemList.get(position) instanceof Movie) { 296 | type = TYPE_MOVIE; 297 | } else if (mItemList.get(position) instanceof RelatedMoviesItem) { 298 | type = TYPE_RELATED_ITEMS; 299 | } 300 | 301 | return type; 302 | } 303 | 304 | static class GenericViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 305 | 306 | private ItemClickListener clickListener; 307 | 308 | public GenericViewHolder(View itemView) { 309 | super(itemView); 310 | itemView.setOnClickListener(this); 311 | } 312 | 313 | public void setClickListener(ItemClickListener itemClickListener) { 314 | this.clickListener = itemClickListener; 315 | } 316 | 317 | @Override 318 | public void onClick(View v) { 319 | this.clickListener.onClick(v, getPosition()); 320 | } 321 | } 322 | 323 | /** 324 | * ViewHolder of the movie element 325 | */ 326 | class MovieViewHolder extends GenericViewHolder { 327 | 328 | @Bind(R.id.movie_thumbnail) 329 | protected FadeInNetworkImageView thumbnail; 330 | 331 | public MovieViewHolder(View view) { 332 | super(view); 333 | ButterKnife.bind(this, view); 334 | } 335 | } 336 | 337 | /** 338 | * ViewHolder of the related movies element which contains reference 339 | * to related movies recyclerView and textView header of that element 340 | */ 341 | class RelatedMoviesViewHolder extends GenericViewHolder { 342 | 343 | @Bind(R.id.related_movies_recycler) 344 | protected RecyclerView relatedItemsRecyclerView; 345 | 346 | @Bind(R.id.related_movies_header) 347 | protected TextView relatedMoviesHeader; 348 | 349 | @Bind(R.id.progress_view) 350 | protected CircularProgressView progressView; 351 | 352 | public RelatedMoviesViewHolder(View view) { 353 | super(view); 354 | ButterKnife.bind(this, view); 355 | } 356 | 357 | @Override 358 | public void onClick(View v) { 359 | // do nothing 360 | } 361 | } 362 | 363 | public void setRelatedItemsPosition(int relatedItemsPosition) { 364 | this.relatedItemsPosition = relatedItemsPosition; 365 | } 366 | 367 | // Overriding this method to get access to recyclerView on which current MovieAdapter has been attached. 368 | // In the future we will use that reference for scrolling to newly added relatedMovies item 369 | @Override 370 | public void onAttachedToRecyclerView(RecyclerView recyclerView) { 371 | super.onAttachedToRecyclerView(recyclerView); 372 | mRecyclerView = recyclerView; 373 | } 374 | } 375 | 376 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/adapter/RelatedMoviesAdapter.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.adapter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.android.msahakyan.nestedrecycler.R; 11 | import com.android.msahakyan.nestedrecycler.activity.MovieDetailActivity; 12 | import com.android.msahakyan.nestedrecycler.application.AppController; 13 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 14 | import com.android.msahakyan.nestedrecycler.common.ItemClickListener; 15 | import com.android.msahakyan.nestedrecycler.model.Movie; 16 | import com.android.msahakyan.nestedrecycler.model.RecyclerListItem; 17 | import com.android.msahakyan.nestedrecycler.net.Endpoint; 18 | import com.android.msahakyan.nestedrecycler.view.FadeInNetworkImageView; 19 | import com.android.volley.toolbox.ImageLoader; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | import butterknife.Bind; 25 | import butterknife.ButterKnife; 26 | 27 | /** 28 | * @author msahakyan 29 | *

30 | * Related movies adapter which is actually adapter of nested recycler view 31 | */ 32 | public class RelatedMoviesAdapter extends RecyclerView.Adapter { 33 | 34 | private List mMovieItems; 35 | private Context mContext; 36 | private ImageLoader mImageLoader = AppController.getInstance().getImageLoader(); 37 | 38 | public RelatedMoviesAdapter(Context context, List movieItems) { 39 | mMovieItems = movieItems; 40 | mContext = context; 41 | } 42 | 43 | @Override 44 | public RelatedMoviesViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) { 45 | View view = LayoutInflater.from(mContext).inflate(R.layout.layout_movie_related_item, null, false); 46 | return new RelatedMoviesViewHolder(view); 47 | } 48 | 49 | @Override 50 | public void onBindViewHolder(RelatedMoviesViewHolder holder, int position) { 51 | final Movie movie = mMovieItems.get(position); 52 | if (movie.getPosterPath() != null) { 53 | String fullPosterPath = Endpoint.IMAGE + "/w185/" + movie.getPosterPath(); 54 | holder.thumbnail.setImageUrl(fullPosterPath, mImageLoader); 55 | holder.thumbnail.setErrorImageResId(R.drawable.error); 56 | } 57 | holder.setClickListener(new ItemClickListener() { 58 | @Override 59 | public void onClick(View view, int position) { 60 | startDetailsActivity(position); 61 | } 62 | }); 63 | } 64 | 65 | private void startDetailsActivity(int position) { 66 | List movieList = new ArrayList<>(mMovieItems.subList(position, mMovieItems.size())); 67 | Intent intent = new Intent(mContext, MovieDetailActivity.class); 68 | RecyclerListItem recyclerListItem = new RecyclerListItem(); 69 | recyclerListItem.setItems(movieList); 70 | intent.putExtra(BundleKey.EXTRA_MOVIE_LIST, recyclerListItem); 71 | mContext.startActivity(intent); 72 | } 73 | 74 | @Override 75 | public int getItemCount() { 76 | return mMovieItems.size(); 77 | } 78 | 79 | static class RelatedMoviesViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 80 | 81 | private ItemClickListener clickListener; 82 | 83 | @Bind(R.id.movie_related_thumbnail) 84 | protected FadeInNetworkImageView thumbnail; 85 | 86 | public RelatedMoviesViewHolder(View view) { 87 | super(view); 88 | ButterKnife.bind(this, view); 89 | view.setOnClickListener(this); 90 | } 91 | 92 | public void setClickListener(ItemClickListener itemClickListener) { 93 | this.clickListener = itemClickListener; 94 | } 95 | 96 | @Override 97 | public void onClick(View v) { 98 | this.clickListener.onClick(v, getPosition()); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/adapter/SmartFragmentStatePagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentStatePagerAdapter; 6 | import android.util.SparseArray; 7 | import android.view.ViewGroup; 8 | 9 | /* 10 | Extension of FragmentStatePagerAdapter which intelligently caches 11 | all active fragments and manages the fragment life-cycles. 12 | Usage involves extending from SmartFragmentStatePagerAdapter as you would any other PagerAdapter. 13 | */ 14 | public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerAdapter { 15 | // Sparse array to keep track of registered fragments in memory 16 | private SparseArray registeredFragments = new SparseArray<>(); 17 | 18 | public SmartFragmentStatePagerAdapter(FragmentManager fragmentManager) { 19 | super(fragmentManager); 20 | } 21 | 22 | // Register the fragment when the item is instantiated 23 | @Override 24 | public Object instantiateItem(ViewGroup container, int position) { 25 | Fragment fragment = (Fragment) super.instantiateItem(container, position); 26 | registeredFragments.put(position, fragment); 27 | return fragment; 28 | } 29 | 30 | // Unregister when the item is inactive 31 | @Override 32 | public void destroyItem(ViewGroup container, int position, Object object) { 33 | registeredFragments.remove(position); 34 | super.destroyItem(container, position, object); 35 | } 36 | 37 | // Returns the fragment for the position (if instantiated) 38 | public Fragment getRegisteredFragment(int position) { 39 | return registeredFragments.get(position); 40 | } 41 | } -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/adapter/TrailerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.adapter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | 11 | import com.android.msahakyan.nestedrecycler.R; 12 | import com.android.msahakyan.nestedrecycler.activity.TrailerActivity; 13 | import com.android.msahakyan.nestedrecycler.application.AppController; 14 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 15 | import com.android.msahakyan.nestedrecycler.common.ItemClickListener; 16 | import com.android.msahakyan.nestedrecycler.model.Trailer; 17 | import com.android.msahakyan.nestedrecycler.net.Endpoint; 18 | import com.android.msahakyan.nestedrecycler.view.FadeInNetworkImageView; 19 | import com.android.volley.toolbox.ImageLoader; 20 | 21 | import java.util.List; 22 | 23 | import butterknife.Bind; 24 | import butterknife.ButterKnife; 25 | 26 | /** 27 | * @author msahakyan 28 | *

29 | * Movie trailers adapter 30 | */ 31 | public class TrailerAdapter extends RecyclerView.Adapter { 32 | 33 | private List mTrailerList; 34 | private Context mContext; 35 | 36 | public TrailerAdapter(Context context, List movieTrailers) { 37 | mTrailerList = movieTrailers; 38 | mContext = context; 39 | } 40 | 41 | @Override 42 | public TrailerViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) { 43 | View view = LayoutInflater.from(mContext).inflate(R.layout.layout_trailer_item, null, false); 44 | return new TrailerViewHolder(view); 45 | } 46 | 47 | @Override 48 | public void onBindViewHolder(TrailerViewHolder holder, int position) { 49 | final Trailer trailer = mTrailerList.get(position); 50 | if (trailer != null) { 51 | ImageLoader imageLoader = AppController.getInstance().getImageLoader(); 52 | holder.trailerThumbnail.setImageUrl(getYoutubeThmbUrl(trailer.getSource()), imageLoader); 53 | holder.trailerName.setText(trailer.getName()); 54 | } 55 | holder.setClickListener(new ItemClickListener() { 56 | @Override 57 | public void onClick(View view, int position) { 58 | startTrailerActivity(trailer); 59 | } 60 | }); 61 | } 62 | 63 | private String getYoutubeThmbUrl(String source) { 64 | return Endpoint.YOUTUBE_THUMBNAIL + source + "/mqdefault.jpg"; 65 | } 66 | 67 | private void startTrailerActivity(Trailer trailer) { 68 | Intent intent = new Intent(mContext, TrailerActivity.class); 69 | intent.putExtra(BundleKey.EXTRA_TRAILER_ID, trailer.getSource()); 70 | mContext.startActivity(intent); 71 | } 72 | 73 | @Override 74 | public int getItemCount() { 75 | return mTrailerList.size(); 76 | } 77 | 78 | static class TrailerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 79 | 80 | private ItemClickListener clickListener; 81 | 82 | @Bind(R.id.movie_trailer_thumbnail) 83 | protected FadeInNetworkImageView trailerThumbnail; 84 | 85 | @Bind(R.id.movie_trailer_name) 86 | protected TextView trailerName; 87 | 88 | public TrailerViewHolder(View view) { 89 | super(view); 90 | ButterKnife.bind(this, view); 91 | view.setOnClickListener(this); 92 | } 93 | 94 | public void setClickListener(ItemClickListener itemClickListener) { 95 | this.clickListener = itemClickListener; 96 | } 97 | 98 | @Override 99 | public void onClick(View v) { 100 | this.clickListener.onClick(v, getPosition()); 101 | } 102 | } 103 | } 104 | 105 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/application/AppController.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.application; 2 | 3 | /** 4 | * @author msahakyan 5 | */ 6 | 7 | import android.app.Application; 8 | import android.text.TextUtils; 9 | 10 | import com.android.msahakyan.nestedrecycler.cache.BitmapLruCache; 11 | import com.android.volley.Request; 12 | import com.android.volley.RequestQueue; 13 | import com.android.volley.toolbox.ImageLoader; 14 | import com.android.volley.toolbox.Volley; 15 | 16 | public class AppController extends Application { 17 | 18 | public static final String TAG = AppController.class 19 | .getSimpleName(); 20 | 21 | private RequestQueue mRequestQueue; 22 | private ImageLoader mImageLoader; 23 | 24 | private static AppController mInstance; 25 | 26 | @Override 27 | public void onCreate() { 28 | super.onCreate(); 29 | mInstance = this; 30 | } 31 | 32 | public static synchronized AppController getInstance() { 33 | return mInstance; 34 | } 35 | 36 | public RequestQueue getRequestQueue() { 37 | if (mRequestQueue == null) { 38 | mRequestQueue = Volley.newRequestQueue(getApplicationContext()); 39 | } 40 | 41 | return mRequestQueue; 42 | } 43 | 44 | public ImageLoader getImageLoader() { 45 | getRequestQueue(); 46 | if (mImageLoader == null) { 47 | mImageLoader = new ImageLoader(this.mRequestQueue, 48 | BitmapLruCache.getInstance()); 49 | } 50 | return this.mImageLoader; 51 | } 52 | 53 | public void addToRequestQueue(Request req, String tag) { 54 | // set the default tag if tag is empty 55 | req.setTag(TextUtils.isEmpty(tag) ? TAG : tag); 56 | getRequestQueue().add(req); 57 | } 58 | 59 | public void addToRequestQueue(Request req) { 60 | addToRequestQueue(req, null); 61 | } 62 | 63 | public void cancelPendingRequests(Object tag) { 64 | if (mRequestQueue != null) { 65 | mRequestQueue.cancelAll(tag); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/cache/BitmapLruCache.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.cache; 2 | 3 | import android.graphics.Bitmap; 4 | import android.support.v4.util.LruCache; 5 | 6 | import com.android.volley.toolbox.ImageLoader.ImageCache; 7 | 8 | public class BitmapLruCache extends LruCache implements ImageCache { 9 | 10 | private static BitmapLruCache sInstance; 11 | 12 | public static BitmapLruCache getInstance() { 13 | if (sInstance == null) { 14 | sInstance = new BitmapLruCache(getDefaultLruCacheSize()); 15 | } 16 | return sInstance; 17 | } 18 | 19 | public static int getDefaultLruCacheSize() { 20 | final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); 21 | final int cacheSize = maxMemory / 8; 22 | 23 | return cacheSize; 24 | } 25 | 26 | private BitmapLruCache(int sizeInKiloBytes) { 27 | super(sizeInKiloBytes); 28 | } 29 | 30 | @Override 31 | protected int sizeOf(String key, Bitmap value) { 32 | return value.getRowBytes() * value.getHeight() / 1024; 33 | } 34 | 35 | @Override 36 | public Bitmap getBitmap(String url) { 37 | return get(url); 38 | } 39 | 40 | @Override 41 | public void putBitmap(String url, Bitmap bitmap) { 42 | put(url, bitmap); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/BundleKey.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | /** 4 | * @author msahakyan 5 | */ 6 | public interface BundleKey { 7 | 8 | String EXTRA_MOVIE = "extra_movie"; 9 | String EXTRA_MOVIE_LIST = "extra_movie_list"; 10 | String EXTRA_TRAILER_ID = "extra_trailer_id"; 11 | String EXTRA_NOTIFICATION = "extra_notification"; 12 | String EXTRA_MOVIE_ID = "extra_movie_id"; 13 | String HAS_NEXT = "has_next"; 14 | String HAS_PREVIOUS = "has_previous"; 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/DepthPageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.view.View; 5 | 6 | public class DepthPageTransformer implements ViewPager.PageTransformer { 7 | private static final float MIN_SCALE = 0.75f; 8 | 9 | public void transformPage(View view, float position) { 10 | int pageWidth = view.getWidth(); 11 | 12 | if (position < -1) { // [-Infinity,-1) 13 | // This page is way off-screen to the left. 14 | view.setAlpha(0); 15 | 16 | } else if (position <= 0) { // [-1,0] 17 | // Use the default slide transition when moving to the left page 18 | view.setAlpha(1); 19 | view.setTranslationX(0); 20 | view.setScaleX(1); 21 | view.setScaleY(1); 22 | 23 | } else if (position <= 1) { // (0,1] 24 | // Fade the page out. 25 | view.setAlpha(1 - position); 26 | 27 | // Counteract the default slide transition 28 | view.setTranslationX(pageWidth * -position); 29 | 30 | // Scale the page down (between MIN_SCALE and 1) 31 | float scaleFactor = MIN_SCALE 32 | + (1 - MIN_SCALE) * (1 - Math.abs(position)); 33 | view.setScaleX(scaleFactor); 34 | view.setScaleY(scaleFactor); 35 | 36 | } else { // (1,+Infinity] 37 | // This page is way off-screen to the right. 38 | view.setAlpha(0); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/Helper.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | 7 | import java.util.Collection; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by msahakyan on 05/12/15. 12 | */ 13 | public class Helper { 14 | 15 | public static AlertDialog createConfirmationDialog(Context context, int titleResId, int messageResId, 16 | int positiveBtnResId, int negativeBtnResId, final ConfirmationCallback callback) { 17 | return new AlertDialog.Builder(context) 18 | .setIcon(android.R.drawable.ic_dialog_alert) 19 | .setTitle(context.getString(titleResId)) 20 | .setMessage(context.getString(messageResId)) 21 | .setPositiveButton(context.getString(positiveBtnResId), new DialogInterface.OnClickListener() { 22 | @Override 23 | public void onClick(DialogInterface dialog, int which) { 24 | callback.onConfirm(); 25 | } 26 | }) 27 | .setNegativeButton(context.getString(negativeBtnResId), new DialogInterface.OnClickListener() { 28 | @Override 29 | public void onClick(DialogInterface dialog, int which) { 30 | callback.onCancel(); 31 | } 32 | }).show(); 33 | } 34 | 35 | /** 36 | * Returns comma separated values for the given list of ids 37 | * 38 | * @param genreIds 39 | * @return java.lang.String 40 | */ 41 | public static String getCsvGenreIds(List genreIds) { 42 | if (isEmpty(genreIds)) { 43 | return null; 44 | } 45 | StringBuilder output = new StringBuilder(); 46 | for (Integer id : genreIds) { 47 | output.append(id).append(","); 48 | } 49 | output.deleteCharAt(output.length() -1); 50 | 51 | return output.toString(); 52 | } 53 | 54 | /** 55 | * Helper interface 56 | */ 57 | public interface ConfirmationCallback { 58 | /** 59 | * Called on confirmation 60 | */ 61 | public void onConfirm(); 62 | 63 | /** 64 | * Called on cancellation 65 | */ 66 | public void onCancel(); 67 | } 68 | 69 | public static boolean isEmpty(Collection collection) { 70 | return collection == null || collection.size() == 0; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/HorizontalItemDecorator.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | 7 | /** 8 | * @author msahakyan 9 | */ 10 | public class HorizontalItemDecorator extends RecyclerView.ItemDecoration { 11 | 12 | private final int mHorizontalSpaceWidth; 13 | 14 | public HorizontalItemDecorator(int horizontalSpaceHeight) { 15 | this.mHorizontalSpaceWidth = horizontalSpaceHeight; 16 | } 17 | 18 | @Override 19 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 20 | RecyclerView.State state) { 21 | outRect.left = outRect.right = mHorizontalSpaceWidth; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/ItemClickListener.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by msahakyan on 15/11/15. 7 | *

8 | * This interface will be overridden in viewHolder classes 9 | * to be able to call onClick method on corresponding recyclerView items 10 | */ 11 | public interface ItemClickListener { 12 | void onClick(View view, int position); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/PushNotification.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | import android.support.annotation.IntDef; 6 | 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | 10 | public class PushNotification implements Parcelable { 11 | 12 | private static final String TAG = PushNotification.class.getSimpleName(); 13 | public static final int PRIORITY_HIGH = 0; 14 | 15 | @IntDef 16 | @Retention(RetentionPolicy.SOURCE) 17 | public @interface PushPriority { 18 | } 19 | 20 | private long id; 21 | private String message; 22 | private String title; 23 | private String bigTitle; 24 | private String imageUrl; 25 | private String iconUrl; 26 | private int priority; 27 | 28 | public PushNotification() { 29 | } 30 | 31 | protected PushNotification(Parcel in) { 32 | id = in.readLong(); 33 | message = in.readString(); 34 | title = in.readString(); 35 | bigTitle = in.readString(); 36 | imageUrl = in.readString(); 37 | iconUrl = in.readString(); 38 | priority = in.readInt(); 39 | } 40 | 41 | public static final Creator CREATOR = new Creator() { 42 | @Override 43 | public PushNotification createFromParcel(Parcel in) { 44 | return new PushNotification(in); 45 | } 46 | 47 | @Override 48 | public PushNotification[] newArray(int size) { 49 | return new PushNotification[size]; 50 | } 51 | }; 52 | 53 | @Override 54 | public int describeContents() { 55 | return 0; 56 | } 57 | 58 | @Override 59 | public void writeToParcel(Parcel dest, int flags) { 60 | dest.writeLong(id); 61 | dest.writeString(message); 62 | dest.writeString(title); 63 | dest.writeString(bigTitle); 64 | dest.writeString(imageUrl); 65 | dest.writeString(iconUrl); 66 | dest.writeInt(priority); 67 | } 68 | 69 | public long getId() { 70 | return id; 71 | } 72 | 73 | public void setId(long id) { 74 | this.id = id; 75 | } 76 | 77 | public String getMessage() { 78 | return message; 79 | } 80 | 81 | public void setMessage(String message) { 82 | this.message = message; 83 | } 84 | 85 | public String getTitle() { 86 | return title; 87 | } 88 | 89 | public void setTitle(String title) { 90 | this.title = title; 91 | } 92 | 93 | public String getBigTitle() { 94 | return bigTitle; 95 | } 96 | 97 | public void setBigTitle(String bigTitle) { 98 | this.bigTitle = bigTitle; 99 | } 100 | 101 | public String getImageUrl() { 102 | return imageUrl; 103 | } 104 | 105 | public void setImageUrl(String imageUrl) { 106 | this.imageUrl = imageUrl; 107 | } 108 | 109 | public String getIconUrl() { 110 | return iconUrl; 111 | } 112 | 113 | public void setIconUrl(String iconUrl) { 114 | this.iconUrl = iconUrl; 115 | } 116 | 117 | public int getPriority() { 118 | return priority; 119 | } 120 | 121 | public void setPriority(int priority) { 122 | this.priority = priority; 123 | } 124 | } -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/VerticalItemDecorator.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | 7 | /** 8 | * @author msahakyan 9 | */ 10 | public class VerticalItemDecorator extends RecyclerView.ItemDecoration { 11 | 12 | private final int mVerticalSpaceWidth; 13 | 14 | public VerticalItemDecorator(int verticalSpaceWidth) { 15 | this.mVerticalSpaceWidth = verticalSpaceWidth; 16 | } 17 | 18 | @Override 19 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 20 | RecyclerView.State state) { 21 | outRect.top = outRect.bottom = mVerticalSpaceWidth; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/ViewAnimator.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.view.View; 4 | import android.view.ViewGroup; 5 | import android.view.ViewGroup.LayoutParams; 6 | import android.view.animation.Animation; 7 | import android.view.animation.Transformation; 8 | import android.widget.ScrollView; 9 | 10 | /** 11 | * @author msahakyan 12 | */ 13 | public class ViewAnimator { 14 | 15 | private static final int ANIMATION_TIME = 1000; // milliseconds 16 | private int initialHeight; 17 | 18 | public void expand(final ViewGroup v) { 19 | v.measure(LayoutParams.MATCH_PARENT, initialHeight); 20 | final int targetHeight = initialHeight; 21 | v.getLayoutParams().height = 1; 22 | v.setVisibility(View.VISIBLE); 23 | Animation a = new Animation() { 24 | @Override 25 | protected void applyTransformation(float interpolatedTime, Transformation t) { 26 | ((ScrollView) v.getParent().getParent()).scrollTo(0, 5000); 27 | v.getLayoutParams().height = interpolatedTime == 1 28 | ? targetHeight 29 | : (int) (targetHeight * interpolatedTime); 30 | v.requestLayout(); 31 | } 32 | 33 | @Override 34 | public boolean willChangeBounds() { 35 | return true; 36 | } 37 | }; 38 | 39 | // 1dp/ms 40 | a.setDuration(ANIMATION_TIME); 41 | v.startAnimation(a); 42 | } 43 | 44 | public void collapse(final ViewGroup v) { 45 | initialHeight = v.getMeasuredHeight(); 46 | 47 | Animation a = new Animation() { 48 | @Override 49 | protected void applyTransformation(float interpolatedTime, Transformation t) { 50 | if (interpolatedTime == 1) { 51 | v.setVisibility(View.GONE); 52 | } else { 53 | v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime); 54 | v.requestLayout(); 55 | } 56 | } 57 | 58 | @Override 59 | public boolean willChangeBounds() { 60 | return true; 61 | } 62 | }; 63 | 64 | // 1dp/ms 65 | a.setDuration(ANIMATION_TIME); 66 | v.startAnimation(a); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/ZoomOutPageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.view.View; 5 | 6 | public class ZoomOutPageTransformer implements ViewPager.PageTransformer { 7 | private static final float MIN_SCALE = 0.85f; 8 | private static final float MIN_ALPHA = 0.5f; 9 | 10 | public void transformPage(View view, float position) { 11 | int pageWidth = view.getWidth(); 12 | int pageHeight = view.getHeight(); 13 | 14 | if (position < -1) { // [-Infinity,-1) 15 | // This page is way off-screen to the left. 16 | view.setAlpha(0); 17 | 18 | } else if (position <= 1) { // [-1,1] 19 | // Modify the default slide transition to shrink the page as well 20 | float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); 21 | float vertMargin = pageHeight * (1 - scaleFactor) / 2; 22 | float horzMargin = pageWidth * (1 - scaleFactor) / 2; 23 | if (position < 0) { 24 | view.setTranslationX(horzMargin - vertMargin / 2); 25 | } else { 26 | view.setTranslationX(-horzMargin + vertMargin / 2); 27 | } 28 | 29 | // Scale the page down (between MIN_SCALE and 1) 30 | view.setScaleX(scaleFactor); 31 | view.setScaleY(scaleFactor); 32 | 33 | // Fade the page relative to its size. 34 | view.setAlpha(MIN_ALPHA + 35 | (scaleFactor - MIN_SCALE) / 36 | (1 - MIN_SCALE) * (1 - MIN_ALPHA)); 37 | 38 | } else { // (1,+Infinity] 39 | // This page is way off-screen to the right. 40 | view.setAlpha(0); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/common/abtest/ABTestConfig.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.common.abtest; 2 | 3 | import android.content.Context; 4 | import android.content.res.AssetManager; 5 | import android.content.res.Resources; 6 | 7 | import com.amazon.insights.AmazonInsights; 8 | import com.amazon.insights.InsightsCredentials; 9 | 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | import java.util.Properties; 13 | 14 | /** 15 | * Created by msahakyan on 05/12/15. 16 | */ 17 | public class ABTestConfig { 18 | 19 | private AmazonInsights sInstance; 20 | 21 | /** 22 | * Returns singleton instance of AmazonInsights 23 | * 24 | * @param context 25 | * @return {com.amazon.insights.AmazonInsights} 26 | */ 27 | public AmazonInsights getInstance(Context context) { 28 | if (sInstance == null) { 29 | final InsightsCredentials credentials = getCredentials(context); 30 | sInstance = AmazonInsights.newInstance(credentials, context.getApplicationContext()); 31 | } 32 | 33 | return sInstance; 34 | } 35 | 36 | /** 37 | * Returns instance of InsightsCredentials 38 | * 39 | * @param context 40 | * @return {com.amazon.insights.InsightsCredentials} 41 | */ 42 | private InsightsCredentials getCredentials(Context context) { 43 | // Create a credentials object using the keys from the 44 | // Amazon Apps & Games Developer Portal's A/B Testing site. 45 | String[] amazonCreds = loadCredentials(context); 46 | return AmazonInsights.newCredentials(amazonCreds[0], amazonCreds[1]); 47 | } 48 | 49 | /** 50 | * Loads Amazon credentials from properties file 51 | * 52 | * @return {String[]} 53 | */ 54 | private String[] loadCredentials(Context context) { 55 | 56 | Resources resources = context.getResources(); 57 | AssetManager assetManager = resources.getAssets(); 58 | String[] creds = new String[2]; 59 | 60 | // Read from the /assets directory 61 | try { 62 | InputStream inputStream = assetManager.open("amazon.properties"); 63 | Properties properties = new Properties(); 64 | properties.load(inputStream); 65 | 66 | String publicKey = properties.getProperty("public_key"); 67 | String privateKey = properties.getProperty("private_key"); 68 | 69 | creds[0] = publicKey; 70 | creds[1] = privateKey; 71 | 72 | } catch (IOException e) { 73 | System.err.println("Failed get property file"); 74 | e.printStackTrace(); 75 | } 76 | 77 | return creds; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/config/Config.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.config; 2 | 3 | /** 4 | * @author msahakyan 5 | */ 6 | public interface Config { 7 | // Google Console APIs developer key 8 | // Replace this key with your's 9 | String DEVELOPER_KEY = "AIzaSyABYoczeHg4XABx_jMRfv-CqmA2YMsIY4A"; 10 | String API_KEY = "746bcc0040f68b8af9d569f27443901f"; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/fragment/MovieDetailFragment.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.view.ViewPager; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.text.TextUtils; 9 | import android.util.Log; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.view.animation.TranslateAnimation; 14 | import android.widget.ImageView; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.android.msahakyan.nestedrecycler.R; 19 | import com.android.msahakyan.nestedrecycler.adapter.BackdropPagerAdapter; 20 | import com.android.msahakyan.nestedrecycler.adapter.TrailerAdapter; 21 | import com.android.msahakyan.nestedrecycler.common.BundleKey; 22 | import com.android.msahakyan.nestedrecycler.common.DepthPageTransformer; 23 | import com.android.msahakyan.nestedrecycler.common.Helper; 24 | import com.android.msahakyan.nestedrecycler.common.VerticalItemDecorator; 25 | import com.android.msahakyan.nestedrecycler.config.Config; 26 | import com.android.msahakyan.nestedrecycler.model.Backdrop; 27 | import com.android.msahakyan.nestedrecycler.model.ImageListParser; 28 | import com.android.msahakyan.nestedrecycler.model.Movie; 29 | import com.android.msahakyan.nestedrecycler.model.Trailer; 30 | import com.android.msahakyan.nestedrecycler.model.TrailerListParser; 31 | import com.android.msahakyan.nestedrecycler.net.Endpoint; 32 | import com.android.msahakyan.nestedrecycler.net.NetworkRequestListener; 33 | import com.android.msahakyan.nestedrecycler.net.NetworkUtilsImpl; 34 | import com.android.volley.Request; 35 | import com.android.volley.VolleyError; 36 | import com.github.rahatarmanahmed.cpv.CircularProgressView; 37 | import com.google.gson.Gson; 38 | import com.viewpagerindicator.CirclePageIndicator; 39 | 40 | import org.json.JSONObject; 41 | 42 | import java.util.ArrayList; 43 | import java.util.HashMap; 44 | import java.util.List; 45 | import java.util.Map; 46 | 47 | import butterknife.Bind; 48 | import butterknife.ButterKnife; 49 | 50 | 51 | /** 52 | * @author msahakyan 53 | */ 54 | public class MovieDetailFragment extends Fragment { 55 | 56 | private static final String TAG = MovieDetailFragment.class.getSimpleName(); 57 | private static final int PAGE_LIMIT = 25; 58 | 59 | @Bind(R.id.backdrops_pager) 60 | protected ViewPager mBackdropsPager; 61 | 62 | @Bind(R.id.pager_indicator) 63 | protected CirclePageIndicator mPagerIndicator; 64 | 65 | @Bind(R.id.movie_detail_title) 66 | protected TextView movieTitle; 67 | 68 | @Bind(R.id.movie_detail_date) 69 | protected TextView movieDate; 70 | 71 | @Bind(R.id.movie_detail_vote_average) 72 | protected TextView movieVoteAverage; 73 | 74 | @Bind(R.id.movie_detail_description) 75 | protected TextView movieDescription; 76 | 77 | @Bind(R.id.progress_view) 78 | protected CircularProgressView progressView; 79 | 80 | @Bind(R.id.movie_detail_trailer_recycler) 81 | protected RecyclerView mTrailerRecycler; 82 | 83 | @Bind(R.id.label_trailers) 84 | protected TextView mTrailersLabel; 85 | 86 | @Bind(R.id.ic_arrow) 87 | protected ImageView mIconArrow; 88 | 89 | private String mEndpoint; 90 | private Map mUrlParams; 91 | 92 | private Movie mCurrentMovie; 93 | 94 | public MovieDetailFragment() { 95 | } 96 | 97 | public static MovieDetailFragment newInstance() { 98 | return new MovieDetailFragment(); 99 | } 100 | 101 | @Override 102 | public void onCreate(Bundle savedInstanceState) { 103 | super.onCreate(savedInstanceState); 104 | } 105 | 106 | @Override 107 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 108 | Bundle savedInstanceState) { 109 | // Inflate the layout for this fragment 110 | View view = inflater.inflate(R.layout.fragment_movie_detail, container, false); 111 | ButterKnife.bind(this, view); 112 | 113 | mTrailerRecycler.setLayoutManager(new LinearLayoutManager(getActivity())); 114 | mTrailerRecycler.addItemDecoration(new VerticalItemDecorator((int) getActivity().getResources().getDimension(R.dimen.padding_size_large))); 115 | 116 | mCurrentMovie = getMovieFromArguments(); 117 | if (mCurrentMovie != null) { 118 | loadBackdrops(mCurrentMovie.getId()); 119 | loadTrailers(mCurrentMovie.getId()); 120 | } else { 121 | Log.w(TAG, "Can't load movies from intent"); 122 | } 123 | setupAnimation(); 124 | 125 | return view; 126 | } 127 | 128 | private void setupAnimation() { 129 | TranslateAnimation animation = new TranslateAnimation(0.0f, 30.0f, 0.0f, 0.0f); 130 | animation.setDuration(500); 131 | animation.setRepeatCount(Integer.MAX_VALUE); 132 | animation.setRepeatMode(2); 133 | animation.setFillAfter(true); 134 | if (hasNextPage()) { 135 | mIconArrow.setVisibility(View.VISIBLE); 136 | mIconArrow.startAnimation(animation); 137 | } else { 138 | mIconArrow.setVisibility(View.GONE); 139 | mIconArrow.clearAnimation(); 140 | } 141 | } 142 | 143 | private void loadBackdrops(long movieId) { 144 | initEndpointAndUrlParams(movieId); 145 | progressView.startAnimation(); 146 | progressView.setVisibility(View.VISIBLE); 147 | 148 | new NetworkUtilsImpl().executeJsonRequest(Request.Method.GET, new StringBuilder(mEndpoint), 149 | mUrlParams, new NetworkRequestListener() { 150 | @Override 151 | public void onSuccess(JSONObject jsonResponse) { 152 | progressView.clearAnimation(); 153 | progressView.setVisibility(View.GONE); 154 | List backdropList = new Gson().fromJson(jsonResponse.toString(), ImageListParser.class).getBackdrops(); 155 | 156 | if (!Helper.isEmpty(backdropList)) { 157 | if (backdropList.size() > PAGE_LIMIT) { 158 | backdropList = backdropList.subList(0, PAGE_LIMIT); 159 | } 160 | mBackdropsPager.setPageTransformer(false, new DepthPageTransformer()); 161 | } else { 162 | // Show poster if there are no any available backdrops 163 | backdropList = new ArrayList<>(1); 164 | Backdrop poster = new Backdrop(); 165 | poster.setFilePath(mCurrentMovie.getPosterPath()); 166 | backdropList.add(poster); 167 | } 168 | BackdropPagerAdapter mPagerAdapter = new BackdropPagerAdapter(getActivity(), backdropList); 169 | mBackdropsPager.setAdapter(mPagerAdapter); 170 | mBackdropsPager.setPageTransformer(false, new DepthPageTransformer()); 171 | mPagerIndicator.setViewPager(mBackdropsPager); 172 | } 173 | 174 | @Override 175 | public void onError(VolleyError error) { 176 | progressView.clearAnimation(); 177 | progressView.setVisibility(View.GONE); 178 | Toast.makeText(getActivity(), "Error: " + error.getMessage(), Toast.LENGTH_SHORT).show(); 179 | } 180 | }); 181 | } 182 | 183 | private void loadTrailers(long movieId) { 184 | String endpoint = Endpoint.MOVIE + movieId; 185 | Map urlParams = new HashMap<>(); 186 | urlParams.put("api_key", Config.API_KEY); 187 | urlParams.put("append_to_response", "trailers"); 188 | 189 | progressView.startAnimation(); 190 | progressView.setVisibility(View.VISIBLE); 191 | new NetworkUtilsImpl().executeJsonRequest(Request.Method.GET, new StringBuilder(endpoint), 192 | urlParams, new NetworkRequestListener() { 193 | @Override 194 | public void onSuccess(JSONObject jsonResponse) { 195 | progressView.clearAnimation(); 196 | progressView.setVisibility(View.GONE); 197 | List trailerList = new Gson().fromJson(jsonResponse.toString(), TrailerListParser.class).getTrailerList(); 198 | if (!Helper.isEmpty(trailerList)) { 199 | mTrailersLabel.setVisibility(View.VISIBLE); 200 | mTrailerRecycler.setVisibility(View.VISIBLE); 201 | TrailerAdapter trailerAdapter = new TrailerAdapter(getActivity(), trailerList); 202 | mTrailerRecycler.setAdapter(trailerAdapter); 203 | trailerAdapter.notifyDataSetChanged(); 204 | } else { 205 | mTrailersLabel.setVisibility(View.GONE); 206 | mTrailerRecycler.setVisibility(View.GONE); 207 | } 208 | } 209 | 210 | @Override 211 | public void onError(VolleyError error) { 212 | progressView.clearAnimation(); 213 | progressView.setVisibility(View.GONE); 214 | mTrailersLabel.setVisibility(View.GONE); 215 | mTrailerRecycler.setVisibility(View.GONE); 216 | Toast.makeText(getActivity(), "Error: " + error.getMessage(), Toast.LENGTH_SHORT).show(); 217 | } 218 | }); 219 | } 220 | 221 | 222 | private void initEndpointAndUrlParams(long movieId) { 223 | mEndpoint = Endpoint.MOVIE + movieId + "/images"; 224 | mUrlParams = new HashMap<>(); 225 | mUrlParams.put("api_key", Config.API_KEY); 226 | } 227 | 228 | private Movie getMovieFromArguments() { 229 | Movie movie = null; 230 | if (getArguments().containsKey(BundleKey.EXTRA_MOVIE)) { 231 | movie = (Movie) getArguments().getSerializable(BundleKey.EXTRA_MOVIE); 232 | if (movie != null) { 233 | movieTitle.setText(movie.getTitle()); 234 | movieDate.setText(movie.getReleaseDate()); 235 | movieVoteAverage.setText(String.valueOf(movie.getVoteAverage())); 236 | movieDescription.setText(!TextUtils.isEmpty(movie.getOverview()) ? 237 | movie.getOverview() : getString(R.string.no_description_available)); 238 | } 239 | } 240 | return movie; 241 | } 242 | 243 | private boolean hasNextPage() { 244 | return getArguments().getBoolean(BundleKey.HAS_NEXT, false); 245 | } 246 | 247 | private boolean hasPreviousPage() { 248 | return getArguments().getBoolean(BundleKey.HAS_PREVIOUS, false); 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/Backdrop.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.google.gson.annotations.SerializedName; 7 | 8 | /** 9 | * @author msahakyan 10 | */ 11 | public class Backdrop implements Parcelable { 12 | 13 | public String getFilePath() { 14 | return filePath; 15 | } 16 | 17 | public void setFilePath(String filePath) { 18 | this.filePath = filePath; 19 | } 20 | 21 | public int getVoteCount() { 22 | return voteCount; 23 | } 24 | 25 | public void setVoteCount(int voteCount) { 26 | this.voteCount = voteCount; 27 | } 28 | 29 | public double getCoteAverage() { 30 | return coteAverage; 31 | } 32 | 33 | public void setCoteAverage(double coteAverage) { 34 | this.coteAverage = coteAverage; 35 | } 36 | 37 | @SerializedName("file_path") 38 | private String filePath; 39 | 40 | @SerializedName("vote_count") 41 | private int voteCount; 42 | 43 | @SerializedName("vote_average") 44 | private double coteAverage; 45 | 46 | public Backdrop() { 47 | } 48 | 49 | protected Backdrop(Parcel in) { 50 | filePath = in.readString(); 51 | voteCount = in.readInt(); 52 | coteAverage = in.readDouble(); 53 | } 54 | 55 | public static final Creator CREATOR = new Creator() { 56 | @Override 57 | public Backdrop createFromParcel(Parcel in) { 58 | return new Backdrop(in); 59 | } 60 | 61 | @Override 62 | public Backdrop[] newArray(int size) { 63 | return new Backdrop[size]; 64 | } 65 | }; 66 | 67 | @Override 68 | public int describeContents() { 69 | return 0; 70 | } 71 | 72 | @Override 73 | public void writeToParcel(Parcel dest, int flags) { 74 | dest.writeString(filePath); 75 | dest.writeInt(voteCount); 76 | dest.writeDouble(coteAverage); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/ImageListParser.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author msahakyan 9 | */ 10 | public class ImageListParser { 11 | 12 | @SerializedName("id") 13 | private long id; 14 | 15 | @SerializedName("backdrops") 16 | private List backdrops; 17 | 18 | public long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(long id) { 23 | this.id = id; 24 | } 25 | 26 | public void setBackdrops(List backdrops) { 27 | this.backdrops = backdrops; 28 | } 29 | 30 | public List getBackdrops() { 31 | return backdrops; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/Movie.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author msahakyan 9 | */ 10 | public class Movie implements RecyclerItem { 11 | 12 | @SerializedName("poster_path") 13 | private String posterPath; 14 | 15 | @SerializedName("adult") 16 | private boolean adult; 17 | 18 | @SerializedName("overview") 19 | private String overview; 20 | 21 | @SerializedName("release_date") 22 | private String releaseDate; 23 | 24 | @SerializedName("genre_ids") 25 | private List genreIds; 26 | 27 | @SerializedName("id") 28 | private long id; 29 | 30 | @SerializedName("original_title") 31 | private String originalTitle; 32 | 33 | @SerializedName("original_language") 34 | private String originalLanguage; 35 | 36 | @SerializedName("title") 37 | private String title; 38 | 39 | @SerializedName("backdrop_path") 40 | private String backdropPath; 41 | 42 | @SerializedName("popularity") 43 | private double popularity; 44 | 45 | @SerializedName("vote_count") 46 | private int voteCount; 47 | 48 | @SerializedName("video") 49 | private boolean video; 50 | 51 | @SerializedName("vote_average") 52 | private double voteAverage; 53 | 54 | public String getPosterPath() { 55 | return posterPath; 56 | } 57 | 58 | public void setPosterPath(String posterPath) { 59 | this.posterPath = posterPath; 60 | } 61 | 62 | public boolean isAdult() { 63 | return adult; 64 | } 65 | 66 | public void setAdult(boolean adult) { 67 | this.adult = adult; 68 | } 69 | 70 | public String getOverview() { 71 | return overview; 72 | } 73 | 74 | public void setOverview(String overview) { 75 | this.overview = overview; 76 | } 77 | 78 | public String getReleaseDate() { 79 | return releaseDate; 80 | } 81 | 82 | public void setReleaseDate(String releaseDate) { 83 | this.releaseDate = releaseDate; 84 | } 85 | 86 | public List getGenreIds() { 87 | return genreIds; 88 | } 89 | 90 | public void setGenreIds(List genreIds) { 91 | this.genreIds = genreIds; 92 | } 93 | 94 | public long getId() { 95 | return id; 96 | } 97 | 98 | public void setId(long id) { 99 | this.id = id; 100 | } 101 | 102 | public String getOriginalTitle() { 103 | return originalTitle; 104 | } 105 | 106 | public void setOriginalTitle(String originalTitle) { 107 | this.originalTitle = originalTitle; 108 | } 109 | 110 | public String getOriginalLanguage() { 111 | return originalLanguage; 112 | } 113 | 114 | public void setOriginalLanguage(String originalLanguage) { 115 | this.originalLanguage = originalLanguage; 116 | } 117 | 118 | public String getTitle() { 119 | return title; 120 | } 121 | 122 | public void setTitle(String title) { 123 | this.title = title; 124 | } 125 | 126 | public String getBackdropPath() { 127 | return backdropPath; 128 | } 129 | 130 | public void setBackdropPath(String backdropPath) { 131 | this.backdropPath = backdropPath; 132 | } 133 | 134 | public double getPopularity() { 135 | return popularity; 136 | } 137 | 138 | public void setPopularity(double popularity) { 139 | this.popularity = popularity; 140 | } 141 | 142 | public int getVoteCount() { 143 | return voteCount; 144 | } 145 | 146 | public void setVoteCount(int voteCount) { 147 | this.voteCount = voteCount; 148 | } 149 | 150 | public boolean isVideo() { 151 | return video; 152 | } 153 | 154 | public void setVideo(boolean video) { 155 | this.video = video; 156 | } 157 | 158 | public double getVoteAverage() { 159 | return voteAverage; 160 | } 161 | 162 | public void setVoteAverage(int voteAverage) { 163 | this.voteAverage = voteAverage; 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/MovieListParser.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author msahakyan 9 | */ 10 | public class MovieListParser { 11 | 12 | @SerializedName("page") 13 | private int page; 14 | 15 | @SerializedName("results") 16 | private List results; 17 | 18 | @SerializedName("total_results") 19 | private int totalResults; 20 | 21 | @SerializedName("total_pages") 22 | private int totalPages; 23 | 24 | public int getPage() { 25 | return page; 26 | } 27 | 28 | public void setPage(int page) { 29 | this.page = page; 30 | } 31 | 32 | public List getResults() { 33 | return results; 34 | } 35 | 36 | public void setResults(List results) { 37 | this.results = results; 38 | } 39 | 40 | public int getTotalResults() { 41 | return totalResults; 42 | } 43 | 44 | public void setTotalResults(int totalResults) { 45 | this.totalResults = totalResults; 46 | } 47 | 48 | public int getTotalPages() { 49 | return totalPages; 50 | } 51 | 52 | public void setTotalPages(int totalPages) { 53 | this.totalPages = totalPages; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/RecyclerItem.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * @author msahakyan 8 | * Common interface for both type of items which are using in current project 9 | */ 10 | public interface RecyclerItem extends Serializable { 11 | List getGenreIds(); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/RecyclerListItem.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * @author msahakyan 8 | */ 9 | public class RecyclerListItem implements Serializable { 10 | 11 | private List items; 12 | 13 | public List getItems() { 14 | return items; 15 | } 16 | 17 | public void setItems(List items) { 18 | this.items = items; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/RelatedMoviesItem.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author msahakyan 7 | */ 8 | public class RelatedMoviesItem implements RecyclerItem { 9 | 10 | private List relatedMovieList; 11 | 12 | public List getRelatedMovieList() { 13 | return relatedMovieList; 14 | } 15 | 16 | public void setRelatedMovieList(List relatedMovieList) { 17 | this.relatedMovieList = relatedMovieList; 18 | } 19 | 20 | @Override 21 | public List getGenreIds() { 22 | return null; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/Trailer.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * @author msahakyan 8 | */ 9 | public class Trailer implements Parcelable { 10 | 11 | private String name; 12 | private String size; //example: "Standard" 13 | private String source; //example: "9NfCuPiUxcw" 14 | private String type; //example: "Trailer" 15 | 16 | protected Trailer(Parcel in) { 17 | name = in.readString(); 18 | size = in.readString(); 19 | source = in.readString(); 20 | type = in.readString(); 21 | } 22 | 23 | public static final Creator CREATOR = new Creator() { 24 | @Override 25 | public Trailer createFromParcel(Parcel in) { 26 | return new Trailer(in); 27 | } 28 | 29 | @Override 30 | public Trailer[] newArray(int size) { 31 | return new Trailer[size]; 32 | } 33 | }; 34 | 35 | @Override 36 | public int describeContents() { 37 | return 0; 38 | } 39 | 40 | @Override 41 | public void writeToParcel(Parcel dest, int flags) { 42 | dest.writeString(name); 43 | dest.writeString(size); 44 | dest.writeString(source); 45 | dest.writeString(type); 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public void setName(String name) { 53 | this.name = name; 54 | } 55 | 56 | public String getSize() { 57 | return size; 58 | } 59 | 60 | public void setSize(String size) { 61 | this.size = size; 62 | } 63 | 64 | public String getSource() { 65 | return source; 66 | } 67 | 68 | public void setSource(String source) { 69 | this.source = source; 70 | } 71 | 72 | public String getType() { 73 | return type; 74 | } 75 | 76 | public void setType(String type) { 77 | this.type = type; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/model/TrailerListParser.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.model; 2 | 3 | import com.google.gson.annotations.SerializedName; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * @author msahakyan 9 | */ 10 | public class TrailerListParser { 11 | 12 | @SerializedName("trailers") 13 | private TrailerObj trailerObj; 14 | 15 | public TrailerObj getTrailers() { 16 | return trailerObj; 17 | } 18 | 19 | public void setTrailerObj(TrailerObj trailerObj) { 20 | this.trailerObj = trailerObj; 21 | } 22 | 23 | public List getTrailerList() { 24 | return this.trailerObj.getTrailerList(); 25 | } 26 | } 27 | 28 | class TrailerObj { 29 | 30 | @SerializedName("youtube") 31 | private List trailerList; 32 | 33 | public List getTrailerList() { 34 | return trailerList; 35 | } 36 | 37 | public void setTrailerList(List trailerList) { 38 | this.trailerList = trailerList; 39 | } 40 | } -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/net/CustomRetryPolicy.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.net; 2 | 3 | import com.android.volley.DefaultRetryPolicy; 4 | import com.android.volley.VolleyError; 5 | 6 | import java.net.HttpURLConnection; 7 | 8 | /** 9 | * @author msahakyan 10 | */ 11 | public class CustomRetryPolicy extends DefaultRetryPolicy { 12 | 13 | public CustomRetryPolicy(int initialTimeoutMs, int maxNumRetries, float backoffMultiplier) { 14 | super(initialTimeoutMs, maxNumRetries, backoffMultiplier); 15 | } 16 | 17 | @Override 18 | public void retry(VolleyError error) throws VolleyError { 19 | if ((error.networkResponse.statusCode < HttpURLConnection.HTTP_INTERNAL_ERROR && 20 | error.networkResponse.statusCode != HttpURLConnection.HTTP_NOT_FOUND)) { 21 | throw error; 22 | } 23 | super.retry(error); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/net/Endpoint.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.net; 2 | 3 | /** 4 | * @author msahakyan 5 | */ 6 | public interface Endpoint { 7 | String DISCOVER = "http://api.themoviedb.org/3/discover/movie"; 8 | String SEARCH = "http://api.themoviedb.org/3/search/movie"; 9 | String MOVIE = "http://api.themoviedb.org/3/movie/"; 10 | String IMAGE = "http://image.tmdb.org/t/p"; 11 | String YOUTUBE_THUMBNAIL = "http://img.youtube.com/vi/"; 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/net/INetworkUtils.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.net; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Created by msahakyan on 23/12/15. 7 | */ 8 | public interface INetworkUtils { 9 | 10 | /** 11 | * Creates JsonRequest 12 | * 13 | * @param method 14 | * @param endpoint 15 | * @param urlParams 16 | * @param requestListener 17 | */ 18 | void executeJsonRequest(int method, StringBuilder endpoint, Map urlParams, NetworkRequestListener requestListener); 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/net/NetworkRequestListener.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.net; 2 | 3 | import com.android.volley.VolleyError; 4 | 5 | import org.json.JSONObject; 6 | 7 | /** 8 | * @author msahakyan 9 | */ 10 | public interface NetworkRequestListener { 11 | /** 12 | * Success callback 13 | * 14 | * @param jsonResponse 15 | */ 16 | void onSuccess(JSONObject jsonResponse); 17 | 18 | /** 19 | * Error callback 20 | * 21 | * @param error 22 | */ 23 | void onError(VolleyError error); 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/net/NetworkUtilsImpl.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.net; 2 | 3 | import com.android.msahakyan.nestedrecycler.application.AppController; 4 | import com.android.volley.Response; 5 | import com.android.volley.VolleyError; 6 | import com.android.volley.toolbox.JsonObjectRequest; 7 | 8 | import org.json.JSONObject; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * @author msahakyan 14 | */ 15 | public class NetworkUtilsImpl implements INetworkUtils { 16 | 17 | private static final int REQUEST_TIMEOUT = 5 * 1000; 18 | private static final int MAX_RETRIES = 3; 19 | private static final int BACKOFF_MULTIPLIER = 1; 20 | 21 | @Override 22 | public void executeJsonRequest(int method, StringBuilder endpoint, Map urlParams, final NetworkRequestListener requestListener) { 23 | if (urlParams != null) { 24 | int i = 0; 25 | for (Map.Entry entry : urlParams.entrySet()) { 26 | if (i == 0) { 27 | endpoint.append("?"); 28 | } else { 29 | endpoint.append("&"); 30 | } 31 | endpoint.append(entry.getKey()).append("=").append(entry.getValue()); 32 | i++; 33 | } 34 | } 35 | 36 | JsonObjectRequest jsonRequest = new JsonObjectRequest(method, endpoint.toString(), null, 37 | new Response.Listener() { 38 | @Override 39 | public void onResponse(JSONObject response) { 40 | requestListener.onSuccess(response); 41 | } 42 | }, 43 | new Response.ErrorListener() { 44 | @Override 45 | public void onErrorResponse(VolleyError error) { 46 | requestListener.onError(error); 47 | } 48 | } 49 | ); 50 | 51 | jsonRequest.setRetryPolicy(new CustomRetryPolicy(REQUEST_TIMEOUT, MAX_RETRIES, BACKOFF_MULTIPLIER)); 52 | 53 | // Adding request to request queue 54 | AppController.getInstance().addToRequestQueue(jsonRequest); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/provider/SearchSuggestionsProvider.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.provider; 2 | 3 | import android.content.SearchRecentSuggestionsProvider; 4 | 5 | /** 6 | * Created by msahakyan on 08/12/15. 7 | * 8 | * Content provider for recent query suggestions 9 | */ 10 | public class SearchSuggestionsProvider extends SearchRecentSuggestionsProvider { 11 | 12 | public final static String AUTHORITY = "com.android.msahakyan.nestedrecycler.provider.SearchSuggestionsProvider"; 13 | public final static int MODE = DATABASE_MODE_QUERIES; 14 | 15 | public SearchSuggestionsProvider() { 16 | setupSuggestions(AUTHORITY, MODE); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/android/msahakyan/nestedrecycler/view/FadeInNetworkImageView.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.drawable.BitmapDrawable; 6 | import android.graphics.drawable.ColorDrawable; 7 | import android.graphics.drawable.Drawable; 8 | import android.graphics.drawable.TransitionDrawable; 9 | import android.util.AttributeSet; 10 | 11 | import com.android.volley.toolbox.NetworkImageView; 12 | 13 | 14 | /** 15 | * @author msahakyan 16 | */ 17 | public class FadeInNetworkImageView extends NetworkImageView { 18 | 19 | private static final int FADE_IN_TIME_MS = 250; 20 | 21 | public FadeInNetworkImageView(Context context) { 22 | super(context); 23 | } 24 | 25 | public FadeInNetworkImageView(Context context, AttributeSet attrs) { 26 | super(context, attrs); 27 | } 28 | 29 | public FadeInNetworkImageView(Context context, AttributeSet attrs, int defStyle) { 30 | super(context, attrs, defStyle); 31 | } 32 | 33 | @Override 34 | public void setImageBitmap(Bitmap bm) { 35 | TransitionDrawable td = new TransitionDrawable(new Drawable[]{ 36 | new ColorDrawable(getResources().getColor(android.R.color.transparent)), 37 | new BitmapDrawable(getContext().getResources(), bm) 38 | }); 39 | 40 | setImageDrawable(td); 41 | td.startTransition(FADE_IN_TIME_MS); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi-v11/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-hdpi-v11/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-hdpi/ic_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-hdpi/ic_arrow_down.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-hdpi/ic_arrow_up.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-hdpi/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi-v11/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-mdpi-v11/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-mdpi/ic_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-mdpi/ic_arrow_down.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-mdpi/ic_arrow_up.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-mdpi/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi-v11/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xhdpi-v11/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xhdpi/ic_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xhdpi/ic_arrow_down.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xhdpi/ic_arrow_up.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xhdpi/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi-v11/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxhdpi-v11/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxhdpi/ic_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxhdpi/ic_arrow_down.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxhdpi/ic_arrow_up.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxhdpi/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi-v11/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxxhdpi-v11/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxxhdpi/ic_arrow.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_arrow_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxxhdpi/ic_arrow_down.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_arrow_up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxxhdpi/ic_arrow_up.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_stat_movies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable-xxxhdpi/ic_stat_movies.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable/error.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/loading.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/drawable/loading.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_movie_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_trailer.xml: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/backdrop_pager_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_movie_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 20 | 21 | 25 | 26 | 29 | 30 | 43 | 44 | 54 | 55 | 56 | 69 | 70 | 80 | 81 | 95 | 96 | 107 | 108 | 122 | 123 | 127 | 128 | 138 | 139 | 143 | 144 | 145 | 146 | 159 | 160 | 169 | 170 | 183 | 184 | 190 | 191 | 198 | 199 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_movie_item.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_movie_recycler.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_movie_related_item.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_movie_related_items.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 26 | 27 | 31 | 32 | 33 | 34 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_trailer_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 |

5 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/raw/movie_detail_framed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/raw/movie_detail_framed.png -------------------------------------------------------------------------------- /app/src/main/res/raw/movie_list_framed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/raw/movie_list_framed.png -------------------------------------------------------------------------------- /app/src/main/res/raw/search_results_framed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/raw/search_results_framed.png -------------------------------------------------------------------------------- /app/src/main/res/raw/similar_movies_framed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/raw/similar_movies_framed.png -------------------------------------------------------------------------------- /app/src/main/res/raw/youtube_player_framed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/app/src/main/res/raw/youtube_player_framed.png -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #263238 4 | #212121 5 | #CFD8DC 6 | #777777 7 | #ececec 8 | #acacac 9 | #424242 10 | #616161 11 | #FFFFFF 12 | #AF7817 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 8dp 7 | 8dp 8 | 5dp 9 | 220dp 10 | 3dp 11 | 150dp 12 | 180dp 13 | 90dp 14 | 130dp 15 | 140dp 16 | 17 | 13sp 18 | 12sp 19 | 16sp 20 | 170dp 21 | 250dp 22 | 6dp 23 | 300dp 24 | 5dp 25 | 80dp 26 | 35dp 27 | 450dp 28 | 30dp 29 | 15sp 30 | 180dp 31 | 400dp 32 | 200dp 33 | 12dp 34 | 16dp 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Movies 3 | Movie name 4 | 1990 5 | Similar movies 6 | thriller 7 | Loading data... 8 | Title 9 | Date 10 | Genre 11 | Description 12 | Confirm 13 | Do you want to continue to show details page? 14 | Yes 15 | Cancel 16 | Search 17 | Search movie 18 | Loading more data... 19 | There are no related items for this movie 20 | Backdrops 21 | Vote average 22 | There was an error initializing the YouTubePlayer (%1$s) 23 | Trailers 24 | No description available 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 14 | 15 | 18 | 19 | 23 | 24 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/xml/searchable.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/test/java/com/android/msahakyan/nestedrecycler/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.android.msahakyan.nestedrecycler; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/msahakyan/nested-recycler-view/ca7a0f8cd9c2a44572b3c701820c9901afd5fc85/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 05 00:17:53 CEST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.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 | --------------------------------------------------------------------------------