@@ -0,0 +1,3130 @@
+package com.zelory.kace.adressbook.presenter;%0A%0Aimport com.zelory.kace.adressbook.data.DataManager;%0Aimport com.zelory.kace.adressbook.data.model.AddressBook;%0Aimport rx.Observable;%0Aimport rx.schedulers.Schedulers;%0A%0Aimport javax.swing.*;%0Aimport java.io.File;%0A%0Apublic class AddressBookPresenter %7B%0A    private View view;%0A%0A    public AddressBookPresenter(View view) %7B%0A        this.view = view;%0A    %7D%0A%0A    public void loadAddressBook(File file) %7B%0A        view.showLoading();%0A        DataManager.getInstance()%0A                .loadAddressBook(file)%0A                .subscribeOn(Schedulers.io())%0A                .subscribe(addressBook -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.showAddressBook(addressBook);%0A                    view.dismissLoading();%0A                %7D), throwable -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.onError(throwable);%0A                    view.dismissLoading();%0A                %7D));%0A    %7D%0A%0A    public void saveAddressBook(AddressBook addressBook, String path) %7B%0A        view.showLoading();%0A        DataManager.getInstance()%0A                .save(addressBook, path)%0A                .subscribeOn(Schedulers.io())%0A                .subscribe(savedAddressBook -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.showAddressBook(savedAddressBook);%0A                    view.dismissLoading();%0A                %7D), throwable -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.onError(throwable);%0A                    view.dismissLoading();%0A                %7D));%0A    %7D%0A%0A    public void sortPersonsByName(AddressBook addressBook) %7B%0A        view.showLoading();%0A        Observable.from(addressBook.getPersons())%0A                .toSortedList((person1, person2) -%3E person1.getName().compareTo(person2.getName()))%0A                .doOnNext(addressBook::setPersons)%0A                .subscribeOn(Schedulers.io())%0A                .subscribe(savedAddressBook -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.showAddressBook(addressBook);%0A                    view.dismissLoading();%0A                %7D), throwable -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.onError(throwable);%0A                    view.dismissLoading();%0A                %7D));%0A    %7D%0A%0A    public void sortPersonsByZip(AddressBook addressBook) %7B%0A        view.showLoading();%0A        Observable.from(addressBook.getPersons())%0A                .toSortedList((person1, person2) -%3E person1.getZip().compareTo(person2.getZip()))%0A                .doOnNext(addressBook::setPersons)%0A                .subscribeOn(Schedulers.io())%0A                .subscribe(savedAddressBook -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.showAddressBook(addressBook);%0A                    view.dismissLoading();%0A                %7D), throwable -%3E SwingUtilities.invokeLater(() -%3E %7B%0A                    view.onError(throwable);%0A                    view.dismissLoading();%0A                %7D));%0A    %7D%0A%0A    public interface View %7B%0A%0A        void showAddressBook(AddressBook addressBook);%0A%0A        void showLoading();%0A%0A        void dismissLoading();%0A%0A        void onError(Throwable throwable);%0A    %7D%0A%7D%0A

Add presenter to handle saving and loading data asynchronously