Skip to content

Commit

Permalink
List divider added for tablet and landscape mode.
Browse files Browse the repository at this point in the history
NMC-2142: Upload file button text size configured.
  • Loading branch information
surinder-tsys committed Sep 4, 2024
1 parent 76a21c0 commit 95df4ce
Show file tree
Hide file tree
Showing 12 changed files with 453 additions and 3 deletions.
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 @@ -44,11 +45,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 @@ -99,6 +102,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 @@ -177,6 +182,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 @@ -186,6 +193,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 @@ -373,4 +397,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
Loading

0 comments on commit 95df4ce

Please sign in to comment.