You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@taverna.apache.org by ia...@apache.org on 2017/01/11 15:20:01 UTC
[3/7] incubator-taverna-mobile git commit: Add some strings and
change instance names
Add some strings and change instance names
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/af6dbf77
Tree: http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/tree/af6dbf77
Diff: http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/diff/af6dbf77
Branch: refs/heads/ian_taverna_server
Commit: af6dbf77f27fceb7bb5940f5a0e3446d86b08b3f
Parents: 8c5ca23
Author: Ian Dunlop <ia...@manchester.ac.uk>
Authored: Tue Dec 20 15:35:28 2016 +0000
Committer: Ian Dunlop <ia...@manchester.ac.uk>
Committed: Tue Dec 20 15:35:28 2016 +0000
----------------------------------------------------------------------
.../ui/playerlogin/PlayerLoginFragment.java | 261 -------------------
.../ui/playerlogin/PlayerLoginMvpView.java | 32 ---
.../ui/playerlogin/PlayerLoginPresenter.java | 201 --------------
.../TavernaServerCreateRunFragment.java | 258 ++++++++++++++++++
.../TavernaServerCreateRunMvpView.java | 32 +++
.../TavernaServerCreateRunPresenter.java | 195 ++++++++++++++
.../ui/workflowrun/WorkflowRunActivity.java | 10 +-
7 files changed, 490 insertions(+), 499 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/af6dbf77/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginFragment.java b/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginFragment.java
deleted file mode 100644
index 1dcf279..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginFragment.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
- * 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.playerlogin;
-
-
-import android.content.Context;
-import android.os.Bundle;
-import android.support.annotation.Nullable;
-import android.support.design.widget.Snackbar;
-import android.support.design.widget.TextInputLayout;
-import android.support.v4.app.Fragment;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.widget.CheckBox;
-import android.widget.EditText;
-
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.data.DataManager;
-import org.apache.taverna.mobile.data.local.PreferencesHelper;
-import org.apache.taverna.mobile.utils.ConnectionInfo;
-import org.apache.taverna.mobile.utils.Constants;
-
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import butterknife.OnClick;
-import rx.Subscription;
-
-
-public class PlayerLoginFragment extends Fragment implements PlayerLoginMvpView, View
- .OnFocusChangeListener {
-
- @BindView(R.id.etEmail)
- EditText mEditTextEmail;
-
- @BindView(R.id.etPassword)
- EditText mEditTextPassword;
-
- @BindView(R.id.input_layout_email)
- TextInputLayout mTextInputEmail;
-
- @BindView(R.id.input_layout_password)
- TextInputLayout mTextInputPassword;
-
- @BindView(R.id.cbRemember)
- CheckBox mCheckBoxRemember;
- OnSuccessful mCallback;
- private DataManager dataManager;
- private PlayerLoginPresenter mPlayerLoginPresenter;
- private Subscription mSubscriptions;
-
- public static PlayerLoginFragment newInstance() {
-
- Bundle args = new Bundle();
-
- PlayerLoginFragment fragment = new PlayerLoginFragment();
- fragment.setArguments(args);
- return fragment;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- dataManager = new DataManager(new PreferencesHelper(getContext()));
- mPlayerLoginPresenter = new PlayerLoginPresenter(dataManager);
-
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
- savedInstanceState) {
-
- View rootView = inflater.inflate(R.layout.fragment_player_login_layout, container, false);
- ButterKnife.bind(this, rootView);
- mPlayerLoginPresenter.attachView(this);
- String email = dataManager.getPreferencesHelper().getPlayerUserEmail();
- String pw = dataManager.getPreferencesHelper().getPlayerUserPassword();
- mEditTextEmail.setText(email);
- mEditTextPassword.setText(pw);
- return rootView;
- }
-
- @Override
- public void onActivityCreated(@Nullable Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
-
- mEditTextEmail.addTextChangedListener(new CustomTextWatcher(mEditTextEmail));
- mEditTextEmail.setOnFocusChangeListener(this);
-
- mEditTextPassword.addTextChangedListener(new CustomTextWatcher(mEditTextPassword));
- mEditTextPassword.setOnFocusChangeListener(this);
- }
-
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- mPlayerLoginPresenter.detachView();
- }
-
-
- @OnClick(R.id.bLogin)
- public void login(View v) {
- if (ConnectionInfo.isConnectingToInternet(getContext())) {
- String workflowURL = getActivity().getIntent().getStringExtra(Constants.WORKFLOW_URL);
- mPlayerLoginPresenter.playerLogin(workflowURL, mEditTextEmail.getText().toString().trim(),
- mEditTextPassword.getText().toString().trim(), mCheckBoxRemember
- .isChecked());
-
-// if (!mEditTextEmail.getText().toString().trim().isEmpty() && !mEditTextPassword
-// .getText().toString().trim().isEmpty()) {
-//
-// mPlayerLoginPresenter.playerLogin(mEditTextEmail.getText().toString().trim(),
-// mEditTextPassword.getText().toString().trim(), mCheckBoxRemember
-// .isChecked());
-//
-// } else {
-//
-// showError(R.string.error_vaild_credential);
-// }
- } else {
-
- showError(R.string.no_internet_connection);
- }
- }
-
- @Override
- public void showError(int stringID) {
- final Snackbar snackbar = Snackbar.make(mEditTextPassword, getString(stringID), Snackbar
- .LENGTH_LONG);
- snackbar.setAction("OK", new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- snackbar.dismiss();
- }
- });
-
- snackbar.show();
- }
-
- @Override
- public void showCredentialError() {
- mTextInputEmail.setError(getString(R.string.err_login_email));
- mTextInputPassword.setError(getString(R.string.err_login_password));
- requestFocus(mEditTextPassword);
- }
-
- @Override
- public void runLocation(String runID) {
- mCallback.onRunStart(runID);
- }
-
- private void validateEmail() {
-
- if (mEditTextEmail.getText().toString().trim().isEmpty()) {
- mTextInputEmail.setError(getString(R.string.err_login_email));
- } else {
- mTextInputEmail.setError(null);
- }
-
-
- }
-
- private void requestFocus(View view) {
- if (view.requestFocus()) {
- getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams
- .SOFT_INPUT_STATE_ALWAYS_VISIBLE);
- }
- }
-
- private void validatePassword() {
- if (mEditTextPassword.getText().toString().trim().isEmpty()) {
- mTextInputPassword.setError(getString(R.string.err_login_password));
- } else {
- mTextInputPassword.setError(null);
- }
-
-
- }
-
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- switch (v.getId()) {
- case R.id.etEmail:
- if (!v.hasFocus()) {
- validateEmail();
- }
- break;
- case R.id.etPassword:
- if (!v.hasFocus()) {
- validatePassword();
- }
- break;
- }
- }
-
- @Override
- public void onAttach(Context context) {
- super.onAttach(context);
-
- try {
- mCallback = (OnSuccessful) getActivity();
- } catch (ClassCastException e) {
- throw new ClassCastException(getActivity().toString()
- + " must implement OnSuccessful");
- }
- }
-
-
- public interface OnSuccessful {
- void onRunStart(String runID);
- }
-
- private class CustomTextWatcher implements TextWatcher {
-
- private View view;
-
- private CustomTextWatcher(View view) {
- this.view = view;
- }
-
- public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
-
- }
-
- public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
-
- }
-
- public void afterTextChanged(Editable editable) {
- switch (view.getId()) {
- case R.id.etEmail:
- validateEmail();
- break;
- case R.id.etPassword:
- validatePassword();
- break;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/af6dbf77/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginMvpView.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginMvpView.java b/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginMvpView.java
deleted file mode 100644
index 8ad3cb3..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginMvpView.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.playerlogin;
-
-import org.apache.taverna.mobile.ui.base.MvpView;
-
-
-public interface PlayerLoginMvpView extends MvpView {
-
- void showError(int stringID);
-
- void showCredentialError();
-
- void runLocation(String runID);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/af6dbf77/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginPresenter.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginPresenter.java b/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginPresenter.java
deleted file mode 100644
index 7d6c174..0000000
--- a/app/src/main/java/org/apache/taverna/mobile/ui/playerlogin/PlayerLoginPresenter.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * 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.playerlogin;
-
-import android.util.Base64;
-import android.util.Log;
-
-import org.apache.taverna.mobile.R;
-import org.apache.taverna.mobile.data.DataManager;
-import org.apache.taverna.mobile.data.model.PlayerWorkflow;
-import org.apache.taverna.mobile.data.model.PlayerWorkflowDetail;
-import org.apache.taverna.mobile.ui.base.BasePresenter;
-import org.apache.taverna.mobile.utils.Constants;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import okhttp3.Headers;
-import okhttp3.MediaType;
-import okhttp3.RequestBody;
-import okhttp3.ResponseBody;
-import retrofit2.Response;
-import retrofit2.adapter.rxjava.HttpException;
-import rx.Observable;
-import rx.Observer;
-import rx.Subscription;
-import rx.android.schedulers.AndroidSchedulers;
-import rx.functions.Func1;
-import rx.schedulers.Schedulers;
-
-
-public class PlayerLoginPresenter extends BasePresenter<PlayerLoginMvpView> {
-
- private static final String TAG = PlayerLoginPresenter.class.getSimpleName();
-
- private DataManager mDataManager;
-
- private Subscription mSubscriptions;
-
- public PlayerLoginPresenter(DataManager dataManager) {
- mDataManager = dataManager;
- }
-
- @Override
- public void attachView(PlayerLoginMvpView mvpView) {
- super.attachView(mvpView);
- }
-
- @Override
- public void detachView() {
- super.detachView();
- if (mSubscriptions != null) mSubscriptions.unsubscribe();
- }
-
- public void playerLogin(final String workflowURL, final String username, final String password, final boolean loginFlag) {
- if (mSubscriptions != null) mSubscriptions.unsubscribe();
-
- if (mSubscriptions != null) mSubscriptions.unsubscribe();
-
- mSubscriptions = mDataManager.downloadWorkflowContent(workflowURL)
- .concatMap(new Func1<ResponseBody, Observable<Response<ResponseBody>>>() {
- @Override
- public Observable<Response<ResponseBody>> call(ResponseBody responseBody) {
-
- StringBuffer sb = new StringBuffer();
- String post = "";
-
- String basicAuth = getEncodedCredential(username, password);
- // mDataManager.getPreferencesHelper()
- // .getUserPlayerCredential();
- boolean flag = false;
- try {
-
- BufferedReader bufferedReader = new BufferedReader(
- new InputStreamReader(responseBody.byteStream()));
-
- String str = "";
-
- while ((str = bufferedReader.readLine()) != null) {
- sb.append(str);
- }
-
- bufferedReader.close();
-
- //String data = "{\"document\":\"data:application/octet-stream;base64," +
- // Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64
- // .URL_SAFE | Base64.NO_WRAP).replace('-', '+') + "\"}";
-
- /// post = "{\"workflow\":" + data + "}";
- flag = true;
- } catch (IOException e) {
- Log.e(TAG, "call: ", e);
- }
- if (flag) {
- RequestBody body =
- RequestBody.create(MediaType.parse("application/vnd.taverna.t2flow+xml"), sb.toString());
-
- return mDataManager.uploadWorkflowContent(body, basicAuth.trim());
- } else {
- return Observable.empty();
- }
-
-
- }
- }).observeOn(AndroidSchedulers.mainThread())
- .subscribeOn(Schedulers.io())
- .subscribe(new Observer<Response<ResponseBody>>() {
-
- @Override
- public void onCompleted() {
-
- }
-
- @Override
- public void onError(Throwable e) {
-
- }
-
- @Override
- public void onNext(Response response) {
- getMvpView().runLocation(response.headers().get("Location"));
- }
- });
-// .observeOn(AndroidSchedulers.mainThread())
-// .subscribeOn(Schedulers.io())
-// .subscribe(new Observer<PlayerWorkflowDetail>() {
-// @Override
-// public void onCompleted() {
-// }
-//
-// @Override
-// public void onError(Throwable e) {
-//
-// getMvpView().showError(R.string.general_run_err);
-// }
-//
-// @Override
-// public void onNext(PlayerWorkflowDetail playerWorkflowDetail) {
-// getMvpView().validCredential(playerWorkflowDetail.getRun().getName());
-// }
-// });
-
-// mSubscriptions = mDataManager.authPlayerUserLoginDetail(getEncodedCredential(username,
-// password), loginFlag)
-// .observeOn(AndroidSchedulers.mainThread())
-// .subscribeOn(Schedulers.io())
-// .subscribe(new Observer<ResponseBody>() {
-// @Override
-// public void onCompleted() {
-//
-// }
-//
-// @Override
-// public void onError(Throwable e) {
-// Log.e(TAG, "onError: ", e);
-// if (e instanceof HttpException) {
-// if (((HttpException) e).code() == 401) {
-// getMvpView().showCredentialError();
-// } else if (((HttpException) e).code() == 406) {
-// getMvpView().validCredential();
-// mDataManager.getPreferencesHelper()
-// .setUserPlayerLoggedInFlagAndCredential(loginFlag,
-// getEncodedCredential(username, password));
-//
-// } else {
-// getMvpView().showError(R.string.servererr);
-// }
-// }
-// }
-//
-// @Override
-// public void onNext(ResponseBody responseBody) {
-// Log.d(TAG, "onCompleted: " + responseBody.byteStream());
-// }
-// });
-
- }
-
- private String getEncodedCredential(String username, String password) {
-
- return "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64
- .NO_WRAP);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/af6dbf77/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunFragment.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunFragment.java b/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunFragment.java
new file mode 100644
index 0000000..2c1f2ab
--- /dev/null
+++ b/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunFragment.java
@@ -0,0 +1,258 @@
+/*
+ * 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.tavernaserver.createrun;
+
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.support.design.widget.Snackbar;
+import android.support.design.widget.TextInputLayout;
+import android.support.v4.app.Fragment;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.CheckBox;
+import android.widget.EditText;
+
+import org.apache.taverna.mobile.R;
+import org.apache.taverna.mobile.data.DataManager;
+import org.apache.taverna.mobile.data.local.PreferencesHelper;
+import org.apache.taverna.mobile.utils.ConnectionInfo;
+import org.apache.taverna.mobile.utils.Constants;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+import rx.Subscription;
+
+
+public class TavernaServerCreateRunFragment extends Fragment implements TavernaServerCreateRunMvpView, View
+ .OnFocusChangeListener {
+
+ @BindView(R.id.etEmail)
+ EditText mEditTextEmail;
+
+ @BindView(R.id.etPassword)
+ EditText mEditTextPassword;
+
+ @BindView(R.id.input_layout_email)
+ TextInputLayout mTextInputEmail;
+
+ @BindView(R.id.input_layout_password)
+ TextInputLayout mTextInputPassword;
+
+ @BindView(R.id.cbRemember)
+ CheckBox mCheckBoxRemember;
+ OnSuccessful mCallback;
+ private DataManager dataManager;
+ private TavernaServerCreateRunPresenter tavernaPlayerCreateRunPresenter;
+ private Subscription mSubscriptions;
+
+ public static TavernaServerCreateRunFragment newInstance() {
+
+ Bundle args = new Bundle();
+
+ TavernaServerCreateRunFragment fragment = new TavernaServerCreateRunFragment();
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ dataManager = new DataManager(new PreferencesHelper(getContext()));
+ tavernaPlayerCreateRunPresenter = new TavernaServerCreateRunPresenter(dataManager);
+
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
+ savedInstanceState) {
+
+ View rootView = inflater.inflate(R.layout.fragment_player_login_layout, container, false);
+ ButterKnife.bind(this, rootView);
+ tavernaPlayerCreateRunPresenter.attachView(this);
+ String email = dataManager.getPreferencesHelper().getPlayerUserEmail();
+ String pw = dataManager.getPreferencesHelper().getPlayerUserPassword();
+ mEditTextEmail.setText(email);
+ mEditTextPassword.setText(pw);
+ return rootView;
+ }
+
+ @Override
+ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ mEditTextEmail.addTextChangedListener(new CustomTextWatcher(mEditTextEmail));
+ mEditTextEmail.setOnFocusChangeListener(this);
+
+ mEditTextPassword.addTextChangedListener(new CustomTextWatcher(mEditTextPassword));
+ mEditTextPassword.setOnFocusChangeListener(this);
+ }
+
+
+ @Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ tavernaPlayerCreateRunPresenter.detachView();
+ }
+
+
+ @OnClick(R.id.bLogin)
+ public void login(View v) {
+ if (ConnectionInfo.isConnectingToInternet(getContext())) {
+ String workflowURL = getActivity().getIntent().getStringExtra(Constants.WORKFLOW_URL);
+
+ if (!mEditTextEmail.getText().toString().trim().isEmpty() && !mEditTextPassword
+ .getText().toString().trim().isEmpty()) {
+
+ tavernaPlayerCreateRunPresenter.playerLogin(workflowURL, mEditTextEmail.getText().toString().trim(),
+ mEditTextPassword.getText().toString().trim(), mCheckBoxRemember
+ .isChecked());
+
+ } else {
+
+ showError(R.string.error_vaild_credential);
+ }
+ } else {
+
+ showError(R.string.no_internet_connection);
+ }
+ }
+
+ @Override
+ public void showError(int stringID) {
+ final Snackbar snackbar = Snackbar.make(mEditTextPassword, getString(stringID), Snackbar
+ .LENGTH_LONG);
+ snackbar.setAction("OK", new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ snackbar.dismiss();
+ }
+ });
+
+ snackbar.show();
+ }
+
+ @Override
+ public void showCredentialError() {
+ mTextInputEmail.setError(getString(R.string.err_login_email));
+ mTextInputPassword.setError(getString(R.string.err_login_password));
+ requestFocus(mEditTextPassword);
+ }
+
+ @Override
+ public void runLocation(String runID) {
+ mCallback.onRunStart(runID);
+ }
+
+ private void validateEmail() {
+
+ if (mEditTextEmail.getText().toString().trim().isEmpty()) {
+ mTextInputEmail.setError(getString(R.string.err_login_email));
+ } else {
+ mTextInputEmail.setError(null);
+ }
+
+
+ }
+
+ private void requestFocus(View view) {
+ if (view.requestFocus()) {
+ getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams
+ .SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+ }
+ }
+
+ private void validatePassword() {
+ if (mEditTextPassword.getText().toString().trim().isEmpty()) {
+ mTextInputPassword.setError(getString(R.string.err_login_password));
+ } else {
+ mTextInputPassword.setError(null);
+ }
+
+
+ }
+
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ switch (v.getId()) {
+ case R.id.etEmail:
+ if (!v.hasFocus()) {
+ validateEmail();
+ }
+ break;
+ case R.id.etPassword:
+ if (!v.hasFocus()) {
+ validatePassword();
+ }
+ break;
+ }
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+
+ try {
+ mCallback = (OnSuccessful) getActivity();
+ } catch (ClassCastException e) {
+ throw new ClassCastException(getActivity().toString()
+ + " must implement OnSuccessful");
+ }
+ }
+
+
+ public interface OnSuccessful {
+ void onRunStart(String runID);
+ }
+
+ private class CustomTextWatcher implements TextWatcher {
+
+ private View view;
+
+ private CustomTextWatcher(View view) {
+ this.view = view;
+ }
+
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ public void afterTextChanged(Editable editable) {
+ switch (view.getId()) {
+ case R.id.etEmail:
+ validateEmail();
+ break;
+ case R.id.etPassword:
+ validatePassword();
+ break;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/af6dbf77/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunMvpView.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunMvpView.java b/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunMvpView.java
new file mode 100644
index 0000000..662f194
--- /dev/null
+++ b/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunMvpView.java
@@ -0,0 +1,32 @@
+/*
+ * 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.tavernaserver.createrun;
+
+import org.apache.taverna.mobile.ui.base.MvpView;
+
+
+public interface TavernaServerCreateRunMvpView extends MvpView {
+
+ void showError(int stringID);
+
+ void showCredentialError();
+
+ void runLocation(String runID);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/af6dbf77/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunPresenter.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunPresenter.java b/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunPresenter.java
new file mode 100644
index 0000000..f250e33
--- /dev/null
+++ b/app/src/main/java/org/apache/taverna/mobile/ui/tavernaserver/createrun/TavernaServerCreateRunPresenter.java
@@ -0,0 +1,195 @@
+/*
+ * 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.tavernaserver.createrun;
+
+import android.util.Base64;
+import android.util.Log;
+
+import org.apache.taverna.mobile.data.DataManager;
+import org.apache.taverna.mobile.ui.base.BasePresenter;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import okhttp3.MediaType;
+import okhttp3.RequestBody;
+import okhttp3.ResponseBody;
+import retrofit2.Response;
+import rx.Observable;
+import rx.Observer;
+import rx.Subscription;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+
+public class TavernaServerCreateRunPresenter extends BasePresenter<TavernaServerCreateRunMvpView> {
+
+ private static final String TAG = TavernaServerCreateRunPresenter.class.getSimpleName();
+
+ private DataManager mDataManager;
+
+ private Subscription mSubscriptions;
+
+ public TavernaServerCreateRunPresenter(DataManager dataManager) {
+ mDataManager = dataManager;
+ }
+
+ @Override
+ public void attachView(TavernaServerCreateRunMvpView mvpView) {
+ super.attachView(mvpView);
+ }
+
+ @Override
+ public void detachView() {
+ super.detachView();
+ if (mSubscriptions != null) mSubscriptions.unsubscribe();
+ }
+
+ public void playerLogin(final String workflowURL, final String username, final String password, final boolean loginFlag) {
+ if (mSubscriptions != null) mSubscriptions.unsubscribe();
+
+ if (mSubscriptions != null) mSubscriptions.unsubscribe();
+
+ mSubscriptions = mDataManager.downloadWorkflowContent(workflowURL)
+ .concatMap(new Func1<ResponseBody, Observable<Response<ResponseBody>>>() {
+ @Override
+ public Observable<Response<ResponseBody>> call(ResponseBody responseBody) {
+
+ StringBuffer sb = new StringBuffer();
+ String post = "";
+
+ String basicAuth = getEncodedCredential(username, password);
+ // mDataManager.getPreferencesHelper()
+ // .getUserPlayerCredential();
+ boolean flag = false;
+ try {
+
+ BufferedReader bufferedReader = new BufferedReader(
+ new InputStreamReader(responseBody.byteStream()));
+
+ String str = "";
+
+ while ((str = bufferedReader.readLine()) != null) {
+ sb.append(str);
+ }
+
+ bufferedReader.close();
+
+ //String data = "{\"document\":\"data:application/octet-stream;base64," +
+ // Base64.encodeToString(sb.toString().getBytes("UTF-8"), Base64
+ // .URL_SAFE | Base64.NO_WRAP).replace('-', '+') + "\"}";
+
+ /// post = "{\"workflow\":" + data + "}";
+ flag = true;
+ } catch (IOException e) {
+ Log.e(TAG, "call: ", e);
+ }
+ if (flag) {
+ RequestBody body =
+ RequestBody.create(MediaType.parse("application/vnd.taverna.t2flow+xml"), sb.toString());
+
+ return mDataManager.uploadWorkflowContent(body, basicAuth.trim());
+ } else {
+ return Observable.empty();
+ }
+
+
+ }
+ }).observeOn(AndroidSchedulers.mainThread())
+ .subscribeOn(Schedulers.io())
+ .subscribe(new Observer<Response<ResponseBody>>() {
+
+ @Override
+ public void onCompleted() {
+
+ }
+
+ @Override
+ public void onError(Throwable e) {
+
+ }
+
+ @Override
+ public void onNext(Response response) {
+ getMvpView().runLocation(response.headers().get("Location"));
+ }
+ });
+// .observeOn(AndroidSchedulers.mainThread())
+// .subscribeOn(Schedulers.io())
+// .subscribe(new Observer<PlayerWorkflowDetail>() {
+// @Override
+// public void onCompleted() {
+// }
+//
+// @Override
+// public void onError(Throwable e) {
+//
+// getMvpView().showError(R.string.general_run_err);
+// }
+//
+// @Override
+// public void onNext(PlayerWorkflowDetail playerWorkflowDetail) {
+// getMvpView().validCredential(playerWorkflowDetail.getRun().getName());
+// }
+// });
+
+// mSubscriptions = mDataManager.authPlayerUserLoginDetail(getEncodedCredential(username,
+// password), loginFlag)
+// .observeOn(AndroidSchedulers.mainThread())
+// .subscribeOn(Schedulers.io())
+// .subscribe(new Observer<ResponseBody>() {
+// @Override
+// public void onCompleted() {
+//
+// }
+//
+// @Override
+// public void onError(Throwable e) {
+// Log.e(TAG, "onError: ", e);
+// if (e instanceof HttpException) {
+// if (((HttpException) e).code() == 401) {
+// getMvpView().showCredentialError();
+// } else if (((HttpException) e).code() == 406) {
+// getMvpView().validCredential();
+// mDataManager.getPreferencesHelper()
+// .setUserPlayerLoggedInFlagAndCredential(loginFlag,
+// getEncodedCredential(username, password));
+//
+// } else {
+// getMvpView().showError(R.string.servererr);
+// }
+// }
+// }
+//
+// @Override
+// public void onNext(ResponseBody responseBody) {
+// Log.d(TAG, "onCompleted: " + responseBody.byteStream());
+// }
+// });
+
+ }
+
+ private String getEncodedCredential(String username, String password) {
+
+ return "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64
+ .NO_WRAP);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-taverna-mobile/blob/af6dbf77/app/src/main/java/org/apache/taverna/mobile/ui/workflowrun/WorkflowRunActivity.java
----------------------------------------------------------------------
diff --git a/app/src/main/java/org/apache/taverna/mobile/ui/workflowrun/WorkflowRunActivity.java b/app/src/main/java/org/apache/taverna/mobile/ui/workflowrun/WorkflowRunActivity.java
index ad44e37..2b8dc32 100644
--- a/app/src/main/java/org/apache/taverna/mobile/ui/workflowrun/WorkflowRunActivity.java
+++ b/app/src/main/java/org/apache/taverna/mobile/ui/workflowrun/WorkflowRunActivity.java
@@ -34,7 +34,8 @@ import org.apache.taverna.mobile.R;
import org.apache.taverna.mobile.data.DataManager;
import org.apache.taverna.mobile.data.local.PreferencesHelper;
import org.apache.taverna.mobile.ui.DownloadingFragment;
-import org.apache.taverna.mobile.ui.playerlogin.PlayerLoginFragment;
+import org.apache.taverna.mobile.ui.tavernaserver.createrun.TavernaServerCreateRunFragment;
+import org.apache.taverna.mobile.ui.tavernaserver.inputs.TavernaServerInputsFragment;
import org.apache.taverna.mobile.utils.Constants;
import org.apache.taverna.mobile.utils.NonSwipeableViewPager;
import org.apache.taverna.mobile.utils.WebViewGenerator;
@@ -47,7 +48,7 @@ import butterknife.ButterKnife;
import static com.raizlabs.android.dbflow.config.FlowManager.getContext;
public class WorkflowRunActivity extends FragmentActivity implements WorkflowRunMvpView,
- PlayerLoginFragment.OnSuccessful {
+ TavernaServerCreateRunFragment.OnSuccessful {
@@ -174,10 +175,9 @@ public class WorkflowRunActivity extends FragmentActivity implements WorkflowRun
public Fragment getItem(int position) {
switch (position) {
case 0:
- return PlayerLoginFragment.newInstance();
+ return TavernaServerCreateRunFragment.newInstance();
case 1:
- return DownloadingFragment.newInstance(getString(R.string
- .downloading_workflow_lable));
+ return TavernaServerInputsFragment.newInstance();
case 2:
return DownloadingFragment.newInstance(getString(R.string
.uploading_workflow_lable));