<file_sep>package son.nt.en.feed.adapter;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.lang.ref.WeakReference;
import java.util.List;

import son.nt.en.R;
import son.nt.en.elite.BusElite;
import son.nt.en.elite.EliteDto;
import son.nt.en.otto.OttoBus;

/**
 * Created by Sonnt on 7/7/15.
 */
public class AdapterFeedElite extends RecyclerView.Adapter<AdapterFeedElite.ViewHolder> {

    private static final String TAG = AdapterFeedElite.class.getSimpleName();
    public List<EliteDto> mValues;
    Context context;
    private final WeakReference<Context> contextWeakReference;

    private int previous = 0;

    public AdapterFeedElite(Context cx) {
        this.context = cx;
        this.contextWeakReference = new WeakReference<>(cx);
    }

    public void setData(List<EliteDto> mValues) {
        this.mValues = mValues;
        notifyDataSetChanged();
    }

    public EliteDto getItem(int position) {
        return mValues.get(position);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_feed_elite_daily, viewGroup, false);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {
        EliteDto EliteDto = mValues.get(position);
        final EliteDto dto = EliteDto;

        String no = String.valueOf(position).trim();
        if (no.length() == 1) {
            no = no + "  ";
        } else if (no.length() == 2) {
            no = no + " ";
        }
        viewHolder.createdTimeTextView.setText(no);

        viewHolder.messageTextView.setText(dto.title);
        viewHolder.messengerTextView.setText(dto.des);


        Glide.with(context) //
                .load(dto.image)//
                .centerCrop()//
                .diskCacheStrategy(DiskCacheStrategy.ALL)//
                .into(viewHolder.imgBackground);

    }

    @Override
    public int getItemCount() {
        return mValues == null ? 0 : mValues.size();
    }


    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView messageTextView;
        public TextView messengerTextView;
        public TextView createdTimeTextView;

        public ImageView imgBackground;

        public ViewHolder(View v) {
            super(v);
            messageTextView = (TextView) itemView.findViewById(R.id.messageTextView);
            messengerTextView = (TextView) itemView.findViewById(R.id.messengerTextView);
            createdTimeTextView = (TextView) itemView.findViewById(R.id.createdTimeTextView);
            imgBackground = (ImageView) itemView.findViewById(R.id.imageView);
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    OttoBus.post(new BusElite(getAdapterPosition()));

                }
            });
        }
    }
}
<file_sep>// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'me.tatarka:gradle-retrolambda:3.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

ext {
    // Sdk and tools
    minSdkVersion = 16
    targetSdkVersion = 23
    compileSdkVersion = 23
    buildToolsVersion = '23.0.3'

    // App dependencies
    supportLibraryVersion = '24.0.0'
    butterKnifeVersion = '7.0.1'
    frescoVersion = '0.10.0'
    dagger2Version = '2.2'
    pacerlVersion= '1.1.5'
    rxAndroidVersion = '1.2.0'
    gsonVersion = '2.6.2'
    rxJavaVersion = '1.1.5'
    retrofitVersion = '2.0.2'
    loggingInterceptorVersion = '2.7.5'
    okhttp3Version ='3.3.1'

    //Testing
    robolectricVersion = '3.1-rc1'
    jUnitVersion = '4.12'
    assertJVersion = '1.7.1'
    mockitoVersion = '2.0.2-beta'
    powerMockitoVersion = '1.6.5'
    hamcrestVersion = '1.3'
    dexmakerVersion = '1.0'
    espressoVersion = '2.2.2'
    runnerVersion = '0.5'
    rulesVersion = '0.5'
    testingSupportLibVersion = '0.1'

    supportLibraryDependencies = [
            appcompatV7:     "com.android.support:appcompat-v7:${supportLibraryVersion}",
            supportV4:             "com.android.support:support-v4:${supportLibraryVersion}",
            design:    "com.android.support:design:${supportLibraryVersion}",
            recyclerview:             "com.android.support:recyclerview-v7:${supportLibraryVersion}",
            cardview:            "com.android.support:cardview-v7:${supportLibraryVersion}",
            annotations:"com.android.support:support-annotations:${supportLibraryVersion}",
    ]

    domainDependencies = [
            daggerApt:     "com.google.dagger:dagger-compiler:${dagger2Version}",
            dagger:             "com.google.dagger:dagger:${dagger2Version}",
            parcelerApt:"org.parceler:parceler:${pacerlVersion}",
            parceler:"org.parceler:parceler-api:${pacerlVersion}",
            rxJava:             "io.reactivex:rxjava:${rxJavaVersion}",
            rxAndroid: "io.reactivex:rxandroid:${rxAndroidVersion}",
            fresco:"com.facebook.fresco:fresco:${frescoVersion}",
            butterknife:"com.jakewharton:butterknife:${butterKnifeVersion}",
            gson:"com.google.code.gson:gson:${gsonVersion}",
            retrofit:"com.squareup.retrofit2:retrofit:${retrofitVersion}",
            retrofitAdapter: "com.squareup.retrofit2:adapter-rxjava:${retrofitVersion}",
            retrofitConverter: "com.squareup.retrofit2:converter-gson:${retrofitVersion}",
    ]
    domainTestDependencies = [
            junit:              "junit:junit:${jUnitVersion}",
            mockito:            "org.mockito:mockito-all:${mockitoVersion}",
            robolectric:        "org.robolectric:robolectric:${robolectricVersion}",
    ]
}
<file_sep>package son.nt.en.di;

import android.app.Application;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

/**
 * Created by sonnt on 8/15/16.
 */
@Module
public class AppModule
{
    Application mApplication;

    public AppModule(Application mApplication)
    {
        this.mApplication = mApplication;
    }

    @Provides
    @Singleton
    Application provideMyApplication()
    {
        return mApplication;
    }

    @Provides
    @Singleton
    DatabaseReference provideDatabaseReference()
    {
        return FirebaseDatabase.getInstance().getReference();
    }
}
<file_sep>package son.nt.en.login;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import son.nt.en.HomeActivity;
import son.nt.en.R;
import son.nt.en.base.BaseActivity;
import son.nt.en.google_client_api.DaggerGoogleApiComponent;
import son.nt.en.google_client_api.GoogleApiClientModule;

/**
 * A login screen that offers login via email/password.
 */
public class LoginActivity extends BaseActivity
        implements OnClickListener, GoogleApiClient.OnConnectionFailedListener {

    private static final int REQUEST_READ_CONTACTS = 0;
    private static final String REQUEST_START = "REQUEST_START";

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

    private static final int RC_SIGN_IN = 9001;

    @BindView(R.id.sign_in_button)
    SignInButton mSignInButton;

    @BindView(R.id.login_welcome)
    TextView mTxtWelcome;
    @BindView(R.id.login_skip)
    TextView mTxtSkip;

    @Inject
    FirebaseAuth mFirebaseAuth;
    @Inject
    FirebaseUser mFirebaseUser;

    @Inject
    GoogleApiClient mGoogleApiClient;


    private boolean isNotStart = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);

        isNotStart = getIntent().getBooleanExtra("REQUEST_START", false);

        //inject
        GoogleApiClientModule googleApiClientModule = new GoogleApiClientModule(this, getString(R.string.default_web_client_id), this);
        DaggerGoogleApiComponent.builder().googleApiClientModule(googleApiClientModule).build().inject(this);

        // Set up the login form.
        mTxtWelcome.setText(getString(R.string.welcome_to, getString(R.string.app_name)));

        mSignInButton.setOnClickListener(this);
        mTxtSkip.setOnClickListener(this);
        if (mFirebaseUser != null) {
            moveToHome();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sign_in_button: {
                Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
                startActivityForResult(signInIntent, RC_SIGN_IN);
                break;
            }
            case R.id.login_skip: {
                moveToHome();

                break;
            }

        }
    }

    private void moveToHome() {
        Toast.makeText(this, "Hello " + mFirebaseUser.getDisplayName(), Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(this, HomeActivity.class);
        startActivity(intent);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()) {
                // Google Sign In was successful, authenticate with Firebase
                GoogleSignInAccount account = result.getSignInAccount();
                firebaseAuthWithGoogle(account);
            } else {
                // Google Sign In failed
                Log.e(TAG, "Google Sign In failed.");
            }
        }
    }

    private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
        Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
        AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
        mFirebaseAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                // If sign in fails, display a message to the user. If sign in succeeds
                // the auth state listener will be notified and logic to handle the
                // signed in user can be handled in the listener.
                if (!task.isSuccessful()) {
                    Log.w(TAG, "signInWithCredential", task.getException());
                    Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
                } else {
                    if (isNotStart) {
                        setResult(RESULT_OK);
                        finish();

                    } else {
                        moveToHome();
                        finish();
                    }

                }

            }
        });
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        //Do nothing

    }


}
<file_sep>package son.nt.en.hellochao;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import com.bumptech.glide.Glide;
import com.squareup.otto.Subscribe;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import son.nt.en.FireBaseConstant;
import son.nt.en.R;
import son.nt.en.base.BaseFragment;
import son.nt.en.otto.OttoBus;
import son.nt.en.service.GoPlayer;
import son.nt.en.service.MusicService;
import son.nt.en.utils.Logger;

