bug fixes

added user agent for network image loader
This commit is contained in:
Mariotaku Lee 2015-06-29 03:32:51 +08:00
parent a13dd300db
commit be7bf1e948
12 changed files with 54 additions and 35 deletions

View File

@ -16,6 +16,14 @@ public class RawItemArray implements Selectable {
this.array = array;
}
public RawItemArray(final int[] array) {
final Integer[] converted = new Integer[array.length];
for (int i = 0, j = array.length; i < j; i++) {
converted[i] = array[i];
}
this.array = converted;
}
@Override
public String getSQL() {
return Utils.toString(array, ',', true);

View File

@ -79,7 +79,7 @@ dependencies {
compile 'com.github.mariotaku:DragSortListView:0.6.1'
compile 'com.github.mariotaku:SlidingMenu:1.3'
compile 'com.github.uucky:ColorPicker-Android:0.9.7@aar'
compile 'com.github.boxme:AsyncManager:9391ed71d7@aar'
compile 'com.github.boxme:asyncmanager:1.0.0'
compile 'com.sprylab.android.texturevideoview:texturevideoview:1.0.0'
compile 'com.squareup:pollexor:2.0.2'
compile 'org.apache.commons:commons-lang3:3.4'

View File

@ -85,6 +85,7 @@ import org.mariotaku.twidere.util.VideoLoader;
import org.mariotaku.twidere.util.VideoLoader.VideoLoadingListener;
import java.io.File;
import java.util.concurrent.TimeUnit;
import pl.droidsonroids.gif.GifSupportChecker;
import pl.droidsonroids.gif.GifTextureView;
@ -863,7 +864,8 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements
final int position = mMediaPlayerControl.getCurrentPosition();
if (duration <= 0 || position < 0) return;
mProgressBar.setProgress(Math.round(1000 * position / (float) duration));
final int durationSecs = duration / 1000, positionSecs = position / 1000;
final long durationSecs = TimeUnit.SECONDS.convert(duration, TimeUnit.MILLISECONDS),
positionSecs = TimeUnit.SECONDS.convert(position, TimeUnit.MILLISECONDS);
mDurationLabel.setText(String.format("%02d:%02d", durationSecs / 60, durationSecs % 60));
mPositionLabel.setText(String.format("%02d:%02d", positionSecs / 60, positionSecs % 60));
mHandler.postDelayed(this, 16);

View File

@ -22,16 +22,13 @@ package org.mariotaku.twidere.model;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import com.db.chart.model.BarSet;
import com.db.chart.model.ChartSet;
import org.mariotaku.querybuilder.Columns;
import org.mariotaku.querybuilder.Expression;
import org.mariotaku.querybuilder.RawItemArray;
import org.mariotaku.twidere.provider.TwidereDataStore.NetworkUsages;
import org.mariotaku.twidere.util.MathUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@ -56,12 +53,13 @@ public class NetworkUsageInfo {
this.dayMax = dayMax;
}
public static NetworkUsageInfo get(Context context, Date start, Date end, int dayMin, int dayMax) {
public static NetworkUsageInfo get(Context context, Date start, Date end, int dayMin, int dayMax, int[] networks) {
final ContentResolver cr = context.getContentResolver();
final long startTime = TimeUnit.HOURS.convert(start.getTime(), TimeUnit.MILLISECONDS);
final long endTime = TimeUnit.HOURS.convert(end.getTime(), TimeUnit.MILLISECONDS);
final Expression where = Expression.and(Expression.greaterEquals(NetworkUsages.TIME_IN_HOURS, startTime),
Expression.lesserThan(NetworkUsages.TIME_IN_HOURS, endTime));
Expression.lesserThan(NetworkUsages.TIME_IN_HOURS, endTime),
Expression.in(new Columns.Column(NetworkUsages.REQUEST_NETWORK), new RawItemArray(networks)));
final int days = (int) TimeUnit.DAYS.convert(endTime - startTime, TimeUnit.HOURS);
final Cursor c = cr.query(NetworkUsages.CONTENT_URI, NetworkUsages.COLUMNS,
where.getSQL(), null, NetworkUsages.TIME_IN_HOURS);
@ -89,28 +87,12 @@ public class NetworkUsageInfo {
}
c.close();
final BarSet apiSet = new BarSet();
final BarSet mediaSet = new BarSet();
final BarSet usageStatisticsSet = new BarSet();
double dayUsageMax = 0;
for (int i = 0; i < days; i++) {
String day = String.valueOf(i + 1);
final double[] dayUsage = chartUsage[i];
apiSet.addBar(day, (float) dayUsage[RequestType.API.getValue()]);
mediaSet.addBar(day, (float) dayUsage[RequestType.MEDIA.getValue()]);
usageStatisticsSet.addBar(day, (float) dayUsage[RequestType.USAGE_STATISTICS.getValue()]);
dayUsageMax = Math.max(dayUsageMax, MathUtils.sum(dayUsage));
}
apiSet.setColor(Color.RED);
mediaSet.setColor(Color.GREEN);
usageStatisticsSet.setColor(Color.BLUE);
final ArrayList<ChartSet> data = new ArrayList<>();
data.add(apiSet);
data.add(mediaSet);
data.add(usageStatisticsSet);
return new NetworkUsageInfo(chartUsage, usageTotal, totalReceived, totalSent, dayUsageMax, dayMin, dayMax);
}

View File

@ -21,7 +21,7 @@ package org.mariotaku.twidere.preference;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.ConnectivityManager;
import android.preference.Preference;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
@ -30,8 +30,6 @@ import android.view.ViewGroup;
import android.widget.TextView;
import com.db.chart.model.BarSet;
import com.db.chart.view.AxisController;
import com.db.chart.view.StackBarChartView;
import com.desmond.asyncmanager.AsyncManager;
import com.desmond.asyncmanager.TaskRunnable;
@ -100,7 +98,8 @@ public class NetworkUsageSummaryPreferences extends Preference {
task = new TaskRunnable<Object[], NetworkUsageInfo, NetworkUsageSummaryPreferences>() {
@Override
public NetworkUsageInfo doLongOperation(Object[] params) throws InterruptedException {
return NetworkUsageInfo.get((Context) params[0], (Date) params[1], (Date) params[2], dayMin, dayMax);
final int[] network = {ConnectivityManager.TYPE_MOBILE};
return NetworkUsageInfo.get((Context) params[0], (Date) params[1], (Date) params[2], dayMin, dayMax, network);
}
@Override

View File

@ -59,6 +59,9 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import static android.text.TextUtils.isEmpty;
/**
@ -111,10 +114,14 @@ public class TwitterAPIFactory implements TwidereConstants {
final OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(connectionTimeout, TimeUnit.SECONDS);
final long connectionTimeoutMillis = TimeUnit.MILLISECONDS.convert(connectionTimeout, TimeUnit.SECONDS);
final SSLSocketFactory sslSocketFactory;
if (ignoreSslError) {
client.setSslSocketFactory(SSLCertificateSocketFactory.getInsecure(0, null));
} else {
client.setSslSocketFactory(SSLCertificateSocketFactory.getDefault(0, null));
sslSocketFactory = SSLCertificateSocketFactory.getInsecure((int) connectionTimeoutMillis, null);
if (sslSocketFactory instanceof SSLCertificateSocketFactory) {
}
client.setSslSocketFactory(sslSocketFactory);
}
if (enableProxy) {
client.setProxy(getProxy(prefs));

View File

@ -53,6 +53,7 @@ import org.mariotaku.twidere.util.MediaPreviewUtils;
import org.mariotaku.twidere.util.SharedPreferencesWrapper;
import org.mariotaku.twidere.util.TwidereLinkify;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.UserAgentUtils;
import org.mariotaku.twidere.util.Utils;
import java.io.FileNotFoundException;
@ -67,6 +68,7 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const
private final Context mContext;
private final SharedPreferencesWrapper mPreferences;
private final boolean mUseThumbor;
private final String mUserAgent;
private Thumbor mThumbor;
private RestHttpClient mClient;
private final boolean mFullImage;
@ -80,6 +82,7 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const
mFullImage = fullImage;
mTwitterProfileImageSize = context.getString(R.string.profile_image_size);
mUseThumbor = useThumbor;
mUserAgent = UserAgentUtils.getDefaultUserAgentString(context);
reloadConnectivitySettings();
}
@ -163,6 +166,7 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
additionalHeaders.add(Pair.create("Accept", "image/webp, */*"));
}
additionalHeaders.add(Pair.create("User-Agent", mUserAgent));
final String method = GET.METHOD;
final String requestUri;
if (auth != null && auth.hasAuthorization()) {

View File

@ -23,6 +23,7 @@ import android.content.Context;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.util.Pair;
import com.squareup.okhttp.Call;
@ -43,6 +44,7 @@ import org.mariotaku.restfu.http.RestHttpRequest;
import org.mariotaku.restfu.http.RestHttpResponse;
import org.mariotaku.restfu.http.RestQueuedRequest;
import org.mariotaku.restfu.http.mime.TypedData;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.util.DebugModeUtils;
import java.io.IOException;
@ -70,7 +72,12 @@ public class OkHttpRestClient implements RestHttpClient {
@Override
public RestHttpResponse execute(RestHttpRequest restHttpRequest) throws IOException {
final Call call = newCall(restHttpRequest);
return new OkRestHttpResponse(call.execute());
try {
return new OkRestHttpResponse(call.execute());
} catch (IOException e) {
Log.w(Constants.LOGTAG, e);
throw e;
}
}
private Call newCall(final RestHttpRequest restHttpRequest) {

View File

@ -26,10 +26,17 @@
android:padding="@dimen/element_spacing_normal">
<TextView
android:id="@+id/mobile_network_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/on_mobile_network" />
<LinearLayout
android:id="@+id/total_usage_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/mobile_network_label"
android:layout_margin="@dimen/element_spacing_large"
android:gravity="center_vertical"
android:orientation="horizontal">
@ -100,7 +107,6 @@
android:layout_below="@+id/total_usage_container"
android:visibility="gone">
<TextView
android:id="@+id/day_usage_max"
android:layout_width="wrap_content"

View File

@ -4,6 +4,9 @@
<color name="nyan_background">#003366</color>
<color name="background_color_window_light">#eeeeee</color>
<color name="background_color_window_dark">#202020</color>
<color name="background_color_window_viewer">#000</color>
<color name="background_color_window_white">#fff</color>
<color name="background_color_window_black">#000</color>
<color name="background_color_window_settings_wizard">#fafafa</color>
<color name="bg_refresh_progress_color_light">#f5f5f5</color>
<color name="bg_refresh_progress_color_dark">#333333</color>

View File

@ -768,4 +768,5 @@
<string name="usage_label_received">Received</string>
<string name="this_month">This month</string>
<string name="media_preload">Media preload</string>
<string name="on_mobile_network">On mobile network</string>
</resources>

View File

@ -230,7 +230,7 @@
<style name="Theme.Twidere.Viewer" parent="Theme.AppCompat">
<!-- Window attributes -->
<item name="android:windowBackground">@android:color/black</item>
<item name="android:windowBackground">@color/background_color_window_viewer</item>
<!--<item name="android:windowIsTranslucent">true</item>-->
<!--<item name="android:colorBackgroundCacheHint">@null</item>-->
<item name="windowActionBarOverlay">true</item>