Skip to content

Commit

Permalink
Clean up the code bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
manjunathc23 committed Mar 9, 2017
1 parent 675a61e commit 785c3de
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 81 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright 2017 Manjunath Chandrashekar & Mudit Pant

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html)
![SDK](https://img.shields.io/badge/SDK-16%2B-green.svg)
![Release](https://img.shields.io/badge/release-0.0.2-green.svg)
![Release](https://img.shields.io/badge/release-0.0.3-green.svg)
[![Jitpack](https://jitpack.io/v/myntra/CoachMarks.svg)](https://jitpack.io/#myntra/CoachMarks)
[![Build Status](https://travis-ci.org/myntra/CoachMarks.svg?branch=master)](https://travis-ci.org/myntra/CoachMarks)
[![CircleCI](https://circleci.com/gh/myntra/CoachMarks.svg?style=svg)](https://circleci.com/gh/myntra/CoachMarks)
Expand All @@ -23,15 +23,15 @@ Add jitpack to your root `build.gradle`
Add the dependency
```
dependencies {
compile 'com.github.myntra:CoachMarks:0.0.2'
compile 'com.github.myntra:CoachMarks:0.0.3'
}
```


License
-------

Copyright Manjunath Chandrashekar & Mudit Pant 2017
Copyright 2017 Manjunath Chandrashekar & Mudit Pant

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions coachmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
versionCode 1
versionName "0.0.2"
versionName "0.0.3"
vectorDrawables.useSupportLibrary = true
}

Expand Down Expand Up @@ -38,8 +38,9 @@ dependencies {

//SUPPORT LIB
compile libraries.supportAppCompat
compile libraries.supportAnnotations

//Utils
//ZETA COMPONENTS
compile libraries.zetaUtils

//PROGRAMMING
Expand Down
66 changes: 38 additions & 28 deletions coachmarks/src/main/java/com/myntra/coachmarks/PopUpCoachMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@
import zeta.android.utils.view.ViewUtils;

public class PopUpCoachMark extends DialogFragment implements IPopUpCoachMarkPresentation, View.OnClickListener {

private static final String TAG = PopUpCoachMark.class.getSimpleName();

private static final int NO_MARGIN = 0;
private static final String ARG_POP_UP_COACH_MARK_BUILDER_PARCEL = "ARG_POP_UP_COACH_MARK_BUILDER_PARCEL";

private Views mViews;
private PopUpCoachMarkPresenter mPopUpCoachMarkPresenter;
private PopUpCoachMarkPresenter mPresenter;

static class Views extends BaseViews {

Expand Down Expand Up @@ -91,10 +92,10 @@ static class Views extends BaseViews {
@BindView(R2.id.v_notch_base_white_top)
View vNotchBaseWhiteTop;

@BindView(R2.id.test)
LinearLayout test;
@BindView(R2.id.ll_coachmark_text_wrapper_layout)
LinearLayout llCoachMarkTextWrapperLayout;

Views(View root) {
Views(@NonNull View root) {
super(root);
}
}
Expand Down Expand Up @@ -132,42 +133,47 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
final ITypeFaceProvider typeFaceProvider = new DefaultTypeFaceProvider(context);
final IScreenInfoProvider screenInfoProvider = new DefaultScreenInfoProvider(context);

mPopUpCoachMarkPresenter = new PopUpCoachMarkPresenter(stringResourceProvider, dimensionResourceProvider,
mPresenter = new PopUpCoachMarkPresenter(stringResourceProvider, dimensionResourceProvider,
typeFaceProvider, screenInfoProvider);
//coach mark bundle is injected in onCreate as its available from bundle only
//coach mark presenter params is injected in onCreate as it's available from bundle
//If we decide to migrate to DI pattern this will be useful
mPopUpCoachMarkPresenter.onCreate(getCoachMarkBuilderFromBundle());
final CoachMarkBuilder coachMarkBuilderFromBundle = getCoachMarkBuilderFromBundle();
assert coachMarkBuilderFromBundle != null;
mPresenter.onCreate(coachMarkBuilderFromBundle);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
final View view = inflater.inflate(R.layout.pop_up_coach_mark, container, false);
mViews = new Views(view);
mPopUpCoachMarkPresenter.onCreateView(this);
mPresenter.onCreateView(this);
registerClickListener();
return view;
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mPopUpCoachMarkPresenter.onViewCreated();
mPresenter.onViewCreated();
}

@Override
public void onDestroyView() {
super.onDestroyView();
mPresenter.onDestroyView();
unRegisterClickListener();
mViews = null;
}

@Override
public void onDestroy() {
super.onDestroy();
mPopUpCoachMarkPresenter.onDestroy();
mPopUpCoachMarkPresenter = null;
mPresenter.onDestroy();
mPresenter = null;
}

//region presentation methods
Expand All @@ -188,7 +194,7 @@ public void dismissWithError(String message) {
}

@Override
public void onDismiss() {
public void closeCoachMarkDialog() {
dismiss();
}

Expand All @@ -210,7 +216,7 @@ public void setPopUpViewPositionWithRespectToImage(@CoachMarkAlignPosition int a
}

@Override
public void setPopUpViewTopLeft(Rect margin, @CoachMarkLayoutOrientation int orientation) {
public void setPopUpViewTopLeft(@NonNull Rect margin, @CoachMarkLayoutOrientation int orientation) {
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.llPopUpCoachMarkParent.getLayoutParams();
layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom);
mViews.llPopUpCoachMarkParent.setLayoutParams(layoutParams);
Expand All @@ -220,7 +226,7 @@ public void setPopUpViewTopLeft(Rect margin, @CoachMarkLayoutOrientation int ori
}

@Override
public void setPopUpViewBottomRight(Rect margin, @CoachMarkLayoutOrientation int orientation) {
public void setPopUpViewBottomRight(@NonNull Rect margin, @CoachMarkLayoutOrientation int orientation) {
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.llPopUpCoachMarkParent.getLayoutParams();
layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom);
mViews.llPopUpCoachMarkParent.setLayoutParams(layoutParams);
Expand All @@ -233,23 +239,23 @@ public void setPopUpViewBottomRight(Rect margin, @CoachMarkLayoutOrientation int
public void setDismissButtonPositionLeft() {
RelativeLayout.LayoutParams okButtonLayoutParams = (RelativeLayout.LayoutParams) mViews.tvPopUpDismissButton.getLayoutParams();
RelativeLayout.LayoutParams separatorLayoutParams = (RelativeLayout.LayoutParams) mViews.vSeparator.getLayoutParams();
RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.test.getLayoutParams();
RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.llCoachMarkTextWrapperLayout.getLayoutParams();
okButtonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, mViews.rlCoachMarkTextPart.getId());
mViews.tvPopUpDismissButton.setLayoutParams(okButtonLayoutParams);
separatorLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.tvPopUpDismissButton.getId());
mViews.vSeparator.setLayoutParams(separatorLayoutParams);
coachMarkTextParams.addRule(RelativeLayout.RIGHT_OF, mViews.vSeparator.getId());
mViews.test.setLayoutParams(coachMarkTextParams);
mViews.llCoachMarkTextWrapperLayout.setLayoutParams(coachMarkTextParams);
}

@Override
public void setDismissButtonPositionRight() {
RelativeLayout.LayoutParams okButtonLayoutParams = (RelativeLayout.LayoutParams) mViews.tvPopUpDismissButton.getLayoutParams();
RelativeLayout.LayoutParams separatorLayoutParams = (RelativeLayout.LayoutParams) mViews.vSeparator.getLayoutParams();
RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.test.getLayoutParams();
RelativeLayout.LayoutParams coachMarkTextParams = (RelativeLayout.LayoutParams) mViews.llCoachMarkTextWrapperLayout.getLayoutParams();
coachMarkTextParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, mViews.rlCoachMarkTextPart.getId());
mViews.test.setLayoutParams(coachMarkTextParams);
separatorLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.test.getId());
mViews.llCoachMarkTextWrapperLayout.setLayoutParams(coachMarkTextParams);
separatorLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.llCoachMarkTextWrapperLayout.getId());
mViews.vSeparator.setLayoutParams(separatorLayoutParams);
okButtonLayoutParams.addRule(RelativeLayout.RIGHT_OF, mViews.vSeparator.getId());
mViews.tvPopUpDismissButton.setLayoutParams(okButtonLayoutParams);
Expand All @@ -272,15 +278,15 @@ public void startAlphaAnimationOnImage() {
}

@Override
public void setNotchPositionIfPopUpTopLeft(Rect margin, float rotation) {
public void setNotchPositionIfPopUpTopLeft(@NonNull Rect margin, float rotation) {
mViews.vRightBottomNotch.setRotation(rotation);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViews.vRightBottomNotch.getLayoutParams();
layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom);
mViews.vRightBottomNotch.setLayoutParams(layoutParams);
}

@Override
public void setNotchPositionIfPopUpBottomRight(Rect margin, float rotation) {
public void setNotchPositionIfPopUpBottomRight(@NonNull Rect margin, float rotation) {
mViews.vLeftTopNotch.setRotation(rotation);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViews.vLeftTopNotch.getLayoutParams();
layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom);
Expand All @@ -303,15 +309,15 @@ public void setUpGravityForCoachMarkText(@CoachMarkTextGravity int gravity) {
}

@Override
public void uiAdjustmentForNotchIfPopUpRight(Rect margin) {
public void uiAdjustmentForNotchIfPopUpRight(@NonNull Rect margin) {
ViewUtils.setToVisible(mViews.vNotchBaseWhiteLeft);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.vNotchBaseWhiteLeft.getLayoutParams();
layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom);
mViews.vNotchBaseWhiteLeft.setLayoutParams(layoutParams);
}

@Override
public void uiAdjustmentForNotchIfPopUpBottom(Rect margin) {
public void uiAdjustmentForNotchIfPopUpBottom(@NonNull Rect margin) {
ViewUtils.setToVisible(mViews.vNotchBaseWhiteTop);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mViews.vNotchBaseWhiteTop.getLayoutParams();
layoutParams.setMargins(margin.left, margin.top, margin.right, margin.bottom);
Expand All @@ -327,18 +333,22 @@ public void setCoachMarkMessage(String message) {

//region click listeners
@Override
public void onClick(View v) {
public void onClick(@Nullable View v) {
if (v == null) {
return;
}
if (v.getId() == R.id.tv_ok_button) {
if (mPopUpCoachMarkPresenter != null) {
mPopUpCoachMarkPresenter.onOkButtonClicked();
if (mPresenter != null) {
mPresenter.onOkButtonClicked();
}
} else if (v.getId() == R.id.rl_shim_out_view_parent) {
mPopUpCoachMarkPresenter.onShimClicked();
mPresenter.onShimClicked();
}
}
//endregion

//region helper methods
@Nullable
private CoachMarkBuilder getCoachMarkBuilderFromBundle() {
return getArguments().getParcelable(ARG_POP_UP_COACH_MARK_BUILDER_PARCEL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.annotation.ColorRes;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;

Expand Down Expand Up @@ -41,6 +42,7 @@ public static Builder create(Point coachMarkViewAnchorTop,
.setImageLayoutInformation(ImageLayoutInformation.create(R.dimen.coach_mark_zero_dp, R.dimen.coach_mark_zero_dp).build());
}

@NonNull
@SuppressWarnings("unused")
public Builder newBuilder() {
return new AutoValue_CoachMarkBuilder.Builder(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.util.Log;

import com.myntra.coachmarks.providers.interfaces.ITypeFaceProvider;
Expand All @@ -18,6 +19,7 @@ public DefaultTypeFaceProvider(final Context context) {
}

@Override
@Nullable
public Typeface getTypeFaceFromAssets(final String fontFilePath) {
try {
return Typeface.createFromAsset(mContext.getAssets(), fontFilePath);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.myntra.coachmarks.providers.interfaces;

import android.graphics.Typeface;
import android.support.annotation.Nullable;

public interface ITypeFaceProvider {
@Nullable
Typeface getTypeFaceFromAssets(final String fontFilePath);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.myntra.coachmarks.ui.common;

import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import butterknife.ButterKnife;

public abstract class BaseViews {

@Nullable
private View mRoot;

protected BaseViews(View root) {
protected BaseViews(@NonNull View root) {
mRoot = root;
ButterKnife.bind(this, root);
}

@Nullable
public View getRootView() {
return mRoot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void setImageInformation(double centerX, double centerY, int imageWidth,

void dismissWithError(String message);

void onDismiss();
void closeCoachMarkDialog();

void startThrobAnimationOnImage();

Expand Down
Loading

0 comments on commit 785c3de

Please sign in to comment.