Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: Revert local search #2745

Merged
merged 6 commits into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,19 @@
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.SearchView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;

Expand Down Expand Up @@ -85,6 +89,7 @@ public class UploadFilesActivity extends FileActivity implements
private Account mAccountOnCreation;
private DialogFragment mCurrentDialog;
private Menu mOptionsMenu;
private SearchView mSearchView;

public static final String EXTRA_CHOSEN_FILES =
UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CHOSEN_FILES";
Expand Down Expand Up @@ -221,6 +226,15 @@ public boolean onCreateOptionsMenu(Menu menu) {
MenuItem switchView = menu.findItem(R.id.action_switch_view);
switchView.setTitle(isGridView() ? R.string.action_switch_list_view : R.string.action_switch_grid_view);

int fontColor = ThemeUtils.fontColor(this);
final MenuItem item = menu.findItem(R.id.action_search);
mSearchView = (SearchView) MenuItemCompat.getActionView(item);
EditText editText = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
editText.setHintTextColor(fontColor);
editText.setTextColor(fontColor);
ImageView searchClose = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
searchClose.setColorFilter(fontColor);

return super.onCreateOptionsMenu(menu);
}

Expand Down Expand Up @@ -290,27 +304,43 @@ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
}
return true;
}

private boolean isSearchOpen() {
if (mSearchView == null) {
return false;
} else {
View mSearchEditFrame = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_edit_frame);
return (mSearchEditFrame != null && mSearchEditFrame.getVisibility() == View.VISIBLE);
}
}

@Override
public void onBackPressed() {
if (mDirectories.getCount() <= 1) {
finish();
return;
}
popDirname();
mFileListFragment.onNavigateUp();
mCurrentDir = mFileListFragment.getCurrentDirectory();

if (mCurrentDir.getParentFile() == null) {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
if (isSearchOpen() && mSearchView != null) {
mSearchView.setQuery("", false);
mFileListFragment.onClose();
mSearchView.onActionViewCollapsed();
setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
} else {
if (mDirectories.getCount() <= 1) {
finish();
return;
}
popDirname();
mFileListFragment.onNavigateUp();
mCurrentDir = mFileListFragment.getCurrentDirectory();

if (mCurrentDir.getParentFile() == null) {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
}
}
}

// invalidate checked state when navigating directories
if(!mLocalFolderPickerMode) {
setSelectAllMenuItem(mOptionsMenu.findItem(R.id.action_select_all), false);
// invalidate checked state when navigating directories
if (!mLocalFolderPickerMode) {
setSelectAllMenuItem(mOptionsMenu.findItem(R.id.action_select_all), false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -56,7 +57,7 @@
import java.util.Set;

/**
* This Adapter populates a RecycylerView with all files and directories contained in a local directory
* This Adapter populates a {@link RecyclerView} with all files and directories contained in a local directory
*/
public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements FilterableListAdapter {

Expand Down Expand Up @@ -99,6 +100,7 @@ public void registerDataSetObserver(DataSetObserver observer) {
// not needed
}

@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
// not needed
}
Expand Down Expand Up @@ -160,7 +162,7 @@ public long getItemId(int position) {
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof LocalFileListFooterViewHolder) {
((LocalFileListFooterViewHolder) holder).footerText.setText(getFooterText());
} else {
Expand Down Expand Up @@ -229,9 +231,9 @@ private void setThumbnail(File file, ImageView thumbnailView) {
} else {
thumbnailView.setImageResource(R.drawable.file);

/** Cancellation needs do be checked and done before changing the drawable in fileIcon, or
/* Cancellation needs do be checked and done before changing the drawable in fileIcon, or
* {@link ThumbnailsCacheManager#cancelPotentialThumbnailWork} will NEVER cancel any task.
**/
*/
boolean allowedToCreateNewThumbnail = (ThumbnailsCacheManager.cancelPotentialThumbnailWork(file, thumbnailView));


Expand Down Expand Up @@ -281,8 +283,9 @@ public int getItemViewType(int position) {
}
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
default:
case VIEWTYPE_ITEM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.FloatingActionButton;
Expand Down Expand Up @@ -81,7 +82,8 @@
import java.util.ArrayList;

public class ExtendedListFragment extends Fragment
implements OnItemClickListener, OnEnforceableRefreshListener, SearchView.OnQueryTextListener {
implements OnItemClickListener, OnEnforceableRefreshListener, SearchView.OnQueryTextListener,
SearchView.OnCloseListener {

protected static final String TAG = ExtendedListFragment.class.getSimpleName();

Expand Down Expand Up @@ -176,6 +178,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
final MenuItem item = menu.findItem(R.id.action_search);
searchView = (SearchView) MenuItemCompat.getActionView(item);
searchView.setOnQueryTextListener(this);
searchView.setOnCloseListener(this);

final Handler handler = new Handler();

Expand Down Expand Up @@ -203,7 +206,10 @@ public void onFocusChange(View v, final boolean hasFocus) {
@Override
public void run() {
if (getActivity() != null && !(getActivity() instanceof FolderPickerActivity)) {
setFabEnabled(!hasFocus);

if (!(getActivity() instanceof UploadFilesActivity)) {
setFabEnabled(!hasFocus);
}

boolean searchSupported = AccountUtils.hasSearchSupport(AccountUtils.
getCurrentOwnCloudAccount(MainApp.getAppContext()));
Expand Down Expand Up @@ -336,9 +342,15 @@ public void run() {
}
}

@Override
public boolean onClose() {
performSearch("", true);

return false;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreateView");

View v = inflater.inflate(R.layout.list_fragment, null);
Expand Down Expand Up @@ -460,7 +472,7 @@ public void onActivityCreated(Bundle savedInstanceState) {


@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
Log_OC.d(TAG, "onSaveInstanceState()");
savedInstanceState.putBoolean(KEY_IS_GRID_VISIBLE, isGridEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void onAttach(Activity activity) {
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log_OC.i(TAG, "onCreateView() start");
View v = super.onCreateView(inflater, container, savedInstanceState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void onAttach(Context context) {
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log_OC.i(TAG, "onCreateView() start");
View v = super.onCreateView(inflater, container, savedInstanceState);
bottomNavigationView = v.findViewById(R.id.bottom_navigation_view);
Expand Down Expand Up @@ -604,7 +604,7 @@ public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
* Saves the current listed folder.
*/
@Override
public void onSaveInstanceState(Bundle outState) {
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putParcelable(KEY_FILE, mFile);
if (searchFragment) {
outState.putParcelable(KEY_CURRENT_SEARCH_TYPE, Parcels.wrap(currentSearchType));
Expand Down