Source:
<code>public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_search_history, container, false); ButterKnife.bind(this, rootView); recentSearches = recentSearchesDao.recentSearches(10); recent_searches_delete_button.setOnClickListener(v -> { new AlertDialog.Builder(getContext()) .setMessage(getString(R.string.delete_recent_searches_dialog)) .setPositiveButton(android.R.string.yes, (dialog, which) -> { recentSearchesDao.deleteAll(recentSearches); Toast.makeText(getContext(),getString(R.string.search_history_deleted),Toast.LENGTH_SHORT).show(); recentSearches = recentSearchesDao.recentSearches(10); adapter = new ArrayAdapter<String>(getContext(),R.layout.item_recent_searches, recentSearches); recentSearchesList.setAdapter(adapter); adapter.notifyDataSetChanged(); dialog.dismiss(); }) .setNegativeButton(android.R.string.no, null) .create() .show(); }); currentThemeIsDark = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("theme", false); <START> if (currentThemeIsDark) { <END> adapter = new ArrayAdapter<String>(getContext(), R.layout.item_recent_searches_dark_theme, recentSearches); } else { adapter = new ArrayAdapter<String>(getContext(), R.layout.item_recent_searches, recentSearches); } recentSearchesList.setAdapter(adapter); recentSearchesList.setOnItemClickListener((parent, view, position, id) -> ( (SearchActivity)getContext()).updateText(recentSearches.get(position))); adapter.notifyDataSetChanged(); return rootView; }</code><technical_language>This identical code line 88. this a method code is repeated. Also, if this is a separate method, more easily unit testable (though unit tests required)</technical_language>

Target:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_search_history, container, false); ButterKnife.bind(this, rootView); recentSearches = recentSearchesDao.recentSearches(10); if(recentSearches.isEmpty()) { recent_searches_delete_button.setVisibility(View.GONE); recent_searches_text_view.setText(R.string.no_recent_searches); } recent_searches_delete_button.setOnClickListener(v -> { new AlertDialog.Builder(getContext()) .setMessage(getString(R.string.delete_recent_searches_dialog)) .setPositiveButton(android.R.string.yes, (dialog, which) -> { recentSearchesDao.deleteAll(recentSearches); recent_searches_delete_button.setVisibility(View.GONE); recent_searches_text_view.setText(R.string.no_recent_searches); Toast.makeText(getContext(),getString(R.string.search_history_deleted),Toast.LENGTH_SHORT).show(); recentSearches = recentSearchesDao.recentSearches(10); adapter = new ArrayAdapter<String>(getContext(),R.layout.item_recent_searches, recentSearches); recentSearchesList.setAdapter(adapter); adapter.notifyDataSetChanged(); dialog.dismiss(); }) .setNegativeButton(android.R.string.no, null) .create() .show(); }); currentThemeIsDark = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("theme", false); setAdapterForThemes(getContext(), currentThemeIsDark); recentSearchesList.setAdapter(adapter); recentSearchesList.setOnItemClickListener((parent, view, position, id) -> ( (SearchActivity)getContext()).updateText(recentSearches.get(position))); adapter.notifyDataSetChanged(); return rootView; }