├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── Search.iml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── lucasurbas │ │ └── search │ │ └── ApplicationTest.java │ ├── fivehundredpx │ ├── java │ │ └── com │ │ │ └── lucasurbas │ │ │ └── search │ │ │ ├── constant │ │ │ └── Url.java │ │ │ ├── dagger │ │ │ └── ApiModule.java │ │ │ ├── model │ │ │ ├── Photo.java │ │ │ └── Response.java │ │ │ ├── request │ │ │ ├── FiveHundredPxApi.java │ │ │ └── SearchApiProxy.java │ │ │ └── widget │ │ │ ├── GridSpacingDecoration.java │ │ │ ├── ItemViewHolder.java │ │ │ └── RecyclerViewHelper.java │ └── res │ │ ├── layout │ │ └── row_photo.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ ├── github │ ├── java │ │ └── com │ │ │ └── lucasurbas │ │ │ └── search │ │ │ ├── constant │ │ │ └── Url.java │ │ │ ├── dagger │ │ │ └── ApiModule.java │ │ │ ├── model │ │ │ ├── Response.java │ │ │ └── User.java │ │ │ ├── request │ │ │ ├── GithubApi.java │ │ │ └── SearchApiProxy.java │ │ │ └── widget │ │ │ ├── DividerItemDecoration.java │ │ │ ├── ItemViewHolder.java │ │ │ └── RecyclerViewHelper.java │ └── res │ │ ├── drawable │ │ └── placeholder_avatar.xml │ │ ├── layout │ │ └── row_user.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── lucasurbas │ │ │ └── search │ │ │ ├── App.java │ │ │ ├── DetailActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── adapter │ │ │ └── ItemsAdapter.java │ │ │ ├── architecture │ │ │ ├── BaseActivity.java │ │ │ ├── BaseFragment.java │ │ │ ├── BaseInteractor.java │ │ │ ├── BasePresenter.java │ │ │ ├── Interactor.java │ │ │ ├── PresenterForInteractor.java │ │ │ ├── PresenterForView.java │ │ │ └── View.java │ │ │ ├── constant │ │ │ └── Field.java │ │ │ ├── dagger │ │ │ └── InjectionModule.java │ │ │ ├── db │ │ │ ├── Database.java │ │ │ ├── ORMLiteDatabase.java │ │ │ ├── ORMLiteHelper.java │ │ │ └── OnTableChangedListener.java │ │ │ ├── event │ │ │ └── OpenDetailScreenEvent.java │ │ │ ├── fragment │ │ │ ├── detail │ │ │ │ ├── DetailFragment.java │ │ │ │ ├── interactor │ │ │ │ │ ├── DetailInteractor.java │ │ │ │ │ └── DetailInteractorImpl.java │ │ │ │ ├── presenter │ │ │ │ │ ├── DetailPresenterForInteractor.java │ │ │ │ │ ├── DetailPresenterForView.java │ │ │ │ │ └── DetailPresenterImpl.java │ │ │ │ └── view │ │ │ │ │ ├── DetailView.java │ │ │ │ │ └── DetailViewState.java │ │ │ └── search │ │ │ │ ├── SearchFragment.java │ │ │ │ ├── interactor │ │ │ │ ├── SearchInteractor.java │ │ │ │ └── SearchInteractorImpl.java │ │ │ │ ├── presenter │ │ │ │ ├── SearchPresenterForInteractor.java │ │ │ │ ├── SearchPresenterForView.java │ │ │ │ └── SearchPresenterImpl.java │ │ │ │ └── view │ │ │ │ ├── SearchView.java │ │ │ │ └── SearchViewState.java │ │ │ ├── model │ │ │ ├── IdProvider.java │ │ │ ├── SearchItem.java │ │ │ └── SearchItemsProvider.java │ │ │ ├── request │ │ │ └── SearchApi.java │ │ │ ├── util │ │ │ ├── ResourceHelper.java │ │ │ └── Util.java │ │ │ └── widget │ │ │ ├── FixedRatioImageView.java │ │ │ └── ProgressIndicator.java │ └── res │ │ ├── drawable-hdpi │ │ ├── ic_search_white_24dp.png │ │ ├── ic_star_border_white_24dp.png │ │ ├── ic_star_white_24dp.png │ │ └── ic_web_white_24dp.png │ │ ├── drawable-mdpi │ │ ├── ic_search_white_24dp.png │ │ ├── ic_star_border_white_24dp.png │ │ ├── ic_star_white_24dp.png │ │ └── ic_web_white_24dp.png │ │ ├── drawable-xhdpi │ │ ├── ic_search_white_24dp.png │ │ ├── ic_star_border_white_24dp.png │ │ ├── ic_star_white_24dp.png │ │ └── ic_web_white_24dp.png │ │ ├── drawable-xxhdpi │ │ ├── ic_search_white_24dp.png │ │ ├── ic_star_border_white_24dp.png │ │ ├── ic_star_white_24dp.png │ │ └── ic_web_white_24dp.png │ │ ├── drawable-xxxhdpi │ │ ├── ic_search_white_24dp.png │ │ ├── ic_star_border_white_24dp.png │ │ ├── ic_star_white_24dp.png │ │ └── ic_web_white_24dp.png │ │ ├── drawable │ │ └── background_progress_bar.xml │ │ ├── layout-sw720dp │ │ └── activity_main.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_detail.xml │ │ ├── fragment_search.xml │ │ └── widget_progress_indicator.xml │ │ ├── menu │ │ ├── menu_detail.xml │ │ └── menu_search.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── dimens.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── lucasurbas │ └── search │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── readme └── viper.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Search -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Search 2 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Search-blue.svg?style=flat)](http://android-arsenal.com/details/3/2448) 3 | 4 | viper architecture example 5 | 6 | This is example of application built with VIPER architecture. It's built on top of sockeqwe's [Mosby](https://github.com/sockeqwe/mosby). 7 | 8 | ### Diagram 9 | 10 | ![](https://github.com/lurbas/Search/blob/master/readme/viper.png) 11 | 12 | ### Viper 13 | I encourage you to read more about this pattern [here](https://speakerdeck.com/sergigracia/clean-architecture-viper) (slide above from the same presentation) 14 | 15 | ### License 16 | 17 | Copyright 2015 Lucas Urbas 18 | 19 | Licensed under the Apache License, Version 2.0 (the "License"); 20 | you may not use this file except in compliance with the License. 21 | You may obtain a copy of the License at 22 | 23 | http://www.apache.org/licenses/LICENSE-2.0 24 | 25 | Unless required by applicable law or agreed to in writing, software 26 | distributed under the License is distributed on an "AS IS" BASIS, 27 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 | See the License for the specific language governing permissions and 29 | limitations under the License. 30 | -------------------------------------------------------------------------------- /Search.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /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 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.neenbedankt.android-apt' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "23.0.0" 7 | 8 | defaultConfig { 9 | applicationId "com.lucasurbas.search" 10 | minSdkVersion 15 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | productFlavors { 22 | github { 23 | applicationId = "com.lucasurbas.search.github" 24 | } 25 | fivehundredpx { 26 | applicationId = "com.lucasurbas.search.fivehundredpx" 27 | } 28 | } 29 | packagingOptions { 30 | exclude 'META-INF/services/javax.annotation.processing.Processor' 31 | } 32 | } 33 | 34 | dependencies { 35 | compile fileTree(dir: 'libs', include: ['*.jar']) 36 | compile 'com.android.support:appcompat-v7:23.0.0' 37 | compile 'com.android.support:recyclerview-v7:23.0.0' 38 | compile 'com.android.support:cardview-v7:23.0.0' 39 | compile 'com.android.support:palette-v7:23.0.0' 40 | compile 'com.android.support:design:23.0.0' 41 | compile 'com.android.support:percent:23.0.0' 42 | compile 'com.jakewharton:butterknife:7.0.1' 43 | compile 'frankiesardo:icepick:3.0.2' 44 | compile 'com.hannesdorfmann.mosby:core:1.3.0' 45 | compile 'com.hannesdorfmann.mosby:mvp:1.3.0' 46 | compile 'com.hannesdorfmann.mosby:viewstate:1.3.0' 47 | compile 'com.squareup.dagger:dagger:1.2.2' 48 | apt 'com.squareup.dagger:dagger-compiler:1.2.2' 49 | compile 'com.squareup.retrofit:retrofit:1.9.0' 50 | compile 'com.squareup.okhttp:okhttp:2.3.0' 51 | compile 'com.squareup.picasso:picasso:2.5.2' 52 | compile 'io.reactivex:rxandroid:1.0.1' 53 | compile 'com.github.florent37:picassopalette:1.0.2@aar' 54 | compile 'com.makeramen:roundedimageview:2.2.0' 55 | compile 'com.j256.ormlite:ormlite-android:4.48' 56 | compile 'de.greenrobot:eventbus:2.4.0' 57 | } 58 | -------------------------------------------------------------------------------- /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/Lucas/Library/Android/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/lucasurbas/search/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search; 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/fivehundredpx/java/com/lucasurbas/search/constant/Url.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.constant; 2 | 3 | /** 4 | * Created by Lucas on 29/08/15. 5 | */ 6 | public class Url { 7 | 8 | public static final String BASE_URL = "https://api.500px.com/v1"; 9 | public static final String PATH_SEARCH = "/photos/search"; 10 | 11 | public static final String QUERY_TERM = "term"; 12 | public static final String QUERY_CONSUMER_KEY = "consumer_key"; 13 | public static final String VALUE_CONSUMER_KEY = "K0nMK4dOqd4KZYPKsNy6VlmgVPPlhMGxeGVp0Eth"; 14 | } 15 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/dagger/ApiModule.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.dagger; 2 | 3 | import com.google.gson.Gson; 4 | import com.lucasurbas.search.constant.Url; 5 | import com.lucasurbas.search.fragment.search.interactor.SearchInteractorImpl; 6 | import com.lucasurbas.search.request.FiveHundredPxApi; 7 | import com.lucasurbas.search.request.SearchApi; 8 | import com.lucasurbas.search.request.SearchApiProxy; 9 | import com.squareup.okhttp.OkHttpClient; 10 | 11 | import javax.inject.Singleton; 12 | 13 | import dagger.Module; 14 | import dagger.Provides; 15 | import retrofit.RestAdapter; 16 | import retrofit.client.OkClient; 17 | import retrofit.converter.GsonConverter; 18 | 19 | /** 20 | * Created by Lucas on 29/08/15. 21 | */ 22 | @Module( 23 | complete = false, 24 | library = true, 25 | 26 | injects = { 27 | SearchInteractorImpl.class 28 | } 29 | ) 30 | public class ApiModule { 31 | 32 | @Provides 33 | FiveHundredPxApi providesApi(Gson gson, OkHttpClient client) { 34 | 35 | RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(client)) 36 | .setEndpoint(Url.BASE_URL) 37 | .setLogLevel(RestAdapter.LogLevel.FULL) 38 | .setConverter(new GsonConverter(gson)) 39 | .build(); 40 | 41 | return restAdapter.create(FiveHundredPxApi.class); 42 | } 43 | 44 | @Provides 45 | @Singleton 46 | SearchApi providesSearchApi(FiveHundredPxApi fiveHundredPxApi){ 47 | return new SearchApiProxy(fiveHundredPxApi); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/model/Photo.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.model; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Created by Lucas on 29/08/15. 8 | */ 9 | public class Photo { 10 | 11 | @Expose 12 | @SerializedName("id") 13 | private long id; 14 | 15 | @Expose 16 | @SerializedName("description") 17 | private String description; 18 | 19 | @Expose 20 | @SerializedName("image_url") 21 | private String imageUrl; 22 | 23 | @Expose 24 | @SerializedName("url") 25 | private String url; 26 | 27 | public long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getDescription() { 36 | return description; 37 | } 38 | 39 | public void setDescription(String description) { 40 | this.description = description; 41 | } 42 | 43 | public String getImageUrl() { 44 | return imageUrl; 45 | } 46 | 47 | public void setImageUrl(String imageUrl) { 48 | this.imageUrl = imageUrl; 49 | } 50 | 51 | public String getUrl() { 52 | return url; 53 | } 54 | 55 | public void setUrl(String url) { 56 | this.url = url; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/model/Response.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.model; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Lucas on 29/08/15. 11 | */ 12 | public class Response implements SearchItemsProvider { 13 | 14 | @Expose 15 | @SerializedName("photos") 16 | List photoList; 17 | 18 | @Override 19 | public List getSearchItems() { 20 | ArrayList list = new ArrayList<>(); 21 | SearchItem searchItem; 22 | for (Photo p : photoList) { 23 | searchItem = new SearchItem(); 24 | searchItem.setId(p.getId()); 25 | searchItem.setTitle(p.getDescription()); 26 | searchItem.setImageUrl(p.getImageUrl()); 27 | searchItem.setWebUrl(String.format("https://500px.com%s", p.getUrl())); 28 | list.add(searchItem); 29 | } 30 | return list; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/request/FiveHundredPxApi.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.request; 2 | 3 | import com.lucasurbas.search.constant.Url; 4 | import com.lucasurbas.search.model.Response; 5 | 6 | import retrofit.http.GET; 7 | import retrofit.http.Query; 8 | import rx.Observable; 9 | 10 | /** 11 | * Created by Lucas on 29/08/15. 12 | */ 13 | public interface FiveHundredPxApi { 14 | 15 | @GET(Url.PATH_SEARCH) 16 | Observable query(@Query(Url.QUERY_TERM) String term, 17 | @Query(Url.QUERY_CONSUMER_KEY) String consumerKey); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/request/SearchApiProxy.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.request; 2 | 3 | import com.lucasurbas.search.constant.Url; 4 | import com.lucasurbas.search.model.SearchItemsProvider; 5 | 6 | import rx.Observable; 7 | 8 | /** 9 | * Created by Lucas on 29/08/15. 10 | */ 11 | public class SearchApiProxy implements SearchApi { 12 | 13 | private FiveHundredPxApi fiveHundredPxApi; 14 | 15 | public SearchApiProxy(FiveHundredPxApi fiveHundredPxApi) { 16 | this.fiveHundredPxApi = fiveHundredPxApi; 17 | } 18 | 19 | @Override 20 | public Observable query(String query) { 21 | return fiveHundredPxApi.query(query, Url.VALUE_CONSUMER_KEY); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/widget/GridSpacingDecoration.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.graphics.Rect; 4 | import android.support.v7.widget.GridLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.support.v7.widget.StaggeredGridLayoutManager; 7 | import android.util.TypedValue; 8 | import android.view.View; 9 | 10 | /** 11 | * Created by Lucas on 29/08/15. 12 | */ 13 | public class GridSpacingDecoration extends RecyclerView.ItemDecoration { 14 | 15 | @Override 16 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 17 | 18 | super.getItemOffsets(outRect, view, parent, state); 19 | 20 | int spacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, view.getResources().getDisplayMetrics()); 21 | int halfSpacing = spacing / 2; 22 | 23 | int childCount = parent.getChildCount(); 24 | int childIndex = parent.getChildAdapterPosition(view); 25 | int spanCount = getTotalSpan(view, parent); 26 | int spanIndex = childIndex % spanCount; 27 | 28 | /* INVALID SPAN */ 29 | if (spanCount < 1) return; 30 | 31 | outRect.top = halfSpacing; 32 | outRect.bottom = halfSpacing; 33 | outRect.left = halfSpacing; 34 | outRect.right = halfSpacing; 35 | 36 | if (isTopEdge(childIndex, spanCount)) { 37 | outRect.top = spacing; 38 | } 39 | // if (isLeftEdge(spanIndex, spanCount)) { 40 | // outRect.left = spacing; 41 | // } 42 | // if (isRightEdge(spanIndex, spanCount)) { 43 | // outRect.right = spacing; 44 | // } 45 | if (isBottomEdge(childIndex, childCount, spanCount)) { 46 | outRect.bottom = spacing; 47 | } 48 | } 49 | 50 | protected int getTotalSpan(View view, RecyclerView parent) { 51 | RecyclerView.LayoutManager mgr = parent.getLayoutManager(); 52 | if (mgr instanceof GridLayoutManager) { 53 | return ((GridLayoutManager) mgr).getSpanCount(); 54 | } else if (mgr instanceof StaggeredGridLayoutManager) { 55 | return ((StaggeredGridLayoutManager) mgr).getSpanCount(); 56 | } 57 | return -1; 58 | } 59 | 60 | protected boolean isLeftEdge(int spanIndex, int spanCount) { 61 | return spanIndex == 0; 62 | } 63 | 64 | protected boolean isRightEdge(int spanIndex, int spanCount) { 65 | return spanIndex == spanCount - 1; 66 | } 67 | 68 | protected boolean isTopEdge(int childIndex, int spanCount) { 69 | return childIndex < spanCount; 70 | } 71 | 72 | protected boolean isBottomEdge(int childIndex, int childCount, int spanCount) { 73 | return childIndex >= childCount - spanCount; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/widget/ItemViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.support.v4.graphics.drawable.DrawableCompat; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.View; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.lucasurbas.search.App; 12 | import com.lucasurbas.search.R; 13 | import com.lucasurbas.search.event.OpenDetailScreenEvent; 14 | import com.lucasurbas.search.model.SearchItem; 15 | import com.squareup.picasso.Picasso; 16 | 17 | import javax.inject.Inject; 18 | 19 | import butterknife.Bind; 20 | import butterknife.ButterKnife; 21 | import de.greenrobot.event.EventBus; 22 | 23 | /** 24 | * Created by Lucas on 30/08/15. 25 | */ 26 | public class ItemViewHolder extends RecyclerView.ViewHolder { 27 | 28 | private static final String TAG = ItemViewHolder.class.getSimpleName(); 29 | 30 | @Inject 31 | Picasso picasso; 32 | 33 | @Bind(R.id.item_container) 34 | View itemContainer; 35 | @Bind(R.id.footer) 36 | View footer; 37 | @Bind(R.id.iv_image) 38 | ImageView ivPhoto; 39 | @Bind(R.id.tv_desc) 40 | TextView tvDescription; 41 | @Bind(R.id.iv_favourite) 42 | ImageView ivFavourite; 43 | @Bind(R.id.tv_best_result) 44 | TextView tvBestResult; 45 | 46 | public ItemViewHolder(View view) { 47 | super(view); 48 | ButterKnife.bind(this, view); 49 | App.getObjectGraph().inject(this); 50 | } 51 | 52 | public static int getLayoutResId() { 53 | return R.layout.row_photo; 54 | } 55 | 56 | public void presentSearchItem(final Context context, final SearchItem searchItem, boolean bestResult) { 57 | 58 | tvDescription.setTextColor(context.getResources().getColor(R.color.toolbar_icon)); 59 | itemContainer.setBackgroundColor(context.getResources().getColor(R.color.primary)); 60 | if (searchItem.isFavourite()) { 61 | ivFavourite.setVisibility(View.VISIBLE); 62 | 63 | final Drawable originalDrawable = ivFavourite.getDrawable(); 64 | final Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable); 65 | 66 | int color = context.getResources().getColor(R.color.toolbar_icon); 67 | DrawableCompat.setTint(wrappedDrawable, color); 68 | ivFavourite.setImageDrawable(wrappedDrawable); 69 | } else { 70 | ivFavourite.setVisibility(View.GONE); 71 | } 72 | if (searchItem.isVisited()) { 73 | ivPhoto.setAlpha(0.33f); 74 | itemContainer.setAlpha(0.6f); 75 | } else { 76 | ivPhoto.setAlpha(1f); 77 | itemContainer.setAlpha(1f); 78 | } 79 | tvBestResult.setVisibility(bestResult ? View.VISIBLE : View.GONE); 80 | 81 | picasso.load(searchItem.getImageUrl()) 82 | .fit() 83 | .into(ivPhoto); 84 | // , 85 | // PicassoPalette.with(searchItem.getImageUrl(), ivPhoto) 86 | // .intoCallBack(new BitmapPalette.CallBack() { 87 | // @Override 88 | // public void onPaletteLoaded(Palette palette) { 89 | // Palette.Swatch swatch = palette.getDarkVibrantSwatch(); 90 | // if (swatch != null) { 91 | // itemContainer.setBackgroundColor(swatch.getRgb()); 92 | // tvDescription.setTextColor(swatch.getTitleTextColor()); 93 | // DrawableCompat.setTint(ivFavourite.getDrawable(), swatch.getTitleTextColor()); 94 | // } 95 | // } 96 | // }) 97 | // ); 98 | 99 | String title = searchItem.getTitle(); 100 | tvDescription.setText(title == null || title.isEmpty() ? context.getString(R.string.t_no_desc) : title); 101 | 102 | itemContainer.setOnClickListener(new View.OnClickListener() { 103 | @Override 104 | public void onClick(View v) { 105 | EventBus.getDefault().post(new OpenDetailScreenEvent(searchItem)); 106 | } 107 | }); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/java/com/lucasurbas/search/widget/RecyclerViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.DefaultItemAnimator; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.ViewTreeObserver; 8 | 9 | import com.lucasurbas.search.util.Util; 10 | 11 | /** 12 | * Created by Lucas on 29/08/15. 13 | */ 14 | public class RecyclerViewHelper { 15 | 16 | public static void setup(Context context, final RecyclerView recyclerView){ 17 | final GridLayoutManager manager = new GridLayoutManager(context, 2); 18 | final int columnWidth = (int) Util.pxFromDp(context, 150); 19 | int padding = (int) Util.pxFromDp(context, 2); 20 | recyclerView.setPadding(padding, 0, padding, 0); 21 | recyclerView.setLayoutManager(manager); 22 | recyclerView.setItemAnimator(new DefaultItemAnimator()); 23 | recyclerView.addItemDecoration(new GridSpacingDecoration()); 24 | 25 | recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 26 | @Override 27 | public void onGlobalLayout() { 28 | if (columnWidth > 0) { 29 | int spanCount = Math.max(1, (recyclerView.getMeasuredWidth() - recyclerView.getPaddingLeft() - recyclerView.getPaddingRight()) / columnWidth); 30 | manager.setSpanCount(spanCount); 31 | } 32 | } 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/res/layout/row_photo.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 20 | 21 | 28 | 29 | 42 | 43 | 44 | 45 | 49 | 50 | 60 | 61 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #212121 4 | #000000 5 | #424242 6 | #F44336 7 | #AAFFFFFF 8 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Search for 500px 4 | 500px - Hello world! 5 | -------------------------------------------------------------------------------- /app/src/fivehundredpx/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/constant/Url.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.constant; 2 | 3 | /** 4 | * Created by Lucas on 30/08/15. 5 | */ 6 | public class Url { 7 | 8 | public static final String BASE_URL = "https://api.github.com"; 9 | public static final String PATH_SEARCH_USERS = "/search/users"; 10 | 11 | public static final String QUERY_Q = "q"; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/dagger/ApiModule.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.dagger; 2 | 3 | import com.google.gson.Gson; 4 | import com.lucasurbas.search.constant.Url; 5 | import com.lucasurbas.search.fragment.search.interactor.SearchInteractorImpl; 6 | import com.lucasurbas.search.request.GithubApi; 7 | import com.lucasurbas.search.request.SearchApi; 8 | import com.lucasurbas.search.request.SearchApiProxy; 9 | import com.squareup.okhttp.OkHttpClient; 10 | 11 | import javax.inject.Singleton; 12 | 13 | import dagger.Module; 14 | import dagger.Provides; 15 | import retrofit.RestAdapter; 16 | import retrofit.client.OkClient; 17 | import retrofit.converter.GsonConverter; 18 | 19 | /** 20 | * Created by Lucas on 30/08/15. 21 | */ 22 | @Module( 23 | complete = false, 24 | library = true, 25 | 26 | injects = { 27 | SearchInteractorImpl.class 28 | } 29 | ) 30 | public class ApiModule { 31 | 32 | @Provides 33 | GithubApi providesApi(Gson gson, OkHttpClient client) { 34 | 35 | RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(client)) 36 | .setEndpoint(Url.BASE_URL) 37 | .setLogLevel(RestAdapter.LogLevel.FULL) 38 | .setConverter(new GsonConverter(gson)) 39 | .build(); 40 | 41 | return restAdapter.create(GithubApi.class); 42 | } 43 | 44 | @Provides 45 | @Singleton 46 | SearchApi providesSearchApi(GithubApi githubApi){ 47 | return new SearchApiProxy(githubApi); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/model/Response.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.model; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Lucas on 30/08/15. 11 | */ 12 | public class Response implements SearchItemsProvider { 13 | 14 | @Expose 15 | @SerializedName("items") 16 | List userList; 17 | 18 | @Override 19 | public List getSearchItems() { 20 | ArrayList list = new ArrayList<>(); 21 | SearchItem searchItem; 22 | for (User u : userList) { 23 | searchItem = new SearchItem(); 24 | searchItem.setId(u.getId()); 25 | searchItem.setTitle(u.getLogin()); 26 | searchItem.setImageUrl(u.getAvatarUrl()); 27 | searchItem.setWebUrl(u.getUrl()); 28 | list.add(searchItem); 29 | } 30 | return list; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/model/User.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.model; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import com.google.gson.annotations.SerializedName; 5 | 6 | /** 7 | * Created by Lucas on 30/08/15. 8 | */ 9 | public class User { 10 | 11 | @Expose 12 | @SerializedName("id") 13 | private long id; 14 | 15 | @Expose 16 | @SerializedName("login") 17 | private String login; 18 | 19 | @Expose 20 | @SerializedName("avatar_url") 21 | private String avatarUrl; 22 | 23 | @Expose 24 | @SerializedName("html_url") 25 | private String url; 26 | 27 | public long getId() { 28 | return id; 29 | } 30 | 31 | public void setId(long id) { 32 | this.id = id; 33 | } 34 | 35 | public String getLogin() { 36 | return login; 37 | } 38 | 39 | public void setLogin(String login) { 40 | this.login = login; 41 | } 42 | 43 | public String getAvatarUrl() { 44 | return avatarUrl; 45 | } 46 | 47 | public void setAvatarUrl(String avatarUrl) { 48 | this.avatarUrl = avatarUrl; 49 | } 50 | 51 | public String getUrl() { 52 | return url; 53 | } 54 | 55 | public void setUrl(String url) { 56 | this.url = url; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/request/GithubApi.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.request; 2 | 3 | import com.lucasurbas.search.constant.Url; 4 | import com.lucasurbas.search.model.Response; 5 | 6 | import retrofit.http.GET; 7 | import retrofit.http.Query; 8 | import rx.Observable; 9 | 10 | /** 11 | * Created by Lucas on 30/08/15. 12 | */ 13 | public interface GithubApi { 14 | @GET(Url.PATH_SEARCH_USERS) 15 | Observable query(@Query(Url.QUERY_Q) String query); 16 | } 17 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/request/SearchApiProxy.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.request; 2 | 3 | import com.lucasurbas.search.model.SearchItemsProvider; 4 | 5 | import rx.Observable; 6 | 7 | /** 8 | * Created by Lucas on 30/08/15. 9 | */ 10 | public class SearchApiProxy implements SearchApi { 11 | 12 | private GithubApi githubApi; 13 | 14 | public SearchApiProxy(GithubApi githubApi) { 15 | this.githubApi = githubApi; 16 | } 17 | 18 | @Override 19 | public Observable query(String query) { 20 | return githubApi.query(query); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/widget/DividerItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Rect; 7 | import android.graphics.drawable.Drawable; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.View; 11 | 12 | /* 13 | * Copyright (C) 2014 The Android Open Source Project 14 | * 15 | * Licensed under the Apache License, Version 2.0 (the "License"); 16 | * you may not use this file except in compliance with the License. 17 | * You may obtain a copy of the License at 18 | * 19 | * http://www.apache.org/licenses/LICENSE-2.0 20 | * 21 | * Unless required by applicable law or agreed to in writing, software 22 | * distributed under the License is distributed on an "AS IS" BASIS, 23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 | * See the License for the specific language governing permissions and 25 | * limitations under the License. 26 | */ 27 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { 28 | 29 | private static final int[] ATTRS = new int[]{ 30 | android.R.attr.listDivider 31 | }; 32 | 33 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL; 34 | 35 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL; 36 | 37 | private Drawable mDivider; 38 | 39 | private int mOrientation; 40 | 41 | public DividerItemDecoration(Context context, int orientation) { 42 | final TypedArray a = context.obtainStyledAttributes(ATTRS); 43 | mDivider = a.getDrawable(0); 44 | a.recycle(); 45 | setOrientation(orientation); 46 | } 47 | 48 | public void setOrientation(int orientation) { 49 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { 50 | throw new IllegalArgumentException("invalid orientation"); 51 | } 52 | mOrientation = orientation; 53 | } 54 | 55 | @Override 56 | public void onDraw(Canvas c, RecyclerView parent) { 57 | if (mOrientation == VERTICAL_LIST) { 58 | drawVertical(c, parent); 59 | } else { 60 | drawHorizontal(c, parent); 61 | } 62 | } 63 | 64 | public void drawVertical(Canvas c, RecyclerView parent) { 65 | final int left = parent.getPaddingLeft(); 66 | final int right = parent.getWidth() - parent.getPaddingRight(); 67 | 68 | final int childCount = parent.getChildCount(); 69 | for (int i = 0; i < childCount; i++) { 70 | final View child = parent.getChildAt(i); 71 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 72 | .getLayoutParams(); 73 | final int top = child.getBottom() + params.bottomMargin; 74 | final int bottom = top + mDivider.getIntrinsicHeight(); 75 | mDivider.setBounds(left, top, right, bottom); 76 | mDivider.draw(c); 77 | } 78 | } 79 | 80 | public void drawHorizontal(Canvas c, RecyclerView parent) { 81 | final int top = parent.getPaddingTop(); 82 | final int bottom = parent.getHeight() - parent.getPaddingBottom(); 83 | 84 | final int childCount = parent.getChildCount(); 85 | for (int i = 0; i < childCount; i++) { 86 | final View child = parent.getChildAt(i); 87 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child 88 | .getLayoutParams(); 89 | final int left = child.getRight() + params.rightMargin; 90 | final int right = left + mDivider.getIntrinsicHeight(); 91 | mDivider.setBounds(left, top, right, bottom); 92 | mDivider.draw(c); 93 | } 94 | } 95 | 96 | @Override 97 | public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) { 98 | if (mOrientation == VERTICAL_LIST) { 99 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); 100 | } else { 101 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/widget/ItemViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.support.v4.graphics.drawable.DrawableCompat; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.View; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.lucasurbas.search.App; 12 | import com.lucasurbas.search.R; 13 | import com.lucasurbas.search.event.OpenDetailScreenEvent; 14 | import com.lucasurbas.search.model.SearchItem; 15 | import com.squareup.picasso.Picasso; 16 | 17 | import javax.inject.Inject; 18 | 19 | import butterknife.Bind; 20 | import butterknife.ButterKnife; 21 | import de.greenrobot.event.EventBus; 22 | 23 | /** 24 | * Created by Lucas on 30/08/15. 25 | */ 26 | public class ItemViewHolder extends RecyclerView.ViewHolder { 27 | 28 | @Inject 29 | Picasso picasso; 30 | 31 | @Bind(R.id.item_container) 32 | View itemContainer; 33 | @Bind(R.id.iv_avatar) 34 | ImageView ivAvatar; 35 | @Bind(R.id.tv_login) 36 | TextView tvLogin; 37 | @Bind(R.id.iv_favourite) 38 | ImageView ivFavourite; 39 | @Bind(R.id.tv_best_result) 40 | TextView tvBestResult; 41 | 42 | public ItemViewHolder(View view) { 43 | super(view); 44 | ButterKnife.bind(this, view); 45 | App.getObjectGraph().inject(this); 46 | } 47 | 48 | public static int getLayoutResId() { 49 | return R.layout.row_user; 50 | } 51 | 52 | public void presentSearchItem(final Context context, final SearchItem searchItem, boolean bestResult) { 53 | 54 | if (searchItem.isFavourite()) { 55 | ivFavourite.setVisibility(View.VISIBLE); 56 | 57 | final Drawable originalDrawable = ivFavourite.getDrawable(); 58 | final Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable); 59 | 60 | int color = context.getResources().getColor(R.color.toolbar_icon); 61 | DrawableCompat.setTint(wrappedDrawable, color); 62 | ivFavourite.setImageDrawable(wrappedDrawable); 63 | } else { 64 | ivFavourite.setVisibility(View.GONE); 65 | } 66 | if (searchItem.isVisited()) { 67 | ivAvatar.setAlpha(0.33f); 68 | tvLogin.setAlpha(0.33f); 69 | } else { 70 | ivAvatar.setAlpha(1f); 71 | tvLogin.setAlpha(1f); 72 | } 73 | tvBestResult.setVisibility(bestResult ? View.VISIBLE : View.GONE); 74 | 75 | picasso.load(searchItem.getImageUrl()) 76 | .fit() 77 | .placeholder(R.drawable.placeholder_avatar) 78 | .into(ivAvatar); 79 | tvLogin.setText(searchItem.getTitle()); 80 | 81 | itemContainer.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | EventBus.getDefault().post(new OpenDetailScreenEvent(searchItem)); 85 | } 86 | }); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/github/java/com/lucasurbas/search/widget/RecyclerViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.DefaultItemAnimator; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | 8 | /** 9 | * Created by Lucas on 30/08/15. 10 | */ 11 | public class RecyclerViewHelper { 12 | 13 | public static void setup(Context context, final RecyclerView recyclerView){ 14 | final LinearLayoutManager manager = new LinearLayoutManager(context); 15 | manager.setOrientation(LinearLayoutManager.VERTICAL); 16 | recyclerView.setLayoutManager(manager); 17 | recyclerView.setItemAnimator(new DefaultItemAnimator()); 18 | recyclerView.addItemDecoration(new DividerItemDecoration(context, 19 | DividerItemDecoration.VERTICAL_LIST)); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/github/res/drawable/placeholder_avatar.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/github/res/layout/row_user.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 22 | 23 | 30 | 31 | 38 | 39 | 48 | 49 | 50 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/github/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #EEEEEE 4 | #BDBDBD 5 | #FAFAFA 6 | #00BCD4 7 | #8A000000 8 | -------------------------------------------------------------------------------- /app/src/github/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Search for Github 4 | Github - Hello world! 5 | -------------------------------------------------------------------------------- /app/src/github/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/App.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search; 2 | 3 | import android.app.Application; 4 | 5 | import com.lucasurbas.search.dagger.InjectionModule; 6 | 7 | import dagger.ObjectGraph; 8 | 9 | /** 10 | * Created by Lucas on 29/08/15. 11 | */ 12 | public class App extends Application { 13 | 14 | private static ObjectGraph objectGraph; 15 | 16 | @Override public void onCreate() { 17 | super.onCreate(); 18 | objectGraph = ObjectGraph.create(new InjectionModule(this)); 19 | } 20 | 21 | public static ObjectGraph getObjectGraph() { 22 | return objectGraph; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/DetailActivity.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v4.app.Fragment; 7 | 8 | import com.lucasurbas.search.architecture.BaseActivity; 9 | import com.lucasurbas.search.fragment.detail.DetailFragment; 10 | import com.lucasurbas.search.model.SearchItem; 11 | 12 | /** 13 | * Created by Lucas on 30/08/15. 14 | */ 15 | public class DetailActivity extends BaseActivity { 16 | 17 | private static final String KEY_SEARCH_ITEM = "key_search_item"; 18 | 19 | public static Intent getStartIntent(Context context, SearchItem searchItem){ 20 | Intent intent = new Intent(context, DetailActivity.class); 21 | intent.putExtra(KEY_SEARCH_ITEM, searchItem); 22 | return intent; 23 | } 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | 29 | if(savedInstanceState == null){ 30 | SearchItem searchItem = getIntent().getParcelableExtra(KEY_SEARCH_ITEM); 31 | Fragment fragment = DetailFragment.newInstance(searchItem); 32 | getSupportFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | 6 | import com.lucasurbas.search.architecture.BaseActivity; 7 | import com.lucasurbas.search.event.OpenDetailScreenEvent; 8 | import com.lucasurbas.search.fragment.detail.DetailFragment; 9 | import com.lucasurbas.search.fragment.search.SearchFragment; 10 | 11 | import de.greenrobot.event.EventBus; 12 | 13 | public class MainActivity extends BaseActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_main); 19 | 20 | if (savedInstanceState == null) { 21 | Fragment fragment = SearchFragment.newInstance(); 22 | getSupportFragmentManager().beginTransaction().replace(R.id.container_master, fragment).commit(); 23 | } 24 | } 25 | 26 | @Override 27 | protected void onResume() { 28 | super.onResume(); 29 | EventBus.getDefault().register(this); 30 | } 31 | 32 | @Override 33 | protected void onPause() { 34 | super.onPause(); 35 | EventBus.getDefault().unregister(this); 36 | } 37 | 38 | public void onEvent(OpenDetailScreenEvent event) { 39 | if (findViewById(R.id.container_detail) == null) { 40 | startActivity(DetailActivity.getStartIntent(this, event.getSearchItem())); 41 | } else { 42 | Fragment fragment = DetailFragment.newInstance(event.getSearchItem()); 43 | getSupportFragmentManager().beginTransaction().replace(R.id.container_detail, fragment).commit(); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/adapter/ItemsAdapter.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.lucasurbas.search.model.SearchItem; 10 | import com.lucasurbas.search.widget.ItemViewHolder; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by Lucas on 30/08/15. 17 | */ 18 | public class ItemsAdapter extends RecyclerView.Adapter { 19 | 20 | private List searchItems; 21 | private Context context; 22 | 23 | public ItemsAdapter(Context context) { 24 | this.searchItems = new ArrayList<>(); 25 | this.context = context; 26 | } 27 | 28 | @Override 29 | public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 30 | View view = LayoutInflater.from(parent.getContext()).inflate(ItemViewHolder.getLayoutResId(), parent, false); 31 | return new ItemViewHolder(view); 32 | } 33 | 34 | @Override 35 | public void onBindViewHolder(final ItemViewHolder holder, final int position) { 36 | 37 | final SearchItem searchItem = searchItems.get(position); 38 | boolean bestResult = position == 0; 39 | holder.presentSearchItem(context, searchItem, bestResult); 40 | } 41 | 42 | public void setItems(List itemList) { 43 | this.searchItems = itemList; 44 | notifyDataSetChanged(); 45 | } 46 | 47 | @Override 48 | public int getItemCount() { 49 | return searchItems.size(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | 5 | /** 6 | * Created by lucas.urbas on 29/08/15. 7 | */ 8 | public abstract class BaseActivity extends AppCompatActivity { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.hannesdorfmann.mosby.mvp.viewstate.MvpViewStateFragment; 6 | 7 | /** 8 | * Created by lucas.urbas on 29/08/15. 9 | */ 10 | public abstract class BaseFragment> extends MvpViewStateFragment { 11 | 12 | @Override 13 | public void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setRetainInstance(true); 16 | } 17 | 18 | @Override 19 | public void onViewCreated(android.view.View view, Bundle savedInstanceState) { 20 | super.onViewCreated(view, savedInstanceState); 21 | presenter.onViewCreated(); 22 | } 23 | 24 | @Override 25 | public void onPause() { 26 | super.onPause(); 27 | presenter.onPause(); 28 | } 29 | 30 | @Override 31 | public void onResume() { 32 | super.onResume(); 33 | presenter.onResume(); 34 | } 35 | 36 | @Override 37 | public void onDestroy() { 38 | presenter.onDestroy(); 39 | super.onDestroy(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/BaseInteractor.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | 4 | /** 5 | * Created by lucas.urbas on 29/08/15. 6 | */ 7 | public class BaseInteractor

implements Interactor

{ 8 | 9 | private P subscribedPresenter; 10 | 11 | public BaseInteractor() { 12 | 13 | } 14 | 15 | @Override 16 | public P getPresenter() { 17 | return subscribedPresenter; 18 | } 19 | 20 | @Override 21 | public boolean isPresenterSubscribed() { 22 | return subscribedPresenter != null; 23 | } 24 | 25 | @Override 26 | public void subscribePresenter(P presenter) { 27 | this.subscribedPresenter = presenter; 28 | } 29 | 30 | @Override 31 | public void unsubscribePresenter() { 32 | this.subscribedPresenter = null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/BasePresenter.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | import android.support.annotation.Nullable; 4 | 5 | import com.hannesdorfmann.mosby.mvp.MvpBasePresenter; 6 | 7 | import java.lang.ref.WeakReference; 8 | 9 | /** 10 | * Created by lucas.urbas on 29/08/15. 11 | */ 12 | public abstract class BasePresenter extends MvpBasePresenter implements PresenterForInteractor, PresenterForView { 13 | 14 | private I interactor; 15 | private WeakReference viewRef; 16 | 17 | public BasePresenter() { 18 | super(); 19 | this.interactor = createInteractor(); 20 | } 21 | 22 | @Override 23 | public void onViewCreated() { 24 | interactor.subscribePresenter(this); 25 | } 26 | 27 | @Override 28 | public void onPause() { 29 | 30 | } 31 | 32 | @Override 33 | public void onResume() { 34 | 35 | } 36 | 37 | @Override 38 | public void onDestroy() { 39 | interactor.unsubscribePresenter(); 40 | } 41 | 42 | @Override 43 | public I getInteractor() { 44 | return interactor; 45 | } 46 | 47 | @Override 48 | public void attachView(V view) { 49 | viewRef = new WeakReference(view); 50 | } 51 | 52 | /** 53 | * Get the attached view. You should always call {@link #isViewAttached()} to check if the view 54 | * is 55 | * attached to avoid NullPointerExceptions. 56 | * 57 | * @return null, if view is not attached, otherwise the concrete view instance 58 | */ 59 | @Nullable 60 | protected V getView() { 61 | return viewRef == null ? null : viewRef.get(); 62 | } 63 | 64 | /** 65 | * Checks if a view is attached to this presenter. You should always call this method before 66 | * calling {@link #getView()} to get the view instance. 67 | */ 68 | protected boolean isViewAttached() { 69 | return viewRef != null && viewRef.get() != null; 70 | } 71 | 72 | @Override 73 | public void detachView(boolean retainInstance) { 74 | if (viewRef != null) { 75 | viewRef.clear(); 76 | viewRef = null; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/Interactor.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | /** 4 | * Created by lucas.urbas on 29/08/15. 5 | */ 6 | public interface Interactor

{ 7 | 8 | P getPresenter(); 9 | 10 | boolean isPresenterSubscribed(); 11 | 12 | void subscribePresenter(P presenter); 13 | 14 | void unsubscribePresenter(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/PresenterForInteractor.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | /** 4 | * Created by lucas.urbas on 29/08/15. 5 | */ 6 | public interface PresenterForInteractor { 7 | 8 | I getInteractor(); 9 | 10 | I createInteractor(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/PresenterForView.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | import com.hannesdorfmann.mosby.mvp.MvpPresenter; 4 | 5 | /** 6 | * Created by Lucas on 29/08/15. 7 | */ 8 | public interface PresenterForView extends MvpPresenter { 9 | 10 | void onViewCreated(); 11 | 12 | void onPause(); 13 | 14 | void onResume(); 15 | 16 | void onDestroy(); 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/architecture/View.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.architecture; 2 | 3 | import com.hannesdorfmann.mosby.mvp.MvpView; 4 | 5 | /** 6 | * Created by Lucas on 29/08/15. 7 | */ 8 | public interface View extends MvpView { 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/constant/Field.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.constant; 2 | 3 | /** 4 | * Created by lucas.urbas on 31/08/15. 5 | */ 6 | public class Field { 7 | 8 | public static final String ID = "ID"; 9 | public static final String ORDER = "ORDER"; 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/dagger/InjectionModule.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.dagger; 2 | 3 | import android.content.Context; 4 | 5 | import com.google.gson.Gson; 6 | import com.google.gson.GsonBuilder; 7 | import com.lucasurbas.search.db.Database; 8 | import com.lucasurbas.search.db.ORMLiteHelper; 9 | import com.lucasurbas.search.db.ORMLiteDatabase; 10 | import com.lucasurbas.search.fragment.detail.DetailFragment; 11 | import com.lucasurbas.search.fragment.detail.interactor.DetailInteractorImpl; 12 | import com.lucasurbas.search.fragment.search.interactor.SearchInteractorImpl; 13 | import com.lucasurbas.search.widget.ItemViewHolder; 14 | import com.squareup.okhttp.OkHttpClient; 15 | import com.squareup.picasso.Picasso; 16 | 17 | import java.util.concurrent.TimeUnit; 18 | 19 | import javax.inject.Singleton; 20 | 21 | import dagger.Module; 22 | import dagger.Provides; 23 | 24 | /** 25 | * Created by Lucas on 29/08/15. 26 | */ 27 | @Module( 28 | library = true, 29 | injects = { 30 | ItemViewHolder.class, 31 | DetailFragment.class, 32 | SearchInteractorImpl.class, 33 | DetailInteractorImpl.class 34 | }, 35 | includes = { 36 | ApiModule.class 37 | }) 38 | public class InjectionModule { 39 | 40 | private static final int CACHE_TIME = 120; //seconds 41 | 42 | private Context applicationContext; 43 | 44 | public InjectionModule(Context context) { 45 | this.applicationContext = context; 46 | } 47 | 48 | @Provides 49 | @Singleton 50 | public Context provideContext() { 51 | return applicationContext; 52 | } 53 | 54 | @Provides 55 | @Singleton 56 | Picasso providesPicasso() { 57 | return Picasso.with(applicationContext); 58 | } 59 | 60 | // @Provides 61 | // Interceptor providesInterceptor() { 62 | // return new Interceptor() { 63 | // @Override 64 | // public Response intercept(Chain chain) throws IOException { 65 | // Response originalResponse = chain.proceed(chain.request()); 66 | // return originalResponse.newBuilder() 67 | // .header("Cache-Control", String.format("max-age=%d, only-if-cached, max-stale=%d", CACHE_TIME, 0)) 68 | // .build(); 69 | // 70 | // } 71 | // }; 72 | // } 73 | 74 | @Provides 75 | Gson providesGson() { 76 | return new GsonBuilder() 77 | .excludeFieldsWithoutExposeAnnotation() 78 | .create(); 79 | } 80 | 81 | @Provides 82 | OkHttpClient providesOkHttpClient() { 83 | OkHttpClient client = new OkHttpClient(); 84 | client.setConnectTimeout(10, TimeUnit.SECONDS); 85 | // client.setCache(new Cache(applicationContext.getCacheDir(), 10 * 1024 * 1024)); 86 | // client.networkInterceptors().add(interceptor); 87 | return client; 88 | } 89 | 90 | @Provides 91 | @Singleton 92 | ORMLiteHelper providesDatabaseHelper(Context context){ 93 | return new ORMLiteHelper(context); 94 | } 95 | 96 | @Provides 97 | @Singleton 98 | Database providesDatabase(ORMLiteHelper helper){ 99 | return new ORMLiteDatabase(helper); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/db/Database.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.db; 2 | 3 | import com.lucasurbas.search.model.IdProvider; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Created by lucas.urbas on 31/08/15. 9 | */ 10 | public interface Database { 11 | 12 | void reset(); 13 | 14 | void addOnTableChangedListener(OnTableChangedListener listener); 15 | 16 | void removeOnTableChangedListener(OnTableChangedListener listener); 17 | 18 | T getItem(Class type, Long id); 19 | 20 | List getItemList(Class type, List idList); 21 | 22 | void createOrUpdateItem(Class type, T item); 23 | 24 | void createOrUpdateItemList(Class type, List itemList); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/db/ORMLiteDatabase.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.db; 2 | 3 | import com.j256.ormlite.stmt.QueryBuilder; 4 | import com.lucasurbas.search.constant.Field; 5 | import com.lucasurbas.search.model.IdProvider; 6 | 7 | import java.sql.SQLException; 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.List; 11 | import java.util.concurrent.Callable; 12 | 13 | /** 14 | * Created by lucas.urbas on 31/08/15. 15 | */ 16 | public class ORMLiteDatabase implements Database { 17 | 18 | private static final String TAG = ORMLiteDatabase.class.getSimpleName(); 19 | 20 | private ORMLiteHelper helper; 21 | private List listenerList; 22 | 23 | public ORMLiteDatabase(ORMLiteHelper helper) { 24 | this.helper = helper; 25 | listenerList = Collections.synchronizedList(new ArrayList()); 26 | } 27 | 28 | @Override 29 | public void reset() { 30 | helper.resetDatabase(); 31 | } 32 | 33 | @Override 34 | public void addOnTableChangedListener(OnTableChangedListener listener) { 35 | listenerList.add(listener); 36 | } 37 | 38 | @Override 39 | public void removeOnTableChangedListener(OnTableChangedListener listener) { 40 | if(listener != null) { 41 | listenerList.remove(listener); 42 | } 43 | } 44 | 45 | @Override 46 | public T getItem(Class type, Long id) { 47 | try { 48 | return helper.getCustomDao(type).queryForId(id); 49 | } catch (SQLException e) { 50 | e.printStackTrace(); 51 | return null; 52 | } 53 | } 54 | 55 | @Override 56 | public List getItemList(Class type, List idList) { 57 | try { 58 | QueryBuilder query = helper.getCustomDao(type).queryBuilder(); 59 | query.where().in(Field.ID, idList); 60 | query.orderBy(Field.ORDER, true); 61 | return helper.getCustomDao(type).query(query.prepare()); 62 | } catch (SQLException e) { 63 | e.printStackTrace(); 64 | return null; 65 | } 66 | } 67 | 68 | @Override 69 | public void createOrUpdateItem(Class type, T item) { 70 | try { 71 | helper.getCustomDao(type).createOrUpdate(item); 72 | } catch (SQLException e) { 73 | e.printStackTrace(); 74 | return; 75 | } 76 | notifyDatabaseChanged(type, item); 77 | } 78 | 79 | @Override 80 | public void createOrUpdateItemList(final Class type, final List itemList) { 81 | try { 82 | helper.getCustomDao(type).callBatchTasks(new Callable() { 83 | @Override 84 | public Object call() throws Exception { 85 | for (T item : itemList) { 86 | helper.getCustomDao(type).createOrUpdate(item); 87 | } 88 | return null; 89 | } 90 | }); 91 | } catch (Exception e) { 92 | e.printStackTrace(); 93 | return; 94 | } 95 | notifyDatabaseChanged(type, itemList); 96 | } 97 | 98 | private void notifyDatabaseChanged(Class type, T item) { 99 | for (OnTableChangedListener listener : listenerList) { 100 | if (listener.getTableType().equals(type) && listener.getIds().contains(item.getId())) { 101 | listener.onChanged(); 102 | } 103 | } 104 | } 105 | 106 | private void notifyDatabaseChanged(Class type, List itemList) { 107 | for (OnTableChangedListener listener : listenerList) { 108 | if (listener.getTableType().equals(type)) { 109 | for (T item : itemList) { 110 | if (listener.getIds().contains(item.getId())) { 111 | listener.onChanged(); 112 | break; 113 | } 114 | } 115 | } 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/db/ORMLiteHelper.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.db; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | 6 | import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; 7 | import com.j256.ormlite.dao.Dao; 8 | import com.j256.ormlite.support.ConnectionSource; 9 | import com.j256.ormlite.table.TableUtils; 10 | import com.lucasurbas.search.model.SearchItem; 11 | 12 | import java.sql.SQLException; 13 | 14 | /** 15 | * Created by lucas.urbas on 31/08/15. 16 | */ 17 | public class ORMLiteHelper extends OrmLiteSqliteOpenHelper { 18 | 19 | private static final int VERSION = 1; 20 | private static final String DATABASE_NAME = "database"; 21 | 22 | public ORMLiteHelper(Context context) { 23 | super(context, DATABASE_NAME, null, VERSION); 24 | } 25 | 26 | @Override 27 | public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { 28 | try { 29 | TableUtils.createTable(connectionSource, SearchItem.class); 30 | } catch (SQLException e) { 31 | throw new RuntimeException(e); 32 | } 33 | } 34 | 35 | @Override 36 | public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { 37 | // for now, upgrades on DB version, consist on drop all DB.. 38 | 39 | try { 40 | TableUtils.dropTable(connectionSource, SearchItem.class, true); 41 | 42 | 43 | TableUtils.createTable(connectionSource, SearchItem.class); 44 | } catch (SQLException e) { 45 | throw new RuntimeException(e); 46 | } 47 | 48 | } 49 | 50 | public void resetDatabase() { 51 | try { 52 | // Drop tables 53 | TableUtils.dropTable(connectionSource, SearchItem.class, true); 54 | // Create Tables 55 | TableUtils.createTable(connectionSource, SearchItem.class); 56 | 57 | } catch (SQLException e) { 58 | throw new RuntimeException(e); 59 | } 60 | } 61 | 62 | public Dao getCustomDao(Class clazz) { 63 | try { 64 | return getDao(clazz); 65 | } catch (java.sql.SQLException e) { 66 | e.printStackTrace(); 67 | return null; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/db/OnTableChangedListener.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.db; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by lucas.urbas on 31/08/15. 7 | */ 8 | public interface OnTableChangedListener { 9 | 10 | void onChanged(); 11 | 12 | Class getTableType(); 13 | 14 | List getIds(); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/event/OpenDetailScreenEvent.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.event; 2 | 3 | import com.lucasurbas.search.model.SearchItem; 4 | 5 | /** 6 | * Created by Lucas on 31/08/15. 7 | */ 8 | public class OpenDetailScreenEvent { 9 | private SearchItem searchItem; 10 | 11 | public OpenDetailScreenEvent(SearchItem searchItem){ 12 | this.searchItem = searchItem; 13 | } 14 | 15 | public SearchItem getSearchItem() { 16 | return searchItem; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/DetailFragment.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.os.Bundle; 5 | import android.support.design.widget.FloatingActionButton; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.graphics.drawable.DrawableCompat; 8 | import android.support.v4.view.ViewCompat; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.LayoutInflater; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.ImageView; 16 | import android.widget.TextView; 17 | 18 | import com.hannesdorfmann.mosby.mvp.viewstate.ViewState; 19 | import com.lucasurbas.search.App; 20 | import com.lucasurbas.search.R; 21 | import com.lucasurbas.search.architecture.BaseFragment; 22 | import com.lucasurbas.search.fragment.detail.presenter.DetailPresenterForView; 23 | import com.lucasurbas.search.fragment.detail.presenter.DetailPresenterImpl; 24 | import com.lucasurbas.search.fragment.detail.view.DetailView; 25 | import com.lucasurbas.search.fragment.detail.view.DetailViewState; 26 | import com.lucasurbas.search.model.SearchItem; 27 | import com.lucasurbas.search.util.Util; 28 | import com.squareup.picasso.Picasso; 29 | 30 | import javax.inject.Inject; 31 | 32 | import butterknife.Bind; 33 | 34 | /** 35 | * Created by Lucas on 30/08/15. 36 | */ 37 | public class DetailFragment extends BaseFragment implements DetailView { 38 | 39 | private static final String TAG = DetailFragment.class.getSimpleName(); 40 | private static final String KEY_SEARCH_ITEM = "key_search_item"; 41 | 42 | @Inject 43 | Picasso picasso; 44 | 45 | @Bind(R.id.toolbar) 46 | Toolbar toolbar; 47 | 48 | @Bind(R.id.iv_image) 49 | ImageView ivImage; 50 | 51 | @Bind(R.id.tv_title) 52 | TextView tvTitle; 53 | 54 | @Bind(R.id.fab_favourite) 55 | FloatingActionButton fabFavourite; 56 | 57 | 58 | public static Fragment newInstance(SearchItem searchItem) { 59 | Fragment fragment = new DetailFragment(); 60 | Bundle b = new Bundle(); 61 | b.putParcelable(KEY_SEARCH_ITEM, searchItem); 62 | fragment.setArguments(b); 63 | return fragment; 64 | } 65 | 66 | @Override 67 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 68 | Bundle savedInstanceState) { 69 | return inflater.inflate(R.layout.fragment_detail, container, false); 70 | } 71 | 72 | @Override 73 | public void onViewCreated(View view, Bundle savedInstanceState) { 74 | //ButterKnife in parent class 75 | App.getObjectGraph().inject(this); 76 | super.onViewCreated(view, savedInstanceState); 77 | setupToolbar(); 78 | setupFab(); 79 | } 80 | 81 | private void setupToolbar() { 82 | ViewCompat.setElevation(toolbar, Util.pxFromDp(getActivity(), 4)); 83 | toolbar.setTitle(R.string.t_screen_details); 84 | toolbar.inflateMenu(R.menu.menu_detail); 85 | Menu menu = toolbar.getMenu(); 86 | MenuItem searchItem = menu.findItem(R.id.action_web); 87 | Drawable drawable = searchItem.getIcon(); 88 | drawable = DrawableCompat.wrap(drawable); 89 | DrawableCompat.setTint(drawable, getResources().getColor(R.color.toolbar_icon)); 90 | searchItem.setIcon(drawable); 91 | toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { 92 | @Override 93 | public boolean onMenuItemClick(MenuItem item) { 94 | switch (item.getItemId()) { 95 | case R.id.action_web: 96 | getPresenter().openInBrowser(); 97 | return true; 98 | } 99 | return false; 100 | } 101 | }); 102 | } 103 | 104 | private void setupFab() { 105 | fabFavourite.setOnClickListener(new View.OnClickListener() { 106 | @Override 107 | public void onClick(View v) { 108 | getPresenter().toggleFavourite(); 109 | } 110 | }); 111 | } 112 | 113 | @Override 114 | public ViewState createViewState() { 115 | return new DetailViewState(); 116 | } 117 | 118 | @Override 119 | public void onNewViewStateInstance() { 120 | SearchItem searchItem = getArguments().getParcelable(KEY_SEARCH_ITEM); 121 | getPresenter().initSearchItem(searchItem); 122 | getPresenter().setVisited(); 123 | } 124 | 125 | @Override 126 | public DetailPresenterForView createPresenter() { 127 | return new DetailPresenterImpl(getActivity()); 128 | } 129 | 130 | @Override 131 | public void setItem(SearchItem searchItem) { 132 | ((DetailViewState) getViewState()).setItem(searchItem); 133 | picasso.load(searchItem.getImageUrl()) 134 | .fit() 135 | .into(ivImage); 136 | tvTitle.setText(searchItem.getTitle()); 137 | } 138 | 139 | @Override 140 | public void showFavouriteState(boolean isFavourite) { 141 | ((DetailViewState) getViewState()).setFavourite(isFavourite); 142 | int resId = isFavourite ? R.drawable.ic_star_white_24dp : R.drawable.ic_star_border_white_24dp; 143 | 144 | final Drawable originalDrawable = getResources().getDrawable(resId); 145 | final Drawable wrappedDrawable = DrawableCompat.wrap(originalDrawable); 146 | 147 | int color = getResources().getColor(R.color.toolbar_icon); 148 | DrawableCompat.setTint(wrappedDrawable, color); 149 | fabFavourite.setImageDrawable(wrappedDrawable); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/interactor/DetailInteractor.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail.interactor; 2 | 3 | import com.lucasurbas.search.architecture.Interactor; 4 | import com.lucasurbas.search.fragment.detail.presenter.DetailPresenterForInteractor; 5 | import com.lucasurbas.search.model.SearchItem; 6 | 7 | /** 8 | * Created by Lucas on 30/08/15. 9 | */ 10 | public interface DetailInteractor extends Interactor{ 11 | 12 | void setFavourite(SearchItem searchItem, boolean favourite); 13 | 14 | void setVisited(SearchItem searchItem, boolean visited); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/interactor/DetailInteractorImpl.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail.interactor; 2 | 3 | import android.util.Log; 4 | 5 | import com.lucasurbas.search.App; 6 | import com.lucasurbas.search.architecture.BaseInteractor; 7 | import com.lucasurbas.search.db.Database; 8 | import com.lucasurbas.search.fragment.detail.presenter.DetailPresenterForInteractor; 9 | import com.lucasurbas.search.model.SearchItem; 10 | 11 | import javax.inject.Inject; 12 | 13 | import rx.Observable; 14 | import rx.Observer; 15 | import rx.android.schedulers.AndroidSchedulers; 16 | import rx.functions.Func1; 17 | import rx.schedulers.Schedulers; 18 | 19 | /** 20 | * Created by Lucas on 30/08/15. 21 | */ 22 | public class DetailInteractorImpl extends BaseInteractor implements DetailInteractor { 23 | 24 | private static final String TAG = DetailInteractorImpl.class.getSimpleName(); 25 | 26 | @Inject 27 | Database database; 28 | 29 | public DetailInteractorImpl(){ 30 | App.getObjectGraph().inject(this); 31 | } 32 | 33 | @Override 34 | public void setFavourite(final SearchItem searchItem, final boolean favourite) { 35 | Observable.just(searchItem) 36 | .map(UPDATE_IN_DB) 37 | .subscribeOn(Schedulers.io()) 38 | .observeOn(AndroidSchedulers.mainThread()) 39 | .subscribe(new Observer() { 40 | @Override 41 | public void onCompleted() { 42 | 43 | } 44 | 45 | @Override 46 | public void onError(Throwable e) { 47 | Log.v(TAG, "Error: " + e.getMessage()); 48 | if (isPresenterSubscribed()) { 49 | getPresenter().favouriteChanged(!favourite, false); 50 | } 51 | } 52 | 53 | @Override 54 | public void onNext(SearchItem item) { 55 | if (isPresenterSubscribed()) { 56 | getPresenter().favouriteChanged(favourite, true); 57 | } 58 | } 59 | }); 60 | } 61 | 62 | @Override 63 | public void setVisited(final SearchItem searchItem, final boolean visited) { 64 | Observable.just(searchItem) 65 | .map(UPDATE_IN_DB) 66 | .subscribeOn(Schedulers.io()) 67 | .observeOn(AndroidSchedulers.mainThread()) 68 | .subscribe(new Observer() { 69 | @Override 70 | public void onCompleted() { 71 | 72 | } 73 | 74 | @Override 75 | public void onError(Throwable e) { 76 | Log.v(TAG, "Error: " + e.getMessage()); 77 | if (isPresenterSubscribed()) { 78 | getPresenter().visitChanged(!visited, false); 79 | } 80 | } 81 | 82 | @Override 83 | public void onNext(SearchItem item) { 84 | if (isPresenterSubscribed()) { 85 | getPresenter().visitChanged(visited, true); 86 | } 87 | } 88 | }); 89 | } 90 | 91 | private final Func1 UPDATE_IN_DB = 92 | new Func1() { 93 | @Override 94 | public SearchItem call(SearchItem searchItem) { 95 | database.createOrUpdateItem(SearchItem.class, searchItem); 96 | return searchItem; 97 | } 98 | }; 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/presenter/DetailPresenterForInteractor.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail.presenter; 2 | 3 | import com.lucasurbas.search.architecture.PresenterForInteractor; 4 | import com.lucasurbas.search.fragment.detail.interactor.DetailInteractor; 5 | 6 | /** 7 | * Created by Lucas on 30/08/15. 8 | */ 9 | public interface DetailPresenterForInteractor extends PresenterForInteractor{ 10 | 11 | void visitChanged(boolean isVisited, boolean success); 12 | 13 | void favouriteChanged(boolean isFavourite, boolean success); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/presenter/DetailPresenterForView.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail.presenter; 2 | 3 | import com.lucasurbas.search.architecture.PresenterForView; 4 | import com.lucasurbas.search.fragment.detail.view.DetailView; 5 | import com.lucasurbas.search.model.SearchItem; 6 | 7 | /** 8 | * Created by Lucas on 30/08/15. 9 | */ 10 | public interface DetailPresenterForView extends PresenterForView{ 11 | 12 | void initSearchItem(SearchItem searchItem); 13 | 14 | void toggleFavourite(); 15 | 16 | void openInBrowser(); 17 | 18 | void setVisited(); 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/presenter/DetailPresenterImpl.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail.presenter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.util.Log; 7 | 8 | import com.lucasurbas.search.architecture.BasePresenter; 9 | import com.lucasurbas.search.fragment.detail.interactor.DetailInteractor; 10 | import com.lucasurbas.search.fragment.detail.interactor.DetailInteractorImpl; 11 | import com.lucasurbas.search.fragment.detail.view.DetailView; 12 | import com.lucasurbas.search.model.SearchItem; 13 | 14 | /** 15 | * Created by Lucas on 30/08/15. 16 | */ 17 | public class DetailPresenterImpl extends BasePresenter implements DetailPresenterForView, DetailPresenterForInteractor { 18 | 19 | private static final String TAG = DetailPresenterImpl.class.getSimpleName(); 20 | 21 | private Context context; 22 | private SearchItem searchItem; 23 | 24 | public DetailPresenterImpl(Context context) { 25 | this.context = context; 26 | } 27 | 28 | @Override 29 | public DetailInteractor createInteractor() { 30 | return new DetailInteractorImpl(); 31 | } 32 | 33 | @Override 34 | public void initSearchItem(SearchItem searchItem) { 35 | this.searchItem = searchItem; 36 | if (getView() != null) { 37 | getView().setItem(searchItem); 38 | getView().showFavouriteState(searchItem.isFavourite()); 39 | } 40 | } 41 | 42 | @Override 43 | public void toggleFavourite() { 44 | searchItem.setIsFavourite(!searchItem.isFavourite()); 45 | if (getView() != null) { 46 | getView().showFavouriteState(searchItem.isFavourite()); 47 | } 48 | getInteractor().setFavourite(searchItem, searchItem.isFavourite()); 49 | 50 | } 51 | 52 | @Override 53 | public void openInBrowser() { 54 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(searchItem.getWebUrl())); 55 | context.startActivity(browserIntent); 56 | } 57 | 58 | @Override 59 | public void setVisited() { 60 | if (!searchItem.isVisited()) { 61 | searchItem.setIsVisited(true); 62 | getInteractor().setVisited(searchItem, true); 63 | } 64 | } 65 | 66 | @Override 67 | public void visitChanged(boolean isVisited, boolean success) { 68 | if (!success) { 69 | searchItem.setIsVisited(isVisited); 70 | Log.e(TAG, "visitChanged Error"); 71 | } 72 | } 73 | 74 | @Override 75 | public void favouriteChanged(boolean isFavourite, boolean success) { 76 | if (!success) { 77 | Log.e(TAG, "favouriteChanged Error"); 78 | searchItem.setIsFavourite(isFavourite); 79 | if (getView() != null) { 80 | getView().showFavouriteState(isFavourite); 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/view/DetailView.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail.view; 2 | 3 | 4 | import com.lucasurbas.search.architecture.View; 5 | import com.lucasurbas.search.model.SearchItem; 6 | 7 | /** 8 | * Created by Lucas on 30/08/15. 9 | */ 10 | public interface DetailView extends View { 11 | 12 | void setItem(SearchItem searchItem); 13 | 14 | void showFavouriteState(boolean isFavourite); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/detail/view/DetailViewState.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.detail.view; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.hannesdorfmann.mosby.mvp.viewstate.RestoreableViewState; 6 | import com.lucasurbas.search.model.SearchItem; 7 | 8 | /** 9 | * Created by Lucas on 30/08/15. 10 | */ 11 | public class DetailViewState implements RestoreableViewState { 12 | 13 | private final String KEY_ITEM = "key_item"; 14 | private final String KEY_FAVOURITE = "key_favourite"; 15 | 16 | private SearchItem searchItem; 17 | private boolean isFavourite; 18 | 19 | @Override 20 | public void saveInstanceState(Bundle out) { 21 | out.putBoolean(KEY_FAVOURITE, isFavourite); 22 | out.putParcelable(KEY_ITEM, searchItem); 23 | } 24 | 25 | @Override 26 | public RestoreableViewState restoreInstanceState(Bundle in) { 27 | if (in == null) { 28 | return null; 29 | } 30 | this.isFavourite = in.getBoolean(KEY_FAVOURITE, false); 31 | this.searchItem = in.getParcelable(KEY_ITEM); 32 | return this; 33 | } 34 | 35 | @Override 36 | public void apply(DetailView view, boolean b) { 37 | 38 | view.showFavouriteState(isFavourite); 39 | view.setItem(searchItem); 40 | } 41 | 42 | public void setItem(SearchItem item) { 43 | this.searchItem = item; 44 | } 45 | 46 | public void setFavourite(boolean isFavourite) { 47 | this.isFavourite = isFavourite; 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/SearchFragment.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search; 2 | 3 | import android.graphics.drawable.Drawable; 4 | import android.os.Bundle; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.graphics.drawable.DrawableCompat; 7 | import android.support.v4.view.ViewCompat; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.LayoutInflater; 11 | import android.view.Menu; 12 | import android.view.MenuItem; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.hannesdorfmann.mosby.mvp.viewstate.ViewState; 19 | import com.lucasurbas.search.R; 20 | import com.lucasurbas.search.adapter.ItemsAdapter; 21 | import com.lucasurbas.search.architecture.BaseFragment; 22 | import com.lucasurbas.search.fragment.search.presenter.SearchPresenterForView; 23 | import com.lucasurbas.search.fragment.search.presenter.SearchPresenterImpl; 24 | import com.lucasurbas.search.fragment.search.view.SearchView; 25 | import com.lucasurbas.search.fragment.search.view.SearchViewState; 26 | import com.lucasurbas.search.model.SearchItem; 27 | import com.lucasurbas.search.util.Util; 28 | import com.lucasurbas.search.widget.RecyclerViewHelper; 29 | 30 | import java.util.List; 31 | 32 | import butterknife.Bind; 33 | 34 | public class SearchFragment extends BaseFragment implements SearchView { 35 | 36 | private static final String TAG = SearchFragment.class.getSimpleName(); 37 | 38 | @Bind(R.id.toolbar) 39 | Toolbar toolbar; 40 | 41 | @Bind(R.id.pi_searching) 42 | View piSearching; 43 | 44 | @Bind(R.id.rv_search_result) 45 | RecyclerView rvSearchResult; 46 | 47 | @Bind(R.id.tv_info) 48 | TextView tvInfo; 49 | 50 | private ItemsAdapter adapter; 51 | 52 | public static Fragment newInstance() { 53 | return new SearchFragment(); 54 | } 55 | 56 | @Override 57 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 58 | Bundle savedInstanceState) { 59 | return inflater.inflate(R.layout.fragment_search, container, false); 60 | } 61 | 62 | @Override 63 | public void onViewCreated(View view, Bundle savedInstanceState) { 64 | //ButterKnife in parent class 65 | super.onViewCreated(view, savedInstanceState); 66 | setupToolbar(); 67 | setupRecyclerView(); 68 | } 69 | 70 | private void setupToolbar() { 71 | ViewCompat.setElevation(toolbar, Util.pxFromDp(getActivity(), 4)); 72 | toolbar.setTitle(R.string.app_name); 73 | toolbar.inflateMenu(R.menu.menu_search); 74 | Menu menu = toolbar.getMenu(); 75 | MenuItem searchItem = menu.findItem(R.id.action_search); 76 | Drawable drawable = searchItem.getIcon(); 77 | drawable = DrawableCompat.wrap(drawable); 78 | DrawableCompat.setTint(drawable, getResources().getColor(R.color.toolbar_icon)); 79 | searchItem.setIcon(drawable); 80 | android.support.v7.widget.SearchView searchWidget = (android.support.v7.widget.SearchView) searchItem.getActionView(); 81 | searchWidget.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() { 82 | @Override 83 | public boolean onQueryTextSubmit(String query) { 84 | //search action 85 | getPresenter().search(query); 86 | return true; 87 | } 88 | 89 | @Override 90 | public boolean onQueryTextChange(String newText) { 91 | return false; 92 | } 93 | }); 94 | } 95 | 96 | private void setupRecyclerView() { 97 | RecyclerViewHelper.setup(getActivity(), rvSearchResult); 98 | 99 | adapter = new ItemsAdapter(getActivity()); 100 | rvSearchResult.setAdapter(adapter); 101 | } 102 | 103 | @Override 104 | public ViewState createViewState() { 105 | return new SearchViewState(); 106 | } 107 | 108 | @Override 109 | public void onNewViewStateInstance() { 110 | getPresenter().init(); 111 | } 112 | 113 | @Override 114 | public SearchPresenterForView createPresenter() { 115 | return new SearchPresenterImpl(getActivity()); 116 | } 117 | 118 | @Override 119 | public void showItemList(List itemList) { 120 | ((SearchViewState) getViewState()).setItemList(itemList); 121 | adapter.setItems(itemList); 122 | } 123 | 124 | @Override 125 | public void showProgressIndicator(boolean show) { 126 | ((SearchViewState) getViewState()).setSearching(show); 127 | piSearching.setVisibility(show ? View.VISIBLE : View.GONE); 128 | } 129 | 130 | @Override 131 | public void showError(String message) { 132 | Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); 133 | } 134 | 135 | @Override 136 | public void setInfoText(String text) { 137 | ((SearchViewState) getViewState()).setInfoText(text); 138 | tvInfo.setText(text); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/interactor/SearchInteractor.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search.interactor; 2 | 3 | import com.lucasurbas.search.architecture.Interactor; 4 | import com.lucasurbas.search.fragment.search.presenter.SearchPresenterForInteractor; 5 | 6 | /** 7 | * Created by Lucas on 29/08/15. 8 | */ 9 | public interface SearchInteractor extends Interactor { 10 | 11 | void search(String query); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/interactor/SearchInteractorImpl.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search.interactor; 2 | 3 | import android.util.Log; 4 | 5 | import com.lucasurbas.search.App; 6 | import com.lucasurbas.search.architecture.BaseInteractor; 7 | import com.lucasurbas.search.db.Database; 8 | import com.lucasurbas.search.db.OnTableChangedListener; 9 | import com.lucasurbas.search.fragment.search.presenter.SearchPresenterForInteractor; 10 | import com.lucasurbas.search.model.SearchItem; 11 | import com.lucasurbas.search.model.SearchItemsProvider; 12 | import com.lucasurbas.search.request.SearchApi; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | import javax.inject.Inject; 18 | 19 | import rx.Observable; 20 | import rx.Observer; 21 | import rx.android.schedulers.AndroidSchedulers; 22 | import rx.functions.Func1; 23 | import rx.schedulers.Schedulers; 24 | 25 | /** 26 | * Created by Lucas on 29/08/15. 27 | */ 28 | public class SearchInteractorImpl extends BaseInteractor implements SearchInteractor { 29 | 30 | private static final String TAG = SearchInteractorImpl.class.getSimpleName(); 31 | 32 | @Inject 33 | SearchApi searchApi; 34 | @Inject 35 | Database database; 36 | 37 | private List ids; 38 | 39 | private OnTableChangedListener onTableChangedListener = new OnTableChangedListener() { 40 | @Override 41 | public void onChanged() { 42 | Log.v(TAG, "!!! Database Changed !!!"); 43 | getSearchItemsFromDatabase(ids); 44 | } 45 | 46 | @Override 47 | public Class getTableType() { 48 | return SearchItem.class; 49 | } 50 | 51 | @Override 52 | public List getIds() { 53 | return ids; 54 | } 55 | }; 56 | 57 | public SearchInteractorImpl() { 58 | App.getObjectGraph().inject(this); 59 | } 60 | 61 | @Override 62 | public void search(String query) { 63 | searchApi.query(query) 64 | .map(UPDATE_IN_DB) 65 | .subscribeOn(Schedulers.io()) 66 | .observeOn(AndroidSchedulers.mainThread()) 67 | .subscribe(new Observer>() { 68 | @Override 69 | public void onCompleted() { 70 | 71 | } 72 | 73 | @Override 74 | public void onError(Throwable e) { 75 | Log.v(TAG, "Error: " + e.getMessage()); 76 | if (isPresenterSubscribed()) { 77 | getPresenter().showItemList(false, null, true); 78 | } 79 | } 80 | 81 | @Override 82 | public void onNext(List itemList) { 83 | if (isPresenterSubscribed()) { 84 | getPresenter().showItemList(true, itemList, true); 85 | } 86 | } 87 | }); 88 | } 89 | 90 | private final Func1> UPDATE_IN_DB = 91 | new Func1>() { 92 | @Override 93 | public List call(SearchItemsProvider provider) { 94 | database.removeOnTableChangedListener(onTableChangedListener); 95 | 96 | List itemsFromApi = provider.getSearchItems(); 97 | ids = extractIdList(itemsFromApi); 98 | List itemsFromDb = database.getItemList(SearchItem.class, ids); 99 | List itemsUpdated = update(itemsFromApi, itemsFromDb); 100 | database.createOrUpdateItemList(SearchItem.class, itemsUpdated); 101 | 102 | database.addOnTableChangedListener(onTableChangedListener); 103 | return itemsUpdated; 104 | } 105 | }; 106 | 107 | private List extractIdList(List itemsFromApi) { 108 | List ids = new ArrayList<>(); 109 | for(SearchItem searchItem : itemsFromApi){ 110 | ids.add(searchItem.getId()); 111 | } 112 | return ids; 113 | } 114 | 115 | private List update(List itemsFromApi, List itemsFromDb) { 116 | int i = 0; 117 | for(SearchItem searchItem : itemsFromApi){ 118 | searchItem.setOrder(++i); 119 | for(SearchItem searchItemFromDb : itemsFromDb){ 120 | if(searchItem.getId() == searchItemFromDb.getId()){ 121 | searchItem.setIsFavourite(searchItemFromDb.isFavourite()); 122 | searchItem.setIsVisited(searchItemFromDb.isVisited()); 123 | break; 124 | } 125 | } 126 | } 127 | return itemsFromApi; 128 | } 129 | 130 | private void getSearchItemsFromDatabase(final List ids){ 131 | Observable.just(ids) 132 | .map(GET_FROM_DB) 133 | .subscribeOn(Schedulers.io()) 134 | .observeOn(AndroidSchedulers.mainThread()) 135 | .subscribe(new Observer>() { 136 | @Override 137 | public void onCompleted() { 138 | 139 | } 140 | 141 | @Override 142 | public void onError(Throwable e) { 143 | Log.v(TAG, "Error: " + e.getMessage()); 144 | } 145 | 146 | @Override 147 | public void onNext(List itemList) { 148 | if (isPresenterSubscribed()) { 149 | getPresenter().showItemList(true, itemList, false); 150 | } 151 | } 152 | }); 153 | } 154 | 155 | private final Func1, List> GET_FROM_DB = 156 | new Func1, List>() { 157 | @Override 158 | public List call(List ids) { 159 | List itemsFromDb = database.getItemList(SearchItem.class, ids); 160 | return itemsFromDb; 161 | } 162 | }; 163 | 164 | @Override 165 | public void unsubscribePresenter() { 166 | super.unsubscribePresenter(); 167 | database.removeOnTableChangedListener(onTableChangedListener); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/presenter/SearchPresenterForInteractor.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search.presenter; 2 | 3 | import com.lucasurbas.search.architecture.PresenterForInteractor; 4 | import com.lucasurbas.search.fragment.search.interactor.SearchInteractor; 5 | import com.lucasurbas.search.model.SearchItem; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Lucas on 29/08/15. 11 | */ 12 | public interface SearchPresenterForInteractor extends PresenterForInteractor{ 13 | 14 | void showItemList(boolean success, List itemList, boolean isRequested); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/presenter/SearchPresenterForView.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search.presenter; 2 | 3 | import com.lucasurbas.search.architecture.PresenterForView; 4 | import com.lucasurbas.search.fragment.search.view.SearchView; 5 | 6 | /** 7 | * Created by Lucas on 29/08/15. 8 | */ 9 | public interface SearchPresenterForView extends PresenterForView{ 10 | 11 | void init(); 12 | 13 | void search(String query); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/presenter/SearchPresenterImpl.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search.presenter; 2 | 3 | import android.content.Context; 4 | 5 | import com.lucasurbas.search.R; 6 | import com.lucasurbas.search.architecture.BasePresenter; 7 | import com.lucasurbas.search.fragment.search.interactor.SearchInteractor; 8 | import com.lucasurbas.search.fragment.search.interactor.SearchInteractorImpl; 9 | import com.lucasurbas.search.fragment.search.view.SearchView; 10 | import com.lucasurbas.search.model.SearchItem; 11 | 12 | import java.util.List; 13 | import java.util.concurrent.atomic.AtomicInteger; 14 | 15 | /** 16 | * Created by Lucas on 29/08/15. 17 | */ 18 | public class SearchPresenterImpl extends BasePresenter implements SearchPresenterForView, SearchPresenterForInteractor { 19 | 20 | private static final String EMPTY = ""; 21 | 22 | private AtomicInteger queryCounter; 23 | private Context context; 24 | 25 | public SearchPresenterImpl(Context context) { 26 | this.context = context; 27 | this.queryCounter = new AtomicInteger(); 28 | } 29 | 30 | @Override 31 | public void init() { 32 | if (getView() != null) { 33 | getView().setInfoText(context.getString(R.string.t_welcome)); 34 | } 35 | } 36 | 37 | @Override 38 | public SearchInteractor createInteractor() { 39 | return new SearchInteractorImpl(); 40 | } 41 | 42 | @Override 43 | public void search(String query) { 44 | if (queryCounter.getAndIncrement() == 0) { 45 | if (getView() != null) { 46 | getView().showProgressIndicator(true); 47 | getView().setInfoText(EMPTY); 48 | } 49 | } 50 | getInteractor().search(query); 51 | } 52 | 53 | @Override 54 | public void showItemList(boolean success, List itemList, boolean isRequested) { 55 | if (isRequested && queryCounter.decrementAndGet() == 0) { 56 | if (getView() != null) { 57 | getView().showProgressIndicator(false); 58 | } 59 | } 60 | if (getView() != null) { 61 | getView().setInfoText(EMPTY); 62 | } 63 | if (getView() != null && success) { 64 | getView().showItemList(itemList); 65 | if (itemList.size() <= 0) { 66 | getView().setInfoText(context.getString(R.string.t_no_items)); 67 | } 68 | } else if (getView() != null) { 69 | getView().showError(context.getString(R.string.error_connection)); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/view/SearchView.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search.view; 2 | 3 | 4 | import com.lucasurbas.search.architecture.View; 5 | import com.lucasurbas.search.model.SearchItem; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by Lucas on 29/08/15. 11 | */ 12 | public interface SearchView extends View { 13 | 14 | void showItemList(List itemList); 15 | 16 | void showProgressIndicator(boolean show); 17 | 18 | void showError(String message); 19 | 20 | void setInfoText(String text); 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/fragment/search/view/SearchViewState.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.fragment.search.view; 2 | 3 | import android.os.Bundle; 4 | 5 | import com.hannesdorfmann.mosby.mvp.viewstate.RestoreableViewState; 6 | import com.lucasurbas.search.model.SearchItem; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Lucas on 29/08/15. 13 | */ 14 | public class SearchViewState implements RestoreableViewState { 15 | 16 | private final String KEY_ITEMS = "key_items"; 17 | private final String KEY_SEARCHING = "key_searching"; 18 | private final String KEY_INFO_TEXT = "key_info_text"; 19 | 20 | private ArrayList searchItemList; 21 | private boolean isSearching; 22 | private String infoText; 23 | 24 | @Override 25 | public void saveInstanceState(Bundle out) { 26 | out.putBoolean(KEY_SEARCHING, isSearching); 27 | out.putParcelableArrayList(KEY_ITEMS, searchItemList); 28 | out.putString(KEY_INFO_TEXT, infoText); 29 | } 30 | 31 | @Override 32 | public RestoreableViewState restoreInstanceState(Bundle in) { 33 | if (in == null) { 34 | return null; 35 | } 36 | this.isSearching = in.getBoolean(KEY_SEARCHING, false); 37 | this.searchItemList = in.getParcelableArrayList(KEY_ITEMS); 38 | this.infoText = in.getString(KEY_INFO_TEXT); 39 | return this; 40 | } 41 | 42 | @Override 43 | public void apply(SearchView view, boolean b) { 44 | view.showProgressIndicator(isSearching); 45 | view.showItemList(searchItemList); 46 | view.setInfoText(infoText); 47 | } 48 | 49 | public void setSearching(boolean isSearching) { 50 | this.isSearching = isSearching; 51 | } 52 | 53 | public void setItemList(List itemList) { 54 | if(itemList != null) { 55 | this.searchItemList = new ArrayList<>(itemList); 56 | } 57 | } 58 | 59 | public void setInfoText(String infoText) { 60 | this.infoText = infoText; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/model/IdProvider.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.model; 2 | 3 | /** 4 | * Created by lucas.urbas on 31/08/15. 5 | */ 6 | public interface IdProvider { 7 | long getId(); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/model/SearchItem.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.j256.ormlite.field.DatabaseField; 7 | import com.j256.ormlite.table.DatabaseTable; 8 | import com.lucasurbas.search.constant.Field; 9 | 10 | /** 11 | * Created by Lucas on 30/08/15. 12 | */ 13 | @DatabaseTable 14 | public class SearchItem implements Parcelable, IdProvider { 15 | 16 | @DatabaseField(id = true) 17 | private long id; 18 | 19 | @DatabaseField() 20 | private String title; 21 | 22 | @DatabaseField() 23 | private String imageUrl; 24 | 25 | @DatabaseField() 26 | private String webUrl; 27 | 28 | @DatabaseField() 29 | private boolean isFavourite; 30 | 31 | @DatabaseField() 32 | private boolean isVisited; 33 | 34 | @DatabaseField(columnName = Field.ORDER) 35 | private int order; 36 | 37 | public SearchItem() { 38 | // for ORMLite 39 | } 40 | 41 | protected SearchItem(Parcel in) { 42 | readFromParcel(in); 43 | } 44 | 45 | public static final Creator CREATOR = new Creator() { 46 | @Override 47 | public SearchItem createFromParcel(Parcel in) { 48 | return new SearchItem(in); 49 | } 50 | 51 | @Override 52 | public SearchItem[] newArray(int size) { 53 | return new SearchItem[size]; 54 | } 55 | }; 56 | 57 | @Override 58 | public long getId() { 59 | return id; 60 | } 61 | 62 | public void setId(long id) { 63 | this.id = id; 64 | } 65 | 66 | public String getTitle() { 67 | return title; 68 | } 69 | 70 | public void setTitle(String title) { 71 | this.title = title; 72 | } 73 | 74 | public String getImageUrl() { 75 | return imageUrl; 76 | } 77 | 78 | public void setImageUrl(String imageUrl) { 79 | this.imageUrl = imageUrl; 80 | } 81 | 82 | public String getWebUrl() { 83 | return webUrl; 84 | } 85 | 86 | public void setWebUrl(String webUrl) { 87 | this.webUrl = webUrl; 88 | } 89 | 90 | public boolean isFavourite() { 91 | return isFavourite; 92 | } 93 | 94 | public void setIsFavourite(boolean isFavourite) { 95 | this.isFavourite = isFavourite; 96 | } 97 | 98 | public boolean isVisited() { 99 | return isVisited; 100 | } 101 | 102 | public void setIsVisited(boolean isVisited) { 103 | this.isVisited = isVisited; 104 | } 105 | 106 | public void setOrder(int order) { 107 | this.order = order; 108 | } 109 | 110 | @Override 111 | public int describeContents() { 112 | return 0; 113 | } 114 | 115 | @Override 116 | public void writeToParcel(Parcel out, int i) { 117 | out.writeLong(id); 118 | out.writeString(title); 119 | out.writeString(imageUrl); 120 | out.writeString(webUrl); 121 | out.writeByte((byte) (isFavourite ? 1 : 0)); 122 | out.writeByte((byte) (isVisited ? 1 : 0)); 123 | out.writeInt(order); 124 | } 125 | 126 | private void readFromParcel(Parcel in){ 127 | id = in.readLong(); 128 | title = in.readString(); 129 | imageUrl = in.readString(); 130 | webUrl = in.readString(); 131 | isFavourite = in.readByte() != 0; 132 | isVisited = in.readByte() != 0; 133 | order = in.readInt(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/model/SearchItemsProvider.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by Lucas on 29/08/15. 7 | */ 8 | public interface SearchItemsProvider { 9 | 10 | List getSearchItems(); 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/request/SearchApi.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.request; 2 | 3 | import com.lucasurbas.search.model.SearchItemsProvider; 4 | 5 | import rx.Observable; 6 | 7 | /** 8 | * Created by Lucas on 29/08/15. 9 | */ 10 | public interface SearchApi { 11 | 12 | Observable query(String query); 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/util/ResourceHelper.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.util; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageManager; 5 | import android.content.res.Resources; 6 | import android.content.res.TypedArray; 7 | 8 | import com.lucasurbas.search.R; 9 | 10 | /** 11 | * Created by Lucas on 29/08/15. 12 | */ 13 | public class ResourceHelper { 14 | 15 | /** 16 | * Get a color value from a theme attribute. 17 | * 18 | * @param context used for getting the color. 19 | * @param attribute theme attribute. 20 | * @param defaultColor default to use. 21 | * @return color value 22 | */ 23 | public static int getThemeColor(Context context, int attribute, int defaultColor) { 24 | int themeColor = 0; 25 | String packageName = context.getPackageName(); 26 | try { 27 | Context packageContext = context.createPackageContext(packageName, 0); 28 | packageContext.setTheme(R.style.AppTheme); 29 | Resources.Theme theme = packageContext.getTheme(); 30 | TypedArray ta = theme.obtainStyledAttributes(new int[]{attribute}); 31 | themeColor = ta.getColor(0, defaultColor); 32 | ta.recycle(); 33 | } catch (PackageManager.NameNotFoundException e) { 34 | e.printStackTrace(); 35 | } 36 | return themeColor; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/util/Util.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.util; 2 | 3 | import android.content.Context; 4 | 5 | /** 6 | * Created by Lucas on 29/08/15. 7 | */ 8 | public class Util { 9 | 10 | public static float pxFromDp(final Context context, final float dp) { 11 | return dp * context.getResources().getDisplayMetrics().density; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/widget/FixedRatioImageView.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | import android.widget.ImageView; 7 | 8 | import com.lucasurbas.search.R; 9 | 10 | /** 11 | * Created by Lucas on 29/08/15. 12 | */ 13 | public class FixedRatioImageView extends ImageView { 14 | 15 | private int aspectRatioWidth; 16 | private int aspectRatioHeight; 17 | 18 | public FixedRatioImageView(Context context) { 19 | super(context); 20 | } 21 | 22 | public FixedRatioImageView(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | init(context, attrs); 25 | } 26 | 27 | public FixedRatioImageView(Context context, AttributeSet attrs, int defStyle) { 28 | super(context, attrs, defStyle); 29 | init(context, attrs); 30 | } 31 | 32 | private void init(Context context, AttributeSet attrs) { 33 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FixedRatioImageView); 34 | 35 | aspectRatioWidth = a.getInt(R.styleable.FixedRatioImageView_ratioWidth, 4); 36 | aspectRatioHeight = a.getInt(R.styleable.FixedRatioImageView_ratioHeight, 3); 37 | 38 | a.recycle(); 39 | } 40 | 41 | @Override 42 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 43 | int originalWidth = MeasureSpec.getSize(widthMeasureSpec); 44 | int originalHeight = MeasureSpec.getSize(heightMeasureSpec); 45 | 46 | int calculatedHeight = originalWidth * aspectRatioHeight / aspectRatioWidth; 47 | 48 | int finalWidth, finalHeight; 49 | 50 | finalWidth = originalWidth; 51 | finalHeight = calculatedHeight; 52 | 53 | 54 | super.onMeasure( 55 | MeasureSpec.makeMeasureSpec(finalWidth, MeasureSpec.EXACTLY), 56 | MeasureSpec.makeMeasureSpec(finalHeight, MeasureSpec.EXACTLY)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/lucasurbas/search/widget/ProgressIndicator.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search.widget; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.Color; 6 | import android.graphics.Outline; 7 | import android.os.Build; 8 | import android.support.v4.view.ViewCompat; 9 | import android.util.AttributeSet; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewOutlineProvider; 13 | import android.widget.FrameLayout; 14 | 15 | import com.lucasurbas.search.R; 16 | import com.lucasurbas.search.util.Util; 17 | 18 | /** 19 | * Created by Lucas on 29/08/15. 20 | */ 21 | public class ProgressIndicator extends FrameLayout { 22 | 23 | public ProgressIndicator(Context context) { 24 | super(context); 25 | inflateChild(context); 26 | init(); 27 | } 28 | 29 | public ProgressIndicator(Context context, AttributeSet attrs) { 30 | super(context, attrs); 31 | inflateChild(context); 32 | init(); 33 | } 34 | 35 | private void inflateChild(Context context) { 36 | LayoutInflater.from(context).inflate(R.layout.widget_progress_indicator, this, true); 37 | } 38 | 39 | private void init() { 40 | 41 | ViewCompat.setElevation(this, Util.pxFromDp(getContext(), 8)); 42 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 43 | ViewOutlineProvider viewOutlineProvider = new ViewOutlineProvider() { 44 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 45 | @Override 46 | public void getOutline(View view, Outline outline) { 47 | // Or read size directly from the view's width/height 48 | int w = ViewCompat.isLaidOut(ProgressIndicator.this) ? getWidth() : getMeasuredWidth(); 49 | int h = ViewCompat.isLaidOut(ProgressIndicator.this) ? getHeight() : getMeasuredHeight(); 50 | outline.setOval(0, 0, w, h); 51 | } 52 | }; 53 | setBackgroundColor(Color.WHITE); 54 | setOutlineProvider(viewOutlineProvider); 55 | setClipToOutline(true); 56 | } else { 57 | setBackgroundResource(R.drawable.background_progress_bar); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-hdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_star_border_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-hdpi/ic_star_border_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_star_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-hdpi/ic_star_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_web_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-hdpi/ic_web_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-mdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_star_border_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-mdpi/ic_star_border_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_star_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-mdpi/ic_star_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_web_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-mdpi/ic_web_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xhdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_star_border_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xhdpi/ic_star_border_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_star_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xhdpi/ic_star_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_web_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xhdpi/ic_web_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_star_border_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxhdpi/ic_star_border_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_star_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxhdpi/ic_star_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_web_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxhdpi/ic_web_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_star_border_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxxhdpi/ic_star_border_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_star_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxxhdpi/ic_star_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_web_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/drawable-xxxhdpi/ic_web_white_24dp.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/background_progress_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout-sw720dp/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 16 | 17 | 22 | 23 | 28 | 29 | 30 | 41 | 42 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 18 | 19 | 22 | 23 | 30 | 31 | 42 | 43 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_search.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 17 | 18 | 25 | 26 | 30 | 31 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/widget_progress_indicator.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_detail.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_search.xml: -------------------------------------------------------------------------------- 1 | 3 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -28dp 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -46dp 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Settings 4 | Search 5 | Web 6 | 7 | Connection Error 8 | No description 9 | No items 10 | Welcome!\nStart searching 11 | 12 | Details 13 | LOGO 14 | 15 | Best Match 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/test/java/com/lucasurbas/search/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.lucasurbas.search; 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:1.3.0' 9 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | maven{ 20 | url 'https://oss.sonatype.org/content/repositories/snapshots/' 21 | } 22 | 23 | maven { 24 | url "https://jitpack.io" 25 | } 26 | 27 | maven { 28 | url 'https://clojars.org/repo/' 29 | } 30 | } 31 | } 32 | 33 | task clean(type: Delete) { 34 | delete rootProject.buildDir 35 | } 36 | -------------------------------------------------------------------------------- /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/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Aug 28 21:17:22 CEST 2015 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.4-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 | -------------------------------------------------------------------------------- /readme/viper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lurbas/ViperArchitectureExample/764c065d36a673be39cd2e82ab4c4c928dde265b/readme/viper.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------