Skip to content

Commit

Permalink
Refactored RestMovieSource, MediaDataSource & ConfigurationUsecase
Browse files Browse the repository at this point in the history
  • Loading branch information
saulmm committed May 3, 2015
1 parent 0bb8014 commit 20593fa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
@Generated("dagger.internal.codegen.ComponentProcessor")
public final class ConfigurationUsecaseController_Factory implements Factory<ConfigurationUsecaseController> {
private final Provider<MediaDataSource> mediaDataSourceProvider;
private final Provider<Bus> uiBusProvider;
private final Provider<Bus> mainBusProvider;

public ConfigurationUsecaseController_Factory(Provider<MediaDataSource> mediaDataSourceProvider, Provider<Bus> uiBusProvider) {
public ConfigurationUsecaseController_Factory(Provider<MediaDataSource> mediaDataSourceProvider, Provider<Bus> mainBusProvider) {
assert mediaDataSourceProvider != null;
this.mediaDataSourceProvider = mediaDataSourceProvider;
assert uiBusProvider != null;
this.uiBusProvider = uiBusProvider;
assert mainBusProvider != null;
this.mainBusProvider = mainBusProvider;
}

@Override
public ConfigurationUsecaseController get() {
return new ConfigurationUsecaseController(mediaDataSourceProvider.get(), uiBusProvider.get());
return new ConfigurationUsecaseController(mediaDataSourceProvider.get(), mainBusProvider.get());
}

public static Factory<ConfigurationUsecaseController> create(Provider<MediaDataSource> mediaDataSourceProvider, Provider<Bus> uiBusProvider) {
return new ConfigurationUsecaseController_Factory(mediaDataSourceProvider, uiBusProvider);
public static Factory<ConfigurationUsecaseController> create(Provider<MediaDataSource> mediaDataSourceProvider, Provider<Bus> mainBusProvider) {
return new ConfigurationUsecaseController_Factory(mediaDataSourceProvider, mainBusProvider);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ public interface ConfigurationUsecase extends Usecase {
/**
* Request data source the configuration data
*/
public void requestConfiguration ();
void requestConfiguration ();

/**
* Callback used to be notified when the configuration data has been received
*
* @param configurationResponse the configuration with the data about the endpoint
* of the images
*/
public void onConfigurationReceived (ConfigurationResponse configurationResponse);
void onConfigurationReceived (ConfigurationResponse configurationResponse);

/**
* Configures the endpoint used to retrieve images from the movie database api
*
* @param configurationResponse the configuration with the data about the endpoint of the images
*/
public void configureImageUrl (ConfigurationResponse configurationResponse);
void configureImageUrl (ConfigurationResponse configurationResponse);

/**
* Sends a configured to request images from the movie database api
*
* @param url configurated url
*/
public void sendConfiguredUrlToPresenter(String url);
void sendConfiguredUrlToPresenter(String url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,23 @@

import javax.inject.Inject;

/**
* This class is an implementation of {@link ConfigurationUsecase}
*/

@SuppressWarnings("FieldCanBeLocal")
public class ConfigurationUsecaseController implements ConfigurationUsecase {

private final String DESIRED_QUALITY = "w780";
private final String QUALITY_DESIRED = "w780";
private final String QUALITY_ORIGINAL = "original";

private final MediaDataSource mMediaDataSource;
Bus bus;

/**
* Constructor of the class.
*
* @param uiBus The bus to communicate the domain module and the app module
* @param mediaDataSource The data source to retrieve the configuariton
*/
@Inject
public ConfigurationUsecaseController(MediaDataSource mediaDataSource, Bus uiBus) {
private final Bus mMainBus;

if (mediaDataSource == null)
throw new IllegalArgumentException("Media data source cannot be null");

if (uiBus == null)
throw new IllegalArgumentException("Ui bus cannot be null");
@Inject
public ConfigurationUsecaseController(MediaDataSource mediaDataSource, Bus mainBus) {

bus = uiBus;
mMediaDataSource = mediaDataSource;
mMediaDataSource = mediaDataSource;
mMainBus = mainBus;

bus.register(this);
mMainBus.register(this);
}

@Override
Expand All @@ -54,31 +42,30 @@ public void execute() {
@Override
public void onConfigurationReceived(ConfigurationResponse configuration) {

bus.unregister(this);
mMainBus.unregister(this);
configureImageUrl(configuration);
}

public void configureImageUrl (ConfigurationResponse configurationResponse) {

String url = "";
String url;

if (configurationResponse.getImages() != null) {

url = configurationResponse.getImages()
.getBase_url();
String imageQuality = "";
url = configurationResponse.getImages().getBase_url();

for (String quality : configurationResponse.getImages().getBackdrop_sizes()) {

if (quality.equals(DESIRED_QUALITY)) {
if (quality.equals(QUALITY_DESIRED)) {

imageQuality = DESIRED_QUALITY;
imageQuality = QUALITY_DESIRED;
break;
}
}

if (imageQuality.equals(""))
imageQuality = "original";
imageQuality = QUALITY_ORIGINAL;

url += imageQuality;
sendConfiguredUrlToPresenter(url);
Expand All @@ -89,6 +76,6 @@ public void configureImageUrl (ConfigurationResponse configurationResponse) {
@Override
public void sendConfiguredUrlToPresenter (String url) {

bus.post(url);
mMainBus.post(url);
}
}
15 changes: 5 additions & 10 deletions HackVG/model/src/main/java/com/hackvg/model/MediaDataSource.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
package com.hackvg.model;

/**
* Created by saulmm on 31/01/15.
*/
public interface MediaDataSource {

public void getShows ();
void getMovies();

public void getMovies();

public void getDetailMovie (String id);
void getDetailMovie (String id);

/**
* Get the reviews for a particular movie id.
*
* @param id movie id
*/
public void getReviews (String id);
void getReviews (String id);

public void getConfiguration ();
void getConfiguration ();

/**
* Get a list of images represented by a MoviesWrapper
* class
*
* @param movieId the movie id
*/
public void getImages (String movieId);
void getImages (String movieId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ public RestMovieSource(Bus bus) {
this.bus = bus;
}

@Override
public void getShows() {

// moviesDBApi.getPopularShows(Constants.API_KEY, moviesResponseCallback);
}

@Override
public void getMovies() {

Expand Down

0 comments on commit 20593fa

Please sign in to comment.