Skip to content

Commit

Permalink
WiP for #2485
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyScherzinger committed May 9, 2018
1 parent 14a127e commit 254ac96
Show file tree
Hide file tree
Showing 14 changed files with 651 additions and 117 deletions.
1 change: 1 addition & 0 deletions drawable_resources/ic_star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions drawable_resources/ic_star_outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions drawable_resources/ic_tag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.adapter;

import android.accounts.Account;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.fragment.FileDetailActivitiesFragment;
import com.owncloud.android.ui.fragment.FileDetailSharingFragment;

/**
* File details pager adapter.
*/
public class FileDetailTabAdapter extends FragmentStatePagerAdapter {
private OCFile file;
private Account account;

public FileDetailTabAdapter(FragmentManager fm, OCFile file, Account account) {
super(fm);

this.file = file;
this.account = account;
}

@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return FileDetailActivitiesFragment.newInstance(file, account);
case 1:
return FileDetailSharingFragment.newInstance(file, account);
default:
return null;
}
}

@Override
public int getCount() {
return 2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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;

import android.accounts.Account;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.owncloud.android.R;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.FileActivity;

public class FileDetailActivitiesFragment extends Fragment {

private static final String ARG_FILE = "FILE";
private static final String ARG_ACCOUNT = "ACCOUNT";

private OCFile file;
private Account account;

public static FileDetailActivitiesFragment newInstance(OCFile file, Account account) {
FileDetailActivitiesFragment fragment = new FileDetailActivitiesFragment();
Bundle args = new Bundle();
args.putParcelable(ARG_FILE, file);
args.putParcelable(ARG_ACCOUNT, account);
fragment.setArguments(args);
return fragment;
}

@Override
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {

file = getArguments().getParcelable(ARG_FILE);
account = getArguments().getParcelable(ARG_ACCOUNT);

if (savedInstanceState != null) {
file = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
}

View view = inflater.inflate(R.layout.file_details_activities_fragment, container, false);

setupView(view);

return view;
}

private void setupView(View view) {
// TODO populate activities list
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -53,6 +55,7 @@
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.adapter.FileDetailTabAdapter;
import com.owncloud.android.ui.adapter.UserListAdapter;
import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
Expand All @@ -68,8 +71,7 @@
/**
* This Fragment is used to display the details about a file.
*/
public class FileDetailFragment extends FileFragment implements OnClickListener,
CompoundButton.OnCheckedChangeListener {
public class FileDetailFragment extends FileFragment implements OnClickListener {

private int mLayout;
private View mView;
Expand Down Expand Up @@ -154,13 +156,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

if (mLayout == R.layout.file_details_fragment) {
int accentColor = ThemeUtils.primaryAccentColor(getContext());
SwitchCompat favoriteToggle = mView.findViewById(R.id.fdFavorite);
favoriteToggle.setOnCheckedChangeListener(this);
ThemeUtils.tintSwitch(favoriteToggle, accentColor, false);
ProgressBar progressBar = mView.findViewById(R.id.fdProgressBar);
ThemeUtils.colorHorizontalProgressBar(progressBar, ThemeUtils.primaryAccentColor(getContext()));
mProgressListener = new ProgressListener(progressBar);
mView.findViewById(R.id.fdCancelBtn).setOnClickListener(this);
mView.findViewById(R.id.fdFavorite).setOnClickListener(this);
((TextView)mView.findViewById(R.id.fdShareTitle)).setTextColor(accentColor);
((TextView)mView.findViewById(R.id.fdShareWithUsersTitle)).setTextColor(accentColor);
}
Expand All @@ -169,6 +169,38 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
return mView;
}

private void setupViewPager(View view) {
TabLayout tabLayout = view.findViewById(R.id.tab_layout);
tabLayout.removeAllTabs();

tabLayout.addTab(tabLayout.newTab().setText(R.string.drawer_item_activities));
tabLayout.addTab(tabLayout.newTab().setText(R.string.share_dialog_title));

tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

final ViewPager viewPager = view.findViewById(R.id.pager);
final FileDetailTabAdapter adapter = new FileDetailTabAdapter
(getFragmentManager(), getFile(),mAccount);
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(TabLayout.Tab tab) {

}

@Override
public void onTabReselected(TabLayout.Tab tab) {

}
});
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down Expand Up @@ -359,18 +391,26 @@ public void onClick(View v) {
((FileDisplayActivity) mContainerActivity).cancelTransference(getFile());
break;
}
case R.id.fdFavorite: {
if (getFile().isAvailableOffline()) {
((ImageView)getView().findViewById(R.id.fdFavorite)).
setImageDrawable(getResources()
.getDrawable(R.drawable.ic_star_outline));
} else {
((ImageView)getView().findViewById(R.id.fdFavorite))
.setImageDrawable(getResources()
.getDrawable(R.drawable.ic_star));
}
mContainerActivity.getFileOperationsHelper()
.toggleOfflineFile(getFile(), !getFile().isAvailableOffline());
break;
}
default:
Log_OC.e(TAG, "Incorrect view clicked!");
break;
}
}

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SwitchCompat favSwitch = getView().findViewById(R.id.fdFavorite);
mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), favSwitch.isChecked());
}

/**
* Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.
*
Expand Down Expand Up @@ -419,15 +459,13 @@ public void updateFileDetails(boolean transferring, boolean refresh) {
setFilename(file.getFileName());
setFiletype(file);
setFilesize(file.getFileLength());

setTimeModified(file.getModificationTimestamp());

SwitchCompat favSwitch = getView().findViewById(R.id.fdFavorite);
favSwitch.setChecked(file.isAvailableOffline());

setShareByLinkInfo(file.isSharedViaLink());

setShareWithUserInfo();
if (file.isAvailableOffline()) {
((ImageView)getView().findViewById(R.id.fdFavorite)).setImageDrawable(getResources().getDrawable(R.drawable.ic_star));
} else {
((ImageView)getView().findViewById(R.id.fdFavorite)).setImageDrawable(getResources().getDrawable(R.drawable.ic_star_outline));
}

// configure UI for depending upon local state of the file
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
Expand All @@ -448,6 +486,9 @@ public void updateFileDetails(boolean transferring, boolean refresh) {
setButtonsForRemote();
}
}

setupViewPager(getView());

getView().invalidate();
}

Expand Down Expand Up @@ -634,9 +675,6 @@ private static void setListViewHeightBasedOnChildren(ListView listView) {
*/
private void setButtonsForTransferring() {
if (!isEmpty()) {
// let's protect the user from himself ;)
getView().findViewById(R.id.fdFavorite).setEnabled(false);

// show the progress bar for the transfer
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE);
TextView progressText = getView().findViewById(R.id.fdProgressText);
Expand All @@ -660,8 +698,6 @@ private void setButtonsForTransferring() {
*/
private void setButtonsForDown() {
if (!isEmpty()) {
getView().findViewById(R.id.fdFavorite).setEnabled(true);

// hides the progress bar
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
TextView progressText = getView().findViewById(R.id.fdProgressText);
Expand All @@ -674,8 +710,6 @@ private void setButtonsForDown() {
*/
private void setButtonsForRemote() {
if (!isEmpty()) {
getView().findViewById(R.id.fdFavorite).setEnabled(true);

// hides the progress bar
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
TextView progressText = getView().findViewById(R.id.fdProgressText);
Expand Down
Loading

0 comments on commit 254ac96

Please sign in to comment.