// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java
// public class EventImpl extends Event {
// 
// 
// }
// 
// Path: library/src/main/java/com/hadlink/library/model/Event.java
// public class Event {
// 
//     public final static int NET_REQUEST_ERROR = 0x10;
// 
//     public int arg;
//     private Object object;
// 
//     public <T extends Object> T getObject() {
//         return (T) object;
//     }
// 
//     public void setObject(Object obj) {
//         this.object = obj;
//     }
// }
// 
// Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java
// public class RxBus {
// 
//     private RxBus() {
//     }
// 
//     private static volatile RxBus mInstance;
// 
//     public static RxBus getDefault() {
//         if (mInstance == null) {
//             synchronized (RxBus.class) {
//                 if (mInstance == null) {
//                     mInstance = new RxBus();
//                 }
//             }
//         }
//         return mInstance;
//     }
// 
//     private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create());
// 
//     public void post(Object event) {
//         bus.onNext(event);
//     }
// 
//     public <T> Observable<T> take(final Class<T> eventType) {
//         return bus.filter(new Func1<Object, Boolean>() {
//             @Override
//             public Boolean call(Object o) {
//                 return eventType.isInstance(o);
//             }
//         }).cast(eventType);
//     }
//     //usage
//     /*private void setTabTitle(int position) {
//         Event event = new Event();
//         event.setAction(Event.SEND_TAB_TITLE_ACTION);
//         CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position);
//         event.setObject(pageTitle);
//         RxBus.getDefault().post(event);
//     }*/
//     /*rxBusSubscript = RxBus.getDefault().take(Event.class)
//     .subscribe(new Action1<Event>() {
//         @Override
//         public void call(Event event) {
//             changeContent(event);
//         }
//     }, new Action1<Throwable>() {
//         @Override
//         public void call(Throwable throwable) {
//         }
//     });*/
// }


import com.hadlink.easynet.conf.ErrorInfo;
import com.hadlink.easynet.util.NetUtils;
import com.hadlink.lay_s.model.EventImpl;
import com.hadlink.library.model.Event;
import com.hadlink.library.util.rx.RxBus;
/*
 *    Copyright (c) 2016, lyao. lomoliger@hotmail.com
 *
 *     Part of the code from the open source community,
 *     thanks stackOverflow & gitHub .
 *     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.hadlink.lay_s.datamanager.net.netcallback;


public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> {

    public MyNetCallBack(String eventTag) {
        super(eventTag);
    }

    public MyNetCallBack() {
        super(null);
    }

    /**
     * 除了Invalid 返回的是原对象之外，其余都是String
     */
    @Override public void onDispatchError(Error error, ErrorInfo e) {

        switch (error) {
            case Internal:
                break;
            case Invalid:
                /**
                 * 当数据无效时候你做的处理
                 */
                T result = (T) e.getObject();

                break;
            case NetWork:
                break;
            case Server:
                break;
            case UnKnow:
                break;
        }
        //post event
// Path: lay-s/src/main/java/com/hadlink/lay_s/model/EventImpl.java
// public class EventImpl extends Event {
// 
// 
// }
// 
// Path: library/src/main/java/com/hadlink/library/model/Event.java
// public class Event {
// 
//     public final static int NET_REQUEST_ERROR = 0x10;
// 
//     public int arg;
//     private Object object;
// 
//     public <T extends Object> T getObject() {
//         return (T) object;
//     }
// 
//     public void setObject(Object obj) {
//         this.object = obj;
//     }
// }
// 
// Path: library/src/main/java/com/hadlink/library/util/rx/RxBus.java
// public class RxBus {
// 
//     private RxBus() {
//     }
// 
//     private static volatile RxBus mInstance;
// 
//     public static RxBus getDefault() {
//         if (mInstance == null) {
//             synchronized (RxBus.class) {
//                 if (mInstance == null) {
//                     mInstance = new RxBus();
//                 }
//             }
//         }
//         return mInstance;
//     }
// 
//     private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create());
// 
//     public void post(Object event) {
//         bus.onNext(event);
//     }
// 
//     public <T> Observable<T> take(final Class<T> eventType) {
//         return bus.filter(new Func1<Object, Boolean>() {
//             @Override
//             public Boolean call(Object o) {
//                 return eventType.isInstance(o);
//             }
//         }).cast(eventType);
//     }
//     //usage
//     /*private void setTabTitle(int position) {
//         Event event = new Event();
//         event.setAction(Event.SEND_TAB_TITLE_ACTION);
//         CharSequence pageTitle = viewpager.getAdapter().getPageTitle(position);
//         event.setObject(pageTitle);
//         RxBus.getDefault().post(event);
//     }*/
//     /*rxBusSubscript = RxBus.getDefault().take(Event.class)
//     .subscribe(new Action1<Event>() {
//         @Override
//         public void call(Event event) {
//             changeContent(event);
//         }
//     }, new Action1<Throwable>() {
//         @Override
//         public void call(Throwable throwable) {
//         }
//     });*/
// }


// Path: lay-s/src/main/java/com/hadlink/lay_s/datamanager/net/netcallback/MyNetCallBack.java
import com.hadlink.easynet.conf.ErrorInfo;
import com.hadlink.easynet.util.NetUtils;
import com.hadlink.lay_s.model.EventImpl;
import com.hadlink.library.model.Event;
import com.hadlink.library.util.rx.RxBus;

/*
 *    Copyright (c) 2016, lyao. lomoliger@hotmail.com
 *
 *     Part of the code from the open source community,
 *     thanks stackOverflow & gitHub .
 *     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.hadlink.lay_s.datamanager.net.netcallback;


public abstract class MyNetCallBack<T> extends NetUtils.callBack<T> {

    public MyNetCallBack(String eventTag) {
        super(eventTag);
    }

    public MyNetCallBack() {
        super(null);
    }

    /**
     * 除了Invalid 返回的是原对象之外，其余都是String
     */
    @Override public void onDispatchError(Error error, ErrorInfo e) {

        switch (error) {
            case Internal:
                break;
            case Invalid:
                /**
                 * 当数据无效时候你做的处理
                 */
                T result = (T) e.getObject();

                break;
            case NetWork:
                break;
            case Server:
                break;
            case UnKnow:
                break;
        }
        //post event
        Event event = new EventImpl();