You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.8 KiB
119 lines
3.8 KiB
11 years ago
|
/*
|
||
|
* Copyright 2010-2013 Eric Kok et al.
|
||
|
*
|
||
|
* Transdroid is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* Transdroid is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with Transdroid. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*/
|
||
11 years ago
|
package org.transdroid.core.gui;
|
||
|
|
||
|
import java.util.List;
|
||
|
|
||
|
import org.androidannotations.annotations.EViewGroup;
|
||
|
import org.androidannotations.annotations.ViewById;
|
||
10 years ago
|
import org.transdroid.R;
|
||
11 years ago
|
import org.transdroid.core.gui.navigation.NavigationHelper;
|
||
|
import org.transdroid.core.gui.navigation.SetTransferRatesDialog;
|
||
|
import org.transdroid.core.gui.navigation.SetTransferRatesDialog.OnRatesPickedListener;
|
||
11 years ago
|
import org.transdroid.daemon.Torrent;
|
||
|
import org.transdroid.daemon.util.FileSizeConverter;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.view.View;
|
||
|
import android.widget.RelativeLayout;
|
||
|
import android.widget.TextView;
|
||
11 years ago
|
import de.keyboardsurfer.android.widget.crouton.Crouton;
|
||
11 years ago
|
|
||
11 years ago
|
@EViewGroup(resName = "actionbar_serverstatus")
|
||
|
public class ServerStatusView extends RelativeLayout implements OnRatesPickedListener {
|
||
11 years ago
|
|
||
|
@ViewById
|
||
|
protected TextView downcountText, upcountText, downcountSign, upcountSign, downspeedText, upspeedText;
|
||
10 years ago
|
@ViewById
|
||
|
protected View speedswrapperLayout;
|
||
11 years ago
|
private TorrentsActivity activity;
|
||
|
|
||
11 years ago
|
public ServerStatusView(Context context) {
|
||
|
super(context);
|
||
|
}
|
||
|
|
||
11 years ago
|
public ServerStatusView(TorrentsActivity activity) {
|
||
|
super(activity);
|
||
|
this.activity = activity;
|
||
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Updates the statistics as shown in the action bar through this server status view.
|
||
|
* @param torrents The most recently received list of torrents
|
||
11 years ago
|
* @param dormantAsInactive
|
||
11 years ago
|
*/
|
||
11 years ago
|
public void update(List<Torrent> torrents, boolean dormantAsInactive) {
|
||
11 years ago
|
|
||
11 years ago
|
if (torrents == null) {
|
||
|
downcountText.setText(null);
|
||
|
upcountText.setText(null);
|
||
|
downspeedText.setText(null);
|
||
|
upspeedText.setText(null);
|
||
|
downcountSign.setVisibility(View.INVISIBLE);
|
||
|
upcountSign.setVisibility(View.INVISIBLE);
|
||
10 years ago
|
speedswrapperLayout.setOnClickListener(null);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
int downcount = 0, upcount = 0, downspeed = 0, upspeed = 0;
|
||
|
for (Torrent torrent : torrents) {
|
||
11 years ago
|
|
||
11 years ago
|
// Downloading torrents count towards downloads and uploads, seeding torrents towards uploads
|
||
11 years ago
|
if (torrent.isDownloading(dormantAsInactive)) {
|
||
11 years ago
|
downcount++;
|
||
|
upcount++;
|
||
11 years ago
|
} else if (torrent.isSeeding(dormantAsInactive)) {
|
||
11 years ago
|
upcount++;
|
||
|
}
|
||
|
downspeed += torrent.getRateDownload();
|
||
|
upspeed += torrent.getRateUpload();
|
||
11 years ago
|
|
||
11 years ago
|
}
|
||
|
|
||
|
downcountText.setText(Integer.toString(downcount));
|
||
|
upcountText.setText(Integer.toString(upcount));
|
||
11 years ago
|
downspeedText.setText(FileSizeConverter.getSize(downspeed) + "/s");
|
||
|
upspeedText.setText(FileSizeConverter.getSize(upspeed) + "/s");
|
||
11 years ago
|
downcountSign.setVisibility(View.VISIBLE);
|
||
|
upcountSign.setVisibility(View.VISIBLE);
|
||
10 years ago
|
speedswrapperLayout.setOnClickListener(onStartDownPickerClicked);
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
|
private OnClickListener onStartDownPickerClicked = new OnClickListener() {
|
||
|
public void onClick(View v) {
|
||
11 years ago
|
new SetTransferRatesDialog().setOnRatesPickedListener(ServerStatusView.this).show(
|
||
10 years ago
|
activity.getFragmentManager(), "SetTransferRatesDialog");
|
||
11 years ago
|
}
|
||
|
};
|
||
|
|
||
|
@Override
|
||
|
public void onRatesPicked(int maxDownloadSpeed, int maxUploadSpeed) {
|
||
|
activity.updateMaxSpeeds(maxDownloadSpeed, maxUploadSpeed);
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
@Override
|
||
|
public void resetRates() {
|
||
|
activity.updateMaxSpeeds(null, null);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void onInvalidNumber() {
|
||
|
Crouton.showText(activity, R.string.error_notanumber, NavigationHelper.CROUTON_ERROR_STYLE);
|
||
|
}
|
||
|
|
||
11 years ago
|
}
|