Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Refactored the App #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
import java.util.concurrent.TimeUnit;

public class IssTrackingPresenter implements IssTrackingPresenterInterface {
private final IssTrackingInteractorInterface issTrackingInteractorInterface;
private IssTrackingViewInterface view;
private final IssTrackingViewInterface nullView = new IssTrackingViewInterface.NullView();
private final IssTrackingRepositoryInterface issTrackingRepositoryInterface;
private IssTrackingView view;
private final IssTrackingView nullView = new IssTrackingView.NullView();
private Disposable timerSubscription;
private CompositeDisposable compositeDisposable = new CompositeDisposable();
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
private final Scheduler scheduler;
private final Observable<Long> timer = Observable.timer(60, TimeUnit.SECONDS, AndroidSchedulers.mainThread());

public IssTrackingPresenter(IssTrackingInteractorInterface issTrackingInteractorInterface) {
this(issTrackingInteractorInterface, AndroidSchedulers.mainThread());
public IssTrackingPresenter(IssTrackingRepositoryInterface issTrackingRepositoryInterface) {
this(issTrackingRepositoryInterface, AndroidSchedulers.mainThread());
}

private IssTrackingPresenter(IssTrackingInteractorInterface issTrackingInteractorInterface, Scheduler scheduler) {
this.issTrackingInteractorInterface = issTrackingInteractorInterface;
private IssTrackingPresenter(IssTrackingRepositoryInterface issTrackingRepositoryInterface, Scheduler scheduler) {
this.issTrackingRepositoryInterface = issTrackingRepositoryInterface;
this.view = nullView;
this.scheduler = scheduler;
}

@Override
public void setView(IssTrackingViewInterface view) {
public void setView(IssTrackingView view) {
this.view = view;
}

@Override
public void retrieveCurrentPosition() {
Disposable currentPositionSubscription = issTrackingInteractorInterface.getCurrentPosition()
Disposable currentPositionSubscription = issTrackingRepositoryInterface.getCurrentPosition()
.subscribeOn(Schedulers.io())
.observeOn(scheduler)
.subscribe(currentPositionResponse -> view.setIssPosition(currentPositionResponse.position),
Expand All @@ -52,7 +52,7 @@ public void retrieveCurrentPosition() {
@Override
public void retrievePassTimes(double latitude, double longitude) {
view.willRetrievePassTimes();
Disposable passTimesSubscription = issTrackingInteractorInterface.getPassTimes(latitude, longitude)
Disposable passTimesSubscription = issTrackingRepositoryInterface.getPassTimes(latitude, longitude)
.subscribeOn(Schedulers.io())
.observeOn(scheduler)
.subscribe(passTimesResponse -> view.showPassTimes(passTimesResponse.passTimes),
Expand All @@ -63,7 +63,7 @@ public void retrievePassTimes(double latitude, double longitude) {
@Override
public void retrievePeopleInSpace() {
view.willRetrievePeopleInSpace();
Disposable peopleInSpaceSubscription = issTrackingInteractorInterface.getPeopleInSpace()
Disposable peopleInSpaceSubscription = issTrackingRepositoryInterface.getPeopleInSpace()
.subscribeOn(Schedulers.io())
.observeOn(scheduler)
.subscribe(peopleInSpaceResponse -> view.showPeopleInSpace(peopleInSpaceResponse.people),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IssTrackingPresenterInterface {

void retrievePeopleInSpace();

void setView(IssTrackingViewInterface view);
void setView(IssTrackingView view);

void stop();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import io.reactivex.Observable;

public class IssTrackingInteractor implements IssTrackingInteractorInterface {
public class IssTrackingRepository implements IssTrackingRepositoryInterface {
private final IssTrackingApiInterface api;

public IssTrackingInteractor(IssTrackingApiInterface api) {
public IssTrackingRepository(IssTrackingApiInterface api) {
this.api = api;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.reactivex.Observable;

public interface IssTrackingInteractorInterface {
public interface IssTrackingRepositoryInterface {
Observable<IssTrackingApiInterface.CurrentPositionResponse> getCurrentPosition();

Observable<IssTrackingApiInterface.PassTimesResponse> getPassTimes(double latitude,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

public interface IssTrackingViewInterface {
public interface IssTrackingView {

void showCurrentPositionError();

Expand All @@ -24,7 +24,7 @@ public interface IssTrackingViewInterface {

void showPeopleInSpace(List<IssTrackingApiInterface.Person> people);

class NullView implements IssTrackingViewInterface {
class NullView implements IssTrackingView {

@Override
public void showCurrentPositionError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ import com.ferranpons.spacehub.R
import com.ferranpons.spacehub.issTracking.IssTrackingApi
import com.ferranpons.spacehub.issTracking.IssTrackingApiInterface
import com.ferranpons.spacehub.issTracking.IssTrackingPresenterInterface
import com.ferranpons.spacehub.issTracking.IssTrackingViewInterface
import com.ferranpons.spacehub.issTracking.IssTrackingView
import com.ferranpons.spacehub.issTracking.IssTrackingPresenter
import com.ferranpons.spacehub.issTracking.IssTrackingInteractor
import com.ferranpons.spacehub.issTracking.IssTrackingRepository

class ScheduleFragment : Fragment(), IssTrackingViewInterface {
class ScheduleFragment : Fragment(), IssTrackingView {
private lateinit var issTrackingPresenter: IssTrackingPresenterInterface

override fun onAttach(context: Context) {
super.onAttach(context)

issTrackingPresenter = IssTrackingPresenter(IssTrackingInteractor(IssTrackingApi.getIssTrackingApi("http://api.open-notify.org")))
issTrackingPresenter = IssTrackingPresenter(
IssTrackingRepository(
IssTrackingApi.getIssTrackingApi("http://api.open-notify.org")
)
)
(issTrackingPresenter as IssTrackingPresenter).setView(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_schedule, container, false)
return view
return inflater.inflate(R.layout.fragment_schedule, container, false)
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down