Add file size to Files (#292)

Merge branch 'master' into 290-file-size

# Conflicts:
#	app/src/main/res/values/strings.xml

Generic word for size text

Add file size to Files

Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/292
This commit is contained in:
M M Arif 2020-03-16 20:01:49 +00:00
parent ef9a0d57c2
commit 8df11645e8
4 changed files with 58 additions and 7 deletions

View File

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R; import org.mian.gitnex.R;
import org.mian.gitnex.helpers.Toasty; import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Files; import org.mian.gitnex.models.Files;
import org.mian.gitnex.util.AppUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -38,6 +39,7 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
private ImageView fileTypeImage; private ImageView fileTypeImage;
private TextView fileName; private TextView fileName;
private TextView fileType; private TextView fileType;
private TextView fileInfo;
private FilesViewHolder(View itemView) { private FilesViewHolder(View itemView) {
@ -45,6 +47,7 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
fileName = itemView.findViewById(R.id.fileName); fileName = itemView.findViewById(R.id.fileName);
fileTypeImage = itemView.findViewById(R.id.fileImage); fileTypeImage = itemView.findViewById(R.id.fileImage);
fileType = itemView.findViewById(R.id.fileType); fileType = itemView.findViewById(R.id.fileType);
fileInfo = itemView.findViewById(R.id.fileInfo);
//ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu); //ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu);
@ -158,6 +161,8 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
if(currentItem.getType().equals("file")) { if(currentItem.getType().equals("file")) {
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_file_new)); holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_file_new));
holder.fileInfo.setVisibility(View.VISIBLE);
holder.fileInfo.setText(AppUtil.formatFileSizeInDetail(currentItem.getSize()));
} }
else if(currentItem.getType().equals("dir")) { else if(currentItem.getType().equals("dir")) {
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_folder_24)); holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_folder_24));

View File

@ -32,6 +32,7 @@ public class AppUtil {
boolean haveConnectedMobile = false; boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
assert cm != null;
NetworkInfo[] netInfo = cm.getAllNetworkInfo(); NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) { for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI")) if (ni.getTypeName().equalsIgnoreCase("WIFI"))
@ -65,7 +66,7 @@ public class AppUtil {
} }
public int charactersLength(String str) { public int charactersLength(String str) {
return str.length(); return str.length();
} }
public Boolean checkStringsWithAlphaNumeric(String str) { // [a-zA-Z0-9] public Boolean checkStringsWithAlphaNumeric(String str) { // [a-zA-Z0-9]
@ -116,7 +117,6 @@ public class AppUtil {
String repoSize = null; String repoSize = null;
double k = size;
double m = size/1024.0; double m = size/1024.0;
double g = ((size/1024.0)/1024.0); double g = ((size/1024.0)/1024.0);
double t = (((size/1024.0)/1024.0)/1024.0); double t = (((size/1024.0)/1024.0)/1024.0);
@ -125,18 +125,52 @@ public class AppUtil {
if ( t > 1 ) { if ( t > 1 ) {
repoSize = dec.format(t).concat(" TB"); repoSize = dec.format(t).concat(" TB");
} else if ( g > 1 ) { }
else if ( g > 1 ) {
repoSize = dec.format(g).concat(" GB"); repoSize = dec.format(g).concat(" GB");
} else if ( m > 1 ) { }
else if ( m > 1 ) {
repoSize = dec.format(m).concat(" MB"); repoSize = dec.format(m).concat(" MB");
} else if ( k > 1 ) { }
repoSize = dec.format(k).concat(" KB"); else if ( (double) size > 1 ) {
repoSize = dec.format((double) size).concat(" KB");
} }
return repoSize; return repoSize;
} }
public static String formatFileSizeInDetail(long size) {
String fileSize = null;
double k = size/1024.0;
double m = ((size/1024.0)/1024.0);
double g = (((size/1024.0)/1024.0)/1024.0);
double t = ((((size/1024.0)/1024.0)/1024.0)/1024.0);
DecimalFormat dec = new DecimalFormat("0.00");
if ( t > 1 ) {
fileSize = dec.format(t).concat(" TB");
}
else if ( g > 1 ) {
fileSize = dec.format(g).concat(" GB");
}
else if ( m > 1 ) {
fileSize = dec.format(m).concat(" MB");
}
else if ( k > 1 ) {
fileSize = dec.format(k).concat(" KB");
}
else if ( (double) size > 1 ) {
fileSize = dec.format((double) size).concat(" B");
}
return fileSize;
}
public static String customDateFormat(String customDate) { public static String customDateFormat(String customDate) {
String[] parts = customDate.split("-"); String[] parts = customDate.split("-");

View File

@ -43,10 +43,21 @@
android:textColor="?attr/primaryTextColor" android:textColor="?attr/primaryTextColor"
android:textSize="16sp" /> android:textSize="16sp" />
<TextView
android:id="@+id/fileInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".20"
android:layout_marginBottom="0dp"
android:text="@string/sizeCopy"
android:visibility="gone"
android:textColor="?attr/primaryTextColor"
android:textSize="12sp" />
<ImageView <ImageView
android:id="@+id/filesDropdownMenu" android:id="@+id/filesDropdownMenu"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_weight=".10" android:layout_weight=".0"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:scaleType="fitEnd" android:scaleType="fitEnd"

View File

@ -556,6 +556,7 @@
<string name="downloadFileSaved">File is saved to Download directory</string> <string name="downloadFileSaved">File is saved to Download directory</string>
<string name="excludeFilesInFileviewer">This file type is not supported in file viewer. Download it instead from the three dotted menu?</string> <string name="excludeFilesInFileviewer">This file type is not supported in file viewer. Download it instead from the three dotted menu?</string>
<string name="sizeCopy">Size</string>
<string name="shareIssue">Share Issue</string> <string name="shareIssue">Share Issue</string>
<string name="shareRepository">Share Repository</string> <string name="shareRepository">Share Repository</string>
</resources> </resources>