/**
 * Created by sonnt on 7/11/16.
 */
public class HelloChaoFragment extends BaseFragment implements HelloChaoContract.View, View.OnClickListener, TextWatcher {

    public static final String TAG = HelloChaoFragment.class.getSimpleName();
    private RecyclerView mMessageRecyclerView;
    private LinearLayoutManager mLinearLayoutManager;
    private ProgressBar mProgressBar;

    @BindView(R.id.CoordinatorLayoutChat)
    CoordinatorLayout mCoordinatorLayout;

    @BindView(R.id.txt_search)
    EditText txtSearch;
    @BindView(R.id.btn_clear)
    View btnClear;


    @BindView(R.id.player_play)
    ImageView mImgPlay;

    @BindView(R.id.img_track)
    ImageView mImgTrack;

    @BindView(R.id.txt_title)
    TextView mTxtTitle;

    @BindView(R.id.txt_des)
    TextView mTxtDes;

    DatabaseReference mFirebaseDatabaseReference;

    private AdapterHelloChao mAdapter;

    boolean isBind = false;

    MusicService mPlayService;

    SearchHandler mSearchHandler;

    HelloChaoContract.Presenter mPresenter;

    public static HelloChaoFragment newInstace() {
        HelloChaoFragment f = new HelloChaoFragment();
        return f;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        OttoBus.register(this);
        MusicService.bindToMe(getContext(), serviceConnectionPlayer);
        mPresenter = new HelloChaoPresenter(this, FirebaseDatabase.getInstance().getReference());
    }

    @Override
    public void onDestroy() {
        OttoBus.unRegister(this);
        getActivity().unbindService(serviceConnectionPlayer);
        if (mSearchHandler != null) {
            mSearchHandler.removeMessage();
            mSearchHandler = null;
        }
        super.onDestroy();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_hello_chao, container, false);
        ButterKnife.bind(this, view);
        // Initialize ProgressBar and RecyclerView.
        mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
        mMessageRecyclerView = (RecyclerView) view.findViewById(R.id.messageRecyclerView);

        //search
        btnClear.setOnClickListener(this);
        txtSearch.addTextChangedListener(this);

        mLinearLayoutManager = new LinearLayoutManager(getActivity());
        mLinearLayoutManager.setStackFromEnd(true);
        mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
        mAdapter = new AdapterHelloChao(getActivity());

        // New child entries
        mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
        mFirebaseDatabaseReference.child(FireBaseConstant.TABLE_HELLO_CHAO).orderByChild("text")
                .addValueEventListener(valueEventListener);

        mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
        mMessageRecyclerView.setAdapter(mAdapter);

        //onclick
        mImgPlay.setOnClickListener(this);

        return view;

    }

    ServiceConnection serviceConnectionPlayer = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            MusicService.LocalBinder localBinder = (MusicService.LocalBinder) service;
            mPlayService = localBinder.getService();
            isBind = true;

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            isBind = false;
            mPlayService = null;
        }
    };

    @Subscribe
    public void getSelection(BusSentence busSentence) {
        if (mPlayService != null) {
            mPlayService.setDataToService(mAdapter.mValues);
            mPlayService.playAtPos(busSentence.pos);
        }

    }

    /**
     * called from {@link MusicService#play()}
     */

    @Subscribe
    public void getFromService(GoPlayer goPlayer) {
        mTxtTitle.setText(goPlayer.title);
        mTxtDes.setText(goPlayer.des);
        mImgPlay.setImageResource(goPlayer.command == GoPlayer.DO_PLAY ? R.drawable.icon_paused : R.drawable.icon_played);
        if (goPlayer.image != null) {
            Glide.with(this).load(goPlayer.image).fitCenter().into(mImgTrack);
        }

    }

    ValueEventListener valueEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Logger.debug(TAG, ">>>" + " valueEventListener onDataChange");
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            List<HelloChaoSentences> list = new ArrayList<>();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                HelloChaoSentences post = postSnapshot.getValue(HelloChaoSentences.class);
                list.add(post);
            }

            mAdapter.setData(list);
            mPresenter.setData(list);
            mMessageRecyclerView.scrollToPosition(0);
            if (mPlayService != null) {
                mPlayService.setDataToService(list);
            }

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);

        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_clear: {
                txtSearch.setText("");
                break;
            }
            case R.id.player_play: {
                if (mPlayService != null) {
                    mPlayService.play();
                }
                break;
            }
        }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        if (s.length() > 0) {
            btnClear.setVisibility(View.VISIBLE);
        } else {
            btnClear.setVisibility(View.GONE);
        }
        if (mSearchHandler == null) {
            mSearchHandler = new SearchHandler(this);
        }
        mSearchHandler.removeMessage();
        mSearchHandler.doSearch();

    }

    private void doSearch() {
        String keyword = txtSearch.getText().toString();
        Logger.debug(TAG, ">>>" + "doSearch:" + keyword);
        mPresenter.doSearch(keyword);

    }

    @Override
    public void resultSearch(List<HelloChaoSentences> list) {
        mAdapter.setData(list);

    }

    private static class SearchHandler extends Handler {
        public static final int WHAT_SEARCH = 1;

        WeakReference<HelloChaoFragment> helloChaoFragmentWeakReference = new WeakReference<HelloChaoFragment>(null);

        public SearchHandler(HelloChaoFragment helloChaoFragment) {
            helloChaoFragmentWeakReference = new WeakReference<HelloChaoFragment>(helloChaoFragment);

        }

        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
                case WHAT_SEARCH: {
                    HelloChaoFragment f = helloChaoFragmentWeakReference.get();
                    if (f != null) {
                        f.doSearch();
                    }
                    break;
                }

            }
        }

        public void removeMessage() {
            removeMessages(WHAT_SEARCH);
        }

        public void doSearch() {
            sendEmptyMessageDelayed(WHAT_SEARCH, 750);
        }
    }

}
<file_sep>package son.nt.en.feed;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import rx.Single;
import rx.SingleSubscriber;
import son.nt.en.FireBaseConstant;
import son.nt.en.MsConst;
import son.nt.en.elite.EliteDto;
import son.nt.en.esl.EslDailyDto;
import son.nt.en.hellochao.HelloChaoSentences;
import son.nt.en.utils.Logger;

/**
 * Created by sonnt on 8/22/16.
 */
public class FeedRepository implements FeedContract.IRepository {


    public static final String TAG = FeedRepository.class.getSimpleName();
    SingleSubscriber<List<EliteDto>> subscriberElite;
    SingleSubscriber<List<EslDailyDto>> subscriberEsl;

    DatabaseReference mDatabaseReference;

    @Inject
    public FeedRepository(DatabaseReference databaseReference) {
        mDatabaseReference = databaseReference;
    }

    @Override
    public void getElite(SingleSubscriber<List<EliteDto>> getElites) {
        this.subscriberElite = getElites;

        Query query = mDatabaseReference.child(FireBaseConstant.TABLE_ELITE_DAILY).limitToFirst(5);
        query.addListenerForSingleValueEvent(mEliteValueEventListener);
    }

    @Override
    public void getESL(SingleSubscriber<List<EslDailyDto>> subscriberEsl) {
        this.subscriberEsl = subscriberEsl;

        Query query = mDatabaseReference.child(FireBaseConstant.TABLE_ESL_DAILY).limitToFirst(5);
        query.addListenerForSingleValueEvent(mESlValueEventListener);
    }

