-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MustafaHasria
committed
Jun 29, 2021
1 parent
0a8f66e
commit b7bac19
Showing
22 changed files
with
2,830 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/example/smoathapplication/api/ApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/example/smoathapplication/api/ApiStateListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/example/smoathapplication/api/endpoints/MovieApis.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/example/smoathapplication/models/home/caller/MovieCaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/example/smoathapplication/models/home/response/CountryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/example/smoathapplication/models/home/response/ExternalsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/example/smoathapplication/models/home/response/ImageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/example/smoathapplication/models/home/response/LinksResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.