package lib.morkim.mfw.ui;

import android.content.Context;

import java.util.Observable;
import java.util.Observer;

import lib.morkim.mfw.app.AppContext;
import lib.morkim.mfw.domain.Model;
import lib.morkim.mfw.usecase.UseCase;
import lib.morkim.mfw.usecase.UseCaseProgress;
import lib.morkim.mfw.usecase.UseCaseResult;
import lib.morkim.mfw.usecase.UseCaseStateListener;

public abstract class Presenter implements Observer, UseCaseStateListener {

	private AppContext appContext;
	protected Viewable viewable;

	public Presenter(Viewable viewable) {
		
		this.viewable = viewable;
		this.appContext = viewable.getMorkimContext();
	}

	public void unbindViewModel() {

//		viewModel.unregister();
	}

	public void bindViewModel(Viewable viewable) {

//		viewModel.register(viewable);
//		viewModel.notifyView();
	}

	@Override
	public void update(Observable observable, Object data) {
		synchronized (this) {
//			onUpdate(observable, data, viewModel);
//			if (viewModel.hasListener())
//				viewModel.notifyUiView();
		}
	}

	protected void onUpdate(Observable observable, Object data,
			ViewModel viewModel) {
	}

//	public ViewModel getViewModel() {
//		return viewModel;
//	}
//
//	public void setViewModel(ViewModel viewModel) {
//		this.viewModel = viewModel;
//	}

	protected Controller getController() {
		return viewable.getController();
	}

	public AppContext getAppContext() {
		return appContext;
	}

	protected Context getContext() {
		return viewable.getContext();
	}

	public void setAppContext(AppContext appContext) {
		this.appContext = appContext;
	}
	
	protected Model getModel() {
		return appContext.getModel();
	}

	@Override
	public void onUseCaseStart(UseCase useCase) {}

	@Override
	public void onUseCaseUpdate(UseCaseProgress response) {}

	@Override
	public void onUseCaseComplete(UseCaseResult response) {}

	@Override
	public void onUseCaseCancel() {}
}
@@ -65,1826 +65,556 @@
 ort 
-java.util.Observable;%0Aimport java.util.Observer;%0A%0Aimport lib.morkim.mfw.app.AppContext;%0Aimport lib.morkim.mfw.domain.Model;%0Aimport lib.morkim.mfw.usecase.UseCase;%0Aimport lib.morkim.mfw.usecase.UseCaseProgress;%0Aimport lib.morkim.mfw.usecase.UseCaseResult;%0Aimport lib.morkim.mfw.usecase.UseCaseStateListener;%0A%0Apublic abstract class Presenter implements Observer, UseCaseStateListener %7B%0A%0A%09private AppContext appContext;%0A%09protected Viewable viewable;%0A%0A%09public Presenter(Viewable viewable) %7B%0A%09%09%0A%09%09this.viewable = viewable;%0A%09%09this.appContext = viewable.getMorkimContext();%0A%09%7D%0A%0A%09public void unbindViewModel() %7B%0A%0A//%09%09viewModel.unregister();%0A%09%7D%0A%0A%09public void bindViewModel(Viewable viewable) %7B%0A%0A//%09%09viewModel.register(viewable);%0A//%09%09viewModel.notifyView();%0A%09%7D%0A%0A%09@Override%0A%09public void update(Observable observable, Object data) %7B%0A%09%09synchronized (this) %7B%0A//%09%09%09onUpdate(observable, data, viewModel);%0A//%09%09%09if (viewModel.hasListener())%0A//%09%09%09%09viewModel.notifyUiView();%0A%09%09%7D%0A%09%7D%0A%0A%09protected void onUpdate(Observable observable, Object data,%0A%09%09%09ViewModel viewModel) %7B%0A%09%7D%0A%0A//%09public ViewModel getViewModel() %7B%0A//%09%09return viewModel;%0A//%09%7D%0A//%0A//%09public void setViewModel(ViewModel viewModel) %7B%0A//%09%09this.viewModel = viewModel;%0A//%09%7D%0A%0A%09protected Controller getController() %7B%0A%09%09return viewable.getController();%0A%09%7D%0A%0A%09public AppContext getAppContext() %7B%0A%09%09return appContext;%0A%09%7D%0A%0A%09protected Context getContext() %7B%0A%09%09return viewable.getContext();%0A%09%7D%0A%0A%09public void setAppContext(AppContext appContext) %7B%0A%09%09this.appContext = appContext;%0A%09%7D%0A%09%0A%09protected Model getModel() %7B%0A%09%09return appContext.getModel();%0A%09%7D%0A%0A%09@Override%0A%09public void onUseCaseStart(UseCase useCase) %7B%7D%0A%0A%09@Override%0A%09public void onUseCaseUpdate(UseCaseProgress response) %7B%7D%0A%0A%09@Override%0A%09public void onUseCaseComplete(UseCaseResult response) %7B%7D%0A%0A%09@Override%0A%09public void onUseCaseCancel() %7B
+lib.morkim.mfw.app.AppContext;%0A%0Apublic abstract class Presenter %7B%0A%0A%09private AppContext appContext;%0A%09protected Viewable viewable;%0A%0A%09public Presenter(Viewable viewable) %7B%0A%09%09%0A%09%09this.viewable = viewable;%0A%09%09this.appContext = viewable.getMorkimContext();%0A%09%7D%0A%0A%09protected Controller getController() %7B%0A%09%09return viewable.getController();%0A%09%7D%0A%0A%09public AppContext getAppContext() %7B%0A%09%09return appContext;%0A%09%7D%0A%0A%09protected Context getContext() %7B%0A%09%09return viewable.getContext();%0A%09%7D%0A%0A%09public void setAppContext(AppContext appContext) %7B%0A%09%09this.appContext = appContext;%0A%09
 %7D%0A%7D

Remove view model in presenter