Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List divider added for tab and land mode & Upload Files button text size configured #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/src/main/java/com/nmc/android/utils/DisplayUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nmc.android.utils

import android.content.res.Configuration
import com.owncloud.android.MainApp
import com.owncloud.android.R

object DisplayUtils {

@JvmStatic
fun isShowDividerForList(): Boolean = isTablet() || isLandscapeOrientation()

@JvmStatic
fun isTablet(): Boolean = MainApp.getAppContext().resources.getBoolean(R.bool.isTablet)

@JvmStatic
fun isLandscapeOrientation(): Boolean =
MainApp.getAppContext().resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -55,6 +56,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.inject.Inject;

Expand Down Expand Up @@ -194,6 +196,19 @@ public void onCreate(Bundle savedInstanceState) {
binding.uploadFilesBtnUpload.setOnClickListener(this);
binding.uploadFilesBtnUpload.setEnabled(mLocalFolderPickerMode);

//reduce the button text size so that the text doesn't go to next line
//this should only happen for GERMAN language
//and device should not be tablet and should be in portrait mode
if (!com.nmc.android.utils.DisplayUtils.isTablet() && !com.nmc.android.utils.DisplayUtils.isLandscapeOrientation()) {
if (Locale.getDefault().getLanguage().equals(Locale.GERMAN.getLanguage())
|| Locale.getDefault().getLanguage().equals(Locale.GERMANY.getLanguage())) {
binding.uploadFilesBtnUpload.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimensionPixelSize(R.dimen.txt_size_13sp));
binding.uploadFilesBtnCancel.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimensionPixelSize(R.dimen.txt_size_13sp));
}
}

int localBehaviour = preferences.getUploaderBehaviour();

