Add ability to manually enter login server credentials

This commit is contained in:
Garrett Mills 2021-05-12 12:41:05 -05:00
parent 398903588e
commit 3decdf19eb
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
7 changed files with 134 additions and 12 deletions

View File

@ -13,7 +13,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.StarshipHyperlink">
<activity android:name=".LoginTokenScannerActivity"></activity>
<activity android:name=".LoginTokenFormActivity"></activity>
<activity android:name=".LoginTokenScannerActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -0,0 +1,40 @@
package dev.garrettmills.starship.hyperlink;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import dev.garrettmills.starship.hyperlink.util.LoginToken;
public class LoginTokenFormActivity extends AppCompatActivity {
EditText serverInput;
EditText tokenInput;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_token_form);
serverInput = findViewById(R.id.activity_login_token_form_serverEditText);
tokenInput = findViewById(R.id.activity_login_token_form_tokenEditText);
}
public void onContinueClick(View view) {
if ( serverInput.getText().length() > 0 && tokenInput.getText().length() > 0 ) {
String loginToken = "hyperlink|" + serverInput.getText().toString() + "|" + tokenInput.getText().toString();
if ( !LoginToken.isValidLoginToken(loginToken) ) {
Toast.makeText(this, "Invalid credentials. Make sure both the server and token are the proper format.", Toast.LENGTH_LONG);
return;
}
Intent result = new Intent();
result.putExtra(Hyperlink.EXTRA_LOGIN_TOKEN, loginToken);
setResult(RESULT_OK, result);
finish();
}
}
}

View File

@ -104,7 +104,7 @@ public class LoginTokenScannerActivity extends AppCompatActivity implements QRCo
}
public void onQRCodeFound(String qrCode) {
if ( !isValidLoginToken(qrCode) ) return;
if ( !LoginToken.isValidLoginToken(qrCode) ) return;
Intent result = new Intent();
result.putExtra(Hyperlink.EXTRA_LOGIN_TOKEN, qrCode);
@ -114,13 +114,4 @@ public class LoginTokenScannerActivity extends AppCompatActivity implements QRCo
}
public void onQRCodeNotFound() {}
public boolean isValidLoginToken(String token) {
try {
new LoginToken(token);
return true;
} catch (InvalidLoginTokenException e) {
return false;
}
}
}

View File

@ -21,6 +21,11 @@ public class MainActivity extends AppCompatActivity {
startActivityForResult(intent, Hyperlink.REQUEST_LOGIN_TOKEN);
}
public void onEnterCredentialsClick(View view) {
Intent intent = new Intent(this, LoginTokenFormActivity.class);
startActivityForResult(intent, Hyperlink.REQUEST_LOGIN_TOKEN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

View File

@ -1,6 +1,15 @@
package dev.garrettmills.starship.hyperlink.util;
public class LoginToken {
public static boolean isValidLoginToken(String token) {
try {
new LoginToken(token);
return true;
} catch (InvalidLoginTokenException e) {
return false;
}
}
private String _server;
private String _token;

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_margin="64dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Hyperlink Server Information"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Server Address"
android:textSize="22sp" />
<EditText
android:id="@+id/activity_login_token_form_serverEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="https://hyperlink.url/"
android:inputType="text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Token"
android:textSize="22sp" />
<EditText
android:id="@+id/activity_login_token_form_tokenEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />
<Button
android:id="@+id/activity_login_token_form_loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onContinueClick"
android:text="Continue" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>

View File

@ -7,7 +7,7 @@
tools:context=".MainActivity">
<Button
android:id="@+id/activity_main_qrCodeFoundButton"
android:id="@+id/activity_main_scannerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onScanTokenClick"
@ -18,4 +18,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/activity_main_manualButton"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_marginTop="32dp"
android:onClick="onEnterCredentialsClick"
android:text="Enter Credentials"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/activity_main_scannerButton" />
</androidx.constraintlayout.widget.ConstraintLayout>