Code optimisation.

This commit is contained in:
A117870935 2022-06-24 10:45:22 +05:30
parent 757102a5f1
commit 414e0754bf
6 changed files with 26 additions and 65 deletions

View file

@ -1,9 +1,11 @@
/* /*
* ownCloud Android client application * ownCloud Android client application
* *
* @author TSI-mc
* Copyright (C) 2012 Bartek Przybylski * Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2015 ownCloud Inc. * Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2021 Chris Narkiewicz <hello@ezaquarii.com> * Copyright (C) 2021 Chris Narkiewicz <hello@ezaquarii.com>
* Copyright (C) 2022 TSI-mc
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, * it under the terms of the GNU General Public License version 2,
@ -2367,4 +2369,8 @@ public class FileDataStorageManager {
public User getUser() { public User getUser() {
return user; return user;
} }
public OCFile getDefaultRootPath(){
return new OCFile(OCFile.ROOT_PATH);
}
} }

View file

@ -139,8 +139,6 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
mSearchOnlyFolders = true; mSearchOnlyFolders = true;
mDoNotEnterEncryptedFolder = true; mDoNotEnterEncryptedFolder = true;
mChooseBtn.setText(getResources().getString(R.string.common_select)); mChooseBtn.setText(getResources().getString(R.string.common_select));
mChooseBtn.setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_tick,
null));
break; break;
default: default:
caption = themeUtils.getDefaultDisplayNameForRootFolder(this); caption = themeUtils.getDefaultDisplayNameForRootFolder(this);

View file

@ -51,7 +51,7 @@ import com.owncloud.android.utils.FileStorageUtils
import com.owncloud.android.utils.theme.ThemeColorUtils import com.owncloud.android.utils.theme.ThemeColorUtils
import com.owncloud.android.utils.theme.ThemeDrawableUtils import com.owncloud.android.utils.theme.ThemeDrawableUtils
import com.owncloud.android.utils.MimeTypeUtil import com.owncloud.android.utils.MimeTypeUtil
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView.SectionedAdapter import me.zhanghai.android.fastscroll.PopupTextProvider
import java.util.Calendar import java.util.Calendar
import java.util.Date import java.util.Date
@ -65,7 +65,7 @@ class GalleryAdapter(
themeColorUtils: ThemeColorUtils, themeColorUtils: ThemeColorUtils,
themeDrawableUtils: ThemeDrawableUtils themeDrawableUtils: ThemeDrawableUtils
) : SectionedRecyclerViewAdapter<SectionedViewHolder>(), CommonOCFileListAdapterInterface, PopupTextProvider { ) : SectionedRecyclerViewAdapter<SectionedViewHolder>(), CommonOCFileListAdapterInterface, PopupTextProvider {
private var files: List<GalleryItems> = mutableListOf() var files: List<GalleryItems> = mutableListOf()
private val ocFileListDelegate: OCFileListDelegate private val ocFileListDelegate: OCFileListDelegate
private var storageManager: FileDataStorageManager private var storageManager: FileDataStorageManager
@ -163,42 +163,37 @@ class GalleryAdapter(
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
fun showAllGalleryItems( fun showAllGalleryItems(
storageManager: FileDataStorageManager,
remotePath: String, remotePath: String,
mediaObject: MutableList<OCFile>,
mediaState: GalleryFragmentBottomSheetDialog.MediaState, mediaState: GalleryFragmentBottomSheetDialog.MediaState,
photoFragment: GalleryFragment photoFragment: GalleryFragment
) { ) {
val items = storageManager.allGalleryItems val items = storageManager.allGalleryItems
mediaObject.clear()
mediaObject.addAll( val filteredList = items.filter { it != null && it.remotePath.startsWith(remotePath) }
items.filter { it != null && it.remotePath.startsWith(remotePath) }
)
setMediaFilter( setMediaFilter(filteredList,
mediaObject, mediaState, mediaState,
photoFragment photoFragment
) )
} }
// Set Image/Video List According to Selection of Hide/Show Image/Video // Set Image/Video List According to Selection of Hide/Show Image/Video
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
fun setMediaFilter( private fun setMediaFilter(
mediaObject: List<OCFile>, items: List<OCFile>,
mediaState: GalleryFragmentBottomSheetDialog.MediaState, mediaState: GalleryFragmentBottomSheetDialog.MediaState,
photoFragment: GalleryFragment photoFragment: GalleryFragment
) { ) {
val finalSortedList: List<OCFile> = when (mediaState) { val finalSortedList: List<OCFile> = when (mediaState) {
GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_PHOTOS_ONLY -> { GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_PHOTOS_ONLY -> {
mediaObject.filter { MimeTypeUtil.isImage(it.mimeType) }.distinct() items.filter { MimeTypeUtil.isImage(it.mimeType) }.distinct()
} }
GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_VIDEOS_ONLY -> { GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_VIDEOS_ONLY -> {
mediaObject.filter { MimeTypeUtil.isVideo(it.mimeType) }.distinct() items.filter { MimeTypeUtil.isVideo(it.mimeType) }.distinct()
} }
else -> mediaObject else -> items
} }
if (finalSortedList.isEmpty()) { if (finalSortedList.isEmpty()) {

View file

@ -33,10 +33,11 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.nextcloud.utils.view.FastScroll;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.activity.FolderPickerActivity; import com.owncloud.android.ui.activity.FolderPickerActivity;
import com.owncloud.android.ui.activity.ToolbarActivity; import com.owncloud.android.ui.activity.ToolbarActivity;
@ -44,11 +45,9 @@ import com.owncloud.android.ui.adapter.CommonOCFileListAdapterInterface;
import com.owncloud.android.ui.adapter.GalleryAdapter; import com.owncloud.android.ui.adapter.GalleryAdapter;
import com.owncloud.android.ui.asynctasks.GallerySearchTask; import com.owncloud.android.ui.asynctasks.GallerySearchTask;
import com.owncloud.android.ui.events.ChangeMenuEvent; import com.owncloud.android.ui.events.ChangeMenuEvent;
import com.owncloud.android.ui.fragment.util.GalleryFastScrollViewHelper;
import com.owncloud.android.utils.theme.ThemeMenuUtils; import com.owncloud.android.utils.theme.ThemeMenuUtils;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -71,10 +70,11 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
private GalleryAdapter mAdapter; private GalleryAdapter mAdapter;
private static final int SELECT_LOCATION_REQUEST_CODE = 212; private static final int SELECT_LOCATION_REQUEST_CODE = 212;
private OCFile remoteFilePath; private OCFile remoteFile;
private GalleryFragmentBottomSheetDialog galleryFragmentBottomSheetDialog; private GalleryFragmentBottomSheetDialog galleryFragmentBottomSheetDialog;
@Inject ThemeMenuUtils themeMenuUtils; @Inject ThemeMenuUtils themeMenuUtils;
@Inject FileDataStorageManager fileDataStorageManager;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -104,6 +104,8 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = super.onCreateView(inflater, container, savedInstanceState); View v = super.onCreateView(inflater, container, savedInstanceState);
remoteFile = fileDataStorageManager.getDefaultRootPath();
getRecyclerView().addOnScrollListener(new RecyclerView.OnScrollListener() { getRecyclerView().addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
@ -119,12 +121,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
if (mediaObject == null) {
mediaObject = new ArrayList<>();
} else {
mediaObject.clear();
}
currentSearchType = SearchType.GALLERY_SEARCH; currentSearchType = SearchType.GALLERY_SEARCH;
menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT; menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
@ -162,8 +158,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
@Override @Override
public void onRefresh() { public void onRefresh() {
super.onRefresh(); super.onRefresh();
mediaObject.clear();
handleSearchEvent(); handleSearchEvent();
} }
@ -288,7 +282,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
private void searchAndDisplayAfterChangingFolder() { private void searchAndDisplayAfterChangingFolder() {
mAdapter.clear(); mAdapter.clear();
mediaObject.clear();
runGallerySearchTask(); runGallerySearchTask();
} }
@ -339,17 +332,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
@Override @Override
public void updateMediaContent(GalleryFragmentBottomSheetDialog.MediaState mediaState) { public void updateMediaContent(GalleryFragmentBottomSheetDialog.MediaState mediaState) {
if (!mediaObject.isEmpty()) { showAllGalleryItems();
mAdapter.setMediaFilter(mediaObject,
mediaState,
this);
} else {
setEmptyListMessage(SearchType.GALLERY_SEARCH);
}
updateSubtitle(mediaState);
} }
@Override @Override
@ -360,8 +343,8 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
} }
public void showAllGalleryItems() { public void showAllGalleryItems() {
mAdapter.showAllGalleryItems(mContainerActivity.getStorageManager(), remoteFile.getRemotePath(), mAdapter.showAllGalleryItems(remoteFile.getRemotePath(),
mediaObject, galleryFragmentBottomSheetDialog.getCurrMediaState(), galleryFragmentBottomSheetDialog.getCurrMediaState(),
this); this);
updateSubtitle(galleryFragmentBottomSheetDialog.getCurrMediaState()); updateSubtitle(galleryFragmentBottomSheetDialog.getCurrMediaState());

View file

@ -918,12 +918,4 @@
<string name="select_media_folder">Medienordner festlegen</string> <string name="select_media_folder">Medienordner festlegen</string>
<string name="choose_location">Speicherort wählen</string> <string name="choose_location">Speicherort wählen</string>
<string name="common_select">Auswählen</string> <string name="common_select">Auswählen</string>
<string name="subtitle_photos_videos">Fotos &amp; videos</string>
<string name="show_images">Bilder anzeigen</string>
<string name="subtitle_photos_only">Nur Fotos</string>
<string name="show_video">Videos anzeigen</string>
<string name="subtitle_videos_only">Nur Videos</string>
<string name="select_media_folder">Medienordner festlegen</string>
<string name="choose_location">Speicherort wählen</string>
<string name="common_select">Auswählen</string>
</resources> </resources>

View file

@ -1016,23 +1016,10 @@
<string name="select_media_folder">Set media folder</string> <string name="select_media_folder">Set media folder</string>
<string name="choose_location">Choose location</string> <string name="choose_location">Choose location</string>
<string name="common_select">Select</string> <string name="common_select">Select</string>
<string name="subtitle_photos_videos">Photos &amp; videos</string>
<string name="show_images">Show photos</string>
<string name="subtitle_photos_only">Photos only</string>
<string name="show_video">Show videos</string>
<string name="subtitle_videos_only">Videos only</string>
<string name="select_media_folder">Set media folder</string>
<string name="lock_file">Lock file</string> <string name="lock_file">Lock file</string>
<string name="unlock_file">Unlock file</string> <string name="unlock_file">Unlock file</string>
<string name="error_file_lock">Error changing file lock status</string> <string name="error_file_lock">Error changing file lock status</string>
<string name="locked_by">Locked by %1$s</string> <string name="locked_by">Locked by %1$s</string>
<string name="locked_by_app">Locked by %1$s app</string> <string name="locked_by_app">Locked by %1$s app</string>
<string name="lock_expiration_info">Expires: %1$s</string> <string name="lock_expiration_info">Expires: %1$s</string>
<string name="hide_images">Hide images</string>
<string name="show_images">Show images</string>
<string name="hide_video">Hide video</string>
<string name="show_video">Show video</string>
<string name="select_media_folder">Select the \"Media\" folder</string>
<string name="choose_location">Choose location</string>
<string name="common_select">Select</string>
</resources> </resources>