Skip to content

Commit

Permalink
Prevent frequent toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
thevindu-w committed Nov 10, 2023
1 parent 76355d0 commit 4481ca9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions app/src/main/java/com/tw/clipshare/platformUtils/FSUtils.java
Expand Up @@ -44,6 +44,7 @@ public class FSUtils extends AndroidUtils {
private String outFilePath;
private String baseDirName;
private final LinkedList<PendingFile> pendingFiles;
private static long lastToastTime = 0;

public FSUtils(Context context, Activity activity, LinkedList<PendingFile> pendingFiles) {
super(context, activity);
Expand Down Expand Up @@ -195,13 +196,17 @@ public OutputStream getImageOutStream() {
}

public void getFileDone(String type) {
this.activity.runOnUiThread(
() ->
Toast.makeText(
context,
"Saved " + type + " to " + outFilePath.substring(baseDirName.length() + 1),
Toast.LENGTH_SHORT)
.show());
long currTime = System.currentTimeMillis();
if (currTime - lastToastTime > 2000) {
lastToastTime = currTime;
this.activity.runOnUiThread(
() ->
Toast.makeText(
context,
"Saved " + type + " to " + outFilePath.substring(baseDirName.length() + 1),
Toast.LENGTH_SHORT)
.show());
}
int dotIndex = outFilePath.lastIndexOf('.');
if (dotIndex > 0) {
String extension = outFilePath.substring(dotIndex + 1);
Expand Down

0 comments on commit 4481ca9

Please sign in to comment.