    @Override
    public Single<List<HelloChaoSentences>> getDailyHelloChao() {

        return Single.create(new Single.OnSubscribe<List<HelloChaoSentences>>() {
            @Override
            public void call(SingleSubscriber<? super List<HelloChaoSentences>> singleSubscriber) {
                try {

                    Document document = Jsoup.connect(MsConst.HELLO_CHAO_THU_THACH_TRONG_NGAY).get();
                    Elements items = document.getElementsByAttributeValue("class", "box shadow light callout");
                    Elements data = items.get(0).getElementsByClass("raw-menu");

                    List<HelloChaoSentences> helloChaoSentences = new ArrayList<>();
                    HelloChaoSentences helloChaoSentence;
                    for (Element e : data.get(0).getAllElements()) {
                        if (e.nodeName().equals("li")) {
                            String link = e.getElementsByAttribute("href").attr("href");
                            String textEng = e.getAllElements().get(1).text();
                            String textVi = e.getAllElements().get(0).text().replace(textEng, "");
                            Logger.debug(TAG, ">>>" + "link:" + link + " ;textVi:" + textVi + ";textEng:" + textEng);
                            helloChaoSentence = new HelloChaoSentences(textEng, link, textVi);
                            helloChaoSentences.add(helloChaoSentence);
                        }
                    }

                    singleSubscriber.onSuccess(helloChaoSentences);

                } catch (Exception e) {
                    singleSubscriber.onError(e);
                }
            }
        });
    }


    ValueEventListener mESlValueEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            List<EslDailyDto> list = new ArrayList<>();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                EslDailyDto post = postSnapshot.getValue(EslDailyDto.class);
                list.add(post);
            }
            subscriberEsl.onSuccess(list);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            subscriberEsl.onError(new Throwable(databaseError.getMessage()));
        }
    };


    ValueEventListener mEliteValueEventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            List<EliteDto> list = new ArrayList<>();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                EliteDto post = postSnapshot.getValue(EliteDto.class);
                list.add(post);
            }
            subscriberElite.onSuccess(list);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            subscriberElite.onError(new Exception((databaseError.toException())));
        }
    };


}
<file_sep>package son.nt.en;

import android.app.Application;
import android.content.Intent;

import son.nt.en.di.AppComponent;
import son.nt.en.di.AppModule;
import son.nt.en.di.DaggerAppComponent;
import son.nt.en.service.MusicService;

/**
 * Created by sonnt on 7/15/16.
 */
public class MyApplication extends Application
{
    AppComponent mAppComponent;

    @Override
    public void onCreate()
    {
        super.onCreate();
        dagger2();
        startService(new Intent(getApplicationContext(), MusicService.class));
    }

    @Override
    public void onTerminate()
    {
        super.onTerminate();
        stopService(new Intent(getApplicationContext(), MusicService.class));
    }

    private void dagger2()
    {
        mAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();

    }

    public AppComponent getAppComponent()
    {
        return mAppComponent;
    }
}
<file_sep>package son.nt.en.hellochao;

/**
 * Created by sonnt on 7/14/16.
 */
public class BusSentence {
    public BusSentence(int pos) {
        this.pos = pos;
    }

    public int pos;
}
<file_sep>package son.nt.en.elite;

import son.nt.en.base.IBasePresenter;

/**
 * Created by sonnt on 7/14/16.
 */
public interface ContractDailyElite {
    interface View {

    }

    interface Presenter extends IBasePresenter
    {

    }

    interface Repository {

        void getData();
    }
}
<file_sep>package son.nt.en.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

/**
 * Created by sonnt on 8/15/16.
 */
public abstract class BaseInjectActivity extends BaseActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        injectPresenter();

    }

    abstract public void injectPresenter ();

}
<file_sep>package son.nt.en.feed.di;

import com.google.firebase.database.DatabaseReference;

import dagger.Module;
import dagger.Provides;
import son.nt.en.di.scoped.ActivityScoped;
import son.nt.en.feed.FeedContract;
import son.nt.en.feed.FeedPresenter;
import son.nt.en.feed.FeedRepository;
import son.nt.en.utils.CompositeSubs;

/**
 * Created by sonnt on 8/15/16.
 * This module is used to create {@link son.nt.en.feed.FeedPresenter}
 */
@Module
public class FeedPresenterModule
{
    private FeedContract.View mView;

    public FeedPresenterModule(FeedContract.View mView)
    {
        this.mView = mView;
    }

    @Provides
    @ActivityScoped
    FeedContract.View provideView ()
    {
        return mView;
    }


    @Provides
    @ActivityScoped
    FeedContract.IRepository provideRepository (DatabaseReference databaseReference)
    {
        return new FeedRepository(databaseReference);
    }

    @Provides
    @ActivityScoped
    CompositeSubs provideCompositeSubs ()
    {
        return new CompositeSubs();
    }

    @Provides
    @ActivityScoped
    FeedContract.Presenter providePresenter (FeedContract.IRepository repository, FeedContract.View view, CompositeSubs compositeSubs) {
        return new FeedPresenter(repository, view, compositeSubs);
    }
}
<file_sep>package son.nt.en.esl;

import android.text.TextUtils;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.List;

import rx.Observer;
import son.nt.en.FireBaseConstant;
import son.nt.en.utils.Logger;

/**
 * Created by sonnt on 7/29/16.
 */
public class FireBaseRepository implements EslDailyContract.IRepository
{

    public static final String  TAG   = FireBaseRepository.class.getSimpleName();

    DatabaseReference           mDatabaseReference;
    List<EslDailyDto>           mList = new ArrayList<>();

    Observer<List<EslDailyDto>> observer;

    public FireBaseRepository(DatabaseReference mDatabaseReference)
    {
        this.mDatabaseReference = mDatabaseReference;
    }

    @Override
    public void getData(Observer<List<EslDailyDto>> callback)
    {
        mDatabaseReference.child(FireBaseConstant.TABLE_ESL_DAILY).addValueEventListener(valueEventListener);
        this.observer = callback;
    }

    ValueEventListener valueEventListener = new ValueEventListener()
    {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot)
        {
            mList.clear();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren())
            {
                EslDailyDto post = postSnapshot.getValue(EslDailyDto.class);
                mList.add(post);

            }

            /**
             * get result at {@link EslDailyPresenter#observer}
             */

            observer.onNext(mList);
        }

        @Override
        public void onCancelled(DatabaseError databaseError)
        {
            observer.onError(new Throwable(databaseError.toException()));

        }
    };

    @Override
    public void doSearch4(String keyword, Observer<List<EslDailyDto>> callback)
    {
        Logger.debug(TAG, ">>>" + "doSearch4:" + keyword + ";mList:" + mList.size());
        if (TextUtils.isEmpty(keyword))
        {
            callback.onNext(mList);
            return;
        }

        //search
        List<EslDailyDto> list = new ArrayList<>();
        for (EslDailyDto d : mList)
        {
            if (d.getHomeTitle().toLowerCase().contains(keyword.toLowerCase())
                            || d.getHomeDescription().toLowerCase().contains(keyword.toLowerCase()))
            {
                list.add(d);

            }

        }
        callback.onNext(list);
    }

    @Override
    public List<EslDailyDto> doSearch3(String keyword) {
        if (TextUtils.isEmpty(keyword))
        {
            return mList;
        }

        //search
        List<EslDailyDto> list = new ArrayList<>();
        for (EslDailyDto d : mList)
        {
            if (d.getHomeTitle().toLowerCase().contains(keyword.toLowerCase())
                    || d.getHomeDescription().toLowerCase().contains(keyword.toLowerCase()))
            {
                list.add(d);

            }

        }
        return list;
    }
}
<file_sep>package son.nt.en.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by sonnt on 7/14/16.
 */
public class DataTimesUtil
{
    private static final int SECOND_MILLIS = 1000;
    private static final int MINUTE_MILLIS = 60 * SECOND_MILLIS;
    private static final int HOUR_MILLIS   = 60 * MINUTE_MILLIS;
    private static final int DAY_MILLIS    = 24 * HOUR_MILLIS;

