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

Use reloading on photo view #2250

Merged
merged 1 commit into from
Aug 20, 2019
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
2 changes: 1 addition & 1 deletion scripts/analysis/findbugs-results.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
410
413
4 changes: 4 additions & 0 deletions src/main/java/com/nextcloud/client/di/ComponentsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.owncloud.android.ui.fragment.FileDetailSharingFragment;
import com.owncloud.android.ui.fragment.LocalFileListFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.fragment.PhotoFragment;
import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
import com.owncloud.android.ui.preview.PreviewImageActivity;
import com.owncloud.android.ui.preview.PreviewImageFragment;
Expand Down Expand Up @@ -136,6 +137,9 @@ abstract class ComponentsModule {
@ContributesAndroidInjector abstract PreviewMediaFragment previewMediaFragment();
@ContributesAndroidInjector abstract PreviewTextFragment previewTextFragment();

@ContributesAndroidInjector
abstract PhotoFragment photoFragment();

@ContributesAndroidInjector abstract ReceiveExternalFilesActivity.DialogMultipleAccount dialogMultipleAccount();
@ContributesAndroidInjector abstract ReceiveExternalFilesActivity.DialogInputUploadFilename dialogInputUploadFilename();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,8 @@ public interface AppPreferences {
boolean isUserIdMigrated();

void setMigratedUserId(boolean value);

void setPhotoSearchTimestamp(long timestamp);

long getPhotoSearchTimestamp();
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public final class AppPreferencesImpl implements AppPreferences {
private static final String PREF__LOCK = SettingsActivity.PREFERENCE_LOCK;
private static final String PREF__SELECTED_ACCOUNT_NAME = "select_oc_account";
private static final String PREF__MIGRATED_USER_ID = "migrated_user_id";
private static final String PREF__PHOTO_SEARCH_TIMESTAMP = "photo_search_timestamp";

private final Context context;
private final SharedPreferences preferences;
Expand Down Expand Up @@ -465,6 +466,16 @@ public void setMigratedUserId(boolean value) {
preferences.edit().putBoolean(PREF__MIGRATED_USER_ID, value).apply();
}

@Override
public void setPhotoSearchTimestamp(long timestamp) {
preferences.edit().putLong(PREF__PHOTO_SEARCH_TIMESTAMP, timestamp).apply();
}

@Override
public long getPhotoSearchTimestamp() {
return preferences.getLong(PREF__PHOTO_SEARCH_TIMESTAMP, 0);
}

/**
* Get preference value for a folder.
* If folder is not set itself, it finds an ancestor that is set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
public class EmptyRecyclerView extends RecyclerView {
private View mEmptyView;
private boolean hasFooter;
private boolean hasFooter = false;

public EmptyRecyclerView(Context context) {
super(context);
Expand Down
61 changes: 44 additions & 17 deletions src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import com.owncloud.android.ui.events.DummyDrawerEvent;
import com.owncloud.android.ui.events.SearchEvent;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.fragment.PhotoFragment;
import com.owncloud.android.ui.trashbin.TrashbinActivity;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.DrawerMenuUtil;
Expand Down Expand Up @@ -424,16 +425,32 @@ private void selectNavigationItem(final MenuItem menuItem) {

switch (menuItem.getItemId()) {
case R.id.nav_all_files:
showFiles(false);
EventBus.getDefault().post(new ChangeMenuEvent());
if (this instanceof FileDisplayActivity) {
if (((FileDisplayActivity) this).getListOfFilesFragment() instanceof PhotoFragment) {
showFiles(false);
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
} else {
showFiles(false);
EventBus.getDefault().post(new ChangeMenuEvent());
}
} else {
showFiles(false);
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}

break;
case R.id.nav_favorites:
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.FAVORITE_SEARCH,
SearchEvent.UnsetType.NO_UNSET), menuItem.getItemId());
break;
case R.id.nav_photos:
handleSearchEvents(new SearchEvent("image/%", SearchRemoteOperation.SearchType.CONTENT_TYPE_SEARCH,
SearchEvent.UnsetType.NO_UNSET), menuItem.getItemId());
startPhotoSearch(menuItem);
break;
case R.id.nav_on_device:
EventBus.getDefault().post(new ChangeMenuEvent());
Expand Down Expand Up @@ -479,22 +496,10 @@ private void selectNavigationItem(final MenuItem menuItem) {
menuItem.setChecked(false);
UserInfoActivity.openAccountRemovalConfirmationDialog(getAccount(), getSupportFragmentManager(), true);
break;
case R.id.nav_recently_added:
handleSearchEvents(new SearchEvent("%", SearchRemoteOperation.SearchType.CONTENT_TYPE_SEARCH,
SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR), menuItem.getItemId());
break;
case R.id.nav_recently_modified:
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.RECENTLY_MODIFIED_SEARCH,
SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR), menuItem.getItemId());
break;
case R.id.nav_shared:
handleSearchEvents(new SearchEvent("", SearchRemoteOperation.SearchType.SHARED_SEARCH,
SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR), menuItem.getItemId());
break;
case R.id.nav_videos:
handleSearchEvents(new SearchEvent("video/%", SearchRemoteOperation.SearchType.CONTENT_TYPE_SEARCH,
SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR), menuItem.getItemId());
break;
default:
if (menuItem.getItemId() >= MENU_ITEM_EXTERNAL_LINK &&
menuItem.getItemId() <= MENU_ITEM_EXTERNAL_LINK + 100) {
Expand All @@ -507,9 +512,31 @@ private void selectNavigationItem(final MenuItem menuItem) {
}
}

private void startPhotoSearch(MenuItem menuItem) {
SearchEvent searchEvent = new SearchEvent("image/%",
SearchRemoteOperation.SearchType.PHOTO_SEARCH,
SearchEvent.UnsetType.NO_UNSET);

Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_SEARCH);
intent.putExtra(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent));
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItem.getItemId());
startActivity(intent);
}

private void handleSearchEvents(SearchEvent searchEvent, int menuItemId) {
if (this instanceof FileDisplayActivity) {
EventBus.getDefault().post(searchEvent);
if (((FileDisplayActivity) this).getListOfFilesFragment() instanceof PhotoFragment) {
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction(Intent.ACTION_SEARCH);
intent.putExtra(OCFileListFragment.SEARCH_EVENT, Parcels.wrap(searchEvent));
intent.putExtra(FileDisplayActivity.DRAWER_MENU_ID, menuItemId);
startActivity(intent);
} else {
EventBus.getDefault().post(searchEvent);
}
} else {
Intent intent = new Intent(getApplicationContext(), FileDisplayActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperation;
import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
Expand All @@ -101,12 +102,14 @@
import com.owncloud.android.ui.asynctasks.FetchRemoteFileTask;
import com.owncloud.android.ui.dialog.SendShareDialog;
import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
import com.owncloud.android.ui.events.SearchEvent;
import com.owncloud.android.ui.events.SyncEventFinished;
import com.owncloud.android.ui.events.TokenPushEvent;
import com.owncloud.android.ui.fragment.ExtendedListFragment;
import com.owncloud.android.ui.fragment.FileDetailFragment;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.ui.fragment.OCFileListFragment;
import com.owncloud.android.ui.fragment.PhotoFragment;
import com.owncloud.android.ui.fragment.TaskRetainerFragment;
import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
Expand Down Expand Up @@ -564,7 +567,21 @@ protected void onNewIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
setIntent(intent);
Log_OC.w(TAG, "Ignored Intent requesting to query for " + query);

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();
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);
}
} else if (UsersAndGroupsSearchProvider.ACTION_SHARE_WITH.equals(intent.getAction())) {
Uri data = intent.getData();
String dataString = intent.getDataString();
Expand Down Expand Up @@ -2556,6 +2573,25 @@ public void showFiles(boolean onDeviceOnly) {
getListOfFilesFragment().refreshDirectory();
}

@Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(final SearchEvent event) {
Fragment fragment;

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();
}

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

@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(SyncEventFinished event) {
Bundle bundle = event.getIntent().getExtras();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class LocalFileListAdapter extends RecyclerView.Adapter<RecyclerView.View
private List<File> mFiles = new ArrayList<>();
private List<File> mFilesAll = new ArrayList<>();
private boolean mLocalFolderPicker;
private boolean gridView;
private boolean gridView = false;
private LocalFileListFragmentInterface localFileListFragmentInterface;
private Set<File> checkedFiles;

Expand Down
Loading