use of com.frostwire.android.gui.transfers.TransferManager in project frostwire by frostwire.
the class NotificationUpdateDemon method updatePermanentStatusNotification.
private void updatePermanentStatusNotification() {
if (!ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_GUI_ENABLE_PERMANENT_STATUS_NOTIFICATION)) {
return;
}
if (notificationViews == null || notificationObject == null) {
LOG.warn("Notification views or object are null, review your logic");
return;
}
// number of uploads (seeding) and downloads
TransferManager transferManager;
try {
transferManager = TransferManager.instance();
} catch (IllegalStateException btEngineNotReadyException) {
return;
}
if (transferManager != null) {
int downloads = transferManager.getActiveDownloads();
int uploads = transferManager.getActiveUploads();
if (downloads == 0 && uploads == 0) {
NotificationManager manager = (NotificationManager) mParentContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (manager != null) {
try {
manager.cancel(FROSTWIRE_STATUS_NOTIFICATION);
} catch (SecurityException ignored) {
// possible java.lang.SecurityException
}
}
// quick return
return;
}
// format strings
String sDown = UIUtils.rate2speed(transferManager.getDownloadsBandwidth() / 1024);
String sUp = UIUtils.rate2speed(transferManager.getUploadsBandwidth() / 1024);
// Transfers status.
notificationViews.setTextViewText(R.id.view_permanent_status_text_downloads, downloads + " @ " + sDown);
notificationViews.setTextViewText(R.id.view_permanent_status_text_uploads, uploads + " @ " + sUp);
final NotificationManager notificationManager = (NotificationManager) mParentContext.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
try {
notificationManager.notify(FROSTWIRE_STATUS_NOTIFICATION, notificationObject);
} catch (SecurityException ignored) {
// possible java.lang.SecurityException
} catch (Throwable ignored2) {
// possible android.os.TransactionTooLargeException
ignored2.printStackTrace();
}
}
}
}
use of com.frostwire.android.gui.transfers.TransferManager in project frostwire by frostwire.
the class TransfersFragment method updateMenuItemVisibility.
private void updateMenuItemVisibility(Menu menu) {
TransferManager tm = TransferManager.instance();
boolean bittorrentDisconnected = tm.isBittorrentDisconnected();
final List<Transfer> transfers = tm.getTransfers();
if (transfers != null && transfers.size() > 0) {
if (someTransfersComplete(transfers)) {
menu.findItem(R.id.fragment_transfers_menu_clear_all).setVisible(true);
}
if (!bittorrentDisconnected) {
if (someTransfersActive(transfers)) {
menu.findItem(R.id.fragment_transfers_menu_pause_stop_all).setVisible(true);
}
}
// Preferences > Connectivity is disconnected.
if (someTransfersInactive(transfers)) {
menu.findItem(R.id.fragment_transfers_menu_resume_all).setVisible(true);
}
if (!someTransfersSeeding(transfers) && someTransfersComplete(transfers)) {
menu.findItem(R.id.fragment_transfers_menu_seed_all).setVisible(true);
}
if (someTransfersSeeding(transfers) && someTransfersComplete(transfers)) {
menu.findItem(R.id.fragment_transfers_menu_seed_all).setVisible(true);
menu.findItem(R.id.fragment_transfers_menu_stop_seeding_all).setVisible(true);
}
if (someTransfersSeeding(transfers)) {
menu.findItem(R.id.fragment_transfers_menu_stop_seeding_all).setVisible(true);
}
}
}
use of com.frostwire.android.gui.transfers.TransferManager in project frostwire by frostwire.
the class Offers method showInterstitialOfferIfNecessary.
public static void showInterstitialOfferIfNecessary(Activity ctx, String placement, final boolean shutdownAfterwards, final boolean dismissAfterwards, final boolean ignoreStartedTransfers) {
TransferManager TM = TransferManager.instance();
int startedTransfers = TM.incrementStartedTransfers();
ConfigurationManager CM = ConfigurationManager.instance();
final int INTERSTITIAL_OFFERS_TRANSFER_STARTS = DEBUG_MODE ? 1 : CM.getInt(Constants.PREF_KEY_GUI_INTERSTITIAL_OFFERS_TRANSFER_STARTS);
final int INTERSTITIAL_TRANSFER_OFFERS_TIMEOUT_IN_MINUTES = CM.getInt(Constants.PREF_KEY_GUI_INTERSTITIAL_TRANSFER_OFFERS_TIMEOUT_IN_MINUTES);
final long INTERSTITIAL_TRANSFER_OFFERS_TIMEOUT_IN_MS = DEBUG_MODE ? 10000 : TimeUnit.MINUTES.toMillis(INTERSTITIAL_TRANSFER_OFFERS_TIMEOUT_IN_MINUTES);
long lastInterstitialShownTimestamp = CM.getLong(Constants.PREF_KEY_GUI_INTERSTITIAL_LAST_DISPLAY);
long timeSinceLastOffer = System.currentTimeMillis() - lastInterstitialShownTimestamp;
boolean itsBeenLongEnough = timeSinceLastOffer >= INTERSTITIAL_TRANSFER_OFFERS_TIMEOUT_IN_MS;
boolean startedEnoughTransfers = startedTransfers >= INTERSTITIAL_OFFERS_TRANSFER_STARTS;
if (ignoreStartedTransfers) {
startedEnoughTransfers = true;
}
boolean shouldDisplayFirstOne = (lastInterstitialShownTimestamp == -1 && startedEnoughTransfers);
if (shouldDisplayFirstOne || (itsBeenLongEnough && startedEnoughTransfers)) {
Offers.showInterstitial(ctx, placement, shutdownAfterwards, dismissAfterwards);
TM.resetStartedTransfers();
}
}
use of com.frostwire.android.gui.transfers.TransferManager in project frostwire by frostwire.
the class StartDownloadTask method onPostExecute.
@Override
protected void onPostExecute(Context ctx, Transfer transfer) {
if (transfer != null) {
if (ctx instanceof Activity) {
Offers.showInterstitialOfferIfNecessary((Activity) ctx, Offers.PLACEMENT_INTERSTITIAL_EXIT, false, false);
}
if (!(transfer instanceof InvalidTransfer)) {
TransferManager tm = TransferManager.instance();
if (tm.isBittorrentDownloadAndMobileDataSavingsOn(transfer)) {
UIUtils.showLongMessage(ctx, R.string.torrent_transfer_enqueued_on_mobile_data);
((BittorrentDownload) transfer).pause();
} else {
if (tm.isBittorrentDownloadAndMobileDataSavingsOff(transfer)) {
UIUtils.showLongMessage(ctx, R.string.torrent_transfer_consuming_mobile_data);
}
if (message != null) {
UIUtils.showShortMessage(ctx, message);
}
}
UIUtils.showTransfersOnDownloadStart(ctx);
} else if (!(transfer instanceof ExistingDownload)) {
UIUtils.showLongMessage(ctx, ((InvalidTransfer) transfer).getReasonResId());
}
}
}
Aggregations