Tweak progress bar

This commit is contained in:
Trevor Slocum 2019-06-07 04:41:59 -07:00
parent 7b2895191e
commit e2084d0694
10 changed files with 129 additions and 101 deletions

View File

@ -2,7 +2,6 @@ package space.rocketnine.gophast;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.support.v7.app.AlertDialog;
@ -34,12 +33,10 @@ public class DownloadAdapter extends RecyclerView.Adapter<DownloadAdapter.Downlo
public static class DeltaProgress {
long progress;
long size;
int progress;
public DeltaProgress(long p, long s) {
public DeltaProgress(int p) {
progress = p;
size = s;
}
}
@ -59,7 +56,7 @@ public class DownloadAdapter extends RecyclerView.Adapter<DownloadAdapter.Downlo
txtURL = v.findViewById(R.id.downloadURL);
progressBar = v.findViewById(R.id.downloadProgress);
progressBar.setMax(100000);
progressBar.setMax(10000);
}
}
@ -87,72 +84,66 @@ public class DownloadAdapter extends RecyclerView.Adapter<DownloadAdapter.Downlo
holder.txtName.setText(d.Name);
if (d.Size > 0) {
holder.txtSize.setText(Formatter.formatShortFileSize(context, d.Size));
holder.txtSize.setVisibility(View.VISIBLE);
} else {
holder.txtSize.setVisibility(View.INVISIBLE);
}
holder.txtURL.setText(d.URL);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
holder.progressBar.setProgress((int) (d.Downloaded * 100000.0 / d.Size), true);
holder.progressBar.setProgress((int) (d.Downloaded * 10000.0 / d.Size), true);
} else {
holder.progressBar.setProgress((int) (d.Downloaded * 100000.0 / d.Size));
holder.progressBar.setProgress((int) (d.Downloaded * 10000.0 / d.Size));
}
holder.v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Download d = downloads.get(holder.getAdapterPosition());
if (d == null) {
return;
}
holder.v.setOnClickListener(v -> {
Download d1 = downloads.get(holder.getAdapterPosition());
if (d1 == null) {
return;
}
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(d.Path, d.getMIME());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(d1.Path, d1.getMIME());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
getApp().longToast("No application able to open this file is installed");
}
try {
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
getApp().longToast("No application able to open this file is installed");
}
});
holder.v.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Download d = downloads.get(holder.getAdapterPosition());
if (d == null) {
return true;
}
AlertDialog downloadDialog = new AlertDialog.Builder(activity, R.style.AppTheme_Dialog)
.setTitle(d.Name)
.setItems(R.array.downloadOptions, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Download d = downloads.get(holder.getAdapterPosition());
if (d == null) {
return;
}
if (i == 0) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(d.Path, d.getMIME());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.openWith)));
} else if (i == 1) {
getApp().removeDownload(d);
}
}
})
.create();
downloadDialog.show();
holder.v.setOnLongClickListener(v -> {
Download d12 = downloads.get(holder.getAdapterPosition());
if (d12 == null) {
return true;
}
AlertDialog downloadDialog = new AlertDialog.Builder(activity, R.style.AppTheme_Dialog)
.setTitle(d12.Name)
.setItems(R.array.downloadOptions, (dialogInterface, i) -> {
Download d121 = downloads.get(holder.getAdapterPosition());
if (d121 == null) {
return;
}
if (i == 0) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(d121.Path, d121.getMIME());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.openWith)));
} else if (i == 1) {
getApp().removeDownload(d121);
}
})
.create();
downloadDialog.show();
return true;
});
}
@ -166,15 +157,18 @@ public class DownloadAdapter extends RecyclerView.Adapter<DownloadAdapter.Downlo
DeltaProgress d = (DeltaProgress) payload;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
holder.progressBar.setProgress((int) (d.progress * 100000.0 / d.size), true);
holder.progressBar.setProgress(d.progress, true);
} else {
holder.progressBar.setProgress((int) (d.progress * 100000.0 / d.size));
holder.progressBar.setProgress(d.progress);
}
} else if (payload instanceof DeltaSize) {
DeltaSize d = (DeltaSize) payload;
if (d.size > 0) {
holder.txtSize.setText(Formatter.formatShortFileSize(context, d.size));
gophast.animateView(context, holder.txtSize, R.anim.fade_in);
} else {
holder.txtSize.setVisibility(View.INVISIBLE);
}
}
}

View File

