Skip to content

Commit

Permalink
Fix #74: Some code beauty after finishing this project stage. (#80)
Browse files Browse the repository at this point in the history
- Rename Feed and Gif Component to GifView and FeedView, and RenderableComponent to ReactiveView.
- Rename AnvilRenderComponent to AnvilRenderable.
- Apply some android studio "analyze code" inspect tool sugestions.
  • Loading branch information
raulccabreu authored Nov 24, 2016
1 parent 73bef34 commit 7733714
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 85 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ To run unit tests through a CI or command line:

drone exec --trusted

#Good Pratices
#Good Practices

###Actions Creators

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import android.support.test.espresso.Espresso;
import android.support.test.espresso.IdlingResource;

import br.com.catbag.gifreduxsample.ui.AnvilRenderComponent;
import br.com.catbag.gifreduxsample.ui.AnvilRenderListener;
import br.com.catbag.gifreduxsample.ui.AnvilRenderable;

/**
* Created by niltonvasques on 10/24/16.
Expand All @@ -15,16 +15,16 @@
public class AnvilTestLocker implements IdlingResource, AnvilRenderListener {

private static final int FORCE_IS_IDLE_NOW_DELAY = 250;
private AnvilRenderComponent mAnvilRenderComponent;
private AnvilRenderable mAnvilRenderable;
private ResourceCallback mResourceCallback;
private int mRenderTimes = 0;
private int mLastRenderTimes = 0;
private Handler mHandler = new Handler(Looper.getMainLooper());
private Runnable mForceIsIdleNow = () -> isIdleNow();
private Runnable mForceIsIdleNow = this::isIdleNow;

public AnvilTestLocker(AnvilRenderComponent anvilRenderComponent) {
mAnvilRenderComponent = anvilRenderComponent;
mAnvilRenderComponent.setAnvilRenderListener(this);
public AnvilTestLocker(AnvilRenderable anvilRenderable) {
mAnvilRenderable = anvilRenderable;
mAnvilRenderable.setAnvilRenderListener(this);
}

@Override
Expand Down Expand Up @@ -60,7 +60,7 @@ public void registerIdlingResource() {

public void unregisterIdlingResource() {
mHandler.removeCallbacks(mForceIsIdleNow);
mAnvilRenderComponent.setAnvilRenderListener(null);
mAnvilRenderable.setAnvilRenderListener(null);
Espresso.unregisterIdlingResources(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.hamcrest.Matcher;

import br.com.catbag.gifreduxsample.R;
import br.com.catbag.gifreduxsample.ui.components.GifComponent;
import br.com.catbag.gifreduxsample.ui.components.GifView;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

Expand Down Expand Up @@ -55,8 +55,8 @@ public static Matcher<View> withEqualsGifUuid(final String uuid) {
return new BoundedMatcher<View, View>(View.class) {
@Override
public boolean matchesSafely(View view) {
GifComponent gifComponent = (GifComponent) ((FrameLayout) view).getChildAt(0);
return gifComponent.getGif().getUuid().equals(uuid);
GifView gifView = (GifView) ((FrameLayout) view).getChildAt(0);
return gifView.getGif().getUuid().equals(uuid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
Expand Down Expand Up @@ -35,9 +36,7 @@ public void describeTo(Description description) {
idDescription = this.mResources.getResourceName(mRecyclerViewId);
} catch (Resources.NotFoundException var4) {
idDescription = String.format("%s (resource name not found)",
new Object[] {
Integer.valueOf(mRecyclerViewId)
});
mRecyclerViewId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import br.com.catbag.gifreduxsample.middlewares.RestMiddleware;
import br.com.catbag.gifreduxsample.models.Gif;
import br.com.catbag.gifreduxsample.ui.GifListActivity;
import br.com.catbag.gifreduxsample.ui.components.FeedComponent;
import br.com.catbag.gifreduxsample.ui.components.GifComponent;
import br.com.catbag.gifreduxsample.ui.components.FeedView;
import br.com.catbag.gifreduxsample.ui.components.GifView;
import shared.ReduxBaseTest;
import shared.TestHelper;

Expand Down Expand Up @@ -340,8 +340,8 @@ private Matcher<View> withRecyclerPos(int pos) {
return new RecyclerViewMatcher(getRecyclerView().getId()).atPosition(pos);
}

private FeedComponent getFeedComponent() {
return (FeedComponent) getActivity().findViewById(R.id.feed);
private FeedView getFeedComponent() {
return (FeedView) getActivity().findViewById(R.id.feed);
}

private RecyclerView getRecyclerView() {
Expand All @@ -350,9 +350,9 @@ private RecyclerView getRecyclerView() {
return recyclerView;
}

private GifComponent getGifComponent(int screenPos) {
private GifView getGifComponent(int screenPos) {
FrameLayout frameLayout = (FrameLayout) getRecyclerView().getChildAt(screenPos);
return (GifComponent) frameLayout.getChildAt(0);
return (GifView) frameLayout.getChildAt(0);
}

private GifListActivity getActivity() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="br.com.catbag.gifreduxsample">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SET_DEBUG_APP"></uses-permission>
<uses-permission android:name="android.permission.SET_DEBUG_APP"/>

<application
android:name="br.com.catbag.gifreduxsample.MyApp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
* Created by raulcca on 11/21/16.
*/

