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
*
* @author TSI-mc
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2015 ownCloud Inc.
* 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
* it under the terms of the GNU General Public License version 2,
@ -2367,4 +2369,8 @@ public class FileDataStorageManager {
public User getUser() {
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;
mDoNotEnterEncryptedFolder = true;
mChooseBtn.setText(getResources().getString(R.string.common_select));
mChooseBtn.setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_tick,
null));
break;
default:
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.ThemeDrawableUtils
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.Date
@ -65,7 +65,7 @@ class GalleryAdapter(
themeColorUtils: ThemeColorUtils,
themeDrawableUtils: ThemeDrawableUtils
) : SectionedRecyclerViewAdapter<SectionedViewHolder>(), CommonOCFileListAdapterInterface, PopupTextProvider {
private var files: List<GalleryItems> = mutableListOf()
var files: List<GalleryItems> = mutableListOf()
private val ocFileListDelegate: OCFileListDelegate
private var storageManager: FileDataStorageManager
@ -163,42 +163,37 @@ class GalleryAdapter(
@SuppressLint("NotifyDataSetChanged")
fun showAllGalleryItems(
storageManager: FileDataStorageManager,
remotePath: String,
mediaObject: MutableList<OCFile>,
mediaState: GalleryFragmentBottomSheetDialog.MediaState,
photoFragment: GalleryFragment
) {
val items = storageManager.allGalleryItems
mediaObject.clear()
mediaObject.addAll(
items.filter { it != null && it.remotePath.startsWith(remotePath) }
)
val filteredList = items.filter { it != null && it.remotePath.startsWith(remotePath) }
setMediaFilter(
mediaObject, mediaState,
setMediaFilter(filteredList,
mediaState,
photoFragment
)
}
// Set Image/Video List According to Selection of Hide/Show Image/Video
@SuppressLint("NotifyDataSetChanged")
fun setMediaFilter(
mediaObject: List<OCFile>,
private fun setMediaFilter(
items: List<OCFile>,
mediaState: GalleryFragmentBottomSheetDialog.MediaState,
photoFragment: GalleryFragment
) {
val finalSortedList: List<OCFile> = when (mediaState) {
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 -> {
mediaObject.filter { MimeTypeUtil.isVideo(it.mimeType) }.distinct()
items.filter { MimeTypeUtil.isVideo(it.mimeType) }.distinct()
}
else -> mediaObject
else -> items
}
if (finalSortedList.isEmpty()) {

View file

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

View file

@ -918,12 +918,4 @@
<string name="select_media_folder">Medienordner festlegen</string>
<string name="choose_location">Speicherort wä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>

View file

@ -1016,23 +1016,10 @@
<string name="select_media_folder">Set media folder</string>
<string name="choose_location">Choose location</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="unlock_file">Unlock file</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_app">Locked by %1$s app</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>