adding streaming preferences

started to working on #726
This commit is contained in:
Mariotaku Lee 2017-03-11 02:16:23 +08:00
parent 73f3aab3ee
commit 4367242282
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
19 changed files with 370 additions and 323 deletions

View File

@ -134,21 +134,21 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
@JsonField(name = "retweeted_status")
Status retweetedStatus;
@JsonField(name = "quoted_status")
/**
* <code>repost_status</code> is for Fanfou, <code>quoted_status</code> is for twitter
*/
@JsonField(name = {"quoted_status", "repost_status"})
Status quotedStatus;
/**
* <code>repost_status_id</code> is for Fanfou, <code>quoted_status_id_str</code> is for twitter
*/
@JsonField(name = {"quoted_status_id_str", "repost_status_id"})
String quotedStatusId;
@JsonField(name = "is_quote_status")
boolean isQuoteStatus;
@JsonField(name = "quoted_status_id_str")
String quotedStatusId;
@JsonField(name = "repost_status")
Status repostStatus;
@JsonField(name = "repost_status_id")
String repostStatusId;
@JsonField(name = "card")
CardEntity card;
@ -503,7 +503,6 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
", descendentReplyCount=" + descendentReplyCount +
", retweetedStatus=" + retweetedStatus +
", quotedStatus=" + quotedStatus +
", repostStatus=" + repostStatus +
", card=" + card +
", possiblySensitive=" + possiblySensitive +
", attachments=" + Arrays.toString(attachments) +
@ -548,13 +547,10 @@ public class Status extends TwitterResponseObject implements Comparable<Status>,
inReplyToUserId = null;
inReplyToScreenName = null;
}
if (quotedStatus == null && repostStatus != null) {
quotedStatus = repostStatus;
quotedStatusId = repostStatusId;
if (quotedStatus != null) {
isQuoteStatus = true;
// Set repost media to null if identical to original
if (photo != null && photo.equals(repostStatus.photo)) {
if (photo != null && photo.equals(quotedStatus.photo)) {
photo = null;
}
}

View File

@ -9,6 +9,7 @@ import org.junit.runner.RunWith
import org.mariotaku.twidere.model.*
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.util.concurrent.TimeUnit
/**
@ -57,12 +58,25 @@ class DraftExtensionsTest {
Assert.assertEquals(expected.type, actual.type)
val stl = context.contentResolver.openInputStream(Uri.parse(expected.uri))
val str = context.contentResolver.openInputStream(Uri.parse(actual.uri))
// TODO compare streams
// Assert.assertTrue(IOUtils.contentEquals(stl, str))
Assert.assertTrue(stl.contentEquals(str))
stl.close()
str.close()
}
}
}
}
private fun InputStream.contentEquals(that: InputStream): Boolean {
var len1 = 0
var len2 = 0
val buf1 = ByteArray(8192)
val buf2 = ByteArray(8192)
while (len1 != -1 && len2 != -1) {
len1 = this.read(buf1)
len2 = that.read(buf2)
if (!buf1.contentEquals(buf2)) {
return false
}
}
return len1 == len2
}

View File

@ -10,7 +10,6 @@ import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
import org.jetbrains.annotations.NotNull;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.extension.model.AccountDetailsExtensionsKt;
import org.mariotaku.twidere.fragment.InteractionsTimelineFragment;
@ -103,7 +102,7 @@ public class InteractionsTabConfiguration extends TabConfiguration {
private boolean valueBackup;
MentionsOnlyExtraConfiguration(@NotNull String key) {
MentionsOnlyExtraConfiguration(@NonNull String key) {
super(key, new HasOfficialBooleanHolder());
}

View File

@ -1,151 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.preference;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.internal.widget.PreferenceImageView;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceManager;
import android.support.v7.preference.PreferenceViewHolder;
import android.support.v7.widget.SwitchCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
import org.mariotaku.twidere.model.AccountDetails;
import org.mariotaku.twidere.model.util.AccountUtils;
import org.mariotaku.twidere.util.media.MediaPreloader;
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper;
import javax.inject.Inject;
public abstract class AccountsListPreference extends TintedPreferenceCategory implements Constants {
@Nullable
private final String mSwitchKey;
private final boolean mSwitchDefault;
public AccountsListPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AccountsListPreference);
mSwitchKey = a.getString(R.styleable.AccountsListPreference_switchKey);
mSwitchDefault = a.getBoolean(R.styleable.AccountsListPreference_switchDefault, false);
a.recycle();
}
public void setAccountsData(final AccountDetails[] accounts) {
removeAll();
for (final AccountDetails account : accounts) {
final AccountItemPreference preference = new AccountItemPreference(getContext(), account,
mSwitchKey, getSwitchDefault());
setupPreference(preference, account);
addPreference(preference);
}
final Preference preference = new Preference(getContext());
preference.setLayoutResource(R.layout.settings_layout_click_to_config);
addPreference(preference);
}
@Override
protected void onAttachedToHierarchy(@NonNull final PreferenceManager preferenceManager) {
super.onAttachedToHierarchy(preferenceManager);
if (getPreferenceCount() > 0) return;
setAccountsData(AccountUtils.getAllAccountDetails(AccountManager.get(getContext()), true));
}
protected abstract void setupPreference(AccountItemPreference preference, AccountDetails account);
protected boolean getSwitchDefault() {
return mSwitchDefault;
}
public static final class AccountItemPreference extends Preference implements OnSharedPreferenceChangeListener {
private final AccountDetails mAccount;
@Nullable
private final String mSwitchKey;
private final boolean mSwitchDefault;
private final SharedPreferences mSwitchPreference;
@Inject
MediaPreloader mediaPreloader;
public AccountItemPreference(final Context context, final AccountDetails account,
@Nullable final String switchKey, final boolean switchDefault) {
super(context);
GeneralComponentHelper.build(context).inject(this);
final String switchPreferenceName = ACCOUNT_PREFERENCES_NAME_PREFIX + account.key;
mAccount = account;
mSwitchKey = switchKey;
mSwitchDefault = switchDefault;
mSwitchPreference = context.getSharedPreferences(switchPreferenceName, Context.MODE_PRIVATE);
mSwitchPreference.registerOnSharedPreferenceChangeListener(this);
setTitle(mAccount.user.name);
setSummary(String.format("@%s", mAccount.user.screen_name));
setWidgetLayoutResource(R.layout.layout_preference_switch_indicator);
}
@Override
public void onSharedPreferenceChanged(final SharedPreferences preferences, final String key) {
notifyChanged();
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
final View iconView = holder.findViewById(android.R.id.icon);
if (iconView instanceof PreferenceImageView) {
final ImageView imageView = (ImageView) iconView;
final int maxSize = getContext().getResources().getDimensionPixelSize(R.dimen.element_size_normal);
imageView.setMinimumWidth(maxSize);
imageView.setMinimumHeight(maxSize);
imageView.setMaxWidth(maxSize);
imageView.setMaxHeight(maxSize);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
final View titleView = holder.findViewById(android.R.id.title);
if (titleView instanceof TextView) {
((TextView) titleView).setSingleLine(true);
}
final View summaryView = holder.findViewById(android.R.id.summary);
if (summaryView instanceof TextView) {
((TextView) summaryView).setSingleLine(true);
}
final SwitchCompat switchView = (SwitchCompat) holder.findViewById(android.R.id.toggle);
if (mSwitchKey != null) {
switchView.setChecked(mSwitchPreference.getBoolean(mSwitchKey, mSwitchDefault));
switchView.setVisibility(View.VISIBLE);
} else {
switchView.setVisibility(View.GONE);
}
}
}
}

View File

@ -1,46 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.preference;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import org.mariotaku.twidere.fragment.AccountRefreshSettingsFragment;
import org.mariotaku.twidere.model.AccountDetails;
public class AutoRefreshAccountsListPreference extends AccountsListPreference {
public AutoRefreshAccountsListPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void setupPreference(final AccountItemPreference preference, final AccountDetails account) {
preference.setFragment(AccountRefreshSettingsFragment.class.getName());
final Bundle args = preference.getExtras();
args.putParcelable(EXTRA_ACCOUNT, account);
}
@Override
protected boolean getSwitchDefault() {
return getPreferenceManager().getSharedPreferences().getBoolean(KEY_DEFAULT_AUTO_REFRESH, false);
}
}

View File

@ -1,42 +0,0 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2014 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.preference;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import org.mariotaku.twidere.fragment.AccountNotificationSettingsFragment;
import org.mariotaku.twidere.model.AccountDetails;
public class NotificationAccountsListPreference extends AccountsListPreference {
public NotificationAccountsListPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void setupPreference(final AccountItemPreference preference, final AccountDetails account) {
preference.setFragment(AccountNotificationSettingsFragment.class.getName());
final Bundle args = preference.getExtras();
args.putParcelable(EXTRA_ACCOUNT, account);
}
}

View File

@ -50,7 +50,6 @@ import android.view.WindowManager;
import android.widget.FrameLayout;
import org.apache.commons.lang3.ArrayUtils;
import org.jetbrains.annotations.NotNull;
import org.mariotaku.chameleon.ChameleonUtils;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
@ -576,7 +575,7 @@ public class ThemeUtils implements Constants {
}
@StyleRes
public static int getCurrentTheme(@NotNull final Context context, @StyleRes final int lightTheme,
public static int getCurrentTheme(@NonNull final Context context, @StyleRes final int lightTheme,
@StyleRes final int darkTheme) {
if (TwilightManagerAccessor.INSTANCE.isNight(context)) return darkTheme;
return lightTheme;

View File

@ -111,6 +111,33 @@ public class HeaderDrawerLayout extends ViewGroup {
return false;
}
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
mDragHelper.processTouchEvent(event);
return true;
}
@Override
public boolean canScrollVertically(final int direction) {
if (direction > 0) {
return getHeaderTop() > getHeaderTopMaximum();
} else if (direction < 0) {
return getHeaderTop() < getHeaderTopMaximum();
}
return false;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final View child = getChildAt(0);
final int childWidthMeasureSpec = makeChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight());
final int childHeightMeasureSpec = makeChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom());
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
for (int i = 0, j = getChildCount(); i < j; i++) {
@ -136,6 +163,29 @@ public class HeaderDrawerLayout extends ViewGroup {
}
}
@Override
public void computeScroll() {
boolean invalidate = mDragHelper.continueSettling(true);
if (!mTouchDown && mScroller.computeScrollOffset()) {
if (!invalidate) {
offsetHeaderBy(mScroller.getCurrY() - getHeaderTop());
}
invalidate = true;
}
updateViewOffset();
if (invalidate) {
ViewCompat.postInvalidateOnAnimation(this);
}
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (getChildCount() != 1) {
throw new IllegalArgumentException("Add subview by XML is not allowed.");
}
}
public void flingHeader(float velocity) {
if (mTouchDown) {
mScroller.abortAnimation();
@ -158,21 +208,6 @@ public class HeaderDrawerLayout extends ViewGroup {
return mContainer.getTop();
}
@Override
public void computeScroll() {
boolean invalidate = mDragHelper.continueSettling(true);
if (!mTouchDown && mScroller.computeScrollOffset()) {
if (!invalidate) {
offsetHeaderBy(mScroller.getCurrY() - getHeaderTop());
}
invalidate = true;
}
updateViewOffset();
if (invalidate) {
ViewCompat.postInvalidateOnAnimation(this);
}
}
public int getHeaderTopMaximum() {
return mContainer.getHeaderTopMaximum();
}
@ -181,12 +216,6 @@ public class HeaderDrawerLayout extends ViewGroup {
return mContainer.getHeaderTopMinimum();
}
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
mDragHelper.processTouchEvent(event);
return true;
}
public void setDrawerCallback(DrawerCallback callback) {
mDrawerCallback = callback;
}
@ -195,14 +224,6 @@ public class HeaderDrawerLayout extends ViewGroup {
return mDrawerCallback.canScroll(dy);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
if (getChildCount() != 1) {
throw new IllegalArgumentException("Add subview by XML is not allowed.");
}
}
private void cancelTouchCallback() {
mDrawerCallback.cancelTouch();
}
@ -276,17 +297,6 @@ public class HeaderDrawerLayout extends ViewGroup {
mScrollingHeaderByGesture = scrolling;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final View child = getChildAt(0);
final int childWidthMeasureSpec = makeChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight());
final int childHeightMeasureSpec = makeChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom());
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
private boolean shouldLayoutHeaderBottomCallback() {
if (mDragCallback == null || isInEditMode()) return false;
return mDrawerCallback.shouldLayoutHeaderBottom();

View File

@ -209,6 +209,8 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF
ExtensionsListFragment::class.java)
entriesAdapter.addPreference("refresh", R.drawable.ic_action_refresh, getString(R.string.action_refresh),
R.xml.preferences_refresh)
entriesAdapter.addPreference("streaming", R.drawable.ic_action_streaming, getString(R.string.settings_streaming),
R.xml.preferences_streaming)
entriesAdapter.addPreference("notifications", R.drawable.ic_action_notification, getString(R.string.settings_notifications),
R.xml.preferences_notifications)
entriesAdapter.addPreference("network", R.drawable.ic_action_web, getString(R.string.network),
@ -277,7 +279,7 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF
fun addPreference(tag: String, @DrawableRes icon: Int, title: String, cls: Class<out Fragment>,
args: Bundle? = null) {
args: Bundle? = null) {
entries.add(PreferenceEntry(tag, icon, title, 0, cls.name, args))
notifyDataSetChanged()
}

View File

@ -0,0 +1,135 @@
/*
* 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.preference
import android.accounts.AccountManager
import android.content.Context
import android.content.SharedPreferences
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import android.support.v7.internal.widget.PreferenceImageView
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceManager
import android.support.v7.preference.PreferenceViewHolder
import android.support.v7.widget.SwitchCompat
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import org.mariotaku.twidere.R
import org.mariotaku.twidere.TwidereConstants.ACCOUNT_PREFERENCES_NAME_PREFIX
import org.mariotaku.twidere.model.AccountDetails
import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.util.dagger.GeneralComponentHelper
import org.mariotaku.twidere.util.media.MediaPreloader
import javax.inject.Inject
abstract class AccountsListPreference(context: Context, attrs: AttributeSet? = null) : TintedPreferenceCategory(context, attrs) {
private val switchKeyAttr: String?
private val switchDefaultAttr: Boolean
init {
val a = context.obtainStyledAttributes(attrs, R.styleable.AccountsListPreference)
switchKeyAttr = a.getString(R.styleable.AccountsListPreference_switchKey)
switchDefaultAttr = a.getBoolean(R.styleable.AccountsListPreference_switchDefault, false)
a.recycle()
}
fun setAccountsData(accounts: Array<AccountDetails>) {
removeAll()
for (account in accounts) {
val preference = AccountItemPreference(context, account, switchKeyAttr, getSwitchDefault())
setupPreference(preference, account)
addPreference(preference)
}
val preference = Preference(context)
preference.layoutResource = R.layout.settings_layout_click_to_config
addPreference(preference)
}
override final fun onAttachedToHierarchy(preferenceManager: PreferenceManager) {
super.onAttachedToHierarchy(preferenceManager)
if (preferenceCount > 0) return
setAccountsData(AccountUtils.getAllAccountDetails(AccountManager.get(context), true))
}
protected open fun getSwitchDefault(): Boolean {
return switchDefaultAttr
}
protected abstract fun setupPreference(preference: AccountItemPreference, account: AccountDetails)
class AccountItemPreference(
context: Context,
account: AccountDetails,
private val switchKey: String?,
private val switchDefault: Boolean
) : Preference(context), OnSharedPreferenceChangeListener {
private val switchPreference: SharedPreferences
@Inject
internal lateinit var mediaPreloader: MediaPreloader
init {
GeneralComponentHelper.build(context).inject(this)
val switchPreferenceName = ACCOUNT_PREFERENCES_NAME_PREFIX + account.key
switchPreference = context.getSharedPreferences(switchPreferenceName, Context.MODE_PRIVATE)
switchPreference.registerOnSharedPreferenceChangeListener(this)
title = account.user.name
summary = String.format("@%s", account.user.screen_name)
widgetLayoutResource = R.layout.layout_preference_switch_indicator
}
override fun onSharedPreferenceChanged(preferences: SharedPreferences, key: String) {
notifyChanged()
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val iconView = holder.findViewById(android.R.id.icon)
if (iconView is PreferenceImageView) {
val imageView = iconView
val maxSize = context.resources.getDimensionPixelSize(R.dimen.element_size_normal)
imageView.minimumWidth = maxSize
imageView.minimumHeight = maxSize
imageView.maxWidth = maxSize
imageView.maxHeight = maxSize
imageView.scaleType = ImageView.ScaleType.CENTER_CROP
}
val titleView = holder.findViewById(android.R.id.title)
if (titleView is TextView) {
titleView.setSingleLine(true)
}
val summaryView = holder.findViewById(android.R.id.summary)
if (summaryView is TextView) {
summaryView.setSingleLine(true)
}
val switchView = holder.findViewById(android.R.id.toggle) as SwitchCompat
if (switchKey != null) {
switchView.isChecked = switchPreference.getBoolean(switchKey, switchDefault)
switchView.visibility = View.VISIBLE
} else {
switchView.visibility = View.GONE
}
}
}
}

View File

@ -0,0 +1,40 @@
/*
* 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.preference
import android.content.Context
import android.util.AttributeSet
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT
import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_DEFAULT_AUTO_REFRESH
import org.mariotaku.twidere.fragment.AccountRefreshSettingsFragment
import org.mariotaku.twidere.model.AccountDetails
class AutoRefreshAccountsListPreference(context: Context, attrs: AttributeSet? = null) : AccountsListPreference(context, attrs) {
override fun setupPreference(preference: AccountsListPreference.AccountItemPreference, account: AccountDetails) {
preference.fragment = AccountRefreshSettingsFragment::class.java.name
val args = preference.extras
args.putParcelable(EXTRA_ACCOUNT, account)
}
override fun getSwitchDefault(): Boolean {
return preferenceManager.sharedPreferences.getBoolean(KEY_DEFAULT_AUTO_REFRESH, false)
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.preference
import android.content.Context
import android.util.AttributeSet
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT
import org.mariotaku.twidere.fragment.AccountNotificationSettingsFragment
import org.mariotaku.twidere.model.AccountDetails
class NotificationAccountsListPreference(context: Context, attrs: AttributeSet? = null) : AccountsListPreference(context, attrs) {
override fun setupPreference(preference: AccountsListPreference.AccountItemPreference, account: AccountDetails) {
preference.fragment = AccountNotificationSettingsFragment::class.java.name
val args = preference.extras
args.putParcelable(EXTRA_ACCOUNT, account)
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.preference
import android.content.Context
import android.util.AttributeSet
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT
import org.mariotaku.twidere.fragment.AccountNotificationSettingsFragment
import org.mariotaku.twidere.model.AccountDetails
class StreamingAccountsListPreference(context: Context, attrs: AttributeSet? = null) : AccountsListPreference(context, attrs) {
override fun setupPreference(preference: AccountsListPreference.AccountItemPreference, account: AccountDetails) {
preference.fragment = AccountNotificationSettingsFragment::class.java.name
val args = preference.extras
args.putParcelable(EXTRA_ACCOUNT, account)
}
}

View File

@ -54,7 +54,7 @@ abstract class TimelineStreamCallback(val accountId: String) : UserStreamCallbac
return true
}
override fun onFollow(createdAt: Date, source: User, target: User): Boolean {
override final fun onFollow(createdAt: Date, source: User, target: User): Boolean {
if (source.id == accountId) {
friends.add(target.id)
} else if (target.id == accountId) {
@ -64,7 +64,7 @@ abstract class TimelineStreamCallback(val accountId: String) : UserStreamCallbac
return true
}
override fun onFavorite(createdAt: Date, source: User, target: User,
override final fun onFavorite(createdAt: Date, source: User, target: User,
targetObject: Status): Boolean {
if (source.id == accountId) {
// Update my favorite status
@ -76,14 +76,14 @@ abstract class TimelineStreamCallback(val accountId: String) : UserStreamCallbac
return true
}
override fun onUnfollow(createdAt: Date, source: User, followedUser: User): Boolean {
override final fun onUnfollow(createdAt: Date, source: User, followedUser: User): Boolean {
if (source.id == accountId) {
friends.remove(followedUser.id)
}
return true
}
override fun onQuotedTweet(createdAt: Date, source: User, target: User, targetObject: Status): Boolean {
override final fun onQuotedTweet(createdAt: Date, source: User, target: User, targetObject: Status): Boolean {
if (source.id == accountId) {
} else if (target.id == accountId) {
// Dispatch activity
@ -93,7 +93,7 @@ abstract class TimelineStreamCallback(val accountId: String) : UserStreamCallbac
return true
}
override fun onFavoritedRetweet(createdAt: Date, source: User, target: User, targetObject: Status): Boolean {
override final fun onFavoritedRetweet(createdAt: Date, source: User, target: User, targetObject: Status): Boolean {
if (source.id == accountId) {
} else if (target.id == accountId) {
// Dispatch activity
@ -103,7 +103,7 @@ abstract class TimelineStreamCallback(val accountId: String) : UserStreamCallbac
return true
}
override fun onRetweetedRetweet(createdAt: Date, source: User, target: User, targetObject: Status): Boolean {
override final fun onRetweetedRetweet(createdAt: Date, source: User, target: User, targetObject: Status): Boolean {
if (source.id == accountId) {
} else if (target.id == accountId) {
// Dispatch activity
@ -113,7 +113,7 @@ abstract class TimelineStreamCallback(val accountId: String) : UserStreamCallbac
return true
}
override fun onUserListMemberAddition(createdAt: Date, source: User, target: User, targetObject: UserList): Boolean {
override final fun onUserListMemberAddition(createdAt: Date, source: User, target: User, targetObject: UserList): Boolean {
if (source.id == accountId) {
} else if (target.id == accountId) {
// Dispatch activity

View File

@ -55,7 +55,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.mariotaku.twidere.view.ExtendedFrameLayout
<org.mariotaku.twidere.view.ExtendedSwipeRefreshLayout
android:id="@+id/detailsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -66,7 +66,7 @@
android:layout_height="match_parent"
app:hdl_contentLayout="@layout/fragment_content_pages"
app:hdl_headerLayout="@layout/header_user"/>
</org.mariotaku.twidere.view.ExtendedFrameLayout>
</org.mariotaku.twidere.view.ExtendedSwipeRefreshLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"

View File

@ -976,6 +976,7 @@
<string name="settings">Settings</string>
<string name="settings_interface">Interface</string>
<string name="settings_notifications">Notifications</string>
<string name="settings_streaming">Streaming</string>
<string name="settings_refresh">Refresh</string>
<string name="share_format">Share format</string>

View File

@ -25,15 +25,4 @@
android:title="@string/refresh_type_trends"/>
</org.mariotaku.twidere.preference.TintedPreferenceCategory>
<!--<org.mariotaku.twidere.preference.TintedPreferenceCategory-->
<!--android:enabled="false"-->
<!--android:key="cat_streaming"-->
<!--android:title="@string/streaming">-->
<!--<SwitchPreference-->
<!--android:key="enable_streaming"-->
<!--android:title="@string/enable_streaming"/>-->
<!--</org.mariotaku.twidere.preference.TintedPreferenceCategory>-->
</PreferenceScreen>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<!--suppress AndroidElementNotAllowed -->
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:title="@string/settings_streaming">
<org.mariotaku.twidere.preference.StreamingAccountsListPreference
android:key="cat_accounts"
android:title="@string/preference_title_accounts"
app:switchDefault="false"
app:switchKey="streaming"/>
</PreferenceScreen>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 42 (36781) - http://www.bohemiancoding.com/sketch -->
<title>ic_action_streaming-mdpi</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Action-Icons" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="ic_action_streaming-mdpi">
<rect id="Rectangle-2" x="4" y="4" width="24" height="24"></rect>
<path d="M17.873855,14.2816795 L22,5 L10,17.7183205 L14.126145,17.7183205 L10,27 L22,14.2816795 L17.873855,14.2816795 Z" id="Triangle" fill="#FFFFFF"></path>
<path d="M15,3 L17,3 L17,8 L15,8 L15,3 Z M29,15 L29,17 L24,17 L24,15 L29,15 Z M17,29 L15,29 L15,24 L17,24 L17,29 Z M3,17 L3,15 L8,15 L8,17 L3,17 Z" id="Rectangle" fill="#FFFFFF"></path>
<path d="M23.7781746,6.80761184 L25.1923882,8.22182541 L22.363961,11.0502525 L20.9497475,9.63603897 L23.7781746,6.80761184 Z M25.1923882,23.7781746 L23.7781746,25.1923882 L20.9497475,22.363961 L22.363961,20.9497475 L25.1923882,23.7781746 Z M8.22182541,25.1923882 L6.80761184,23.7781746 L9.63603897,20.9497475 L11.0502525,22.363961 L8.22182541,25.1923882 Z M6.80761184,8.22182541 L8.22182541,6.80761184 L11.0502525,9.63603897 L9.63603897,11.0502525 L6.80761184,8.22182541 Z" id="Rectangle-3" fill="#FFFFFF"></path>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB