├── .gitconfig ├── .gitignore ├── LICENSE ├── Readme.md ├── android ├── .gitignore ├── app │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── in │ │ │ └── ashwanik │ │ │ └── retroclient │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── in │ │ │ │ └── ashwanik │ │ │ │ └── retroclientsample │ │ │ │ ├── BaseApplication.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── MainActivityFragment.java │ │ │ │ ├── models │ │ │ │ ├── Author.java │ │ │ │ ├── BaseObject.java │ │ │ │ ├── Book.java │ │ │ │ ├── BookResponse.java │ │ │ │ └── ErrorBody.java │ │ │ │ └── web │ │ │ │ ├── ApiUrls.java │ │ │ │ └── clients │ │ │ │ ├── AuthorClient.java │ │ │ │ └── BookClient.java │ │ └── res │ │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ ├── content_main.xml │ │ │ └── fragment_main.xml │ │ │ ├── menu │ │ │ └── menu_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-v21 │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── in │ │ └── ashwanik │ │ └── retroclient │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── retro-client │ ├── .gitignore │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── in │ │ │ └── ashwanik │ │ │ ├── retroclient │ │ │ └── ApplicationTest.java │ │ │ └── retroclientlib │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── in │ │ │ │ └── ashwanik │ │ │ │ └── retroclient │ │ │ │ ├── RetroClientServiceInitializer.java │ │ │ │ ├── clients │ │ │ │ └── RetroHttpClient.java │ │ │ │ ├── entities │ │ │ │ ├── DefaultData.java │ │ │ │ ├── ErrorCode.java │ │ │ │ ├── ErrorData.java │ │ │ │ └── ErrorType.java │ │ │ │ ├── interfaces │ │ │ │ ├── ILogger.java │ │ │ │ └── RequestHandler.java │ │ │ │ ├── service │ │ │ │ ├── RetroClientServiceGenerator.java │ │ │ │ └── ServiceGenerator.java │ │ │ │ ├── ui │ │ │ │ ├── CircularProgressDrawable.java │ │ │ │ └── TransparentProgressDialog.java │ │ │ │ └── utils │ │ │ │ ├── Helpers.java │ │ │ │ └── Json.java │ │ └── res │ │ │ └── values │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── in │ │ └── ashwanik │ │ └── retroclientlib │ │ └── ExampleUnitTest.java └── settings.gradle └── api ├── .gitignore ├── app.js └── package.json /.gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | name = Ashwani Kumar 3 | email = "ashwanikumar04@gmail.com" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | gen 3 | .gradle 4 | build 5 | .settings 6 | target 7 | *.iml 8 | .idea 9 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ashwani Kumar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Retro-Client 2 | 3 | Basic features: 4 | 5 | * Provides out of the box network check and error handling 6 | * Show progress view while making network calls 7 | * Multiple methods for initializing Retrofit services 8 | 9 | 10 | ## Installation 11 | 12 | ``` 13 | 14 | compile 'in.ashwanik:retro-client:0.1.2' 15 | 16 | ``` 17 | 18 | ## Usage 19 | Initialize *RetroClient* using **RetroClientServiceInitializer** in an activity or Application class 20 | 21 | ``` 22 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 23 | progressViewColor = getResources().getColor(R.color.colorPrimary, null); 24 | } else { 25 | progressViewColor = getResources().getColor(R.color.colorPrimary); 26 | } 27 | RetroClientServiceInitializer.getInstance().initialize(ApiUrls.BASE_API_URL, getApplicationContext(), progressViewColor, true); 28 | RetroClientServiceInitializer.getInstance().setLogCategoryName("Retro-Client-Sample"); 29 | 30 | ``` 31 | ### Add interceptor 32 | 33 | ``` 34 | List interceptors = new ArrayList<>(); 35 | interceptors.add(new Interceptor() { 36 | @Override 37 | public Response intercept(Chain chain) throws IOException { 38 | Request request = chain.request(); 39 | Response response = chain.proceed(request); 40 | Helpers.d(RetroClientServiceInitializer.getInstance().getLogCategoryName(), response.code() + ""); 41 | return response; 42 | } 43 | }); 44 | RetroClientServiceInitializer.getInstance() 45 | .initialize(ApiUrls.BASE_API_URL, progressViewColor, true, 10 * 1024 * 1024, getCacheDir(), interceptors, null); 46 | RetroClientServiceInitializer.getInstance().setLogCategoryName("Retro-Client-Sample"); 47 | 48 | ``` 49 | 50 | ### Define a client 51 | 52 | ``` 53 | 54 | public interface BookClient { 55 | @GET("/books/{bookId}") 56 | Call get(@Path("bookId") Integer bookId); 57 | 58 | @GET("/books") 59 | Call> get(); 60 | 61 | @POST("/books") 62 | Call create(@Body Book book); 63 | 64 | @PUT("/books/{bookId}") 65 | Call update(@Body Book book, @Path("bookId") Integer bookId); 66 | 67 | @DELETE("/books/{bookId}") 68 | Call delete(@Path("bookId") Integer bookId); 69 | } 70 | 71 | ``` 72 | ### Make the call 73 | 74 | ``` 75 | 76 | RetroClientServiceGenerator serviceGenerator = new RetroClientServiceGenerator(MainActivityFragment.this.getActivity(), false); 77 | BookClient client = serviceGenerator.getService(BookClient.class); 78 | serviceGenerator.execute(client.get(1), new RequestHandler() { 79 | @Override 80 | public void onSuccess(Book response) { 81 | Log.d("RetrofitSample", response.toString()); 82 | } 83 | 84 | @Override 85 | public void onError(ErrorData errorData) { 86 | Log.d("RetrofitSample", errorData.toString()); 87 | } 88 | }); 89 | 90 | ``` 91 | 92 | ### Options for **RetroClientServiceInitializer** 93 | * **baseUrl**: Base Url for API 94 | * **converterFactory**: Set converter factory. Default is JSON 95 | * **timeOut**: Timeout (seconds) for network calls. Default is 30 96 | * **enableRetry**: Enable request retry. Default true 97 | * **isDebug**: Enabling debugging. Level.BODY is used for logging. Default is false 98 | * **logCategoryName**: Log category 99 | * **progressViewColor**: Specify the color of progress view 100 | * **logger**: Logger used for logging exception etc to external services like Crashlytics. 101 | * **cacheDirectory**: Pass location of cache directory. 102 | * **cacheSize**: Size of cache. 103 | 104 | 105 | #### Sample app is available [here](https://github.com/ashwanikumar04/retroclient/tree/master/android) 106 | #### Sample rest API using Node.js is available [here](https://github.com/ashwanikumar04/retroclient/tree/master/api) 107 | 108 | ## History 109 | - Released 0.1.2 version 110 | * Updated Retrofit version 111 | * Fixed issues 112 | * Added support for adding network and application level interceptors 113 | - Released 0.1.1 version 114 | * Updated Retrofit version 115 | * Added support for changing default messages 116 | * Added support for changing cache directory 117 | * Added support for changing cache directory size 118 | * Code refactoring 119 | 120 | - Released 0.1.0 version 121 | 122 | 123 | ## Credits 124 | 1. Nice code for [circular progress view](https://gist.github.com/dmide/7506c7d9614eed90805d) 125 | 2. Retrofit [Examples](https://github.com/square/retrofit/tree/master/samples) 126 | 3. Tutorials on Retrofit by [FutureStud](https://futurestud.io/blog/retrofit-getting-started-and-android-client) 127 | 128 | 129 | 130 | 131 | For more tutorials on Android, please check [here](http://blog.ashwanik.in). -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "in.ashwanik.retroclientsample" 9 | minSdkVersion 16 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.android.support:design:23.1.1' 27 | compile 'com.jakewharton:butterknife:7.0.1' 28 | compile project(':retro-client') 29 | } 30 | -------------------------------------------------------------------------------- /android/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 I:\Installs\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 | -------------------------------------------------------------------------------- /android/app/src/androidTest/java/in/ashwanik/retroclient/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclient; 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 | } -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/BaseApplication.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample; 2 | 3 | import android.app.Application; 4 | import android.os.Build; 5 | 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import in.ashwanik.retroclient.RetroClientServiceInitializer; 11 | import in.ashwanik.retroclient.utils.Helpers; 12 | import in.ashwanik.retroclientsample.web.ApiUrls; 13 | import okhttp3.Interceptor; 14 | import okhttp3.Request; 15 | import okhttp3.Response; 16 | 17 | 18 | public class BaseApplication extends Application { 19 | 20 | @Override 21 | public void onCreate() { 22 | super.onCreate(); 23 | int progressViewColor; 24 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 25 | progressViewColor = getResources().getColor(R.color.colorPrimary, null); 26 | } else { 27 | progressViewColor = getResources().getColor(R.color.colorPrimary); 28 | } 29 | List interceptors = new ArrayList<>(); 30 | interceptors.add(new Interceptor() { 31 | @Override 32 | public Response intercept(Chain chain) throws IOException { 33 | Request request = chain.request(); 34 | Response response = chain.proceed(request); 35 | Helpers.d(RetroClientServiceInitializer.getInstance().getLogCategoryName(), response.code() + ""); 36 | return response; 37 | } 38 | }); 39 | RetroClientServiceInitializer.getInstance() 40 | .initialize(ApiUrls.BASE_API_URL, progressViewColor, true, 10 * 1024 * 1024, getCacheDir(), interceptors, null); 41 | RetroClientServiceInitializer.getInstance().setLogCategoryName("Retro-Client-Sample"); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.Toolbar; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | 9 | 10 | public class MainActivity extends AppCompatActivity { 11 | 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_main); 16 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 17 | setSupportActionBar(toolbar); 18 | 19 | } 20 | 21 | @Override 22 | public boolean onCreateOptionsMenu(Menu menu) { 23 | getMenuInflater().inflate(R.menu.menu_main, menu); 24 | return true; 25 | } 26 | 27 | @Override 28 | public boolean onOptionsItemSelected(MenuItem item) { 29 | // Handle action bar item clicks here. The action bar will 30 | // automatically handle clicks on the Home/Up button, so long 31 | // as you specify a parent activity in AndroidManifest.xml. 32 | int id = item.getItemId(); 33 | 34 | //noinspection SimplifiableIfStatement 35 | if (id == R.id.action_settings) { 36 | return true; 37 | } 38 | 39 | return super.onOptionsItemSelected(item); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/MainActivityFragment.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.Snackbar; 5 | import android.support.v4.app.Fragment; 6 | import android.text.method.ScrollingMovementMethod; 7 | import android.util.Log; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Button; 12 | import android.widget.TextView; 13 | 14 | import java.util.HashMap; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | import butterknife.Bind; 19 | import butterknife.ButterKnife; 20 | import butterknife.OnClick; 21 | import in.ashwanik.retroclient.entities.ErrorData; 22 | import in.ashwanik.retroclient.interfaces.RequestHandler; 23 | import in.ashwanik.retroclient.service.RetroClientServiceGenerator; 24 | import in.ashwanik.retroclientsample.models.Author; 25 | import in.ashwanik.retroclientsample.models.Book; 26 | import in.ashwanik.retroclientsample.models.ErrorBody; 27 | import in.ashwanik.retroclientsample.web.clients.AuthorClient; 28 | import in.ashwanik.retroclientsample.web.clients.BookClient; 29 | 30 | 31 | /** 32 | * A placeholder fragment containing a simple view. 33 | */ 34 | public class MainActivityFragment extends Fragment { 35 | 36 | public MainActivityFragment() { 37 | } 38 | 39 | View view; 40 | 41 | @Bind(R.id.getById) 42 | Button getById; 43 | @Bind(R.id.getAll) 44 | Button getAll; 45 | @Bind(R.id.create) 46 | Button create; 47 | @Bind(R.id.update) 48 | Button update; 49 | @Bind(R.id.delete) 50 | Button delete; 51 | @Bind(R.id.unauthorized) 52 | Button unauthorized; 53 | @Bind(R.id.authorized) 54 | Button authorized; 55 | @Bind(R.id.log) 56 | TextView log; 57 | 58 | private void show(String message) { 59 | log.setText(log.getText() + "\n" + message); 60 | } 61 | 62 | private void showSnackBar(ErrorData errorData, final View button) { 63 | String message = errorData.getMessage(); 64 | try { 65 | ErrorBody error = errorData.getError(ErrorBody.class); 66 | if (error != null) { 67 | message = error.message; 68 | } 69 | } catch (ClassNotFoundException e) { 70 | e.printStackTrace(); 71 | } 72 | 73 | Snackbar.make(button, message, Snackbar.LENGTH_LONG) 74 | .setAction("Retry", new View.OnClickListener() { 75 | @Override 76 | public void onClick(View v) { 77 | onButtonClick(button); 78 | } 79 | }).show(); 80 | } 81 | 82 | @OnClick({R.id.getAll, R.id.getById, R.id.create, R.id.update, R.id.delete, R.id.unauthorized, R.id.authorized}) 83 | public void onButtonClick(final View button) { 84 | RetroClientServiceGenerator serviceGenerator = new RetroClientServiceGenerator(MainActivityFragment.this.getActivity(), false); 85 | BookClient client = serviceGenerator.getService(BookClient.class); 86 | switch (button.getId()) { 87 | case R.id.getById: 88 | serviceGenerator.execute(client.get(1), new RequestHandler() { 89 | @Override 90 | public void onSuccess(Book response) { 91 | show("Book found:" + response.name); 92 | } 93 | 94 | @Override 95 | public void onError(ErrorData errorData) { 96 | showSnackBar(errorData, button); 97 | Log.d("RetrofitSample", errorData.toString()); 98 | } 99 | }); 100 | break; 101 | case R.id.getAll: 102 | serviceGenerator.execute(client.get(), new RequestHandler>() { 103 | @Override 104 | public void onSuccess(List response) { 105 | show("Book found: " + response.size()); 106 | } 107 | 108 | @Override 109 | public void onError(ErrorData errorData) { 110 | showSnackBar(errorData, button); 111 | Log.d("RetrofitSample", errorData.toString()); 112 | } 113 | }); 114 | break; 115 | case R.id.create: 116 | serviceGenerator.execute(client.create(new Book("Book_" + System.currentTimeMillis())), new RequestHandler() { 117 | @Override 118 | public void onSuccess(Book response) { 119 | show("Book found:" + response.name); 120 | } 121 | 122 | @Override 123 | public void onError(ErrorData errorData) { 124 | showSnackBar(errorData, button); 125 | Log.d("RetrofitSample", errorData.toString()); 126 | } 127 | }); 128 | break; 129 | case R.id.update: 130 | serviceGenerator.execute(client.update(new Book("Book_" + System.currentTimeMillis()), 1), new RequestHandler() { 131 | @Override 132 | public void onSuccess(Book response) { 133 | show("Book found:" + response.name); 134 | } 135 | 136 | @Override 137 | public void onError(ErrorData errorData) { 138 | showSnackBar(errorData, button); 139 | Log.d("RetrofitSample", errorData.toString()); 140 | } 141 | }); 142 | break; 143 | case R.id.delete: 144 | serviceGenerator.execute(client.delete(1), new RequestHandler() { 145 | 146 | @Override 147 | public void onSuccess(Void response) { 148 | show("Successfully deleted"); 149 | } 150 | 151 | @Override 152 | public void onError(ErrorData errorData) { 153 | showSnackBar(errorData, button); 154 | } 155 | }); 156 | break; 157 | case R.id.unauthorized: 158 | AuthorClient unauthorizedAuthor = serviceGenerator.getService(AuthorClient.class, "unauthorizedAuthor"); 159 | serviceGenerator.execute(unauthorizedAuthor.get(1), new RequestHandler() { 160 | 161 | @Override 162 | public void onSuccess(Author response) { 163 | show("Author: " + response.name); 164 | } 165 | 166 | @Override 167 | public void onError(ErrorData errorData) { 168 | showSnackBar(errorData, button); 169 | } 170 | }); 171 | break; 172 | case R.id.authorized: 173 | Map headers = new HashMap<>(); 174 | headers.put("x-access-token", "test"); 175 | 176 | RetroClientServiceGenerator authorizedServiceGenerator = new RetroClientServiceGenerator(MainActivityFragment.this.getActivity(), false, headers); 177 | AuthorClient authorizedAuthor = authorizedServiceGenerator.getService(AuthorClient.class, "authorizedAuthor"); 178 | serviceGenerator.execute(authorizedAuthor.get(1), new RequestHandler() { 179 | 180 | @Override 181 | public void onSuccess(Author response) { 182 | show("Author: " + response.name); 183 | } 184 | 185 | @Override 186 | public void onError(ErrorData errorData) { 187 | showSnackBar(errorData, button); 188 | } 189 | }); 190 | break; 191 | } 192 | } 193 | 194 | 195 | @Override 196 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 197 | Bundle savedInstanceState) { 198 | view = inflater.inflate(R.layout.fragment_main, container, false); 199 | ButterKnife.bind(this, view); 200 | log.setText(""); 201 | log.setMovementMethod(new ScrollingMovementMethod()); 202 | return view; 203 | } 204 | 205 | @Override 206 | public void onDestroyView() { 207 | super.onDestroyView(); 208 | ButterKnife.unbind(this); 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/models/Author.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.models; 2 | 3 | /** 4 | * Created by AshwaniK on 1/30/2016. 5 | */ 6 | public class Author { 7 | public int id; 8 | public String name; 9 | 10 | public Author() { 11 | 12 | } 13 | 14 | public Author(String name) { 15 | this.name = name; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "Author{" + 21 | "id=" + id + 22 | ", name='" + name + '\'' + 23 | '}'; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/models/BaseObject.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.models; 2 | 3 | public class BaseObject { 4 | } 5 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/models/Book.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.models; 2 | 3 | /** 4 | * Created by AshwaniK on 1/30/2016. 5 | */ 6 | public class Book { 7 | public int id; 8 | public String name; 9 | 10 | public Book() { 11 | 12 | } 13 | 14 | public Book(String name) { 15 | this.name = name; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "Book{" + 21 | "id=" + id + 22 | ", name='" + name + '\'' + 23 | '}'; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/models/BookResponse.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.models; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by AshwaniK on 1/31/2016. 7 | */ 8 | public class BookResponse { 9 | 10 | public List books; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/models/ErrorBody.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.models; 2 | 3 | public class ErrorBody { 4 | public String message; 5 | public String title; 6 | public int errorCode; 7 | } 8 | -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/web/ApiUrls.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.web; 2 | 3 | /** 4 | * Created by AshwaniK on 1/30/2016. 5 | */ 6 | public class ApiUrls { 7 | public static final String BASE_API_URL = "http://192.168.1.9:3000/"; 8 | } -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/web/clients/AuthorClient.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.web.clients; 2 | 3 | import in.ashwanik.retroclientsample.models.Author; 4 | import retrofit2.Call; 5 | import retrofit2.http.GET; 6 | import retrofit2.http.Path; 7 | 8 | public interface AuthorClient { 9 | @GET("/authors/{authorId}") 10 | Call get(@Path("authorId") Integer authorId); 11 | 12 | } -------------------------------------------------------------------------------- /android/app/src/main/java/in/ashwanik/retroclientsample/web/clients/BookClient.java: -------------------------------------------------------------------------------- 1 | package in.ashwanik.retroclientsample.web.clients; 2 | 3 | import java.util.List; 4 | 5 | import in.ashwanik.retroclientsample.models.Book; 6 | import retrofit2.Call; 7 | import retrofit2.http.Body; 8 | import retrofit2.http.DELETE; 9 | import retrofit2.http.GET; 10 | import retrofit2.http.POST; 11 | import retrofit2.http.PUT; 12 | import retrofit2.http.Path; 13 | 14 | public interface BookClient { 15 | @GET("/books/{bookId}") 16 | Call get(@Path("bookId") Integer bookId); 17 | 18 | @GET("/books") 19 | Call> get(); 20 | 21 | @POST("/books") 22 | Call create(@Body Book book); 23 | 24 | @PUT("/books/{bookId}") 25 | Call update(@Body Book book, @Path("bookId") Integer bookId); 26 | 27 | @DELETE("/books/{bookId}") 28 | Call delete(@Path("bookId") Integer bookId); 29 | } -------------------------------------------------------------------------------- /android/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /android/app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /android/app/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 18 | 19 | 20 | 26 | 27 | 32 | 33 |