mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +03:00
Code optimisation, copyrights added and bug fixing.
This commit is contained in:
parent
ccb07fc73b
commit
a7e925d692
10 changed files with 141 additions and 309 deletions
|
@ -2,9 +2,11 @@
|
|||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Andy Scherzinger
|
||||
* @author TSI-mc
|
||||
* Copyright (C) 2016 Andy Scherzinger
|
||||
* Copyright (C) 2016 Nextcloud
|
||||
* Copyright (C) 2016 ownCloud Inc.
|
||||
* Copyright (C) 2022 TSI-mc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
|
@ -27,7 +29,6 @@ import android.annotation.SuppressLint;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
@ -39,14 +40,19 @@ import com.google.android.material.appbar.AppBarLayout;
|
|||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.card.MaterialCardView;
|
||||
import com.google.android.material.textview.MaterialTextView;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.utils.theme.ThemeButtonUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeLayoutUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
@ -58,7 +64,7 @@ import androidx.core.content.ContextCompat;
|
|||
/**
|
||||
* Base class providing toolbar registration functionality, see {@link #setupToolbar(boolean, boolean)}.
|
||||
*/
|
||||
public abstract class ToolbarActivity extends BaseActivity {
|
||||
public abstract class ToolbarActivity extends BaseActivity implements Injectable {
|
||||
protected MaterialButton mMenuButton;
|
||||
protected MaterialTextView mSearchText;
|
||||
protected MaterialButton mSwitchAccountButton;
|
||||
|
@ -74,16 +80,23 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|||
protected AppCompatSpinner mToolbarSpinner;
|
||||
private boolean isHomeSearchToolbarShow = false;
|
||||
|
||||
@Inject public ThemeColorUtils themeColorUtils;
|
||||
@Inject public ThemeLayoutUtils themeLayoutUtils;
|
||||
@Inject public ThemeToolbarUtils themeToolbarUtils;
|
||||
@Inject public ThemeUtils themeUtils;
|
||||
@Inject public ThemeDrawableUtils themeDrawableUtils;
|
||||
@Inject public ThemeButtonUtils themeButtonUtils;
|
||||
|
||||
/**
|
||||
* Toolbar setup that must be called in implementer's {@link #onCreate} after {@link #setContentView} if they want
|
||||
* to use the toolbar.
|
||||
*/
|
||||
private void setupToolbar(boolean isHomeSearchToolbarShow, boolean showSortListButtonGroup) {
|
||||
int fontColor = ThemeColorUtils.appBarPrimaryFontColor(this);
|
||||
int fontColor = themeColorUtils.appBarPrimaryFontColor(this);
|
||||
|
||||
mToolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(mToolbar);
|
||||
ThemeToolbarUtils.colorStatusBar(this);
|
||||
themeToolbarUtils.colorStatusBar(this);
|
||||
|
||||
mAppBar = findViewById(R.id.appbar);
|
||||
mDefaultToolbar = findViewById(R.id.default_toolbar);
|
||||
|
@ -108,11 +121,11 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|||
mToolbarSpinner = findViewById(R.id.toolbar_spinner);
|
||||
|
||||
if (mToolbar.getOverflowIcon() != null) {
|
||||
ThemeDrawableUtils.tintDrawable(mToolbar.getOverflowIcon(), fontColor);
|
||||
themeDrawableUtils.tintDrawable(mToolbar.getOverflowIcon(), fontColor);
|
||||
}
|
||||
|
||||
if (mToolbar.getNavigationIcon() != null) {
|
||||
ThemeDrawableUtils.tintDrawable(mToolbar.getNavigationIcon(), fontColor);
|
||||
themeDrawableUtils.tintDrawable(mToolbar.getNavigationIcon(), fontColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,7 +144,7 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|||
String title;
|
||||
boolean isRoot = isRoot(chosenFile);
|
||||
|
||||
title = isRoot ? ThemeUtils.getDefaultDisplayNameForRootFolder(this) : chosenFile.getFileName();
|
||||
title = isRoot ? themeUtils.getDefaultDisplayNameForRootFolder(this) : chosenFile.getFileName();
|
||||
updateActionBarTitleAndHomeButtonByString(title);
|
||||
|
||||
if (mAppBar != null) {
|
||||
|
@ -163,13 +176,13 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|||
R.animator.appbar_elevation_off));
|
||||
mDefaultToolbar.setVisibility(View.GONE);
|
||||
mHomeSearchToolbar.setVisibility(View.VISIBLE);
|
||||
ThemeToolbarUtils.colorStatusBar(this, ContextCompat.getColor(this, R.color.bg_default));
|
||||
themeToolbarUtils.colorStatusBar(this, ContextCompat.getColor(this, R.color.bg_default));
|
||||
} else {
|
||||
mAppBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(mAppBar.getContext(),
|
||||
R.animator.appbar_elevation_on));
|
||||
mDefaultToolbar.setVisibility(View.VISIBLE);
|
||||
mHomeSearchToolbar.setVisibility(View.GONE);
|
||||
ThemeToolbarUtils.colorStatusBar(this);
|
||||
themeToolbarUtils.colorStatusBar(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +198,7 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|||
|
||||
// set & color the chosen title
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
ThemeToolbarUtils.setColoredTitle(actionBar, titleToSet, this);
|
||||
themeToolbarUtils.setColoredTitle(actionBar, titleToSet, this);
|
||||
|
||||
// set home button properties
|
||||
if (actionBar != null) {
|
||||
|
@ -277,11 +290,7 @@ public abstract class ToolbarActivity extends BaseActivity {
|
|||
}
|
||||
|
||||
public void updateToolbarSubtitle(@NonNull String subtitle) {
|
||||
if (TextUtils.isEmpty(subtitle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
ThemeToolbarUtils.setColoredSubtitle(actionBar, subtitle, this);
|
||||
themeToolbarUtils.setColoredSubtitle(actionBar, subtitle, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,25 +42,31 @@ import com.owncloud.android.datamodel.GalleryItems
|
|||
import com.owncloud.android.datamodel.OCFile
|
||||
import com.owncloud.android.ui.activity.ComponentsGetter
|
||||
import com.owncloud.android.ui.fragment.GalleryFragment
|
||||
import com.owncloud.android.ui.fragment.GalleryFragmentBottomSheetDialog
|
||||
import com.owncloud.android.ui.fragment.SearchType
|
||||
import com.owncloud.android.ui.interfaces.OCFileListFragmentInterface
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.FileSortOrder
|
||||
import com.owncloud.android.utils.FileStorageUtils
|
||||
import com.owncloud.android.utils.MimeTypeUtil
|
||||
import com.owncloud.android.utils.theme.ThemeColorUtils
|
||||
import com.owncloud.android.utils.theme.ThemeDrawableUtils
|
||||
import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView.SectionedAdapter
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
class GalleryAdapter(
|
||||
val context: Context,
|
||||
user: User,
|
||||
ocFileListFragmentInterface: OCFileListFragmentInterface,
|
||||
preferences: AppPreferences,
|
||||
transferServiceGetter: ComponentsGetter
|
||||
transferServiceGetter: ComponentsGetter,
|
||||
themeColorUtils: ThemeColorUtils,
|
||||
themeDrawableUtils: ThemeDrawableUtils
|
||||
) : SectionedRecyclerViewAdapter<SectionedViewHolder>(), CommonOCFileListAdapterInterface, SectionedAdapter {
|
||||
private var files: List<GalleryItems> = mutableListOf()
|
||||
private var ocFileListDelegate: OCFileListDelegate
|
||||
private val ocFileListDelegate: OCFileListDelegate
|
||||
private var storageManager: FileDataStorageManager
|
||||
|
||||
init {
|
||||
|
@ -76,7 +82,9 @@ class GalleryAdapter(
|
|||
true,
|
||||
transferServiceGetter,
|
||||
showMetadata = false,
|
||||
showShareAvatar = false
|
||||
showShareAvatar = false,
|
||||
themeColorUtils,
|
||||
themeDrawableUtils
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -150,66 +158,47 @@ class GalleryAdapter(
|
|||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun showAllGalleryItems(storageManager: FileDataStorageManager,
|
||||
fun showAllGalleryItems(
|
||||
storageManager: FileDataStorageManager,
|
||||
remotePath: String,
|
||||
mediaObject: MutableList<OCFile>,
|
||||
isVideoHideClicked: Boolean, isImageHideClicked: Boolean,
|
||||
imageList: MutableList<OCFile>, videoList: MutableList<OCFile>, photoFragment: GalleryFragment) {
|
||||
|
||||
mediaState: GalleryFragmentBottomSheetDialog.MediaState,
|
||||
photoFragment: GalleryFragment
|
||||
) {
|
||||
|
||||
val items = storageManager.allGalleryItems
|
||||
mediaObject.clear()
|
||||
|
||||
for (c in items) {
|
||||
if (c is OCFile) {
|
||||
if (c.remotePath.contains(remotePath)) {
|
||||
mediaObject.add(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
mediaObject.addAll(
|
||||
items.filter { it != null && it.remotePath.startsWith(remotePath) }
|
||||
)
|
||||
|
||||
setAdapterWithHideShowImage(
|
||||
mediaObject, isVideoHideClicked, isImageHideClicked, imageList, videoList,
|
||||
setMediaFilter(
|
||||
mediaObject, mediaState,
|
||||
photoFragment
|
||||
)
|
||||
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
//Set Image/Video List According to Selection of Hide/Show Image/Video
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun setAdapterWithHideShowImage(
|
||||
fun setMediaFilter(
|
||||
mediaObject: List<OCFile>,
|
||||
isVideoHideClicked: Boolean, isImageHideClicked: Boolean,
|
||||
imageList: MutableList<OCFile>, videoList: MutableList<OCFile>,
|
||||
mediaState: GalleryFragmentBottomSheetDialog.MediaState,
|
||||
photoFragment: GalleryFragment
|
||||
) {
|
||||
|
||||
val finalSortedList: List<OCFile>
|
||||
val finalSortedList: List<OCFile> = when (mediaState) {
|
||||
GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_PHOTOS_ONLY -> {
|
||||
mediaObject.filter { MimeTypeUtil.isImage(it.mimeType) }.distinct()
|
||||
}
|
||||
GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_VIDEOS_ONLY -> {
|
||||
mediaObject.filter { MimeTypeUtil.isVideo(it.mimeType) }.distinct()
|
||||
}
|
||||
else -> mediaObject
|
||||
}
|
||||
|
||||
if (isVideoHideClicked) {
|
||||
imageList.clear()
|
||||
for (ocFile in mediaObject) {
|
||||
if (MimeTypeUtil.isImage(ocFile.mimeType) && !imageList.contains(ocFile)) {
|
||||
imageList.add(ocFile)
|
||||
}
|
||||
}
|
||||
finalSortedList = imageList
|
||||
if (imageList.isEmpty()) {
|
||||
photoFragment.setEmptyListMessage(SearchType.GALLERY_SEARCH)
|
||||
}
|
||||
} else if (isImageHideClicked) {
|
||||
videoList.clear()
|
||||
for (ocFile in mediaObject) {
|
||||
if (MimeTypeUtil.isVideo(ocFile.mimeType) && !videoList.contains(ocFile)) {
|
||||
videoList.add(ocFile)
|
||||
}
|
||||
}
|
||||
finalSortedList = videoList
|
||||
if (videoList.isEmpty()) {
|
||||
photoFragment.setEmptyListMessage(SearchType.GALLERY_SEARCH)
|
||||
}
|
||||
} else {
|
||||
finalSortedList = mediaObject
|
||||
if (finalSortedList.isEmpty()) {
|
||||
photoFragment.setEmptyListMessage(SearchType.GALLERY_SEARCH)
|
||||
}
|
||||
|
||||
files = finalSortedList
|
||||
|
@ -221,7 +210,7 @@ class GalleryAdapter(
|
|||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun resetAdapter(){
|
||||
fun clear() {
|
||||
files = emptyList()
|
||||
Handler(Looper.getMainLooper()).post { notifyDataSetChanged() }
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
@ -45,7 +44,6 @@ 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.utils.theme.ThemeColorUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeMenuUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -73,14 +71,11 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
private GalleryAdapter mAdapter;
|
||||
|
||||
private static final int SELECT_LOCATION_REQUEST_CODE = 212;
|
||||
private OCFile remoteFilePath;
|
||||
private String remotePath = "/";
|
||||
private OCFile remoteFile = new OCFile("/");//default root path
|
||||
private List<OCFile> mediaObject;
|
||||
private GalleryFragmentBottomSheetDialog galleryFragmentBottomSheetDialog;
|
||||
private List<OCFile> imageList;
|
||||
private List<OCFile> videoList;
|
||||
|
||||
@Inject AppPreferences appPreferences;
|
||||
@Inject ThemeMenuUtils themeMenuUtils;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -92,11 +87,8 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
if (galleryFragmentBottomSheetDialog == null) {
|
||||
FileActivity activity = (FileActivity) getActivity();
|
||||
|
||||
galleryFragmentBottomSheetDialog = new GalleryFragmentBottomSheetDialog(activity,
|
||||
this);
|
||||
galleryFragmentBottomSheetDialog = new GalleryFragmentBottomSheetDialog(this);
|
||||
}
|
||||
imageList = new ArrayList<>();
|
||||
videoList = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,7 +133,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
menuItemAddRemoveValue = MenuItemAddRemove.REMOVE_GRID_AND_SORT;
|
||||
requireActivity().invalidateOptionsMenu();
|
||||
|
||||
updateSubtitle(galleryFragmentBottomSheetDialog.isHideVideos(), galleryFragmentBottomSheetDialog.isHideImages());
|
||||
updateSubtitle(galleryFragmentBottomSheetDialog.getCurrMediaState());
|
||||
|
||||
handleSearchEvent();
|
||||
}
|
||||
|
@ -152,7 +144,9 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
accountManager.getUser(),
|
||||
this,
|
||||
preferences,
|
||||
mContainerActivity);
|
||||
mContainerActivity,
|
||||
themeColorUtils,
|
||||
themeDrawableUtils);
|
||||
|
||||
// val spacing = resources.getDimensionPixelSize(R.dimen.media_grid_spacing)
|
||||
// binding.list.addItemDecoration(MediaGridItemDecoration(spacing))
|
||||
|
@ -226,13 +220,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
startDate = (System.currentTimeMillis() / 1000) - 30 * 24 * 60 * 60;
|
||||
endDate = System.currentTimeMillis() / 1000;
|
||||
|
||||
photoSearchTask = new GallerySearchTask(this,
|
||||
accountManager.getUser(),
|
||||
mContainerActivity.getStorageManager(),
|
||||
startDate,
|
||||
endDate,
|
||||
limit)
|
||||
.execute();
|
||||
runGallerySearchTask();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,24 +258,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
runGallerySearchTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
remotePath = setDefaultRemotePath();
|
||||
}
|
||||
|
||||
private String setDefaultRemotePath() {
|
||||
if (remoteFilePath == null) {
|
||||
setRemoteFilePath(remotePath);
|
||||
}
|
||||
return remotePath;
|
||||
}
|
||||
|
||||
private void setRemoteFilePath(String remotePath) {
|
||||
remoteFilePath = new OCFile(remotePath);
|
||||
remoteFilePath.setFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
@ -297,8 +267,8 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
MenuItem menuItem = menu.findItem(R.id.action_three_dot_icon);
|
||||
|
||||
if (menuItem != null) {
|
||||
ThemeMenuUtils.tintMenuIcon(requireContext(), menuItem,
|
||||
ThemeColorUtils.appBarPrimaryFontColor(requireContext()));
|
||||
themeMenuUtils.tintMenuIcon(menuItem,
|
||||
themeColorUtils.appBarPrimaryFontColor(requireContext()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -307,31 +277,28 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
// Handle item selection
|
||||
if (item.getItemId() == R.id.action_three_dot_icon) {
|
||||
if (!photoSearchQueryRunning) {
|
||||
galleryFragmentBottomSheetDialog.show();
|
||||
return true;
|
||||
}
|
||||
if (item.getItemId() == R.id.action_three_dot_icon && !photoSearchQueryRunning
|
||||
&& galleryFragmentBottomSheetDialog != null) {
|
||||
galleryFragmentBottomSheetDialog.show(getChildFragmentManager(),"data" );
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
if (requestCode == SELECT_LOCATION_REQUEST_CODE) {
|
||||
if (data != null) {
|
||||
OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
|
||||
if (chosenFolder != null) {
|
||||
remoteFilePath = chosenFolder;
|
||||
searchAndDisplayAfterChangingFolder();
|
||||
}
|
||||
if (requestCode == SELECT_LOCATION_REQUEST_CODE && data != null) {
|
||||
OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
|
||||
if (chosenFolder != null) {
|
||||
remoteFile = chosenFolder;
|
||||
searchAndDisplayAfterChangingFolder();
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void searchAndDisplayAfterChangingFolder() {
|
||||
mAdapter.resetAdapter();
|
||||
mAdapter.clear();
|
||||
mediaObject.clear();
|
||||
runGallerySearchTask();
|
||||
}
|
||||
|
@ -382,18 +349,17 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateMediaContent(boolean isHideVideos, boolean isHidePhotos) {
|
||||
public void updateMediaContent(GalleryFragmentBottomSheetDialog.MediaState mediaState) {
|
||||
if (!mediaObject.isEmpty()) {
|
||||
mAdapter.setAdapterWithHideShowImage(mediaObject,
|
||||
isHideVideos,
|
||||
isHidePhotos, imageList, videoList,
|
||||
this);
|
||||
mAdapter.setMediaFilter(mediaObject,
|
||||
mediaState,
|
||||
this);
|
||||
|
||||
} else {
|
||||
setEmptyListMessage(SearchType.GALLERY_SEARCH);
|
||||
}
|
||||
|
||||
updateSubtitle(isHideVideos, isHidePhotos);
|
||||
updateSubtitle(mediaState);
|
||||
|
||||
}
|
||||
|
||||
|
@ -405,20 +371,19 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
}
|
||||
|
||||
public void showAllGalleryItems() {
|
||||
mAdapter.showAllGalleryItems(mContainerActivity.getStorageManager(), remoteFilePath.getRemotePath(),
|
||||
mediaObject, galleryFragmentBottomSheetDialog.isHideVideos(),
|
||||
galleryFragmentBottomSheetDialog.isHideImages(),
|
||||
imageList, videoList, this);
|
||||
mAdapter.showAllGalleryItems(mContainerActivity.getStorageManager(), remoteFile.getRemotePath(),
|
||||
mediaObject, galleryFragmentBottomSheetDialog.getCurrMediaState(),
|
||||
this);
|
||||
|
||||
updateSubtitle(galleryFragmentBottomSheetDialog.isHideVideos(), galleryFragmentBottomSheetDialog.isHideImages());
|
||||
updateSubtitle(galleryFragmentBottomSheetDialog.getCurrMediaState());
|
||||
}
|
||||
|
||||
private void updateSubtitle(boolean isHideVideos, boolean isHidePhotos) {
|
||||
private void updateSubtitle(GalleryFragmentBottomSheetDialog.MediaState mediaState) {
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
String subTitle = requireContext().getResources().getString(R.string.subtitle_photos_videos);
|
||||
if (isHideVideos) {
|
||||
if (mediaState == GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_PHOTOS_ONLY) {
|
||||
subTitle = requireContext().getResources().getString(R.string.subtitle_photos_only);
|
||||
} else if (isHidePhotos) {
|
||||
} else if (mediaState == GalleryFragmentBottomSheetDialog.MediaState.MEDIA_STATE_VIDEOS_ONLY) {
|
||||
subTitle = requireContext().getResources().getString(R.string.subtitle_videos_only);
|
||||
}
|
||||
if (requireActivity() instanceof ToolbarActivity) {
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author TSI-mc
|
||||
* Copyright (C) 2022 TSI-mc
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
public interface GalleryFragmentBottomSheetActions {
|
||||
|
||||
/**
|
||||
* show/hide all the images & videos in particular Folder.
|
||||
*/
|
||||
void updateMediaContent(boolean isHideVideos, boolean isHidePhotos);
|
||||
|
||||
/**
|
||||
* load all media of a particular folder.
|
||||
*/
|
||||
void selectMediaFolder();
|
||||
|
||||
}
|
|
@ -31,4 +31,4 @@ interface GalleryFragmentBottomSheetActions {
|
|||
* load all media of a particular folder.
|
||||
*/
|
||||
fun selectMediaFolder()
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author TSI-mc
|
||||
* Copyright (C) 2022 TSI-mc
|
||||
* Copyright (C) 2022 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.databinding.FragmentGalleryBottomSheetBinding;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class GalleryFragmentBottomSheetDialog extends BottomSheetDialog {
|
||||
|
||||
//media view states
|
||||
private static final int MEDIA_STATE_DEFAULT = 1; //when both photos and videos selected
|
||||
private static final int MEDIA_STATE_PHOTOS_ONLY = 2;
|
||||
private static final int MEDIA_STATE_VIDEOS_ONLY = 3;
|
||||
|
||||
private FragmentGalleryBottomSheetBinding binding;
|
||||
private final GalleryFragmentBottomSheetActions actions;
|
||||
private BottomSheetBehavior mBottomBehavior;
|
||||
private int currentMediaState = MEDIA_STATE_DEFAULT;
|
||||
|
||||
public GalleryFragmentBottomSheetDialog(FileActivity fileActivity,
|
||||
GalleryFragmentBottomSheetActions actions) {
|
||||
super(fileActivity);
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = FragmentGalleryBottomSheetBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
if (getWindow() != null) {
|
||||
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
}
|
||||
setupLayout();
|
||||
setupClickListener();
|
||||
mBottomBehavior = BottomSheetBehavior.from((View) binding.getRoot().getParent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mBottomBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
}
|
||||
|
||||
private void setupLayout() {
|
||||
if (currentMediaState == MEDIA_STATE_PHOTOS_ONLY) {
|
||||
binding.tickMarkShowImages.setVisibility(View.VISIBLE);
|
||||
binding.tickMarkShowVideo.setVisibility(View.GONE);
|
||||
} else if (currentMediaState == MEDIA_STATE_VIDEOS_ONLY) {
|
||||
binding.tickMarkShowImages.setVisibility(View.GONE);
|
||||
binding.tickMarkShowVideo.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
binding.tickMarkShowImages.setVisibility(View.VISIBLE);
|
||||
binding.tickMarkShowVideo.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupClickListener() {
|
||||
|
||||
binding.hideImages.setOnClickListener(v -> {
|
||||
|
||||
if (currentMediaState == MEDIA_STATE_VIDEOS_ONLY) {
|
||||
currentMediaState = MEDIA_STATE_DEFAULT;
|
||||
} else {
|
||||
currentMediaState = MEDIA_STATE_VIDEOS_ONLY;
|
||||
}
|
||||
notifyStateChange();
|
||||
dismiss();
|
||||
});
|
||||
|
||||
binding.hideVideo.setOnClickListener(v -> {
|
||||
|
||||
if (currentMediaState == MEDIA_STATE_PHOTOS_ONLY) {
|
||||
currentMediaState = MEDIA_STATE_DEFAULT;
|
||||
} else {
|
||||
currentMediaState = MEDIA_STATE_PHOTOS_ONLY;
|
||||
}
|
||||
notifyStateChange();
|
||||
dismiss();
|
||||
});
|
||||
|
||||
binding.selectMediaFolder.setOnClickListener(v -> {
|
||||
|
||||
actions.selectMediaFolder();
|
||||
dismiss();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void notifyStateChange() {
|
||||
setupLayout();
|
||||
actions.updateMediaContent(isHideVideos(), isHideImages());
|
||||
}
|
||||
|
||||
public boolean isHideImages() {
|
||||
return currentMediaState == MEDIA_STATE_VIDEOS_ONLY;
|
||||
}
|
||||
|
||||
public boolean isHideVideos() {
|
||||
return currentMediaState == MEDIA_STATE_PHOTOS_ONLY;
|
||||
}
|
||||
|
||||
}
|
|
@ -33,10 +33,10 @@ class GalleryFragmentBottomSheetDialog(
|
|||
) : BottomSheetDialogFragment() {
|
||||
private lateinit var binding: FragmentGalleryBottomSheetBinding
|
||||
private lateinit var mBottomBehavior: BottomSheetBehavior<*>
|
||||
private var currentMediaState: MediaState = MediaState.MEDIA_STATE_DEFAULT
|
||||
private var currentMediaState : MediaState = MediaState.MEDIA_STATE_DEFAULT
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = FragmentGalleryBottomSheetBinding.inflate(layoutInflater, container, false)
|
||||
binding = FragmentGalleryBottomSheetBinding.inflate(layoutInflater,container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
|
@ -102,9 +102,9 @@ class GalleryFragmentBottomSheetDialog(
|
|||
val currMediaState: MediaState
|
||||
get() = currentMediaState
|
||||
|
||||
enum class MediaState {
|
||||
enum class MediaState{
|
||||
MEDIA_STATE_DEFAULT,
|
||||
MEDIA_STATE_PHOTOS_ONLY,
|
||||
MEDIA_STATE_VIDEOS_ONLY
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,23 @@
|
|||
<!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author TSI-mc
|
||||
Copyright (C) 2022 TSI-mc
|
||||
Copyright (C) 2022 Nextcloud GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
<!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author TSI-mc
|
||||
Copyright (C) 2022 TSI-mc
|
||||
Copyright (C) 2022 Nextcloud GmbH
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="@dimen/standard_margin"
|
||||
android:layout_marginEnd="30dp"
|
||||
android:layout_toRightOf="@id/hideImagesImageview"
|
||||
android:layout_toEndOf="@id/hideImagesImageview"
|
||||
android:text="@string/show_images"
|
||||
android:textColor="@color/text_color"
|
||||
android:textSize="@dimen/bottom_sheet_text_size" />
|
||||
|
@ -64,7 +64,6 @@
|
|||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_tick"
|
||||
android:visibility="gone"
|
||||
|
@ -99,7 +98,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="@dimen/standard_margin"
|
||||
android:layout_toRightOf="@id/hideVideoImageView"
|
||||
android:layout_toEndOf="@id/hideVideoImageView"
|
||||
android:text="@string/show_video"
|
||||
android:textColor="@color/text_color"
|
||||
android:textSize="@dimen/bottom_sheet_text_size" />
|
||||
|
@ -108,7 +107,7 @@
|
|||
android:id="@+id/tickMarkShowVideo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_tick"
|
||||
android:visibility="gone"
|
||||
|
|
Loading…
Reference in a new issue