add favourite workflow list presenter layer

Project: http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/commit/3c7f4c1d
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/tree/3c7f4c1d
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/diff/3c7f4c1d

Branch: refs/heads/master
Commit: 3c7f4c1dbcf663a6b055e6af84e31cf9a559e00c
Parents: c39d6b4
Author: Sagar <[email protected]>
Authored: Sat Jul 9 23:50:17 2016 +0530
Committer: Sagar <[email protected]>
Committed: Sat Jul 9 23:50:17 2016 +0530

----------------------------------------------------------------------
 .../FavouriteWorkflowsMvpView.java              | 36 +++++++++
 .../FavouriteWorkflowsPresenter.java            | 84 ++++++++++++++++++++
 2 files changed, 120 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/3c7f4c1d/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsMvpView.java
----------------------------------------------------------------------
diff --git 
a/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsMvpView.java
 
b/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsMvpView.java
new file mode 100644
index 0000000..678f8b4
--- /dev/null
+++ 
b/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsMvpView.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.taverna.mobile.ui.favouriteworkflow;
+
+
+import org.apache.taverna.mobile.data.model.Workflow;
+import org.apache.taverna.mobile.ui.base.MvpView;
+
+import java.util.List;
+
+public interface FavouriteWorkflowsMvpView extends MvpView {
+
+    void showProgressbar(boolean b);
+
+    void showErrorSnackBar();
+
+    void showWorkflows(List<Workflow> workflowList);
+
+    void showNoWorkflowError();
+}

http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/3c7f4c1d/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsPresenter.java
----------------------------------------------------------------------
diff --git 
a/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsPresenter.java
 
b/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsPresenter.java
new file mode 100644
index 0000000..b46d41e
--- /dev/null
+++ 
b/app/src/main/java/org/apache/taverna/mobile/ui/favouriteworkflow/FavouriteWorkflowsPresenter.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.taverna.mobile.ui.favouriteworkflow;
+
+import org.apache.taverna.mobile.data.DataManager;
+import org.apache.taverna.mobile.data.model.Workflow;
+import org.apache.taverna.mobile.ui.base.BasePresenter;
+
+import java.util.List;
+
+import rx.Observer;
+import rx.Subscription;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+
+public class FavouriteWorkflowsPresenter extends 
BasePresenter<FavouriteWorkflowsMvpView> {
+
+    public final String LOG_TAG = getClass().getSimpleName();
+    private DataManager mDataManager;
+    private Subscription mSubscriptions;
+
+
+    public FavouriteWorkflowsPresenter(DataManager dataManager) {
+        mDataManager = dataManager;
+    }
+
+    @Override
+    public void attachView(FavouriteWorkflowsMvpView mvpView) {
+        super.attachView(mvpView);
+    }
+
+    @Override
+    public void detachView() {
+        super.detachView();
+        if (mSubscriptions != null) mSubscriptions.unsubscribe();
+    }
+
+    public void loadAllWorkflow() {
+        if (mSubscriptions != null) mSubscriptions.unsubscribe();
+        mSubscriptions = mDataManager.getFavoriteWorkflowList()
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribeOn(Schedulers.io())
+                .subscribe(new Observer<List<Workflow>>() {
+                    @Override
+                    public void onCompleted() {
+                        getMvpView().showProgressbar(false);
+                    }
+
+                    @Override
+                    public void onError(Throwable e) {
+                        getMvpView().showProgressbar(false);
+                        getMvpView().showErrorSnackBar();
+                    }
+
+                    @Override
+                    public void onNext(List<Workflow> workflowList) {
+                        if(workflowList.size()!=0) {
+                            getMvpView().showWorkflows(workflowList);
+                        }else{
+                            getMvpView().showNoWorkflowError();
+                        }
+                    }
+                });
+
+    }
+
+
+}

Reply via email to