Skip to content

Instantly share code, notes, and snippets.

@fmrsabino
Created October 14, 2016 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmrsabino/a9f12fa55442dbefc33f3a9ff04cbb3b to your computer and use it in GitHub Desktop.
Save fmrsabino/a9f12fa55442dbefc33f3a9ff04cbb3b to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="@+id/activity_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/activity_main_bottomBar" />
<com.roughike.bottombar.BottomBar
android:id="@+id/activity_main_bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ui.search.SearchView"
android:focusableInTouchMode="true"
android:id="@+id/cenas">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/activity_search_query_field"
android:hint="Movie title"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search"
android:id="@+id/activity_search_button"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/activity_search_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
public class MainActivity extends BaseActivity {
@BindView(R.id.activity_main_container) FrameLayout container;
@BindView(R.id.activity_main_bottomBar) BottomBar bottomBar;
private int selectedTabId;
private SearchView searchView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
searchView = new SearchView(this);
}
@Override
protected void onResume() {
super.onResume();
bottomBar.setOnTabSelectListener(tabId -> {
//if (selectedTabId == tabId) return;
selectedTabId = tabId;
container.removeAllViews();
switch (tabId) {
case R.id.tab_search:
container.addView(searchView);
break;
case R.id.tab_favorites:
break;
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putInt("tabId", selectedTabId);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
selectedTabId = savedInstanceState.getInt("tabId");
}
}
public class SearchView extends LinearLayout implements LoaderManager.LoaderCallbacks<SearchPresenter> {
private SearchPresenter presenter;
private SearchAdapter adapter;
@BindView(R.id.activity_search_list) RecyclerView recyclerView;
@BindView(R.id.activity_search_query_field) EditText searchField;
@BindView(R.id.activity_search_button) Button button;
private Subscription buttonOnClick;
public SearchView(Context context) {
super(context);
if (context instanceof AppCompatActivity) {
//hack
((AppCompatActivity) context).getSupportLoaderManager().initLoader(0, null, this);
}
adapter = new SearchAdapter(getContext());
LayoutInflater.from(context).inflate(R.layout.activity_search, this, true);
}
//Loader Callbacks
@Override
public Loader<SearchPresenter> onCreateLoader(int id, Bundle args) {
return new PresenterLoader<>(getContext(), () -> new SearchPresenter(getContext()));
}
@Override
public void onLoadFinished(Loader<SearchPresenter> loader, SearchPresenter presenter) {
this.presenter = presenter;
Timber.i(presenter.toString());
}
@Override
public void onLoaderReset(Loader<SearchPresenter> loader) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment