mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-16 21:54:05 +02:00
replace Fragment for navHostFragment with FragmentContainerView
This commit is contained in:
@@ -159,7 +159,7 @@ dependencies {
|
||||
// CustomActivityOnCrash
|
||||
implementation 'cat.ereza:customactivityoncrash:2.3.0'
|
||||
// AppIntro
|
||||
implementation 'com.github.AppIntro:AppIntro:6.0.0'
|
||||
implementation 'com.github.AppIntro:AppIntro:6.2.0'
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.31'
|
||||
// Room
|
||||
implementation 'androidx.room:room-runtime:2.4.3'
|
||||
|
@@ -66,6 +66,7 @@ import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
@@ -199,7 +200,7 @@ public class MainActivity extends AppCompatActivity
|
||||
R.id.nav_overview, R.id.nav_graph, R.id.nav_table, R.id.nav_statistic, R.id.nav_main_preferences)
|
||||
.setOpenableLayout(drawerLayout)
|
||||
.build();
|
||||
navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
navController = ((NavHostFragment)getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment)).getNavController();
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navigationView, navController);
|
||||
NavigationUI.setupWithNavController(navigationBottomView, navController);
|
||||
|
@@ -28,6 +28,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.navigation.NavDirections;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
@@ -79,7 +80,8 @@ public class BluetoothPreferences extends PreferenceFragmentCompat {
|
||||
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).getCurrentBackStackEntry().getSavedStateHandle().getLiveData("update", false).observe(getViewLifecycleOwner(), new Observer<Boolean>() {
|
||||
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
|
||||
navHostFragment.getNavController().getCurrentBackStackEntry().getSavedStateHandle().getLiveData("update", false).observe(getViewLifecycleOwner(), new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
|
@@ -87,6 +87,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
private ProgressBar progressBar;
|
||||
private Handler progressHandler;
|
||||
private BluetoothCentralManager central;
|
||||
private Context context;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@@ -98,6 +99,8 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
txtSearching = root.findViewById(R.id.txtSearching);
|
||||
progressBar = root.findViewById(R.id.progressBar);
|
||||
|
||||
context = root.getContext();
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -113,9 +116,9 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
|
||||
Timber.d("Bluetooth settings Bluetooth permission check");
|
||||
|
||||
int targetSdkVersion = getActivity().getApplicationInfo().targetSdkVersion;
|
||||
int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
|
||||
|
||||
final BluetoothManager bluetoothManager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
|
||||
final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
|
||||
BluetoothAdapter btAdapter = bluetoothManager.getAdapter();
|
||||
|
||||
// Check if Bluetooth is enabled
|
||||
@@ -127,7 +130,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
}
|
||||
|
||||
// Check if Bluetooth 4.x is available
|
||||
if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
|
||||
if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
|
||||
Timber.d("No Bluetooth 4.x available");
|
||||
Toast.makeText(getContext(), "Bluetooth 4.x " + getContext().getResources().getString(R.string.info_is_not_available), Toast.LENGTH_SHORT).show();
|
||||
stepNavigationBack();
|
||||
@@ -135,11 +138,11 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
}
|
||||
|
||||
// Check if GPS or Network location service is enabled
|
||||
LocationManager locationManager = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
|
||||
LocationManager locationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
|
||||
if (!(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))) {
|
||||
Timber.d("No GPS or Network location service is enabled, ask user for permission");
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(R.string.permission_bluetooth_info_title);
|
||||
builder.setIcon(R.drawable.ic_preferences_about);
|
||||
builder.setMessage(R.string.permission_location_service_info);
|
||||
@@ -147,15 +150,19 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
// Show location settings when the user acknowledges the alert dialog
|
||||
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||
getActivity().startActivity(intent);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.label_no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
stepNavigationBack();
|
||||
}
|
||||
});
|
||||
|
||||
Dialog alertDialog = builder.create();
|
||||
alertDialog.setCanceledOnTouchOutside(false);
|
||||
alertDialog.show();
|
||||
|
||||
stepNavigationBack();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -175,7 +182,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
if (hasPermissions(requiredPermissions)) {
|
||||
startBluetoothDiscovery();
|
||||
} else if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
Timber.d("No access fine location permission granted");
|
||||
|
||||
builder.setMessage(R.string.permission_bluetooth_info)
|
||||
@@ -193,7 +200,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
alertDialog.show();
|
||||
|
||||
} else if (shouldShowRequestPermissionRationale(Manifest.permission.BLUETOOTH_SCAN)) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
Timber.d("No access Bluetooth scan permission granted");
|
||||
|
||||
builder.setMessage(R.string.permission_bluetooth_info)
|
||||
@@ -476,11 +483,7 @@ public class BluetoothSettingsFragment extends Fragment {
|
||||
|
||||
stopBluetoothDiscovery();
|
||||
|
||||
if (getActivity().findViewById(R.id.nav_host_fragment) != null){
|
||||
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).getPreviousBackStackEntry().getSavedStateHandle().set("update", true);
|
||||
Navigation.findNavController(requireActivity(), R.id.nav_host_fragment).navigateUp();
|
||||
} else
|
||||
getActivity().finish();
|
||||
stepNavigationBack();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -20,8 +20,9 @@ import android.view.View;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.NavDirections;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.SlideNavigationDirections;
|
||||
@@ -67,7 +68,9 @@ public class SlideToNavigationAdapter extends AppCompatActivity {
|
||||
}
|
||||
|
||||
if (action != null) {
|
||||
Navigation.findNavController(this, R.id.nav_slide_navigation).navigate(action);
|
||||
NavController navController = ((NavHostFragment)getSupportFragmentManager().findFragmentById(R.id.nav_slide_navigation)).getNavController();
|
||||
|
||||
navController.navigate(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@
|
||||
|
||||
<!-- action_menumain content view where fragments are loaded -->
|
||||
|
||||
<fragment
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
|
@@ -16,7 +16,7 @@
|
||||
android:background="?attr/colorPrimaryDark">
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
<fragment
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
app:navGraph="@navigation/slide_navigation"
|
||||
app:defaultNavHost="false"
|
||||
|
Reference in New Issue
Block a user