public interface IActivityInteractor {
    Observable<ArrayList<ActivityInfoInternal>> getActivities(String packageName);
} public interface IBroadcastReceiverInteractor {
    Observable<ArrayList<BroadcastReceiverInfo>> getBroadcastReceivers(String packageName);
} public interface IContentProviderInteractor {
    Observable<ArrayList<ContentProviderInfo>> getContentProviders(String packageName);
} public interface IPackageInteractor {
    Observable<ArrayList<InstalledPackageHeader>> getInstalledPackages(boolean refresh);
    Observable<String> getAppNameFromPackage(String packageName);
    Observable<AppInfo> getApplicationInfo(String packageName);
    Observable<ArrayList<FeatureInfoInternal>> getRequestedFeatures(String packageName);

} public interface IPermissionsInteractor {
    Observable<ArrayList<DeclaredPermission>> getDeclaredPermissions(String packageName);
    Observable<ArrayList<RequestedPermission>> getRequestedPermissions(String packageName);
} public interface IServiceInteractor {
    Observable<ArrayList<ServiceInfoInternal>> getServices(String packageName);
} public class ActivitiesFragmentPresenterImpl implements IActivitiesFragmentPresenter {

    private IActivityInteractor mInteractor;
    private IActivitiesFragmentView mView;

    public ActivitiesFragmentPresenterImpl(IActivityInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IActivitiesFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideNoValuesText();
        mView.hideDetailContainer();
        mView.showWaitDialog();

        mInteractor.getActivities(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    if (mView != null) {
                        if (result.size() > 0) {
                            mView.setModel(result);
                            mView.showDetailContainer();
                            mView.hideWaitDialog();
                        } else {
                            mView.showNoValuesText();
                            mView.hideWaitDialog();
                        }
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }

    @Override
    public void onActivitySelected(ActivityInfoInternal activity) {
        mView.startActivityDetailActivity(activity);
    }
} public class ActivityDetailActivityPresenterImpl implements IActivityDetailActivityPresenter {
    private IActivityDetailActivityView mView;

    @Override
    public void setView(IActivityDetailActivityView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(ActivityInfoInternal ai) {
        if (mView != null) {
            mView.setTitle(ai.getName());

            int arraySize = 1;
            int currentIndex = 1;

            if (ai.getConfigChanges().size() > 0)
                arraySize++;

            if (ai.getCategories().size() > 0)
                arraySize++;

            if (ai.getFlags().size() > 0)
                arraySize++;

            if (ai.getSoftInputMode().size() > 0)
                arraySize++;

            Object[] items = new Object[arraySize];
            int[] types = new int[arraySize];

            items[0] = ai;
            types[0] = ActivityDetailAdapter.GENERAL;

            if (ai.getConfigChanges().size() > 0) {
                items[currentIndex] = ai.getConfigChanges();
                types[currentIndex] = ActivityDetailAdapter.CONFIG_CHANGES;
                currentIndex++;
            }

            if (ai.getCategories().size() > 0) {
                items[currentIndex] = ai.getCategories();
                types[currentIndex] = ActivityDetailAdapter.CATEGORIES;
                currentIndex++;
            }

            if (ai.getFlags().size() > 0) {
                items[currentIndex] = ai.getFlags();
                types[currentIndex] = ActivityDetailAdapter.FLAGS;
                currentIndex++;
            }

            if (ai.getSoftInputMode().size() > 0) {
                items[currentIndex] = ai.getSoftInputMode();
                types[currentIndex] = ActivityDetailAdapter.SOFT_INPUT_MODE;
                currentIndex++;
            }


            /*Object[] items = new Object[4];
            items[0] = ai;
            items[1] = ai.getConfigChanges();
            items[2] = ai.getCategories();
            items[3] = ai.getSoftInputMode();*/

            /*int[] types = new int[4];
            types[0] = ActivityDetailAdapter.GENERAL;
            types[1] = ActivityDetailAdapter.CONFIG_CHANGES;
            types[2] = ActivityDetailAdapter.CATEGORIES;
            types[3] = ActivityDetailAdapter.SOFT_INPUT_MODE;*/

            mView.setModel(items, types);
        }
    }
} public class ApplicationInfoFragmentPresenterImpl implements IApplicationInfoFragmentPresenter {

    private IPackageInteractor mInteractor;
    private IApplicationInfoFragmentView mView;

    @Inject
    public ApplicationInfoFragmentPresenterImpl(IPackageInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IApplicationInfoFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideDetailContainer();
        mView.showWaitDialog();

        mInteractor.getApplicationInfo(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(appInfo -> {
                    if (mView != null) {
                        Object[] items = new Object[4];
                        items[0] = appInfo.getGeneralInfo();
                        items[1] = appInfo.getDirectoryInfo();
                        items[2] = appInfo.getFlags();
                        items[3] = appInfo.getSignatures();

                        int[] types = new int[4];
                        types[0] = AppInfoAdapter.GENERAL;
                        types[1] = AppInfoAdapter.DIRECTORIES;
                        types[2] = AppInfoAdapter.FLAGS;
                        types[3] = AppInfoAdapter.SIGNATURES;

                        mView.setModel(items, types);
                        mView.showDetailContainer();
                        mView.hideWaitDialog();
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }
} public class BroadcastReceiversFragmentPresenterImpl implements IBroadcastReceiversFragmentPresenter {

    private IBroadcastReceiverInteractor mInteractor;
    private IBroadcastReceiversFragmentView mView;

    public BroadcastReceiversFragmentPresenterImpl(IBroadcastReceiverInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IBroadcastReceiversFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideNoValuesText();
        mView.hideDetailContainer();
        mView.showWaitDialog();

        mInteractor.getBroadcastReceivers(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    if (mView != null) {
                        if (result.size() > 0) {
                            mView.setModel(result);
                            mView.showDetailContainer();
                            mView.hideWaitDialog();
                        } else {
                            mView.showNoValuesText();
                            mView.hideWaitDialog();
                        }
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }

    @Override
    public void onBroadcastReceiverSelected(BroadcastReceiverInfo receiver) {
        mView.startBroadcastReceiverDetailActivity(receiver);
    }
} public class ContentProviderDetailActivityPresenterImpl implements IContentProviderDetailActivityPresenter {
    private IContentProviderDetailActivityView mView;

    @Override
    public void setView(IContentProviderDetailActivityView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(ContentProviderInfo cpi) {
        if (mView != null) {

            mView.setTitle(cpi.getName());

            Object[] items = new Object[3];
            items[0] = cpi;
            items[1] = cpi.getPathPermissions();
            items[2] = cpi.getURIPermissionPatterns();

            int[] types = new int[3];
            types[0] = ContentProviderDetailAdapter.GENERAL;
            types[1] = ContentProviderDetailAdapter.PATH_PERMISSIONS;
            types[2] = ContentProviderDetailAdapter.URI_PERMISSION_PATTERNS;

            mView.setModel(items, types);
        }
    }
} public class ContentProvidersFragmentPresenterImpl implements IContentProvidersFragmentPresenter {

    private IContentProviderInteractor mInteractor;
    private IContentProvidersFragmentView mView;

    public ContentProvidersFragmentPresenterImpl(IContentProviderInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IContentProvidersFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideNoValuesText();
        mView.hideDetailContainer();
        mView.showWaitDialog();

        mInteractor.getContentProviders(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    if (mView != null) {
                        if (result.size() > 0) {
                            mView.setModel(result);
                            mView.showDetailContainer();
                            mView.hideWaitDialog();
                        } else {
                            mView.showNoValuesText();
                            mView.hideWaitDialog();
                        }
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }

    @Override
    public void onContentProviderSelected(ContentProviderInfo provider) {
        mView.startContentProviderDetailActivity(provider);
    }
} public class DeclaredPermissionsFragmentPresenterImpl implements IDeclaredPermissionsFragmentPresenter {
    private IPermissionsInteractor mInteractor;
    private IDeclaredPermissionsFragmentView mView;

    public DeclaredPermissionsFragmentPresenterImpl(IPermissionsInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IDeclaredPermissionsFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideDetailContainer();
        mView.hideNoValuesText();
        mView.showWaitDialog();

        mInteractor.getDeclaredPermissions(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    if (mView != null) {
                        if (result.size() > 0) {
                            mView.setModel(result);
                            mView.showDetailContainer();
                        } else {
                            mView.showNoValuesText();
                            mView.hideWaitDialog();
                        }

                        mView.hideWaitDialog();
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }
} public interface IActivitiesFragmentPresenter {
    void setView(IActivitiesFragmentView view);
    void clearView();
    void init(String packageName);
    void onActivitySelected(ActivityInfoInternal activity);
} public interface IActivityDetailActivityPresenter {
    void setView(IActivityDetailActivityView view);
    void clearView();
    void init(ActivityInfoInternal ai);
} public interface IApplicationInfoFragmentPresenter {
    void setView(IApplicationInfoFragmentView view);
    void clearView();
    void init(String packageName);
} public interface IBroadcastReceiversFragmentPresenter {
    void setView(IBroadcastReceiversFragmentView view);
    void clearView();
    void init(String packageName);
    void onBroadcastReceiverSelected(BroadcastReceiverInfo receiver);
} public interface IContentProviderDetailActivityPresenter {
    void setView(IContentProviderDetailActivityView view);
    void clearView();
    void init(ContentProviderInfo cpi);
} public interface IContentProvidersFragmentPresenter {
    void setView(IContentProvidersFragmentView view);
    void clearView();
    void init(String packageName);
    void onContentProviderSelected(ContentProviderInfo provider);
} public interface IDeclaredPermissionsFragmentPresenter {

    void setView(IDeclaredPermissionsFragmentView view);
    void clearView();
    void init(String packageName);
} public interface IPackageDetailFragmentPresenter {
    void setView(IPackageDetailFragmentView view);
    void clearView();
    void init(String packageName);
} public interface IRequestedFeaturesFragmentPresenter {

    void setView(IRequestedFeaturesFragmentView view);
    void clearView();
    void init(String packageName);
} public interface IRequestedPermissionsFragmentPresenter {

    void setView(IRequestedPermissionsFragmentView view);
    void clearView();
    void init(String packageName);
} public interface IServicesFragmentPresenter {

    void setView(IServicesFragmentView view);
    void clearView();
    void init(String packageName);
} public class PackageDetailFragmentPresenterImpl implements IPackageDetailFragmentPresenter {

    private IPackageInteractor mPackageInteractor;
    private IPackageDetailFragmentView mView;


    @Inject
    public PackageDetailFragmentPresenterImpl(IPackageInteractor interactor) {
        mPackageInteractor = interactor;
    }

    @Override
    public void setView(IPackageDetailFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        if (mView != null) {
            mView.hideDetailContainer();
            mView.showWaitDialog();

            mPackageInteractor.getAppNameFromPackage(packageName)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(appName -> {
                        if (mView != null) {
                            mView.initViews(appName, packageName);
                            mView.showDetailContainer();
                            mView.hideWaitDialog();
                        }
                    }, error -> {
                        if (mView != null) {
                            mView.hideWaitDialog();
                            mView.showError(error.getMessage());
                        }
                    });
        }
    }
} public class RequestedFeaturesFragmentPresenterImpl implements IRequestedFeaturesFragmentPresenter {
    private IPackageInteractor mInteractor;
    private IRequestedFeaturesFragmentView mView;

    public RequestedFeaturesFragmentPresenterImpl(IPackageInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IRequestedFeaturesFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideNoValuesText();
        mView.hideDetailContainer();
        mView.showWaitDialog();

        mInteractor.getRequestedFeatures(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    if (mView != null) {
                        if (result.size() > 0) {
                            mView.setModel(result);
                            mView.showDetailContainer();
                            mView.hideWaitDialog();
                        } else {
                            mView.showNoValuesText();
                            mView.hideWaitDialog();
                        }
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }
} public class RequestedPermissionsFragmentPresenterImpl implements IRequestedPermissionsFragmentPresenter {
    private IPermissionsInteractor mInteractor;
    private IRequestedPermissionsFragmentView mView;

    public RequestedPermissionsFragmentPresenterImpl(IPermissionsInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IRequestedPermissionsFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideNoValuesText();
        mView.hideDetailContainer();
        mView.showWaitDialog();

        mInteractor.getRequestedPermissions(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    if (mView != null) {
                        if (result.size() > 0) {
                            mView.setModel(result);
                            mView.showDetailContainer();
                            mView.hideWaitDialog();
                        } else {
                            mView.showNoValuesText();
                            mView.hideWaitDialog();
                        }
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }
} public class ServicesFragmentPresenterImpl implements IServicesFragmentPresenter {
    private IServiceInteractor mInteractor;
    private IServicesFragmentView mView;

    public ServicesFragmentPresenterImpl(IServiceInteractor interactor) {
        mInteractor = interactor;
    }

    @Override
    public void setView(IServicesFragmentView view) {
        mView = view;
    }

    @Override
    public void clearView() {
        mView = null;
    }

    @Override
    public void init(String packageName) {
        mView.hideNoValuesText();
        mView.hideDetailContainer();
        mView.showWaitDialog();

        mInteractor.getServices(packageName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                    if (mView != null) {
                        if (result.size() > 0) {
                            mView.setModel(result);
                            mView.showDetailContainer();
                            mView.hideWaitDialog();
                        } else {
                            mView.showNoValuesText();
                            mView.hideWaitDialog();
                        }
                    }
                }, error -> {
                    if (mView != null) {
                        mView.hideWaitDialog();
                        mView.showError(error.getMessage());
                    }
                });
    }
}
import dagger.Module;
import dagger.Provides;
import com.livingstoneapp.interactors.IActivityInteractor;
import com.livingstoneapp.interactors.IBroadcastReceiverInteractor;
import com.livingstoneapp.interactors.IContentProviderInteractor;
import com.livingstoneapp.interactors.IPackageInteractor;
import com.livingstoneapp.interactors.IPermissionsInteractor;
import com.livingstoneapp.interactors.IServiceInteractor;
import com.livingstoneapp.presenters.ActivitiesFragmentPresenterImpl;
import com.livingstoneapp.presenters.ActivityDetailActivityPresenterImpl;
import com.livingstoneapp.presenters.ApplicationInfoFragmentPresenterImpl;
import com.livingstoneapp.presenters.BroadcastReceiversFragmentPresenterImpl;
import com.livingstoneapp.presenters.ContentProviderDetailActivityPresenterImpl;
import com.livingstoneapp.presenters.ContentProvidersFragmentPresenterImpl;
import com.livingstoneapp.presenters.DeclaredPermissionsFragmentPresenterImpl;
import com.livingstoneapp.presenters.IActivitiesFragmentPresenter;
import com.livingstoneapp.presenters.IActivityDetailActivityPresenter;
import com.livingstoneapp.presenters.IApplicationInfoFragmentPresenter;
import com.livingstoneapp.presenters.IBroadcastReceiversFragmentPresenter;
import com.livingstoneapp.presenters.IContentProviderDetailActivityPresenter;
import com.livingstoneapp.presenters.IContentProvidersFragmentPresenter;
import com.livingstoneapp.presenters.IDeclaredPermissionsFragmentPresenter;
import com.livingstoneapp.presenters.IPackageDetailFragmentPresenter;
import com.livingstoneapp.presenters.IRequestedFeaturesFragmentPresenter;
import com.livingstoneapp.presenters.IRequestedPermissionsFragmentPresenter;
import com.livingstoneapp.presenters.IServicesFragmentPresenter;
import com.livingstoneapp.presenters.PackageDetailFragmentPresenterImpl;
import com.livingstoneapp.presenters.RequestedFeaturesFragmentPresenterImpl;
import com.livingstoneapp.presenters.RequestedPermissionsFragmentPresenterImpl;
import com.livingstoneapp.presenters.ServicesFragmentPresenterImpl;
package com.livingstoneapp.dagger;



/**
 * Created by renier on 2/2/2016.
 */
@Module
public class PackageDetailActivityModule {

    public PackageDetailActivityModule(boolean provideMocks) {

    }

    @Provides
    IPackageDetailFragmentPresenter providesPackageDetailFragmentPresenter(IPackageInteractor interactor) {
        return new PackageDetailFragmentPresenterImpl(interactor);
    }

    @Provides
    IApplicationInfoFragmentPresenter providesApplicationInfoFragmentPresenter(IPackageInteractor interactor) {
        return new ApplicationInfoFragmentPresenterImpl(interactor);
    }


    @Provides
    IActivitiesFragmentPresenter providesActivitiesFragmentPresenter(IActivityInteractor interactor) {