-
-
Save fmrsabino/a9f12fa55442dbefc33f3a9ff04cbb3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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