mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-02 17:56:56 +01:00
stops refresh service completely when no account enabled
This commit is contained in:
parent
cdd3cceb13
commit
5048d92012
@ -25,6 +25,7 @@ import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.twidere.api.twitter.model.CardDataMap;
|
||||
import org.mariotaku.twidere.api.twitter.model.CardEntity;
|
||||
import org.mariotaku.twidere.api.twitter.model.CreateCardData;
|
||||
import org.mariotaku.twidere.api.twitter.model.CreateCardResult;
|
||||
@ -42,6 +43,9 @@ public interface TwitterCaps {
|
||||
@NonNull @Query("twitter:string:response_card_name") String responseCardName)
|
||||
throws TwitterException;
|
||||
|
||||
@GET("/v2/capi/passthrough/1")
|
||||
CardEntity sendPassThrough(@Form CardDataMap data) throws TwitterException;
|
||||
|
||||
@POST("/v2/cards/create.json")
|
||||
CreateCardResult createCard(@Form("card_data") CreateCardData cardData) throws TwitterException;
|
||||
}
|
||||
|
@ -20,14 +20,14 @@
|
||||
package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.Activity;
|
||||
import org.mariotaku.twidere.api.twitter.model.CursorResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.CursorTimestampResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.TimestampResponse;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
@ -38,11 +38,12 @@ public interface PrivateActivityResources extends PrivateResources {
|
||||
@GET("/activity/about_me.json")
|
||||
ResponseList<Activity> getActivitiesAboutMe(@Query Paging paging) throws TwitterException;
|
||||
|
||||
@GET("/activity/about_me/unread.json?cursor=true")
|
||||
CursorResponse getActivitiesAboutMeUnreadCursor() throws TwitterException;
|
||||
@GET("/activity/about_me/unread.json")
|
||||
CursorTimestampResponse getActivitiesAboutMeUnread(@Query("cursor") boolean cursor) throws TwitterException;
|
||||
|
||||
@POST("/activity/about_me/unread.json")
|
||||
CursorTimestampResponse setActivitiesAboutMeUnread(@Query("cursor") long cursor) throws TwitterException;
|
||||
|
||||
@GET("/activity/about_me/unread.json?cursor=false")
|
||||
TimestampResponse getActivitiesAboutMeUnreadTimestamp() throws TwitterException;
|
||||
|
||||
@GET("/activity/by_friends.json")
|
||||
ResponseList<Activity> getActivitiesByFriends(@Query Paging paging) throws TwitterException;
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.twidere.api.twitter.model;
|
||||
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
|
||||
import org.mariotaku.restfu.http.ValueMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/12/30.
|
||||
*/
|
||||
public class CardDataMap implements ValueMap {
|
||||
protected final Map<String, String> map = new LinkedHashMap<>();
|
||||
|
||||
public void putString(String key, String value) {
|
||||
map.put("twitter:string:" + key, value);
|
||||
}
|
||||
|
||||
public void putLong(String key, long value) {
|
||||
map.put("twitter:long:" + key, String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return LoganSquare.serialize(map);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(String key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(String key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] keys() {
|
||||
final Set<String> keySet = map.keySet();
|
||||
return keySet.toArray(new String[keySet.size()]);
|
||||
}
|
||||
}
|
@ -36,9 +36,7 @@ import java.util.Map;
|
||||
* </pre>
|
||||
* Created by mariotaku on 15/12/30.
|
||||
*/
|
||||
public class CreateCardData {
|
||||
|
||||
private final Map<String, String> map = new LinkedHashMap<>();
|
||||
public class CreateCardData extends CardDataMap {
|
||||
|
||||
public CreateCardData(String name) {
|
||||
this(name, "1");
|
||||
@ -49,21 +47,4 @@ public class CreateCardData {
|
||||
map.put("twitter:api:api:endpoint", endpoint);
|
||||
}
|
||||
|
||||
public void putString(String key, String value) {
|
||||
map.put("twitter:string:" + key, value);
|
||||
}
|
||||
|
||||
public void putLong(String key, long value) {
|
||||
map.put("twitter:long:" + key, String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
return LoganSquare.serialize(map);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,9 +26,15 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
* Created by mariotaku on 15/12/30.
|
||||
*/
|
||||
@JsonObject
|
||||
public class CursorResponse {
|
||||
public class CursorTimestampResponse {
|
||||
@JsonField(name = "cursor")
|
||||
long cursor;
|
||||
@JsonField(name = "timestamp")
|
||||
long timestamp;
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public long getCursor() {
|
||||
return cursor;
|
@ -49,9 +49,9 @@ import org.mariotaku.twidere.service.RefreshService;
|
||||
import org.mariotaku.twidere.util.BugReporter;
|
||||
import org.mariotaku.twidere.util.DebugModeUtils;
|
||||
import org.mariotaku.twidere.util.ExternalThemeManager;
|
||||
import org.mariotaku.twidere.util.TwidereMathUtils;
|
||||
import org.mariotaku.twidere.util.StrictModeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereBugReporter;
|
||||
import org.mariotaku.twidere.util.TwidereMathUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.content.TwidereSQLiteOpenHelper;
|
||||
import org.mariotaku.twidere.util.dagger.ApplicationModule;
|
||||
@ -233,6 +233,9 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
case KEY_CONNECTION_TIMEOUT:
|
||||
case KEY_PROXY_HOST:
|
||||
case KEY_PROXY_PORT:
|
||||
case KEY_PROXY_TYPE:
|
||||
case KEY_PROXY_USERNAME:
|
||||
case KEY_PROXY_PASSWORD:
|
||||
reloadConnectivitySettings();
|
||||
break;
|
||||
case KEY_DNS_SERVER:
|
||||
|
@ -19,25 +19,34 @@
|
||||
|
||||
package org.mariotaku.twidere.fragment;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
|
||||
public class AccountRefreshSettingsFragment extends BaseAccountPreferenceFragment {
|
||||
|
||||
@Override
|
||||
protected int getPreferencesResource() {
|
||||
return R.xml.preferences_account_refresh;
|
||||
}
|
||||
@Override
|
||||
protected int getPreferencesResource() {
|
||||
return R.xml.preferences_account_refresh;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getSwitchPreferenceDefault() {
|
||||
return DEFAULT_AUTO_REFRESH;
|
||||
}
|
||||
@Override
|
||||
protected boolean getSwitchPreferenceDefault() {
|
||||
return DEFAULT_AUTO_REFRESH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected String getSwitchPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
@Nullable
|
||||
protected String getSwitchPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (KEY_AUTO_REFRESH.equals(key)) {
|
||||
Utils.startRefreshServiceIfNeeded(getActivity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Created by mariotaku on 15/12/20.
|
||||
*/
|
||||
public class CardPollFragment extends BaseSupportFragment {
|
||||
public class CardPollFragment extends BaseSupportFragment implements View.OnClickListener {
|
||||
|
||||
public static final Pattern PATTERN_POLL_TEXT_ONLY = Pattern.compile("poll([\\d]+)choice_text_only");
|
||||
private TableLayout mPollContainer;
|
||||
@ -74,6 +74,7 @@ public class CardPollFragment extends BaseSupportFragment {
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mVoteButton.setOnClickListener(this);
|
||||
initChoiceView(savedInstanceState);
|
||||
}
|
||||
|
||||
@ -177,6 +178,11 @@ public class CardPollFragment extends BaseSupportFragment {
|
||||
return getArguments().getParcelable(EXTRA_STATUS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
|
||||
private static class PercentDrawable extends Drawable {
|
||||
|
||||
private final Paint mPaint;
|
||||
|
@ -24,7 +24,6 @@ import android.content.SharedPreferences;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
@ -134,8 +133,9 @@ public class AccountPreferences implements Constants {
|
||||
return preferences;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static long[] getAutoRefreshEnabledAccountIds(final Context context, final long[] accountIds) {
|
||||
if (context == null || accountIds == null) return null;
|
||||
if (context == null || accountIds == null) return new long[0];
|
||||
final long[] temp = new long[accountIds.length];
|
||||
int i = 0;
|
||||
for (final long accountId : accountIds) {
|
||||
|
@ -210,7 +210,11 @@ public class RefreshService extends Service implements Constants {
|
||||
registerReceiver(mPowerStateReceiver, batteryFilter);
|
||||
registerReceiver(mScreenStateReceiver, screenFilter);
|
||||
PowerStateReceiver.setServiceReceiverStarted(true);
|
||||
startAutoRefresh();
|
||||
if (hasAutoRefreshAccounts(this)) {
|
||||
startAutoRefresh();
|
||||
} else {
|
||||
stopSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,6 +43,7 @@ import org.mariotaku.restfu.okhttp.OkHttpRestClient;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.api.twitter.Twitter;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterCaps;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterOAuth;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterUpload;
|
||||
@ -192,7 +193,8 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
client.setProxySelector(ProxySelector.getDefault());
|
||||
client.setProxySelector(null);
|
||||
client.setAuthenticator(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,6 +300,9 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
} else if (TwitterUserStream.class.isAssignableFrom(cls)) {
|
||||
domain = "userstream";
|
||||
versionSuffix = noVersionSuffix ? null : "/1.1/";
|
||||
} else if (TwitterCaps.class.isAssignableFrom(cls)) {
|
||||
domain = "caps";
|
||||
versionSuffix = null;
|
||||
} else {
|
||||
throw new TwitterConverter.UnsupportedTypeException(cls);
|
||||
}
|
||||
|
@ -1830,8 +1830,7 @@ public final class Utils implements Constants {
|
||||
|
||||
public static boolean hasAutoRefreshAccounts(final Context context) {
|
||||
final long[] accountIds = getAccountIds(context);
|
||||
final long[] refreshIds = AccountPreferences.getAutoRefreshEnabledAccountIds(context, accountIds);
|
||||
return refreshIds != null && refreshIds.length > 0;
|
||||
return !ArrayUtils.isEmpty(AccountPreferences.getAutoRefreshEnabledAccountIds(context, accountIds));
|
||||
}
|
||||
|
||||
public static boolean hasStaggeredTimeline() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user