    public static String getTimeAgo(long time)
    {
        if (time < 1000000000000L)
        {
            // if timestamp given in seconds, convert to millis
            time *= 1000;
        }

        long now = System.currentTimeMillis();
        if (time > now || time <= 0)
        {
            return null;
        }

        // TODO: localize
        final long diff = now - time;
        if (diff < MINUTE_MILLIS)
        {
            return "just now";
        }
        else if (diff < 2 * MINUTE_MILLIS)
        {
            return "a minute ago";
        }
        else if (diff < 50 * MINUTE_MILLIS)
        {
            return diff / MINUTE_MILLIS + " minutes ago";
        }
        else if (diff < 90 * MINUTE_MILLIS)
        {
            return "an hour ago";
        }
        else if (diff < 24 * HOUR_MILLIS)
        {
            return diff / HOUR_MILLIS + " hours ago";
        }
        else if (diff < 48 * HOUR_MILLIS)
        {
            return "yesterday";
        }
        else
        {
            return diff / DAY_MILLIS + " days ago";
        }
    }

    public static long convertDateToMilliseconds(String fromFormat, String sourceDate)
    {
        try
        {
            SimpleDateFormat sdfFrom = new SimpleDateFormat(fromFormat);
            //SimpleDateFormat sdfTo = new SimpleDateFormat(toFormat);

            Date date = sdfFrom.parse(sourceDate);
            //String convertedDate = sdfTo.format(date);

            return date.getTime();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return 0L;

    }
}
<file_sep>package son.nt.en.home;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

import son.nt.en.base.BaseFragment;

/**
 * Created by sonnt on 7/11/16.
 */
public class HomeAdapter extends FragmentPagerAdapter {

    private List<BaseFragment> mFragments;

    public HomeAdapter(FragmentManager fm) {
        super(fm);
    }

    public HomeAdapter (FragmentManager fm, List<BaseFragment> mFragments)
    {
        super(fm);
        this.mFragments = mFragments;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments == null ? 0 : mFragments.size();
    }

    public void addFragment(BaseFragment fragment) {
        mFragments.add(fragment);
        notifyDataSetChanged();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return "Page " + position;
    }
}
<file_sep>package son.nt.en.elite;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import android.widget.ProgressBar;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;
import com.squareup.otto.Subscribe;

import org.parceler.Parcels;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import son.nt.en.FireBaseConstant;
import son.nt.en.MyApplication;
import son.nt.en.R;
import son.nt.en.base.BaseInjectActivity;
import son.nt.en.elite.content.EliteContentActivity;
import son.nt.en.elite.di.DaggerEliteComponent;
import son.nt.en.elite.di.ElitePresenterModule;
import son.nt.en.otto.OttoBus;
import son.nt.en.utils.Logger;

public class EliteDailyActivity extends BaseInjectActivity implements ContractDailyElite.View
{
    public static final String TAG = EliteDailyActivity.class.getSimpleName();
    private GridLayoutManager  mLinearLayoutManager;

    @BindView(R.id.CoordinatorLayoutChat)
    CoordinatorLayout          mCoordinatorLayout;

    @BindView(R.id.progressBar) ProgressBar mProgressBar;
    @BindView(R.id.messageRecyclerView) RecyclerView mMessageRecyclerView;

    @Inject DatabaseReference          mFirebaseDatabaseReference;

    private AdapterEliteDaily  mAdapter;

    @Inject
    EliteDailyPresenter        mPresenter;



    @Override
    public void injectPresenter()
    {
        //inject
        DaggerEliteComponent.builder().elitePresenterModule(new ElitePresenterModule(this))//
                .appComponent(((MyApplication)getApplication()).getAppComponent())
                .build()//
                .inject(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        OttoBus.register(this);
        setContentView(R.layout.activity_elite_daily);
        ButterKnife.bind(this);

        getSupportActionBar().setTitle("Reading");
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mLinearLayoutManager = new GridLayoutManager(this, 1);
        mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
        mAdapter = new AdapterEliteDaily(this);

        //        mProgressBar.setVisibility(ProgressBar.INVISIBLE);
        // New child entries
//        mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
        mFirebaseDatabaseReference.child(FireBaseConstant.TABLE_ELITE_DAILY).addValueEventListener(valueEventListener);

        mMessageRecyclerView.setAdapter(mAdapter);

        mPresenter.onStart();
    }

    @Override
    protected void onDestroy()
    {
        OttoBus.unRegister(this);
        super.onDestroy();
    }

    ValueEventListener valueEventListener = new ValueEventListener()
    {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot)
        {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            List<EliteDto> list = new ArrayList<>();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren())
            {
                EliteDto post = postSnapshot.getValue(EliteDto.class);
                list.add(post);
            }
            Logger.debug(TAG, ">>>" + "list:" + list.size());

            mAdapter.setData(list);
            mMessageRecyclerView.scrollToPosition(0);
        }

