Add NoGroupsFragment, Navigate to main fragment if current group deleted

This commit is contained in:
MrLetsplay 2023-10-19 19:41:24 +02:00
parent 09a76c29fe
commit bea0c1499d
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
7 changed files with 81 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import com.cringe_studios.code_guard.fragment.AboutFragment;
import com.cringe_studios.code_guard.fragment.EditOTPFragment; import com.cringe_studios.code_guard.fragment.EditOTPFragment;
import com.cringe_studios.code_guard.fragment.GroupFragment; import com.cringe_studios.code_guard.fragment.GroupFragment;
import com.cringe_studios.code_guard.fragment.NamedFragment; import com.cringe_studios.code_guard.fragment.NamedFragment;
import com.cringe_studios.code_guard.fragment.NoGroupsFragment;
import com.cringe_studios.code_guard.fragment.SettingsFragment; import com.cringe_studios.code_guard.fragment.SettingsFragment;
import com.cringe_studios.code_guard.icon.IconPack; import com.cringe_studios.code_guard.icon.IconPack;
import com.cringe_studios.code_guard.icon.IconPackException; import com.cringe_studios.code_guard.icon.IconPackException;
@ -260,12 +261,16 @@ public class MainActivity extends BaseActivity {
} }
} }
private void navigateToMainGroup() { public void navigateToMainGroup() {
List<String> groups = SettingsUtil.getGroups(this); List<String> groups = SettingsUtil.getGroups(this);
if(!groups.isEmpty()) { if(!groups.isEmpty()) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(GroupFragment.BUNDLE_GROUP, SettingsUtil.getGroups(this).get(0)); bundle.putString(GroupFragment.BUNDLE_GROUP, SettingsUtil.getGroups(this).get(0));
NavigationUtil.navigate(this, GroupFragment.class, bundle); NavigationUtil.navigate(this, GroupFragment.class, bundle);
}else {
ActionBar bar = getSupportActionBar();
if(bar != null) bar.setTitle(R.string.app_name);
NavigationUtil.navigate(this, NoGroupsFragment.class, null);
} }
} }

View File

@ -71,6 +71,10 @@ public class GroupFragment extends NamedFragment {
return binding.getRoot(); return binding.getRoot();
} }
public String getGroupID() {
return groupID;
}
private void saveOTPs() { private void saveOTPs() {
OTPDatabase.promptLoadDatabase(requireActivity(), () -> { OTPDatabase.promptLoadDatabase(requireActivity(), () -> {
try { try {

View File

@ -7,7 +7,9 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.cringe_studios.code_guard.MainActivity;
import com.cringe_studios.code_guard.R; import com.cringe_studios.code_guard.R;
import com.cringe_studios.code_guard.crypto.CryptoException; import com.cringe_studios.code_guard.crypto.CryptoException;
import com.cringe_studios.code_guard.databinding.FragmentMenuDrawerBinding; import com.cringe_studios.code_guard.databinding.FragmentMenuDrawerBinding;
@ -70,6 +72,13 @@ public class MenuDrawerFragment extends BottomSheetDialogFragment {
String id = UUID.randomUUID().toString(); String id = UUID.randomUUID().toString();
SettingsUtil.addGroup(requireContext(), id, groupName); SettingsUtil.addGroup(requireContext(), id, groupName);
groupListAdapter.add(id); groupListAdapter.add(id);
Fragment fragment = NavigationUtil.getCurrentFragment(getParentFragmentManager());
if(fragment instanceof NoGroupsFragment) {
Bundle bundle = new Bundle();
bundle.putString(GroupFragment.BUNDLE_GROUP, id);
NavigationUtil.navigate(this, GroupFragment.class, bundle);
}
}, null); }, null);
} }
@ -95,6 +104,15 @@ public class MenuDrawerFragment extends BottomSheetDialogFragment {
removeGroup(item.getGroupId()); removeGroup(item.getGroupId());
} }
Fragment fragment = NavigationUtil.getCurrentFragment(getParentFragmentManager());
if(fragment instanceof GroupFragment) {
GroupFragment groupFragment = (GroupFragment) fragment;
if(!SettingsUtil.getGroups(requireContext()).contains(groupFragment.getGroupID())) {
// Currently selected group was deleted, navigate to main group
((MainActivity) requireActivity()).navigateToMainGroup();
}
}
groupListAdapter.finishEditing(); groupListAdapter.finishEditing();
}, null); }, null);
} }

