fixed npe
This commit is contained in:
parent
8f506f25a1
commit
3543045320
|
@ -21,6 +21,7 @@ package org.mariotaku.twidere.model;
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||||
|
@ -87,6 +88,7 @@ public class ParcelableCredentials extends ParcelableAccount implements Parcelab
|
||||||
@ParcelableThisPlease
|
@ParcelableThisPlease
|
||||||
@JsonField(name = "api_url_format")
|
@JsonField(name = "api_url_format")
|
||||||
@CursorField(Accounts.API_URL_FORMAT)
|
@CursorField(Accounts.API_URL_FORMAT)
|
||||||
|
@Nullable
|
||||||
public String api_url_format;
|
public String api_url_format;
|
||||||
@ParcelableThisPlease
|
@ParcelableThisPlease
|
||||||
@JsonField(name = "same_oauth_signing_url")
|
@JsonField(name = "same_oauth_signing_url")
|
||||||
|
|
|
@ -50,9 +50,11 @@ import java.lang.ref.WeakReference;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Network diagnostics
|
||||||
* Created by mariotaku on 16/2/9.
|
* Created by mariotaku on 16/2/9.
|
||||||
*/
|
*/
|
||||||
public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
|
@ -110,6 +112,8 @@ public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case LogText.State.DEFAULT:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
mLogTextView.append(coloredText);
|
mLogTextView.append(coloredText);
|
||||||
Selection.setSelection(mLogTextView.getEditableText(), mLogTextView.length());
|
Selection.setSelection(mLogTextView.getEditableText(), mLogTextView.length());
|
||||||
|
@ -185,7 +189,12 @@ public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
publishProgress(new LogText("Testing Network connectivity"));
|
publishProgress(new LogText("Testing Network connectivity"));
|
||||||
publishProgress(LogText.LINEBREAK);
|
publishProgress(LogText.LINEBREAK);
|
||||||
|
|
||||||
final String baseUrl = TwitterAPIFactory.getApiBaseUrl(credentials.api_url_format, "api");
|
final String baseUrl;
|
||||||
|
if (credentials.api_url_format != null) {
|
||||||
|
baseUrl = TwitterAPIFactory.getApiBaseUrl(credentials.api_url_format, "api");
|
||||||
|
} else {
|
||||||
|
baseUrl = TwitterAPIFactory.getApiBaseUrl(DEFAULT_TWITTER_API_URL_FORMAT, "api");
|
||||||
|
}
|
||||||
RestHttpClient client = RestAPIFactory.getRestClient(twitter).getRestClient();
|
RestHttpClient client = RestAPIFactory.getRestClient(twitter).getRestClient();
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
try {
|
try {
|
||||||
|
@ -195,8 +204,8 @@ public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
builder.url(baseUrl);
|
builder.url(baseUrl);
|
||||||
final long start = SystemClock.uptimeMillis();
|
final long start = SystemClock.uptimeMillis();
|
||||||
response = client.newCall(builder.build()).execute();
|
response = client.newCall(builder.build()).execute();
|
||||||
publishProgress(new LogText(String.format(" OK (%d ms)", SystemClock.uptimeMillis()
|
publishProgress(new LogText(String.format(Locale.US, " OK (%d ms)",
|
||||||
- start), LogText.State.OK));
|
SystemClock.uptimeMillis() - start), LogText.State.OK));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
||||||
}
|
}
|
||||||
|
@ -207,8 +216,8 @@ public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
final long start = SystemClock.uptimeMillis();
|
final long start = SystemClock.uptimeMillis();
|
||||||
final CountOutputStream os = new CountOutputStream();
|
final CountOutputStream os = new CountOutputStream();
|
||||||
response.getBody().writeTo(os);
|
response.getBody().writeTo(os);
|
||||||
publishProgress(new LogText(String.format(" %d bytes (%d ms)", os.getTotal(),
|
publishProgress(new LogText(String.format(Locale.US, " %d bytes (%d ms)",
|
||||||
SystemClock.uptimeMillis() - start), LogText.State.OK));
|
os.getTotal(), SystemClock.uptimeMillis() - start), LogText.State.OK));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
||||||
|
@ -272,8 +281,8 @@ public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
try {
|
try {
|
||||||
final long start = SystemClock.uptimeMillis();
|
final long start = SystemClock.uptimeMillis();
|
||||||
publishProgress(new LogText(String.valueOf(dns.lookupResolver(host))));
|
publishProgress(new LogText(String.valueOf(dns.lookupResolver(host))));
|
||||||
publishProgress(new LogText(String.format(" OK (%d ms)", SystemClock.uptimeMillis()
|
publishProgress(new LogText(String.format(Locale.US, " OK (%d ms)",
|
||||||
- start), LogText.State.OK));
|
SystemClock.uptimeMillis() - start), LogText.State.OK));
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
||||||
}
|
}
|
||||||
|
@ -285,8 +294,8 @@ public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
try {
|
try {
|
||||||
final long start = SystemClock.uptimeMillis();
|
final long start = SystemClock.uptimeMillis();
|
||||||
publishProgress(new LogText(Arrays.toString(InetAddress.getAllByName(host))));
|
publishProgress(new LogText(Arrays.toString(InetAddress.getAllByName(host))));
|
||||||
publishProgress(new LogText(String.format(" OK (%d ms)", SystemClock.uptimeMillis()
|
publishProgress(new LogText(String.format(Locale.US, " OK (%d ms)",
|
||||||
- start), LogText.State.OK));
|
SystemClock.uptimeMillis() - start), LogText.State.OK));
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
||||||
}
|
}
|
||||||
|
@ -298,8 +307,8 @@ public class NetworkDiagnosticsFragment extends BaseSupportFragment {
|
||||||
try {
|
try {
|
||||||
final long start = SystemClock.uptimeMillis();
|
final long start = SystemClock.uptimeMillis();
|
||||||
test.execute(twitter);
|
test.execute(twitter);
|
||||||
publishProgress(new LogText(String.format("OK (%d ms)", SystemClock.uptimeMillis()
|
publishProgress(new LogText(String.format(Locale.US, "OK (%d ms)",
|
||||||
- start), LogText.State.OK));
|
SystemClock.uptimeMillis() - start), LogText.State.OK));
|
||||||
} catch (TwitterException e) {
|
} catch (TwitterException e) {
|
||||||
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
publishProgress(new LogText("ERROR: " + e.getMessage(), LogText.State.ERROR));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue