More fabs
This commit is contained in:
parent
ecc3b2e6b8
commit
5cd27b6861
@ -1,6 +1,7 @@
|
|||||||
package com.cringe_studios.cringe_authenticator;
|
package com.cringe_studios.cringe_authenticator;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ import androidx.navigation.ui.AppBarConfiguration;
|
|||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.ActivityMainBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.ActivityMainBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.fragment.DynamicFragment;
|
||||||
|
import com.cringe_studios.cringe_authenticator.fragment.HomeFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.MenuFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
import com.cringe_studios.cringe_authenticator.fragment.SettingsFragment;
|
||||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||||
@ -69,6 +72,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
|
|
||||||
|
if(NavigationUtil.getCurrentFragment(this) instanceof DynamicFragment) {
|
||||||
|
//getMenuInflater().inflate(R.menu.menu_dynamic, menu);
|
||||||
|
getMenuInflater().inflate(R.menu.menu_dynamic, menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -88,6 +98,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
Log.i("AMOGUS", "navigateUp");
|
||||||
|
if(NavigationUtil.getCurrentFragment(this) instanceof DynamicFragment) {
|
||||||
|
NavigationUtil.navigate(this, HomeFragment.class, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSupportNavigateUp() {
|
public boolean onSupportNavigateUp() {
|
||||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
|
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_content_main);
|
||||||
@ -99,4 +117,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
NavigationUtil.navigate(this, SettingsFragment.class, null);
|
NavigationUtil.navigate(this, SettingsFragment.class, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addCode(MenuItem item) {
|
||||||
|
// TODO: add code
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -12,7 +12,9 @@ import androidx.fragment.app.Fragment;
|
|||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.AuthenticateTotpBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.AuthenticateTotpBinding;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.FragmentDynamicBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
|
||||||
public class DynamicFragment extends Fragment {
|
public class DynamicFragment extends Fragment {
|
||||||
|
|
||||||
@ -27,10 +29,6 @@ public class DynamicFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
binding = FragmentDynamicBinding.inflate(inflater, container, false);
|
binding = FragmentDynamicBinding.inflate(inflater, container, false);
|
||||||
/*binding.buttonSecond.setText(requireArguments().getString("tab"));
|
|
||||||
binding.buttonSecond.setOnClickListener(view -> {
|
|
||||||
NavigationUtil.navigate(this, SecondFragment.class, null);
|
|
||||||
});*/
|
|
||||||
|
|
||||||
String tab = requireArguments().getString("tab");
|
String tab = requireArguments().getString("tab");
|
||||||
|
|
||||||
@ -41,7 +39,14 @@ public class DynamicFragment extends Fragment {
|
|||||||
binding.itemList.addView(itemBinding.getRoot());
|
binding.itemList.addView(itemBinding.getRoot());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FabUtil.showFabs(getActivity());
|
||||||
|
|
||||||
return binding.getRoot();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
this.binding = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import androidx.fragment.app.Fragment;
|
|||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentMenuBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.FragmentMenuBinding;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.MenuItemBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.MenuItemBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||||
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
import com.cringe_studios.cringe_authenticator.util.NavigationUtil;
|
||||||
|
|
||||||
public class MenuFragment extends Fragment {
|
public class MenuFragment extends Fragment {
|
||||||
@ -46,7 +47,15 @@ public class MenuFragment extends Fragment {
|
|||||||
// TODO: edit mode
|
// TODO: edit mode
|
||||||
});
|
});
|
||||||
|
|
||||||
|
FabUtil.hideFabs(getActivity());
|
||||||
|
|
||||||
return binding.getRoot();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
this.binding = null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import androidx.navigation.Navigation;
|
|||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.FragmentSettingsBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.FragmentSettingsBinding;
|
||||||
|
import com.cringe_studios.cringe_authenticator.util.FabUtil;
|
||||||
|
|
||||||
public class SettingsFragment extends Fragment {
|
public class SettingsFragment extends Fragment {
|
||||||
|
|
||||||
@ -29,7 +30,15 @@ public class SettingsFragment extends Fragment {
|
|||||||
controller.navigate(R.id.FirstFragment);
|
controller.navigate(R.id.FirstFragment);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
FabUtil.hideFabs(getActivity());
|
||||||
|
|
||||||
return binding.getRoot();
|
return binding.getRoot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
this.binding = null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.cringe_studios.cringe_authenticator.util;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
|
||||||
|
public class FabUtil {
|
||||||
|
|
||||||
|
public static void showFabs(Activity activity) {
|
||||||
|
FloatingActionButton fabScan = activity.findViewById(R.id.fab_scan);
|
||||||
|
if(fabScan != null) {
|
||||||
|
fabScan.setVisibility(View.VISIBLE);
|
||||||
|
fabScan.setClickable(true);
|
||||||
|
fabScan.animate().translationX(-activity.getResources().getDimension(R.dimen.fab1_offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatingActionButton fabInput = activity.findViewById(R.id.fab_input);
|
||||||
|
if(fabInput != null) {
|
||||||
|
fabInput.setVisibility(View.VISIBLE);
|
||||||
|
fabInput.setClickable(true);
|
||||||
|
fabInput.animate().translationX(-activity.getResources().getDimension(R.dimen.fab2_offset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void hideFabs(Activity activity) {
|
||||||
|
FloatingActionButton fabScan = activity.findViewById(R.id.fab_scan);
|
||||||
|
if(fabScan != null) {
|
||||||
|
fabScan.setClickable(false);
|
||||||
|
fabScan.animate().translationX(0).withEndAction(() -> fabScan.setVisibility(View.GONE));
|
||||||
|
}
|
||||||
|
|
||||||
|
FloatingActionButton fabInput = activity.findViewById(R.id.fab_input);
|
||||||
|
if(fabInput != null) {
|
||||||
|
fabInput.setClickable(false);
|
||||||
|
fabInput.animate().translationX(0).withEndAction(() -> fabInput.setVisibility(View.GONE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,14 @@
|
|||||||
package com.cringe_studios.cringe_authenticator.util;
|
package com.cringe_studios.cringe_authenticator.util;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
|
||||||
public class NavigationUtil {
|
public class NavigationUtil {
|
||||||
|
|
||||||
@ -27,4 +29,16 @@ public class NavigationUtil {
|
|||||||
.commit();
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Fragment getCurrentFragment(AppCompatActivity activity) {
|
||||||
|
return getCurrentFragment(activity.getSupportFragmentManager().getPrimaryNavigationFragment().getChildFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Fragment getCurrentFragment(Fragment currentFragment) {
|
||||||
|
return getCurrentFragment(currentFragment.getParentFragment().getChildFragmentManager());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Fragment getCurrentFragment(FragmentManager manager) {
|
||||||
|
return manager.findFragmentById(R.id.nav_host_fragment_content_main);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,26 @@
|
|||||||
|
|
||||||
<include layout="@layout/content_main" />
|
<include layout="@layout/content_main" />
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/fab_input"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_marginEnd="@dimen/fab_margin"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
app:srcCompat="@android:drawable/ic_menu_camera"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/fab_scan"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_marginEnd="@dimen/fab_margin"
|
||||||
|
android:layout_marginBottom="16dp"
|
||||||
|
app:srcCompat="@android:drawable/ic_menu_edit"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -4,32 +4,20 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".fragment.FirstFragment">
|
tools:context=".fragment.HomeFragment">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:padding="16dp">
|
android:padding="16dp">
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/button_first"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/next"
|
|
||||||
app:layout_constraintBottom_toTopOf="@id/textview_first"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textview_first"
|
android:id="@+id/textview_first"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:text="This is the home fragment"
|
||||||
android:text="@string/lorem_ipsum"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
app:layout_constraintTop_toBottomOf="@id/button_first" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".fragment.FirstFragment">
|
tools:context=".fragment.HomeFragment">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".fragment.SecondFragment">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/button_second"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/previous"
|
|
||||||
app:layout_constraintBottom_toTopOf="@id/textview_second"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textview_second"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:text="@string/lorem_ipsum"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/button_second" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
|
@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".fragment.FirstFragment">
|
tools:context=".fragment.HomeFragment">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
17
app/src/main/res/menu/menu_dynamic.xml
Normal file
17
app/src/main/res/menu/menu_dynamic.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context="com.cringe_studios.cringe_authenticator.MainActivity">
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_code"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:title="Add Code"
|
||||||
|
app:showAsAction="never"
|
||||||
|
android:onClick="addCode" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_settings"
|
||||||
|
android:orderInCategory="100"
|
||||||
|
android:title="Settings"
|
||||||
|
app:showAsAction="never"
|
||||||
|
android:onClick="openSettings" />
|
||||||
|
</menu>
|
@ -7,9 +7,9 @@
|
|||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/FirstFragment"
|
android:id="@+id/FirstFragment"
|
||||||
android:name="com.cringe_studios.cringe_authenticator.fragment.FirstFragment"
|
android:name="com.cringe_studios.cringe_authenticator.fragment.HomeFragment"
|
||||||
android:label="@string/first_fragment_label"
|
android:label="@string/first_fragment_label"
|
||||||
tools:layout="@layout/fragment_first">
|
tools:layout="@layout/fragment_home">
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/SecondFragment"
|
android:id="@+id/SecondFragment"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="fab_margin">16dp</dimen>
|
<dimen name="fab_margin">16dp</dimen>
|
||||||
|
<dimen name="fab1_offset">65dp</dimen>
|
||||||
|
<dimen name="fab2_offset">130dp</dimen>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user