View File

@ -0,0 +1,27 @@
package com.cringe_studios.code_guard.fragment;
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.cringe_studios.code_guard.R;
import com.cringe_studios.code_guard.databinding.FragmentNoGroupsBinding;
public class NoGroupsFragment extends NamedFragment {
@Override
public String getName() {
return requireActivity().getString(R.string.fragment_no_groups);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FragmentNoGroupsBinding binding = FragmentNoGroupsBinding.inflate(inflater);
return binding.getRoot();
}
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".fragment.NoGroupsFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_groups" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -82,6 +82,7 @@
<string name="fragment_settings">Einstellungen</string> <string name="fragment_settings">Einstellungen</string>
<string name="fragment_about">Über</string> <string name="fragment_about">Über</string>
<string name="fragment_edit_otp">OTP bearbeiten</string> <string name="fragment_edit_otp">OTP bearbeiten</string>
<string name="fragment_no_groups">Keine Gruppen</string>
<string name="theme_blue_green">Blau/Grün</string> <string name="theme_blue_green">Blau/Grün</string>
<string name="theme_red_blue">Rot/Blau</string> <string name="theme_red_blue">Rot/Blau</string>
<string name="theme_pink_green">Pink/Grün</string> <string name="theme_pink_green">Pink/Grün</string>
@ -167,4 +168,5 @@
<string name="error_duplicate_otp_title">Doppeltes OTP</string> <string name="error_duplicate_otp_title">Doppeltes OTP</string>
<string name="biometric_encryption_unavailable">Biometrische Authentifizierung ist deaktiviert, da sie auf deinem Gerät nicht eingerichtet oder nicht verfügbar ist</string> <string name="biometric_encryption_unavailable">Biometrische Authentifizierung ist deaktiviert, da sie auf deinem Gerät nicht eingerichtet oder nicht verfügbar ist</string>
<string name="locale_system_default">Systemstandard</string> <string name="locale_system_default">Systemstandard</string>
<string name="no_groups">Es existieren momentan keine Gruppen. Öffne das Menü und drücke auf das \'+\'-Symbol, um eine Gruppe zu erstellen</string>
</resources> </resources>

View File

@ -66,6 +66,7 @@
<string name="fragment_settings">Settings</string> <string name="fragment_settings">Settings</string>
<string name="fragment_about">About</string> <string name="fragment_about">About</string>
<string name="fragment_edit_otp">Edit OTP</string> <string name="fragment_edit_otp">Edit OTP</string>
<string name="fragment_no_groups">No Groups</string>
<string-array name="view_edit_move_delete"> <string-array name="view_edit_move_delete">
<item>View</item> <item>View</item>
<item>Edit</item> <item>Edit</item>
@ -173,6 +174,7 @@
<string name="error_duplicate_otp_message">An OTP with the name of the OTP you\'re trying to add already exists.\n\nDo you want to automatically rename the new OTP to distinguish them from each other?</string> <string name="error_duplicate_otp_message">An OTP with the name of the OTP you\'re trying to add already exists.\n\nDo you want to automatically rename the new OTP to distinguish them from each other?</string>
<string name="error_duplicate_otp_title">Duplicate OTP</string> <string name="error_duplicate_otp_title">Duplicate OTP</string>
<string name="biometric_encryption_unavailable">Biometric authentication is disabled because it is not set up or not available on your device</string> <string name="biometric_encryption_unavailable">Biometric authentication is disabled because it is not set up or not available on your device</string>
<string name="no_groups">No groups exist yet. Open the menu and press the \'+\' button to create one</string>
<string-array name="edit_otp_choose_image_options"> <string-array name="edit_otp_choose_image_options">
<item>Image from icon pack</item> <item>Image from icon pack</item>
<item>Image from gallery</item> <item>Image from gallery</item>