Added New User Registration button to authentication activity
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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<String, String> getAuthHeaders() {
|
||||
@@ -132,6 +141,7 @@ public class RemoteDbActivity extends AppCompatActivity {
|
||||
// Remote Database Information
|
||||
tv = (TextView)findViewById(R.id.authStatusTv);
|
||||
btn = (Button)findViewById(R.id.auth_button);
|
||||
if (mLm != null) {
|
||||
if (mLm.mWac.isLoggedIn()) {
|
||||
tv.setText("Authenticated");
|
||||
btn.setText("Log Out");
|
||||
@@ -140,6 +150,7 @@ public class RemoteDbActivity extends AppCompatActivity {
|
||||
btn.setText("Log In");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
View.OnClickListener onAuth =
|
||||
new View.OnClickListener() {
|
||||
|
||||
@@ -59,6 +59,12 @@
|
||||
android:layout_weight="1"
|
||||
android:text="@string/authenticate" />
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:id="@+id/RegisterBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/register" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -327,4 +327,5 @@
|
||||
<string name="refreshBtn">Refresh</string>
|
||||
<string name="back">Back</string>
|
||||
<string name="unvalidatedEventsTitle">Unvalidated Seizure Events</string>
|
||||
<string name="register">Register New User</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user