mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-08 07:48:45 +01:00
added option to turn streaming completely
This commit is contained in:
parent
eaf8c81238
commit
956fd8d7ab
@ -43,7 +43,7 @@ public abstract class SimpleUserStreamCallback extends UserStreamCallback {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onDisconnect(final int code, final String reason) {
|
||||
protected boolean onDisconnectNotice(final int code, final String reason) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -205,14 +205,14 @@ public abstract class UserStreamCallback implements RawCallback<MicroBlogExcepti
|
||||
}
|
||||
case Type.DISCONNECTION:
|
||||
TwitterStreamObject.Disconnect disconnect = object.getDisconnect();
|
||||
return onDisconnect(disconnect.getCode(), disconnect.getReason());
|
||||
return onDisconnectNotice(disconnect.getCode(), disconnect.getReason());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean onConnected();
|
||||
|
||||
protected abstract boolean onDisconnect(int code, String reason);
|
||||
protected abstract boolean onDisconnectNotice(int code, String reason);
|
||||
|
||||
protected abstract boolean onException(@NonNull Throwable ex);
|
||||
|
||||
|
@ -257,7 +257,8 @@ class TwidereApplication : Application(), Constants, OnSharedPreferenceChangeLis
|
||||
KEY_NAME_FIRST, KEY_I_WANT_MY_STARS_BACK -> {
|
||||
contentNotificationManager.updatePreferences()
|
||||
}
|
||||
streamingPowerSavingKey.key, streamingNonMeteredNetworkKey.key -> {
|
||||
streamingEnabledKey.key, streamingPowerSavingKey.key,
|
||||
streamingNonMeteredNetworkKey.key -> {
|
||||
val streamingIntent = Intent(this, StreamingService::class.java)
|
||||
if (activityTracker.isHomeActivityLaunched) {
|
||||
startService(streamingIntent)
|
||||
|
@ -69,6 +69,7 @@ val floatingDetailedContentsKey = KBooleanKey("floating_detailed_contents", true
|
||||
val localTrendsWoeIdKey = KIntKey(KEY_LOCAL_TRENDS_WOEID, 1)
|
||||
val phishingLinksWaringKey = KBooleanKey(KEY_PHISHING_LINK_WARNING, true)
|
||||
val multiColumnWidthKey = KStringKey("multi_column_tab_width", "normal")
|
||||
val streamingEnabledKey = KBooleanKey("streaming_enabled", false)
|
||||
val streamingNonMeteredNetworkKey = KBooleanKey("streaming_non_metered_network", true)
|
||||
val streamingPowerSavingKey = KBooleanKey("streaming_power_saving", true)
|
||||
|
||||
|
@ -26,6 +26,7 @@ import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.TwidereConstants.LOGTAG
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.constant.streamingEnabledKey
|
||||
import org.mariotaku.twidere.constant.streamingNonMeteredNetworkKey
|
||||
import org.mariotaku.twidere.constant.streamingPowerSavingKey
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
@ -99,6 +100,9 @@ class StreamingService : BaseService() {
|
||||
* @return True if there're enabled accounts, false if request not met and service should be stopped
|
||||
*/
|
||||
private fun setupStreaming(): Boolean {
|
||||
if (!preferences[streamingEnabledKey]) {
|
||||
return false
|
||||
}
|
||||
if (!activityTracker.isHomeActivityLaunched) {
|
||||
return false
|
||||
}
|
||||
@ -332,6 +336,11 @@ class StreamingService : BaseService() {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDisconnectNotice(code: Int, reason: String?): Boolean {
|
||||
disconnect();
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onUnhandledEvent(obj: TwitterStreamObject, json: String) {
|
||||
DebugLog.d(LOGTAG, msg = "Unhandled event ${obj.determine()} for ${account.key}: $json")
|
||||
}
|
||||
|
@ -15,9 +15,6 @@ import javax.inject.Inject
|
||||
|
||||
abstract class BaseAbstractTask<Params, Result, Callback>(val context: Context) : AbstractTask<Params, Result, Callback>() {
|
||||
|
||||
protected var initialized: Boolean = false
|
||||
private set
|
||||
|
||||
@Inject
|
||||
lateinit var bus: Bus
|
||||
@Inject
|
||||
@ -38,10 +35,11 @@ abstract class BaseAbstractTask<Params, Result, Callback>(val context: Context)
|
||||
lateinit var userColorNameManager: UserColorNameManager
|
||||
|
||||
init {
|
||||
@Suppress("UNCHECKED_CAST", "LeakingThis")
|
||||
GeneralComponentHelper.build(context).inject(this as BaseAbstractTask<Any, Any, Any>)
|
||||
initialized = true
|
||||
injectMembers()
|
||||
}
|
||||
|
||||
|
||||
private fun injectMembers() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
GeneralComponentHelper.build(context).inject(this as BaseAbstractTask<Any, Any, Any>)
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ abstract class GetActivitiesTask(
|
||||
protected abstract val contentUri: Uri
|
||||
|
||||
override fun doLongOperation(param: RefreshTaskParam): List<TwitterListResponse<Activity>> {
|
||||
if (!initialized || param.shouldAbort) return emptyList()
|
||||
if (param.shouldAbort) return emptyList()
|
||||
val accountIds = param.accountKeys
|
||||
val maxIds = param.maxIds
|
||||
val maxSortIds = param.maxSortIds
|
||||
@ -110,7 +110,6 @@ abstract class GetActivitiesTask(
|
||||
}
|
||||
|
||||
override fun afterExecute(handler: ((Boolean) -> Unit)?, result: List<TwitterListResponse<Activity>>) {
|
||||
if (!initialized) return
|
||||
context.contentResolver.notifyChange(contentUri, null)
|
||||
val exception = AsyncTwitterWrapper.getException(result)
|
||||
bus.post(GetActivitiesTaskEvent(contentUri, false, exception))
|
||||
@ -200,7 +199,6 @@ abstract class GetActivitiesTask(
|
||||
|
||||
@UiThread
|
||||
override fun beforeExecute() {
|
||||
if (!initialized) return
|
||||
bus.post(GetActivitiesTaskEvent(contentUri, true, null))
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ abstract class GetStatusesTask(
|
||||
protected abstract val errorInfoKey: String
|
||||
|
||||
override fun doLongOperation(param: RefreshTaskParam): List<TwitterWrapper.StatusListResponse> {
|
||||
if (!initialized || param.shouldAbort) return emptyList()
|
||||
if (param.shouldAbort) return emptyList()
|
||||
val accountKeys = param.accountKeys
|
||||
val maxIds = param.maxIds
|
||||
val sinceIds = param.sinceIds
|
||||
@ -134,7 +134,6 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
|
||||
override fun afterExecute(handler: ((Boolean) -> Unit)?, result: List<TwitterWrapper.StatusListResponse>) {
|
||||
if (!initialized) return
|
||||
context.contentResolver.notifyChange(contentUri, null)
|
||||
val exception = AsyncTwitterWrapper.getException(result)
|
||||
bus.post(GetStatusesTaskEvent(contentUri, false, exception))
|
||||
@ -142,7 +141,6 @@ abstract class GetStatusesTask(
|
||||
}
|
||||
|
||||
override fun beforeExecute() {
|
||||
if (!initialized) return
|
||||
bus.post(GetStatusesTaskEvent(contentUri, true, null))
|
||||
}
|
||||
|
||||
|
@ -804,6 +804,7 @@
|
||||
<string name="preference_title_multi_column_tabs">Multi column tabs</string>
|
||||
<string name="preference_title_portrait">Portrait</string>
|
||||
<string name="preference_title_storage">Storage</string>
|
||||
<string name="preference_title_streaming_enabled">Enable streaming</string>
|
||||
<string name="preference_title_streaming_non_metered_network">Streaming on free network</string>
|
||||
<string name="preference_title_streaming_power_saving">Power saving mode</string>
|
||||
<string name="preference_title_tablet_mode">Tablet mode</string>
|
||||
|
@ -6,6 +6,7 @@
|
||||
android:title="@string/settings_streaming">
|
||||
|
||||
<org.mariotaku.twidere.preference.StreamingAccountsListPreference
|
||||
android:dependency="streaming_enabled"
|
||||
android:key="cat_accounts"
|
||||
android:title="@string/preference_title_accounts"
|
||||
app:switchDefault="false"
|
||||
@ -15,19 +16,26 @@
|
||||
android:key="cat_general"
|
||||
android:title="@string/general">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="streaming_enabled"
|
||||
android:title="@string/preference_title_streaming_enabled"/>
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:dependency="streaming_enabled"
|
||||
android:key="streaming_power_saving"
|
||||
android:summary="@string/preference_summary_streaming_power_saving"
|
||||
android:title="@string/preference_title_streaming_power_saving"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
android:dependency="streaming_enabled"
|
||||
android:key="streaming_non_metered_network"
|
||||
android:summary="@string/preference_summary_streaming_non_metered_network"
|
||||
android:title="@string/preference_title_streaming_non_metered_network"/>
|
||||
|
||||
<Preference
|
||||
android:dependency="streaming_enabled"
|
||||
android:key="background_streaming_hint"
|
||||
android:summary="@string/preference_summary_background_streaming"
|
||||
android:title="@string/preference_title_background_streaming"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user