bugfixes and codecleanup

This commit is contained in:
JG-Cody 2021-07-21 21:07:08 +02:00
parent 41df46611d
commit 9cf7519c5a
6 changed files with 133 additions and 28 deletions

View File

@ -65,9 +65,9 @@ import java.util.Objects;
import de.jg_cody.Teraplex.ui.credits.CreditsFragment;
import de.jg_cody.Teraplex.ui.settings.SettingsFragment;
import de.jg_cody.Teraplex.ui.tabs.TabsFragment;
import de.jg_cody.Teraplex.ui.tabs.ListAdapter;
import de.jg_cody.Teraplex.ui.tabs.ListItem;
import de.jg_cody.Teraplex.ui.tabs.TabsFragment;
public class MainActivity extends AppCompatActivity {
@ -216,8 +216,14 @@ public class MainActivity extends AppCompatActivity {
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
@ -232,8 +238,14 @@ public class MainActivity extends AppCompatActivity {
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
@ -461,8 +473,36 @@ public class MainActivity extends AppCompatActivity {
public void menurighttopdocumentation(MenuItem i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.jg-cody.de/"));
startActivity(in);
AlertDialog mDialog = new AlertDialog.Builder(this)
.setTitle(getString(R.string.menu_documentation))
.setMessage(getString(R.string.you_will_be_redirected))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vr.vibrate(100);
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.jg-cody.de/"));
startActivity(in);
}
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
public void menurighttopcloseapp(MenuItem i) {

View File

@ -124,8 +124,14 @@ public class HomeFragment extends Fragment {
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null)
.create();
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
@ -154,7 +160,7 @@ public class HomeFragment extends Fragment {
channel.connect(3 * 1000);
session.disconnect();
System.out.println("DISCONNECT");
getActivity().runOnUiThread(new Runnable() {
requireActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), "CONNECTED", Toast.LENGTH_SHORT).show();
@ -179,11 +185,27 @@ public class HomeFragment extends Fragment {
}
});
} catch (Exception e) {
getActivity().runOnUiThread(new Runnable() {
requireActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
e.printStackTrace();
Toast.makeText(getContext(), "INVALID INPUT", Toast.LENGTH_SHORT).show();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.unable_to_connect))
.setMessage(getString(R.string.try_again))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
});
@ -233,7 +255,7 @@ public class HomeFragment extends Fragment {
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) v.getContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
@ -251,8 +273,14 @@ public class HomeFragment extends Fragment {
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.create();
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
@ -293,8 +321,14 @@ public class HomeFragment extends Fragment {
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.create();
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
@ -307,7 +341,7 @@ public class HomeFragment extends Fragment {
togglepassword.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (isPasswordVisible == true) {
if (isPasswordVisible) {
passwordInput.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
isPasswordVisible = false;
} else {

View File

@ -91,8 +91,14 @@ public class SettingsFragment extends Fragment {
})
// A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null)
.create();
.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();

View File

@ -1,8 +1,11 @@
package de.jg_cody.Teraplex.ui.terminal;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@ -18,6 +21,8 @@ import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import java.util.Objects;
import de.jg_cody.Teraplex.R;
public class TerminalFragment extends Fragment {
@ -42,8 +47,24 @@ public class TerminalFragment extends Fragment {
user = prefs.getString("user", null);
password = prefs.getString("password", null);
ip = prefs.getString("ip", null);
if (user == null || ip == null) {
Toast.makeText(getContext(), getString(R.string.login_saved), Toast.LENGTH_SHORT).show();
if (user == null || ip == null || password == null) {
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.unable_to_connect))
.setMessage(getString(R.string.please_login))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
}
}).create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
else {
@ -74,7 +95,6 @@ public class TerminalFragment extends Fragment {
{
if (terminal != null) {
terminal.sendTerminalCommand(terminal_edit_text.getText().toString());
Toast.makeText(getContext(), getString(R.string.login_saved), Toast.LENGTH_SHORT).show();
}
handled=true;

View File

@ -56,7 +56,7 @@
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:ems="10"
android:hint="type commands"
android:hint="TYPE YOUR COMMAND"
android:imeOptions="actionDone"
android:inputType="text"
android:textColor="#FFFFFF"
@ -71,6 +71,7 @@
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/button_right"
app:backgroundTint="@null"
android:text="SEND"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

View File

@ -24,17 +24,17 @@
<string name="felder_dürfen_nicht_leer_sein">INPUTFIELDS CANT BE EMPTY!</string>
<string name="login_saved">LOGIN-DATA SAVED!</string>
//konsole
//terminal
<string name="console">CONSOLE</string>
<string name="button_send_command">SEND COMMAND</string>
<string name="servercommands">SERVERCOMMANDS</string>
<string name="reboot">REBOOT</string>
<string name="shutdown">SHUTDOWN</string>
<string name="unable_to_connect">UNABLE TO CONNECT</string>
<string name="try_again">PLEASE TRY AGAIN</string>
//zeitgesteuerte kommandos
<string name="timed_commands">TIMED COMMANDS</string>
//main
<string name="command">COMMAND</string>
<string name="send_timed_command">SET TIMED COMMAND</string>
//settings
<string name="farben">COLORS</string>
@ -70,6 +70,8 @@
<string name="menu_add">ADD TAB</string>
<string name="menu_remove">REMOVE TABS</string>
//menus
<string name="you_will_be_redirected">YOU WILL BE REDIRECTED TO THE APP-DOCUMENTATION ON OUR WEBSITE</string>
<string name="menu_settings">SETTINGS</string>
<string name="menu_documentation">QUESTION</string>
<string name="menu_about">ABOUT</string>
@ -77,6 +79,8 @@
<string name="menu_language">LANGUAGE</string>
<string name="menu_close">CLOSE</string>
<string name="yes">YES</string>
<string name="no">NO</string>
<string name="ok">OK</string>
<string name="cancel">CANCEL</string>
<string name="invalid">INVALID INPUT</string>