mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-12 17:50:38 +01:00
fixed reply highlighting
This commit is contained in:
parent
c2ef39c879
commit
b728d8744e
@ -36,7 +36,7 @@ subprojects {
|
|||||||
Kotlin : '1.1.1',
|
Kotlin : '1.1.1',
|
||||||
SupportLib : '25.3.1',
|
SupportLib : '25.3.1',
|
||||||
MariotakuCommons : '0.9.13',
|
MariotakuCommons : '0.9.13',
|
||||||
RestFu : '0.9.44',
|
RestFu : '0.9.47',
|
||||||
ObjectCursor : '0.9.16',
|
ObjectCursor : '0.9.16',
|
||||||
PlayServices : '10.2.1',
|
PlayServices : '10.2.1',
|
||||||
MapsUtils : '0.4.4',
|
MapsUtils : '0.4.4',
|
||||||
@ -62,7 +62,7 @@ subprojects {
|
|||||||
Kovenant : '3.3.0',
|
Kovenant : '3.3.0',
|
||||||
ParcelablePlease : '1.0.2',
|
ParcelablePlease : '1.0.2',
|
||||||
Chameleon : '0.9.17',
|
Chameleon : '0.9.17',
|
||||||
UniqR : '0.9',
|
UniqR : '0.9.1',
|
||||||
SQLiteQB : '0.9.15',
|
SQLiteQB : '0.9.15',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,7 @@ dependencies {
|
|||||||
compile "com.github.mariotaku:PickNCrop:${libVersions['PickNCrop']}"
|
compile "com.github.mariotaku:PickNCrop:${libVersions['PickNCrop']}"
|
||||||
compile "com.github.mariotaku.RestFu:library:${libVersions['RestFu']}"
|
compile "com.github.mariotaku.RestFu:library:${libVersions['RestFu']}"
|
||||||
compile "com.github.mariotaku.RestFu:okhttp3:${libVersions['RestFu']}"
|
compile "com.github.mariotaku.RestFu:okhttp3:${libVersions['RestFu']}"
|
||||||
|
compile "com.github.mariotaku.RestFu:logansquare:${libVersions['RestFu']}"
|
||||||
compile 'com.squareup.okhttp3:okhttp:3.6.0'
|
compile 'com.squareup.okhttp3:okhttp:3.6.0'
|
||||||
compile 'com.lnikkila:extendedtouchview:0.1.0'
|
compile 'com.lnikkila:extendedtouchview:0.1.0'
|
||||||
compile 'com.google.dagger:dagger:2.8'
|
compile 'com.google.dagger:dagger:2.8'
|
||||||
@ -189,7 +190,7 @@ dependencies {
|
|||||||
compile "com.github.mariotaku:KPreferences:${libVersions['KPreferences']}"
|
compile "com.github.mariotaku:KPreferences:${libVersions['KPreferences']}"
|
||||||
compile "com.github.mariotaku:Chameleon:${libVersions['Chameleon']}"
|
compile "com.github.mariotaku:Chameleon:${libVersions['Chameleon']}"
|
||||||
compile 'com.github.mariotaku.QR-Code-generator:core:fcab3ea7f4'
|
compile 'com.github.mariotaku.QR-Code-generator:core:fcab3ea7f4'
|
||||||
compile 'com.github.mariotaku.UniqR:android:0.9'
|
compile "com.github.mariotaku.UniqR:android:${libVersions['UniqR']}"
|
||||||
|
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:${libVersions['Kotlin']}"
|
compile "org.jetbrains.kotlin:kotlin-stdlib:${libVersions['Kotlin']}"
|
||||||
compile "nl.komponents.kovenant:kovenant:${libVersions['Kovenant']}"
|
compile "nl.komponents.kovenant:kovenant:${libVersions['Kovenant']}"
|
||||||
|
@ -1 +1 @@
|
|||||||
e174801d3bd84f433aaac0c7d1cff2b6b8c43744
|
541542795b5b0b81f05a93400d7099cc877d2c84
|
||||||
|
@ -1,138 +0,0 @@
|
|||||||
/*
|
|
||||||
* Twidere - Twitter client for Android
|
|
||||||
*
|
|
||||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.mariotaku.microblog.library.twitter.util;
|
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.v4.util.SimpleArrayMap;
|
|
||||||
|
|
||||||
import com.bluelinelabs.logansquare.Commons_ParameterizedTypeAccessor;
|
|
||||||
import com.bluelinelabs.logansquare.ParameterizedType;
|
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
|
||||||
|
|
||||||
import org.mariotaku.microblog.library.twitter.model.TwitterResponse;
|
|
||||||
import org.mariotaku.restfu.RestConverter;
|
|
||||||
import org.mariotaku.restfu.http.ContentType;
|
|
||||||
import org.mariotaku.restfu.http.HttpResponse;
|
|
||||||
import org.mariotaku.restfu.http.mime.Body;
|
|
||||||
import org.mariotaku.restfu.http.mime.SimpleBody;
|
|
||||||
import org.mariotaku.restfu.http.mime.StringBody;
|
|
||||||
import org.mariotaku.twidere.util.JsonSerializer;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mariotaku on 2017/3/23.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class LoganSquareConverterFactory<E extends Exception> extends RestConverter.SimpleFactory<E> {
|
|
||||||
|
|
||||||
protected SimpleArrayMap<Type, RestConverter<HttpResponse, ?, E>> responseConverters = new SimpleArrayMap<>();
|
|
||||||
protected SimpleArrayMap<Type, RestConverter<?, Body, E>> sBodyConverters = new SimpleArrayMap<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestConverter<HttpResponse, ?, E> forResponse(Type type) throws RestConverter.ConvertException {
|
|
||||||
RestConverter<HttpResponse, ?, E> converter = responseConverters.get(type);
|
|
||||||
if (converter != null) {
|
|
||||||
return converter;
|
|
||||||
}
|
|
||||||
return new JsonResponseConverter<>(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestConverter<?, Body, E> forRequest(Type type) throws RestConverter.ConvertException {
|
|
||||||
final RestConverter<?, Body, E> converter = sBodyConverters.get(type);
|
|
||||||
if (converter != null) {
|
|
||||||
return converter;
|
|
||||||
}
|
|
||||||
if (SimpleBody.supports(type)) {
|
|
||||||
return new SimpleBodyConverter<>(type);
|
|
||||||
}
|
|
||||||
return new JsonRequestConverter<>(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private static Object parseOrThrow(HttpResponse response, ParameterizedType<?> type)
|
|
||||||
throws IOException, RestConverter.ConvertException {
|
|
||||||
try {
|
|
||||||
final Object parsed;
|
|
||||||
if (type.rawType == List.class) {
|
|
||||||
final Class cls = type.typeParameters.get(0).rawType;
|
|
||||||
parsed = JsonSerializer.parseList(response.getBody().stream(), cls);
|
|
||||||
} else if (type.rawType == Map.class) {
|
|
||||||
final Class cls = type.typeParameters.get(1).rawType;
|
|
||||||
parsed = JsonSerializer.parseMap(response.getBody().stream(), cls);
|
|
||||||
} else {
|
|
||||||
parsed = JsonSerializer.parse(response.getBody().stream(), type);
|
|
||||||
}
|
|
||||||
if (parsed == null) {
|
|
||||||
throw new IOException("Empty data");
|
|
||||||
}
|
|
||||||
return parsed;
|
|
||||||
} catch (JsonParseException e) {
|
|
||||||
throw new RestConverter.ConvertException("Malformed JSON Data");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class JsonResponseConverter<E extends Exception> implements RestConverter<HttpResponse, Object, E> {
|
|
||||||
private final ParameterizedType<?> type;
|
|
||||||
|
|
||||||
JsonResponseConverter(Type type) {
|
|
||||||
this.type = Commons_ParameterizedTypeAccessor.create(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object convert(HttpResponse httpResponse) throws IOException, ConvertException, E {
|
|
||||||
final Object object = parseOrThrow(httpResponse, type);
|
|
||||||
if (object instanceof TwitterResponse) {
|
|
||||||
((TwitterResponse) object).processResponseHeader(httpResponse);
|
|
||||||
}
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class JsonRequestConverter<E extends Exception> implements RestConverter<Object, Body, E> {
|
|
||||||
private final ParameterizedType<?> type;
|
|
||||||
|
|
||||||
JsonRequestConverter(Type type) {
|
|
||||||
this.type = Commons_ParameterizedTypeAccessor.create(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Body convert(Object request) throws IOException, ConvertException, E {
|
|
||||||
final String json;
|
|
||||||
if (type.rawType == List.class) {
|
|
||||||
final Class<?> cls = type.typeParameters.get(0).rawType;
|
|
||||||
//noinspection unchecked
|
|
||||||
json = JsonSerializer.serializeList((List) request, cls);
|
|
||||||
} else if (type.rawType == Map.class) {
|
|
||||||
final Class<?> cls = type.typeParameters.get(1).rawType;
|
|
||||||
//noinspection unchecked
|
|
||||||
json = JsonSerializer.serializeMap((Map) request, cls);
|
|
||||||
} else {
|
|
||||||
//noinspection unchecked
|
|
||||||
json = JsonSerializer.serialize(request, (ParameterizedType) type);
|
|
||||||
}
|
|
||||||
return new StringBody(json, ContentType.parse("application/json"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
/*
|
|
||||||
* Twidere - Twitter client for Android
|
|
||||||
*
|
|
||||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.mariotaku.microblog.library.twitter.util;
|
|
||||||
|
|
||||||
import org.mariotaku.microblog.library.MicroBlogException;
|
|
||||||
import org.mariotaku.microblog.library.twitter.model.ResponseCode;
|
|
||||||
import org.mariotaku.restfu.oauth.OAuthToken;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mariotaku on 15/5/5.
|
|
||||||
*/
|
|
||||||
public class TwitterConverterFactory extends LoganSquareConverterFactory<MicroBlogException> {
|
|
||||||
|
|
||||||
public TwitterConverterFactory() {
|
|
||||||
responseConverters.put(ResponseCode.class, new ResponseCode.ResponseConverter());
|
|
||||||
responseConverters.put(OAuthToken.class, new OAuthTokenResponseConverter());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -11,27 +11,9 @@ import android.support.annotation.WorkerThread;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
|
||||||
|
|
||||||
import org.mariotaku.microblog.library.MicroBlog;
|
import org.mariotaku.microblog.library.MicroBlog;
|
||||||
import org.mariotaku.microblog.library.MicroBlogException;
|
|
||||||
import org.mariotaku.microblog.library.twitter.util.TwitterConverterFactory;
|
|
||||||
import org.mariotaku.restfu.ExceptionFactory;
|
|
||||||
import org.mariotaku.restfu.RestConverter;
|
|
||||||
import org.mariotaku.restfu.RestFuUtils;
|
|
||||||
import org.mariotaku.restfu.RestMethod;
|
|
||||||
import org.mariotaku.restfu.RestRequest;
|
|
||||||
import org.mariotaku.restfu.annotation.HttpMethod;
|
|
||||||
import org.mariotaku.restfu.http.Authorization;
|
|
||||||
import org.mariotaku.restfu.http.BodyType;
|
|
||||||
import org.mariotaku.restfu.http.Endpoint;
|
import org.mariotaku.restfu.http.Endpoint;
|
||||||
import org.mariotaku.restfu.http.HttpRequest;
|
|
||||||
import org.mariotaku.restfu.http.HttpResponse;
|
|
||||||
import org.mariotaku.restfu.http.MultiValueMap;
|
|
||||||
import org.mariotaku.restfu.http.RawValue;
|
|
||||||
import org.mariotaku.restfu.http.SimpleValueMap;
|
import org.mariotaku.restfu.http.SimpleValueMap;
|
||||||
import org.mariotaku.restfu.http.ValueMap;
|
|
||||||
import org.mariotaku.restfu.http.mime.Body;
|
|
||||||
import org.mariotaku.restfu.oauth.OAuthEndpoint;
|
import org.mariotaku.restfu.oauth.OAuthEndpoint;
|
||||||
import org.mariotaku.restfu.oauth.OAuthToken;
|
import org.mariotaku.restfu.oauth.OAuthToken;
|
||||||
import org.mariotaku.twidere.TwidereConstants;
|
import org.mariotaku.twidere.TwidereConstants;
|
||||||
@ -44,9 +26,7 @@ import org.mariotaku.twidere.model.util.AccountUtils;
|
|||||||
import org.mariotaku.twidere.util.api.TwitterAndroidExtraHeaders;
|
import org.mariotaku.twidere.util.api.TwitterAndroidExtraHeaders;
|
||||||
import org.mariotaku.twidere.util.api.UserAgentExtraHeaders;
|
import org.mariotaku.twidere.util.api.UserAgentExtraHeaders;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -267,108 +247,6 @@ public class MicroBlogAPIFactory implements TwidereConstants {
|
|||||||
|| '0' <= codePoint && codePoint <= '9';
|
|| '0' <= codePoint && codePoint <= '9';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TwidereHttpRequestFactory implements HttpRequest.Factory {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final ExtraHeaders extraHeaders;
|
|
||||||
|
|
||||||
public TwidereHttpRequestFactory(final @Nullable ExtraHeaders extraHeaders) {
|
|
||||||
this.extraHeaders = extraHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <E extends Exception> HttpRequest create(@NonNull Endpoint endpoint, @NonNull RestRequest info,
|
|
||||||
@Nullable Authorization authorization,
|
|
||||||
RestConverter.Factory<E> converterFactory)
|
|
||||||
throws IOException, RestConverter.ConvertException, E {
|
|
||||||
final String restMethod = info.getMethod();
|
|
||||||
final String url = Endpoint.constructUrl(endpoint.getUrl(), info);
|
|
||||||
MultiValueMap<String> headers = info.getHeaders();
|
|
||||||
if (headers == null) {
|
|
||||||
headers = new MultiValueMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (authorization != null && authorization.hasAuthorization()) {
|
|
||||||
headers.add("Authorization", RestFuUtils.sanitizeHeader(authorization.getHeader(endpoint, info)));
|
|
||||||
}
|
|
||||||
if (extraHeaders != null) {
|
|
||||||
for (final Pair<String, String> pair : extraHeaders.get()) {
|
|
||||||
headers.add(pair.getFirst(), RestFuUtils.sanitizeHeader(pair.getSecond()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new HttpRequest(restMethod, url, headers, info.getBody(converterFactory), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TwidereExceptionFactory implements ExceptionFactory<MicroBlogException> {
|
|
||||||
|
|
||||||
private final TwitterConverterFactory converterFactory;
|
|
||||||
|
|
||||||
public TwidereExceptionFactory(TwitterConverterFactory converterFactory) {
|
|
||||||
this.converterFactory = converterFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MicroBlogException newException(Throwable cause, HttpRequest request, HttpResponse response) {
|
|
||||||
final MicroBlogException te;
|
|
||||||
if (cause != null) {
|
|
||||||
te = new MicroBlogException(cause);
|
|
||||||
} else {
|
|
||||||
te = parseTwitterException(response);
|
|
||||||
}
|
|
||||||
te.setHttpRequest(request);
|
|
||||||
te.setHttpResponse(response);
|
|
||||||
return te;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public MicroBlogException parseTwitterException(HttpResponse resp) {
|
|
||||||
try {
|
|
||||||
return (MicroBlogException) converterFactory.forResponse(MicroBlogException.class).convert(resp);
|
|
||||||
} catch (JsonParseException e) {
|
|
||||||
return new MicroBlogException("Malformed JSON Data", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
return new MicroBlogException("IOException while throwing exception", e);
|
|
||||||
} catch (RestConverter.ConvertException e) {
|
|
||||||
return new MicroBlogException(e);
|
|
||||||
} catch (MicroBlogException e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class TwidereRestRequestFactory implements RestRequest.Factory<MicroBlogException> {
|
|
||||||
@Nullable
|
|
||||||
private final Map<String, String> extraRequestParams;
|
|
||||||
|
|
||||||
public TwidereRestRequestFactory(@Nullable Map<String, String> extraRequestParams) {
|
|
||||||
this.extraRequestParams = extraRequestParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestRequest create(RestMethod<MicroBlogException> restMethod,
|
|
||||||
RestConverter.Factory<MicroBlogException> factory,
|
|
||||||
ValueMap valuePool) throws RestConverter.ConvertException, IOException, MicroBlogException {
|
|
||||||
final HttpMethod method = restMethod.getMethod();
|
|
||||||
final String path = restMethod.getPath();
|
|
||||||
final MultiValueMap<String> headers = restMethod.getHeaders(valuePool);
|
|
||||||
final MultiValueMap<String> queries = restMethod.getQueries(valuePool);
|
|
||||||
final MultiValueMap<Body> params = restMethod.getParams(factory, valuePool);
|
|
||||||
final RawValue rawValue = restMethod.getRawValue();
|
|
||||||
final BodyType bodyType = restMethod.getBodyType();
|
|
||||||
final Map<String, Object> extras = restMethod.getExtras();
|
|
||||||
|
|
||||||
if (queries != null && extraRequestParams != null) {
|
|
||||||
for (Map.Entry<String, String> entry : extraRequestParams.entrySet()) {
|
|
||||||
queries.add(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new RestRequest(method.value(), method.allowBody(), path, headers, queries,
|
|
||||||
params, rawValue, bodyType, extras);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ExtraHeaders {
|
public interface ExtraHeaders {
|
||||||
@NonNull
|
@NonNull
|
||||||
List<Pair<String, String>> get();
|
List<Pair<String, String>> get();
|
||||||
|
@ -1520,6 +1520,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
|||||||
val textAndMentions = extractor.extractReplyTextAndMentions(text, inReplyTo)
|
val textAndMentions = extractor.extractReplyTextAndMentions(text, inReplyTo)
|
||||||
if (textAndMentions.replyToOriginalUser) {
|
if (textAndMentions.replyToOriginalUser) {
|
||||||
hintLabel.visibility = View.GONE
|
hintLabel.visibility = View.GONE
|
||||||
|
editable.clearSpans(MentionColorSpan::class.java)
|
||||||
editable.setSpan(MentionColorSpan(mentionColor), 0, textAndMentions.replyStartIndex,
|
editable.setSpan(MentionColorSpan(mentionColor), 0, textAndMentions.replyStartIndex,
|
||||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,7 +9,6 @@ import org.mariotaku.microblog.library.fanfou.FanfouStream
|
|||||||
import org.mariotaku.microblog.library.twitter.*
|
import org.mariotaku.microblog.library.twitter.*
|
||||||
import org.mariotaku.microblog.library.twitter.auth.BasicAuthorization
|
import org.mariotaku.microblog.library.twitter.auth.BasicAuthorization
|
||||||
import org.mariotaku.microblog.library.twitter.auth.EmptyAuthorization
|
import org.mariotaku.microblog.library.twitter.auth.EmptyAuthorization
|
||||||
import org.mariotaku.microblog.library.twitter.util.TwitterConverterFactory
|
|
||||||
import org.mariotaku.restfu.RestAPIFactory
|
import org.mariotaku.restfu.RestAPIFactory
|
||||||
import org.mariotaku.restfu.RestRequest
|
import org.mariotaku.restfu.RestRequest
|
||||||
import org.mariotaku.restfu.http.Authorization
|
import org.mariotaku.restfu.http.Authorization
|
||||||
@ -29,11 +28,13 @@ import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
|||||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory.sFanfouConstantPool
|
import org.mariotaku.twidere.util.MicroBlogAPIFactory.sFanfouConstantPool
|
||||||
import org.mariotaku.twidere.util.MicroBlogAPIFactory.sTwitterConstantPool
|
import org.mariotaku.twidere.util.MicroBlogAPIFactory.sTwitterConstantPool
|
||||||
import org.mariotaku.twidere.util.TwitterContentUtils
|
import org.mariotaku.twidere.util.TwitterContentUtils
|
||||||
import org.mariotaku.twidere.util.api.UserAgentExtraHeaders
|
import org.mariotaku.twidere.util.api.*
|
||||||
import org.mariotaku.twidere.util.dagger.DependencyHolder
|
import org.mariotaku.twidere.util.dagger.DependencyHolder
|
||||||
import org.mariotaku.twidere.util.media.TwidereMediaDownloader
|
import org.mariotaku.twidere.util.media.TwidereMediaDownloader
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Creates [MicroBlog] instances
|
||||||
|
*
|
||||||
* Created by mariotaku on 2016/12/3.
|
* Created by mariotaku on 2016/12/3.
|
||||||
*/
|
*/
|
||||||
fun Credentials.getAuthorization(cls: Class<*>?): Authorization {
|
fun Credentials.getAuthorization(cls: Class<*>?): Authorization {
|
||||||
@ -175,11 +176,10 @@ fun <T> newMicroBlogInstance(context: Context, endpoint: Endpoint, auth: Authori
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val converterFactory = TwitterConverterFactory()
|
factory.setRestConverterFactory(TwitterConverterFactory)
|
||||||
factory.setRestConverterFactory(converterFactory)
|
factory.setExceptionFactory(TwidereExceptionFactory)
|
||||||
factory.setRestRequestFactory(MicroBlogAPIFactory.TwidereRestRequestFactory(extraRequestParams))
|
factory.setRestRequestFactory(TwidereRestRequestFactory(extraRequestParams))
|
||||||
factory.setHttpRequestFactory(MicroBlogAPIFactory.TwidereHttpRequestFactory(extraHeaders))
|
factory.setHttpRequestFactory(TwidereHttpRequestFactory(extraHeaders))
|
||||||
factory.setExceptionFactory(MicroBlogAPIFactory.TwidereExceptionFactory(converterFactory))
|
|
||||||
return factory.build<T>(cls)
|
return factory.build<T>(cls)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Twidere - Twitter client for Android
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mariotaku.twidere.util.api
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParseException
|
||||||
|
import org.mariotaku.microblog.library.MicroBlogException
|
||||||
|
import org.mariotaku.restfu.ExceptionFactory
|
||||||
|
import org.mariotaku.restfu.RestConverter
|
||||||
|
import org.mariotaku.restfu.http.HttpRequest
|
||||||
|
import org.mariotaku.restfu.http.HttpResponse
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create `MicroBlogException`
|
||||||
|
*
|
||||||
|
* Created by mariotaku on 2017/4/11.
|
||||||
|
*/
|
||||||
|
object TwidereExceptionFactory : ExceptionFactory<MicroBlogException> {
|
||||||
|
|
||||||
|
override fun newException(cause: Throwable?, request: HttpRequest?, response: HttpResponse?): MicroBlogException {
|
||||||
|
val te = if (cause != null) {
|
||||||
|
MicroBlogException(cause)
|
||||||
|
} else if (response != null) {
|
||||||
|
parseTwitterException(response)
|
||||||
|
} else {
|
||||||
|
MicroBlogException()
|
||||||
|
}
|
||||||
|
te.httpRequest = request
|
||||||
|
te.httpResponse = response
|
||||||
|
return te
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun parseTwitterException(resp: HttpResponse): MicroBlogException {
|
||||||
|
try {
|
||||||
|
val converter = TwitterConverterFactory.forResponse(MicroBlogException::class.java)
|
||||||
|
return converter.convert(resp) as MicroBlogException
|
||||||
|
} catch (e: JsonParseException) {
|
||||||
|
return MicroBlogException("Malformed JSON Data", e)
|
||||||
|
} catch (e: IOException) {
|
||||||
|
return MicroBlogException("IOException while throwing exception", e)
|
||||||
|
} catch (e: RestConverter.ConvertException) {
|
||||||
|
return MicroBlogException(e)
|
||||||
|
} catch (e: MicroBlogException) {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Twidere - Twitter client for Android
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mariotaku.twidere.util.api
|
||||||
|
|
||||||
|
import org.mariotaku.microblog.library.MicroBlogException
|
||||||
|
import org.mariotaku.restfu.RestConverter
|
||||||
|
import org.mariotaku.restfu.RestFuUtils
|
||||||
|
import org.mariotaku.restfu.RestRequest
|
||||||
|
import org.mariotaku.restfu.http.Authorization
|
||||||
|
import org.mariotaku.restfu.http.Endpoint
|
||||||
|
import org.mariotaku.restfu.http.HttpRequest
|
||||||
|
import org.mariotaku.restfu.http.MultiValueMap
|
||||||
|
import org.mariotaku.twidere.util.MicroBlogAPIFactory
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mariotaku on 2017/4/11.
|
||||||
|
*/
|
||||||
|
class TwidereHttpRequestFactory(
|
||||||
|
private val extraHeaders: MicroBlogAPIFactory.ExtraHeaders?
|
||||||
|
) : HttpRequest.Factory<MicroBlogException> {
|
||||||
|
|
||||||
|
override fun create(endpoint: Endpoint, info: RestRequest, authorization: Authorization?,
|
||||||
|
converterFactory: RestConverter.Factory<MicroBlogException>): HttpRequest {
|
||||||
|
val restMethod = info.method
|
||||||
|
val url = Endpoint.constructUrl(endpoint.url, info)
|
||||||
|
var headers: MultiValueMap<String>? = info.headers
|
||||||
|
if (headers == null) {
|
||||||
|
headers = MultiValueMap<String>()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (authorization != null && authorization.hasAuthorization()) {
|
||||||
|
headers.add("Authorization", RestFuUtils.sanitizeHeader(authorization.getHeader(endpoint, info)))
|
||||||
|
}
|
||||||
|
if (extraHeaders != null) {
|
||||||
|
for (pair in extraHeaders.get()) {
|
||||||
|
headers.add(pair.first, RestFuUtils.sanitizeHeader(pair.second))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HttpRequest(restMethod, url, headers, info.getBody(converterFactory), null)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Twidere - Twitter client for Android
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mariotaku.twidere.util.api
|
||||||
|
|
||||||
|
import org.mariotaku.microblog.library.MicroBlogException
|
||||||
|
import org.mariotaku.restfu.RestConverter
|
||||||
|
import org.mariotaku.restfu.RestMethod
|
||||||
|
import org.mariotaku.restfu.RestRequest
|
||||||
|
import org.mariotaku.restfu.http.ValueMap
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert rest method to rest request
|
||||||
|
*
|
||||||
|
* Created by mariotaku on 2017/4/11.
|
||||||
|
*/
|
||||||
|
class TwidereRestRequestFactory(
|
||||||
|
private val extraRequestParams: Map<String, String>?
|
||||||
|
) : RestRequest.Factory<MicroBlogException> {
|
||||||
|
|
||||||
|
override fun create(restMethod: RestMethod<MicroBlogException>,
|
||||||
|
factory: RestConverter.Factory<MicroBlogException>, valuePool: ValueMap): RestRequest {
|
||||||
|
val method = restMethod.method
|
||||||
|
val path = restMethod.path
|
||||||
|
val headers = restMethod.getHeaders(valuePool)
|
||||||
|
val queries = restMethod.getQueries(valuePool)
|
||||||
|
val params = restMethod.getParams(factory, valuePool)
|
||||||
|
val rawValue = restMethod.rawValue
|
||||||
|
val bodyType = restMethod.bodyType
|
||||||
|
val extras = restMethod.extras
|
||||||
|
|
||||||
|
if (queries != null && extraRequestParams != null) {
|
||||||
|
for ((key, value) in extraRequestParams) {
|
||||||
|
queries.add(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return RestRequest(method.value, method.allowBody, path, headers, queries,
|
||||||
|
params, rawValue, bodyType, extras)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Twidere - Twitter client for Android
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mariotaku.twidere.util.api
|
||||||
|
|
||||||
|
import android.support.v4.util.SimpleArrayMap
|
||||||
|
|
||||||
|
import org.mariotaku.microblog.library.MicroBlogException
|
||||||
|
import org.mariotaku.microblog.library.twitter.model.ResponseCode
|
||||||
|
import org.mariotaku.microblog.library.twitter.model.TwitterResponse
|
||||||
|
import org.mariotaku.microblog.library.twitter.util.OAuthTokenResponseConverter
|
||||||
|
import org.mariotaku.restfu.RestConverter
|
||||||
|
import org.mariotaku.restfu.http.HttpResponse
|
||||||
|
import org.mariotaku.restfu.http.mime.Body
|
||||||
|
import org.mariotaku.restfu.http.mime.SimpleBody
|
||||||
|
import org.mariotaku.restfu.logansqaure.LoganSquareConverterFactory
|
||||||
|
import org.mariotaku.restfu.oauth.OAuthToken
|
||||||
|
|
||||||
|
import java.lang.reflect.Type
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert JSON responses
|
||||||
|
*
|
||||||
|
* Created by mariotaku on 15/5/5.
|
||||||
|
*/
|
||||||
|
object TwitterConverterFactory : LoganSquareConverterFactory<MicroBlogException>() {
|
||||||
|
|
||||||
|
private val responseConverters = SimpleArrayMap<Type, RestConverter<HttpResponse, *, MicroBlogException>>()
|
||||||
|
private val sBodyConverters = SimpleArrayMap<Type, RestConverter<*, Body, MicroBlogException>>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
responseConverters.put(ResponseCode::class.java, ResponseCode.ResponseConverter())
|
||||||
|
responseConverters.put(OAuthToken::class.java, OAuthTokenResponseConverter())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(RestConverter.ConvertException::class)
|
||||||
|
override fun forResponse(type: Type): RestConverter<HttpResponse, *, MicroBlogException> {
|
||||||
|
val converter = responseConverters.get(type)
|
||||||
|
if (converter != null) {
|
||||||
|
return converter
|
||||||
|
}
|
||||||
|
return super.forResponse(type)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(RestConverter.ConvertException::class)
|
||||||
|
override fun forRequest(type: Type): RestConverter<*, Body, MicroBlogException> {
|
||||||
|
val converter = sBodyConverters.get(type)
|
||||||
|
if (converter != null) {
|
||||||
|
return converter
|
||||||
|
}
|
||||||
|
if (SimpleBody.supports(type)) {
|
||||||
|
return SimpleBodyConverter<MicroBlogException>(type)
|
||||||
|
}
|
||||||
|
return super.forRequest(type)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun processParsedObject(obj: Any, httpResponse: HttpResponse) {
|
||||||
|
if (obj is TwitterResponse) {
|
||||||
|
obj.processResponseHeader(httpResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,19 +23,15 @@ import io.nayuki.qrcodegen.QrCode
|
|||||||
import org.mariotaku.uniqr.QrData
|
import org.mariotaku.uniqr.QrData
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Wrapper for `QrCode`
|
||||||
|
*
|
||||||
* Created by mariotaku on 2017/4/10.
|
* Created by mariotaku on 2017/4/10.
|
||||||
*/
|
*/
|
||||||
data class QrCodeData(private val qrCode: QrCode) : QrData {
|
data class QrCodeData(private val qrCode: QrCode) : QrData {
|
||||||
|
|
||||||
override fun getSize(): Int {
|
override fun getSize() = qrCode.size
|
||||||
return qrCode.size
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getVersion(): Int {
|
override fun getVersion() = qrCode.version
|
||||||
return qrCode.version
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun get(x: Int, y: Int): Boolean {
|
override fun get(x: Int, y: Int) = qrCode.getModule(x, y) == 1
|
||||||
return qrCode.getModule(x, y) == 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user