> getCharacterCollection(int characterId, String type) {
- if (!type.equals(COMIC) && !type.equals(EVENT) && !type.equals(SERIES) && !type.equals(STORY))
- throw new IllegalArgumentException("Collection type must be: events|series|comics|stories");
-
- return mMarvelApi.getCharacterCollection(characterId, type);
- }
-}
diff --git a/app/src/main/java/saulmm/avengers/model/rest/utils/interceptors/HttpLoggingInterceptor.java b/app/src/main/java/saulmm/avengers/model/rest/utils/interceptors/HttpLoggingInterceptor.java
deleted file mode 100644
index 36723c0..0000000
--- a/app/src/main/java/saulmm/avengers/model/rest/utils/interceptors/HttpLoggingInterceptor.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright (C) 2015 Square, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package saulmm.avengers.model.rest.utils.interceptors;
-
-import android.util.Log;
-import com.squareup.okhttp.Connection;
-import com.squareup.okhttp.Headers;
-import com.squareup.okhttp.HttpUrl;
-import com.squareup.okhttp.Interceptor;
-import com.squareup.okhttp.MediaType;
-import com.squareup.okhttp.OkHttpClient;
-import com.squareup.okhttp.Protocol;
-import com.squareup.okhttp.Request;
-import com.squareup.okhttp.RequestBody;
-import com.squareup.okhttp.Response;
-import com.squareup.okhttp.ResponseBody;
-import java.io.IOException;
-import java.nio.charset.Charset;
-import java.util.concurrent.TimeUnit;
-import okio.Buffer;
-import okio.BufferedSource;
-
-/**
- * An OkHttp interceptor which logs request and response information. Can be applied as an
- * {@linkplain OkHttpClient#interceptors() application interceptor} or as a
- * {@linkplain OkHttpClient#networkInterceptors() network interceptor}.
- *
- * The format of the logs created by this class should not be considered stable and may change
- * slightly between releases. If you need a stable logging format, use your own interceptor.
- */
-public final class HttpLoggingInterceptor implements Interceptor {
- private static final Charset UTF8 = Charset.forName("UTF-8");
- private static final String TAG = "HttpLoggingInterceptor";
-
- public enum Level {
- /** No logs. */
- NONE,
- /**
- * Logs request and response lines.
- *
- * Example:
- *
{@code
- * --> POST /greeting HTTP/1.1 (3-byte body)
- *
- * <-- HTTP/1.1 200 OK (22ms, 6-byte body)
- * }
- */
- BASIC,
- /**
- * Logs request and response lines and their respective headers.
- *
- * Example:
- *
{@code
- * --> POST /greeting HTTP/1.1
- * Host: example.com
- * Content-Type: plain/text
- * Content-Length: 3
- * --> END POST
- *
- * <-- HTTP/1.1 200 OK (22ms)
- * Content-Type: plain/text
- * Content-Length: 6
- * <-- END HTTP
- * }
- */
- HEADERS,
- /**
- * Logs request and response lines and their respective headers and bodies (if present).
- *
- * Example:
- *
{@code
- * --> POST /greeting HTTP/1.1
- * Host: example.com
- * Content-Type: plain/text
- * Content-Length: 3
- *
- * Hi?
- * --> END GET
- *
- * <-- HTTP/1.1 200 OK (22ms)
- * Content-Type: plain/text
- * Content-Length: 6
- *
- * Hello!
- * <-- END HTTP
- * }
- */
- BODY
- }
-
- public interface Logger {
- void log(String message);
-
- /** A {@link Logger} defaults output appropriate for the current platform. */
- Logger DEFAULT = new Logger() {
- @Override public void log(String message) {
- Log.d(TAG, message);
- }
- };
- }
-
- public HttpLoggingInterceptor() {
- this(Logger.DEFAULT);
- }
-
- public HttpLoggingInterceptor(Logger logger) {
- this.logger = logger;
- }
-
- private final Logger logger;
-
- private volatile Level level = Level.NONE;
-
- /** Change the level at which this interceptor logs. */
- public void setLevel(Level level) {
- this.level = level;
- }
-
- @Override public Response intercept(Chain chain) throws IOException {
- Level level = this.level;
-
- Request request = chain.request();
- if (level == Level.NONE) {
- return chain.proceed(request);
- }
-
- boolean logBody = level == Level.BODY;
- boolean logHeaders = logBody || level == Level.HEADERS;
-
- RequestBody requestBody = request.body();
- boolean hasRequestBody = requestBody != null;
-
- Connection connection = chain.connection();
- Protocol protocol = connection != null ? connection.getProtocol() : Protocol.HTTP_1_1;
- String requestStartMessage =
- "--> " + request.method() + ' ' + requestPath(request.httpUrl()) + ' ' + protocol(protocol);
- if (!logHeaders && hasRequestBody) {
- requestStartMessage += " (" + requestBody.contentLength() + "-byte body)";
- }
- logger.log(requestStartMessage);
-
- if (logHeaders) {
- Headers headers = request.headers();
- for (int i = 0, count = headers.size(); i < count; i++) {
- logger.log(headers.name(i) + ": " + headers.value(i));
- }
-
- String endMessage = "--> END " + request.method();
- if (logBody && hasRequestBody) {
- Buffer buffer = new Buffer();
- requestBody.writeTo(buffer);
-
- Charset charset = UTF8;
- MediaType contentType = requestBody.contentType();
- if (contentType != null) {
- contentType.charset(UTF8);
- }
-
- logger.log("");
- logger.log(buffer.readString(charset));
-
- endMessage += " (" + requestBody.contentLength() + "-byte body)";
- }
- logger.log(endMessage);
- }
-
- long startNs = System.nanoTime();
- Response response = chain.proceed(request);
- long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
-
- ResponseBody responseBody = response.body();
- logger.log("<-- " + protocol(response.protocol()) + ' ' + response.code() + ' '
- + response.message() + " (" + tookMs + "ms"
- + (!logHeaders ? ", " + responseBody.contentLength() + "-byte body" : "") + ')');
-
- if (logHeaders) {
- Headers headers = response.headers();
- for (int i = 0, count = headers.size(); i < count; i++) {
- logger.log(headers.name(i) + ": " + headers.value(i));
- }
-
- String endMessage = "<-- END HTTP";
- if (logBody) {
- BufferedSource source = responseBody.source();
- source.request(Long.MAX_VALUE); // Buffer the entire body.
- Buffer buffer = source.buffer();
-
- Charset charset = UTF8;
- MediaType contentType = responseBody.contentType();
- if (contentType != null) {
- charset = contentType.charset(UTF8);
- }
-
- if (responseBody.contentLength() != 0) {
- logger.log("");
- logger.log(buffer.clone().readString(charset));
- }
-
- endMessage += " (" + buffer.size() + "-byte body)";
- }
- logger.log(endMessage);
- }
-
- return response;
- }
-
- private static String protocol(Protocol protocol) {
- return protocol == Protocol.HTTP_1_0 ? "HTTP/1.0" : "HTTP/1.1";
- }
-
- private static String requestPath(HttpUrl url) {
- String path = url.encodedPath();
- String query = url.encodedQuery();
- return query != null ? (path + '?' + query) : path;
- }
-}
\ No newline at end of file
diff --git a/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterDetailPresenter.java b/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterDetailPresenter.java
index a092daa..1efe14d 100644
--- a/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterDetailPresenter.java
+++ b/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterDetailPresenter.java
@@ -5,41 +5,37 @@
*/
package saulmm.avengers.mvp.presenters;
-import android.content.Context;
-import android.graphics.Bitmap;
import javax.inject.Inject;
import rx.Subscription;
-import saulmm.avengers.domain.GetCharacterInformationUsecase;
-import saulmm.avengers.model.entities.Character;
-import saulmm.avengers.model.entities.CollectionItem;
+import saulmm.avengers.CharacterDetailsUsecase;
+import saulmm.avengers.entities.MarvelCharacter;
import saulmm.avengers.mvp.views.CharacterDetailView;
import saulmm.avengers.mvp.views.View;
-import saulmm.avengers.views.activities.CollectionActivity;
public class CharacterDetailPresenter implements Presenter {
-
- private final Context mActivityContext;
private CharacterDetailView mCharacterDetailView;
- private final GetCharacterInformationUsecase mGetCharacterInformationUsecase;
+ private final CharacterDetailsUsecase mGetCharacterInformationUsecase;
private Subscription mCharacterSubscription;
private int mCharacterId;
private String mCharacterName;
@Inject
- public CharacterDetailPresenter(GetCharacterInformationUsecase getCharacterInformationUsecase,
- Context activityContext) {
-
+ public CharacterDetailPresenter(CharacterDetailsUsecase getCharacterInformationUsecase) {
mGetCharacterInformationUsecase = getCharacterInformationUsecase;
- mActivityContext = activityContext;
}
@Override
public void onCreate() {
if (mCharacterId == -1 || mCharacterName == null)
- throw new IllegalStateException("initializePresenter was not well initialised");
+ throw new IllegalStateException();
+ mCharacterDetailView.disableScroll();
+ askForCharacterDetails();
+ }
+
+ public void askForCharacterDetails() {
mCharacterSubscription = mGetCharacterInformationUsecase.execute()
.subscribe(this::onCharacterReceived, this::manageCharacterError);
}
@@ -65,42 +61,42 @@ public void attachView(View v) {
mCharacterDetailView = (CharacterDetailView) v;
}
- @SuppressWarnings("Convert2MethodRef")
public void initializePresenter(int characterId, String characterName) {
mCharacterId = characterId;
mCharacterName = characterName;
}
private void manageCharacterError(Throwable error) {
- // TODO
}
- private void onCharacterReceived(Character character) {
+ private void onCharacterReceived(MarvelCharacter character) {
mCharacterDetailView.bindCharacter(character);
+
+ if (character.getDescription() != null && !character.getDescription().equals(""))
+ mCharacterDetailView.enableScroll();
}
public void onComicsIndicatorPressed() {
- CollectionActivity.start(mActivityContext, mCharacterId, CollectionItem.COMIC);
+ mCharacterDetailView.goToCharacterComicsView(mCharacterId);
}
public void onSeriesIndicatorPressed() {
- CollectionActivity.start(mActivityContext, mCharacterId, CollectionItem.SERIES);
+ mCharacterDetailView.goToCharacterSeriesView(mCharacterId);
}
public void onStoriesIndicatorPressed() {
- CollectionActivity.start(mActivityContext, mCharacterId, CollectionItem.STORY);
+ mCharacterDetailView.goToCharacterStoriesView(mCharacterId);
}
public void onEventIndicatorPressed() {
- CollectionActivity.start(mActivityContext, mCharacterId, CollectionItem.EVENT);
+ mCharacterDetailView.goToCharacterEventsView(mCharacterId);
}
public void setCharacterId(int characterId) {
mCharacterId = characterId;
}
- public void onImageReceived(Bitmap resource) {
+ public void onImageReceived() {
mCharacterDetailView.hideRevealViewByAlpha();
- mCharacterDetailView.initActivityColors(resource);
}
}
\ No newline at end of file
diff --git a/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterListPresenter.java b/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterListPresenter.java
index 36dc588..6eee80c 100644
--- a/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterListPresenter.java
+++ b/app/src/main/java/saulmm/avengers/mvp/presenters/CharacterListPresenter.java
@@ -9,10 +9,8 @@
import java.util.List;
import javax.inject.Inject;
import rx.Subscription;
-import saulmm.avengers.domain.GetCharactersUsecase;
-import saulmm.avengers.model.entities.Character;
-import saulmm.avengers.model.rest.exceptions.NetworkUknownHostException;
-import saulmm.avengers.model.rest.exceptions.ServerErrorException;
+import saulmm.avengers.GetCharactersUsecase;
+import saulmm.avengers.entities.MarvelCharacter;
import saulmm.avengers.mvp.views.CharacterListView;
import saulmm.avengers.mvp.views.View;
@@ -21,13 +19,12 @@ public class CharacterListPresenter implements Presenter {
private boolean mIsTheCharacterRequestRunning;
private Subscription mCharactersSubscription;
- private List mCharacters;
+ private List mCharacters = new ArrayList<>();
private CharacterListView mAvengersView;
@Inject
public CharacterListPresenter(GetCharactersUsecase charactersUsecase) {
mCharactersUsecase = charactersUsecase;
- mCharacters = new ArrayList<>();
}
@Override
@@ -62,66 +59,52 @@ public void onListEndReached() {
if (!mIsTheCharacterRequestRunning) askForNewCharacters();
}
- @SuppressWarnings("Convert2MethodRef")
- private void askForCharacters() {
+ public void askForCharacters() {
mIsTheCharacterRequestRunning = true;
mAvengersView.hideErrorView();
mAvengersView.showLoadingView();
mCharactersSubscription = mCharactersUsecase.execute()
- .subscribe(characters -> {
- mCharacters.addAll(characters);
- mAvengersView.bindCharacterList(mCharacters);
- mAvengersView.showCharacterList();
- mAvengersView.hideEmptyIndicator();
- mIsTheCharacterRequestRunning = false;
-
- }, error -> {
- showErrorView(error);
- });
-
+ .subscribe(this::onCharactersReceived, this::showErrorView);
}
- private void askForNewCharacters() {
+ public void onCharactersReceived(List characters) {
+ mCharacters.addAll(characters);
+ mAvengersView.bindCharacterList(mCharacters);
+ mAvengersView.showCharacterList();
+ mAvengersView.hideEmptyIndicator();
+ mIsTheCharacterRequestRunning = false;
+ }
+
+ public void askForNewCharacters() {
mAvengersView.showLoadingMoreCharactersIndicator();
mIsTheCharacterRequestRunning = true;
- mCharactersSubscription = mCharactersUsecase.executeIncreasingOffset()
- .subscribe(
-
- newCharacters -> {
- mCharacters.addAll(newCharacters);
- mAvengersView.updateCharacterList (
- GetCharactersUsecase.CHARACTERS_LIMIT);
-
- mAvengersView.hideLoadingIndicator();
- mIsTheCharacterRequestRunning = false;
- },
-
- error -> {
- showGenericError();
- mIsTheCharacterRequestRunning = false;
- }
- );
+ mCharactersSubscription = mCharactersUsecase.execute()
+ .subscribe(this::onNewCharactersReceived, this::onNewCharactersError);
}
- private void showErrorView(Throwable error) {
- if (error instanceof NetworkUknownHostException) {
- mAvengersView.showConnectionErrorMessage();
+ private void onNewCharactersError(Throwable error) {
+ showGenericError();
+ mIsTheCharacterRequestRunning = false;
+ }
- } else if (error instanceof ServerErrorException) {
- mAvengersView.showServerErrorMessage();
+ private void onNewCharactersReceived(List newCharacters) {
+ mCharacters.addAll(newCharacters);
+ mAvengersView.updateCharacterList(GetCharactersUsecase.DEFAULT_CHARACTERS_LIMIT);
- } else {
- mAvengersView.showUknownErrorMessage();
- }
+ mAvengersView.hideLoadingIndicator();
+ mIsTheCharacterRequestRunning = false;
+ }
+ public void showErrorView(Throwable error) {
+ mAvengersView.showUknownErrorMessage();
mAvengersView.hideLoadingMoreCharactersIndicator();
mAvengersView.hideEmptyIndicator();
mAvengersView.hideCharactersList();
}
- private void showGenericError() {
+ public void showGenericError() {
mAvengersView.hideLoadingIndicator();
mAvengersView.showLightError();
}
diff --git a/app/src/main/java/saulmm/avengers/mvp/presenters/CollectionPresenter.java b/app/src/main/java/saulmm/avengers/mvp/presenters/CollectionPresenter.java
index 9879196..374b306 100644
--- a/app/src/main/java/saulmm/avengers/mvp/presenters/CollectionPresenter.java
+++ b/app/src/main/java/saulmm/avengers/mvp/presenters/CollectionPresenter.java
@@ -3,8 +3,10 @@
import android.content.Context;
import java.util.List;
import javax.inject.Inject;
-import saulmm.avengers.domain.GetCollectionUsecase;
-import saulmm.avengers.model.entities.CollectionItem;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+import saulmm.avengers.GetCollectionUsecase;
+import saulmm.avengers.entities.CollectionItem;
import saulmm.avengers.mvp.views.CollectionView;
import saulmm.avengers.mvp.views.View;
@@ -35,8 +37,9 @@ public void attachView(View v) {
@Override
public void onCreate() {
- mGetCollectionUsecase.execute(mCollectionType).subscribe(
- this::onCollectionItemsReceived);
+ mGetCollectionUsecase.setType(mCollectionType);
+ mGetCollectionUsecase.execute()
+ .subscribe(this::onCollectionItemsReceived);
}
public void initialisePresenters(String collectionType, int characterId) {
diff --git a/app/src/main/java/saulmm/avengers/mvp/views/CharacterDetailView.java b/app/src/main/java/saulmm/avengers/mvp/views/CharacterDetailView.java
index feeb27c..08d1e06 100644
--- a/app/src/main/java/saulmm/avengers/mvp/views/CharacterDetailView.java
+++ b/app/src/main/java/saulmm/avengers/mvp/views/CharacterDetailView.java
@@ -6,14 +6,25 @@
package saulmm.avengers.mvp.views;
import android.graphics.Bitmap;
-import saulmm.avengers.model.entities.Character;
+import saulmm.avengers.entities.MarvelCharacter;
public interface CharacterDetailView extends View {
+ void disableScroll();
+
void hideRevealViewByAlpha();
- void showError(String s);
+ void bindCharacter(MarvelCharacter character);
+
+ void enableScroll();
+
+ void goToCharacterComicsView(int characterId);
- void bindCharacter(Character character);
+ void goToCharacterSeriesView(int characterId);
+
+ void goToCharacterEventsView(int characterId);
+
+ void goToCharacterStoriesView(int characterId);
+
+ void showError(String s);
- void initActivityColors(Bitmap resource);
}
diff --git a/app/src/main/java/saulmm/avengers/mvp/views/CharacterListView.java b/app/src/main/java/saulmm/avengers/mvp/views/CharacterListView.java
index 4cfc0c7..a3f0eb6 100644
--- a/app/src/main/java/saulmm/avengers/mvp/views/CharacterListView.java
+++ b/app/src/main/java/saulmm/avengers/mvp/views/CharacterListView.java
@@ -7,12 +7,12 @@
import android.app.ActivityOptions;
import java.util.List;
-import saulmm.avengers.model.entities.Character;
+import saulmm.avengers.entities.MarvelCharacter;
@SuppressWarnings("unused")
public interface CharacterListView extends View {
- void bindCharacterList(List avengers);
+ void bindCharacterList(List avengers);
void showCharacterList();
@@ -38,8 +38,6 @@ public interface CharacterListView extends View {
void updateCharacterList(int charactersLimit);
- ActivityOptions getActivityOptions(int position, android.view.View clickedView);
-
void showConnectionErrorMessage();
void showServerErrorMessage();
diff --git a/app/src/main/java/saulmm/avengers/mvp/views/CollectionView.java b/app/src/main/java/saulmm/avengers/mvp/views/CollectionView.java
index ab0bc1f..013b043 100644
--- a/app/src/main/java/saulmm/avengers/mvp/views/CollectionView.java
+++ b/app/src/main/java/saulmm/avengers/mvp/views/CollectionView.java
@@ -1,7 +1,7 @@
package saulmm.avengers.mvp.views;
import java.util.List;
-import saulmm.avengers.model.entities.CollectionItem;
+import saulmm.avengers.entities.CollectionItem;
public interface CollectionView extends View {
diff --git a/app/src/main/java/saulmm/avengers/utils/OnCharacterImageCallback.java b/app/src/main/java/saulmm/avengers/utils/OnCharacterImageCallback.java
new file mode 100644
index 0000000..d40b548
--- /dev/null
+++ b/app/src/main/java/saulmm/avengers/utils/OnCharacterImageCallback.java
@@ -0,0 +1,7 @@
+package saulmm.avengers.utils;
+
+import android.graphics.Bitmap;
+
+public interface OnCharacterImageCallback {
+ void onReceive(Bitmap bitmap);
+}
\ No newline at end of file
diff --git a/app/src/main/java/saulmm/avengers/views/activities/CharacterDetailActivity.java b/app/src/main/java/saulmm/avengers/views/activities/CharacterDetailActivity.java
index 7087722..a292808 100644
--- a/app/src/main/java/saulmm/avengers/views/activities/CharacterDetailActivity.java
+++ b/app/src/main/java/saulmm/avengers/views/activities/CharacterDetailActivity.java
@@ -12,6 +12,8 @@
import android.databinding.DataBindingUtil;
import android.graphics.Bitmap;
import android.os.Bundle;
+import android.support.design.widget.AppBarLayout;
+import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.graphics.Palette;
@@ -20,6 +22,8 @@
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
+
+import butterknife.Bind;
import butterknife.BindColor;
import butterknife.BindInt;
import butterknife.ButterKnife;
@@ -30,11 +34,14 @@
import saulmm.avengers.AvengersApplication;
import saulmm.avengers.R;
import saulmm.avengers.databinding.ActivityAvengerDetailBinding;
+import saulmm.avengers.entities.CollectionItem;
+import saulmm.avengers.entities.MarvelCharacter;
import saulmm.avengers.injector.components.DaggerAvengerInformationComponent;
import saulmm.avengers.injector.modules.ActivityModule;
import saulmm.avengers.injector.modules.AvengerInformationModule;
import saulmm.avengers.mvp.presenters.CharacterDetailPresenter;
import saulmm.avengers.mvp.views.CharacterDetailView;
+import saulmm.avengers.utils.OnCharacterImageCallback;
import saulmm.avengers.utils.TransitionUtils;
import saulmm.avengers.views.utils.AnimUtils;
@@ -42,6 +49,7 @@ public class CharacterDetailActivity extends AppCompatActivity implements Charac
private static final String EXTRA_CHARACTER_NAME = "character.name";
public static final String EXTRA_CHARACTER_ID = "character.id";
+ @Bind(R.id.character_collapsing) CollapsingToolbarLayout mCollapsing;
@BindInt(R.integer.duration_medium) int mAnimMediumDuration;
@BindInt(R.integer.duration_huge) int mAnimHugeDuration;
@BindColor(R.color.brand_primary_dark) int mColorPrimaryDark;
@@ -49,20 +57,40 @@ public class CharacterDetailActivity extends AppCompatActivity implements Charac
@Inject CharacterDetailPresenter mCharacterDetailPresenter;
private ActivityAvengerDetailBinding mBinding;
+ private OnCharacterImageCallback onCharacterImageCallback = new OnCharacterImageCallback() {
+
+ @Override
+ public void onReceive(Bitmap bitmap) {
+ initActivityColors(bitmap);
+ }
+ };
+
+ private int mScrolleableAppbarLayoutFlags;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ initializeDependencyInjector();
initializeBinding();
initButterknife();
- initializeDependencyInjector();
initializePresenter();
initToolbar();
initTransitions();
}
+ @Override
+ public void disableScroll() {
+ mScrolleableAppbarLayoutFlags = ((AppBarLayout.LayoutParams) mCollapsing.getLayoutParams()).getScrollFlags();
+ AppBarLayout.LayoutParams layoutParams = ((AppBarLayout.LayoutParams) mCollapsing.getLayoutParams());
+ layoutParams.setScrollFlags(0);
+ mCollapsing.setLayoutParams(layoutParams);
+ }
+
private void initializeBinding() {
mBinding = DataBindingUtil.setContentView(
this, R.layout.activity_avenger_detail);
+
+ mBinding.setImageCallback(onCharacterImageCallback);
}
@@ -135,10 +163,10 @@ private void initializeDependencyInjector() {
private void initTransitions() {
final String sharedViewName = getIntent().getStringExtra(
- CharacterListListActivity.EXTRA_IMAGE_TRANSITION_NAME);
+ CharacterListActivity.EXTRA_IMAGE_TRANSITION_NAME);
String characterTitle = getIntent().getStringExtra(
- CharacterListListActivity.EXTRA_CHARACTER_NAME);
+ CharacterListActivity.EXTRA_CHARACTER_NAME);
Transition enterTransition = TransitionUtils.buildSlideTransition(Gravity.BOTTOM);
enterTransition.setDuration(mAnimMediumDuration);
@@ -167,9 +195,6 @@ public void hideRevealViewByAlpha() {
}
private void initToolbar() {
- mBinding.characterCollapsing.setExpandedTitleTextAppearance(
- R.style.Text_CollapsedExpanded);
-
mBinding.characterToolbar.setNavigationOnClickListener(v -> onBackPressed());
}
@@ -183,18 +208,49 @@ public void showError(String errorMessage) {
}
@Override
- public void bindCharacter(saulmm.avengers.model.entities.Character character) {
+ public void bindCharacter(MarvelCharacter character) {
mBinding.setCharacter(character);
}
- @BindingAdapter({"source", "presenter"})
- public static void setImageSource(ImageView v, String url, CharacterDetailPresenter detailPresenter) {
+ @Override
+ public void enableScroll() {
+ AppBarLayout.LayoutParams layoutParams = (AppBarLayout.LayoutParams) mCollapsing.getLayoutParams();
+ layoutParams.setScrollFlags(mScrolleableAppbarLayoutFlags);
+ mCollapsing.setLayoutParams(layoutParams);
+ }
+
+ @Override
+ public void goToCharacterComicsView(int characterId) {
+ CollectionActivity.start(this, characterId, CollectionItem.COMICS);
+ }
+
+ @Override
+ public void goToCharacterSeriesView(int characterId) {
+ CollectionActivity.start(this, characterId, CollectionItem.SERIES);
+ }
+
+ @Override
+ public void goToCharacterEventsView(int characterId) {
+ CollectionActivity.start(this, characterId, CollectionItem.EVENTS);
+ }
+
+ @Override
+ public void goToCharacterStoriesView(int characterId) {
+ CollectionActivity.start(this, characterId, CollectionItem.STORIES);
+ }
+
+ @BindingAdapter({"source", "presenter", "callback"})
+ public static void setImageSource(ImageView v, String url,
+ CharacterDetailPresenter detailPresenter, OnCharacterImageCallback imageCallback) {
+
Glide.with(v.getContext()).load(url).asBitmap().into(new BitmapImageViewTarget(v) {
@Override public void onResourceReady(Bitmap resource,
GlideAnimation super Bitmap> glideAnimation) {
super.onResourceReady(resource, glideAnimation);
v.setImageBitmap(resource);
- detailPresenter.onImageReceived(resource);
+ imageCallback.onReceive(resource);
+ detailPresenter.onImageReceived();
+
}
});
}
diff --git a/app/src/main/java/saulmm/avengers/views/activities/CharacterListListActivity.java b/app/src/main/java/saulmm/avengers/views/activities/CharacterListActivity.java
similarity index 91%
rename from app/src/main/java/saulmm/avengers/views/activities/CharacterListListActivity.java
rename to app/src/main/java/saulmm/avengers/views/activities/CharacterListActivity.java
index 610c2d6..3575cbb 100644
--- a/app/src/main/java/saulmm/avengers/views/activities/CharacterListListActivity.java
+++ b/app/src/main/java/saulmm/avengers/views/activities/CharacterListActivity.java
@@ -24,9 +24,10 @@
import javax.inject.Inject;
import saulmm.avengers.AvengersApplication;
import saulmm.avengers.R;
+import saulmm.avengers.entities.MarvelCharacter;
import saulmm.avengers.injector.components.DaggerAvengersComponent;
import saulmm.avengers.injector.modules.ActivityModule;
-import saulmm.avengers.model.entities.Character;
+
import saulmm.avengers.mvp.presenters.CharacterListPresenter;
import saulmm.avengers.mvp.views.CharacterListView;
import saulmm.avengers.utils.Utils;
@@ -34,13 +35,11 @@
import saulmm.avengers.views.views.RecyclerInsetsDecoration;
-public class CharacterListListActivity extends AppCompatActivity
+public class CharacterListActivity extends AppCompatActivity
implements CharacterListView {
- public final static String EXTRA_CHARACTER_ID = "character_id";
public final static String EXTRA_CHARACTER_NAME = "character_name";
public final static String EXTRA_IMAGE_TRANSITION_NAME = "transition_name";
- public final static int KEY_SHARED_BITMAP = 41;
@Bind(R.id.activity_avengers_recycler) RecyclerView mAvengersRecycler;
@Bind(R.id.activity_avengers_toolbar) Toolbar mAvengersToolbar;
@@ -111,7 +110,7 @@ private void initializeRecyclerView() {
}
@Override
- public void bindCharacterList(List avengers) {
+ public void bindCharacterList(List avengers) {
mCharacterListAdapter = new AvengersListAdapter(avengers, this,
(position, sharedView, characterImageView) -> {
mAvengersListPresenter.onElementClick(position);
@@ -131,7 +130,7 @@ public void showCharacterList() {
@Override
public void updateCharacterList(int charactersAdded) {
mCharacterListAdapter.notifyItemRangeInserted(
- mCharacterListAdapter.getItemCount() + charactersAdded, charactersAdded);
+ mCharacterListAdapter.getItemCount() + charactersAdded, charactersAdded);
}
@Override
@@ -209,13 +208,6 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
}
};
- @Override
- public ActivityOptions getActivityOptions(int position, View clickedView) {
- String sharedViewName = Utils.getListTransitionName(position);
- return ActivityOptions.makeSceneTransitionAnimation(
- this, clickedView, sharedViewName);
- }
-
@Override
public void showConnectionErrorMessage() {
TextView errorTextView = ButterKnife.findById(mErrorView, R.id.view_error_message);
diff --git a/app/src/main/java/saulmm/avengers/views/activities/CollectionActivity.java b/app/src/main/java/saulmm/avengers/views/activities/CollectionActivity.java
index 8bc3764..a254704 100644
--- a/app/src/main/java/saulmm/avengers/views/activities/CollectionActivity.java
+++ b/app/src/main/java/saulmm/avengers/views/activities/CollectionActivity.java
@@ -18,10 +18,10 @@
import javax.inject.Inject;
import saulmm.avengers.AvengersApplication;
import saulmm.avengers.R;
+import saulmm.avengers.entities.CollectionItem;
import saulmm.avengers.injector.components.DaggerAvengerInformationComponent;
import saulmm.avengers.injector.modules.ActivityModule;
import saulmm.avengers.injector.modules.AvengerInformationModule;
-import saulmm.avengers.model.entities.CollectionItem;
import saulmm.avengers.mvp.presenters.CollectionPresenter;
import saulmm.avengers.mvp.views.CollectionView;
diff --git a/app/src/main/java/saulmm/avengers/views/adapter/AvengersListAdapter.java b/app/src/main/java/saulmm/avengers/views/adapter/AvengersListAdapter.java
index 06e59ff..d84c122 100644
--- a/app/src/main/java/saulmm/avengers/views/adapter/AvengersListAdapter.java
+++ b/app/src/main/java/saulmm/avengers/views/adapter/AvengersListAdapter.java
@@ -19,18 +19,20 @@
import com.bumptech.glide.Glide;
import java.util.List;
import saulmm.avengers.R;
+import saulmm.avengers.entities.MarvelCharacter;
import saulmm.avengers.utils.Utils;
-import saulmm.avengers.model.entities.Character;
import saulmm.avengers.views.RecyclerClickListener;
public class AvengersListAdapter extends RecyclerView.Adapter {
private final String NOT_AVAILABLE_URL = "http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available.jpg";
private final RecyclerClickListener mRecyclerListener;
- private final List mCharacters;
+ private final List mCharacters;
private Context mContext;
- public AvengersListAdapter(List avengers, Context context, RecyclerClickListener recyclerClickListener) {
+ public AvengersListAdapter(List avengers, Context context,
+ RecyclerClickListener recyclerClickListener) {
+
mCharacters = avengers;
mContext = context;
mRecyclerListener = recyclerClickListener;
@@ -66,7 +68,7 @@ public CharacterViewHolder(View itemView, final RecyclerClickListener recyclerCl
bindListener(itemView, recyclerClickListener);
}
- public void bindAvenger(Character character) {
+ public void bindAvenger(MarvelCharacter character) {
avengerTitleTextView.setText(character.getName());
avengerTitleTextView.setTransitionName(Utils.getListTransitionName(getPosition()));
diff --git a/app/src/main/res/drawable/gradient_dark_up.xml b/app/src/main/res/drawable/gradient_dark_up.xml
index 218f078..a6f2ac5 100644
--- a/app/src/main/res/drawable/gradient_dark_up.xml
+++ b/app/src/main/res/drawable/gradient_dark_up.xml
@@ -3,8 +3,8 @@
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_avenger_detail.xml b/app/src/main/res/layout/activity_avenger_detail.xml
index d693b21..ddf285f 100644
--- a/app/src/main/res/layout/activity_avenger_detail.xml
+++ b/app/src/main/res/layout/activity_avenger_detail.xml
@@ -8,10 +8,11 @@
-
+
-
+
+
@@ -29,6 +30,7 @@
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
+ app:elevation="0dp"
>
-
+
-
-
-
+
+
+
+
+
+
+
-
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index df4635f..c2c2216 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -42,11 +42,10 @@
- 0dp
-