@ -23,7 +23,7 @@ class DownloadRunnable implements Runnable {
private Runnable notifyProgressRunnable = new Runnable() {
@Override
public void run() {
gophast.adapter.notifyItemChanged(d.Index, new DownloadAdapter.DeltaProgress(d.Downloaded, d.Size));
gophast.adapter.notifyItemChanged(d.Index, new DownloadAdapter.DeltaProgress((int) (d.Downloaded * 10000.0 / d.Size)));
}
};

View File

@ -3,6 +3,7 @@ package space.rocketnine.gophast;
import android.app.Activity;
import android.app.Application;
import android.app.DownloadManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@ -20,6 +21,8 @@ import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;
import java.io.File;
@ -257,6 +260,27 @@ public class GoPhast extends Application {
manager.Manager.setDownloadDir(downloadDir);
}
public void animateView(Context ctx, View v, int animation) {
Animation fadeInAnimation = AnimationUtils.loadAnimation(
ctx, animation);
v.startAnimation(fadeInAnimation);
fadeInAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
v.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
});
}
/**
* This method converts dp unit to equivalent pixels, depending on device density.
*

View File

@ -1,7 +1,6 @@
package space.rocketnine.gophast;
import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
@ -86,17 +85,12 @@ public class MainActivity extends AppCompatActivity {
final View view = getLayoutInflater().inflate(R.layout.dialog_add_download, null);
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this, R.style.AppTheme_Dialog);
alert.setTitle(R.string.addDownload);
alert.setView(view);
alert.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
EditText editurl = view.findViewById(R.id.addDownloadURL);
getApp().addDownload(editurl.getText().toString(), MainActivity.this);
}
alert.setPositiveButton(R.string.add, (dialog, whichButton) -> {
EditText editurl = view.findViewById(R.id.addDownloadURL);
getApp().addDownload(editurl.getText().toString(), MainActivity.this);
});
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
alert.setNegativeButton(android.R.string.cancel, (dialog, whichButton) -> {
});
alert.show();
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="@android:integer/config_shortAnimTime"
android:repeatCount="0" />
</set>

View File

@ -1,5 +1,5 @@
<vector android:height="28dp" android:tint="#FFFFFF"
<vector android:height="32dp" android:tint="#FFFFFF"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="28dp" xmlns:android="http://schemas.android.com/apk/res/android">
android:width="32dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
</vector>

View File

@ -10,14 +10,15 @@
android:id="@+id/btnNewDownload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginBottom="24dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:layout_marginBottom="32dp"
android:src="@drawable/ic_add_white"
android:onClick="newDownload"
app:fabSize="normal"
app:fabCustomSize="64dp"
android:scaleType="center"
app:maxImageSize="28dp"
app:maxImageSize="32dp"
app:elevation="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

View File

@ -14,6 +14,11 @@
android:hint="@string/url"
android:inputType="textUri|textMultiLine"
android:scrollHorizontally="false"
android:singleLine="false" />
android:singleLine="false"
android:minLines="2" />
<View
android:layout_width="match_parent"
android:layout_height="10dp" />
</LinearLayout>

View File

@ -19,10 +19,9 @@
<TextView
android:id="@+id/downloadName"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:gravity="center_vertical"
@ -32,20 +31,6 @@
android:textAppearance="@style/TextAppearance.AppCompat"
android:textSize="18sp" />
<TextView
android:id="@+id/downloadSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:clickable="false"
android:focusable="false"
android:gravity="center_vertical|end"
android:includeFontPadding="false"
android:singleLine="true"
android:ellipsize="none"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textSize="14sp" />
</LinearLayout>
<ProgressBar
@ -65,17 +50,16 @@
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingTop="7dp"
android:paddingRight="4dp"
android:paddingBottom="10dp">
android:orientation="horizontal"
android:padding="4dp"
android:layout_marginBottom="2dp">
<TextView
android:id="@+id/downloadURL"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:includeFontPadding="false"
@ -84,6 +68,22 @@
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textSize="12sp" />
<TextView
android:id="@+id/downloadSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="7dp"
android:clickable="false"
android:focusable="false"
android:visibility="invisible"
android:gravity="center_vertical|end"
android:includeFontPadding="false"
android:singleLine="true"
android:ellipsize="none"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>

View File

@ -20,4 +20,5 @@
<string name="storagePermissionDenied">GoPhast requires storage access to operate</string>
<string name="overwrite">Overwrite</string>
<string name="promptFileExists">File already exists. Overwrite?</string>
<string name="fetchingMetadata">Fetching metadata&#8230;</string>
</resources>