Skip to content

Commit

Permalink
* finish api section
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaHasria committed Jun 29, 2021
1 parent 0a8f66e commit b7bac19
Show file tree
Hide file tree
Showing 22 changed files with 2,830 additions and 10 deletions.
13 changes: 13 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ dependencies {
//paper database
implementation 'io.github.pilgr:paperdb:2.7.1'

//Retrofit 2
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'


//AVI loading
implementation 'com.wang.avi:library:2.1.3'

//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'


}
32 changes: 32 additions & 0 deletions app/src/main/java/com/example/smoathapplication/api/ApiClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.smoathapplication.api;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApiClient {

public static Retrofit retrofit = null;

public static Retrofit getAPIClient() {
if (retrofit == null) {
retrofit = new Retrofit.Builder().baseUrl("https://api.tvmaze.com/")
.client(getHttpOkClient())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}

private static OkHttpClient getHttpOkClient() {
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
httpClientBuilder.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.retryOnConnectionFailure(true);

return httpClientBuilder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.smoathapplication.api;

public interface ApiStateListener {

void onSuccess(Object... params);

void onFailure(Object... params);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.smoathapplication.api.endpoints;

import com.example.smoathapplication.models.home.response.MovieResponse;

import java.util.List;

import retrofit2.Call;
import retrofit2.http.GET;

public interface MovieApis {
String SHOW_ALL = "shows";


@GET(SHOW_ALL)
Call<List<MovieResponse>> getMovies();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import io.paperdb.Paper;

import static com.example.smoathapplication.util.AppConst.PICK_IMAGE;

public class AddMovieActivity extends AppCompatActivity {

//region Components
Expand Down Expand Up @@ -95,13 +97,13 @@ private void checkPermission() {
private void chooseImage() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 100);
startActivityForResult(intent, PICK_IMAGE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) {
if (requestCode == PICK_IMAGE) {
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.smoathapplication.models.home.caller;


import com.example.smoathapplication.api.ApiClient;
import com.example.smoathapplication.api.ApiStateListener;
import com.example.smoathapplication.api.endpoints.MovieApis;
import com.example.smoathapplication.models.home.response.MovieResponse;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MovieCaller {

//region Variables
MovieApis movieApis;
Call<List<MovieResponse>> movieResponseCall;
//endregion

//region Constructor

public MovieCaller() {
movieApis = ApiClient.getAPIClient().create(MovieApis.class);
}
//endregion

//region Get all movies
public void connectToGetAllMoviesApi(final ApiStateListener apiStateListener){
movieResponseCall = movieApis.getMovies();
movieResponseCall.enqueue(new Callback<List<MovieResponse>>() {
@Override
public void onResponse(Call<List<MovieResponse>> call, Response<List<MovieResponse>> response) {
if (response.body() == null){
apiStateListener.onFailure(700);
} else {
if (response.code() == 200){
apiStateListener.onSuccess(response.body());
} else
apiStateListener.onFailure(response.code());
}
}

@Override
public void onFailure(Call<List<MovieResponse>> call, Throwable t) {
apiStateListener.onFailure(null);
}
});
}
//endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.smoathapplication.models.home.response;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class CountryResponse {

@SerializedName("name")
@Expose
private String name;
@SerializedName("code")
@Expose
private String code;
@SerializedName("timezone")
@Expose
private String timezone;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public String getTimezone() {
return timezone;
}

public void setTimezone(String timezone) {
this.timezone = timezone;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.example.smoathapplication.models.home.response;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class ExternalsResponse {

@SerializedName("tvrage")
@Expose
private int tvrage;
@SerializedName("thetvdb")
@Expose
private int thetvdb;
@SerializedName("imdb")
@Expose
private String imdb;

public int getTvrage() {
return tvrage;
}

public void setTvrage(int tvrage) {
this.tvrage = tvrage;
}

public int getThetvdb() {
return thetvdb;
}

public void setThetvdb(int thetvdb) {
this.thetvdb = thetvdb;
}

public String getImdb() {
return imdb;
}

public void setImdb(String imdb) {
this.imdb = imdb;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.smoathapplication.models.home.response;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class ImageResponse {


@SerializedName("medium")
@Expose
private String medium;
@SerializedName("original")
@Expose
private String original;

public String getMedium() {
return medium;
}

public void setMedium(String medium) {
this.medium = medium;
}

public String getOriginal() {
return original;
}

public void setOriginal(String original) {
this.original = original;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.example.smoathapplication.models.home.response;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class LinksResponse {

@SerializedName("self")
@Expose
private SelfResponse self;
@SerializedName("previousepisode")
@Expose
private PreviousepisodeResponse previousepisode;

public SelfResponse getSelf() {
return self;
}

public void setSelf(SelfResponse self) {
this.self = self;
}

public PreviousepisodeResponse getPreviousepisode() {
return previousepisode;
}

public void setPreviousepisode(PreviousepisodeResponse previousepisode) {
this.previousepisode = previousepisode;
}
}
Loading

0 comments on commit b7bac19

Please sign in to comment.