Skip to content

Commit

Permalink
[stable-3.8] (temporary) fix for navigation issue (#4485)
Browse files Browse the repository at this point in the history
[stable-3.8] (temporary) fix for navigation issue
  • Loading branch information
tobiasKaminsky committed Sep 10, 2019
2 parents d94fa72 + d57e594 commit 27b3b8f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@ private void selectNavigationItem(final MenuItem menuItem) {
case R.id.nav_all_files:
if (this instanceof FileDisplayActivity) {
if (((FileDisplayActivity) this).getListOfFilesFragment() instanceof PhotoFragment) {
showFiles(false);
// showFiles(false);
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
intent.setAction(FileDisplayActivity.ALL_FILES);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import android.accounts.AuthenticatorException;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
Expand Down Expand Up @@ -135,7 +134,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;

import javax.annotation.Nullable;
import javax.inject.Inject;
Expand All @@ -162,6 +160,8 @@ public class FileDisplayActivity extends FileActivity
SendShareDialog.SendShareDialogDownloader, Injectable {

public static final String RESTART = "RESTART";
public static final String ALL_FILES = "ALL_FILES";
public static final String PHOTO_SEARCH = "PHOTO_SEARCH";

private SyncBroadcastReceiver mSyncBroadcastReceiver;
private UploadFinishReceiver mUploadFinishReceiver;
Expand Down Expand Up @@ -194,7 +194,7 @@ public class FileDisplayActivity extends FileActivity

private static final String TAG = FileDisplayActivity.class.getSimpleName();

private static final String TAG_LIST_OF_FILES = "LIST_OF_FILES";
public static final String TAG_LIST_OF_FILES = "LIST_OF_FILES";
public static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT";

public static final String TEXT_PREVIEW = "TEXT_PREVIEW";
Expand Down Expand Up @@ -563,22 +563,29 @@ protected void onNewIntent(Intent intent) {
startActivity(intent);
} else // Verify the action and get the query
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
setIntent(intent);

SearchEvent searchEvent = Parcels.unwrap(intent.getParcelableExtra(OCFileListFragment.SEARCH_EVENT));
if (SearchRemoteOperation.SearchType.PHOTO_SEARCH.equals(searchEvent.searchType)) {
Log_OC.d(this, "Switch to photo search fragment");

PhotoFragment photoFragment = new PhotoFragment();
PhotoFragment photoFragment = new PhotoFragment(true);
Bundle bundle = new Bundle();
bundle.putParcelable(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent));
photoFragment.setArguments(bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.left_fragment_container, photoFragment, TAG_LIST_OF_FILES);
transaction.commit();
} else {
Log_OC.w(TAG, "Ignored Intent requesting to query for " + query);
Log_OC.d(this, "Switch to oc file search fragment");

OCFileListFragment photoFragment = new OCFileListFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent));
photoFragment.setArguments(bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.left_fragment_container, photoFragment, TAG_LIST_OF_FILES);
transaction.commit();
}
} else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
Uri data = intent.getData();
Expand All @@ -598,8 +605,13 @@ protected void onNewIntent(Intent intent) {
doShareWith(shareWith, shareType);
}

} else {
Log_OC.e(TAG, String.format(Locale.US, "Unexpected intent %s", intent));
} else if (ALL_FILES.equals(intent.getAction())) {
Log_OC.d(this, "Switch to oc file fragment");

OCFileListFragment fragment = new OCFileListFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
transaction.commit();
}
}

Expand Down Expand Up @@ -2573,16 +2585,17 @@ public void onMessageEvent(final SearchEvent event) {
if (SearchRemoteOperation.SearchType.PHOTO_SEARCH == event.searchType) {
Log_OC.d(this, "Switch to photo search fragment");

fragment = new PhotoFragment();
} else {
Log_OC.d(this, "Switch to OCFileListFragment");

fragment = new OCFileListFragment();
fragment = new PhotoFragment(true);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
transaction.commit();
}
// else {
// Log_OC.d(this, "Switch to OCFileListFragment");
//
// fragment = new OCFileListFragment();
// }

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
transaction.commit();
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ private void parseVirtuals(List<Object> objects, ExtendedListFragment.SearchType
long currentSyncTime = System.currentTimeMillis();
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(ocFile,
currentSyncTime,
false,
true,
false,
mStorageManager,
account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ public void onActivityCreated(Bundle savedInstanceState) {
}

setTitle();

if (searchEvent != null) {
onMessageEvent(searchEvent);
}
}

protected void prepareCurrentSearch(SearchEvent event) {
Expand Down
40 changes: 25 additions & 15 deletions src/main/java/com/owncloud/android/ui/fragment/PhotoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,28 @@ public class PhotoFragment extends OCFileListFragment {
private boolean photoSearchNoNew = false;
private SearchRemoteOperation searchRemoteOperation;
private AsyncTask photoSearchTask;
private SearchEvent searchEvent;
private boolean refresh = false;

public PhotoFragment() {

}

public PhotoFragment(boolean refresh) {
this.refresh = refresh;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

searchEvent = new SearchEvent("image/%",
SearchRemoteOperation.SearchType.PHOTO_SEARCH,
SearchEvent.UnsetType.NO_UNSET);

searchRemoteOperation = new SearchRemoteOperation(searchEvent.getSearchQuery(),
searchEvent.getSearchType(),
false);
}

@Override
Expand Down Expand Up @@ -96,23 +114,24 @@ public void onActivityCreated(Bundle savedInstanceState) {
menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
requireActivity().invalidateOptionsMenu();

handleSearchEvent(searchEvent, false);
handleSearchEvent();
}

@Override
public void onRefresh() {
super.onRefresh();

handleSearchEvent(searchEvent, true);
refresh = true;
handleSearchEvent();
}

@Override
public void onMessageEvent(ChangeMenuEvent changeMenuEvent) {
super.onMessageEvent(changeMenuEvent);
}

private void handleSearchEvent(final SearchEvent event, boolean refresh) {
prepareCurrentSearch(event);
private void handleSearchEvent() {
prepareCurrentSearch(searchEvent);
searchFragment = true;
setEmptyListLoadingMessage();

Expand All @@ -124,6 +143,8 @@ private void handleSearchEvent(final SearchEvent event, boolean refresh) {
mContainerActivity.getStorageManager(),
mFile,
true);

refresh = false;
} else {
mAdapter.showVirtuals(VirtualFolderType.PHOTOS, true, mContainerActivity.getStorageManager());
preferences.setPhotoSearchTimestamp(System.currentTimeMillis());
Expand All @@ -133,17 +154,6 @@ private void handleSearchEvent(final SearchEvent event, boolean refresh) {

setFabVisible(false);

if (currentSearchType != SearchType.SHARED_FILTER) {
boolean searchOnlyFolders = false;
if (getArguments() != null && getArguments().getBoolean(ARG_SEARCH_ONLY_FOLDER, false)) {
searchOnlyFolders = true;
}

searchRemoteOperation = new SearchRemoteOperation(event.getSearchQuery(),
event.getSearchType(),
searchOnlyFolders);
}

searchAndDisplay();
}

Expand Down

0 comments on commit 27b3b8f

Please sign in to comment.