diff --git a/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java index d8d16a6..e26fb79 100644 --- a/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/AuthenticateActivity.java @@ -1,7 +1,9 @@ package uk.org.openseizuredetector; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Handler; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; @@ -46,6 +48,8 @@ public class AuthenticateActivity extends AppCompatActivity { logoutCancelBtn.setOnClickListener(onCancel); Button logoutBtn = (Button)findViewById(R.id.logoutBtn); logoutBtn.setOnClickListener(onLogout); + Button registerBtn = (Button) findViewById(R.id.RegisterBtn); + registerBtn.setOnClickListener(onRegister); mUnameEt = (EditText) findViewById(R.id.username); mPasswdEt = (EditText) findViewById(R.id.password); @@ -158,6 +162,22 @@ public class AuthenticateActivity extends AppCompatActivity { } }; + View.OnClickListener onRegister = + new View.OnClickListener() { + @Override + public void onClick(View view) { + Log.d(TAG, "onRegisterBtn"); + //Intent i; + //i = new Intent(getApplicationContext(), RemoteDbActivity.class); + //i.putExtra("url", "https://osdapi.ddns.net/static/register.html"); + //startActivity(i); + String url = "https://osdapi.ddns.net/static/register.html"; + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(url)); + startActivity(i); + } + }; + private void saveAuthToken(String tokenStr) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); prefs.edit().putString(TOKEN_ID, tokenStr).commit(); diff --git a/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java b/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java index 439a0dc..a05712d 100644 --- a/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java +++ b/app/src/main/java/uk/org/openseizuredetector/RemoteDbActivity.java @@ -29,6 +29,7 @@ public class RemoteDbActivity extends AppCompatActivity { private OsdUtil mUtil; final Handler serverStatusHandler = new Handler(); private String TOKEN_ID = "webApiAuthToken"; + private String mRemtoteUrl = "https://osdapi.ddns.net/"; @Override @@ -40,6 +41,14 @@ public class RemoteDbActivity extends AppCompatActivity { mUtil = new OsdUtil(getApplicationContext(), serverStatusHandler); mConnection = new SdServiceConnection(getApplicationContext()); mUtil.bindToServer(getApplicationContext(), mConnection); + + Bundle extras = getIntent().getExtras(); + if (extras != null) { + String remoteUrl = extras.getString("url"); + mRemtoteUrl = remoteUrl; + Log.d(TAG, "onCreate - mRemoteUrl=" + mRemtoteUrl); + } + waitForConnection(); //mLm= new LogManager(mContext); @@ -62,7 +71,7 @@ public class RemoteDbActivity extends AppCompatActivity { // the mConnection to bind to the service, so we delay half a second to give it chance // to connect before trying to update the UI for the first time (it happens again periodically using the uiTimer) if (mConnection.mBound) { - Log.v(TAG, "waitForConnection - Bound!"); + Log.d(TAG, "waitForConnection - Bound!"); initialiseServiceConnection(); } else { Log.v(TAG, "waitForConnection - waiting..."); @@ -77,6 +86,7 @@ public class RemoteDbActivity extends AppCompatActivity { private void initialiseServiceConnection() { mLm = mConnection.mSdServer.mLm; + mWebView.loadUrl(mRemtoteUrl, getAuthHeaders()); //mWac = mConnection.mSdServer.mLm.mWac; } @@ -99,7 +109,6 @@ public class RemoteDbActivity extends AppCompatActivity { protected void onResume() { super.onResume(); startUiTimer(); - mWebView.loadUrl("https://osdapi.ddns.net/api/events/", getAuthHeaders()); } private HashMap getAuthHeaders() { @@ -132,12 +141,14 @@ public class RemoteDbActivity extends AppCompatActivity { // Remote Database Information tv = (TextView)findViewById(R.id.authStatusTv); btn = (Button)findViewById(R.id.auth_button); - if (mLm.mWac.isLoggedIn()) { - tv.setText("Authenticated"); - btn.setText("Log Out"); - } else { - tv.setText("NOT AUTHENTICATED"); - btn.setText("Log In"); + if (mLm != null) { + if (mLm.mWac.isLoggedIn()) { + tv.setText("Authenticated"); + btn.setText("Log Out"); + } else { + tv.setText("NOT AUTHENTICATED"); + btn.setText("Log In"); + } } } diff --git a/app/src/main/res/layout/activity_authenticate.xml b/app/src/main/res/layout/activity_authenticate.xml index 93a9c90..f71b98e 100644 --- a/app/src/main/res/layout/activity_authenticate.xml +++ b/app/src/main/res/layout/activity_authenticate.xml @@ -59,6 +59,12 @@ android:layout_weight="1" android:text="@string/authenticate" /> +