Newss is an android application mainly built for personal app development learning purpose. This application is built purely in java and is mainly for android platform. This app fetches the articles by consuming News API. It makes use of Retrofit type safe client for handling HTTP request along with GSON object converter. It uses Glide for image downloading and caching. We can definitely use Picasso library too. Please refer this article for significant differences between both. We will also make use of another third-party library to beautify the timestamp of the news application.
Include the below implementations to your dependencies block inside app.gradle
file.
// Recycler view and card view dependency
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.recyclerview:recyclerview:1.1.0"
// For control over item selection of both touch and mouse driven selection
implementation "androidx.recyclerview:recyclerview-selection:1.1.0"
// Image download and caching
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
// Establishing HTTP connection with the API endpoints
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
implementation("com.squareup.okhttp3:okhttp:4.9.0")
// Time formatter
implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final'
NOTE: Please try to update to the libraries to their latest version. When I built this application these were the latest versions.
Head over to News API and create an account to get the API key (generally alphanumeric) which is very much required to establish the connection from the API endpoints.
In your AndroidManifest.xml
add the below permissions:
<uses-permission android:name="android.permission.INTERNET"/>
<!--
Allows Glide to monitor connectivity status and restart failed requests if users go from a
a disconnected to a connected network state.
-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
- Adding colors.xml from this gist.
- [TO ADD]
- The first thing is to create a
model
package and in that package creating aclass
which consumes thejson
response in java.- We use
@SerializedName("name_of_field_in_json_file")
annotation when thejson
property name is different than our variable or field name. - We use
@Expose
to allow or disallow serialization. It is optional. This answer is worth reading. - Next thing is generating the getters for each and every field.
- We use