Skip to content

Commit

Permalink
fix: Fix missing DI in ProductDialogFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
mesinger committed Jun 1, 2024
1 parent cea6525 commit b93ce78
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/de/grobox/transportr/AppComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,5 +57,6 @@ public interface AppComponent {
void inject(SettingsFragment fragment);
void inject(HomePickerDialogFragment fragment);
void inject(WorkPickerDialogFragment fragment);
void inject(ProductDialogFragment fragment);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -62,12 +69,15 @@ public class ProductDialogFragment extends DialogFragment {
private FastItemAdapter<ProductItem> 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);
Expand All @@ -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<Product> 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();
Expand All @@ -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);
Expand Down

0 comments on commit b93ce78

Please sign in to comment.