- private static String getTimeLeft(DccReceiver dccReceiver) {
- if ((dccReceiver.size() == -1) || (dccReceiver.currentRate() == 0)) {
- return "unknown";
- }
- long secondsLeft = (dccReceiver.size() - dccReceiver.progress()) / dccReceiver.currentRate();
- if (secondsLeft > 3600) {
- return String.format("%02d:%02d:%02d", secondsLeft / 3600, (secondsLeft / 60) % 60, secondsLeft % 60);
+ private static String getProgressBar(DccReceiver dccReceiver, int progressBarWidth) {
+ FluentIterable<Character> partialProgressCharacters = from(asList(' ', '\u258f', '\u258e', '\u258d', '\u258c', '\u258b', '\u258a', '\u2589', '\u2588'));
+ double progress = dccReceiver.progress() * 100.0 / dccReceiver.size();
+ double singleBlockWidth = 100.0 / progressBarWidth;
+ int fullProgressBlocks = (int) (progress / singleBlockWidth);
+ double lastBlockProgress = (progress - fullProgressBlocks * singleBlockWidth) / singleBlockWidth;
+ StringBuilder progressBar = new StringBuilder(progressBarWidth);
+ for (int i = 0; i < progressBarWidth; ++i) {
+ if (i < fullProgressBlocks) {
+ progressBar.append(partialProgressCharacters.last().get());
+ } else if (i > fullProgressBlocks) {
+ progressBar.append(partialProgressCharacters.first().get());
+ } else {
+ progressBar.append(partialProgressCharacters.get((int) (lastBlockProgress * (partialProgressCharacters.size() - 1))));
+ }