keylist: add "search for query" button to empty view
This commit is contained in:
parent
0641b9cba6
commit
3411a5c087
|
@ -30,6 +30,7 @@ import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
|
@ -46,8 +47,10 @@ import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AbsListView.MultiChoiceModeListener;
|
import android.widget.AbsListView.MultiChoiceModeListener;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.ViewAnimator;
|
||||||
|
|
||||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||||
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
||||||
|
@ -97,6 +100,8 @@ public class KeyListFragment extends LoaderFragment
|
||||||
// saves the mode object for multiselect, needed for reset at some point
|
// saves the mode object for multiselect, needed for reset at some point
|
||||||
private ActionMode mActionMode = null;
|
private ActionMode mActionMode = null;
|
||||||
|
|
||||||
|
private Button vSearchButton;
|
||||||
|
private ViewAnimator vSearchContainer;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
|
|
||||||
private FloatingActionsMenu mFab;
|
private FloatingActionsMenu mFab;
|
||||||
|
@ -161,7 +166,9 @@ public class KeyListFragment extends LoaderFragment
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
// show app name instead of "keys" from nav drawer
|
// show app name instead of "keys" from nav drawer
|
||||||
getActivity().setTitle(R.string.app_name);
|
final FragmentActivity activity = getActivity();
|
||||||
|
|
||||||
|
activity.setTitle(R.string.app_name);
|
||||||
|
|
||||||
mStickyList.setOnItemClickListener(this);
|
mStickyList.setOnItemClickListener(this);
|
||||||
mStickyList.setAreHeadersSticky(true);
|
mStickyList.setAreHeadersSticky(true);
|
||||||
|
@ -170,7 +177,7 @@ public class KeyListFragment extends LoaderFragment
|
||||||
|
|
||||||
// Adds an empty footer view so that the Floating Action Button won't block content
|
// Adds an empty footer view so that the Floating Action Button won't block content
|
||||||
// in last few rows.
|
// in last few rows.
|
||||||
View footer = new View(getActivity());
|
View footer = new View(activity);
|
||||||
|
|
||||||
int spacing = (int) android.util.TypedValue.applyDimension(
|
int spacing = (int) android.util.TypedValue.applyDimension(
|
||||||
android.util.TypedValue.COMPLEX_UNIT_DIP, 72, getResources().getDisplayMetrics()
|
android.util.TypedValue.COMPLEX_UNIT_DIP, 72, getResources().getDisplayMetrics()
|
||||||
|
@ -194,7 +201,7 @@ public class KeyListFragment extends LoaderFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||||
android.view.MenuInflater inflater = getActivity().getMenuInflater();
|
android.view.MenuInflater inflater = activity.getMenuInflater();
|
||||||
inflater.inflate(R.menu.key_list_multi, menu);
|
inflater.inflate(R.menu.key_list_multi, menu);
|
||||||
mActionMode = mode;
|
mActionMode = mode;
|
||||||
return true;
|
return true;
|
||||||
|
@ -234,7 +241,7 @@ public class KeyListFragment extends LoaderFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
|
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
|
||||||
boolean checked) {
|
boolean checked) {
|
||||||
if (checked) {
|
if (checked) {
|
||||||
mAdapter.setNewSelection(position, true);
|
mAdapter.setNewSelection(position, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,8 +261,21 @@ public class KeyListFragment extends LoaderFragment
|
||||||
// Start out with a progress indicator.
|
// Start out with a progress indicator.
|
||||||
setContentShown(false);
|
setContentShown(false);
|
||||||
|
|
||||||
|
// this view is made visible if no data is available
|
||||||
|
mStickyList.setEmptyView(activity.findViewById(R.id.key_list_empty));
|
||||||
|
|
||||||
|
// click on search button (in empty view) starts query for search string
|
||||||
|
vSearchContainer = (ViewAnimator) activity.findViewById(R.id.search_container);
|
||||||
|
vSearchButton = (Button) activity.findViewById(R.id.search_button);
|
||||||
|
vSearchButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
startSearchForQuery();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Create an empty adapter we will use to display the loaded data.
|
// Create an empty adapter we will use to display the loaded data.
|
||||||
mAdapter = new KeyListAdapter(getActivity(), null, 0);
|
mAdapter = new KeyListAdapter(activity, null, 0);
|
||||||
mStickyList.setAdapter(mAdapter);
|
mStickyList.setAdapter(mAdapter);
|
||||||
|
|
||||||
// Prepare the loader. Either re-connect with an existing one,
|
// Prepare the loader. Either re-connect with an existing one,
|
||||||
|
@ -263,6 +283,18 @@ public class KeyListFragment extends LoaderFragment
|
||||||
getLoaderManager().initLoader(0, null, this);
|
getLoaderManager().initLoader(0, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startSearchForQuery() {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Intent searchIntent = new Intent(activity, ImportKeysActivity.class);
|
||||||
|
searchIntent.putExtra(ImportKeysActivity.EXTRA_QUERY, mQuery);
|
||||||
|
searchIntent.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER);
|
||||||
|
startActivity(searchIntent);
|
||||||
|
}
|
||||||
|
|
||||||
static final String ORDER =
|
static final String ORDER =
|
||||||
KeyRings.HAS_ANY_SECRET + " DESC, UPPER(" + KeyRings.USER_ID + ") ASC";
|
KeyRings.HAS_ANY_SECRET + " DESC, UPPER(" + KeyRings.USER_ID + ") ASC";
|
||||||
|
|
||||||
|
@ -318,9 +350,6 @@ public class KeyListFragment extends LoaderFragment
|
||||||
|
|
||||||
mStickyList.setAdapter(mAdapter);
|
mStickyList.setAdapter(mAdapter);
|
||||||
|
|
||||||
// this view is made visible if no data is available
|
|
||||||
mStickyList.setEmptyView(getActivity().findViewById(R.id.key_list_empty));
|
|
||||||
|
|
||||||
// end action mode, if any
|
// end action mode, if any
|
||||||
if (mActionMode != null) {
|
if (mActionMode != null) {
|
||||||
mActionMode.finish();
|
mActionMode.finish();
|
||||||
|
@ -482,17 +511,25 @@ public class KeyListFragment extends LoaderFragment
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String s) {
|
public boolean onQueryTextChange(String s) {
|
||||||
Log.d(Constants.TAG, "onQueryTextChange s:" + s);
|
Log.d(Constants.TAG, "onQueryTextChange s:" + s);
|
||||||
// Called when the action bar search text has changed. Update
|
// Called when the action bar search text has changed. Update the
|
||||||
// the search filter, and restart the loader to do a new query
|
// search filter, and restart the loader to do a new query with this
|
||||||
// with this filter.
|
// filter.
|
||||||
// If the nav drawer is opened, onQueryTextChange("") is executed.
|
// If the nav drawer is opened, onQueryTextChange("") is executed.
|
||||||
// This hack prevents restarting the loader.
|
// This hack prevents restarting the loader.
|
||||||
// TODO: better way to fix this?
|
if (!s.equals(mQuery)) {
|
||||||
String tmp = (mQuery == null) ? "" : mQuery;
|
|
||||||
if (!s.equals(tmp)) {
|
|
||||||
mQuery = s;
|
mQuery = s;
|
||||||
getLoaderManager().restartLoader(0, null, this);
|
getLoaderManager().restartLoader(0, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s.length() > 2) {
|
||||||
|
vSearchButton.setText(getString(R.string.btn_search_for_query, mQuery));
|
||||||
|
vSearchContainer.setDisplayedChild(1);
|
||||||
|
vSearchContainer.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
vSearchContainer.setDisplayedChild(0);
|
||||||
|
vSearchContainer.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
||||||
>
|
>
|
||||||
|
|
||||||
<!--rebuild functionality of ListFragment -->
|
<!--rebuild functionality of ListFragment -->
|
||||||
|
@ -23,10 +25,11 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/key_list_empty"
|
android:id="@+id/key_list_empty"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="240dp"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:visibility="visible">
|
android:animateLayoutChanges="true"
|
||||||
|
>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -35,6 +38,30 @@
|
||||||
android:text="@string/key_list_empty_text1"
|
android:text="@string/key_list_empty_text1"
|
||||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
|
<org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/search_container"
|
||||||
|
android:inAnimation="@anim/fade_in_delayed"
|
||||||
|
android:outAnimation="@anim/fade_out"
|
||||||
|
android:measureAllChildren="true"
|
||||||
|
custom:initialView="1">
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:id="@+id/search_button"
|
||||||
|
android:gravity="center"
|
||||||
|
tools:text="@string/btn_search_for_query"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
|
@ -1679,5 +1679,6 @@
|
||||||
<string name="share_log_dialog_cancel_button">"Cancel"</string>
|
<string name="share_log_dialog_cancel_button">"Cancel"</string>
|
||||||
<string name="toast_wrong_mimetype">"Wrong data type, expected text!"</string>
|
<string name="toast_wrong_mimetype">"Wrong data type, expected text!"</string>
|
||||||
<string name="toast_no_text">"No text in shared data!"</string>
|
<string name="toast_no_text">"No text in shared data!"</string>
|
||||||
|
<string name="btn_search_for_query">"Search for\n'%s'"</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue