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
fd7c0a95f1
commit
4d3d9297e9
10 changed files with 216 additions and 254 deletions
|
@ -5,10 +5,12 @@
|
|||
* @author David A. Velasco
|
||||
* @author Andy Scherzinger
|
||||
* @author Chris Narkiewicz
|
||||
* @author TSI-mc
|
||||
* Copyright (C) 2011 Bartek Przybylski
|
||||
* Copyright (C) 2016 ownCloud Inc.
|
||||
* Copyright (C) 2018 Andy Scherzinger
|
||||
* Copyright (C) 2019 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,
|
||||
|
@ -531,6 +533,10 @@ public class FileDisplayActivity extends FileActivity
|
|||
searchView.post(() -> searchView.setQuery(searchQuery, true));
|
||||
}
|
||||
setDrawerIndicatorEnabled(false);
|
||||
|
||||
//clear the subtitle while going from
|
||||
updateToolbarSubtitle("");
|
||||
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.addToBackStack(null);
|
||||
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
|
||||
|
|
|
@ -29,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;
|
||||
|
@ -52,9 +51,9 @@ import com.owncloud.android.utils.theme.ThemeLayoutUtils;
|
|||
import com.owncloud.android.utils.theme.ThemeToolbarUtils;
|
||||
import com.owncloud.android.utils.theme.ThemeUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
|
@ -291,10 +290,6 @@ public abstract class ToolbarActivity extends BaseActivity implements Injectable
|
|||
}
|
||||
|
||||
public void updateToolbarSubtitle(@NonNull String subtitle) {
|
||||
if (TextUtils.isEmpty(subtitle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
themeToolbarUtils.setColoredSubtitle(actionBar, subtitle, this);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ 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
|
||||
|
@ -161,67 +162,48 @@ 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setAdapterWithHideShowImage(
|
||||
mediaObject, isVideoHideClicked, isImageHideClicked, imageList, videoList,
|
||||
photoFragment
|
||||
mediaObject.addAll(
|
||||
items.filter { it != null && it.remotePath.startsWith(remotePath) }
|
||||
)
|
||||
|
||||
|
||||
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()) {
|
||||
if (finalSortedList.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
|
||||
}
|
||||
|
||||
files = finalSortedList
|
||||
.groupBy { firstOfMonth(it.modificationTimestamp) }
|
||||
|
@ -232,7 +214,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;
|
||||
|
@ -76,8 +74,6 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
private OCFile remoteFilePath;
|
||||
private GalleryFragmentBottomSheetDialog galleryFragmentBottomSheetDialog;
|
||||
|
||||
@Inject AppPreferences appPreferences;
|
||||
@Inject ThemeColorUtils themeColorUtils;
|
||||
@Inject ThemeMenuUtils themeMenuUtils;
|
||||
|
||||
@Override
|
||||
|
@ -90,8 +86,7 @@ public class GalleryFragment extends OCFileListFragment implements GalleryFragme
|
|||
if (galleryFragmentBottomSheetDialog == null) {
|
||||
FileActivity activity = (FileActivity) getActivity();
|
||||
|
||||
galleryFragmentBottomSheetDialog = new GalleryFragmentBottomSheetDialog(activity,
|
||||
this);
|
||||
galleryFragmentBottomSheetDialog = new GalleryFragmentBottomSheetDialog(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +132,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();
|
||||
}
|
||||
|
@ -216,13 +211,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,24 +249,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,31 +268,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();
|
||||
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) {
|
||||
if (requestCode == SELECT_LOCATION_REQUEST_CODE && data != null) {
|
||||
OCFile chosenFolder = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
|
||||
if (chosenFolder != null) {
|
||||
remoteFilePath = chosenFolder;
|
||||
remoteFile = chosenFolder;
|
||||
searchAndDisplayAfterChangingFolder();
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private void searchAndDisplayAfterChangingFolder() {
|
||||
mAdapter.resetAdapter();
|
||||
mAdapter.clear();
|
||||
mediaObject.clear();
|
||||
runGallerySearchTask();
|
||||
}
|
||||
|
@ -372,18 +340,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,
|
||||
mAdapter.setMediaFilter(mediaObject,
|
||||
mediaState,
|
||||
this);
|
||||
|
||||
} else {
|
||||
setEmptyListMessage(SearchType.GALLERY_SEARCH);
|
||||
}
|
||||
|
||||
updateSubtitle(isHideVideos, isHidePhotos);
|
||||
updateSubtitle(mediaState);
|
||||
|
||||
}
|
||||
|
||||
|
@ -395,20 +362,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) {
|
||||
|
|
|
@ -19,18 +19,16 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
public interface GalleryFragmentBottomSheetActions {
|
||||
package com.owncloud.android.ui.fragment
|
||||
|
||||
interface GalleryFragmentBottomSheetActions {
|
||||
/**
|
||||
* show/hide all the images & videos in particular Folder.
|
||||
*/
|
||||
void updateMediaContent(boolean isHideVideos, boolean isHidePhotos);
|
||||
fun updateMediaContent(mediaState: GalleryFragmentBottomSheetDialog.MediaState)
|
||||
|
||||
/**
|
||||
* load all media of a particular folder.
|
||||
*/
|
||||
void selectMediaFolder();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* 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.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import com.owncloud.android.databinding.FragmentGalleryBottomSheetBinding
|
||||
|
||||
class GalleryFragmentBottomSheetDialog(
|
||||
private val actions: GalleryFragmentBottomSheetActions
|
||||
) : BottomSheetDialogFragment() {
|
||||
private lateinit var binding: FragmentGalleryBottomSheetBinding
|
||||
private lateinit var mBottomBehavior: BottomSheetBehavior<*>
|
||||
private var currentMediaState : MediaState = MediaState.MEDIA_STATE_DEFAULT
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = FragmentGalleryBottomSheetBinding.inflate(layoutInflater,container, false)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupLayout()
|
||||
setupClickListener()
|
||||
mBottomBehavior = BottomSheetBehavior.from(binding.root.parent as View)
|
||||
}
|
||||
|
||||
public override fun onStart() {
|
||||
super.onStart()
|
||||
mBottomBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
|
||||
private fun setupLayout() {
|
||||
when (currentMediaState) {
|
||||
MediaState.MEDIA_STATE_PHOTOS_ONLY -> {
|
||||
binding.tickMarkShowImages.visibility = View.VISIBLE
|
||||
binding.tickMarkShowVideo.visibility = View.GONE
|
||||
}
|
||||
MediaState.MEDIA_STATE_VIDEOS_ONLY -> {
|
||||
binding.tickMarkShowImages.visibility = View.GONE
|
||||
binding.tickMarkShowVideo.visibility = View.VISIBLE
|
||||
}
|
||||
else -> {
|
||||
binding.tickMarkShowImages.visibility = View.VISIBLE
|
||||
binding.tickMarkShowVideo.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupClickListener() {
|
||||
binding.hideImages.setOnClickListener { v: View? ->
|
||||
currentMediaState = if (currentMediaState == MediaState.MEDIA_STATE_VIDEOS_ONLY) {
|
||||
MediaState.MEDIA_STATE_DEFAULT
|
||||
} else {
|
||||
MediaState.MEDIA_STATE_VIDEOS_ONLY
|
||||
}
|
||||
notifyStateChange()
|
||||
dismiss()
|
||||
}
|
||||
binding.hideVideo.setOnClickListener { v: View? ->
|
||||
currentMediaState = if (currentMediaState == MediaState.MEDIA_STATE_PHOTOS_ONLY) {
|
||||
MediaState.MEDIA_STATE_DEFAULT
|
||||
} else {
|
||||
MediaState.MEDIA_STATE_PHOTOS_ONLY
|
||||
}
|
||||
notifyStateChange()
|
||||
dismiss()
|
||||
}
|
||||
binding.selectMediaFolder.setOnClickListener { v: View? ->
|
||||
actions.selectMediaFolder()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyStateChange() {
|
||||
setupLayout()
|
||||
actions.updateMediaContent(currentMediaState)
|
||||
}
|
||||
|
||||
val currMediaState: MediaState
|
||||
get() = currentMediaState
|
||||
|
||||
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