// file upload spinner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
Expand Down Expand Up @@ -43,11 +44,13 @@
import com.owncloud.android.ui.adapter.UploadListAdapter;
import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.ui.decoration.SimpleListItemDividerDecoration;
import com.owncloud.android.utils.FilesSyncHelper;
import com.owncloud.android.utils.theme.ViewThemeUtils;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
Expand Down Expand Up @@ -98,6 +101,8 @@ public class UploadListActivity extends FileActivity {

private UploadListLayoutBinding binding;

private SimpleListItemDividerDecoration simpleListItemDividerDecoration;

public static Intent createIntent(OCFile file, User user, Integer flag, Context context) {
Intent intent = new Intent(context, UploadListActivity.class);
if (flag != null) {
Expand Down Expand Up @@ -176,6 +181,8 @@ private void setupContent() {
int spacing = getResources().getDimensionPixelSize(R.dimen.media_grid_spacing);
binding.list.addItemDecoration(new MediaGridItemDecoration(spacing));
binding.list.setLayoutManager(lm);
simpleListItemDividerDecoration = new SimpleListItemDividerDecoration(this, R.drawable.item_divider, true);
addListItemDecorator();
binding.list.setAdapter(uploadListAdapter);

viewThemeUtils.androidx.themeSwipeRefreshLayout(swipeListRefreshLayout);
Expand All @@ -185,6 +192,23 @@ private void setupContent() {
uploadListAdapter.loadUploadItemsFromDb();
}

private void addListItemDecorator() {
if (com.nmc.android.utils.DisplayUtils.isShowDividerForList()) {
//check and remove divider item decorator if exist then add item decorator
removeListDividerDecorator();
binding.list.addItemDecoration(simpleListItemDividerDecoration);
}
}

/**
* method to remove the divider item decorator
*/
private void removeListDividerDecorator() {
if (binding.list.getItemDecorationCount() > 0) {
binding.list.removeItemDecoration(simpleListItemDividerDecoration);
}
}

private void loadItems() {
uploadListAdapter.loadUploadItemsFromDb();

Expand Down Expand Up @@ -372,4 +396,20 @@ public void onReceive(Context context, Intent intent) {
});
}
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//this should only run when device is not tablet because we are adding dividers in tablet for both the
// orientations
if (!com.nmc.android.utils.DisplayUtils.isTablet()) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//add the divider item decorator when orientation is landscape
addListItemDecorator();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
//remove the divider item decorator when orientation is portrait
removeListDividerDecorator();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.util.DisplayMetrics;
import android.view.View;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;

Expand All @@ -25,7 +26,8 @@ public class SimpleListItemDividerDecoration extends DividerItemDecoration {

private final Rect bounds = new Rect();
private Drawable divider;
private int leftPadding;
private int leftPadding = 0;
private boolean hasFooter;

/**
* Default divider will be used
Expand All @@ -38,6 +40,17 @@ public SimpleListItemDividerDecoration(Context context) {
styledAttributes.recycle();
}

/**
* Custom divider will be used
*
* @param hasFooter if recyclerview has footer and no divider should be shown for footer then pass true else false
*/
public SimpleListItemDividerDecoration(Context context, int resId, boolean hasFooter) {
super(context, DividerItemDecoration.VERTICAL);
this.hasFooter = hasFooter;
divider = ContextCompat.getDrawable(context, resId);
}

@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
canvas.save();
Expand All @@ -51,7 +64,12 @@ public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state)
right = parent.getWidth();
}

final int childCount = parent.getChildCount();
int childCount = parent.getChildCount();

if (hasFooter) {
childCount = childCount - 1;
}

for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
parent.getDecoratedBoundsWithMargins(child, bounds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -32,6 +33,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AbsListView;
import android.widget.Toast;

Expand All @@ -52,6 +54,7 @@
import com.nextcloud.client.jobs.BackgroundJobManager;
import com.nextcloud.client.network.ClientFactory;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.nextcloud.client.utils.Throttler;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.ui.fileactions.FileActionsBottomSheet;
Expand Down Expand Up @@ -87,6 +90,8 @@
import com.owncloud.android.ui.activity.UploadFilesActivity;
import com.owncloud.android.ui.adapter.CommonOCFileListAdapterInterface;
import com.owncloud.android.ui.adapter.OCFileListAdapter;
import com.owncloud.android.ui.decoration.MediaGridItemDecoration;
import com.owncloud.android.ui.decoration.SimpleListItemDividerDecoration;
import com.owncloud.android.ui.dialog.ChooseRichDocumentsTemplateDialogFragment;
import com.owncloud.android.ui.dialog.ChooseTemplateDialogFragment;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
Expand Down Expand Up @@ -232,6 +237,9 @@ public class OCFileListFragment extends ExtendedListFragment implements
protected String mLimitToMimeType;
private FloatingActionButton mFabMain;

private SimpleListItemDividerDecoration simpleListItemDividerDecoration;
private MediaGridItemDecoration mediaGridItemDecoration;

@Inject DeviceInfo deviceInfo;

protected enum MenuItemAddRemove {
Expand All @@ -245,6 +253,13 @@ protected enum MenuItemAddRemove {

private List<MenuItem> mOriginalMenuItems = new ArrayList<>();

private int maxColumnSizeLandscape = 5;

//this variable will help us to provide number of span count for grid view
//the width for single item is approx to 360
private static final int GRID_ITEM_DEFAULT_WIDTH = 360;
private static final int DEFAULT_FALLBACK_SPAN_COUNT = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -443,6 +458,10 @@ protected void setAdapter(Bundle args) {
viewThemeUtils
);

simpleListItemDividerDecoration = new SimpleListItemDividerDecoration(getContext(), R.drawable.item_divider, true);
int spacing = getResources().getDimensionPixelSize(R.dimen.media_grid_spacing);
mediaGridItemDecoration = new MediaGridItemDecoration(spacing);

setRecyclerViewAdapter(mAdapter);

fastScrollUtils.applyFastScroll(getRecyclerView());
Expand Down Expand Up @@ -1520,6 +1539,7 @@ public void switchToListView() {
if (isGridEnabled()) {
switchLayoutManager(false);
}
addRemoveRecyclerViewItemDecorator();
}

public void setGridAsPreferred() {
Expand All @@ -1531,6 +1551,33 @@ public void switchToGridView() {
if (!isGridEnabled()) {
switchLayoutManager(true);
}
addRemoveRecyclerViewItemDecorator();
}

private void addRemoveRecyclerViewItemDecorator() {
if (getRecyclerView().getLayoutManager() instanceof GridLayoutManager) {
removeItemDecorator();
if (getRecyclerView().getItemDecorationCount() == 0) {
getRecyclerView().addItemDecoration(mediaGridItemDecoration);
int padding = getResources().getDimensionPixelSize(R.dimen.grid_recyclerview_padding);
getRecyclerView().setPadding(padding, padding, padding, padding);
}
} else {
removeItemDecorator();
if (getRecyclerView().getItemDecorationCount() == 0 && com.nmc.android.utils.DisplayUtils.isShowDividerForList()) {
getRecyclerView().addItemDecoration(simpleListItemDividerDecoration);
getRecyclerView().setPadding(0, 0, 0, 0);
}
}
}

/**
* method to remove the item decorator
*/
private void removeItemDecorator() {
while (getRecyclerView().getItemDecorationCount() > 0) {
getRecyclerView().removeItemDecorationAt(0);
}
}

public void switchLayoutManager(boolean grid) {
Expand Down Expand Up @@ -1561,12 +1608,40 @@ public int getSpanSize(int position) {
}

getRecyclerView().setLayoutManager(layoutManager);
updateSpanCount(getResources().getConfiguration());
getRecyclerView().scrollToPosition(position);
getAdapter().setGridView(grid);
getRecyclerView().setAdapter(getAdapter());
getAdapter().notifyDataSetChanged();
}

/**
* method will calculate the number of spans required for grid item and will update the span accordingly
*
* @param isGrid
*/
private void calculateAndUpdateSpanCount(boolean isGrid) {
getRecyclerView().getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
getRecyclerView().getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (isGrid) {
int viewWidth = getRecyclerView().getMeasuredWidth();
int newSpanCount = viewWidth / GRID_ITEM_DEFAULT_WIDTH;
RecyclerView.LayoutManager layoutManager = getRecyclerView().getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if (newSpanCount < 1) {
newSpanCount = DEFAULT_FALLBACK_SPAN_COUNT;
}
((GridLayoutManager) layoutManager).setSpanCount(newSpanCount);
layoutManager.requestLayout();
}
}
}
});
}

public CommonOCFileListAdapterInterface getCommonAdapter() {
return mAdapter;
}
Expand Down Expand Up @@ -2139,4 +2214,52 @@ private boolean isAPKorAAB(Set<OCFile> files) {
}
return false;
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (getAdapter() != null) {
getAdapter().notifyDataSetChanged();
}
updateSpanCount(newConfig);
}

/**
* method will update the span count on basis of device orientation for the file listing
*
* @param newConfig current configuration
*/
private void updateSpanCount(Configuration newConfig) {
//this should only run when current view is not media gallery
if (getAdapter() != null) {
int maxColumnSize = (int) AppPreferencesImpl.DEFAULT_GRID_COLUMN;
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//add the divider item decorator when orientation is landscape and device is not tablet
//because we don't have to add divider again as it is already added
if (!com.nmc.android.utils.DisplayUtils.isTablet()) {
addRemoveRecyclerViewItemDecorator();
}
maxColumnSize = maxColumnSizeLandscape;
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
//remove the divider item decorator when orientation is portrait and when device is not tablet
//because we have to show divider in both landscape and portrait mode
if (!com.nmc.android.utils.DisplayUtils.isTablet()) {
removeItemDecorator();
}
maxColumnSize = (int) AppPreferencesImpl.DEFAULT_GRID_COLUMN;
}

if (isGridEnabled()) {
//for tablet calculate size on the basis of screen width
if (com.nmc.android.utils.DisplayUtils.isTablet()) {
calculateAndUpdateSpanCount(true);
} else {
//and for phones directly show the hardcoded column size
if (getRecyclerView().getLayoutManager() instanceof GridLayoutManager) {
((GridLayoutManager) getRecyclerView().getLayoutManager()).setSpanCount(maxColumnSize);
}
}
}
}
}
}
Loading