diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/Terminal/TerminalFragment.java b/app/src/main/java/de/jg_cody/Teraplex/ui/Terminal/TerminalFragment.java index 550e9d6..c8a836c 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/Terminal/TerminalFragment.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/Terminal/TerminalFragment.java @@ -1,5 +1,7 @@ package de.jg_cody.Teraplex.ui.Terminal; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -8,6 +10,7 @@ import android.view.ViewGroup; import android.widget.EditText; import android.widget.ScrollView; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; @@ -23,6 +26,7 @@ public class TerminalFragment extends Fragment { TextView terminal_textView; Terminal terminal; ScrollView scrollView; + public static String user, password, ip; private TerminalViewModel terminalViewModel; @@ -31,51 +35,76 @@ public class TerminalFragment extends Fragment { terminalViewModel = new ViewModelProvider(this).get(TerminalViewModel.class); View root = inflater.inflate(R.layout.fragment_terminal, container, false); - scrollView = (ScrollView) root.findViewById((R.id.scrollView)); - terminal_edit_text = (EditText) root.findViewById(R.id.terminal_edit_text); - terminal_edit_text.setOnKeyListener(new View.OnKeyListener() { - @Override - public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { - if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { - terminal.sendTerminalCommand(terminal_edit_text.getText().toString()); + SharedPreferences prefs = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); + 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(); + + } + else { + Toast.makeText(getContext(), ("test"), Toast.LENGTH_SHORT).show(); + scrollView = (ScrollView) root.findViewById((R.id.scrollView)); + terminal_edit_text = (EditText) root.findViewById(R.id.terminal_edit_text); + terminal_edit_text.setOnKeyListener(new View.OnKeyListener() { + @Override + public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { + if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { + terminal.sendTerminalCommand(terminal_edit_text.getText().toString()); - } - return false; - } - }); - terminal_textView = (TextView) root.findViewById(R.id.terminal_textView); - new Thread() { - public void run() { - terminal = new Terminal(); - while (true) { - try { - requireActivity().runOnUiThread(new Runnable() { - - @Override + } else { + terminal_textView = (TextView) root.findViewById(R.id.terminal_textView); + new Thread() { public void run() { - boolean atBottom = scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY()); - terminal_textView.setText(terminal.getTerminalOutput()); - System.out.println(atBottom); + terminal = new Terminal(); + boolean isFragmentActive = true; + while (isFragmentActive == true) { + Fragment myFragment = (Fragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_terminal); + if (myFragment == null) { - terminal_textView.invalidate(); - scrollView.invalidate(); - scrollView.fullScroll(View.FOCUS_DOWN); + isFragmentActive = false; + } + else if (myFragment.isVisible()) + { + isFragmentActive = false; + } + try { + requireActivity().runOnUiThread(new Runnable() { + + @Override + public void run() { + boolean atBottom = scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY()); + terminal_textView.setText(terminal.getTerminalOutput()); + System.out.println(atBottom); + + terminal_textView.invalidate(); + scrollView.invalidate(); + scrollView.fullScroll(View.FOCUS_DOWN); + + } + }); + Thread.sleep(250); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } - }); - Thread.sleep(250); - } catch (InterruptedException e) { - e.printStackTrace(); + }.start(); } + return false; + } - } - }.start(); + }); + } return root; } + @Override public void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/intro/IntroFragment.java b/app/src/main/java/de/jg_cody/Teraplex/ui/intro/IntroFragment.java index 0efa770..7194a22 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/intro/IntroFragment.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/intro/IntroFragment.java @@ -54,7 +54,7 @@ public class IntroFragment extends Fragment { setDimension(); mMediaPlayer = mediaPlayer; // We want our video to play over and over so we set looping to true. - mMediaPlayer.setLooping(false); + mMediaPlayer.setLooping(true); // We then seek to the current position if it has been set and play the video. if (mCurrentVideoPosition != 0) { mMediaPlayer.seekTo(mCurrentVideoPosition); diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index aaa2e24..782394f 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -91,12 +91,13 @@ android:id="@+id/text_home" android:layout_width="200dp" android:layout_height="wrap_content" - android:layout_marginTop="100dp" + android:layout_marginBottom="50dp" android:gravity="center_horizontal" android:text="@string/Welcome_to_your_HOMEAUTOMATION_APP" android:textAlignment="center" android:textColor="@color/mtrl_btn_text_color_selector" android:textSize="20sp" + app:layout_constraintBottom_toTopOf="@+id/reboot" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/fragment_intro.xml b/app/src/main/res/layout/fragment_intro.xml index aa017a8..265da26 100644 --- a/app/src/main/res/layout/fragment_intro.xml +++ b/app/src/main/res/layout/fragment_intro.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@drawable/background" + android:background="#000000" tools:context=".ui.intro.IntroFragment">