/*
 * Copyright 2017 Spry Rocks, Inc
 *
 *     Licensed under the Apache License, Version 2.0 (the "License");
 *     you may not use this file except in compliance with the License.
 *     You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *     Unless required by applicable law or agreed to in writing, software
 *     distributed under the License is distributed on an "AS IS" BASIS,
 *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *     See the License for the specific language governing permissions and
 *     limitations under the License.
 */

package com.spryrocks.android.modules.ui.mvp.v1;

import android.content.Intent;
import android.os.Bundle;

public abstract class PresenterBase<TPresenterView> implements IPresenter<TPresenterView>, IPresenterCollection {

    private TPresenterView presenterView;

    private PresenterCollection presenterCollection;

    public PresenterBase() {
        presenterCollection = new PresenterCollection();
    }

    @Override
    public void setView(TPresenterView presenterView) {

        if(presenterView == null)
            throw new NullPointerException("presenterView cannot to be null");
        if(this.presenterView != null)
            throw new RuntimeException("Cannot set presenterView twice");

        this.presenterView = presenterView;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        if(presenterView == null)
            throw new NullPointerException("presenterView cannot to be null");

        presenterCollection.onCreate(savedInstanceState);
    }

    @Override
    public void onStart() {
        presenterCollection.onStart();
    }

    @Override
    public void onResume() {
        presenterCollection.onResume();
    }

    @Override
    public void onPause() {
        presenterCollection.onPause();
    }

    @Override
    public void onStop() {
        presenterCollection.onStop();
    }

    @Override
    public void onDestroy() {
        presenterCollection.onDestroy();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        presenterCollection.onSaveInstanceState(outState);
    }

    @Override
    public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
        return presenterCollection.onActivityResult(requestCode, resultCode, data);
    }


    /* protected methods */

    public TPresenterView getView() {
        return presenterView;
    }


    /* public methods */

    @Override
    public <TPresenter extends IPresenter<TPresenterView2>, TPresenterView2>
    TPresenter registerPresenter(TPresenter presenter, TPresenterView2 presenterView) {
        return presenterCollection.registerPresenter(presenter, presenterView);
    }

}

@@ -736,16 +736,248 @@
 undle;%0A%0A
+import com.spryrocks.android.modules.ui.lifecycle.ILifecycleListener;%0Aimport com.spryrocks.android.modules.ui.lifecycle.ILifecycleListenersCollection;%0Aimport com.spryrocks.android.modules.ui.lifecycle.LifecycleListenersCollection;%0A%0A
 public a
@@ -1060,25 +1060,34 @@
 View%3E, I
-Pres
+LifecycleList
 en
-t
 er
+s
 Collecti
@@ -1091,17 +1091,16 @@
 ction %7B%0A
-%0A
     priv
@@ -1146,25 +1146,34 @@
 private 
-Pres
+LifecycleList
 en
-t
 er
+s
 Collecti
@@ -1175,25 +1175,34 @@
 lection 
-pres
+lifecycleList
 en
-t
 er
+s
 Collecti
@@ -1239,33 +1239,42 @@
 ) %7B%0A        
-pres
+lifecycleList
 en
-t
 er
+s
 Collection =
@@ -1278,25 +1278,34 @@
 n = new 
-Pres
+LifecycleList
 en
-t
 er
+s
 Collecti
@@ -1852,33 +1852,42 @@
 );%0A%0A        
-pres
+lifecycleList
 en
-t
 er
+s
 Collection.o
@@ -1968,33 +1968,42 @@
 ) %7B%0A        
-pres
+lifecycleList
 en
-t
 er
+s
 Collection.o
@@ -2066,33 +2066,42 @@
 ) %7B%0A        
-pres
+lifecycleList
 en
-t
 er
+s
 Collection.o
@@ -2164,33 +2164,42 @@
 ) %7B%0A        
-pres
+lifecycleList
 en
-t
 er
+s
 Collection.o
@@ -2260,33 +2260,42 @@
 ) %7B%0A        
-pres
+lifecycleList
 en
-t
 er
+s
 Collection.o
@@ -2358,33 +2358,42 @@
 ) %7B%0A        
-pres
+lifecycleList
 en
-t
 er
+s
 Collection.o
@@ -2488,25 +2488,34 @@
         
-pres
+lifecycleList
 en
-t
 er
+s
 Collecti
@@ -2664,33 +2664,42 @@
      return 
-pres
+lifecycleList
 en
-t
 er
+s
 Collection.o
@@ -2914,186 +2914,87 @@
 lic 
-%3CTPresenter extends IPresenter%3CTPresenterView2%3E, TPresenterView2%3E%0A    TPresenter registerPresenter(TPresenter presenter, TPresenterView2 presenterView) %7B%0A        return pres
+void registerListener(ILifecycleListener listener) %7B%0A        lifecycleList
 en
-t
 er
+s
 Coll
@@ -3012,42 +3012,25 @@
 ster
-Pres
+List
 en
-t
 er(
-presenter, presenterView
+listener
 );%0A 
@@ -3034,11 +3034,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Change presenter collection to lifecyle listener collection in presenter