public class MyDispatcherImpl extends DispatcherImpl<AppState> {
/**
* Your initial state tree
*
* @param state
*/
class MyDispatcherImpl extends DispatcherImpl<AppState> {
public MyDispatcherImpl(AppState state) {
super(state);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Created by raulcca on 11/21/16.
*/

public class MyFluxxan extends Fluxxan<AppState> {
class MyFluxxan extends Fluxxan<AppState> {
/**
* Create a new instance
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void onFailure(Call<ResponseBody> call, Throwable t) {
});
}

public void readFromNetAndWriteToDisk(InputStream inputStream, String pathToSave)
private void readFromNetAndWriteToDisk(InputStream inputStream, String pathToSave)
throws IOException {

File futureStudioIconFile = new File(pathToSave);
Expand All @@ -76,12 +76,8 @@ public void readFromNetAndWriteToDisk(InputStream inputStream, String pathToSave
}

outputStream.flush();
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
inputStream.close();
outputStream.close();
}

public interface SuccessDownloadListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ private void downloadGif(AppState appState, Action action) {
params.put(PayloadParams.PARAM_PATH, pathToSave);
mDispatcher.dispatch(new Action(GIF_DOWNLOAD_SUCCESS, params));
},
e -> {
mDispatcher.dispatch(new Action(GIF_DOWNLOAD_FAILURE, gif.getUuid()));
});
e -> mDispatcher.dispatch(new Action(GIF_DOWNLOAD_FAILURE, gif.getUuid())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Created by niltonvasques on 10/12/16.
*/

public final class GifInnerReducer {
final class GifInnerReducer {
private GifInnerReducer() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* Created by raulcca on 10/31/16.
*/

public interface AnvilRenderComponent {
public interface AnvilRenderable {
void setAnvilRenderListener(AnvilRenderListener listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static trikita.anvil.DSL.visibility;

public class GifListActivity extends StateListenerActivity<AppState>
implements AnvilRenderComponent {
implements AnvilRenderable {

//Binding Data
private boolean mGifProgressVisibility = true;
Expand Down Expand Up @@ -59,9 +59,7 @@ public void setAnvilRenderListener(AnvilRenderListener listener) {
private void bindingViews() {
//Bindings Defaults
Anvil.mount(findViewById(R.id.activity_gif_list), () -> {
withId(R.id.loading, () -> {
visibility(mGifProgressVisibility);
});
withId(R.id.loading, () -> visibility(mGifProgressVisibility));

if (mAnvilRenderListener != null) mAnvilRenderListener.onAnvilRendered();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
/**
* Created by niltonvasques on 10/26/16.
*/
public class FeedComponent extends RenderableComponent {
public class FeedView extends ReactiveView {

private Map<String, Gif> mGifs;
private DrawableCache mDrawables = new DrawableCache();
private LinearLayoutManager mLayoutManager;
private GifsAdapter mGifsAdapter;

public FeedComponent(Context context) {
public FeedView(Context context) {
super(context);
}

public FeedComponent(Context context, AttributeSet attrs) {
public FeedView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public FeedComponent(Context context, AttributeSet attrs, int defStyleAttr) {
public FeedView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

Expand All @@ -52,7 +52,7 @@ public void view() {
LinearLayoutManager.VERTICAL, false);
}
if (mGifsAdapter == null) {
mGifsAdapter = gifsAdapter(mGifs, (gif) -> renderGifView(gif));
mGifsAdapter = gifsAdapter(mGifs, this::renderGifView);
}

Recycler.layoutManager(mLayoutManager);
Expand Down Expand Up @@ -85,11 +85,9 @@ protected void initialState() {
}

private void renderGifView(Gif gif) {
v(GifComponent.class, () -> {
((GifComponent) Anvil.currentView())
.withGifDrawable(createDrawable(gif))
.withGif(gif);
});
v(GifView.class, () -> ((GifView) Anvil.currentView())
.withGifDrawable(createDrawable(gif))
.withGif(gif));
onAnvilRendered();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,33 @@
* Created by felipe on 26/10/16.
*/

public class GifComponent extends RenderableComponent {
public class GifView extends ReactiveView {

private Gif mGif;
private GifDrawable mGifDrawable;
private boolean mHasRequestedDownload = false;

public GifComponent(Context context) {
public GifView(Context context) {
super(context);
}

public GifComponent(Context context, AttributeSet attrs) {
public GifView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public GifComponent(Context context, AttributeSet attrs, int defStyleAttr) {
public GifView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public GifComponent withGif(Gif gif) {
public GifView withGif(Gif gif) {
if (gif != null) {
if (!gif.getUuid().equals(mGif.getUuid())) mHasRequestedDownload = false;
mGif = gif;
}
return this;
}

public GifComponent withGifDrawable(GifDrawable gifDrawable) {
public GifView withGifDrawable(GifDrawable gifDrawable) {
mGifDrawable = gifDrawable;
return this;
}
Expand All @@ -70,9 +70,7 @@ public void view() {
requestContent();
defineBehavior();
});
withId(R.id.gif_loading, () -> {
visibility(mGif.getStatus() == DOWNLOADING);
});
withId(R.id.gif_loading, () -> visibility(mGif.getStatus() == DOWNLOADING));
});
onAnvilRendered();
}
Expand Down Expand Up @@ -127,9 +125,7 @@ private void defineBehavior() {

mGifDrawable.stop();
}
onClick(v -> {
GifActionCreator.getInstance().gifClick(mGif);
});
onClick(v -> GifActionCreator.getInstance().gifClick(mGif));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@

import br.com.catbag.gifreduxsample.MyApp;
import br.com.catbag.gifreduxsample.models.AppState;
import br.com.catbag.gifreduxsample.ui.AnvilRenderComponent;
import br.com.catbag.gifreduxsample.ui.AnvilRenderListener;
import br.com.catbag.gifreduxsample.ui.AnvilRenderable;
import trikita.anvil.RenderableView;

/**
* Created by raulcca on 11/21/16.
*/

public abstract class RenderableComponent extends RenderableView
implements StateListener<AppState>, AnvilRenderComponent {
public abstract class ReactiveView extends RenderableView
implements StateListener<AppState>, AnvilRenderable {

private boolean mIsRegisteredOnStateChange = false;
private AnvilRenderListener mAnvilRenderListener;

public RenderableComponent(Context context) {
public ReactiveView(Context context) {
super(context);
initialState();
}

public RenderableComponent(Context context, AttributeSet attrs) {
public ReactiveView(Context context, AttributeSet attrs) {
super(context, attrs);
initialState();
}

public RenderableComponent(Context context, AttributeSet attrs, int defStyleAttr) {
public ReactiveView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialState();
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_gif_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="br.com.catbag.gifreduxsample.ui.GifListActivity">

<br.com.catbag.gifreduxsample.ui.components.FeedComponent
<br.com.catbag.gifreduxsample.ui.components.FeedView
android:id="@+id/feed"
android:layout_width="match_parent"
android:layout_height="match_parent">
</br.com.catbag.gifreduxsample.ui.components.FeedComponent>
</br.com.catbag.gifreduxsample.ui.components.FeedView>

<include layout="@layout/common_progress"/>
</RelativeLayout>
Loading

0 comments on commit 7733714

Please sign in to comment.