        @Override
        public void onCancelled(DatabaseError databaseError)
        {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);

        }
    };

    @Subscribe
    public void getClick(BusElite busElite)
    {
        EliteDto eliteDto = mAdapter.mValues.get(busElite.pos);
        Intent intent = new Intent(this, EliteContentActivity.class);
        intent.putExtra("data", Parcels.wrap(eliteDto));
        startActivity(intent);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        if (item.getItemId() == android.R.id.home)
        {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
<file_sep>package son.nt.en.chat;

import android.support.annotation.NonNull;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;

/**
 * Created by sonnt on 7/13/16.
 */
public class ChatPresenter implements ChatContract.Presenter
{
    private ChatContract.View mView;
    private FirebaseAuth      mFirebaseAuth;
    private DatabaseReference mDatabaseReference;

    public ChatPresenter(@NonNull ChatContract.View view, @NonNull FirebaseAuth mFirebaseAuth,
                    @NonNull DatabaseReference mDatabaseReference)
    {
        this.mView = view;
        this.mFirebaseAuth = mFirebaseAuth;
        this.mDatabaseReference = mDatabaseReference;
    }

    @Override
    public void onStart()
    {

    }

    @Override
    public void sendMessage(String s)
    {
        final FirebaseUser currentUser = mFirebaseAuth.getCurrentUser();
        if (currentUser == null)
        {
            mView.userDoNotLogin(s);
            return;
        }

        //        FriendlyMessage friendlyMessage = new FriendlyMessage(s, currentUser.getDisplayName(),
        //                        currentUser.getPhotoUrl() != null ? currentUser.getPhotoUrl().toString() : "");

        FriendlyMessage friendlyMessage = new FriendlyMessage(currentUser.getUid(), s, currentUser.getDisplayName(),
                        currentUser.getPhotoUrl() != null ? currentUser.getPhotoUrl().toString() : "",
                        System.currentTimeMillis());
        mDatabaseReference.child(ChatFragment.MESSAGES_CHILD).push().setValue(friendlyMessage)
                        .addOnCompleteListener(new OnCompleteListener<Void>()
                        {
                            @Override
                            public void onComplete(@NonNull Task<Void> task)
                            {
                                mView.clearMessage("");
                            }
                        }).addOnFailureListener(new OnFailureListener()
                        {
                            @Override
                            public void onFailure(@NonNull Exception e)
                            {
                            }
                        });

    }
}
<file_sep>package son.nt.en.elite;

/**
 * Created by sonnt on 7/20/16.
 */
public class EliteContentDto {
    public String id;
    public String content;

    public EliteContentDto() {
    }

    public EliteContentDto(String id, String content) {
        this.id = id;
        this.content = content;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
<file_sep>package son.nt.en.hellochao;

import java.util.List;

import son.nt.en.base.IAudioFile;

/**
 * Created by sonnt on 7/14/16.
 */
public class HelloChaoSentences implements IAudioFile
{
    public String text;
    public String audio;
    public String translate;

    public HelloChaoSentences() {
    }

    public HelloChaoSentences(String text, String audio, String translate) {
        this.text = text;
        this.audio = audio;
        this.translate = translate;
    }

    public String getText() {
        return text;
    }

    public String getAudio() {
        return audio;
    }

    public String getTranslate() {
        return translate;
    }

    @Override
    public String getTitle() {
        return text;
    }

    @Override
    public String getLinkMp3() {
        return audio;
    }

    @Override
    public String getImage() {
        return null;
    }

    @Override
    public String getDescription() {
        return translate;
    }

    @Override
    public List<String> getGroup() {
        return null;
    }

    @Override
    public Long getDuration() {
        return null;
    }

    @Override
    public List<String> getTags() {
        return null;
    }
}
<file_sep>package son.nt.en.esl;

import java.util.List;

import rx.Observer;
import son.nt.en.base.IBasePresenter;

/**
 * Created by sonnt on 7/14/16.
 */
public interface EslDailyContract
{
    interface View
    {

        void resultSearch(List<EslDailyDto> mList);

        void setVisibility(boolean b);
    }

    interface Presenter extends IBasePresenter
    {

        void onDestroy();

        void afterTextChanged(String s);
    }

    interface IRepository
    {
        void getData(Observer<List<EslDailyDto>> callback);

        void doSearch4(String s, Observer<List<EslDailyDto>> callback);

        List<EslDailyDto> doSearch3(String filter);
    }
}
<file_sep>package son.nt.en.service;

/**
 * Created by sonnt on 5/26/16.
 */
public class GoPlayer {
    public static final int DO_PLAY = 1;
    public static final int DO_PAUSE = 2;
    public int command;
    public int pos;
    public String title;
    public String des;
    public String image;

    public GoPlayer(int command) {
        this.command = command;
    }

    public GoPlayer(int command, int pos) {
        this.command = command;
        this.pos = pos;
    }

    public GoPlayer(int command, String title, String des, String image) {
        this.command = command;
        this.title = title;
        this.des = des;
        this.image = image;
    }
}
<file_sep>apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'


android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "son.nt.en"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"

    // Google
    compile 'com.google.android.gms:play-services-auth:9.0.0'
    compile 'com.google.firebase:firebase-database:9.0.0'
    compile 'com.google.firebase:firebase-auth:9.0.0'
    compile 'com.google.firebase:firebase-config:9.0.0'
    compile 'com.google.android.gms:play-services-appinvite:9.0.0'
    compile 'com.google.firebase:firebase-messaging:9.0.0'
    compile 'com.google.android.gms:play-services-ads:9.0.0'
    compile 'com.google.firebase:firebase-crash:9.0.0'
    // Firebase UI
    compile 'com.firebaseui:firebase-ui-database:0.4.0'

    compile 'com.github.bumptech.glide:glide:3.6.1'

    compile 'com.jakewharton:butterknife:8.2.1'
    apt 'com.jakewharton:butterknife-compiler:8.2.1'
    compile 'de.hdodenhof:circleimageview:1.3.0'

    compile 'com.squareup:otto:1.3.8'

    compile 'org.jsoup:jsoup:1.9.2'

    compile 'org.parceler:parceler-api:1.1.5'
    apt 'org.parceler:parceler:1.1.5'

    compile 'io.reactivex:rxandroid:1.2.0'
    compile 'io.reactivex:rxjava:1.1.5'

    //flex-box
    compile 'com.google.android:flexbox:0.2.3'

    //test
    testCompile 'org.mockito:mockito-all:1.10.19'

    //dagger 2
    apt 'com.google.dagger:dagger-compiler:2.0'
    compile 'com.google.dagger:dagger:2.0'
    provided 'javax.annotation:jsr250-api:1.0'



}
<file_sep>package son.nt.en.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import son.nt.en.R;

/**
 * Created by sonnt on 8/11/16.
 */
public class Dagger2Activity extends AppCompatActivity implements View.OnClickListener {

    public static final String TAG = Dagger2Activity.class.getSimpleName();
    @BindView(R.id.btn1)
    Button btn1;
    @BindView(R.id.btn2)
    TextView btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dagger2);
        ButterKnife.bind(this);
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn1: {
                break;
            }
            case R.id.btn2: {
                break;
            }
        }
    }


}
<file_sep>package son.nt.en.hellochao;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.lang.ref.WeakReference;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import son.nt.en.R;
import son.nt.en.otto.OttoBus;

/**
 * Created by Sonnt on 7/7/15.
 */
public class AdapterHelloChao extends RecyclerView.Adapter<AdapterHelloChao.ViewHolder>
{

    private static final String          TAG      = AdapterHelloChao.class.getSimpleName();
    public List<HelloChaoSentences>      mValues;
    Context                              context;
    private final WeakReference<Context> contextWeakReference;

    private int                          previous = 0;

    public AdapterHelloChao(Context cx)
    {
        this.context = cx;
        this.contextWeakReference = new WeakReference<>(cx);
    }

    public void setData(List<HelloChaoSentences> mValues)
    {
        this.mValues = mValues;
        notifyDataSetChanged();
    }

    public HelloChaoSentences getItem(int position)
    {
        return mValues.get(position);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i)
    {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_hello_chao, viewGroup,
                        false);
        return new ViewHolder(view);
    }

//    public void setNewPos(int pos)
//    {
//        mValues.get(previous).setPlaying(false);
//        notifyItemChanged(previous);
//        mValues.get(pos).setPlaying(true);
//        notifyItemChanged(pos);
//
//        previous = pos;
//    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position)
    {
        HelloChaoSentences HelloChaoSentences = mValues.get(position);
        final HelloChaoSentences dto = HelloChaoSentences;

        String no = String.valueOf(position).trim();
        if (no.length() == 1)
        {
            no = no + "  ";
        }
        else if (no.length() == 2)
        {
            no = no + " ";
        }
        viewHolder.createdTimeTextView.setText(no);


        viewHolder.messageTextView.setText(dto.text);
        viewHolder.messengerTextView.setText(dto.translate);

//        if (HelloChaoSentences.isPlaying())
//        {
//            viewHolder.view.setBackgroundResource(R.drawable.d_row_speaking);
//            viewHolder.imageView.setVisibility(View.VISIBLE);
//        }
//        else
//        {
//            viewHolder.imageView.setVisibility(View.GONE);
//            viewHolder.view.setBackgroundResource(android.R.color.transparent);
//        }

//        Glide.with(context).load(HelloChaoSentences.getImage()).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL)
//                        .into(viewHolder.imageGroup);

    }

    @Override
    public int getItemCount()
    {
        return mValues == null ? 0 : mValues.size();
    }

//    public static class ViewHolder extends RecyclerView.ViewHolder
//    {
//        ImageView imageView;
//        ImageView imageGroup;
//        TextView  txtName;
//        View      view;
//        TextView  txtNo;
//
//        public ViewHolder(View itemView)
//        {
//            super(itemView);
//            this.view = itemView.findViewById(R.id.row_voice_main);
//            this.imageView = (ImageView) itemView.findViewById(R.id.row_voice_playing);
//            this.imageGroup = (ImageView) itemView.findViewById(R.id.row_voice_rival);
//            this.txtName = (TextView) itemView.findViewById(R.id.row_voice_text);
//            txtNo = (TextView) itemView.findViewById(R.id.row_voice_no);
//
//            this.view.setOnClickListener(new View.OnClickListener()
//            {
//                @Override
//                public void onClick(View v)
//                {
//                    /**
//                     * @see MusicPackDetailsActivity#itemClick(GoAdapterHelloChao)
//                     */
//                    OttoBus.post(new GoAdapterHelloChao(getAdapterPosition()));
//
//                }
//            });
//
//        }
//    }
    public static class ViewHolder extends RecyclerView.ViewHolder
    {
        public TextView        messageTextView;
        public TextView        messengerTextView;
        public TextView        createdTimeTextView;
        public CircleImageView messengerImageView;
        public CircleImageView levelImageView;

        public ViewHolder(View v)
        {
            super(v);
            messageTextView = (TextView) itemView.findViewById(R.id.messageTextView);
            messengerTextView = (TextView) itemView.findViewById(R.id.messengerTextView);
            createdTimeTextView = (TextView) itemView.findViewById(R.id.createdTimeTextView);
            messengerImageView = (CircleImageView) itemView.findViewById(R.id.messengerImageView);
            levelImageView = (CircleImageView) itemView.findViewById(R.id.levelImageView);
            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    OttoBus.post(new BusSentence(getAdapterPosition()));

                }
            });
        }
    }
}
<file_sep>package son.nt.en.chat;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.firebase.ui.database.FirebaseRecyclerAdapter;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;
import son.nt.en.R;
import son.nt.en.base.BaseFragment;
import son.nt.en.login.LoginActivity;
import son.nt.en.utils.DataTimesUtil;
import son.nt.en.utils.Logger;

