From b93ce78bebe5b9c1420f4cf8a78002e64cdf1dfd Mon Sep 17 00:00:00 2001 From: mesinger Date: Sat, 1 Jun 2024 15:43:26 +0200 Subject: [PATCH] fix: Fix missing DI in ProductDialogFragment --- .../de/grobox/transportr/AppComponent.java | 2 ++ .../trips/search/DirectionsActivity.kt | 2 -- .../trips/search/ProductDialogFragment.java | 30 ++++++++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/grobox/transportr/AppComponent.java b/app/src/main/java/de/grobox/transportr/AppComponent.java index ddd6f715e..79f319f13 100644 --- a/app/src/main/java/de/grobox/transportr/AppComponent.java +++ b/app/src/main/java/de/grobox/transportr/AppComponent.java @@ -34,6 +34,7 @@ import de.grobox.transportr.trips.detail.TripMapFragment; import de.grobox.transportr.trips.search.DirectionsActivity; import de.grobox.transportr.trips.search.DirectionsFragment; +import de.grobox.transportr.trips.search.ProductDialogFragment; import de.grobox.transportr.trips.search.TripsFragment; @Singleton @@ -56,5 +57,6 @@ public interface AppComponent { void inject(SettingsFragment fragment); void inject(HomePickerDialogFragment fragment); void inject(WorkPickerDialogFragment fragment); + void inject(ProductDialogFragment fragment); } diff --git a/app/src/main/java/de/grobox/transportr/trips/search/DirectionsActivity.kt b/app/src/main/java/de/grobox/transportr/trips/search/DirectionsActivity.kt index 0f92d66f7..aed53de4d 100644 --- a/app/src/main/java/de/grobox/transportr/trips/search/DirectionsActivity.kt +++ b/app/src/main/java/de/grobox/transportr/trips/search/DirectionsActivity.kt @@ -130,8 +130,6 @@ class DirectionsActivity : TransportrActivity(), OnOffsetChangedListener { supportFragmentManager.beginTransaction() .replace(R.id.fragmentContainer, TripsFragment(), TripsFragment.TAG) .commit() - // SHIBE -// fragmentContainer.requestFocus() } private fun processIntent(intent: Intent?) { diff --git a/app/src/main/java/de/grobox/transportr/trips/search/ProductDialogFragment.java b/app/src/main/java/de/grobox/transportr/trips/search/ProductDialogFragment.java index 5d1329f01..db0e29433 100755 --- a/app/src/main/java/de/grobox/transportr/trips/search/ProductDialogFragment.java +++ b/app/src/main/java/de/grobox/transportr/trips/search/ProductDialogFragment.java @@ -20,6 +20,9 @@ package de.grobox.transportr.trips.search; import android.app.Dialog; + +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.ViewModelProvider; import android.content.Context; import android.os.Bundle; @@ -38,6 +41,8 @@ import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter; import com.mikepenz.fastadapter.items.AbstractItem; +import org.jetbrains.annotations.NotNull; + import java.util.EnumSet; import java.util.List; import java.util.Set; @@ -47,6 +52,8 @@ import javax.inject.Inject; import de.grobox.transportr.R; +import de.grobox.transportr.TransportrApplication; +import de.grobox.transportr.databinding.FragmentProductDialogBinding; import de.schildbach.pte.dto.Product; import static de.grobox.transportr.utils.TransportrUtils.getDrawableForProduct; @@ -62,12 +69,15 @@ public class ProductDialogFragment extends DialogFragment { private FastItemAdapter adapter; private Button okButton; + private FragmentProductDialogBinding binding; + @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View v = inflater.inflate(R.layout.fragment_product_dialog, container); + binding = FragmentProductDialogBinding.inflate(inflater, container, false); + View v = binding.getRoot(); // RecyclerView - RecyclerView productsView = v.findViewById(R.id.productsView); + RecyclerView productsView = binding.productsView; productsView.setLayoutManager(new LinearLayoutManager(getContext())); adapter = new FastItemAdapter<>(); adapter.withSelectable(true); @@ -85,19 +95,25 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, } // OK Button - okButton = v.findViewById(R.id.okButton); + okButton = binding.okButton; okButton.setOnClickListener(view -> { EnumSet products = getProductsFromItems(adapter.getSelectedItems()); viewModel.setProducts(products); getDialog().cancel(); }); // Cancel Button - Button cancelButton = v.findViewById(R.id.cancelButton); + Button cancelButton = binding.cancelButton; cancelButton.setOnClickListener(view -> getDialog().cancel()); return v; } + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } + @Override public void onStart() { super.onStart(); @@ -114,6 +130,12 @@ public void onStart() { } } + @Override + public void onAttach(@NonNull @NotNull Context context) { + super.onAttach(context); + ((TransportrApplication) getActivity().getApplicationContext()).getComponent().inject(this); + } + @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState);