Added search floating action button to Overview and Categories screen.

Both times it launches the AppListActivity with an empty search box
focussed.
This commit is contained in:
Peter Serwylo 2016-12-08 14:51:54 +11:00
parent 7209ab87f5
commit 908d5f3a05
7 changed files with 53 additions and 5 deletions

View File

@ -1,7 +1,9 @@
package org.fdroid.fdroid.views.main;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
@ -14,6 +16,7 @@ import android.widget.FrameLayout;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.data.CategoryProvider;
import org.fdroid.fdroid.data.Schema;
import org.fdroid.fdroid.views.apps.AppListActivity;
import org.fdroid.fdroid.views.categories.CategoryAdapter;
/**
@ -28,7 +31,7 @@ class CategoriesViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
private final CategoryAdapter categoryAdapter;
private final AppCompatActivity activity;
CategoriesViewBinder(AppCompatActivity activity, FrameLayout parent) {
CategoriesViewBinder(final AppCompatActivity activity, FrameLayout parent) {
this.activity = activity;
View categoriesView = activity.getLayoutInflater().inflate(R.layout.main_tab_categories, parent, true);
@ -40,6 +43,14 @@ class CategoriesViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
categoriesList.setLayoutManager(new LinearLayoutManager(activity));
categoriesList.setAdapter(categoryAdapter);
FloatingActionButton searchFab = (FloatingActionButton) categoriesView.findViewById(R.id.btn_search);
searchFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.startActivity(new Intent(activity, AppListActivity.class));
}
});
activity.getSupportLoaderManager().initLoader(LOADER_ID, null, this);
}

View File

@ -1,7 +1,9 @@
package org.fdroid.fdroid.views.main;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
@ -16,6 +18,7 @@ import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.Schema;
import org.fdroid.fdroid.views.apps.AppListActivity;
import org.fdroid.fdroid.views.whatsnew.WhatsNewAdapter;
/**
@ -52,6 +55,14 @@ class WhatsNewViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
}
});
FloatingActionButton searchFab = (FloatingActionButton) whatsNewView.findViewById(R.id.btn_search);
searchFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.startActivity(new Intent(activity, AppListActivity.class));
}
});
activity.getSupportLoaderManager().initLoader(LOADER_ID, null, this);
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.FloatingActionButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btn_search"
android:src="@drawable/ic_search_white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginEnd="@dimen/fab_margin"
android:layout_marginRight="@dimen/fab_margin" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
@ -16,4 +17,6 @@
app:layout_constraintTop_toTopOf="parent"
android:scrollbars="vertical" />
</LinearLayout>
<include layout="@layout/fab_search" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
@ -23,4 +24,6 @@
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
<include layout="@layout/fab_search" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- The material design specs indicate a 24dp margin on tablets should be used (hence this
file differing from values-v21/dimens.xml):
https://material.google.com/components/buttons-floating-action-button.html -->
<dimen name="fab_margin">24dp</dimen>
</resources>

View File

@ -18,6 +18,8 @@
<!-- The selected item stands out from the background by this elevation -->
<dimen name="details_screenshot_selected_elevation">3dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="whats_new__padding__app_card__horizontal">12dp</dimen>
<dimen name="whats_new__padding__app_card__vertical">10dp</dimen>