From 3d74d80b7a1bb078f375e13e80f829476284f7a9 Mon Sep 17 00:00:00 2001 From: JG-Cody Date: Fri, 23 Feb 2024 19:22:53 +0100 Subject: [PATCH] zusammenkopiert aus Teraplex und CodeGuard --- .../com/example/onetap_ssh/MainActivity.java | 61 ++++++- .../onetap_ssh/fragment/AboutFragment.java | 35 ++++ .../onetap_ssh/util/NavigationUtil.java | 86 +++++++++ .../example/onetap_ssh/util/SettingsUtil.java | 2 +- app/src/main/res/drawable/add_black_24dp.xml | 9 + app/src/main/res/drawable/button_round.xml | 39 +++++ app/src/main/res/drawable/code_black_24dp.xml | 9 + app/src/main/res/drawable/home_black_24dp.xml | 9 + app/src/main/res/drawable/login_24px.xml | 9 + app/src/main/res/drawable/logout_24px.xml | 9 + .../res/drawable/mode_edit_black_24dp.xml | 9 + .../res/drawable/power_settings_new_24px.xml | 9 + .../main/res/drawable/remove_black_24dp.xml | 9 + .../main/res/drawable/restart_alt_24px.xml | 12 ++ app/src/main/res/drawable/teraplex_logo.xml | 58 +++++++ .../res/drawable/visibility_black_24dp.xml | 9 + app/src/main/res/layout/app_bar_main.xml | 8 +- app/src/main/res/layout/fragment_home.xml | 163 ++++++++++++++++-- app/src/main/res/layout/nav_header_main.xml | 20 ++- app/src/main/res/layout/switch_item.xml | 11 ++ .../main/res/menu/activity_main_drawer.xml | 47 ++++- app/src/main/res/menu/main.xml | 9 - app/src/main/res/menu/menu_main.xml | 23 +++ .../main/res/navigation/mobile_navigation.xml | 10 +- app/src/main/res/values/strings.xml | 103 +++++++++++ 25 files changed, 719 insertions(+), 49 deletions(-) create mode 100644 app/src/main/java/com/example/onetap_ssh/fragment/AboutFragment.java create mode 100644 app/src/main/java/com/example/onetap_ssh/util/NavigationUtil.java create mode 100644 app/src/main/res/drawable/add_black_24dp.xml create mode 100644 app/src/main/res/drawable/button_round.xml create mode 100644 app/src/main/res/drawable/code_black_24dp.xml create mode 100644 app/src/main/res/drawable/home_black_24dp.xml create mode 100644 app/src/main/res/drawable/login_24px.xml create mode 100644 app/src/main/res/drawable/logout_24px.xml create mode 100644 app/src/main/res/drawable/mode_edit_black_24dp.xml create mode 100644 app/src/main/res/drawable/power_settings_new_24px.xml create mode 100644 app/src/main/res/drawable/remove_black_24dp.xml create mode 100644 app/src/main/res/drawable/restart_alt_24px.xml create mode 100644 app/src/main/res/drawable/teraplex_logo.xml create mode 100644 app/src/main/res/drawable/visibility_black_24dp.xml create mode 100644 app/src/main/res/layout/switch_item.xml delete mode 100644 app/src/main/res/menu/main.xml create mode 100644 app/src/main/res/menu/menu_main.xml diff --git a/app/src/main/java/com/example/onetap_ssh/MainActivity.java b/app/src/main/java/com/example/onetap_ssh/MainActivity.java index 00d0eaa..dcb1495 100644 --- a/app/src/main/java/com/example/onetap_ssh/MainActivity.java +++ b/app/src/main/java/com/example/onetap_ssh/MainActivity.java @@ -1,12 +1,21 @@ package com.example.onetap_ssh; import android.os.Bundle; +import android.view.MenuItem; import android.view.View; import android.view.Menu; +import com.example.onetap_ssh.fragment.AboutFragment; +import com.example.onetap_ssh.fragment.SettingsFragment; +import com.example.onetap_ssh.util.DialogUtil; +import com.example.onetap_ssh.util.NavigationUtil; +import com.example.onetap_ssh.util.SettingsUtil; +import com.example.onetap_ssh.util.ThemeUtil; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.navigation.NavigationView; +import androidx.appcompat.app.ActionBar; +import androidx.fragment.app.Fragment; import androidx.navigation.NavController; import androidx.navigation.Navigation; import androidx.navigation.ui.AppBarConfiguration; @@ -16,11 +25,17 @@ import androidx.appcompat.app.AppCompatActivity; import com.example.onetap_ssh.databinding.ActivityMainBinding; +import java.util.UUID; + public class MainActivity extends AppCompatActivity { private AppBarConfiguration mAppBarConfiguration; private ActivityMainBinding binding; + private boolean fullyLaunched; + + private boolean lockOnStop = true; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -41,18 +56,20 @@ public class MainActivity extends AppCompatActivity { // Passing each menu ID as a set of Ids because each // menu should be considered as top level destinations. mAppBarConfiguration = new AppBarConfiguration.Builder( - R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow) + R.id.nav_home, R.id.nav_settings, R.id.nav_about) .setOpenableLayout(drawer) .build(); NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main); NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration); NavigationUI.setupWithNavController(navigationView, navController); + + launchApp(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. - getMenuInflater().inflate(R.menu.main, menu); + getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @@ -62,4 +79,44 @@ public class MainActivity extends AppCompatActivity { return NavigationUI.navigateUp(navController, mAppBarConfiguration) || super.onSupportNavigateUp(); } + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } + public void openSettings(MenuItem item) { + NavigationUtil.navigate(this, SettingsFragment.class, null); + } + public void openAbout(MenuItem item) { + NavigationUtil.navigate(this, AboutFragment.class, null); + } + public void lockApp(MenuItem item) { + + } + private void launchApp() { + fullyLaunched = true; + lockOnStop = true; + + ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + ThemeUtil.loadBackground(this); + + + if(SettingsUtil.isFirstLaunch(this) && SettingsUtil.getGroups(this).isEmpty()) { + SettingsUtil.addGroup(this, UUID.randomUUID().toString(), "My Codes"); + DialogUtil.showYesNo(this, R.string.enable_encryption_title, R.string.enable_encryption_message, () -> NavigationUtil.navigate(this, SettingsFragment.class, null), null); + SettingsUtil.setFirstLaunch(this, false); + } + + Fragment fragment = NavigationUtil.getCurrentFragment(this); + + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/onetap_ssh/fragment/AboutFragment.java b/app/src/main/java/com/example/onetap_ssh/fragment/AboutFragment.java new file mode 100644 index 0000000..78bfdbe --- /dev/null +++ b/app/src/main/java/com/example/onetap_ssh/fragment/AboutFragment.java @@ -0,0 +1,35 @@ +package com.example.onetap_ssh.fragment; + +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.example.onetap_ssh.R; +import com.example.onetap_ssh.databinding.FragmentAboutBinding; + +public class AboutFragment extends NamedFragment { + + @Override + public String getName() { + return requireActivity().getString(R.string.fragment_about); + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + FragmentAboutBinding binding = FragmentAboutBinding.inflate(inflater); + try { + PackageManager manager = requireContext().getPackageManager(); + PackageInfo info = manager.getPackageInfo(requireContext().getPackageName(), 0); + String version = info.versionName; + binding.appVersion.setText(version); + } catch (PackageManager.NameNotFoundException ignored) {} + return binding.getRoot(); + } +} diff --git a/app/src/main/java/com/example/onetap_ssh/util/NavigationUtil.java b/app/src/main/java/com/example/onetap_ssh/util/NavigationUtil.java new file mode 100644 index 0000000..c27995c --- /dev/null +++ b/app/src/main/java/com/example/onetap_ssh/util/NavigationUtil.java @@ -0,0 +1,86 @@ +package com.example.onetap_ssh.util; + +import android.os.Bundle; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import com.example.onetap_ssh.R; +//import com.example.onetap_ssh.fragment.MenuDrawerFragment; +import com.example.onetap_ssh.fragment.NamedFragment; + +public class NavigationUtil { + + private static void updateActivity(AppCompatActivity activity, NamedFragment newFragment) { + ActionBar bar = activity.getSupportActionBar(); + if(newFragment == null) newFragment = (NamedFragment) getCurrentFragment(activity.getSupportFragmentManager()); + if(bar != null) bar.setTitle(newFragment.getName()); + activity.invalidateMenu(); + } + + public static void navigate(AppCompatActivity activity, NamedFragment fragment) { + FragmentManager manager = activity.getSupportFragmentManager(); + navigate(manager, fragment, () -> updateActivity(activity, fragment)); + } + + public static void navigate(AppCompatActivity activity, Class fragmentClass, Bundle args) { + FragmentManager manager = activity.getSupportFragmentManager(); + NamedFragment fragment = instantiateFragment(manager, fragmentClass, args); + navigate(activity, fragment); + } + + + public static void navigate(Fragment currentFragment, Class fragmentClass, Bundle args) { + navigate((AppCompatActivity) currentFragment.requireActivity(), fragmentClass, args); + } + + public static void openOverlay(AppCompatActivity activity, NamedFragment overlay) { + FragmentManager manager = activity.getSupportFragmentManager(); + manager.beginTransaction() + .setReorderingAllowed(true) + .add(R.id.nav_host_fragment_content_main, overlay) + .runOnCommit(() -> updateActivity(activity, overlay)) + .commit(); + } + + public static void openOverlay(Fragment currentFragment, NamedFragment overlay) { + AppCompatActivity activity = (AppCompatActivity) currentFragment.requireActivity(); + openOverlay(activity, overlay); + } + + public static void closeOverlay(Fragment currentFragment) { + AppCompatActivity activity = (AppCompatActivity) currentFragment.requireActivity(); + FragmentManager manager = activity.getSupportFragmentManager(); + manager.beginTransaction() + .setReorderingAllowed(true) + .remove(currentFragment) + .runOnCommit(() -> updateActivity(activity, null)) + .commit(); + } + + @SuppressWarnings("unchecked") + private static T instantiateFragment(FragmentManager manager, Class fragmentClass, Bundle args) { + T fragment = (T) manager.getFragmentFactory().instantiate(ClassLoader.getSystemClassLoader(), fragmentClass.getName()); + if(args != null) fragment.setArguments(args); + return fragment; + } + + private static void navigate(FragmentManager manager, Fragment fragment, Runnable onCommit) { + manager.beginTransaction() + .setReorderingAllowed(true) + .replace(R.id.nav_host_fragment_content_main, fragment) + .runOnCommit(onCommit) + .commit(); + } + + public static Fragment getCurrentFragment(AppCompatActivity activity) { + return getCurrentFragment(activity.getSupportFragmentManager()); + } + + public static Fragment getCurrentFragment(FragmentManager manager) { + return manager.findFragmentById(R.id.nav_host_fragment_content_main); + } + +} diff --git a/app/src/main/java/com/example/onetap_ssh/util/SettingsUtil.java b/app/src/main/java/com/example/onetap_ssh/util/SettingsUtil.java index 2cfb146..def2232 100644 --- a/app/src/main/java/com/example/onetap_ssh/util/SettingsUtil.java +++ b/app/src/main/java/com/example/onetap_ssh/util/SettingsUtil.java @@ -203,7 +203,7 @@ public class SettingsUtil { try { return Theme.valueOf(themeId); }catch(IllegalArgumentException e) { - return Theme.BLUE_GREEN; + return Theme.RED_BLUE; } } diff --git a/app/src/main/res/drawable/add_black_24dp.xml b/app/src/main/res/drawable/add_black_24dp.xml new file mode 100644 index 0000000..be33fe4 --- /dev/null +++ b/app/src/main/res/drawable/add_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/button_round.xml b/app/src/main/res/drawable/button_round.xml new file mode 100644 index 0000000..ab3242a --- /dev/null +++ b/app/src/main/res/drawable/button_round.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/code_black_24dp.xml b/app/src/main/res/drawable/code_black_24dp.xml new file mode 100644 index 0000000..ecd966b --- /dev/null +++ b/app/src/main/res/drawable/code_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/home_black_24dp.xml b/app/src/main/res/drawable/home_black_24dp.xml new file mode 100644 index 0000000..a35f1ef --- /dev/null +++ b/app/src/main/res/drawable/home_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/login_24px.xml b/app/src/main/res/drawable/login_24px.xml new file mode 100644 index 0000000..2f98d93 --- /dev/null +++ b/app/src/main/res/drawable/login_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/logout_24px.xml b/app/src/main/res/drawable/logout_24px.xml new file mode 100644 index 0000000..4c70224 --- /dev/null +++ b/app/src/main/res/drawable/logout_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/mode_edit_black_24dp.xml b/app/src/main/res/drawable/mode_edit_black_24dp.xml new file mode 100644 index 0000000..df26add --- /dev/null +++ b/app/src/main/res/drawable/mode_edit_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/power_settings_new_24px.xml b/app/src/main/res/drawable/power_settings_new_24px.xml new file mode 100644 index 0000000..e6ecb5c --- /dev/null +++ b/app/src/main/res/drawable/power_settings_new_24px.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/remove_black_24dp.xml b/app/src/main/res/drawable/remove_black_24dp.xml new file mode 100644 index 0000000..41d4592 --- /dev/null +++ b/app/src/main/res/drawable/remove_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/restart_alt_24px.xml b/app/src/main/res/drawable/restart_alt_24px.xml new file mode 100644 index 0000000..a42071f --- /dev/null +++ b/app/src/main/res/drawable/restart_alt_24px.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/teraplex_logo.xml b/app/src/main/res/drawable/teraplex_logo.xml new file mode 100644 index 0000000..fae2fc0 --- /dev/null +++ b/app/src/main/res/drawable/teraplex_logo.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/visibility_black_24dp.xml b/app/src/main/res/drawable/visibility_black_24dp.xml new file mode 100644 index 0000000..6fcd57a --- /dev/null +++ b/app/src/main/res/drawable/visibility_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index f9421c6..1900dbe 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -9,14 +9,12 @@ + android:fitsSystemWindows="true"> - + android:layout_height="?attr/actionBarSize" /> diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index f3d9b08..4515018 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -1,22 +1,165 @@ - - + +