mirror of
https://github.com/nextcloud/android.git
synced 2024-11-30 17:11:58 +03:00
move stuff to helper class
This commit is contained in:
parent
8397a48dde
commit
7800d33ff5
2 changed files with 179 additions and 121 deletions
|
@ -57,6 +57,7 @@ import com.owncloud.android.ui.activity.FileActivity;
|
|||
import com.owncloud.android.ui.adapter.UserListAdapter;
|
||||
import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.SharePasswordDialogFragment;
|
||||
import com.owncloud.android.ui.fragment.util.FileDetailSharingFragmentHelper;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -157,34 +158,11 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
private void setupView() {
|
||||
setShareByLinkInfo(file.isSharedViaLink());
|
||||
setShareWithUserInfo();
|
||||
setupSearchView();
|
||||
}
|
||||
|
||||
private void setupSearchView() {
|
||||
SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
|
||||
// assumes parent activity is the searchable activity
|
||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
|
||||
|
||||
// do not iconify the widget; expand it by default
|
||||
searchView.setIconifiedByDefault(false);
|
||||
|
||||
// avoid fullscreen with softkeyboard
|
||||
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
Log_OC.v(TAG, "onQueryTextSubmit intercepted, query: " + query);
|
||||
// return true to prevent the query is processed to be queried;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
// leave it for the parent listener in the hierarchy / default behaviour
|
||||
return false;
|
||||
}
|
||||
});
|
||||
FileDetailSharingFragmentHelper.setupSearchView(
|
||||
(SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE),
|
||||
searchView,
|
||||
getActivity().getComponentName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,38 +209,13 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
usersList.setVisibility(View.VISIBLE);
|
||||
usersList.setAdapter(mUserGroupsAdapter);
|
||||
noList.setVisibility(View.GONE);
|
||||
setListViewHeightBasedOnChildren(usersList);
|
||||
FileDetailSharingFragmentHelper.setListViewHeightBasedOnChildren(usersList);
|
||||
} else {
|
||||
usersList.setVisibility(View.GONE);
|
||||
noList.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix scroll in ListView when the parent is a ScrollView
|
||||
*/
|
||||
private static void setListViewHeightBasedOnChildren(ListView listView) {
|
||||
ListAdapter listAdapter = listView.getAdapter();
|
||||
if (listAdapter == null) {
|
||||
return;
|
||||
}
|
||||
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
|
||||
int totalHeight = 0;
|
||||
View view = null;
|
||||
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||
view = listAdapter.getView(i, view, listView);
|
||||
if (i == 0) {
|
||||
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
|
||||
totalHeight += view.getMeasuredHeight();
|
||||
}
|
||||
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
||||
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
||||
listView.setLayoutParams(params);
|
||||
listView.requestLayout();
|
||||
}
|
||||
|
||||
@OnClick(R.id.share_by_link)
|
||||
public void toggleShareByLink() {
|
||||
if (shareByLink.isChecked()) {
|
||||
|
@ -306,55 +259,22 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
|
||||
private void prepareOptionsMenu(Menu menu) {
|
||||
Resources res = getResources();
|
||||
setupHideFileListingMenuItem(menu.findItem(R.id.action_share_link_hide_file_listing));
|
||||
setupPasswordMenuItem(menu.findItem(R.id.action_share_link_password), res);
|
||||
setupExpirationDateMenuItem(menu.findItem(R.id.action_share_link_expiration_date), res);
|
||||
}
|
||||
|
||||
private void setupPasswordMenuItem(MenuItem password, Resources res) {
|
||||
if (publicShare.isPasswordProtected()) {
|
||||
password.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_password_label,
|
||||
res.getString(R.string.share_via_link_password_title)
|
||||
));
|
||||
} else {
|
||||
password.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_password_label,
|
||||
res.getString(R.string.share_via_link_no_password_title)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private void setupHideFileListingMenuItem(MenuItem fileListing) {
|
||||
if (!file.isFolder()) {
|
||||
fileListing.setVisible(false);
|
||||
} else {
|
||||
if(shareByLinkAllowEditing.isChecked()) {
|
||||
boolean readOnly = (publicShare.getPermissions() & OCShare.READ_PERMISSION_FLAG) != 0;
|
||||
fileListing.setChecked(!readOnly);
|
||||
} else {
|
||||
fileListing.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupExpirationDateMenuItem(MenuItem expirationDate, Resources res) {
|
||||
long expirationDateValue = publicShare.getExpirationDate();
|
||||
if (expirationDateValue > 0) {
|
||||
String formattedDate =
|
||||
SimpleDateFormat.getDateInstance().format(
|
||||
new Date(expirationDateValue)
|
||||
);
|
||||
expirationDate.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_expiration_date_label,
|
||||
formattedDate
|
||||
));
|
||||
} else {
|
||||
expirationDate.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_expiration_date_label,
|
||||
res.getString(R.string.share_via_link_menu_expiration_date_never)
|
||||
));
|
||||
}
|
||||
FileDetailSharingFragmentHelper.setupHideFileListingMenuItem(
|
||||
menu.findItem(R.id.action_share_link_hide_file_listing),
|
||||
file.isFolder(),
|
||||
shareByLinkAllowEditing.isChecked(),
|
||||
publicShare.getPermissions()
|
||||
);
|
||||
FileDetailSharingFragmentHelper.setupPasswordMenuItem(
|
||||
menu.findItem(R.id.action_share_link_password),
|
||||
publicShare.isPasswordProtected(),
|
||||
res
|
||||
);
|
||||
FileDetailSharingFragmentHelper.setupExpirationDateMenuItem(
|
||||
menu.findItem(R.id.action_share_link_expiration_date),
|
||||
publicShare.getExpirationDate(),
|
||||
res
|
||||
);
|
||||
}
|
||||
|
||||
private boolean optionsItemSelected(MenuItem item) {
|
||||
|
@ -459,8 +379,8 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
* instance ready to use. If not ready, does nothing.
|
||||
*/
|
||||
public void refreshPublicShareFromDB() {
|
||||
if (isPublicShareDisabled()) {
|
||||
hidePublicShare();
|
||||
if (FileDetailSharingFragmentHelper.isPublicShareDisabled(capabilities)) {
|
||||
shareByLinkContainer.setVisibility(View.GONE);
|
||||
} else if (((FileActivity) getActivity()).getStorageManager() != null) {
|
||||
// Get public share
|
||||
publicShare = ((FileActivity) getActivity()).getStorageManager().getFirstShareByPathAndType(
|
||||
|
@ -475,8 +395,8 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
}
|
||||
|
||||
/**
|
||||
* Updates in the UI the section about public share with the information in the current public share bound to
|
||||
* mFile, if any.
|
||||
* Updates in the UI the section about public share with the information
|
||||
* in the current public share bound to, if any.
|
||||
*/
|
||||
private void updatePublicShareSection() {
|
||||
if (publicShare != null && ShareType.PUBLIC_LINK.equals(publicShare.getShareType())) {
|
||||
|
@ -489,18 +409,4 @@ public class FileDetailSharingFragment extends Fragment implements UserListAdapt
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' when public share is disabled in the server.
|
||||
*/
|
||||
private boolean isPublicShareDisabled() {
|
||||
return (capabilities != null && capabilities.getFilesSharingPublicEnabled().isFalse());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides all the UI elements related to public share.
|
||||
*/
|
||||
private void hidePublicShare() {
|
||||
shareByLinkContainer.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Andy Scherzinger
|
||||
* Copyright (C) 2018 Andy Scherzinger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.fragment.util;
|
||||
|
||||
import android.app.SearchManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.shares.OCShare;
|
||||
import com.owncloud.android.lib.resources.status.OCCapability;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Helper calls for visibility logic of the sharing fragment.
|
||||
*/
|
||||
public class FileDetailSharingFragmentHelper {
|
||||
|
||||
public static void setupHideFileListingMenuItem(MenuItem fileListing,
|
||||
boolean isFolder,
|
||||
boolean isEditingAllowed,
|
||||
int publicSharePermissions) {
|
||||
if (!isFolder) {
|
||||
fileListing.setVisible(false);
|
||||
} else {
|
||||
if (isEditingAllowed) {
|
||||
boolean readOnly = (publicSharePermissions & OCShare.READ_PERMISSION_FLAG) != 0;
|
||||
fileListing.setChecked(!readOnly);
|
||||
} else {
|
||||
fileListing.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupPasswordMenuItem(MenuItem password, boolean isPasswordProtected, Resources res) {
|
||||
if (isPasswordProtected) {
|
||||
password.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_password_label,
|
||||
res.getString(R.string.share_via_link_password_title)
|
||||
));
|
||||
} else {
|
||||
password.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_password_label,
|
||||
res.getString(R.string.share_via_link_no_password_title)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupExpirationDateMenuItem(MenuItem expirationDate, long expirationDateValue, Resources res) {
|
||||
if (expirationDateValue > 0) {
|
||||
String formattedDate =
|
||||
SimpleDateFormat.getDateInstance().format(
|
||||
new Date(expirationDateValue)
|
||||
);
|
||||
expirationDate.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_expiration_date_label,
|
||||
formattedDate
|
||||
));
|
||||
} else {
|
||||
expirationDate.setTitle(res.getString(
|
||||
R.string.share_via_link_menu_expiration_date_label,
|
||||
res.getString(R.string.share_via_link_menu_expiration_date_never)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupSearchView(SearchManager searchManager, SearchView searchView, ComponentName componentName) {
|
||||
// assumes parent activity is the searchable activity
|
||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(componentName));
|
||||
|
||||
// do not iconify the widget; expand it by default
|
||||
searchView.setIconifiedByDefault(false);
|
||||
|
||||
// avoid fullscreen with softkeyboard
|
||||
searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
// return true to prevent the query is processed to be queried;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
// leave it for the parent listener in the hierarchy / default behaviour
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 'True' when public share is disabled in the server.
|
||||
*/
|
||||
public static boolean isPublicShareDisabled(OCCapability capabilities) {
|
||||
return (capabilities != null && capabilities.getFilesSharingPublicEnabled().isFalse());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix scroll in ListView when the parent is a ScrollView
|
||||
*/
|
||||
public static void setListViewHeightBasedOnChildren(ListView listView) {
|
||||
ListAdapter listAdapter = listView.getAdapter();
|
||||
if (listAdapter == null) {
|
||||
return;
|
||||
}
|
||||
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
|
||||
int totalHeight = 0;
|
||||
View view = null;
|
||||
for (int i = 0; i < listAdapter.getCount(); i++) {
|
||||
view = listAdapter.getView(i, view, listView);
|
||||
if (i == 0) {
|
||||
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
}
|
||||
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
|
||||
totalHeight += view.getMeasuredHeight();
|
||||
}
|
||||
ViewGroup.LayoutParams params = listView.getLayoutParams();
|
||||
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
|
||||
listView.setLayoutParams(params);
|
||||
listView.requestLayout();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue