Skip to content

Commit

Permalink
[android] Improved BitTorrent Status display on transfers.
Browse files Browse the repository at this point in the history
  • Loading branch information
gubatron committed Mar 25, 2016
1 parent e3c6e00 commit e9b879a
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 29 deletions.
2 changes: 1 addition & 1 deletion android/apollo/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- UI catetgory -->
<!-- UI category -->
<PreferenceCategory android:title="@string/settings_ui_category" >

<!-- Color scheme -->
Expand Down
3 changes: 3 additions & 0 deletions android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,7 @@
<string name="learn_more">Learn more</string>
<string name="enable_experimental">Experimental Features</string>
<string name="selected">selected</string>
<string name="check_internet_connection">Check Internet connection</string>
<string name="bittorrent_off_data_saver_on">"BitTorrent off (Data Saver On)"</string>
<string name="bittorrent_off">BitTorrent off</string>
</resources>
1 change: 1 addition & 0 deletions android/src/com/frostwire/android/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private Constants() {
public static final String ACTION_MEDIA_PLAYER_PAUSED = "com.frostwire.android.ACTION_MEDIA_PLAYER_PAUSED";
public static final String ACTION_REFRESH_FINGER = "com.frostwire.android.ACTION_REFRESH_FINGER";
public static final String ACTION_SETTINGS_SELECT_STORAGE = "com.frostwire.android.ACTION_SETTINGS_SELECT_STORAGE";
public static final String ACTION_SETTINGS_OPEN_TORRENT_SETTINGS = "com.frostwire.android.ACTION_SETTINGS_OPEN_TORRENT_SETTINGS";
public static final String ACTION_NOTIFY_SDCARD_MOUNTED = "com.frostwire.android.ACTION_NOTIFY_SDCARD_MOUNTED";
public static final String EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION = "com.frostwire.android.EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION";
public static final String EXTRA_DOWNLOAD_COMPLETE_PATH = "com.frostwire.android.EXTRA_DOWNLOAD_COMPLETE_PATH";
Expand Down
4 changes: 4 additions & 0 deletions android/src/com/frostwire/android/gui/NetworkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ private NetworkManager(Application context) {
this.context = context;
}

public boolean isInternetDown() {
return !isDataWIFIUp() && !isDataMobileUp() && !isDataWiMAXUp();
}

public boolean isDataUp() {
// boolean logic trick, since sometimes android reports WIFI and MOBILE up at the same time
return (isDataWIFIUp() != isDataMobileUp()) || isDataWiMAXUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,25 @@
import android.app.Dialog;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.*;
import android.preference.Preference.OnPreferenceChangeListener;
import android.view.MenuItem;
import android.view.View;
import android.view.*;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import com.frostwire.android.AndroidPlatform;
import com.frostwire.android.R;
import com.frostwire.android.StoragePicker;
import com.frostwire.android.core.ConfigurationManager;
import com.frostwire.android.core.Constants;
import com.frostwire.android.gui.LocalSearchEngine;
import com.frostwire.android.gui.NetworkManager;
import com.frostwire.android.gui.SearchEngine;
import com.frostwire.android.StoragePicker;
import com.frostwire.android.gui.services.Engine;
import com.frostwire.android.gui.services.EngineService;
import com.frostwire.android.gui.transfers.TransferManager;
Expand All @@ -52,7 +51,6 @@
import com.frostwire.android.gui.views.preference.StoragePreference;
import com.frostwire.bittorrent.BTEngine;
import com.frostwire.logging.Logger;
import com.frostwire.util.StringUtils;
import com.frostwire.uxstats.UXAction;
import com.frostwire.uxstats.UXStats;

Expand All @@ -67,6 +65,7 @@ public class SettingsActivity extends PreferenceActivity {

private static final Logger LOG = Logger.getLogger(SettingsActivity.class);
private static String currentPreferenceKey = null;
private boolean finishOnBack = false;

@Override
protected void onResume() {
Expand All @@ -89,9 +88,15 @@ public void onCreate(Bundle savedInstanceState) {
setupComponents();

String action = getIntent().getAction();
if (action != null && action.equals(Constants.ACTION_SETTINGS_SELECT_STORAGE)) {
if (action != null) {
getIntent().setAction(null);
StoragePreference.invokeStoragePreference(this);
if (action.equals(Constants.ACTION_SETTINGS_SELECT_STORAGE)) {
StoragePreference.invokeStoragePreference(this);
} else if (action.equals(Constants.ACTION_SETTINGS_OPEN_TORRENT_SETTINGS)) {
finishOnBack = true;
openPreference("frostwire.prefs.torrent.preference_category");
return;
}
}

updateConnectSwitch();
Expand Down Expand Up @@ -524,15 +529,35 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
* @param preferenceScreen
*/
private void initializePreferenceScreen(PreferenceScreen preferenceScreen) {
if (preferenceScreen == null) {
return;
}

final Dialog dialog = preferenceScreen.getDialog();
if (dialog != null) {

dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialog.dismiss();
if (finishOnBack) {
finish();
return;
}
}
});

hideActionBarIcon(dialog.getActionBar());
View homeButton = dialog.findViewById(android.R.id.home);

if (homeButton != null) {
OnClickListener dismissDialogClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (finishOnBack) {
finish();
return;
}
dialog.dismiss();
}
};
Expand All @@ -552,4 +577,18 @@ public void onClick(View v) {
}
}
}

private void openPreference(String key) {
PreferenceScreen preferenceScreen = getPreferenceScreen();
final ListAdapter listAdapter = preferenceScreen.getRootAdapter();

final int itemsCount = listAdapter.getCount();
int itemNumber;
for (itemNumber = 0; itemNumber < itemsCount; ++itemNumber) {
if (listAdapter.getItem(itemNumber).equals(findPreference(key))) {
preferenceScreen.onItemClick(null, null, itemNumber, 0);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.frostwire.android.gui.adapters.TransferListAdapter;
import com.frostwire.android.gui.dialogs.MenuDialog;
import com.frostwire.android.gui.dialogs.MenuDialog.MenuItem;
import com.frostwire.android.gui.services.Engine;
import com.frostwire.android.gui.services.EngineService;
import com.frostwire.android.gui.tasks.DownloadSoundcloudFromUrlTask;
import com.frostwire.android.gui.transfers.*;
Expand Down Expand Up @@ -89,7 +90,6 @@ public class TransfersFragment extends AbstractFragment implements TimerObserver
private final EngineService.CheckDHTUICallback onDHTCheckCallback;
private static boolean firstTimeShown = true;
private Handler vpnRichToastHandler;
private final long VPN_NOTIFICATION_DURATION = 10000;

public TransfersFragment() {
super(R.layout.fragment_transfers);
Expand Down Expand Up @@ -221,15 +221,56 @@ public void onVpnStatus(final boolean vpnActive) {
}

private class OnCheckDHTCallback implements EngineService.CheckDHTUICallback {
private View.OnClickListener onTextDHTPeersClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(v.getContext(), SettingsActivity.class);
if (showTorrentSettingsOnClick) {
i.setAction(Constants.ACTION_SETTINGS_OPEN_TORRENT_SETTINGS);
}
v.getContext().startActivity(i);
}
};

private boolean showTorrentSettingsOnClick;

@Override
public void onCheckDHT(final boolean dhtEnabled, final int dhtPeers) {
if (textDHTPeers==null || !TransfersFragment.this.isAdded()) {
return;
}
textDHTPeers.setVisibility(dhtEnabled ? View.VISIBLE : View.GONE);

textDHTPeers.setVisibility(View.VISIBLE);
textDHTPeers.setOnClickListener(onTextDHTPeersClickListener);
showTorrentSettingsOnClick = true;

// No Internet
if (NetworkManager.instance().isInternetDown()) {
textDHTPeers.setText(R.string.check_internet_connection);
return;
}

// Saving Data on Mobile
if (TransferManager.instance().isMobileAndDataSavingsOn()) {
textDHTPeers.setText(R.string.bittorrent_off_data_saver_on);
return;
}

// BitTorrent Turned off
if (Engine.instance().isStopped() || Engine.instance().isDisconnected()) {
// takes you to main settings screen so you can turn it back on.
showTorrentSettingsOnClick = false;
textDHTPeers.setText(R.string.bittorrent_off);
return;
}

// No DHT
if (!dhtEnabled) {
textDHTPeers.setVisibility(View.GONE);
return;
}

// DHT On.
textDHTPeers.setText(dhtPeers + " " + TransfersFragment.this.getString(R.string.dht_contacts));
}
}
Expand Down Expand Up @@ -274,13 +315,12 @@ public void onShow() {
if (!TransfersFragment.isVPNactive) {
showVPNRichToast();
}
} else {
//LOG.info("Shown some other time.");
}
}

private void showVPNRichToast() {
vpnRichToast.setVisibility(View.VISIBLE);
long VPN_NOTIFICATION_DURATION = 10000;
vpnRichToastHandler.postDelayed(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -538,7 +578,7 @@ private boolean someTransfersActive(List<Transfer> transfers) {
return false;
}

public void startTransferFromURL() {
private void startTransferFromURL() {
String url = addTransferUrlTextView.getText();
if (!StringUtils.isNullOrEmpty(url) && (url.startsWith("magnet") || url.startsWith("http"))) {
toggleAddTransferControls();
Expand Down Expand Up @@ -634,7 +674,7 @@ private void hideAddTransfersKeyboard() {
* Is it using the SD Card's private (non-persistent after uninstall) app folder to save
* downloaded files?
*/
public static boolean isUsingSDCardPrivateStorage() {
private static boolean isUsingSDCardPrivateStorage() {
String primaryPath = Environment.getExternalStorageDirectory().getAbsolutePath();
String currentPath = ConfigurationManager.instance().getStoragePath();

Expand Down Expand Up @@ -689,7 +729,7 @@ public enum TransferStatus {

private static final class ButtonAddTransferListener extends ClickAdapter<TransfersFragment> {

public ButtonAddTransferListener(TransfersFragment f) {
ButtonAddTransferListener(TransfersFragment f) {
super(f);
}

Expand All @@ -701,7 +741,7 @@ public void onClick(TransfersFragment f, View v) {

private static final class ButtonMenuListener extends ClickAdapter<TransfersFragment> {

public ButtonMenuListener(TransfersFragment f) {
ButtonMenuListener(TransfersFragment f) {
super(f);
}

Expand All @@ -713,7 +753,7 @@ public void onClick(TransfersFragment f, View v) {

private static final class AddTransferTextListener extends ClickAdapter<TransfersFragment> implements OnItemClickListener, OnActionListener {

public AddTransferTextListener(TransfersFragment owner) {
AddTransferTextListener(TransfersFragment owner) {
super(owner);
}

Expand Down Expand Up @@ -752,7 +792,7 @@ private static final class ButtonTabListener extends ClickAdapter<TransfersFragm

private final TransferStatus status;

public ButtonTabListener(TransfersFragment f, TransferStatus status) {
ButtonTabListener(TransfersFragment f, TransferStatus status) {
super(f);
this.status = status;
}
Expand All @@ -766,7 +806,7 @@ public void onClick(TransfersFragment f, View v) {

private static final class SDCardNotificationListener extends ClickAdapter<TransfersFragment> {

public SDCardNotificationListener(TransfersFragment owner) {
SDCardNotificationListener(TransfersFragment owner) {
super(owner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,21 @@ private boolean isBittorrentDownload(DownloadTransfer transfer) {
return transfer instanceof UIBittorrentDownload || transfer instanceof TorrentFetcherDownload;
}

public boolean isBittorrentSearchResultAndMobileDataSavingsOn(SearchResult sr) {
return sr instanceof TorrentSearchResult &&
NetworkManager.instance().isDataMobileUp() &&
public boolean isMobileAndDataSavingsOn() {
return NetworkManager.instance().isDataMobileUp() &&
!ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_NETWORK_USE_MOBILE_DATA);
}

public boolean isBittorrentSearchResultAndMobileDataSavingsOn(SearchResult sr) {
return sr instanceof TorrentSearchResult && isMobileAndDataSavingsOn();
}

public boolean isBittorrentDownloadAndMobileDataSavingsOn(DownloadTransfer transfer) {
return isBittorrentDownload(transfer) &&
NetworkManager.instance().isDataMobileUp() &&
!ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_NETWORK_USE_MOBILE_DATA);
return isBittorrentDownload(transfer) && isMobileAndDataSavingsOn();
}

public boolean isBittorrentDownloadAndMobileDataSavingsOff(DownloadTransfer transfer) {
return isBittorrentDownload(transfer) &&
NetworkManager.instance().isDataMobileUp() &&
ConfigurationManager.instance().getBoolean(Constants.PREF_KEY_NETWORK_USE_MOBILE_DATA);
return isBittorrentDownload(transfer) && isMobileAndDataSavingsOn();
}

public boolean isBittorrentDisconnected() {
Expand Down

1 comment on commit e9b879a

@gubatron
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #107

Please sign in to comment.