/**
 * Created by sonnt on 7/11/16.
 */
public class ChatFragment extends BaseFragment implements ChatContract.View
{

    public static final String                                          FRIENDLY_MSG_LENGTH      = "friendly_msg_length";
    public static final int                                             REQUEST_LOGIN            = 1000;
    private static final String                                         TAG                      = ChatFragment.class
                    .getSimpleName();
    // Firebase instance variables
    private DatabaseReference                                           mFirebaseDatabaseReference;
    private FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder> mFirebaseAdapter;

    public static final String                                          MESSAGES_CHILD           = "messages";
    private static final int                                            REQUEST_INVITE           = 1;
    public static final int                                             DEFAULT_MSG_LENGTH_LIMIT = 10;
    public static final String                                          ANONYMOUS                = "anonymous";
    private static final String                                         MESSAGE_SENT_EVENT       = "message_sent";
    private String                                                      mUsername;
    private String                                                      mPhotoUrl;
    private SharedPreferences                                           mSharedPreferences;
    private GoogleApiClient                                             mGoogleApiClient;

    private Button                                                      mSendButton;
    private RecyclerView                                                mMessageRecyclerView;
    private LinearLayoutManager                                         mLinearLayoutManager;
    private ProgressBar                                                 mProgressBar;
    private EditText                                                    mMessageEditText;

    @BindView(R.id.CoordinatorLayoutChat)
    CoordinatorLayout                                                   mCoordinatorLayout;

    private ChatContract.Presenter                                      mPresenter;

    public static ChatFragment newInstance()
    {
        ChatFragment f = new ChatFragment();
        return f;
    }

    public static class MessageViewHolder extends RecyclerView.ViewHolder
    {
        public TextView        messageTextView;
        public TextView        messengerTextView;
        public TextView        createdTimeTextView;
        public CircleImageView messengerImageView;
        public CircleImageView levelImageView;

        public MessageViewHolder(View v)
        {
            super(v);
            messageTextView = (TextView) itemView.findViewById(R.id.messageTextView);
            messengerTextView = (TextView) itemView.findViewById(R.id.messengerTextView);
            createdTimeTextView = (TextView) itemView.findViewById(R.id.createdTimeTextView);
            messengerImageView = (CircleImageView) itemView.findViewById(R.id.messengerImageView);
            levelImageView = (CircleImageView) itemView.findViewById(R.id.levelImageView);
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        mPresenter = new ChatPresenter(this, FirebaseAuth.getInstance(), FirebaseDatabase.getInstance().getReference());
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                    @Nullable Bundle savedInstanceState)
    {
        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
        View view = inflater.inflate(R.layout.fragment_chat, container, false);
        ButterKnife.bind(this, view);
        // Initialize ProgressBar and RecyclerView.
        mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
        mMessageRecyclerView = (RecyclerView) view.findViewById(R.id.messageRecyclerView);
        mLinearLayoutManager = new LinearLayoutManager(getActivity());
        mLinearLayoutManager.setStackFromEnd(true);
        mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);

        //        mProgressBar.setVisibility(ProgressBar.INVISIBLE);
        // New child entries
        mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
        mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class,
                        R.layout.row_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD))
        {

            @Override
            protected void populateViewHolder(MessageViewHolder viewHolder, FriendlyMessage friendlyMessage,
                            int position)
            {
                mProgressBar.setVisibility(ProgressBar.INVISIBLE);
                viewHolder.messageTextView.setText(friendlyMessage.getText());
                viewHolder.messengerTextView.setText(friendlyMessage.getName());
                viewHolder.createdTimeTextView.setText(friendlyMessage.getCreatedTime() == null ? "Once upon a time"
                                : DataTimesUtil.getTimeAgo(friendlyMessage.getCreatedTime()));

                if (friendlyMessage.getPhotoUrl() == null)
                {
                    viewHolder.messengerImageView.setImageDrawable(
                                    ContextCompat.getDrawable(getContext(), R.drawable.ic_account_circle_black_36dp));
                }
                else
                {
                    Glide.with(getContext()).load(friendlyMessage.getPhotoUrl()).into(viewHolder.messengerImageView);
                }
                Glide.with(getContext()).load("http://Img.softnyx.net/1/gb/about/rank_1.gif")
                                .diskCacheStrategy(DiskCacheStrategy.ALL).into(viewHolder.levelImageView);

            }
        };

        mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver()
        {
            @Override
            public void onItemRangeInserted(int positionStart, int itemCount)
            {
                super.onItemRangeInserted(positionStart, itemCount);
                int friendlyMessageCount = mFirebaseAdapter.getItemCount();
                int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
                // If the recycler view is initially being loaded or the
                //œ user is at the bottom of the list, scroll to the bottom
                // of the list to show the newly added message.
                if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1)
                                && lastVisiblePosition == (positionStart - 1)))
                {
                    mMessageRecyclerView.scrollToPosition(positionStart);
                }
            }
        });

        mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
        mMessageRecyclerView.setAdapter(mFirebaseAdapter);

        mMessageEditText = (EditText) view.findViewById(R.id.messageEditText);
        //        mMessageEditText.setFilters(new InputFilter[]
        //        { new InputFilter.LengthFilter(mSharedPreferences.getInt(FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) });
        mMessageEditText.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
            {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
            {
                if (charSequence.toString().trim().length() > 0)
                {
                    mSendButton.setEnabled(true);
                }
                else
                {
                    mSendButton.setEnabled(false);
                }
            }

            @Override
            public void afterTextChanged(Editable editable)
            {
            }
        });

        mSendButton = (Button) view.findViewById(R.id.sendButton);
        mSendButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                mPresenter.sendMessage(mMessageEditText.getText().toString());
                //
                //                FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername,
                //                                mPhotoUrl);
                //                mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(friendlyMessage)
                //                                .addOnFailureListener(new OnFailureListener()
                //                                {
                //                                    @Override
                //                                    public void onFailure(@NonNull Exception e)
                //                                    {
                //                                        Logger.debug(TAG, ">>>" + "onFailure:" + e.toString());
                //                                    }
                //                                });
                //                mMessageEditText.setText("");
            }
        });

        return view;
    }

    @Override
    public void onResume()
    {
        super.onResume();
        mPresenter.onStart();
    }

    @Override
    public void userDoNotLogin(String s)
    {
        Snackbar.make(mSendButton, "Please login first", Snackbar.LENGTH_LONG)
                        .setAction("Login", new View.OnClickListener()
                        {
                            @Override
                            public void onClick(View v)
                            {
                                startActivityForResult(new Intent(getActivity(), LoginActivity.class), REQUEST_LOGIN);

                            }
                        }).show();

    }

    @Override
    public void clearMessage(String s)
    {
        mMessageEditText.setText(s);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK)
        {
            switch (requestCode)
            {
                case REQUEST_LOGIN:
                {
                    Logger.debug(TAG, ">>>" + "onActivityResult REQUEST_LOGIN");
                    mPresenter.sendMessage(mMessageEditText.getText().toString());
                    break;
                }
            }
        }
    }
}
<file_sep>package son.nt.en.google_client_api;

import dagger.Component;
import son.nt.en.HomeActivity;
import son.nt.en.di.scoped.ActivityScoped;
import son.nt.en.firebase.FireBaseModule;
import son.nt.en.login.LoginActivity;

/**
 * Created by sonnt on 8/20/16.
 */
@ActivityScoped
@Component(modules = {GoogleApiClientModule.class, FireBaseModule.class})
public interface GoogleApiComponent {
    void inject(LoginActivity loginActivity);
    void inject(HomeActivity loginActivity);

}
<file_sep>package son.nt.en.esl;

import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.otto.Subscribe;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import son.nt.en.R;
import son.nt.en.base.BaseFragment;
import son.nt.en.otto.OttoBus;
import son.nt.en.service.GoPlayer;
import son.nt.en.service.MusicService;

/**
 * Created by sonnt on 7/15/16.
 */
public class EslDaiLyFragment extends BaseFragment implements View.OnClickListener, TextWatcher, EslDailyContract.View
{
    public static final String TAG    = EslDaiLyFragment.class.getSimpleName();
    private RecyclerView       mMessageRecyclerView;
    private ProgressBar        mProgressBar;

