diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/TwidereConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/TwidereConstants.java index 56d809f59..5aa1b83f0 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/TwidereConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/TwidereConstants.java @@ -53,6 +53,7 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst String TWITTER_CONSUMER_SECRET = "0UnEHDq5IzVK9nstiz2nWOtG5rOMM5JkUpATfM78Do"; String DEFAULT_TWITTER_API_URL_FORMAT = "https://[DOMAIN.]twitter.com/"; + String DEFAULT_TWITTER_OAUTH_BASE_URL = "https://api.twitter.com/oauth/"; String SCHEME_HTTP = "http"; String SCHEME_HTTPS = "https"; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterConstants.java deleted file mode 100644 index 9b3d64696..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterConstants.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.api.twitter; - -public interface TwitterConstants { - - public static final String DEFAULT_OAUTH_BASE_URL = "https://api.twitter.com/oauth/"; - public static final String DEFAULT_SIGNING_OAUTH_BASE_URL = DEFAULT_OAUTH_BASE_URL; - - public static final String PATH_SEGMENT_AUTHENTICATION = "authenticate"; - public static final String PATH_SEGMENT_REQUEST_TOKEN = "request_token"; - public static final String PATH_SEGMENT_ACCESS_TOKEN = "access_token"; - public static final String PATH_SEGMENT_AUTHORIZATION = "authorize"; - - public static final String DEFAULT_OAUTH_REQUEST_TOKEN_URL = DEFAULT_OAUTH_BASE_URL + PATH_SEGMENT_REQUEST_TOKEN; - public static final String DEFAULT_OAUTH_AUTHORIZATION_URL = DEFAULT_OAUTH_BASE_URL + PATH_SEGMENT_AUTHORIZATION; - public static final String DEFAULT_OAUTH_ACCESS_TOKEN_URL = DEFAULT_OAUTH_BASE_URL + PATH_SEGMENT_ACCESS_TOKEN; - public static final String DEFAULT_OAUTH_AUTHENTICATION_URL = DEFAULT_OAUTH_BASE_URL + PATH_SEGMENT_AUTHENTICATION; - - public static final String DEFAULT_SIGNING_OAUTH_REQUEST_TOKEN_URL = DEFAULT_SIGNING_OAUTH_BASE_URL - + PATH_SEGMENT_REQUEST_TOKEN; - public static final String DEFAULT_SIGNING_OAUTH_AUTHORIZATION_URL = DEFAULT_SIGNING_OAUTH_BASE_URL - + PATH_SEGMENT_AUTHORIZATION; - public static final String DEFAULT_SIGNING_OAUTH_ACCESS_TOKEN_URL = DEFAULT_SIGNING_OAUTH_BASE_URL - + PATH_SEGMENT_ACCESS_TOKEN; - public static final String DEFAULT_SIGNING_OAUTH_AUTHENTICATION_URL = DEFAULT_SIGNING_OAUTH_BASE_URL - + PATH_SEGMENT_AUTHENTICATION; - - public static final String DEFAULT_REST_BASE_URL = "https://api.twitter.com/1.1/"; - public static final String DEFAULT_SIGNING_REST_BASE_URL = DEFAULT_REST_BASE_URL; - - public static final String ENDPOINT_ACCOUNT_REMOVE_PROFILE_BANNER = "account/remove_profile_banner.json"; - public static final String ENDPOINT_ACCOUNT_SETTINGS = "account/settings.json"; - public static final String ENDPOINT_ACCOUNT_UPDATE_PROFILE = "account/update_profile.json"; - public static final String ENDPOINT_ACCOUNT_UPDATE_PROFILE_BACKGROUND_IMAGE = "account/update_profile_background_image.json"; - public static final String ENDPOINT_ACCOUNT_UPDATE_PROFILE_BANNER = "account/update_profile_banner.json"; - public static final String ENDPOINT_ACCOUNT_UPDATE_PROFILE_COLORS = "account/update_profile_colors.json"; - public static final String ENDPOINT_ACCOUNT_UPDATE_PROFILE_IMAGE = "account/update_profile_image.json"; - public static final String ENDPOINT_ACCOUNT_VERIFY_CREDENTIALS = "account/verify_credentials.json"; - - public static final String ENDPOINT_ACTIVITY_ABOUT_ME = "activity/about_me.json"; - public static final String ENDPOINT_ACTIVITY_BY_FRIENDS = "activity/by_friends.json"; - - public static final String ENDPOINT_CONVERSATION_SHOW = "conversation/show.json"; - - public static final String ENDPOINT_TRANSLATIONS_SHOW = "translations/show.json"; - - public static final String ENDPOINT_BLOCKS_CREATE = "blocks/create.json"; - public static final String ENDPOINT_BLOCKS_DESTROY = "blocks/destroy.json"; - public static final String ENDPOINT_BLOCKS_LIST = "blocks/list.json"; - public static final String ENDPOINT_BLOCKS_IDS = "blocks/ids.json"; - - public static final String ENDPOINT_MUTES_USERS_CREATE = "mutes/users/create.json"; - public static final String ENDPOINT_MUTES_USERS_DESTROY = "mutes/users/destroy.json"; - public static final String ENDPOINT_MUTES_USERS_LIST = "mutes/users/list.json"; - public static final String ENDPOINT_MUTES_USERS_IDS = "mutes/users/ids.json"; - - public static final String ENDPOINT_DIRECT_MESSAGES = "direct_messages.json"; - public static final String ENDPOINT_DIRECT_MESSAGES_DESTROY = "direct_messages/destroy.json"; - public static final String ENDPOINT_DIRECT_MESSAGES_NEW = "direct_messages/new.json"; - public static final String ENDPOINT_DIRECT_MESSAGES_SENT = "direct_messages/sent.json"; - public static final String ENDPOINT_DIRECT_MESSAGES_SHOW = "direct_messages/show.json"; - - public static final String TEMPLATE_DM_CONVERSATION_DELETE = "dm/conversation/%d-%d/delete.json"; - - public static final String ENDPOINT_FAVORITES_LIST = "favorites/list.json"; - public static final String ENDPOINT_FAVORITES_CREATE = "favorites/create.json"; - public static final String ENDPOINT_FAVORITES_DESTROY = "favorites/destroy.json"; - - public static final String ENDPOINT_GEO_PLACE = "geo/place.json"; - public static final String ENDPOINT_GEO_REVERSE_GEOCODE = "geo/reverse_geocode.json"; - public static final String ENDPOINT_GEO_SEARCH = "geo/search.json"; - public static final String ENDPOINT_GEO_SIMILAR_PLACES = "geo/similar_places.json"; - - public static final String ENDPOINT_FOLLOWERS_IDS = "followers/ids.json"; - public static final String ENDPOINT_FRIENDS_IDS = "friends/ids.json"; - public static final String ENDPOINT_FOLLOWERS_LIST = "followers/list.json"; - public static final String ENDPOINT_FRIENDS_LIST = "friends/list.json"; - public static final String ENDPOINT_FRIENDSHIPS_CREATE = "friendships/create.json"; - public static final String ENDPOINT_FRIENDSHIPS_DESTROY = "friendships/destroy.json"; - public static final String ENDPOINT_FRIENDSHIPS_INCOMING = "friendships/incoming.json"; - public static final String ENDPOINT_FRIENDSHIPS_LOOKUP = "friendships/lookup.json"; - public static final String ENDPOINT_FRIENDSHIPS_OUTGOING = "friendships/outgoing.json"; - public static final String ENDPOINT_FRIENDSHIPS_SHOW = "friendships/show.json"; - public static final String ENDPOINT_FRIENDSHIPS_UPDATE = "friendships/update.json"; - public static final String ENDPOINT_FRIENDSHIPS_ACCEPT = "friendships/accept.json"; - public static final String ENDPOINT_FRIENDSHIPS_DENY = "friendships/deny.json"; - - public static final String ENDPOINT_HELP_CONFIGURATION = "help/configuration.json"; - public static final String ENDPOINT_HELP_LANGUAGES = "help/languages.json"; - public static final String ENDPOINT_LEGAL_PRIVACY = "legal/privacy.json"; - public static final String ENDPOINT_LEGAL_TOS = "legal/tos.json"; - - public static final String ENDPOINT_LISTS_CREATE = "lists/create.json"; - public static final String ENDPOINT_LISTS_DESTROY = "lists/destroy.json"; - public static final String ENDPOINT_LISTS_LIST = "lists/list.json"; - public static final String ENDPOINT_LISTS_MEMBERSHIPS = "lists/memberships.json"; - public static final String ENDPOINT_LISTS_MEMBERS = "lists/members.json"; - public static final String ENDPOINT_LISTS_MEMBERS_CREATE = "lists/members/create.json"; - public static final String ENDPOINT_LISTS_MEMBERS_CREATE_ALL = "lists/members/create_all.json"; - public static final String ENDPOINT_LISTS_MEMBERS_DESTROY = "lists/members/destroy.json"; - public static final String ENDPOINT_LISTS_MEMBERS_DESTROY_ALL = "lists/members/destroy_all.json"; - public static final String ENDPOINT_LISTS_MEMBERS_SHOW = "lists/members/show.json"; - public static final String ENDPOINT_LISTS_SHOW = "lists/show.json"; - public static final String ENDPOINT_LISTS_STATUSES = "lists/statuses.json"; - public static final String ENDPOINT_LISTS_SUBSCRIPTIONS = "lists/subscriptions.json"; - public static final String ENDPOINT_LISTS_SUBSCRIBERS = "lists/subscribers.json"; - public static final String ENDPOINT_LISTS_SUBSCRIBERS_CREATE = "lists/subscribers/create.json"; - public static final String ENDPOINT_LISTS_SUBSCRIBERS_DESTROY = "lists/subscribers/destroy.json"; - public static final String ENDPOINT_LISTS_SUBSCRIBERS_SHOW = "lists/subscribers/show.json"; - public static final String ENDPOINT_LISTS_UPDATE = "lists/update.json"; - public static final String ENDPOINT_LISTS_OWNERSHIPS = "lists/ownerships.json"; - - public static final String ENDPOINT_RATE_LIMIT_STATUS = "application/rate_limit_status.json"; - - public static final String ENDPOINT_SAVED_SEARCHES_CREATE = "saved_searches/create.json"; - public static final String ENDPOINT_SAVED_SEARCHES_LIST = "saved_searches/list.json"; - - public static final String ENDPOINT_SEARCH_TWEETS = "search/tweets.json"; - - public static final String ENDPOINT_STATUSES_HOME_TIMELINE = "statuses/home_timeline.json"; - public static final String ENDPOINT_STATUSES_MENTIONS_TIMELINE = "statuses/mentions_timeline.json"; - public static final String ENDPOINT_STATUSES_OEMBED = "statuses/oembed.json"; - public static final String ENDPOINT_STATUSES_RETWEETS_OF_ME = "statuses/retweets_of_me.json"; - public static final String ENDPOINT_STATUSES_RETWEETERS_IDS = "statuses/retweeters/ids.json"; - public static final String ENDPOINT_STATUSES_SHOW = "statuses/show.json"; - public static final String ENDPOINT_STATUSES_UPDATE = "statuses/update.json"; - public static final String ENDPOINT_STATUSES_USER_TIMELINE = "statuses/user_timeline.json"; - public static final String ENDPOINT_STATUSES_MEDIA_TIMELINE = "statuses/media_timeline.json"; - public static final String ENDPOINT_STATUSES_REPORT_SPAM = "statuses/report_spam.json"; - - public static final String ENDPOINT_TRENDS_AVAILABLE = "trends/available.json"; - public static final String ENDPOINT_TRENDS_CLOSEST = "trends/closest.json"; - public static final String ENDPOINT_TRENDS_PLACE = "trends/place.json"; - - public static final String ENDPOINT_USERS_LOOKUP = "users/lookup.json"; - public static final String ENDPOINT_USERS_REPORT_SPAM = "users/report_spam.json"; - public static final String ENDPOINT_USERS_SEARCH = "users/search.json"; - public static final String ENDPOINT_USERS_SHOW = "users/show.json"; - public static final String ENDPOINT_USERS_SUGGESTIONS = "users/suggestions.json"; - - public static final String DEFAULT_UPLOAD_BASE_URL = "https://upload.twitter.com/1.1/"; - public static final String DEFAULT_SIGNING_UPLOAD_BASE_URL = DEFAULT_UPLOAD_BASE_URL; - - public static final String ENDPOINT_MEDIA_UPLOAD = "media/upload.json"; -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java index a74f0da98..7e8a018d5 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterException.java @@ -135,17 +135,6 @@ public class TwitterException extends Exception implements TwitterResponse, Http return errors[0].getCode(); } - /** - * Returns error message from the API if available. - * - * @return error message from the API - * @since Twitter4J 2.2.3 - */ - public String getErrorMessage() { - if (errors == null || errors.length == 0) return null; - return errors[0].getMessage(); - } - public RestHttpRequest getHttpRequest() { return request; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/TwitterUpload.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterUpload.java similarity index 97% rename from twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/TwitterUpload.java rename to twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterUpload.java index e5cc04496..a09d8d183 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/api/TwitterUpload.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/TwitterUpload.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.api.twitter.api; +package org.mariotaku.twidere.api.twitter; import org.mariotaku.simplerestapi.http.BodyType; import org.mariotaku.simplerestapi.http.mime.FileTypedData; diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/CharacterUtil.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/CharacterUtil.java deleted file mode 100644 index cc026ef1a..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/CharacterUtil.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.api.twitter.util; - -/** - * @author Yusuke Yamamoto - yusuke at mac.com - * @since Twitter4J 2.1.2 - */ -public final class CharacterUtil { - private CharacterUtil() { - throw new AssertionError(); - } - - /** - * Counts the length of the tweet - * - * @param text tweet to be counted - * @return the length of the tweet - */ - public static int count(final String text) { - return text.length(); - } - - /** - * Returns true if the length of the string is exceeding length limitation - * - * @param text String to be examined - * @return if the length of the string is exceeding length limitation - */ - public static boolean isExceedingLengthLimitation(final String text) { - return count(text) > 140; - } -} diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/InternalParseUtil.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/InternalParseUtil.java index d7677f2f5..1f858eca5 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/InternalParseUtil.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/InternalParseUtil.java @@ -19,22 +19,7 @@ package org.mariotaku.twidere.api.twitter.util; -import org.json.JSONException; -import org.json.JSONObject; import org.mariotaku.simplerestapi.http.RestHttpResponse; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.text.NumberFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.TimeZone; - -import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.TwitterResponse; /** @@ -43,151 +28,12 @@ import org.mariotaku.twidere.api.twitter.model.TwitterResponse; * @author Yusuke Yamamoto - yusuke at mac.com */ public final class InternalParseUtil { - private static ThreadLocal> formatMap = new ThreadLocal>() { - @Override - protected Map initialValue() { - return new HashMap(); - } - }; private InternalParseUtil() { // should never be instantiated throw new AssertionError(); } - public static boolean getBoolean(final String name, final JSONObject json) { - final String str = getRawString(name, json); - if (null == str || "null".equals(str)) return false; - return Boolean.valueOf(str); - } - - public static Date getDate(final String name, final JSONObject json) throws TwitterException { - return getDate(name, json, "EEE MMM d HH:mm:ss z yyyy"); - } - - public static Date getDate(final String name, final JSONObject json, final String format) throws TwitterException { - final String dateStr = getUnescapedString(name, json); - if ("null".equals(dateStr) || null == dateStr) - return null; - else - return getDate(dateStr, format); - } - - public static Date getDate(final String date, final String format) throws TwitterException { - SimpleDateFormat sdf = formatMap.get().get(format); - if (null == sdf) { - sdf = new SimpleDateFormat(format, Locale.ENGLISH); - sdf.setTimeZone(TimeZone.getTimeZone("GMT")); - formatMap.get().put(format, sdf); - } - try { - return sdf.parse(date); - } catch (final ParseException pe) { - throw new TwitterException("Unexpected date format(" + date + ") returned from twitter.com", pe); - } - } - - public static double getDouble(final String name, final JSONObject json) { - final String str2 = getRawString(name, json); - if (null == str2 || "".equals(str2) || "null".equals(str2)) - return -1; - else - return Double.valueOf(str2); - } - - public static int getInt(final String str) { - if (null == str || "".equals(str) || "null".equals(str)) - return -1; - else { - try { - return Integer.valueOf(str); - } catch (final NumberFormatException nfe) { - // workaround for the API side issue - // http://twitter4j.org/jira/browse/TFJ-484 - return -1; - } - } - } - - public static int getInt(final String name, final JSONObject json) { - return getInt(getRawString(name, json)); - } - - public static long getLong(String str) { - if (null == str || "".equals(str) || "null".equals(str)) - return -1; - else { - try { - final Number number = NumberFormat.getInstance().parse(str); - return number.longValue(); - } catch (final ParseException e) { - } - // some count over 100 will be expressed as "100+" - if (str.endsWith("+")) { - str = str.substring(0, str.length() - 1); - try { - return Integer.valueOf(str) + 1; - } catch (final NumberFormatException nfe) { - // workaround for the API side issue - // http://twitter4j.org/jira/browse/TFJ-484 - return -1; - } - } - try { - return Long.valueOf(str); - } catch (final NumberFormatException nfe) { - // workaround for the API side issue - // http://twitter4j.org/jira/browse/TFJ-484 - return -1; - } - } - } - - public static long getLong(final String name, final JSONObject json) { - return getLong(getRawString(name, json)); - } - - public static String getRawString(final String name, final JSONObject json) { - try { - if (json.isNull(name)) return null; - return json.getString(name); - } catch (final JSONException e) { - return null; - } - } - - public static String getUnescapedString(final String name, final JSONObject json) { - final String str = getRawString(name, json); - if (str == null) return null; - return str.replace("&", "&").replace("<", "<").replace(">", ">"); - } - - public static String getURLDecodedString(final String name, final JSONObject json) { - String returnValue = getRawString(name, json); - if (returnValue != null) { - try { - returnValue = URLDecoder.decode(returnValue, "UTF-8"); - } catch (final UnsupportedEncodingException ignore) { - } - } - return returnValue; - } - - public static Date parseTrendsDate(final String asOfStr) throws TwitterException { - Date parsed; - switch (asOfStr.length()) { - case 10: - parsed = new Date(Long.parseLong(asOfStr) * 1000); - break; - case 20: - parsed = getDate(asOfStr, "yyyy-MM-dd'T'HH:mm:ss'Z'"); - break; - default: - parsed = getDate(asOfStr, "EEE, d MMM yyyy HH:mm:ss z"); - } - return parsed; - } - public static int toAccessLevel(final RestHttpResponse res) { if (null == res) return -1; final String xAccessLevel = res.getHeader("X-Access-Level"); diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/TimeSpanConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/TimeSpanConverter.java deleted file mode 100644 index 563de0181..000000000 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/TimeSpanConverter.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2015 Mariotaku Lee - * - * 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 . - */ - -package org.mariotaku.twidere.api.twitter.util; - -import java.text.MessageFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -/** - * @author Joern Huxhorn - jhuxhorn at googlemail.com - * @author Yusuke Yamamoto - yusuke at mac.com - * @since Twitter4J 2.1.0 - */ -public final class TimeSpanConverter { - private static final int ONE_HOUR_IN_SECONDS = 60 * 60; - private static final int ONE_DAY_IN_SECONDS = 24 * ONE_HOUR_IN_SECONDS; - private static final int ONE_MONTH_IN_SECONDS = 30 * ONE_DAY_IN_SECONDS; - - private final MessageFormat[] formats = new MessageFormat[6]; - private final SimpleDateFormat dateMonth; - private final SimpleDateFormat dateMonthYear; - - private static final int NOW = 0; - private static final int N_SECONDS_AGO = 1; - private static final int A_MINUTE_AGO = 2; - private static final int N_MINUTES_AGO = 3; - private static final int AN_HOUR_AGO = 4; - private static final int N_HOURS_AGO = 5; - - /** - * Constructs an instance with default locale - */ - public TimeSpanConverter() { - this(Locale.getDefault()); - } - - /** - * Constructs an instance with the specified locale - * - * @param locale locale - */ - public TimeSpanConverter(final Locale locale) { - final String language = locale.getLanguage(); - if ("it".equals(language)) { - formats[NOW] = new MessageFormat("Ora"); - formats[N_SECONDS_AGO] = new MessageFormat("{0} secondi fa"); - formats[A_MINUTE_AGO] = new MessageFormat("1 minuto fa"); - formats[N_MINUTES_AGO] = new MessageFormat("{0} minuti fa"); - formats[AN_HOUR_AGO] = new MessageFormat("1 ora fa"); - formats[N_HOURS_AGO] = new MessageFormat("{0} ore fa"); - dateMonth = new SimpleDateFormat("d MMM", locale); - dateMonthYear = new SimpleDateFormat("d MMM yy", locale); - } else if ("kr".equals(language)) { - formats[NOW] = new MessageFormat("지금"); - formats[N_SECONDS_AGO] = new MessageFormat("{0}초 전"); - formats[A_MINUTE_AGO] = new MessageFormat("1분 전"); - formats[N_MINUTES_AGO] = new MessageFormat("{0}분 전"); - formats[AN_HOUR_AGO] = new MessageFormat("1시간 전"); - formats[N_HOURS_AGO] = new MessageFormat("{0} ore fa"); - dateMonth = new SimpleDateFormat("M월 d일", locale); - dateMonthYear = new SimpleDateFormat("yy년 M월 d일", locale); - } else if ("es".equals(language)) { - formats[NOW] = new MessageFormat("Ahora"); - formats[N_SECONDS_AGO] = new MessageFormat("hace {0} segundos"); - formats[A_MINUTE_AGO] = new MessageFormat("hace 1 munito"); - formats[N_MINUTES_AGO] = new MessageFormat("hace {0} munitos"); - formats[AN_HOUR_AGO] = new MessageFormat("hace 1 hora"); - formats[N_HOURS_AGO] = new MessageFormat("hace {0} horas"); - dateMonth = new SimpleDateFormat("d MMM", locale); - dateMonthYear = new SimpleDateFormat("d MMM yy", locale); - } else if ("fr".equals(language)) { - formats[NOW] = new MessageFormat("Maintenant"); - formats[N_SECONDS_AGO] = new MessageFormat("Il y a {0} secondes"); - formats[A_MINUTE_AGO] = new MessageFormat("Il y a 1 minute"); - formats[N_MINUTES_AGO] = new MessageFormat("Il y a {0} minutes"); - formats[AN_HOUR_AGO] = new MessageFormat("Il y a 1 heure"); - formats[N_HOURS_AGO] = new MessageFormat("Il y a {0} heures"); - dateMonth = new SimpleDateFormat("d MMM", locale); - dateMonthYear = new SimpleDateFormat("d MMM yy", locale); - } else if ("de".equals(language)) { - formats[NOW] = new MessageFormat("Jetzt"); - formats[N_SECONDS_AGO] = new MessageFormat("vor {0} Sekunden"); - formats[A_MINUTE_AGO] = new MessageFormat("vor 1 Minute"); - formats[N_MINUTES_AGO] = new MessageFormat("vor {0} Minuten"); - formats[AN_HOUR_AGO] = new MessageFormat("vor 1 Stunde"); - formats[N_HOURS_AGO] = new MessageFormat("vor {0} Stunden"); - dateMonth = new SimpleDateFormat("d MMM", locale); - dateMonthYear = new SimpleDateFormat("d MMM yy", locale); - } else if ("ja".equals(language)) { - formats[NOW] = new MessageFormat("今"); - formats[N_SECONDS_AGO] = new MessageFormat("{0}秒前"); - formats[A_MINUTE_AGO] = new MessageFormat("1分前"); - formats[N_MINUTES_AGO] = new MessageFormat("{0}分前"); - formats[AN_HOUR_AGO] = new MessageFormat("1時間前"); - formats[N_HOURS_AGO] = new MessageFormat("{0}時間前"); - dateMonth = new SimpleDateFormat("M月d日", locale); - dateMonthYear = new SimpleDateFormat("yy年M月d日", locale); - } else { - formats[NOW] = new MessageFormat("now"); - formats[N_SECONDS_AGO] = new MessageFormat("{0} seconds ago"); - formats[A_MINUTE_AGO] = new MessageFormat("1 minute ago"); - formats[N_MINUTES_AGO] = new MessageFormat("{0} minutes ago"); - formats[AN_HOUR_AGO] = new MessageFormat("1 hour ago"); - formats[N_HOURS_AGO] = new MessageFormat("{0} hours ago"); - dateMonth = new SimpleDateFormat("d MMM", Locale.ENGLISH); - dateMonthYear = new SimpleDateFormat("d MMM yy", Locale.ENGLISH); - } - } - - public String toTimeSpanString(final Date date) { - return toTimeSpanString(date.getTime()); - } - - public String toTimeSpanString(final long milliseconds) { - final int deltaInSeconds = (int) ((System.currentTimeMillis() - milliseconds) / 1000); - if (deltaInSeconds >= ONE_DAY_IN_SECONDS) { - if (deltaInSeconds >= ONE_MONTH_IN_SECONDS) - return dateMonthYear.format(new Date(milliseconds)); - else - return dateMonth.format(new Date(milliseconds)); - } - return toTimeSpanString(deltaInSeconds); - } - - private String toTimeSpanString(final int deltaInSeconds) { - if (deltaInSeconds <= 1) - return formats[NOW].format(null); - else if (deltaInSeconds < 60) return formats[N_SECONDS_AGO].format(new Object[] { deltaInSeconds }); - - if (deltaInSeconds < 45 * 60) { - final int minutes = deltaInSeconds / 60; - if (minutes == 1) return formats[A_MINUTE_AGO].format(null); - return formats[N_MINUTES_AGO].format(new Object[] { minutes }); - } - - if (deltaInSeconds < 105 * 60) return formats[AN_HOUR_AGO].format(null); - final int hours = (deltaInSeconds + 15 * 60) / ONE_HOUR_IN_SECONDS; - return formats[N_HOURS_AGO].format(new Object[] { hours }); - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/APIEditorActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/APIEditorActivity.java index 97f215f4b..3b66c7915 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/APIEditorActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/APIEditorActivity.java @@ -37,13 +37,11 @@ import android.widget.Toast; import org.mariotaku.twidere.R; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; -import org.mariotaku.twidere.api.twitter.TwitterConstants; - import static org.mariotaku.twidere.util.ParseUtils.parseString; import static org.mariotaku.twidere.util.Utils.getNonEmptyString; import static org.mariotaku.twidere.util.Utils.trim; -public class APIEditorActivity extends BaseSupportDialogActivity implements TwitterConstants, OnCheckedChangeListener, +public class APIEditorActivity extends BaseSupportDialogActivity implements OnCheckedChangeListener, OnClickListener, CompoundButton.OnCheckedChangeListener { private EditText mEditAPIUrlFormat; @@ -150,7 +148,7 @@ public class APIEditorActivity extends BaseSupportDialogActivity implements Twit String consumerKey, consumerSecret; final SharedPreferences pref = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); - final String prefApiUrlFormat = getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_REST_BASE_URL); + final String prefApiUrlFormat = getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_TWITTER_API_URL_FORMAT); final int prefAuthType = pref.getInt(KEY_AUTH_TYPE, Accounts.AUTH_TYPE_OAUTH); final boolean prefSameOAuthSigningUrl = pref.getBoolean(KEY_SAME_OAUTH_SIGNING_URL, false); final boolean prefNoVersionSuffix = pref.getBoolean(KEY_NO_VERSION_SUFFIX, false); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/BrowserSignInActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/BrowserSignInActivity.java index 8b11f2588..d9b4221be 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/BrowserSignInActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/BrowserSignInActivity.java @@ -49,6 +49,7 @@ import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; import org.mariotaku.twidere.util.AsyncTaskUtils; import org.mariotaku.twidere.util.OAuthPasswordAuthenticator; import org.mariotaku.twidere.util.TwitterAPIUtils; +import org.mariotaku.twidere.util.Utils; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; @@ -61,7 +62,7 @@ import static android.text.TextUtils.isEmpty; import static org.mariotaku.twidere.util.Utils.getNonEmptyString; @SuppressLint("SetJavaScriptEnabled") -public class BrowserSignInActivity extends BaseSupportDialogActivity implements TwitterConstants { +public class BrowserSignInActivity extends BaseSupportDialogActivity { private static final String INJECT_CONTENT = "javascript:window.injector.processHTML(''+document.getElementsByTagName('html')[0].innerHTML+'');"; @@ -239,7 +240,7 @@ public class BrowserSignInActivity extends BaseSupportDialogActivity implements consumerSecret = defConsumerSecret; } try { - final Endpoint endpoint = new Endpoint(DEFAULT_OAUTH_BASE_URL); + final Endpoint endpoint = new Endpoint(Utils.getApiUrl(DEFAULT_TWITTER_API_URL_FORMAT, "api", "oauth")); final Authorization auth = new OAuthAuthorization(consumerKey, consumerSecret); final TwitterOAuth twitter = TwitterAPIUtils.getInstance(mActivity, endpoint, auth, TwitterOAuth.class); return twitter.getRequestToken(OAUTH_CALLBACK_OOB); diff --git a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java index 3b4adea45..183f6437a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java +++ b/twidere/src/main/java/org/mariotaku/twidere/activity/support/SignInActivity.java @@ -65,7 +65,6 @@ import org.mariotaku.simplerestapi.http.Endpoint; import org.mariotaku.twidere.R; import org.mariotaku.twidere.activity.SettingsActivity; import org.mariotaku.twidere.api.twitter.Twitter; -import org.mariotaku.twidere.api.twitter.TwitterConstants; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.TwitterOAuth; import org.mariotaku.twidere.api.twitter.auth.BasicAuthorization; @@ -103,8 +102,7 @@ import static org.mariotaku.twidere.util.Utils.isUserLoggedIn; import static org.mariotaku.twidere.util.Utils.showErrorMessage; import static org.mariotaku.twidere.util.Utils.trim; -public class SignInActivity extends BaseAppCompatActivity implements TwitterConstants, OnClickListener, - TextWatcher { +public class SignInActivity extends BaseAppCompatActivity implements OnClickListener, TextWatcher { private static final String TWITTER_SIGNUP_URL = "https://twitter.com/signup"; private static final String EXTRA_API_LAST_CHANGE = "api_last_change"; diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/DefaultAPIPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/DefaultAPIPreference.java index 785767b8e..777ddbf91 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/DefaultAPIPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/DefaultAPIPreference.java @@ -40,15 +40,13 @@ import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.provider.TwidereDataStore.Accounts; -import org.mariotaku.twidere.api.twitter.TwitterConstants; - import static android.text.TextUtils.isEmpty; import static org.mariotaku.twidere.util.ParseUtils.parseString; import static org.mariotaku.twidere.util.Utils.getNonEmptyString; import static org.mariotaku.twidere.util.Utils.trim; -public class DefaultAPIPreference extends DialogPreference implements Constants, TwitterConstants, - OnCheckedChangeListener, OnClickListener, CompoundButton.OnCheckedChangeListener { +public class DefaultAPIPreference extends DialogPreference implements Constants, OnCheckedChangeListener, + OnClickListener, CompoundButton.OnCheckedChangeListener { private EditText mEditAPIUrlFormat; private CheckBox mEditSameOAuthSigningUrl, mEditNoVersionSuffix; @@ -98,7 +96,7 @@ public class DefaultAPIPreference extends DialogPreference implements Constants, @Override protected void onBindDialogView(@NonNull final View view) { final SharedPreferences pref = getSharedPreferences(); - final String apiUrlFormat = getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_REST_BASE_URL); + final String apiUrlFormat = getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_TWITTER_API_URL_FORMAT); final int authType = pref.getInt(KEY_AUTH_TYPE, Accounts.AUTH_TYPE_OAUTH); final boolean sameOAuthSigningUrl = pref.getBoolean(KEY_SAME_OAUTH_SIGNING_URL, false); final boolean noVersionSuffix = pref.getBoolean(KEY_NO_VERSION_SUFFIX, false); @@ -159,7 +157,7 @@ public class DefaultAPIPreference extends DialogPreference implements Constants, super.onRestoreInstanceState(savedInstanceState.getParcelable(EXTRA_DATA)); final SharedPreferences pref = getSharedPreferences(); - final String prefApiUrlFormat = getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_REST_BASE_URL); + final String prefApiUrlFormat = getNonEmptyString(pref, KEY_API_URL_FORMAT, DEFAULT_TWITTER_API_URL_FORMAT); final int prefAuthType = pref.getInt(KEY_AUTH_TYPE, Accounts.AUTH_TYPE_OAUTH); final boolean prefSameOAuthSigningUrl = pref.getBoolean(KEY_API_URL_FORMAT, false); final String prefConsumerKey = getNonEmptyString(pref, KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY); diff --git a/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java b/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java index 336db92a3..1ece1c0ba 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java +++ b/twidere/src/main/java/org/mariotaku/twidere/service/BackgroundOperationService.java @@ -96,7 +96,7 @@ import org.mariotaku.twidere.api.twitter.model.StatusUpdate; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.model.UserMentionEntity; -import org.mariotaku.twidere.api.twitter.api.TwitterUpload; +import org.mariotaku.twidere.api.twitter.TwitterUpload; import static android.text.TextUtils.isEmpty; import static org.mariotaku.twidere.util.ContentValuesCreator.createMessageDraft; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIUtils.java index 0ff1da9ad..232bcb97c 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/TwitterAPIUtils.java @@ -26,7 +26,7 @@ import org.mariotaku.twidere.TwidereConstants; import org.mariotaku.twidere.api.twitter.Twitter; import org.mariotaku.twidere.api.twitter.TwitterException; import org.mariotaku.twidere.api.twitter.TwitterOAuth; -import org.mariotaku.twidere.api.twitter.api.TwitterUpload; +import org.mariotaku.twidere.api.twitter.TwitterUpload; import org.mariotaku.twidere.api.twitter.auth.BasicAuthorization; import org.mariotaku.twidere.api.twitter.auth.EmptyAuthorization; import org.mariotaku.twidere.api.twitter.auth.OAuthAuthorization; diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java index 8c076c1f5..d663864fe 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -266,7 +266,7 @@ import static org.mariotaku.twidere.util.TwidereLinkify.PATTERN_TWITTER_PROFILE_ import static org.mariotaku.twidere.util.TwidereLinkify.TWITTER_PROFILE_IMAGES_AVAILABLE_SIZES; @SuppressWarnings("unused") -public final class Utils implements Constants, TwitterConstants { +public final class Utils implements Constants { public static final Pattern PATTERN_XML_RESOURCE_IDENTIFIER = Pattern.compile("res/xml/([\\w_]+)\\.xml");