// Path: app/src/main/java/com/architjn/audiobook/presenter/MainPresenter.java
// public class MainPresenter implements IMainPresenter {
//     private final Context context;
//     private final PrefUtils pref;
//     private MainInteractor interactor;
//     private IMainView view;
//     private ViewPager viewPager;
//     private AllAudioBookViewFragment allFrag;
//     private NewAudioBookFragment newFrag;
//     private OnGoingAudioBookFragment ongoingFrag;
//     private FinishedAudioBookFragment finishedFrag;
// 
//     public MainPresenter(Context context) {
//         this.view = (IMainView) context;
//         this.context = context;
//         this.interactor = new MainInteractor(context, this);
//         pref = PrefUtils.getInstance(context);
//         init();
//     }
// 
//     private void init() {
//         if (pref.getAudioBookFolderPath() == null) {
//             AlertDialog.Builder dialog = new AlertDialog.Builder(context);
//             dialog.setTitle(R.string.select_directory)
//                     .setMessage(R.string.select_directory_dialog_msg)
//                     .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
//                         @Override
//                         public void onClick(DialogInterface dialogInterface, int i) {
//                             if (view != null)
//                                 if (PermissionChecker.requestForPermission(context,
//                                         Manifest.permission.READ_EXTERNAL_STORAGE,
//                                         R.string.read_permission_request, MainActivity.READ_PERMISSION_REQUEST))
//                                     view.startFolderChooser();
//                         }
//                     })
//                     .create().show();
//         } else interactor.scanForNewAudioBooks();
//     }
// 
//     public void setupViewPager(ViewPager viewPager, FragmentManager supportFragmentManager) {
//         this.viewPager = viewPager;
//         allFrag = new AllAudioBookViewFragment();
//         newFrag = new NewAudioBookFragment();
//         ongoingFrag = new OnGoingAudioBookFragment();
//         finishedFrag = new FinishedAudioBookFragment();
//         ViewPagerAdapter adapter = new ViewPagerAdapter(context, supportFragmentManager);
//         adapter.addFragment(allFrag, R.string.all);
//         adapter.addFragment(newFrag, R.string.new_txt);
//         adapter.addFragment(ongoingFrag, R.string.ongoing);
//         adapter.addFragment(finishedFrag, R.string.finished);
//         viewPager.setAdapter(adapter);
//         viewPager.setCurrentItem(interactor.getPageWithSomeData());
//     }
// 
//     public void setTabLayout(TabLayout tabLayout) {
//         tabLayout.setupWithViewPager(viewPager);
//     }
// 
//     @Override
//     public void startFolderChooser() {
//         if (view != null)
//             view.startFolderChooser();
//     }
// 
//     @Override
//     public void onNewAudioBookLoaded() {
//         allFrag.updateBookList();
//         newFrag.updateBookList();
//     }
// 
//     public MainInteractor getInteractor() {
//         return interactor;
//     }
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/interfaces/IMainView.java
// public interface IMainView {
//     void startFolderChooser();
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/service/PlayerService.java
// public class PlayerService extends Service implements IPlayerService {
// 
//     private MediaPlayer mediaPlayer;
//     private boolean gotContent;
//     private PlayerInteractor interactor;
// 
//     @Nullable
//     @Override
//     public IBinder onBind(Intent intent) {
//         return null;
//     }
// 
//     @Override
//     public int onStartCommand(Intent intent, int flags, int startId) {
//         interactor = PlayerInteractor.getInstance(this);
//         interactor.setServiceListener(this);
//         mediaPlayer = new MediaPlayer();
//         gotContent = false;
//         return START_STICKY;
//     }
// 
//     @Override
//     public void setSource(BookChapter chapter) {
//         try {
//             gotContent = false;
//             mediaPlayer.reset();
//             mediaPlayer.setDataSource(chapter.getData());
//             gotContent = true;
//             mediaPlayer.prepare();
//             mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//                 @Override
//                 public void onCompletion(MediaPlayer mp) {
//                     if (interactor != null) {
//                         changeAudioFile(interactor.getNextChapter());
//                     }
//                 }
//             });
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     private void changeAudioFile(BookChapter nextChapter) {
//         try {
//             if (mediaPlayer != null && nextChapter != null) {
//                 mediaPlayer.reset();
//                 mediaPlayer.setDataSource(nextChapter.getData());
//                 interactor.askToPlay();
//             }
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public int play() {
//         if (mediaPlayer != null && gotContent) {
//             if (!mediaPlayer.isPlaying()) {
//                 mediaPlayer.start();
//                 interactor.setStatus(PLAYING);
//             } else if (mediaPlayer != null) {
//                 mediaPlayer.pause();
//                 interactor.setStatus(PAUSED);
//             }
//             return mediaPlayer.getCurrentPosition();
//         }
//         return -1;
//     }
// 
//     @Override
//     public void onSeekChange(int progress) {
//         if (mediaPlayer != null && gotContent)
//             mediaPlayer.seekTo(progress);
//     }
// }


import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.content.PermissionChecker;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import com.architjn.audiobook.R;
import com.architjn.audiobook.presenter.MainPresenter;
import com.architjn.audiobook.interfaces.IMainView;
import com.architjn.audiobook.service.PlayerService;
import butterknife.BindView;
import butterknife.ButterKnife;
package com.architjn.audiobook.ui.activity;




public class MainActivity extends AppCompatActivity implements IMainView {

    private static final int FOLDER_CHOOSER = 3231;
    public static final int READ_PERMISSION_REQUEST = 7766;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    @BindView(R.id.tabs)
    TabLayout tabLayout;
// Path: app/src/main/java/com/architjn/audiobook/presenter/MainPresenter.java
// public class MainPresenter implements IMainPresenter {
//     private final Context context;
//     private final PrefUtils pref;
//     private MainInteractor interactor;
//     private IMainView view;
//     private ViewPager viewPager;
//     private AllAudioBookViewFragment allFrag;
//     private NewAudioBookFragment newFrag;
//     private OnGoingAudioBookFragment ongoingFrag;
//     private FinishedAudioBookFragment finishedFrag;
// 
//     public MainPresenter(Context context) {
//         this.view = (IMainView) context;
//         this.context = context;
//         this.interactor = new MainInteractor(context, this);
//         pref = PrefUtils.getInstance(context);
//         init();
//     }
// 
//     private void init() {
//         if (pref.getAudioBookFolderPath() == null) {
//             AlertDialog.Builder dialog = new AlertDialog.Builder(context);
//             dialog.setTitle(R.string.select_directory)
//                     .setMessage(R.string.select_directory_dialog_msg)
//                     .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
//                         @Override
//                         public void onClick(DialogInterface dialogInterface, int i) {
//                             if (view != null)
//                                 if (PermissionChecker.requestForPermission(context,
//                                         Manifest.permission.READ_EXTERNAL_STORAGE,
//                                         R.string.read_permission_request, MainActivity.READ_PERMISSION_REQUEST))
//                                     view.startFolderChooser();
//                         }
//                     })
//                     .create().show();
//         } else interactor.scanForNewAudioBooks();
//     }
// 
//     public void setupViewPager(ViewPager viewPager, FragmentManager supportFragmentManager) {
//         this.viewPager = viewPager;
//         allFrag = new AllAudioBookViewFragment();
//         newFrag = new NewAudioBookFragment();
//         ongoingFrag = new OnGoingAudioBookFragment();
//         finishedFrag = new FinishedAudioBookFragment();
//         ViewPagerAdapter adapter = new ViewPagerAdapter(context, supportFragmentManager);
//         adapter.addFragment(allFrag, R.string.all);
//         adapter.addFragment(newFrag, R.string.new_txt);
//         adapter.addFragment(ongoingFrag, R.string.ongoing);
//         adapter.addFragment(finishedFrag, R.string.finished);
//         viewPager.setAdapter(adapter);
//         viewPager.setCurrentItem(interactor.getPageWithSomeData());
//     }
// 
//     public void setTabLayout(TabLayout tabLayout) {
//         tabLayout.setupWithViewPager(viewPager);
//     }
// 
//     @Override
//     public void startFolderChooser() {
//         if (view != null)
//             view.startFolderChooser();
//     }
// 
//     @Override
//     public void onNewAudioBookLoaded() {
//         allFrag.updateBookList();
//         newFrag.updateBookList();
//     }
// 
//     public MainInteractor getInteractor() {
//         return interactor;
//     }
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/interfaces/IMainView.java
// public interface IMainView {
//     void startFolderChooser();
// }
// 
// Path: app/src/main/java/com/architjn/audiobook/service/PlayerService.java
// public class PlayerService extends Service implements IPlayerService {
// 
//     private MediaPlayer mediaPlayer;
//     private boolean gotContent;
//     private PlayerInteractor interactor;
// 
//     @Nullable
//     @Override
//     public IBinder onBind(Intent intent) {
//         return null;
//     }
// 
//     @Override
//     public int onStartCommand(Intent intent, int flags, int startId) {
//         interactor = PlayerInteractor.getInstance(this);
//         interactor.setServiceListener(this);
//         mediaPlayer = new MediaPlayer();
//         gotContent = false;
//         return START_STICKY;
//     }
// 
//     @Override
//     public void setSource(BookChapter chapter) {
//         try {
//             gotContent = false;
//             mediaPlayer.reset();
//             mediaPlayer.setDataSource(chapter.getData());
//             gotContent = true;
//             mediaPlayer.prepare();
//             mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//                 @Override
//                 public void onCompletion(MediaPlayer mp) {
//                     if (interactor != null) {
//                         changeAudioFile(interactor.getNextChapter());
//                     }
//                 }
//             });
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     private void changeAudioFile(BookChapter nextChapter) {
//         try {
//             if (mediaPlayer != null && nextChapter != null) {
//                 mediaPlayer.reset();
//                 mediaPlayer.setDataSource(nextChapter.getData());
//                 interactor.askToPlay();
//             }
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public int play() {
//         if (mediaPlayer != null && gotContent) {
//             if (!mediaPlayer.isPlaying()) {
//                 mediaPlayer.start();
//                 interactor.setStatus(PLAYING);
//             } else if (mediaPlayer != null) {
//                 mediaPlayer.pause();
//                 interactor.setStatus(PAUSED);
//             }
//             return mediaPlayer.getCurrentPosition();
//         }
//         return -1;
//     }
// 
//     @Override
//     public void onSeekChange(int progress) {
//         if (mediaPlayer != null && gotContent)
//             mediaPlayer.seekTo(progress);
//     }
// }


// Path: app/src/main/java/com/architjn/audiobook/ui/activity/MainActivity.java
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.content.PermissionChecker;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import com.architjn.audiobook.R;
import com.architjn.audiobook.presenter.MainPresenter;
import com.architjn.audiobook.interfaces.IMainView;
import com.architjn.audiobook.service.PlayerService;
import butterknife.BindView;
import butterknife.ButterKnife;

package com.architjn.audiobook.ui.activity;




public class MainActivity extends AppCompatActivity implements IMainView {

    private static final int FOLDER_CHOOSER = 3231;
    public static final int READ_PERMISSION_REQUEST = 7766;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    @BindView(R.id.tabs)
    TabLayout tabLayout;
    private MainPresenter presenter;