    @BindView(R.id.CoordinatorLayoutChat)
    CoordinatorLayout          mCoordinatorLayout;

    @BindView(R.id.txt_search)
    EditText                   txtSearch;
    @BindView(R.id.btn_clear)
    View                       btnClear;

    private AdapterEslDaily    mAdapter;

    boolean                    isBind = false;

    MusicService               mPlayService;

    EslDailyContract.Presenter mPresenter;

    @BindView(R.id.player_play)
    ImageView                  mImgPlay;
    @BindView(R.id.img_track)
    ImageView                  mImgTrack;

    @BindView(R.id.txt_title)
    TextView                   mTxtTitle;

    @BindView(R.id.txt_des)
    TextView                   mTxtDes;

    public static EslDaiLyFragment newInstace()
    {
        EslDaiLyFragment f = new EslDaiLyFragment();
        return f;

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        OttoBus.register(this);

        MusicService.bindToMe(getContext(), serviceConnectionPlayer);

        final FireBaseRepository repo = new FireBaseRepository(FirebaseDatabase.getInstance().getReference());
        mPresenter = new EslDailyPresenter(this, repo);

        mPresenter.onStart();

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                    @Nullable Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.fragment_hello_chao, container, false);
        ButterKnife.bind(this, view);
        // Initialize ProgressBar and RecyclerView.
        mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar);
        mMessageRecyclerView = (RecyclerView) view.findViewById(R.id.messageRecyclerView);
        GridLayoutManager mLinearLayoutManager = new GridLayoutManager(getActivity(), 1);
        //        mLinearLayoutManager.setStackFromEnd(true);
        mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
        mAdapter = new AdapterEslDaily(getActivity());

        mMessageRecyclerView.setAdapter(mAdapter);

        //search
        btnClear.setOnClickListener(this);
        txtSearch.addTextChangedListener(this);
        mImgPlay.setOnClickListener(this);
        return view;
    }

    @Override
    public void onDestroy()
    {
        OttoBus.unRegister(this);
        getActivity().unbindService(serviceConnectionPlayer);
        mPresenter.onDestroy();

        super.onDestroy();

    }

    ServiceConnection serviceConnectionPlayer = new ServiceConnection()
    {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service)
        {
            MusicService.LocalBinder localBinder = (MusicService.LocalBinder) service;
            mPlayService = localBinder.getService();
            isBind = true;
        }

        @Override
        public void onServiceDisconnected(ComponentName name)
        {
            isBind = false;
            mPlayService = null;
        }
    };

    /**
     * who calls this {@link son.nt.en.esl.AdapterEslDaily.ViewHolder#ViewHolder(View)}
     *
     * @param busSentence
     */

    @Subscribe
    public void getSelection(BusEsl busSentence)
    {
        if (mPlayService != null)
        {
            mPlayService.setDataToService(mAdapter.mValues);
            mPlayService.playAtPos(busSentence.pos);
        }
    }

    /**
     * called from {@link MusicService#play()}
     *
     * @param goPlayer
     */

    @Subscribe
    public void getControlFromService(GoPlayer goPlayer)
    {
        mTxtTitle.setText(goPlayer.title);
        mTxtDes.setText(goPlayer.des);
        mImgPlay.setImageResource(
                        goPlayer.command == GoPlayer.DO_PLAY ? R.drawable.icon_paused : R.drawable.icon_played);
        if (goPlayer.image != null)
        {
            Glide.with(this).load(goPlayer.image).fitCenter().into(mImgTrack);
        }

    }

    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
            case R.id.btn_clear:
            {
                txtSearch.setText("");
                break;
            }
            case R.id.player_play:
            {
                if (mPlayService != null)
                {
                    mPlayService.play();
                }
                break;
            }

        }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after)
    {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count)
    {

    }

    @Override
    public void afterTextChanged(Editable s)
    {
        mPresenter.afterTextChanged(s.toString());
    }

    @Override
    public void resultSearch(List<EslDailyDto> list)
    {
        mProgressBar.setVisibility(ProgressBar.INVISIBLE);
        mAdapter.setData(list);
        mMessageRecyclerView.scrollToPosition(0);

    }

    @Override
    public void setVisibility(boolean b)
    {
        btnClear.setVisibility(b ? View.VISIBLE : View.GONE);
    }
}
<file_sep>package son.nt.en.service;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.os.PowerManager;

import java.util.ArrayList;
import java.util.List;

import son.nt.en.base.IAudioFile;
import son.nt.en.otto.OttoBus;
import son.nt.en.service.notification.INotification;
import son.nt.en.service.notification.NotificationImpl;
import son.nt.en.utils.Logger;

public class MusicService extends Service
{
    INotification              iNotification;
    Playback                   iPlayback;

    public static final String TAG                    = "MusicService";
    public static final String ACTION_TOGGLE_PLAYBACK = "com.example.android.musicplayer.action.TOGGLE_PLAYBACK";
    public static final String ACTION_PLAY            = "com.example.android.musicplayer.action.PLAY";
    public static final String ACTION_PAUSE           = "com.example.android.musicplayer.action.PAUSE";
    public static final String ACTION_STOP            = "com.example.android.musicplayer.action.STOP";
    public static final String ACTION_SKIP            = "com.example.android.musicplayer.action.SKIP";
    public static final String ACTION_REWIND          = "com.example.android.musicplayer.action.REWIND";
    public static final String ACTION_URL             = "com.example.android.musicplayer.action.URL";




    public static Intent getService(Context context)
    {
        return new Intent(context, MusicService.class);
    }

    public static void bindToMe(Context context, ServiceConnection musicServiceConnection)
    {
        context.bindService(MusicService.getService(context), musicServiceConnection, Context.BIND_AUTO_CREATE);
    }

    public class LocalBinder extends Binder
    {

        public MusicService getService()
        {
            return MusicService.this;
        }

    }

    enum State
    {
        Fetching, Stopped, Playing, Paused, Preparing
    }

    State                     mState        = State.Stopped;

    LocalBinder               localBinder   = new LocalBinder();
    MediaPlayer               mediaPlayer;

    AudioManager              audioManager;

    boolean                   isStreaming;
    String                    songTitle;

    IAudioFile                currentItem;
    int                       currentPos    = 0;

    float                     currentVolume = 0.7f;

    List<IAudioFile>          listMusic     = new ArrayList<>();

    MusicPlayback.Callback    musicPlayBackCallback;

    public MusicService()
    {
        Logger.debug(TAG, ">>>" + "MusicService");

    }

