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:
@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.models.Files;
|
||||
import org.mian.gitnex.util.AppUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,6 +39,7 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
||||
private ImageView fileTypeImage;
|
||||
private TextView fileName;
|
||||
private TextView fileType;
|
||||
private TextView fileInfo;
|
||||
|
||||
private FilesViewHolder(View itemView) {
|
||||
|
||||
@@ -45,6 +47,7 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
||||
fileName = itemView.findViewById(R.id.fileName);
|
||||
fileTypeImage = itemView.findViewById(R.id.fileImage);
|
||||
fileType = itemView.findViewById(R.id.fileType);
|
||||
fileInfo = itemView.findViewById(R.id.fileInfo);
|
||||
|
||||
//ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu);
|
||||
|
||||
@@ -158,6 +161,8 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
||||
|
||||
if(currentItem.getType().equals("file")) {
|
||||
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")) {
|
||||
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_folder_24));
|
||||
|
||||
@@ -32,6 +32,7 @@ public class AppUtil {
|
||||
boolean haveConnectedMobile = false;
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
assert cm != null;
|
||||
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
|
||||
for (NetworkInfo ni : netInfo) {
|
||||
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
|
||||
@@ -65,7 +66,7 @@ public class AppUtil {
|
||||
}
|
||||
|
||||
public int charactersLength(String str) {
|
||||
return str.length();
|
||||
return str.length();
|
||||
}
|
||||
|
||||
public Boolean checkStringsWithAlphaNumeric(String str) { // [a-zA-Z0-9]
|
||||
@@ -116,7 +117,6 @@ public class AppUtil {
|
||||
|
||||
String repoSize = null;
|
||||
|
||||
double k = size;
|
||||
double m = size/1024.0;
|
||||
double g = ((size/1024.0)/1024.0);
|
||||
double t = (((size/1024.0)/1024.0)/1024.0);
|
||||
@@ -125,18 +125,52 @@ public class AppUtil {
|
||||
|
||||
if ( t > 1 ) {
|
||||
repoSize = dec.format(t).concat(" TB");
|
||||
} else if ( g > 1 ) {
|
||||
}
|
||||
else if ( g > 1 ) {
|
||||
repoSize = dec.format(g).concat(" GB");
|
||||
} else if ( m > 1 ) {
|
||||
}
|
||||
else if ( m > 1 ) {
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
String[] parts = customDate.split("-");
|
||||
|
||||
Reference in New Issue
Block a user