Skip to content
This repository has been archived by the owner on Jul 5, 2021. It is now read-only.

Commit

Permalink
Fix incorrect dagger injection of HomeViewModel in TabTrayFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-cheng committed Apr 30, 2020
1 parent 308e8a7 commit f2337d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.mozilla.focus.telemetry.TelemetryWrapper;
import org.mozilla.focus.utils.Settings;
import org.mozilla.focus.utils.ViewUtils;
import org.mozilla.rocket.content.BaseViewModelFactory;
import org.mozilla.rocket.content.ExtentionKt;
import org.mozilla.rocket.home.HomeViewModel;
import org.mozilla.rocket.nightmode.themed.ThemedImageView;
import org.mozilla.rocket.nightmode.themed.ThemedRecyclerView;
Expand All @@ -68,6 +70,10 @@

import java.util.List;

import javax.inject.Inject;

import dagger.Lazy;

public class TabTrayFragment extends DialogFragment implements TabTrayContract.View,
View.OnClickListener, TabTrayAdapter.TabClickListener {

Expand Down Expand Up @@ -107,6 +113,8 @@ public class TabTrayFragment extends DialogFragment implements TabTrayContract.V
private Runnable dismissRunnable = this::dismissAllowingStateLoss;

private TabTrayViewModel tabTrayViewModel = null;
@Inject
Lazy<HomeViewModel> homeViewModelCreator;
private HomeViewModel homeViewModel = null;

private ThemedImageView imgPrivateBrowsing, imgNewTab;
Expand All @@ -124,6 +132,7 @@ public static TabTrayFragment newInstance() {

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
ExtentionKt.appComponent(this).inject(this);
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, R.style.TabTrayTheme);

Expand Down Expand Up @@ -192,7 +201,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
adapter.setShoppingSearch(showShoppingSearch, uiModel.getKeyword());
}
});
homeViewModel = new ViewModelProvider(getActivity(), new ViewModelProvider.NewInstanceFactory()).get(HomeViewModel.class);
homeViewModel = new ViewModelProvider(requireActivity(), new BaseViewModelFactory<>(homeViewModelCreator::get)).get(HomeViewModel.class);
backgroundView = view.findViewById(R.id.root_layout);
logoMan = backgroundView.findViewById(R.id.logo_man);
imgPrivateBrowsing = view.findViewById(R.id.img_private_browsing);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/mozilla/rocket/di/AppComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.mozilla.focus.fragment.DownloadsFragment
import org.mozilla.focus.history.BrowsingHistoryFragment
import org.mozilla.focus.persistence.TabsDatabase
import org.mozilla.focus.persistence.di.TabsModule
import org.mozilla.focus.tabs.tabtray.TabTrayFragment
import org.mozilla.focus.urlinput.UrlInputFragment
import org.mozilla.rocket.chrome.ChromeViewModel
import org.mozilla.rocket.chrome.di.ChromeModule
Expand Down Expand Up @@ -107,6 +108,7 @@ interface AppComponent {
fun inject(browserFragment: org.mozilla.rocket.privately.browse.BrowserFragment)
fun inject(downloadsFragment: DownloadsFragment)
fun inject(homeFragment: HomeFragment)
fun inject(tabTrayFragment: TabTrayFragment)
fun inject(privateHomeFragment: PrivateHomeFragment)
fun inject(urlInputFragment: UrlInputFragment)
fun inject(menuDialog: MenuDialog)
Expand Down

0 comments on commit f2337d5

Please sign in to comment.