    private void setupMediaPlayerIfNeeded()
    {
        Logger.debug(TAG, ">>>" + "setupMediaPlayerIfNeeded");
        if (mediaPlayer == null)
        {
            mediaPlayer = new MediaPlayer();
            mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);

            mediaPlayer.setOnPreparedListener(onPreparedListener);
            mediaPlayer.setOnCompletionListener(onCompletionListener);
            mediaPlayer.setOnErrorListener(onErrorListener);

        }
        else
        {
            mediaPlayer.reset();
        }
    }

    @Override
    public void onCreate()
    {
        super.onCreate();
        Logger.debug(TAG, ">>>" + "onCreate");
        audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

        iNotification = new NotificationImpl(this, this);

        IntentFilter filter = new IntentFilter();
        filter.addAction(NotificationImpl.ACTION_NEXT);
        filter.addAction(NotificationImpl.ACTION_PREV);
        filter.addAction(NotificationImpl.ACTION_PLAY);
        filter.addAction(NotificationImpl.ACTION_CLOSE);
        registerReceiver(receiver, filter);

    }

    @Override
    public void onDestroy()
    {
        unregisterReceiver(receiver);
        super.onDestroy();

    }


    public void processTogglePlayback()
    {
        if (mState == State.Paused || mState == State.Stopped)
        {
            processPlayRequest();
        }
        else
        {
            processPauseRequest();
        }

    }

    public void processPlayRequest()
    {
        Logger.debug(TAG, ">>>" + "processPlayRequest");
        if (mState == State.Stopped)
        {
            if (!listMusic.isEmpty() && currentItem != null)
            {
                currentItem = listMusic.get(currentPos);
                playNextSong(currentItem);
            }
        }
        else if (mState == State.Paused)
        {
            mState = State.Playing;
//            setupAsForeGroundCustom(currentItem);
            play();
        }

    }

    public void playAtPos(int pos)
    {
        currentPos = pos;
        if (!listMusic.isEmpty())
        {
            currentItem = listMusic.get(currentPos);
            playNextSong(currentItem);
            //            play();
        }

    }

    public void processPauseRequest()
    {
        Logger.debug(TAG, ">>>" + "processPauseRequest");
        if (mState == State.Playing)
        {
            mState = State.Paused;
            mediaPlayer.pause();
            relaxResource(false);
        }

    }

    public void processAddRequest(IAudioFile audioFile)
    {
        Logger.debug(TAG, ">>>" + "processAddRequest");
        listMusic.clear();
        currentPos = 0;
        this.currentItem = audioFile;

        playNextSong(audioFile);

    }

    public void playNextSong(IAudioFile currentItem)
    {
        String url = currentItem.getLinkMp3();
        Logger.debug(TAG, ">>>" + "playNextSong:" + url);
        if (musicPlayBackCallback != null)
        {
            musicPlayBackCallback.onPreparing(currentItem);
        }
        mState = State.Stopped;

        relaxResource(false);
        try
        {
            setupMediaPlayerIfNeeded();

            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.setDataSource(url);
            isStreaming = url.startsWith("http:") || url.startsWith("https:");

            songTitle = url;

            mState = State.Preparing;
//            setupAsForeGroundCustom(currentItem);

            /**
             * @see onPreparedListener
             */

            mediaPlayer.prepareAsync();

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }

    public void setDataToService(List<? extends IAudioFile> list)
    {
        Logger.debug(TAG, ">>>" + "setDataToService:" + list.size());
        if (list == null || list.size() == 0)
        {
            return;
        }

        this.listMusic.clear();
        this.listMusic.addAll(list);
        //        if (type == 1)
        //        {
        //
        //            this.listMusic.clear();
        //            this.listMusic.addAll(list);
        //        } else
        //        {
        //            this.listEsl.clear();
        //            this.listEsl.addAll(list);
        //        }
        currentPos = 0;
        currentItem = listMusic.get(currentPos);
        //        playNextSong(currentItem);

    }

    void relaxResource(boolean isReleaseMediaPlayer)
    {
        stopForeground(true);
        if (isReleaseMediaPlayer && mediaPlayer != null)
        {
            mediaPlayer.reset();
            mediaPlayer.release();
            mediaPlayer = null;
        }

    }

    public void play()
    {
        if (mediaPlayer.isPlaying())
        {
            iNotification.doPause();

            mediaPlayer.pause();
            OttoBus.post(new GoPlayer(GoPlayer.DO_PAUSE, currentItem.getTitle(), currentItem.getDescription(), currentItem.getImage()));
            return;
        }

        if (!mediaPlayer.isPlaying())
        {
            iNotification.doPlay();
            OttoBus.post(new GoPlayer(GoPlayer.DO_PLAY, currentItem.getTitle(), currentItem.getDescription(), currentItem.getImage()));
            mediaPlayer.start();
        }

    }

    @Override
    public IBinder onBind(Intent intent)
    {
        Logger.debug(TAG, ">>>" + "onBind");
        return localBinder;
    }

    MediaPlayer.OnPreparedListener   onPreparedListener   = new MediaPlayer.OnPreparedListener()
                                                          {
                                                              @Override
                                                              public void onPrepared(MediaPlayer mediaPlayer)
                                                              {
                                                                  Logger.debug(TAG, ">>>" + "onPrepared");
                                                                  if (musicPlayBackCallback != null)
                                                                  {
                                                                      musicPlayBackCallback.onPlaying(currentItem);
                                                                  }
                                                                  mState = State.Playing;

                                                                  iNotification.setData(currentItem);
                                                                  //                                                                  updateNotification(currentItem);
//                                                                  setupAsForeGroundCustom(currentItem);
                                                                  play();

                                                              }
                                                          };

    MediaPlayer.OnCompletionListener onCompletionListener = new MediaPlayer.OnCompletionListener()
                                                          {
                                                              @Override
                                                              public void onCompletion(MediaPlayer mediaPlayer)
                                                              {
                                                                  if (listMusic.isEmpty())
                                                                  {
                                                                      return;
                                                                  }
                                                                  currentPos++;
                                                                  if (currentPos == listMusic.size())
                                                                  {
                                                                      currentPos = 0;
                                                                  }
                                                                  currentItem = listMusic.get(currentPos);
                                                                  playNextSong(currentItem);

                                                              }
                                                          };
    MediaPlayer.OnErrorListener      onErrorListener      = new MediaPlayer.OnErrorListener()
                                                          {
                                                              @Override
                                                              public boolean onError(MediaPlayer mediaPlayer, int i,
                                                                              int i1)
                                                              {
                                                                  //                                                                  if (listMusic.isEmpty())
                                                                  //                                                                  {
                                                                  //                                                                      return false;
                                                                  //                                                                  }
                                                                  //                                                                  currentPos++;
                                                                  //                                                                  if (currentPos == listMusic.size())
                                                                  //                                                                  {
                                                                  //                                                                      currentPos = 0;
                                                                  //                                                                  }
                                                                  //                                                                  currentItem = listMusic.get(currentPos);
                                                                  //                                                                  playNextSong(currentItem);
                                                                  return true;
                                                              }
                                                          };

    public void setMusicPlayBackCallback(MusicPlayback.Callback cb)
    {
        this.musicPlayBackCallback = cb;
    }

    private final BroadcastReceiver receiver = new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context context, Intent intent)
        {
            String action = intent.getAction();
            if (action.equals(NotificationImpl.ACTION_PLAY))
            {
                play();
            }
            else if (action.equals(NotificationImpl.ACTION_NEXT))
            {

                playAtPos(currentPos ++);
            }
            else if (action.equals(NotificationImpl.ACTION_PREV))
            {
                playAtPos(currentPos --);
            }
            else if (action.equals(NotificationImpl.ACTION_CLOSE))
            {
                relaxResource(true);
//                if (mediaPlayer != null && mediaPlayer.isPlaying())
//                {
//                    mediaPlayer.stop();
//                    mediaPlayer.reset();
//                    mediaPlayer.release();
//                    mediaPlayer = null;
//                }
//               stopForeground(true);
            }
        }
    };


}
<file_sep>package son.nt.en.elite;

import org.parceler.Parcel;

/**
 * Created by sonnt on 7/20/16.
 */
@Parcel
public class EliteDto {
    public String id;
    public String title;
    public String image;
    public String linkDetail;
    public String des;
    public String authPic;
    public String authName;
    public long publishTime;
    public String content;


    public EliteDto() {
    }

    public EliteDto(String id, String title, String image, String linkDetail, String des, String authPic, String authName, long publishTime, String content) {
        this.id = id;
        this.title = title;
        this.image = image;
        this.linkDetail = linkDetail;
        this.des = des;
        this.authPic = authPic;
        this.authName = authName;
        this.publishTime = publishTime;
        this.content = content;
    }


}
<file_sep>package son.nt.en.elite.di;

import com.google.firebase.database.DatabaseReference;

import dagger.Module;
import dagger.Provides;
import son.nt.en.elite.ContractDailyElite;
import son.nt.en.elite.EliteRepository;

/**
 * Created by sonnt on 8/15/16.
 * This module is used to create {@link son.nt.en.elite.EliteDailyPresenter}
 */
@Module
public class ElitePresenterModule
{
    private ContractDailyElite.View mView;

    public ElitePresenterModule(ContractDailyElite.View mView)
    {
        this.mView = mView;
    }

    @Provides
    ContractDailyElite.View provideView ()
    {
        return mView;
    }

    @Provides
    ContractDailyElite.Repository provideRepository (DatabaseReference databaseReference)
    {
        return new EliteRepository(databaseReference);
    }
}
<file_sep>package son.nt.en.elite;

import com.google.firebase.database.DatabaseReference;

import javax.inject.Inject;

/**
 * Created by sonnt on 8/15/16.
 */
public class EliteRepository implements ContractDailyElite.Repository
{

    private DatabaseReference mDatabaseReference;

    @Inject
    public EliteRepository(DatabaseReference mDatabaseReference)
    {
        this.mDatabaseReference = mDatabaseReference;
    }

    @Override
    public void getData()
    {

    }
}
