mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2024-12-16 15:48:13 +08:00
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:
parent
ef9a0d57c2
commit
8df11645e8
@ -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"))
|
||||
@ -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("-");
|
||||
|
@ -43,10 +43,21 @@
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
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
|
||||
android:id="@+id/filesDropdownMenu"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight=".10"
|
||||
android:layout_weight=".0"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:scaleType="fitEnd"
|
||||
|
@ -556,6 +556,7 @@
|
||||
<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="sizeCopy">Size</string>
|
||||
<string name="shareIssue">Share Issue</string>
|
||||
<string name="shareRepository">Share Repository</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user