From bd0ea16b97fffc8d461418b25c1adc8b36fe496a Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 17 Apr 2017 21:10:14 +0800 Subject: [PATCH] kotlin migration --- build.gradle | 2 +- .../twidere/annotation/TabAccountFlags.java | 35 +++ .../fragment/NetworkDiagnosticsFragment.java | 8 +- .../twidere/model/tab/BooleanHolder.java | 5 +- .../twidere/model/tab/DrawableHolder.java | 26 +- .../twidere/model/tab/StringHolder.java | 4 +- .../twidere/model/tab/TabConfiguration.java | 264 ------------------ .../FavoriteTimelineTabConfiguration.java | 95 ------- .../model/tab/impl/HomeTabConfiguration.java | 101 ------- .../impl/InteractionsTabConfiguration.java | 177 ------------ .../tab/impl/MessagesTabConfiguration.java | 40 --- .../impl/PublicTimelineTabConfiguration.java | 67 ----- .../tab/impl/SearchTabConfiguration.java | 83 ------ .../tab/impl/TrendsTabConfiguration.java | 96 ------- .../UserListTimelineTabConfiguration.java | 71 ----- .../impl/UserTimelineTabConfiguration.java | 71 ----- .../twidere/util/CustomTabUtils.java | 6 +- .../util/KeyboardShortcutsHandler.java | 6 +- .../twidere/util/PermissionsManager.java | 22 +- .../org/mariotaku/twidere/util/Utils.java | 38 ++- .../mariotaku/ktextension/ParcelExtensions.kt | 33 +++ .../activity/AssistLauncherActivity.kt | 18 +- .../twidere/activity/BaseActivity.kt | 2 +- .../twidere/activity/ComposeActivity.kt | 2 +- .../twidere/activity/LinkHandlerActivity.kt | 5 +- .../activity/PremiumDashboardActivity.kt | 4 +- .../activity/UsageStatisticsActivity.kt | 11 +- .../twidere/adapter/BaseArrayAdapter.kt | 3 +- .../adapter/BaseRecyclerViewAdapter.kt | 3 +- .../adapter/ComposeAutoCompleteAdapter.kt | 4 +- .../twidere/adapter/DraftsAdapter.kt | 4 +- .../twidere/adapter/DummyItemAdapter.kt | 4 +- .../adapter/UserAutoCompleteAdapter.kt | 4 +- .../twidere/constant/PreferenceKeys.kt | 17 +- .../fragment/AccountsDashboardFragment.kt | 3 +- .../fragment/AccountsManagerFragment.kt | 7 +- .../fragment/AddStatusFilterDialogFragment.kt | 5 +- .../twidere/fragment/BaseDialogFragment.kt | 3 +- .../twidere/fragment/BaseFragment.kt | 6 +- .../twidere/fragment/CustomTabsFragment.kt | 11 +- .../DeleteUserListMembersDialogFragment.kt | 5 +- .../DestroyFriendshipDialogFragment.kt | 5 +- .../twidere/fragment/GroupFragment.kt | 2 +- .../fragment/HostMappingsListFragment.kt | 5 +- .../fragment/ReportSpamDialogFragment.kt | 5 +- .../twidere/fragment/UserFragment.kt | 6 +- .../twidere/fragment/UserListFragment.kt | 4 +- .../content/RetweetQuoteDialogFragment.kt | 5 +- .../twidere/loader/BaseUserListsLoader.kt | 4 +- .../loader/MicroBlogAPIStatusesLoader.kt | 4 +- .../twidere/model/AccountPreferences.kt | 71 +++-- .../twidere/model/tab/TabConfiguration.kt | 176 ++++++++++++ .../tab/conf/BooleanExtraConfiguration.kt | 10 +- .../tab/conf/StringExtraConfiguration.kt | 7 +- .../conf/TrendsLocationExtraConfiguration.kt | 8 +- .../model/tab/conf/UserExtraConfiguration.kt | 7 +- .../tab/conf/UserListExtraConfiguration.kt | 3 +- .../impl/FavoriteTimelineTabConfiguration.kt | 76 +++++ .../model/tab/impl/HomeTabConfiguration.kt | 86 ++++++ .../tab/impl/InteractionsTabConfiguration.kt | 142 ++++++++++ .../tab/impl/MessagesTabConfiguration.kt | 23 ++ .../impl/PublicTimelineTabConfiguration.kt | 49 ++++ .../model/tab/impl/SearchTabConfiguration.kt | 72 +++++ .../model/tab/impl/TrendsTabConfiguration.kt | 87 ++++++ .../impl/UserListTimelineTabConfiguration.kt | 63 +++++ .../tab/impl/UserTimelineTabConfiguration.kt | 62 ++++ .../twidere/provider/TwidereDataProvider.kt | 12 +- .../twidere/service/BaseIntentService.kt | 4 +- .../mariotaku/twidere/service/BaseService.kt | 3 +- .../service/LengthyOperationsService.kt | 4 +- .../twidere/service/StreamingService.kt | 2 +- .../twidere/task/AddUserListMembersTask.kt | 5 +- .../twidere/task/BaseAbstractTask.kt | 8 +- .../twidere/task/ManagedAsyncTask.kt | 7 +- .../twidere/util/AsyncTwitterWrapper.kt | 13 +- .../twidere/util/HttpClientFactory.kt | 7 +- .../twidere/util/ReadStateManager.kt | 4 +- .../util/StatusAdapterLinkClickHandler.kt | 4 +- .../twidere/util/TaskServiceRunner.kt | 18 +- .../twidere/util/dagger/ApplicationModule.kt | 38 +-- .../twidere/util/dagger/DependencyHolder.kt | 8 +- .../mariotaku/twidere/util/net/TwidereDns.kt | 8 +- .../main/res-localized/values-ar/strings.xml | 2 +- .../main/res-localized/values-ast/strings.xml | 2 +- .../main/res-localized/values-ca/strings.xml | 2 +- .../main/res-localized/values-cs/strings.xml | 2 +- .../main/res-localized/values-da/strings.xml | 2 +- .../main/res-localized/values-de/strings.xml | 2 +- .../main/res-localized/values-es/strings.xml | 2 +- .../main/res-localized/values-fa/strings.xml | 2 +- .../main/res-localized/values-fi/strings.xml | 2 +- .../main/res-localized/values-fr/strings.xml | 2 +- .../main/res-localized/values-gl/strings.xml | 2 +- .../main/res-localized/values-hr/strings.xml | 2 +- .../main/res-localized/values-hu/strings.xml | 2 +- .../main/res-localized/values-in/strings.xml | 2 +- .../main/res-localized/values-it/strings.xml | 2 +- .../main/res-localized/values-iw/strings.xml | 2 +- .../main/res-localized/values-ja/strings.xml | 2 +- .../main/res-localized/values-ko/strings.xml | 2 +- .../main/res-localized/values-ms/strings.xml | 2 +- .../main/res-localized/values-nl/strings.xml | 2 +- .../main/res-localized/values-no/strings.xml | 2 +- .../main/res-localized/values-pl/strings.xml | 2 +- .../main/res-localized/values-pt/strings.xml | 2 +- .../main/res-localized/values-ru/strings.xml | 2 +- .../main/res-localized/values-sv/strings.xml | 2 +- .../main/res-localized/values-te/strings.xml | 2 +- .../main/res-localized/values-th/strings.xml | 2 +- .../main/res-localized/values-tr/strings.xml | 2 +- .../main/res-localized/values-uk/strings.xml | 2 +- .../res-localized/values-zh-rCN/strings.xml | 2 +- .../res-localized/values-zh-rHK/strings.xml | 2 +- .../main/res-localized/values-zh/strings.xml | 2 +- twidere/src/main/res/values/strings.xml | 2 +- 115 files changed, 1270 insertions(+), 1294 deletions(-) create mode 100644 twidere/src/main/java/org/mariotaku/twidere/annotation/TabAccountFlags.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/TabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.java delete mode 100644 twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.java create mode 100644 twidere/src/main/kotlin/org/mariotaku/ktextension/ParcelExtensions.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/TabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.kt create mode 100644 twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.kt diff --git a/build.gradle b/build.gradle index 875416c10..b5860ce15 100644 --- a/build.gradle +++ b/build.gradle @@ -58,7 +58,7 @@ subprojects { MultiValueSwitch : '0.9.8', PickNCrop : '0.9.25', AndroidGIFDrawable : '1.2.6', - KPreferences : '0.9.6', + KPreferences : '0.9.7', Kovenant : '3.3.0', ParcelablePlease : '1.0.2', Chameleon : '0.9.17', diff --git a/twidere/src/main/java/org/mariotaku/twidere/annotation/TabAccountFlags.java b/twidere/src/main/java/org/mariotaku/twidere/annotation/TabAccountFlags.java new file mode 100644 index 000000000..0adc69925 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/annotation/TabAccountFlags.java @@ -0,0 +1,35 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.annotation; + +import android.support.annotation.IntDef; + +/** + * Created by mariotaku on 2017/4/17. + */ +@IntDef(value = {TabAccountFlags.FLAG_HAS_ACCOUNT, TabAccountFlags.FLAG_ACCOUNT_REQUIRED, + TabAccountFlags.FLAG_ACCOUNT_MULTIPLE, TabAccountFlags.FLAG_ACCOUNT_MUTABLE}, flag = true) +public @interface TabAccountFlags { + + int FLAG_HAS_ACCOUNT = 1; + int FLAG_ACCOUNT_REQUIRED = 2; + int FLAG_ACCOUNT_MULTIPLE = 4; + int FLAG_ACCOUNT_MUTABLE = 8; +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java b/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java index 54966f627..8d9a030a6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java +++ b/twidere/src/main/java/org/mariotaku/twidere/fragment/NetworkDiagnosticsFragment.java @@ -4,6 +4,7 @@ import android.accounts.AccountManager; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.Uri; import android.os.AsyncTask; @@ -41,7 +42,6 @@ import org.mariotaku.twidere.model.account.cred.OAuthCredentials; import org.mariotaku.twidere.model.util.AccountUtils; import org.mariotaku.twidere.util.DataStoreUtils; import org.mariotaku.twidere.util.MicroBlogAPIFactory; -import org.mariotaku.twidere.util.SharedPreferencesWrapper; import org.mariotaku.twidere.util.Utils; import org.mariotaku.twidere.util.dagger.DependencyHolder; import org.mariotaku.twidere.util.net.TwidereDns; @@ -151,10 +151,10 @@ public class NetworkDiagnosticsFragment extends BaseFragment { publishProgress(LogText.LINEBREAK, LogText.LINEBREAK); DependencyHolder holder = DependencyHolder.Companion.get(mContext); final Dns dns = holder.getDns(); - final SharedPreferencesWrapper prefs = holder.getPreferences(); + final SharedPreferences prefs = holder.getPreferences(); publishProgress(new LogText("Network preferences"), LogText.LINEBREAK); - publishProgress(new LogText("using_resolver: " + prefs.getBoolean(KEY_BUILTIN_DNS_RESOLVER)), LogText.LINEBREAK); - publishProgress(new LogText("tcp_dns_query: " + prefs.getBoolean(KEY_TCP_DNS_QUERY)), LogText.LINEBREAK); + publishProgress(new LogText("using_resolver: " + prefs.getBoolean(KEY_BUILTIN_DNS_RESOLVER, false)), LogText.LINEBREAK); + publishProgress(new LogText("tcp_dns_query: " + prefs.getBoolean(KEY_TCP_DNS_QUERY, false)), LogText.LINEBREAK); publishProgress(new LogText("dns_server: " + prefs.getString(KEY_DNS_SERVER, null)), LogText.LINEBREAK); publishProgress(LogText.LINEBREAK); publishProgress(new LogText("System DNS servers"), LogText.LINEBREAK); diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/BooleanHolder.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/BooleanHolder.java index 243726a8b..d8251b222 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/BooleanHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/tab/BooleanHolder.java @@ -4,19 +4,22 @@ import android.content.Context; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.BoolRes; +import android.support.annotation.NonNull; /** * Created by mariotaku on 2016/11/28. */ -public abstract class BooleanHolder implements Parcelable { +public abstract class BooleanHolder { public abstract boolean createBoolean(Context context); + @NonNull public static BooleanHolder resource(@BoolRes int resourceId) { return new Resource(resourceId); } + @NonNull public static BooleanHolder constant(boolean value) { return new Constant(value); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/DrawableHolder.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/DrawableHolder.java index d86f2d5eb..28ffff85a 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/DrawableHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/tab/DrawableHolder.java @@ -7,21 +7,20 @@ import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import org.apache.commons.lang3.text.WordUtils; +import org.mariotaku.kpreferences.SharedPreferencesExtensionsKt; import org.mariotaku.twidere.R; +import org.mariotaku.twidere.constant.PreferenceKeysKt; import org.mariotaku.twidere.util.dagger.DependencyHolder; import java.util.ArrayList; import java.util.List; -import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_I_WANT_MY_STARS_BACK; - /** * Created by mariotaku on 2016/11/27. */ public abstract class DrawableHolder { - private String name; @Nullable @@ -148,23 +147,41 @@ public abstract class DrawableHolder { } public static class Builtin extends DrawableHolder { + @NonNull public static final DrawableHolder HOME = new Builtin("home", R.drawable.ic_action_home); + @NonNull public static final DrawableHolder HEART = new Builtin("heart", R.drawable.ic_action_heart); + @NonNull public static final DrawableHolder HASHTAG = new Builtin("hashtag", R.drawable.ic_action_hashtag); + @NonNull public static final DrawableHolder ACCOUNTS = new Builtin("accounts", R.drawable.ic_action_accounts); + @NonNull public static final DrawableHolder LIST = new Builtin("list", R.drawable.ic_action_list); + @NonNull public static final DrawableHolder MENTION = new Builtin("mention", R.drawable.ic_action_at); + @NonNull public static final DrawableHolder NOTIFICATIONS = new Builtin("notifications", R.drawable.ic_action_notification); + @NonNull public static final DrawableHolder GALLERY = new Builtin("gallery", R.drawable.ic_action_gallery); + @NonNull public static final DrawableHolder MESSAGE = new Builtin("message", R.drawable.ic_action_message); + @NonNull public static final DrawableHolder QUOTE = new Builtin("quote", R.drawable.ic_action_quote); + @NonNull public static final DrawableHolder SEARCH = new Builtin("search", R.drawable.ic_action_search); + @NonNull public static final DrawableHolder STAGGERED = new Builtin("staggered", R.drawable.ic_action_view_quilt); + @NonNull public static final DrawableHolder STAR = new Builtin("star", R.drawable.ic_action_star); + @NonNull public static final DrawableHolder TRENDS = new Builtin("trends", R.drawable.ic_action_trends); + @NonNull public static final DrawableHolder TWIDERE = new Builtin("twidere", R.drawable.ic_action_twidere); + @NonNull public static final DrawableHolder TWITTER = new Builtin("twitter", R.drawable.ic_action_twitter); + @NonNull public static final DrawableHolder USER = new Builtin("user", R.drawable.ic_action_user); + @NonNull public static final DrawableHolder FAVORITE = new DrawableHolder() { @NonNull @Override @@ -181,7 +198,8 @@ public abstract class DrawableHolder { @NonNull @Override public Drawable createDrawable(Context context) { - if (DependencyHolder.Companion.get(context).preferences.getBoolean(KEY_I_WANT_MY_STARS_BACK)) { + final DependencyHolder holder = DependencyHolder.Companion.get(context); + if (SharedPreferencesExtensionsKt.get(holder.preferences, PreferenceKeysKt.getIWantMyStarsBackKey())) { return ContextCompat.getDrawable(context, R.drawable.ic_action_star); } return ContextCompat.getDrawable(context, R.drawable.ic_action_heart); diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/StringHolder.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/StringHolder.java index 15cdfa0db..9cc94e226 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/StringHolder.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/tab/StringHolder.java @@ -3,16 +3,18 @@ package org.mariotaku.twidere.model.tab; import android.content.Context; import android.os.Parcel; import android.os.Parcelable; +import android.support.annotation.NonNull; import android.support.annotation.StringRes; /** * Created by mariotaku on 2016/11/28. */ -public abstract class StringHolder implements Parcelable { +public abstract class StringHolder { public abstract String createString(Context context); + @NonNull public static StringHolder resource(@StringRes int resourceId) { return new Resource(resourceId); } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/TabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/TabConfiguration.java deleted file mode 100644 index 189355634..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/TabConfiguration.java +++ /dev/null @@ -1,264 +0,0 @@ -package org.mariotaku.twidere.model.tab; - -import android.content.Context; -import android.content.Intent; -import android.support.annotation.CallSuper; -import android.support.annotation.IntDef; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.v4.app.Fragment; -import android.view.View; -import android.view.ViewGroup; - -import org.mariotaku.twidere.annotation.CustomTabType; -import org.mariotaku.twidere.fragment.CustomTabsFragment.TabEditorDialogFragment; -import org.mariotaku.twidere.model.AccountDetails; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.impl.FavoriteTimelineTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.HomeTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.InteractionsTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.MessagesTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.PublicTimelineTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.SearchTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.TrendsTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.UserListTimelineTabConfiguration; -import org.mariotaku.twidere.model.tab.impl.UserTimelineTabConfiguration; - -import java.util.ArrayList; -import java.util.List; - -import kotlin.Pair; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public abstract class TabConfiguration { - - public static final int FLAG_HAS_ACCOUNT = 0b0001; - public static final int FLAG_ACCOUNT_REQUIRED = 0b0010; - public static final int FLAG_ACCOUNT_MULTIPLE = 0b0100; - public static final int FLAG_ACCOUNT_MUTABLE = 0b1000; - - @NonNull - public abstract StringHolder getName(); - - @NonNull - public abstract DrawableHolder getIcon(); - - @AccountFlags - public abstract int getAccountFlags(); - - @NonNull - public abstract Class getFragmentClass(); - - public boolean isSingleTab() { - return false; - } - - public int getSortPosition() { - return 0; - } - - @Nullable - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return null; - } - - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - return true; - } - - public boolean readExtraConfigurationFrom(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - return false; - } - - public boolean checkAccountAvailability(@NonNull AccountDetails details) { - return true; - } - - @NonNull - public static List> all() { - List> all = new ArrayList<>(); - for (String type : allTypes()) { - all.add(new Pair<>(type, ofType(type))); - } - return all; - } - - @NonNull - public static String[] allTypes() { - return new String[]{ - CustomTabType.HOME_TIMELINE, - CustomTabType.NOTIFICATIONS_TIMELINE, - CustomTabType.TRENDS_SUGGESTIONS, - CustomTabType.DIRECT_MESSAGES, - CustomTabType.FAVORITES, - CustomTabType.USER_TIMELINE, - CustomTabType.SEARCH_STATUSES, - CustomTabType.LIST_TIMELINE, - CustomTabType.PUBLIC_TIMELINE, - }; - } - - @Nullable - public static TabConfiguration ofType(@CustomTabType String type) { - switch (type) { - case CustomTabType.HOME_TIMELINE: - return new HomeTabConfiguration(); - case CustomTabType.NOTIFICATIONS_TIMELINE: - return new InteractionsTabConfiguration(); - case CustomTabType.DIRECT_MESSAGES: - return new MessagesTabConfiguration(); - case CustomTabType.LIST_TIMELINE: - return new UserListTimelineTabConfiguration(); - case CustomTabType.FAVORITES: - return new FavoriteTimelineTabConfiguration(); - case CustomTabType.USER_TIMELINE: - return new UserTimelineTabConfiguration(); - case CustomTabType.TRENDS_SUGGESTIONS: - return new TrendsTabConfiguration(); - case CustomTabType.SEARCH_STATUSES: - return new SearchTabConfiguration(); - case CustomTabType.PUBLIC_TIMELINE: - return new PublicTimelineTabConfiguration(); - } - return null; - } - - @IntDef(value = {FLAG_HAS_ACCOUNT, FLAG_ACCOUNT_REQUIRED, FLAG_ACCOUNT_MULTIPLE, - FLAG_ACCOUNT_MUTABLE}, flag = true) - protected @interface AccountFlags { - - } - - public static abstract class ExtraConfiguration { - private final String key; - private StringHolder title; - @Nullable - private StringHolder summary; - @Nullable - private StringHolder headerTitle; - private int position; - private boolean mutable; - - private Context context; - private View view; - - protected ExtraConfiguration(String key) { - this.key = key; - } - - public String getKey() { - return key; - } - - public StringHolder getTitle() { - return title; - } - - public void setTitle(StringHolder title) { - this.title = title; - } - - @Nullable - public StringHolder getSummary() { - return summary; - } - - public void setSummary(@Nullable StringHolder summary) { - this.summary = summary; - } - - public ExtraConfiguration title(StringHolder title) { - setTitle(title); - return this; - } - - public ExtraConfiguration summary(StringHolder summary) { - setSummary(summary); - return this; - } - - public ExtraConfiguration title(@StringRes int titleRes) { - setTitle(StringHolder.resource(titleRes)); - return this; - } - - public ExtraConfiguration summary(@StringRes int summaryRes) { - setSummary(StringHolder.resource(summaryRes)); - return this; - } - - @Nullable - public StringHolder getHeaderTitle() { - return headerTitle; - } - - public void setHeaderTitle(@Nullable StringHolder headerTitle) { - this.headerTitle = headerTitle; - } - - public ExtraConfiguration headerTitle(@Nullable StringHolder title) { - setHeaderTitle(title); - return this; - } - - public ExtraConfiguration headerTitle(@StringRes int titleRes) { - setHeaderTitle(StringHolder.resource(titleRes)); - return this; - } - - public int getPosition() { - return position; - } - - public void setPosition(int position) { - this.position = position; - } - - public boolean isMutable() { - return mutable; - } - - public void setMutable(boolean mutable) { - this.mutable = mutable; - } - - public ExtraConfiguration mutable(boolean mutable) { - setMutable(mutable); - return this; - } - - @NonNull - public abstract View onCreateView(Context context, ViewGroup parent); - - @CallSuper - public void onCreate(Context context) { - this.context = context; - } - - public final Context getContext() { - return context; - } - - public View getView() { - return view; - } - - @CallSuper - public void onViewCreated(@NonNull Context context, @NonNull View view, @NonNull TabEditorDialogFragment fragment) { - this.view = view; - } - - public void onActivityResult(@NonNull final TabEditorDialogFragment fragment, int requestCode, int resultCode, @Nullable Intent data) { - - } - - public void onAccountSelectionChanged(@Nullable AccountDetails account) { - - } - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.java deleted file mode 100644 index b33c0fd84..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.content.Context; -import android.os.Parcel; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.UserFavoritesFragment; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; -import org.mariotaku.twidere.model.tab.argument.UserArguments; -import org.mariotaku.twidere.model.tab.conf.UserExtraConfiguration; -import org.mariotaku.twidere.util.dagger.DependencyHolder; - -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER; -import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_I_WANT_MY_STARS_BACK; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class FavoriteTimelineTabConfiguration extends TabConfiguration { - final static StringHolder TAB_NAME = new StringHolder() { - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - - } - - @Override - public String createString(Context context) { - if (DependencyHolder.Companion.get(context).preferences.getBoolean(KEY_I_WANT_MY_STARS_BACK)) { - return context.getString(R.string.title_favorites); - } - return context.getString(R.string.title_likes); - } - }; - - @NonNull - @Override - public StringHolder getName() { - return TAB_NAME; - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.FAVORITE; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_REQUIRED; - } - - @Nullable - @Override - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return new ExtraConfiguration[]{ - new UserExtraConfiguration(EXTRA_USER).title(R.string.title_user).headerTitle(R.string.title_user) - }; - } - - @Override - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - UserArguments arguments = (UserArguments) tab.getArguments(); - assert arguments != null; - switch (extraConf.getKey()) { - case EXTRA_USER: { - final ParcelableUser user = ((UserExtraConfiguration) extraConf).getValue(); - if (user == null) return false; - arguments.setUserKey(user.key); - break; - } - } - return true; - } - - @NonNull - @Override - public Class getFragmentClass() { - return UserFavoritesFragment.class; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.java deleted file mode 100644 index a7d5127d7..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.HomeTimelineFragment; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; -import org.mariotaku.twidere.model.tab.conf.BooleanExtraConfiguration; -import org.mariotaku.twidere.model.tab.extra.HomeTabExtras; - -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_HIDE_QUOTES; -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_HIDE_REPLIES; -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_HIDE_RETWEETS; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class HomeTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.title_home); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.HOME; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_MULTIPLE | FLAG_ACCOUNT_MUTABLE; - } - - @Nullable - @Override - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return new ExtraConfiguration[]{ - new BooleanExtraConfiguration(EXTRA_HIDE_RETWEETS, false).title(R.string.hide_retweets).mutable(true), - new BooleanExtraConfiguration(EXTRA_HIDE_QUOTES, false).title(R.string.hide_quotes).mutable(true), - new BooleanExtraConfiguration(EXTRA_HIDE_REPLIES, false).title(R.string.hide_replies).mutable(true), - }; - } - - @Override - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final HomeTabExtras extras = (HomeTabExtras) tab.getExtras(); - assert extras != null; - switch (extraConf.getKey()) { - case EXTRA_HIDE_RETWEETS: { - extras.setHideRetweets(((BooleanExtraConfiguration) extraConf).getValue()); - break; - } - case EXTRA_HIDE_QUOTES: { - extras.setHideQuotes(((BooleanExtraConfiguration) extraConf).getValue()); - break; - } - case EXTRA_HIDE_REPLIES: { - extras.setHideReplies(((BooleanExtraConfiguration) extraConf).getValue()); - break; - } - } - return true; - } - - @Override - public boolean readExtraConfigurationFrom(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final HomeTabExtras extras = (HomeTabExtras) tab.getExtras(); - if (extras == null) return false; - switch (extraConf.getKey()) { - case EXTRA_HIDE_RETWEETS: { - ((BooleanExtraConfiguration) extraConf).setValue(extras.isHideRetweets()); - break; - } - case EXTRA_HIDE_QUOTES: { - ((BooleanExtraConfiguration) extraConf).setValue(extras.isHideQuotes()); - break; - } - case EXTRA_HIDE_REPLIES: { - ((BooleanExtraConfiguration) extraConf).setValue(extras.isHideReplies()); - break; - } - } - return true; - } - - @NonNull - @Override - public Class getFragmentClass() { - return HomeTimelineFragment.class; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.java deleted file mode 100644 index d155eaee2..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.java +++ /dev/null @@ -1,177 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.view.View; -import android.widget.CheckBox; -import android.widget.TextView; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.extension.model.AccountDetailsExtensionsKt; -import org.mariotaku.twidere.fragment.InteractionsTimelineFragment; -import org.mariotaku.twidere.model.AccountDetails; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.BooleanHolder; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; -import org.mariotaku.twidere.model.tab.conf.BooleanExtraConfiguration; -import org.mariotaku.twidere.model.tab.extra.InteractionsTabExtras; -import org.mariotaku.twidere.model.util.AccountUtils; - -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_MENTIONS_ONLY; -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_MY_FOLLOWING_ONLY; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class InteractionsTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.interactions); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.NOTIFICATIONS; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_MULTIPLE | FLAG_ACCOUNT_MUTABLE; - } - - @Nullable - @Override - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return new ExtraConfiguration[]{ - new BooleanExtraConfiguration(EXTRA_MY_FOLLOWING_ONLY, false).title(R.string.following_only).mutable(true), - new MentionsOnlyExtraConfiguration(EXTRA_MENTIONS_ONLY).title(R.string.mentions_only).mutable(true), - }; - } - - @Override - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final InteractionsTabExtras extras = (InteractionsTabExtras) tab.getExtras(); - assert extras != null; - switch (extraConf.getKey()) { - case EXTRA_MY_FOLLOWING_ONLY: { - extras.setMyFollowingOnly(((BooleanExtraConfiguration) extraConf).getValue()); - break; - } - case EXTRA_MENTIONS_ONLY: { - extras.setMentionsOnly(((BooleanExtraConfiguration) extraConf).getValue()); - break; - } - } - return true; - } - - @Override - public boolean readExtraConfigurationFrom(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final InteractionsTabExtras extras = (InteractionsTabExtras) tab.getExtras(); - if (extras == null) return false; - switch (extraConf.getKey()) { - case EXTRA_MY_FOLLOWING_ONLY: { - ((BooleanExtraConfiguration) extraConf).setValue(extras.isMyFollowingOnly()); - break; - } - case EXTRA_MENTIONS_ONLY: { - ((BooleanExtraConfiguration) extraConf).setValue(extras.isMentionsOnly()); - break; - } - } - return true; - } - - @NonNull - @Override - public Class getFragmentClass() { - return InteractionsTimelineFragment.class; - } - - private static class MentionsOnlyExtraConfiguration extends BooleanExtraConfiguration { - - private boolean valueBackup; - - MentionsOnlyExtraConfiguration(@NonNull String key) { - super(key, new HasOfficialBooleanHolder()); - } - - @Override - public void onAccountSelectionChanged(@Nullable AccountDetails account) { - final boolean hasOfficial; - if (account == null || account.dummy) { - hasOfficial = AccountUtils.hasOfficialKeyAccount(getContext()); - } else { - hasOfficial = AccountDetailsExtensionsKt.isOfficial(account, getContext()); - } - ((HasOfficialBooleanHolder) getDefaultValue()).hasOfficial = hasOfficial; - final View view = getView(); - final CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox); - final TextView titleView = (TextView) view.findViewById(android.R.id.title); - final TextView summaryView = (TextView) view.findViewById(android.R.id.summary); - view.setEnabled(hasOfficial); - titleView.setEnabled(hasOfficial); - summaryView.setEnabled(hasOfficial); - checkBox.setEnabled(hasOfficial); - if (hasOfficial) { - checkBox.setChecked(valueBackup); - summaryView.setVisibility(View.GONE); - } else { - valueBackup = checkBox.isChecked(); - checkBox.setChecked(true); - summaryView.setText(R.string.summary_interactions_not_available); - summaryView.setVisibility(View.VISIBLE); - } - } - - @Override - public boolean getValue() { - if (((HasOfficialBooleanHolder) getDefaultValue()).hasOfficial) { - return super.getValue(); - } - return valueBackup; - } - - private static class HasOfficialBooleanHolder extends BooleanHolder implements Parcelable { - - private boolean hasOfficial; - - @Override - public boolean createBoolean(Context context) { - return hasOfficial; - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - } - - public static final Creator CREATOR = new Creator() { - @Override - public HasOfficialBooleanHolder createFromParcel(Parcel in) { - return new HasOfficialBooleanHolder(); - } - - @Override - public HasOfficialBooleanHolder[] newArray(int size) { - return new HasOfficialBooleanHolder[size]; - } - }; - } - } - -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.java deleted file mode 100644 index 183eb0c13..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.message.MessagesEntriesFragment; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class MessagesTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.title_direct_messages); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.MESSAGE; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_MULTIPLE | FLAG_ACCOUNT_MUTABLE; - } - - @NonNull - @Override - public Class getFragmentClass() { - return MessagesEntriesFragment.class; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.java deleted file mode 100644 index 0a9adf6b6..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2017 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.model.tab.impl; - -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.annotation.AccountType; -import org.mariotaku.twidere.fragment.PublicTimelineFragment; -import org.mariotaku.twidere.model.AccountDetails; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class PublicTimelineTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.title_public_timeline); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.QUOTE; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_REQUIRED | FLAG_ACCOUNT_MUTABLE; - } - - @NonNull - @Override - public Class getFragmentClass() { - return PublicTimelineFragment.class; - } - - @Override - public boolean checkAccountAvailability(@NonNull final AccountDetails details) { - return AccountType.FANFOU.equals(details.type) - || AccountType.STATUSNET.equals(details.type); - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.java deleted file mode 100644 index b7843de4c..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.StatusesSearchFragment; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; -import org.mariotaku.twidere.model.tab.argument.TextQueryArguments; -import org.mariotaku.twidere.model.tab.conf.StringExtraConfiguration; - -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_QUERY; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class SearchTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.action_search); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.SEARCH; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_REQUIRED; - } - - @Nullable - @Override - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return new ExtraConfiguration[]{ - new StringExtraConfiguration(EXTRA_QUERY, null).maxLines(1).title(R.string.search_statuses).headerTitle(R.string.query) - }; - } - - @Override - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final TextQueryArguments arguments = (TextQueryArguments) tab.getArguments(); - assert arguments != null; - switch (extraConf.getKey()) { - case EXTRA_QUERY: { - final String query = ((StringExtraConfiguration) extraConf).getValue(); - if (query == null) return false; - arguments.setQuery(query); - break; - } - } - return true; - } - - @Override - public boolean readExtraConfigurationFrom(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final TextQueryArguments arguments = (TextQueryArguments) tab.getArguments(); - if (arguments == null) return false; - switch (extraConf.getKey()) { - case EXTRA_QUERY: { - ((StringExtraConfiguration) extraConf).setValue(arguments.getQuery()); - break; - } - } - return true; - } - - @NonNull - @Override - public Class getFragmentClass() { - return StatusesSearchFragment.class; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.java deleted file mode 100644 index 15400be8f..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.TrendsSuggestionsFragment; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; -import org.mariotaku.twidere.model.tab.conf.TrendsLocationExtraConfiguration; -import org.mariotaku.twidere.model.tab.extra.TrendsTabExtras; - -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_PLACE; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class TrendsTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.trends); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.HASHTAG; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_REQUIRED | FLAG_ACCOUNT_MUTABLE; - } - - @Nullable - @Override - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return new ExtraConfiguration[]{ - new TrendsLocationExtraConfiguration(EXTRA_PLACE).title(R.string.trends_location).mutable(true), - }; - } - - @Override - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final TrendsTabExtras extras = (TrendsTabExtras) tab.getExtras(); - assert extras != null; - switch (extraConf.getKey()) { - case EXTRA_PLACE: { - TrendsLocationExtraConfiguration conf = (TrendsLocationExtraConfiguration) extraConf; - TrendsLocationExtraConfiguration.Place place = conf.getValue(); - if (place != null) { - extras.setWoeId(place.getWoeId()); - extras.setPlaceName(place.getName()); - } else { - extras.setWoeId(0); - extras.setPlaceName(null); - } - break; - } - } - return true; - } - - @Override - public boolean readExtraConfigurationFrom(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - final TrendsTabExtras extras = (TrendsTabExtras) tab.getExtras(); - if (extras == null) return false; - switch (extraConf.getKey()) { - case EXTRA_PLACE: { - final int woeId = extras.getWoeId(); - final String name = extras.getPlaceName(); - if (name != null) { - TrendsLocationExtraConfiguration.Place place = new TrendsLocationExtraConfiguration.Place(woeId, name); - ((TrendsLocationExtraConfiguration) extraConf).setValue(place); - } else { - ((TrendsLocationExtraConfiguration) extraConf).setValue(null); - } - break; - } - } - return true; - } - - @NonNull - @Override - public Class getFragmentClass() { - return TrendsSuggestionsFragment.class; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.java deleted file mode 100644 index 714d2d2bf..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.UserListTimelineFragment; -import org.mariotaku.twidere.model.ParcelableUserList; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; -import org.mariotaku.twidere.model.tab.argument.UserListArguments; -import org.mariotaku.twidere.model.tab.conf.UserListExtraConfiguration; - -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER_LIST; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class UserListTimelineTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.list_timeline); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.LIST; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_REQUIRED; - } - - @Nullable - @Override - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return new ExtraConfiguration[]{ - new UserListExtraConfiguration(EXTRA_USER_LIST).title(R.string.user_list).headerTitle(R.string.user_list) - }; - } - - @Override - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - UserListArguments arguments = (UserListArguments) tab.getArguments(); - assert arguments != null; - switch (extraConf.getKey()) { - case EXTRA_USER_LIST: { - final ParcelableUserList userList = ((UserListExtraConfiguration) extraConf).getValue(); - if (userList == null) return false; - arguments.setListId(userList.id); - break; - } - } - return true; - } - - @NonNull - @Override - public Class getFragmentClass() { - return UserListTimelineFragment.class; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.java b/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.java deleted file mode 100644 index 5032215eb..000000000 --- a/twidere/src/main/java/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.mariotaku.twidere.model.tab.impl; - -import android.content.Context; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; - -import org.mariotaku.twidere.R; -import org.mariotaku.twidere.fragment.UserTimelineFragment; -import org.mariotaku.twidere.model.ParcelableUser; -import org.mariotaku.twidere.model.Tab; -import org.mariotaku.twidere.model.tab.DrawableHolder; -import org.mariotaku.twidere.model.tab.StringHolder; -import org.mariotaku.twidere.model.tab.TabConfiguration; -import org.mariotaku.twidere.model.tab.argument.UserArguments; -import org.mariotaku.twidere.model.tab.conf.UserExtraConfiguration; - -import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER; - -/** - * Created by mariotaku on 2016/11/27. - */ - -public class UserTimelineTabConfiguration extends TabConfiguration { - @NonNull - @Override - public StringHolder getName() { - return StringHolder.resource(R.string.users_statuses); - } - - @NonNull - @Override - public DrawableHolder getIcon() { - return DrawableHolder.Builtin.USER; - } - - @AccountFlags - @Override - public int getAccountFlags() { - return FLAG_HAS_ACCOUNT | FLAG_ACCOUNT_REQUIRED; - } - - @Nullable - @Override - public ExtraConfiguration[] getExtraConfigurations(Context context) { - return new ExtraConfiguration[]{ - new UserExtraConfiguration(EXTRA_USER).title(R.string.title_user).headerTitle(R.string.title_user) - }; - } - - @Override - public boolean applyExtraConfigurationTo(@NonNull Tab tab, @NonNull ExtraConfiguration extraConf) { - UserArguments arguments = (UserArguments) tab.getArguments(); - assert arguments != null; - switch (extraConf.getKey()) { - case EXTRA_USER: { - final ParcelableUser user = ((UserExtraConfiguration) extraConf).getValue(); - if (user == null) return false; - arguments.setUserKey(user.key); - break; - } - } - return true; - } - - @NonNull - @Override - public Class getFragmentClass() { - return UserTimelineFragment.class; - } -} diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java b/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java index 860dfae1e..0c7364beb 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/CustomTabUtils.java @@ -103,7 +103,7 @@ public class CustomTabUtils implements Constants { if (tabExtras != null) { args.putParcelable(EXTRA_EXTRAS, tabExtras); } - final TabConfiguration conf = TabConfiguration.ofType(type); + final TabConfiguration conf = TabConfiguration.Companion.ofType(type); final Class cls = conf != null ? conf.getFragmentClass() : InvalidTabFragment.class; final String tabTypeName = getTabTypeName(context, type); final DrawableHolder icon = DrawableHolder.parse(iconType); @@ -188,7 +188,7 @@ public class CustomTabUtils implements Constants { public static String getTabTypeName(final Context context, @CustomTabType final String type) { if (context == null) return null; - final TabConfiguration conf = TabConfiguration.ofType(type); + final TabConfiguration conf = TabConfiguration.Companion.ofType(type); if (conf == null) return null; return conf.getName().createString(context); } @@ -206,7 +206,7 @@ public class CustomTabUtils implements Constants { } public static boolean isTabTypeValid(@NonNull final String tabType) { - return TabConfiguration.ofType(Tab.getTypeAlias(tabType)) != null; + return TabConfiguration.Companion.ofType(Tab.getTypeAlias(tabType)) != null; } public static boolean hasAccountKey(final Context context, @NonNull final Bundle args, diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/KeyboardShortcutsHandler.java b/twidere/src/main/java/org/mariotaku/twidere/util/KeyboardShortcutsHandler.java index 90e8486a3..e8ec24587 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/KeyboardShortcutsHandler.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/KeyboardShortcutsHandler.java @@ -2,6 +2,7 @@ package org.mariotaku.twidere.util; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.support.annotation.NonNull; @@ -64,11 +65,10 @@ public class KeyboardShortcutsHandler implements KeyboardShortcutConstants { sMetaNameMap.put(KeyEvent.META_SHIFT_ON, "shift"); } - private final SharedPreferencesWrapper mPreferences; + private final SharedPreferences mPreferences; public KeyboardShortcutsHandler(final Context context) { - mPreferences = SharedPreferencesWrapper.getInstance(context, - KEYBOARD_SHORTCUTS_PREFERENCES_NAME, Context.MODE_PRIVATE); + mPreferences = context.getSharedPreferences(KEYBOARD_SHORTCUTS_PREFERENCES_NAME, Context.MODE_PRIVATE); } public String findAction(@NonNull KeyboardShortcutSpec spec) { diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java b/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java index adb4d6063..4ceac7df6 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/PermissionsManager.java @@ -39,19 +39,19 @@ public class PermissionsManager implements Constants { private static final String[] PERMISSIONS_DENIED = {PERMISSION_DENIED}; - private final SharedPreferencesWrapper mPreferences; - private final PackageManager mPackageManager; + private final SharedPreferences preferences; + private final PackageManager packageManager; private final Context mContext; public PermissionsManager(final Context context) { mContext = context; - mPreferences = SharedPreferencesWrapper.getInstance(context, PERMISSION_PREFERENCES_NAME, Context.MODE_PRIVATE); - mPackageManager = context.getPackageManager(); + preferences = context.getSharedPreferences(PERMISSION_PREFERENCES_NAME, Context.MODE_PRIVATE); + packageManager = context.getPackageManager(); } public boolean accept(final String packageName, final String[] permissions) { if (packageName == null || permissions == null) return false; - final SharedPreferences.Editor editor = mPreferences.edit(); + final SharedPreferences.Editor editor = preferences.edit(); editor.putString(packageName, TwidereArrayUtils.toString(permissions, '|', false)); return editor.commit(); } @@ -84,12 +84,12 @@ public class PermissionsManager implements Constants { public boolean checkSignature(final String pname) { if (mContext.getPackageName().equals(pname)) return true; if (BuildConfig.DEBUG) return false; - return mPackageManager.checkSignatures(pname, mContext.getPackageName()) == PackageManager.SIGNATURE_MATCH; + return packageManager.checkSignatures(pname, mContext.getPackageName()) == PackageManager.SIGNATURE_MATCH; } public boolean deny(final String packageName) { if (packageName == null) return false; - final SharedPreferences.Editor editor = mPreferences.edit(); + final SharedPreferences.Editor editor = preferences.edit(); editor.putString(packageName, PERMISSION_DENIED); return editor.commit(); @@ -97,7 +97,7 @@ public class PermissionsManager implements Constants { public Map getAll() { final Map map = new HashMap<>(); - for (final Map.Entry entry : mPreferences.getAll().entrySet()) { + for (final Map.Entry entry : preferences.getAll().entrySet()) { if (entry.getValue() instanceof String) { map.put(entry.getKey(), (String) entry.getValue()); } @@ -106,7 +106,7 @@ public class PermissionsManager implements Constants { } public String getPackageNameByUid(final int uid) { - final String[] pkgs = mPackageManager.getPackagesForUid(uid); + final String[] pkgs = packageManager.getPackagesForUid(uid); if (pkgs != null && pkgs.length > 0) return pkgs[0]; return null; } @@ -117,7 +117,7 @@ public class PermissionsManager implements Constants { public String[] getPermissions(final String packageName) { if (isEmpty(packageName)) return new String[0]; - final String permissionsString = mPreferences.getString(packageName, null); + final String permissionsString = preferences.getString(packageName, null); if (isEmpty(permissionsString)) return new String[0]; if (permissionsString.contains(PERMISSION_DENIED)) return PERMISSIONS_DENIED; return permissionsString.split("\\|"); @@ -125,7 +125,7 @@ public class PermissionsManager implements Constants { public boolean revoke(final String packageName) { if (packageName == null) return false; - final SharedPreferences.Editor editor = mPreferences.edit(); + final SharedPreferences.Editor editor = preferences.edit(); editor.remove(packageName); return editor.commit(); } 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 0df2509be..df19553ce 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/Utils.java @@ -70,6 +70,7 @@ import android.widget.Toast; import org.apache.commons.lang3.ArrayUtils; import org.json.JSONException; +import org.mariotaku.kpreferences.SharedPreferencesExtensionsKt; import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.microblog.library.twitter.model.RateLimitStatus; import org.mariotaku.pickncrop.library.PNCUtils; @@ -78,10 +79,10 @@ import org.mariotaku.sqliteqb.library.Columns; import org.mariotaku.sqliteqb.library.Columns.Column; import org.mariotaku.sqliteqb.library.Expression; import org.mariotaku.sqliteqb.library.Selectable; -import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.R; import org.mariotaku.twidere.annotation.CustomTabType; import org.mariotaku.twidere.annotation.ProfileImageSize; +import org.mariotaku.twidere.constant.PreferenceKeysKt; import org.mariotaku.twidere.model.AccountDetails; import org.mariotaku.twidere.model.ParcelableStatus; import org.mariotaku.twidere.model.ParcelableUserMention; @@ -102,9 +103,35 @@ import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static org.mariotaku.twidere.TwidereConstants.DEFAULT_SHARE_FORMAT; +import static org.mariotaku.twidere.TwidereConstants.FORMAT_PATTERN_TITLE; +import static org.mariotaku.twidere.TwidereConstants.KEY_SHARE_FORMAT; +import static org.mariotaku.twidere.TwidereConstants.KEY_TAB_DISPLAY_OPTION; +import static org.mariotaku.twidere.TwidereConstants.LOGTAG; +import static org.mariotaku.twidere.TwidereConstants.METADATA_KEY_EXTENSION_USE_JSON; +import static org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_USER_KEY; +import static org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME; +import static org.mariotaku.twidere.TwidereConstants.TAB_CODE_DIRECT_MESSAGES; +import static org.mariotaku.twidere.TwidereConstants.TAB_CODE_HOME_TIMELINE; +import static org.mariotaku.twidere.TwidereConstants.TAB_CODE_NOTIFICATIONS_TIMELINE; +import static org.mariotaku.twidere.TwidereConstants.VALUE_TAB_DISPLAY_OPTION_ICON; +import static org.mariotaku.twidere.TwidereConstants.VALUE_TAB_DISPLAY_OPTION_LABEL; +import static org.mariotaku.twidere.constant.CompatibilityConstants.EXTRA_ACCOUNT_ID; +import static org.mariotaku.twidere.constant.CompatibilityConstants.QUERY_PARAM_USER_ID; +import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY; +import static org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEYS; +import static org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_PEBBLE_NOTIFICATION; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.DEFAULT_QUOTE_FORMAT; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.FORMAT_PATTERN_LINK; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.FORMAT_PATTERN_NAME; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.FORMAT_PATTERN_TEXT; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_BANDWIDTH_SAVING_MODE; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_DEFAULT_ACCOUNT_KEY; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_PEBBLE_NOTIFICATIONS; +import static org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_QUOTE_FORMAT; import static org.mariotaku.twidere.util.TwidereLinkify.PATTERN_TWITTER_PROFILE_IMAGES; -public final class Utils implements Constants { +public final class Utils { public static final Pattern PATTERN_XML_RESOURCE_IDENTIFIER = Pattern.compile("res/xml/([\\w_]+)\\.xml"); public static final Pattern PATTERN_RESOURCE_IDENTIFIER = Pattern.compile("@([\\w_]+)/([\\w_]+)"); @@ -855,10 +882,11 @@ public final class Utils implements Constants { || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS; } - public static boolean isMediaPreviewEnabled(Context context, SharedPreferencesWrapper preferences) { - if (!preferences.getBoolean(KEY_MEDIA_PREVIEW)) return false; + public static boolean isMediaPreviewEnabled(Context context, SharedPreferences preferences) { + if (!SharedPreferencesExtensionsKt.get(preferences, PreferenceKeysKt.getMediaPreviewKey())) + return false; final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - return !ConnectivityManagerCompat.isActiveNetworkMetered(cm) || !preferences.getBoolean(KEY_BANDWIDTH_SAVING_MODE); + return !ConnectivityManagerCompat.isActiveNetworkMetered(cm) || !preferences.getBoolean(KEY_BANDWIDTH_SAVING_MODE, false); } /** diff --git a/twidere/src/main/kotlin/org/mariotaku/ktextension/ParcelExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/ktextension/ParcelExtensions.kt new file mode 100644 index 000000000..bade87021 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/ktextension/ParcelExtensions.kt @@ -0,0 +1,33 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.ktextension + +import android.os.Parcel + +private const val byteTrue: Byte = 1 +private const val byteFalse: Byte = 0 + +fun Parcel.readBoolean(): Boolean { + return readByte() == byteTrue +} + +fun Parcel.writeBoolean(bool: Boolean) { + writeByte(if (bool) byteTrue else byteFalse) +} \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AssistLauncherActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AssistLauncherActivity.kt index 8b0d3b0fa..903284f50 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AssistLauncherActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/AssistLauncherActivity.kt @@ -4,26 +4,20 @@ import android.app.Activity import android.content.Context import android.content.Intent import android.os.Bundle -import org.mariotaku.twidere.Constants import org.mariotaku.twidere.TwidereConstants.SHARED_PREFERENCES_NAME import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.SharedPreferenceConstants.* -import org.mariotaku.twidere.util.SharedPreferencesWrapper -class AssistLauncherActivity : Activity(), Constants { +class AssistLauncherActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val prefs = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, - Context.MODE_PRIVATE) + val prefs = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) val composeNowAction = prefs.getString(KEY_COMPOSE_NOW_ACTION, VALUE_COMPOSE_NOW_ACTION_COMPOSE) - val action: String - if (VALUE_COMPOSE_NOW_ACTION_TAKE_PHOTO == composeNowAction) { - action = INTENT_ACTION_COMPOSE_TAKE_PHOTO - } else if (VALUE_COMPOSE_NOW_ACTION_PICK_IMAGE == composeNowAction) { - action = INTENT_ACTION_COMPOSE_PICK_IMAGE - } else { - action = INTENT_ACTION_COMPOSE + val action = when (composeNowAction) { + VALUE_COMPOSE_NOW_ACTION_TAKE_PHOTO -> INTENT_ACTION_COMPOSE_TAKE_PHOTO + VALUE_COMPOSE_NOW_ACTION_PICK_IMAGE -> INTENT_ACTION_COMPOSE_PICK_IMAGE + else -> INTENT_ACTION_COMPOSE } val intent = Intent(action) intent.flags = Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt index 5324a62d7..224cd22e4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/BaseActivity.kt @@ -89,7 +89,7 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity, IThe @Inject lateinit var bus: Bus @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var kPreferences: KPreferences @Inject diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt index 3e1958a53..50b1b800c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt @@ -1567,7 +1567,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } private fun setupEditText() { - val sendByEnter = preferences.getBoolean(KEY_QUICK_SEND) + val sendByEnter = preferences[quickSendKey] EditTextEnterHandler.attach(editText, ComposeEnterListener(this), sendByEnter) editText.addTextChangedListener(object : TextWatcher { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt index dd8bb40e7..1de86f948 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt @@ -67,7 +67,6 @@ import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.analyzer.PurchaseFinished import org.mariotaku.twidere.util.* import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback -import org.mariotaku.twidere.util.Utils.LINK_ID_FILTERS_IMPORT_BLOCKS import org.mariotaku.twidere.util.linkhandler.TwidereLinkMatcher import org.mariotaku.twidere.util.theme.getCurrentThemeResource @@ -356,7 +355,7 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro setTitle(R.string.title_statuses) } LINK_ID_USER_FAVORITES -> { - if (preferences.getBoolean(SharedPreferenceConstants.KEY_I_WANT_MY_STARS_BACK)) { + if (preferences[iWantMyStarsBackKey]) { setTitle(R.string.title_favorites) } else { setTitle(R.string.title_likes) @@ -375,7 +374,7 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro setTitle(R.string.action_twitter_muted_users) } LINK_ID_USER_LIST -> { - setTitle(R.string.user_list) + setTitle(R.string.title_user_list) } LINK_ID_GROUP -> { setTitle(R.string.group) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt index f97285c15..badd2a4df 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/PremiumDashboardActivity.kt @@ -3,6 +3,7 @@ package org.mariotaku.twidere.activity import android.app.Activity import android.content.Context import android.content.Intent +import android.content.SharedPreferences import android.os.Bundle import android.support.v4.app.DialogFragment import android.support.v4.app.NavUtils @@ -28,7 +29,6 @@ import org.mariotaku.twidere.adapter.BaseRecyclerViewAdapter import org.mariotaku.twidere.fragment.ProgressDialogFragment import org.mariotaku.twidere.model.analyzer.PurchaseFinished import org.mariotaku.twidere.util.Analyzer -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.dagger.GeneralComponent import org.mariotaku.twidere.util.premium.ExtraFeaturesService import org.mariotaku.twidere.util.schedule.StatusScheduleProvider @@ -166,7 +166,7 @@ class PremiumDashboardActivity : BaseActivity() { protected lateinit var extraFeaturesService: ExtraFeaturesService @Inject - protected lateinit var preferences: SharedPreferencesWrapper + protected lateinit var preferences: SharedPreferences @Inject protected lateinit var mScheduleProviderFactory: StatusScheduleProvider.Factory diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UsageStatisticsActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UsageStatisticsActivity.kt index 048bacb2f..85119b33f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UsageStatisticsActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UsageStatisticsActivity.kt @@ -21,18 +21,19 @@ package org.mariotaku.twidere.activity import android.os.Bundle import android.support.v4.app.Fragment -import org.mariotaku.twidere.Constants.KEY_USAGE_STATISTICS +import org.mariotaku.kpreferences.contains +import org.mariotaku.kpreferences.get +import org.mariotaku.kpreferences.set import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_RESID +import org.mariotaku.twidere.constant.usageStatisticsKey import org.mariotaku.twidere.fragment.SettingsDetailsFragment class UsageStatisticsActivity : BaseActivity() { override fun onDestroy() { - if (!preferences.contains(KEY_USAGE_STATISTICS)) { - val editor = preferences.edit() - editor.putBoolean(KEY_USAGE_STATISTICS, preferences.getBoolean(KEY_USAGE_STATISTICS)) - editor.apply() + if (isFinishing && usageStatisticsKey !in preferences) { + preferences[usageStatisticsKey] = preferences[usageStatisticsKey] } super.onDestroy() } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseArrayAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseArrayAdapter.kt index f2541d413..26f69c021 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseArrayAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseArrayAdapter.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.adapter import android.content.Context +import android.content.SharedPreferences import android.support.v4.text.BidiFormatter import com.bumptech.glide.RequestManager import org.mariotaku.kpreferences.get @@ -51,7 +52,7 @@ open class BaseArrayAdapter( @Inject lateinit var multiSelectManager: MultiSelectManager @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var permissionsManager: PermissionsManager diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseRecyclerViewAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseRecyclerViewAdapter.kt index 763de34c5..8808819ca 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseRecyclerViewAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/BaseRecyclerViewAdapter.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.adapter import android.content.Context +import android.content.SharedPreferences import android.support.v4.text.BidiFormatter import android.support.v7.widget.RecyclerView import com.bumptech.glide.RequestManager @@ -51,7 +52,7 @@ abstract class BaseRecyclerViewAdapter( @Inject override final lateinit var bidiFormatter: BidiFormatter @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var readStateManager: ReadStateManager @Inject diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ComposeAutoCompleteAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ComposeAutoCompleteAdapter.kt index b8756465d..68f272d0c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ComposeAutoCompleteAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/ComposeAutoCompleteAdapter.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.adapter import android.content.Context +import android.content.SharedPreferences import android.database.Cursor import android.graphics.PorterDuff.Mode import android.support.v4.widget.SimpleCursorAdapter @@ -35,7 +36,6 @@ import org.mariotaku.twidere.extension.loadProfileImage import org.mariotaku.twidere.model.SuggestionItem import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.provider.TwidereDataStore.Suggestions -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.dagger.GeneralComponent import org.mariotaku.twidere.view.ProfileImageView @@ -45,7 +45,7 @@ class ComposeAutoCompleteAdapter(context: Context, val requestManager: RequestMa R.layout.list_item_auto_complete, null, emptyArray(), intArrayOf(), 0) { @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var userColorNameManager: UserColorNameManager diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DraftsAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DraftsAdapter.kt index dd446c8c6..38c117e3d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DraftsAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DraftsAdapter.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.adapter import android.content.Context +import android.content.SharedPreferences import android.database.Cursor import android.support.v4.widget.SimpleCursorAdapter import android.support.v7.widget.RecyclerViewAccessor @@ -30,7 +31,6 @@ import org.mariotaku.kpreferences.get import org.mariotaku.library.objectcursor.ObjectCursor import org.mariotaku.twidere.constant.mediaPreviewStyleKey import org.mariotaku.twidere.model.Draft -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.dagger.GeneralComponent import org.mariotaku.twidere.view.holder.DraftViewHolder import javax.inject.Inject @@ -41,7 +41,7 @@ class DraftsAdapter( ) : SimpleCursorAdapter(context, DraftViewHolder.layoutResource, null, emptyArray(), intArrayOf(), 0) { @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences private val mediaPreviewStyle: Int diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt index 850b665cc..9c07909cf 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/DummyItemAdapter.kt @@ -1,6 +1,7 @@ package org.mariotaku.twidere.adapter import android.content.Context +import android.content.SharedPreferences import android.support.v4.text.BidiFormatter import android.support.v7.widget.RecyclerView import com.bumptech.glide.RequestManager @@ -14,7 +15,6 @@ import org.mariotaku.twidere.constant.* import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.util.getActivityStatus import org.mariotaku.twidere.util.AsyncTwitterWrapper -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.TwidereLinkify import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.dagger.GeneralComponent @@ -32,7 +32,7 @@ class DummyItemAdapter( ) : IStatusesAdapter, IUsersAdapter, IUserListsAdapter { @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject override lateinit var twitterWrapper: AsyncTwitterWrapper @Inject diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/UserAutoCompleteAdapter.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/UserAutoCompleteAdapter.kt index 12630bf51..e136d4c1c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/UserAutoCompleteAdapter.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/adapter/UserAutoCompleteAdapter.kt @@ -21,6 +21,7 @@ package org.mariotaku.twidere.adapter import android.annotation.SuppressLint import android.content.Context +import android.content.SharedPreferences import android.database.Cursor import android.net.Uri import android.support.v4.widget.SimpleCursorAdapter @@ -40,7 +41,6 @@ import org.mariotaku.twidere.extension.loadProfileImage import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.Utils import org.mariotaku.twidere.util.dagger.GeneralComponent @@ -54,7 +54,7 @@ class UserAutoCompleteAdapter( ) : SimpleCursorAdapter(context, R.layout.list_item_auto_complete, null, emptyArray(), intArrayOf(), 0) { @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var userColorNameManager: UserColorNameManager diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt index a3c68a9b2..76924ee64 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt @@ -14,7 +14,6 @@ import org.mariotaku.twidere.TwidereConstants.KEY_MEDIA_PRELOAD import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.annotation.ImageShapeStyle import org.mariotaku.twidere.annotation.PreviewStyle -import org.mariotaku.twidere.constant.SharedPreferenceConstants.* import org.mariotaku.twidere.extension.getNonEmptyString import org.mariotaku.twidere.model.CustomAPIConfig import org.mariotaku.twidere.model.UserKey @@ -76,6 +75,22 @@ 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) +val quickSendKey = KBooleanKey(KEY_QUICK_SEND, false) +val refreshAfterTweetKey = KBooleanKey(KEY_REFRESH_AFTER_TWEET, false) +val homeRefreshMentionsKey = KBooleanKey(KEY_HOME_REFRESH_MENTIONS, true) +val homeRefreshDirectMessagesKey = KBooleanKey(KEY_HOME_REFRESH_DIRECT_MESSAGES, true) +val homeRefreshSavedSearchesKey = KBooleanKey(KEY_HOME_REFRESH_SAVED_SEARCHES, true) + +object cacheSizeLimitKey : KSimpleKey(KEY_CACHE_SIZE_LIMIT, 300) { + override fun read(preferences: SharedPreferences) = preferences.getInt(key, def).coerceIn(100, + 500) + + override fun write(editor: SharedPreferences.Editor, value: Int): Boolean { + editor.putInt(key, value) + return true + } + +} object overrideLanguageKey : KSimpleKey("override_language", null) { override fun read(preferences: SharedPreferences): Locale? { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt index 34921d809..a496c74c9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsDashboardFragment.kt @@ -74,6 +74,7 @@ import org.mariotaku.twidere.annotation.ProfileImageSize import org.mariotaku.twidere.annotation.Referral import org.mariotaku.twidere.constant.KeyboardShortcutConstants.* import org.mariotaku.twidere.constant.extraFeaturesNoticeVersionKey +import org.mariotaku.twidere.constant.iWantMyStarsBackKey import org.mariotaku.twidere.constant.newDocumentApiKey import org.mariotaku.twidere.constant.profileImageStyleKey import org.mariotaku.twidere.extension.loadProfileBanner @@ -301,7 +302,7 @@ class AccountsDashboardFragment : BaseFragment(), LoaderCallbacks, noAccountContainer.visibility = View.VISIBLE profileContainer.visibility = View.INVISIBLE } - useStarsForLikes = preferences.getBoolean(KEY_I_WANT_MY_STARS_BACK) + useStarsForLikes = preferences[iWantMyStarsBackKey] accountsAdapter.accounts = accounts val defaultKey = preferences.getString(KEY_DEFAULT_ACCOUNT_KEY, null)?.let(UserKey::valueOf) ?: accounts.firstOrNull { it.activated }?.key diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsManagerFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsManagerFragment.kt index c989d931c..45886b753 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsManagerFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AccountsManagerFragment.kt @@ -20,6 +20,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo import com.bumptech.glide.Glide import kotlinx.android.synthetic.main.layout_draggable_list_with_empty_view.* import nl.komponents.kovenant.task +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.Bundle import org.mariotaku.ktextension.set import org.mariotaku.sqliteqb.library.Expression @@ -31,7 +32,7 @@ import org.mariotaku.twidere.activity.ColorPickerDialogActivity import org.mariotaku.twidere.adapter.AccountDetailsAdapter import org.mariotaku.twidere.annotation.Referral import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NEW_DOCUMENT_API +import org.mariotaku.twidere.constant.newDocumentApiKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.extension.model.getAccountKey import org.mariotaku.twidere.extension.model.setActivated @@ -151,8 +152,8 @@ class AccountsManagerFragment : BaseFragment(), LoaderManager.LoaderCallbacks
  • , view: View, position: Int, id: Long) { val account = adapter.getItem(position) - IntentUtils.openUserProfile(context, account.user, preferences.getBoolean(KEY_NEW_DOCUMENT_API), Referral.SELF_PROFILE, - null) + IntentUtils.openUserProfile(context, account.user, preferences[newDocumentApiKey], + Referral.SELF_PROFILE, null) } override fun onCreateLoader(id: Int, args: Bundle?): Loader> { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt index 65c58d7ab..ea23d3794 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AddStatusFilterDialogFragment.kt @@ -25,9 +25,10 @@ import android.os.Bundle import android.support.v4.app.FragmentManager import android.support.v7.app.AlertDialog import com.twitter.Extractor +import org.mariotaku.kpreferences.get import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_STATUS -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.ParcelableUserMention @@ -49,7 +50,7 @@ class AddStatusFilterDialogFragment : BaseDialogFragment() { val builder = AlertDialog.Builder(context) filterItems = filterItemsInfo val entries = arrayOfNulls(filterItems!!.size) - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) + val nameFirst = preferences[nameFirstKey] for (i in 0 until entries.size) { val info = filterItems!![i] when (info.type) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt index 3caaf7a5d..14d870d69 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseDialogFragment.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.fragment import android.content.Context +import android.content.SharedPreferences import android.support.v4.app.DialogFragment import com.squareup.otto.Bus import com.twitter.Validator @@ -37,7 +38,7 @@ open class BaseDialogFragment : DialogFragment() { @Inject lateinit var userColorNameManager: UserColorNameManager @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var kPreferences: KPreferences @Inject diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt index 1ffd34a31..64fd25218 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/BaseFragment.kt @@ -20,12 +20,14 @@ package org.mariotaku.twidere.fragment import android.content.Context +import android.content.SharedPreferences import android.os.Bundle import android.support.v4.app.Fragment import android.support.v4.text.BidiFormatter import com.squareup.otto.Bus import com.twitter.Validator import nl.komponents.kovenant.Promise +import okhttp3.Dns import org.mariotaku.restfu.http.RestHttpClient import org.mariotaku.twidere.fragment.iface.IBaseFragment import org.mariotaku.twidere.model.DefaultFeatures @@ -52,7 +54,7 @@ open class BaseFragment : Fragment(), IBaseFragment { @Inject lateinit var userColorNameManager: UserColorNameManager @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var notificationManager: NotificationManagerWrapper @Inject @@ -73,6 +75,8 @@ open class BaseFragment : Fragment(), IBaseFragment { lateinit var timelineSyncManagerFactory: TimelineSyncManager.Factory @Inject lateinit var restHttpClient: RestHttpClient + @Inject + lateinit var dns: Dns protected val statusScheduleProvider: StatusScheduleProvider? get() = statusScheduleProviderFactory.newInstance(context) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt index 833ec38ca..9eccf99a1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CustomTabsFragment.kt @@ -58,6 +58,7 @@ import org.mariotaku.twidere.activity.SettingsActivity import org.mariotaku.twidere.adapter.AccountsSpinnerAdapter import org.mariotaku.twidere.adapter.ArrayAdapter import org.mariotaku.twidere.annotation.CustomTabType +import org.mariotaku.twidere.annotation.TabAccountFlags import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.model.AccountDetails @@ -142,7 +143,7 @@ class CustomTabsFragment : BaseFragment(), LoaderCallbacks, MultiChoice val subMenu = itemAdd.subMenu subMenu.clear() for ((type, conf) in TabConfiguration.all()) { - val accountRequired = TabConfiguration.FLAG_ACCOUNT_REQUIRED in conf.accountFlags + val accountRequired = TabAccountFlags.FLAG_ACCOUNT_REQUIRED in conf.accountFlags val subItem = subMenu.add(0, 0, conf.sortPosition, conf.name.createString(context)) val disabledByNoAccount = accountRequired && accounts.none(conf::checkAccountAvailability) val disabledByDuplicateTab = conf.isSingleTab && CustomTabUtils.isTabAdded(context, type) @@ -282,11 +283,11 @@ class CustomTabsFragment : BaseFragment(), LoaderCallbacks, MultiChoice val editMode = tag == TAG_EDIT_TAB - val hasAccount = TabConfiguration.FLAG_HAS_ACCOUNT in conf.accountFlags - val accountMutable = TabConfiguration.FLAG_ACCOUNT_MUTABLE in conf.accountFlags + val hasAccount = TabAccountFlags.FLAG_HAS_ACCOUNT in conf.accountFlags + val accountMutable = TabAccountFlags.FLAG_ACCOUNT_MUTABLE in conf.accountFlags if (hasAccount && (accountMutable || !editMode)) { accountContainer.visibility = View.VISIBLE - val accountRequired = TabConfiguration.FLAG_ACCOUNT_REQUIRED in conf.accountFlags + val accountRequired = TabAccountFlags.FLAG_ACCOUNT_REQUIRED in conf.accountFlags accountsAdapter.clear() if (!accountRequired) { accountsAdapter.add(AccountDetails.dummy()) @@ -358,7 +359,7 @@ class CustomTabsFragment : BaseFragment(), LoaderCallbacks, MultiChoice if (tab.extras == null) { tab.extras = CustomTabUtils.newTabExtras(tabType) } - if (hasAccount && (!editMode || TabConfiguration.FLAG_ACCOUNT_MUTABLE in conf.accountFlags)) { + if (hasAccount && (!editMode || TabAccountFlags.FLAG_ACCOUNT_MUTABLE in conf.accountFlags)) { val account = accountSpinner.selectedItem as? AccountDetails ?: return@setOnClickListener if (!account.dummy) { tab.arguments?.accountKeys = arrayOf(account.key) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DeleteUserListMembersDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DeleteUserListMembersDialogFragment.kt index db3b048bd..714588ac4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DeleteUserListMembersDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DeleteUserListMembersDialogFragment.kt @@ -24,11 +24,12 @@ import android.content.DialogInterface import android.os.Bundle import android.support.v4.app.FragmentManager import android.support.v7.app.AlertDialog +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.toTypedArray import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USERS import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER_LIST -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.ParcelableUserList @@ -54,7 +55,7 @@ class DeleteUserListMembersDialogFragment : BaseDialogFragment(), DialogInterfac if (users == null || userList == null) throw NullPointerException() if (users.size == 1) { val user = users[0] - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) + val nameFirst = preferences[nameFirstKey] val displayName = userColorNameManager.getDisplayName(user, nameFirst) builder.setTitle(getString(R.string.delete_user, displayName)) builder.setMessage(getString(R.string.delete_user_from_list_confirm, displayName, userList.name)) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DestroyFriendshipDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DestroyFriendshipDialogFragment.kt index 1b51fc99c..369512062 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DestroyFriendshipDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DestroyFriendshipDialogFragment.kt @@ -24,11 +24,12 @@ import android.content.DialogInterface import android.os.Bundle import android.support.v4.app.FragmentManager import android.support.v7.app.AlertDialog +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.Bundle import org.mariotaku.ktextension.set import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.model.ParcelableUser @@ -46,7 +47,7 @@ class DestroyFriendshipDialogFragment : BaseDialogFragment(), DialogInterface.On override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val builder = AlertDialog.Builder(context) - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) + val nameFirst = preferences[nameFirstKey] val displayName = userColorNameManager.getDisplayName(user, nameFirst) builder.setTitle(getString(R.string.unfollow_user, displayName)) builder.setMessage(getString(R.string.unfollow_user_confirm_message, displayName)) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt index 37768a5d3..1e3cae9cb 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt @@ -71,7 +71,7 @@ class GroupFragment : AbsToolbarTabPagesFragment(), LoaderCallbacks(), AdapterView.OnItemClickListener, MultiChoiceModeListener, OnSharedPreferenceChangeListener { - private lateinit var hostMapping: SharedPreferencesWrapper + private lateinit var hostMapping: SharedPreferences override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) - hostMapping = SharedPreferencesWrapper.getInstance(activity, - Constants.HOST_MAPPING_PREFERENCES_NAME, Context.MODE_PRIVATE) + hostMapping = activity.getSharedPreferences(HOST_MAPPING_PREFERENCES_NAME, Context.MODE_PRIVATE) hostMapping.registerOnSharedPreferenceChangeListener(this) listView.choiceMode = ListView.CHOICE_MODE_MULTIPLE_MODAL listView.setMultiChoiceModeListener(this) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ReportSpamDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ReportSpamDialogFragment.kt index fd11b2809..1e19ade7d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ReportSpamDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ReportSpamDialogFragment.kt @@ -24,9 +24,10 @@ import android.content.DialogInterface import android.os.Bundle import android.support.v4.app.FragmentManager import android.support.v7.app.AlertDialog +import org.mariotaku.kpreferences.get import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.model.ParcelableUser @@ -47,7 +48,7 @@ class ReportSpamDialogFragment : BaseDialogFragment(), DialogInterface.OnClickLi val builder = AlertDialog.Builder(context) val user = user if (user != null) { - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) + val nameFirst = preferences[nameFirstKey] val displayName = userColorNameManager.getDisplayName(user, nameFirst) builder.setTitle(getString(R.string.report_user, displayName)) builder.setMessage(getString(R.string.report_user_confirm_message, displayName)) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt index 8098ae25b..228482f4e 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFragment.kt @@ -654,7 +654,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) val activity = activity - nameFirst = preferences.getBoolean(KEY_NAME_FIRST) + nameFirst = preferences[nameFirstKey] cardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity, preferences[themeBackgroundOptionKey], preferences[themeBackgroundAlphaKey]) actionBarShadowColor = 0xA0000000.toInt() @@ -1136,7 +1136,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, } } TAB_TYPE_FAVORITES -> { - if (preferences.getBoolean(KEY_I_WANT_MY_STARS_BACK)) { + if (preferences[iWantMyStarsBackKey]) { actionBar.subtitle = resources.getQuantityString(R.plurals.N_favorites, user.favorites_count.toInt(), user.favorites_count) } else { @@ -1458,7 +1458,7 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener, position = TAB_POSITION_STATUSES) pagerAdapter.add(cls = UserMediaTimelineFragment::class.java, args = tabArgs, name = getString(R.string.media), type = TAB_TYPE_MEDIA, position = TAB_POSITION_MEDIA) - if (preferences.getBoolean(KEY_I_WANT_MY_STARS_BACK)) { + if (preferences[iWantMyStarsBackKey]) { pagerAdapter.add(cls = UserFavoritesFragment::class.java, args = tabArgs, name = getString(R.string.title_favorites), type = TAB_TYPE_FAVORITES, position = TAB_POSITION_FAVORITES) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt index be6eec38e..cff89bd2b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt @@ -84,7 +84,7 @@ class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener, if (userList != null) { activity.title = userList.name } else { - activity.setTitle(R.string.user_list) + activity.setTitle(R.string.title_user_list) } activity.invalidateOptionsMenu() } @@ -359,7 +359,7 @@ class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener, override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val builder = AlertDialog.Builder(context) builder.setView(R.layout.dialog_user_list_detail_editor) - builder.setTitle(R.string.user_list) + builder.setTitle(R.string.title_user_list) builder.setPositiveButton(android.R.string.ok, this) builder.setNegativeButton(android.R.string.cancel, this) val dialog = builder.create() diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/content/RetweetQuoteDialogFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/content/RetweetQuoteDialogFragment.kt index 6ef1681e1..1f316a93c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/content/RetweetQuoteDialogFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/content/RetweetQuoteDialogFragment.kt @@ -39,6 +39,7 @@ import android.widget.Toast import com.twitter.Validator import nl.komponents.kovenant.Promise import nl.komponents.kovenant.task +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.* import org.mariotaku.library.objectcursor.ObjectCursor import org.mariotaku.microblog.library.MicroBlog @@ -46,7 +47,7 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.activity.content.RetweetQuoteDialogActivity import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_QUICK_SEND +import org.mariotaku.twidere.constant.quickSendKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.extension.model.textLimit @@ -115,7 +116,7 @@ class RetweetQuoteDialogFragment : AbsStatusDialogFragment() { } return false } - }, preferences.getBoolean(KEY_QUICK_SEND)) + }, preferences[quickSendKey]) enterHandler.addTextChangedListener(object : SimpleTextWatcher { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt index fc03566b0..99243108c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt @@ -21,6 +21,7 @@ package org.mariotaku.twidere.loader import android.accounts.AccountManager import android.content.Context +import android.content.SharedPreferences import android.support.v4.content.FixedAsyncTaskLoader import android.util.Log import org.mariotaku.kpreferences.get @@ -39,7 +40,6 @@ import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.ParcelableUserListUtils -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList import org.mariotaku.twidere.util.dagger.GeneralComponent import java.util.* @@ -53,7 +53,7 @@ abstract class BaseUserListsLoader( data: List? ) : FixedAsyncTaskLoader>(context), ICursorSupportLoader { @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences protected val data = NoDuplicatesArrayList() diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt index f90b9552d..86d8d4f0d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MicroBlogAPIStatusesLoader.kt @@ -21,6 +21,7 @@ package org.mariotaku.twidere.loader import android.accounts.AccountManager import android.content.Context +import android.content.SharedPreferences import android.database.sqlite.SQLiteDatabase import android.support.annotation.WorkerThread import org.mariotaku.kpreferences.get @@ -41,7 +42,6 @@ import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.ParcelableStatusUtils import org.mariotaku.twidere.task.twitter.GetStatusesTask import org.mariotaku.twidere.util.DebugLog -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.cache.JsonCache import org.mariotaku.twidere.util.dagger.GeneralComponent @@ -76,7 +76,7 @@ abstract class MicroBlogAPIStatusesLoader( @Inject lateinit var jsonCache: JsonCache @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var userColorNameManager: UserColorNameManager diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/AccountPreferences.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/AccountPreferences.kt index 5a78fb2a0..3cd7f9552 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/AccountPreferences.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/AccountPreferences.kt @@ -21,18 +21,26 @@ package org.mariotaku.twidere.model import android.accounts.AccountManager import android.content.Context +import android.content.SharedPreferences import android.media.RingtoneManager import android.net.Uri import android.support.v4.content.ContextCompat import android.text.TextUtils +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.contains import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.ACCOUNT_PREFERENCES_NAME_PREFIX import org.mariotaku.twidere.constant.SharedPreferenceConstants.* +import org.mariotaku.twidere.constant.defaultAutoRefreshKey import org.mariotaku.twidere.model.util.AccountUtils -class AccountPreferences(private val context: Context, val accountKey: UserKey) { - private val preferences = context.getSharedPreferences("$ACCOUNT_PREFERENCES_NAME_PREFIX$accountKey", Context.MODE_PRIVATE) +class AccountPreferences( + private val context: Context, + private val preferences: SharedPreferences, + val accountKey: UserKey +) { + private val accountPreferences = context.getSharedPreferences( + "$ACCOUNT_PREFERENCES_NAME_PREFIX$accountKey", Context.MODE_PRIVATE) val defaultNotificationLightColor: Int get() { @@ -45,20 +53,24 @@ class AccountPreferences(private val context: Context, val accountKey: UserKey) } val directMessagesNotificationType: Int - get() = preferences.getInt(KEY_NOTIFICATION_TYPE_DIRECT_MESSAGES, DEFAULT_NOTIFICATION_TYPE_DIRECT_MESSAGES) + get() = accountPreferences.getInt(KEY_NOTIFICATION_TYPE_DIRECT_MESSAGES, + DEFAULT_NOTIFICATION_TYPE_DIRECT_MESSAGES) val homeTimelineNotificationType: Int - get() = preferences.getInt(KEY_NOTIFICATION_TYPE_HOME, DEFAULT_NOTIFICATION_TYPE_HOME) + get() = accountPreferences.getInt(KEY_NOTIFICATION_TYPE_HOME, + DEFAULT_NOTIFICATION_TYPE_HOME) val mentionsNotificationType: Int - get() = preferences.getInt(KEY_NOTIFICATION_TYPE_MENTIONS, DEFAULT_NOTIFICATION_TYPE_MENTIONS) + get() = accountPreferences.getInt(KEY_NOTIFICATION_TYPE_MENTIONS, + DEFAULT_NOTIFICATION_TYPE_MENTIONS) val notificationLightColor: Int - get() = preferences.getInt(KEY_NOTIFICATION_LIGHT_COLOR, defaultNotificationLightColor) + get() = accountPreferences.getInt(KEY_NOTIFICATION_LIGHT_COLOR, + defaultNotificationLightColor) val notificationRingtone: Uri get() { - val ringtone = preferences.getString(KEY_NOTIFICATION_RINGTONE, null) + val ringtone = accountPreferences.getString(KEY_NOTIFICATION_RINGTONE, null) if (TextUtils.isEmpty(ringtone)) { return RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) } else { @@ -67,57 +79,66 @@ class AccountPreferences(private val context: Context, val accountKey: UserKey) } val isAutoRefreshEnabled: Boolean - get() = preferences.getBoolean(KEY_AUTO_REFRESH, preferences.getBoolean(KEY_DEFAULT_AUTO_REFRESH, false)) + get() = accountPreferences.getBoolean(KEY_AUTO_REFRESH, preferences[defaultAutoRefreshKey]) val isAutoRefreshHomeTimelineEnabled: Boolean - get() = preferences.getBoolean(KEY_AUTO_REFRESH_HOME_TIMELINE, DEFAULT_AUTO_REFRESH_HOME_TIMELINE) + get() = accountPreferences.getBoolean(KEY_AUTO_REFRESH_HOME_TIMELINE, + DEFAULT_AUTO_REFRESH_HOME_TIMELINE) val isAutoRefreshMentionsEnabled: Boolean - get() = preferences.getBoolean(KEY_AUTO_REFRESH_MENTIONS, DEFAULT_AUTO_REFRESH_MENTIONS) + get() = accountPreferences.getBoolean(KEY_AUTO_REFRESH_MENTIONS, + DEFAULT_AUTO_REFRESH_MENTIONS) val isAutoRefreshDirectMessagesEnabled: Boolean - get() = preferences.getBoolean(KEY_AUTO_REFRESH_DIRECT_MESSAGES, DEFAULT_AUTO_REFRESH_DIRECT_MESSAGES) + get() = accountPreferences.getBoolean(KEY_AUTO_REFRESH_DIRECT_MESSAGES, + DEFAULT_AUTO_REFRESH_DIRECT_MESSAGES) val isAutoRefreshTrendsEnabled: Boolean - get() = preferences.getBoolean(KEY_AUTO_REFRESH_TRENDS, DEFAULT_AUTO_REFRESH_TRENDS) + get() = accountPreferences.getBoolean(KEY_AUTO_REFRESH_TRENDS, DEFAULT_AUTO_REFRESH_TRENDS) val isStreamingEnabled: Boolean - get() = preferences.getBoolean(KEY_ENABLE_STREAMING, false) + get() = accountPreferences.getBoolean(KEY_ENABLE_STREAMING, false) val isStreamHomeTimelineEnabled: Boolean - get() = preferences.getBoolean("stream_home_timeline", true) + get() = accountPreferences.getBoolean("stream_home_timeline", true) val isStreamInteractionsEnabled: Boolean - get() = preferences.getBoolean("stream_interactions", true) + get() = accountPreferences.getBoolean("stream_interactions", true) val isStreamDirectMessagesEnabled: Boolean - get() = preferences.getBoolean("stream_direct_messages", true) + get() = accountPreferences.getBoolean("stream_direct_messages", true) val isStreamNotificationUsersEnabled: Boolean - get() = preferences.getBoolean("stream_notification_users", true) + get() = accountPreferences.getBoolean("stream_notification_users", true) val isDirectMessagesNotificationEnabled: Boolean - get() = preferences.getBoolean(KEY_DIRECT_MESSAGES_NOTIFICATION, DEFAULT_DIRECT_MESSAGES_NOTIFICATION) + get() = accountPreferences.getBoolean(KEY_DIRECT_MESSAGES_NOTIFICATION, + DEFAULT_DIRECT_MESSAGES_NOTIFICATION) val isHomeTimelineNotificationEnabled: Boolean - get() = preferences.getBoolean(KEY_HOME_TIMELINE_NOTIFICATION, DEFAULT_HOME_TIMELINE_NOTIFICATION) + get() = accountPreferences.getBoolean(KEY_HOME_TIMELINE_NOTIFICATION, + DEFAULT_HOME_TIMELINE_NOTIFICATION) val isInteractionsNotificationEnabled: Boolean - get() = preferences.getBoolean(KEY_MENTIONS_NOTIFICATION, DEFAULT_MENTIONS_NOTIFICATION) + get() = accountPreferences.getBoolean(KEY_MENTIONS_NOTIFICATION, + DEFAULT_MENTIONS_NOTIFICATION) val isNotificationFollowingOnly: Boolean - get() = preferences.getBoolean(KEY_NOTIFICATION_FOLLOWING_ONLY, false) + get() = accountPreferences.getBoolean(KEY_NOTIFICATION_FOLLOWING_ONLY, false) val isNotificationMentionsOnly: Boolean - get() = preferences.getBoolean(KEY_NOTIFICATION_MENTIONS_ONLY, false) + get() = accountPreferences.getBoolean(KEY_NOTIFICATION_MENTIONS_ONLY, false) val isNotificationEnabled: Boolean - get() = preferences.getBoolean(KEY_NOTIFICATION, DEFAULT_NOTIFICATION) + get() = accountPreferences.getBoolean(KEY_NOTIFICATION, DEFAULT_NOTIFICATION) companion object { - fun getAccountPreferences(context: Context, accountKeys: Array): Array { - return Array(accountKeys.size) { AccountPreferences(context, accountKeys[it]) } + fun getAccountPreferences(context: Context, preferences: SharedPreferences, + accountKeys: Array): Array { + return Array(accountKeys.size) { + AccountPreferences(context, preferences, accountKeys[it]) + } } fun isNotificationHasLight(flags: Int): Boolean { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/TabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/TabConfiguration.kt new file mode 100644 index 000000000..b5104d7c9 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/TabConfiguration.kt @@ -0,0 +1,176 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab + +import android.content.Context +import android.content.Intent +import android.support.annotation.CallSuper +import android.support.annotation.StringRes +import android.support.v4.app.Fragment +import android.view.View +import android.view.ViewGroup +import org.mariotaku.twidere.annotation.CustomTabType +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.fragment.CustomTabsFragment.TabEditorDialogFragment +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.impl.* + +/** + * Created by mariotaku on 2016/11/27. + */ + +abstract class TabConfiguration { + + abstract val name: StringHolder + + abstract val icon: DrawableHolder + + @get:TabAccountFlags + abstract val accountFlags: Int + + abstract val fragmentClass: Class + + open val isSingleTab: Boolean + get() = false + + open val sortPosition: Int + get() = 0 + + open fun getExtraConfigurations(context: Context): Array? { + return null + } + + open fun applyExtraConfigurationTo(tab: Tab, extraConf: ExtraConfiguration): Boolean { + return true + } + + open fun readExtraConfigurationFrom(tab: Tab, extraConf: ExtraConfiguration): Boolean { + return false + } + + open fun checkAccountAvailability(details: AccountDetails): Boolean { + return true + } + + abstract class ExtraConfiguration { + val key: String + val title: StringHolder + + var summary: StringHolder? = null + var headerTitle: StringHolder? = null + + var position: Int = 0 + var isMutable: Boolean = false + + lateinit var context: Context + private set + + lateinit var view: View + private set + + protected constructor(key: String, title: StringHolder) { + this.key = key + this.title = title + } + + protected constructor(key: String, titleRes: Int) :this(key, StringHolder.resource(titleRes)) + + fun summary(summary: StringHolder): ExtraConfiguration { + this.summary = summary + return this + } + + fun summary(@StringRes summaryRes: Int): ExtraConfiguration { + summary = StringHolder.resource(summaryRes) + return this + } + + fun headerTitle(title: StringHolder?): ExtraConfiguration { + headerTitle = title + return this + } + + fun headerTitle(@StringRes titleRes: Int): ExtraConfiguration { + headerTitle = StringHolder.resource(titleRes) + return this + } + + fun mutable(mutable: Boolean): ExtraConfiguration { + isMutable = mutable + return this + } + + abstract fun onCreateView(context: Context, parent: ViewGroup): View + + @CallSuper + open fun onCreate(context: Context) { + this.context = context + } + + @CallSuper + open fun onViewCreated(context: Context, view: View, fragment: TabEditorDialogFragment) { + this.view = view + } + + open fun onActivityResult(fragment: TabEditorDialogFragment, requestCode: Int, + resultCode: Int, data: Intent?) { + + } + + open fun onAccountSelectionChanged(account: AccountDetails?) { + + } + } + + companion object { + + fun all(): List> { + return allTypes().mapNotNull { + val conf = ofType(it) ?: return@mapNotNull null + return@mapNotNull Pair(it, conf) + } + } + + fun allTypes(): Array { + return arrayOf(CustomTabType.HOME_TIMELINE, CustomTabType.NOTIFICATIONS_TIMELINE, + CustomTabType.TRENDS_SUGGESTIONS, CustomTabType.DIRECT_MESSAGES, + CustomTabType.FAVORITES, CustomTabType.USER_TIMELINE, + CustomTabType.SEARCH_STATUSES, CustomTabType.LIST_TIMELINE, + CustomTabType.PUBLIC_TIMELINE) + } + + fun ofType(@CustomTabType type: String): TabConfiguration? { + when (type) { + CustomTabType.HOME_TIMELINE -> return HomeTabConfiguration() + CustomTabType.NOTIFICATIONS_TIMELINE -> return InteractionsTabConfiguration() + CustomTabType.DIRECT_MESSAGES -> return MessagesTabConfiguration() + CustomTabType.LIST_TIMELINE -> return UserListTimelineTabConfiguration() + CustomTabType.FAVORITES -> return FavoriteTimelineTabConfiguration() + CustomTabType.USER_TIMELINE -> return UserTimelineTabConfiguration() + CustomTabType.TRENDS_SUGGESTIONS -> return TrendsTabConfiguration() + CustomTabType.SEARCH_STATUSES -> return SearchTabConfiguration() + CustomTabType.PUBLIC_TIMELINE -> return PublicTimelineTabConfiguration() + } + return null + } + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/BooleanExtraConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/BooleanExtraConfiguration.kt index 5a0d6cb52..0b120c53d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/BooleanExtraConfiguration.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/BooleanExtraConfiguration.kt @@ -10,6 +10,7 @@ import android.widget.TextView import org.mariotaku.twidere.R import org.mariotaku.twidere.fragment.CustomTabsFragment import org.mariotaku.twidere.model.tab.BooleanHolder +import org.mariotaku.twidere.model.tab.StringHolder import org.mariotaku.twidere.model.tab.TabConfiguration /** @@ -17,8 +18,9 @@ import org.mariotaku.twidere.model.tab.TabConfiguration */ open class BooleanExtraConfiguration( key: String, + title: StringHolder, val defaultValue: BooleanHolder -) : TabConfiguration.ExtraConfiguration(key) { +) : TabConfiguration.ExtraConfiguration(key, title) { open var value: Boolean get() = checkBox.isChecked @@ -28,7 +30,11 @@ open class BooleanExtraConfiguration( private lateinit var checkBox: CheckBox - constructor(key: String, def: Boolean) : this(key, BooleanHolder.constant(def)) + constructor(key: String, title: StringHolder, def: Boolean) : this(key, title, + BooleanHolder.constant(def)) + + constructor(key: String, title: Int, def: Boolean) : this(key, StringHolder.resource(title), + BooleanHolder.constant(def)) override fun onCreateView(context: Context, parent: ViewGroup): View { return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_checkbox, parent, false) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/StringExtraConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/StringExtraConfiguration.kt index 3f45a69d4..f132278c6 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/StringExtraConfiguration.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/StringExtraConfiguration.kt @@ -8,12 +8,14 @@ import android.widget.EditText import org.mariotaku.twidere.R import org.mariotaku.twidere.fragment.CustomTabsFragment +import org.mariotaku.twidere.model.tab.StringHolder import org.mariotaku.twidere.model.tab.TabConfiguration /** * Created by mariotaku on 2016/12/5. */ -class StringExtraConfiguration(key: String, private val def: String?) : TabConfiguration.ExtraConfiguration(key) { +class StringExtraConfiguration(key: String, title: StringHolder, private val def: String?) : + TabConfiguration.ExtraConfiguration(key, title) { var maxLines: Int = 0 var value: String? @@ -22,6 +24,9 @@ class StringExtraConfiguration(key: String, private val def: String?) : TabConfi private lateinit var editText: EditText + constructor(key: String, titleRes: Int, def: String?) : this(key, + StringHolder.resource(titleRes), def) + override fun onCreateView(context: Context, parent: ViewGroup): View { return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_text, parent, false) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/TrendsLocationExtraConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/TrendsLocationExtraConfiguration.kt index 3f00e024d..38a5ec3bb 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/TrendsLocationExtraConfiguration.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/TrendsLocationExtraConfiguration.kt @@ -15,14 +15,16 @@ import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY import org.mariotaku.twidere.constant.IntentConstants.EXTRA_LOCATION import org.mariotaku.twidere.fragment.CustomTabsFragment.TabEditorDialogFragment import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.tab.StringHolder import org.mariotaku.twidere.model.tab.TabConfiguration /** * Created by mariotaku on 2016/12/5. */ open class TrendsLocationExtraConfiguration( - key: String -) : TabConfiguration.ExtraConfiguration(key) { + key: String, + title: StringHolder +) : TabConfiguration.ExtraConfiguration(key, title) { open var value: Place? = null set(value) { @@ -37,6 +39,8 @@ open class TrendsLocationExtraConfiguration( private lateinit var summaryView: TextView + constructor(key: String, titleRes: Int) : this(key, StringHolder.resource(titleRes)) + override fun onCreateView(context: Context, parent: ViewGroup): View { return LayoutInflater.from(context).inflate(R.layout.layout_extra_config_checkbox, parent, false) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserExtraConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserExtraConfiguration.kt index 827592562..21bd08481 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserExtraConfiguration.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserExtraConfiguration.kt @@ -23,7 +23,8 @@ import org.mariotaku.twidere.view.holder.SimpleUserViewHolder * Created by mariotaku on 2016/11/28. */ -class UserExtraConfiguration(key: String) : TabConfiguration.ExtraConfiguration(key) { +class UserExtraConfiguration(key: String) : TabConfiguration.ExtraConfiguration(key, + R.string.title_user) { var value: ParcelableUser? = null private set @@ -61,8 +62,8 @@ class UserExtraConfiguration(key: String) : TabConfiguration.ExtraConfiguration( override fun onActivityResult(fragment: TabEditorDialogFragment, requestCode: Int, resultCode: Int, data: Intent?) { when (requestCode) { 1 -> { - if (resultCode == Activity.RESULT_OK) { - val user: ParcelableUser = data!!.getParcelableExtra(EXTRA_USER) + if (resultCode == Activity.RESULT_OK && data != null) { + val user: ParcelableUser = data.getParcelableExtra(EXTRA_USER) viewHolder.displayUser(user) viewHolder.itemView.visibility = View.VISIBLE hintView.visibility = View.GONE diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserListExtraConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserListExtraConfiguration.kt index f701dd8b3..f614a6261 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserListExtraConfiguration.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/conf/UserListExtraConfiguration.kt @@ -23,7 +23,8 @@ import org.mariotaku.twidere.view.holder.SimpleUserListViewHolder * Created by mariotaku on 2016/11/28. */ -class UserListExtraConfiguration(key: String) : TabConfiguration.ExtraConfiguration(key) { +class UserListExtraConfiguration(key: String) : TabConfiguration.ExtraConfiguration(key, + R.string.title_user_list) { var value: ParcelableUserList? = null private set diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.kt new file mode 100644 index 000000000..7d08243f9 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/FavoriteTimelineTabConfiguration.kt @@ -0,0 +1,76 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import android.content.Context +import org.mariotaku.kpreferences.get +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER +import org.mariotaku.twidere.constant.iWantMyStarsBackKey +import org.mariotaku.twidere.fragment.UserFavoritesFragment +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration +import org.mariotaku.twidere.model.tab.argument.UserArguments +import org.mariotaku.twidere.model.tab.conf.UserExtraConfiguration +import org.mariotaku.twidere.util.dagger.DependencyHolder + +/** + * Created by mariotaku on 2016/11/27. + */ + +class FavoriteTimelineTabConfiguration : TabConfiguration() { + + override val name = FavoriteStringHolder + + override val icon = DrawableHolder.Builtin.FAVORITE + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or + TabAccountFlags.FLAG_ACCOUNT_REQUIRED + + override val fragmentClass = UserFavoritesFragment::class.java + + override fun getExtraConfigurations(context: Context) = arrayOf( + UserExtraConfiguration(EXTRA_USER).headerTitle(R.string.title_user) + ) + + override fun applyExtraConfigurationTo(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val arguments = tab.arguments as UserArguments + when (extraConf.key) { + EXTRA_USER -> { + val user = (extraConf as UserExtraConfiguration).value ?: return false + arguments.setUserKey(user.key) + } + } + return true + } + + object FavoriteStringHolder : StringHolder() { + + override fun createString(context: Context): String { + if (DependencyHolder.get(context).preferences[iWantMyStarsBackKey]) { + return context.getString(R.string.title_favorites) + } + return context.getString(R.string.title_likes) + } + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.kt new file mode 100644 index 000000000..4098ef98b --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/HomeTabConfiguration.kt @@ -0,0 +1,86 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import android.content.Context +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.constant.IntentConstants.* +import org.mariotaku.twidere.fragment.HomeTimelineFragment +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration +import org.mariotaku.twidere.model.tab.conf.BooleanExtraConfiguration +import org.mariotaku.twidere.model.tab.extra.HomeTabExtras + +/** + * Created by mariotaku on 2016/11/27. + */ + +class HomeTabConfiguration : TabConfiguration() { + + override val name = StringHolder.resource(R.string.title_home) + + override val icon = DrawableHolder.Builtin.HOME + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or + TabAccountFlags.FLAG_ACCOUNT_MULTIPLE or TabAccountFlags.FLAG_ACCOUNT_MUTABLE + + override val fragmentClass = HomeTimelineFragment::class.java + + override fun getExtraConfigurations(context: Context) = arrayOf( + BooleanExtraConfiguration(EXTRA_HIDE_RETWEETS, R.string.hide_retweets, false).mutable(true), + BooleanExtraConfiguration(EXTRA_HIDE_QUOTES, R.string.hide_quotes, false).mutable(true), + BooleanExtraConfiguration(EXTRA_HIDE_REPLIES, R.string.hide_replies, false).mutable(true) + ) + + override fun applyExtraConfigurationTo(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val extras = tab.extras as HomeTabExtras + when (extraConf.key) { + EXTRA_HIDE_RETWEETS -> { + extras.isHideRetweets = (extraConf as BooleanExtraConfiguration).value + } + EXTRA_HIDE_QUOTES -> { + extras.isHideQuotes = (extraConf as BooleanExtraConfiguration).value + } + EXTRA_HIDE_REPLIES -> { + extras.isHideReplies = (extraConf as BooleanExtraConfiguration).value + } + } + return true + } + + override fun readExtraConfigurationFrom(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val extras = tab.extras as? HomeTabExtras ?: return false + when (extraConf.key) { + EXTRA_HIDE_RETWEETS -> { + (extraConf as BooleanExtraConfiguration).value = extras.isHideRetweets + } + EXTRA_HIDE_QUOTES -> { + (extraConf as BooleanExtraConfiguration).value = extras.isHideQuotes + } + EXTRA_HIDE_REPLIES -> { + (extraConf as BooleanExtraConfiguration).value = extras.isHideReplies + } + } + return true + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt new file mode 100644 index 000000000..ed699b9d8 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/InteractionsTabConfiguration.kt @@ -0,0 +1,142 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import android.content.Context +import android.view.View +import android.widget.CheckBox +import android.widget.TextView +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_MENTIONS_ONLY +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_MY_FOLLOWING_ONLY +import org.mariotaku.twidere.extension.model.isOfficial +import org.mariotaku.twidere.fragment.InteractionsTimelineFragment +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.BooleanHolder +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration +import org.mariotaku.twidere.model.tab.conf.BooleanExtraConfiguration +import org.mariotaku.twidere.model.tab.extra.InteractionsTabExtras +import org.mariotaku.twidere.model.util.AccountUtils + +/** + * Created by mariotaku on 2016/11/27. + */ + +class InteractionsTabConfiguration : TabConfiguration() { + + override val name = StringHolder.resource(R.string.interactions) + + override val icon = DrawableHolder.Builtin.NOTIFICATIONS + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or + TabAccountFlags.FLAG_ACCOUNT_MULTIPLE or TabAccountFlags.FLAG_ACCOUNT_MUTABLE + + override val fragmentClass = InteractionsTimelineFragment::class.java + + override fun getExtraConfigurations(context: Context) = arrayOf( + BooleanExtraConfiguration(EXTRA_MY_FOLLOWING_ONLY, R.string.following_only, false).mutable(true), + MentionsOnlyExtraConfiguration(EXTRA_MENTIONS_ONLY).mutable(true) + ) + + override fun applyExtraConfigurationTo(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val extras = tab.extras as InteractionsTabExtras + when (extraConf.key) { + EXTRA_MY_FOLLOWING_ONLY -> { + extras.isMyFollowingOnly = (extraConf as BooleanExtraConfiguration).value + } + EXTRA_MENTIONS_ONLY -> { + extras.isMentionsOnly = (extraConf as BooleanExtraConfiguration).value + } + } + return true + } + + override fun readExtraConfigurationFrom(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val extras = tab.extras as? InteractionsTabExtras ?: return false + when (extraConf.key) { + EXTRA_MY_FOLLOWING_ONLY -> { + (extraConf as BooleanExtraConfiguration).value = extras.isMyFollowingOnly + } + EXTRA_MENTIONS_ONLY -> { + (extraConf as BooleanExtraConfiguration).value = extras.isMentionsOnly + } + } + return true + } + + private class MentionsOnlyExtraConfiguration(key: String) : BooleanExtraConfiguration(key, + StringHolder.resource(R.string.mentions_only), + MentionsOnlyExtraConfiguration.HasOfficialBooleanHolder()) { + + private var valueBackup: Boolean = false + + override fun onAccountSelectionChanged(account: AccountDetails?) { + val hasOfficial: Boolean + if (account == null || account.dummy) { + hasOfficial = AccountUtils.hasOfficialKeyAccount(context) + } else { + hasOfficial = account.isOfficial(context) + } + (defaultValue as HasOfficialBooleanHolder).hasOfficial = hasOfficial + val checkBox = view.findViewById(android.R.id.checkbox) as CheckBox + val titleView = view.findViewById(android.R.id.title) as TextView + val summaryView = view.findViewById(android.R.id.summary) as TextView + view.isEnabled = hasOfficial + titleView.isEnabled = hasOfficial + summaryView.isEnabled = hasOfficial + checkBox.isEnabled = hasOfficial + if (hasOfficial) { + checkBox.isChecked = valueBackup + summaryView.visibility = View.GONE + } else { + valueBackup = checkBox.isChecked + checkBox.isChecked = true + summaryView.setText(R.string.summary_interactions_not_available) + summaryView.visibility = View.VISIBLE + } + } + + override var value: Boolean + get() { + if ((defaultValue as HasOfficialBooleanHolder).hasOfficial) { + return super.value + } + return valueBackup + } + set(value) { + super.value = value + } + + private class HasOfficialBooleanHolder : BooleanHolder() { + + var hasOfficial: Boolean = false + + override fun createBoolean(context: Context): Boolean { + return hasOfficial + } + + } + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.kt new file mode 100644 index 000000000..9d188bb82 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/MessagesTabConfiguration.kt @@ -0,0 +1,23 @@ +package org.mariotaku.twidere.model.tab.impl + +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.fragment.message.MessagesEntriesFragment +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration + +/** + * Created by mariotaku on 2016/11/27. + */ + +class MessagesTabConfiguration : TabConfiguration() { + override val name = StringHolder.resource(R.string.title_direct_messages) + + override val icon = DrawableHolder.Builtin.MESSAGE + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or + TabAccountFlags.FLAG_ACCOUNT_MULTIPLE or TabAccountFlags.FLAG_ACCOUNT_MUTABLE + + override val fragmentClass = MessagesEntriesFragment::class.java +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.kt new file mode 100644 index 000000000..88158262a --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/PublicTimelineTabConfiguration.kt @@ -0,0 +1,49 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.fragment.PublicTimelineFragment +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration + +/** + * Created by mariotaku on 2016/11/27. + */ + +class PublicTimelineTabConfiguration : TabConfiguration() { + + override val name = StringHolder.resource(R.string.title_public_timeline) + + override val icon = DrawableHolder.Builtin.QUOTE + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or + TabAccountFlags.FLAG_ACCOUNT_REQUIRED or TabAccountFlags.FLAG_ACCOUNT_MUTABLE + + override val fragmentClass = PublicTimelineFragment::class.java + + override fun checkAccountAvailability(details: AccountDetails): Boolean { + return AccountType.FANFOU == details.type || AccountType.STATUSNET == details.type + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.kt new file mode 100644 index 000000000..4e2ec86b7 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/SearchTabConfiguration.kt @@ -0,0 +1,72 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import android.content.Context +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_QUERY +import org.mariotaku.twidere.fragment.StatusesSearchFragment +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration +import org.mariotaku.twidere.model.tab.argument.TextQueryArguments +import org.mariotaku.twidere.model.tab.conf.StringExtraConfiguration + +/** + * Created by mariotaku on 2016/11/27. + */ + +class SearchTabConfiguration : TabConfiguration() { + + override val name = StringHolder.resource(R.string.action_search) + + override val icon = DrawableHolder.Builtin.SEARCH + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or TabAccountFlags.FLAG_ACCOUNT_REQUIRED + + override val fragmentClass = StatusesSearchFragment::class.java + + override fun getExtraConfigurations(context: Context) = arrayOf( + StringExtraConfiguration(EXTRA_QUERY, R.string.search_statuses, null).maxLines(1).headerTitle(R.string.query) + ) + + override fun applyExtraConfigurationTo(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val arguments = tab.arguments as TextQueryArguments + when (extraConf.key) { + EXTRA_QUERY -> { + val query = (extraConf as StringExtraConfiguration).value ?: return false + arguments.query = query + } + } + return true + } + + override fun readExtraConfigurationFrom(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val arguments = tab.arguments as? TextQueryArguments ?: return false + when (extraConf.key) { + EXTRA_QUERY -> { + (extraConf as StringExtraConfiguration).value = arguments.query + } + } + return true + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.kt new file mode 100644 index 000000000..2812b8f8d --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/TrendsTabConfiguration.kt @@ -0,0 +1,87 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import android.content.Context +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_PLACE +import org.mariotaku.twidere.fragment.TrendsSuggestionsFragment +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration +import org.mariotaku.twidere.model.tab.conf.TrendsLocationExtraConfiguration +import org.mariotaku.twidere.model.tab.extra.TrendsTabExtras + +/** + * Created by mariotaku on 2016/11/27. + */ + +class TrendsTabConfiguration : TabConfiguration() { + + override val name = StringHolder.resource(R.string.trends) + + override val icon = DrawableHolder.Builtin.HASHTAG + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or + TabAccountFlags.FLAG_ACCOUNT_REQUIRED or TabAccountFlags.FLAG_ACCOUNT_MUTABLE + + override val fragmentClass = TrendsSuggestionsFragment::class.java + + override fun getExtraConfigurations(context: Context) = arrayOf( + TrendsLocationExtraConfiguration(EXTRA_PLACE, R.string.trends_location).mutable(true) + ) + + override fun applyExtraConfigurationTo(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val extras = tab.extras as TrendsTabExtras + when (extraConf.key) { + EXTRA_PLACE -> { + val conf = extraConf as TrendsLocationExtraConfiguration + val place = conf.value + if (place != null) { + extras.woeId = place.woeId + extras.placeName = place.name + } else { + extras.woeId = 0 + extras.placeName = null + } + } + } + return true + } + + override fun readExtraConfigurationFrom(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val extras = tab.extras as? TrendsTabExtras ?: return false + when (extraConf.key) { + EXTRA_PLACE -> { + val woeId = extras.woeId + val name = extras.placeName + if (name != null) { + val place = TrendsLocationExtraConfiguration.Place(woeId, name) + (extraConf as TrendsLocationExtraConfiguration).value = place + } else { + (extraConf as TrendsLocationExtraConfiguration).value = null + } + } + } + return true + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.kt new file mode 100644 index 000000000..71870c7e2 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserListTimelineTabConfiguration.kt @@ -0,0 +1,63 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import android.content.Context +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER_LIST +import org.mariotaku.twidere.fragment.UserListTimelineFragment +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration +import org.mariotaku.twidere.model.tab.argument.UserListArguments +import org.mariotaku.twidere.model.tab.conf.UserListExtraConfiguration + +/** + * Created by mariotaku on 2016/11/27. + */ + +class UserListTimelineTabConfiguration : TabConfiguration() { + + override val name = StringHolder.resource(R.string.list_timeline) + + override val icon = DrawableHolder.Builtin.LIST + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or + TabAccountFlags.FLAG_ACCOUNT_REQUIRED + + override val fragmentClass = UserListTimelineFragment::class.java + + override fun getExtraConfigurations(context: Context) = arrayOf( + UserListExtraConfiguration(EXTRA_USER_LIST).headerTitle(R.string.title_user_list) + ) + + override fun applyExtraConfigurationTo(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val arguments = tab.arguments as UserListArguments + when (extraConf.key) { + EXTRA_USER_LIST -> { + val userList = (extraConf as UserListExtraConfiguration).value ?: return false + arguments.listId = userList.id + } + } + return true + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.kt new file mode 100644 index 000000000..26131cb8d --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/model/tab/impl/UserTimelineTabConfiguration.kt @@ -0,0 +1,62 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 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.model.tab.impl + +import android.content.Context +import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.TabAccountFlags +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_USER +import org.mariotaku.twidere.fragment.UserTimelineFragment +import org.mariotaku.twidere.model.Tab +import org.mariotaku.twidere.model.tab.DrawableHolder +import org.mariotaku.twidere.model.tab.StringHolder +import org.mariotaku.twidere.model.tab.TabConfiguration +import org.mariotaku.twidere.model.tab.argument.UserArguments +import org.mariotaku.twidere.model.tab.conf.UserExtraConfiguration + +/** + * Created by mariotaku on 2016/11/27. + */ + +class UserTimelineTabConfiguration : TabConfiguration() { + + override val name = StringHolder.resource(R.string.users_statuses) + + override val icon = DrawableHolder.Builtin.USER + + override val accountFlags = TabAccountFlags.FLAG_HAS_ACCOUNT or TabAccountFlags.FLAG_ACCOUNT_REQUIRED + + override val fragmentClass = UserTimelineFragment::class.java + + override fun getExtraConfigurations(context: Context) = arrayOf( + UserExtraConfiguration(EXTRA_USER).headerTitle(R.string.title_user) + ) + + override fun applyExtraConfigurationTo(tab: Tab, extraConf: TabConfiguration.ExtraConfiguration): Boolean { + val arguments = tab.arguments as UserArguments + when (extraConf.key) { + EXTRA_USER -> { + val user = (extraConf as UserExtraConfiguration).value ?: return false + arguments.setUserKey(user.key) + } + } + return true + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/provider/TwidereDataProvider.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/provider/TwidereDataProvider.kt index 5a99770af..0b40747d6 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/provider/TwidereDataProvider.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/provider/TwidereDataProvider.kt @@ -21,6 +21,7 @@ package org.mariotaku.twidere.provider import android.content.ContentProvider import android.content.ContentValues +import android.content.SharedPreferences import android.database.Cursor import android.database.MatrixCursor import android.database.SQLException @@ -65,7 +66,7 @@ class TwidereDataProvider : ContentProvider(), LazyLoadCallback { @Inject lateinit internal var notificationManager: NotificationManagerWrapper @Inject - lateinit internal var preferences: SharedPreferencesWrapper + lateinit internal var preferences: SharedPreferences @Inject lateinit internal var dns: Dns @Inject @@ -461,7 +462,8 @@ class TwidereDataProvider : ContentProvider(), LazyLoadCallback { TABLE_ID_STATUSES -> { if (!uri.getBooleanQueryParameter(QUERY_PARAM_SHOW_NOTIFICATION, true)) return backgroundExecutor.execute { - val prefs = AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)) + val prefs = AccountPreferences.getAccountPreferences(context, preferences, + DataStoreUtils.getAccountKeys(context)) prefs.filter { it.isNotificationEnabled && it.isHomeTimelineNotificationEnabled }.forEach { val positionTag = getPositionTag(CustomTabType.HOME_TIMELINE, it.accountKey) contentNotificationManager.showTimeline(it, positionTag) @@ -472,7 +474,8 @@ class TwidereDataProvider : ContentProvider(), LazyLoadCallback { TABLE_ID_ACTIVITIES_ABOUT_ME -> { if (!uri.getBooleanQueryParameter(QUERY_PARAM_SHOW_NOTIFICATION, true)) return backgroundExecutor.execute { - val prefs = AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)) + val prefs = AccountPreferences.getAccountPreferences(context, preferences, + DataStoreUtils.getAccountKeys(context)) prefs.filter { it.isNotificationEnabled && it.isInteractionsNotificationEnabled }.forEach { val positionTag = getPositionTag(ReadPositionTag.ACTIVITIES_ABOUT_ME, it.accountKey) contentNotificationManager.showInteractions(it, positionTag) @@ -483,7 +486,8 @@ class TwidereDataProvider : ContentProvider(), LazyLoadCallback { TABLE_ID_MESSAGES_CONVERSATIONS -> { if (!uri.getBooleanQueryParameter(QUERY_PARAM_SHOW_NOTIFICATION, true)) return backgroundExecutor.execute { - val prefs = AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)) + val prefs = AccountPreferences.getAccountPreferences(context, preferences, + DataStoreUtils.getAccountKeys(context)) prefs.filter { it.isNotificationEnabled && it.isDirectMessagesNotificationEnabled }.forEach { contentNotificationManager.showMessages(it) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseIntentService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseIntentService.kt index 4513442b4..8719a7d78 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseIntentService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseIntentService.kt @@ -1,11 +1,11 @@ package org.mariotaku.twidere.service import android.app.IntentService +import android.content.SharedPreferences import com.twitter.Extractor import com.twitter.Validator import org.mariotaku.twidere.util.AsyncTwitterWrapper import org.mariotaku.twidere.util.NotificationManagerWrapper -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.dagger.GeneralComponent import javax.inject.Inject @@ -13,7 +13,7 @@ import javax.inject.Inject abstract class BaseIntentService(tag: String) : IntentService(tag) { @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var twitterWrapper: AsyncTwitterWrapper @Inject diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseService.kt index ac2650541..76a4df1b2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/BaseService.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.service import android.app.Service +import android.content.SharedPreferences import android.net.ConnectivityManager import com.twitter.Extractor import com.twitter.Validator @@ -30,7 +31,7 @@ import javax.inject.Inject abstract class BaseService : Service() { @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var twitterWrapper: AsyncTwitterWrapper @Inject diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/LengthyOperationsService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/LengthyOperationsService.kt index 9ff1b75fe..a1338cfe7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/LengthyOperationsService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/LengthyOperationsService.kt @@ -40,6 +40,7 @@ import nl.komponents.kovenant.task import nl.komponents.kovenant.ui.successUi import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.abstask.library.ManualTaskStarter +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.configure import org.mariotaku.ktextension.toLongOr import org.mariotaku.ktextension.toTypedArray @@ -55,6 +56,7 @@ import org.mariotaku.restfu.http.mime.SimpleBody import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.* +import org.mariotaku.twidere.constant.refreshAfterTweetKey import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.draft.SendDirectMessageActionExtras import org.mariotaku.twidere.model.draft.StatusObjectActionExtras @@ -318,7 +320,7 @@ class LengthyOperationsService : BaseIntentService("lengthy_operations") { }) } } - if (preferences.getBoolean(KEY_REFRESH_AFTER_TWEET)) { + if (preferences[refreshAfterTweetKey]) { handler.post { twitterWrapper.refreshAll() } } stopForeground(false) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt index 95bf5e656..a465fd0f2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/StreamingService.kt @@ -133,7 +133,7 @@ class StreamingService : BaseService() { private fun updateStreamingInstances(): Boolean { val am = AccountManager.get(this) val supportedAccounts = AccountUtils.getAllAccountDetails(am, true).filter { it.isStreamingSupported } - val supportedPrefs = supportedAccounts.map { AccountPreferences(this, it.key) } + val supportedPrefs = supportedAccounts.map { AccountPreferences(this, preferences, it.key) } val enabledAccounts = supportedAccounts.filter { account -> return@filter supportedPrefs.any { account.key == it.accountKey && it.isStreamingEnabled diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/AddUserListMembersTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/AddUserListMembersTask.kt index 299e5dccf..6321d373b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/AddUserListMembersTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/AddUserListMembersTask.kt @@ -1,10 +1,11 @@ package org.mariotaku.twidere.task import android.content.Context +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.mapToArray import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.twidere.R -import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_NAME_FIRST +import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.SingleResponse @@ -43,7 +44,7 @@ class AddUserListMembersTask( val message: String if (users.size == 1) { val user = users.first() - val nameFirst = preferences.getBoolean(KEY_NAME_FIRST) + val nameFirst = preferences[nameFirstKey] val displayName = userColorNameManager.getDisplayName(user.key, user.name, user.screen_name, nameFirst) message = context.getString(R.string.message_toast_added_user_to_list, displayName, result.data.name) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/BaseAbstractTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/BaseAbstractTask.kt index b7b65eb25..4c3ea1e44 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/BaseAbstractTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/BaseAbstractTask.kt @@ -1,12 +1,16 @@ package org.mariotaku.twidere.task import android.content.Context +import android.content.SharedPreferences import com.squareup.otto.Bus import com.twitter.Extractor import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.kpreferences.KPreferences import org.mariotaku.twidere.model.DefaultFeatures -import org.mariotaku.twidere.util.* +import org.mariotaku.twidere.util.AsyncTwitterWrapper +import org.mariotaku.twidere.util.ErrorInfoStore +import org.mariotaku.twidere.util.ReadStateManager +import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.dagger.GeneralComponent import org.mariotaku.twidere.util.media.MediaPreloader import org.mariotaku.twidere.util.premium.ExtraFeaturesService @@ -27,7 +31,7 @@ abstract class BaseAbstractTask(val context: Context) @Inject lateinit var mediaPreloader: MediaPreloader @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var kPreferences: KPreferences @Inject diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/ManagedAsyncTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/ManagedAsyncTask.kt index 7585ddf81..da808f623 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/ManagedAsyncTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/ManagedAsyncTask.kt @@ -20,17 +20,14 @@ package org.mariotaku.twidere.task import android.content.Context +import android.content.SharedPreferences import android.os.AsyncTask - import com.squareup.otto.Bus - import org.mariotaku.twidere.model.event.TaskStateChangedEvent import org.mariotaku.twidere.util.AsyncTaskManager import org.mariotaku.twidere.util.AsyncTwitterWrapper -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.dagger.GeneralComponent - import javax.inject.Inject abstract class ManagedAsyncTask @JvmOverloads constructor( @@ -45,7 +42,7 @@ abstract class ManagedAsyncTask @JvmOverloads construc @Inject lateinit var userColorNameManager: UserColorNameManager @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences @Inject lateinit var asyncTwitterWrapper: AsyncTwitterWrapper diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt index fdc7c87b4..11c926c75 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/AsyncTwitterWrapper.kt @@ -21,6 +21,7 @@ package org.mariotaku.twidere.util import android.content.ContentValues import android.content.Context +import android.content.SharedPreferences import android.net.Uri import com.squareup.otto.Bus import com.squareup.otto.Subscribe @@ -36,7 +37,9 @@ import org.mariotaku.microblog.library.twitter.model.* import org.mariotaku.sqliteqb.library.Expression import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants -import org.mariotaku.twidere.constant.SharedPreferenceConstants +import org.mariotaku.twidere.constant.homeRefreshDirectMessagesKey +import org.mariotaku.twidere.constant.homeRefreshMentionsKey +import org.mariotaku.twidere.constant.homeRefreshSavedSearchesKey import org.mariotaku.twidere.constant.nameFirstKey import org.mariotaku.twidere.model.* import org.mariotaku.twidere.model.event.* @@ -56,7 +59,7 @@ import java.util.* class AsyncTwitterWrapper( val context: Context, private val bus: Bus, - private val preferences: SharedPreferencesWrapper, + private val preferences: SharedPreferences, private val asyncTaskManager: AsyncTaskManager, private val notificationManager: NotificationManagerWrapper ) { @@ -280,7 +283,7 @@ class AsyncTwitterWrapper( accountKeys.toNulls()) } }) - if (preferences.getBoolean(SharedPreferenceConstants.KEY_HOME_REFRESH_MENTIONS)) { + if (preferences[homeRefreshMentionsKey]) { getActivitiesAboutMeAsync(object : SimpleRefreshTaskParam() { override val accountKeys: Array by lazy { action() } @@ -290,12 +293,12 @@ class AsyncTwitterWrapper( } }) } - if (preferences.getBoolean(SharedPreferenceConstants.KEY_HOME_REFRESH_DIRECT_MESSAGES)) { + if (preferences[homeRefreshDirectMessagesKey]) { getMessagesAsync(object : GetMessagesTask.RefreshMessagesTaskParam(context) { override val accountKeys: Array by lazy { action() } }) } - if (preferences.getBoolean(SharedPreferenceConstants.KEY_HOME_REFRESH_SAVED_SEARCHES)) { + if (preferences[homeRefreshSavedSearchesKey]) { getSavedSearchesAsync(action()) } return true diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt index dae5ed789..d6ba3221b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/HttpClientFactory.kt @@ -1,13 +1,16 @@ package org.mariotaku.twidere.util import android.content.Context +import android.content.SharedPreferences import android.net.Uri import android.util.Base64 import okhttp3.* +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.toIntOr import org.mariotaku.restfu.http.RestHttpClient import org.mariotaku.restfu.okhttp3.OkHttpRestClient import org.mariotaku.twidere.constant.SharedPreferenceConstants.* +import org.mariotaku.twidere.constant.cacheSizeLimitKey import org.mariotaku.twidere.util.dagger.DependencyHolder import java.io.IOException import java.net.InetSocketAddress @@ -41,12 +44,12 @@ object HttpClientFactory { builder.cache(cache) } - class HttpClientConfiguration(val prefs: SharedPreferencesWrapper) { + class HttpClientConfiguration(val prefs: SharedPreferences) { var readTimeoutSecs: Long = -1 var writeTimeoutSecs: Long = -1 var connectionTimeoutSecs: Long = prefs.getInt(KEY_CONNECTION_TIMEOUT, 10).toLong() - var cacheSize: Int = prefs.getInt(KEY_CACHE_SIZE_LIMIT, 300).coerceIn(100..500) + var cacheSize: Int = prefs[cacheSizeLimitKey] internal fun applyTo(builder: OkHttpClient.Builder) { if (connectionTimeoutSecs >= 0) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/ReadStateManager.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/ReadStateManager.kt index 677c79b23..32ca2f7e3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/ReadStateManager.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/ReadStateManager.kt @@ -29,8 +29,8 @@ import org.mariotaku.twidere.annotation.ReadPositionTag class ReadStateManager(context: Context) { - private val preferences = SharedPreferencesWrapper.getInstance(context, - TIMELINE_POSITIONS_PREFERENCES_NAME, Context.MODE_PRIVATE) + private val preferences = context.getSharedPreferences(TIMELINE_POSITIONS_PREFERENCES_NAME, + Context.MODE_PRIVATE) fun getPosition(key: String): Long { if (TextUtils.isEmpty(key)) return -1 diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.kt index cbdc0436f..1480880e4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/StatusAdapterLinkClickHandler.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.util import android.content.Context +import android.content.SharedPreferences import android.support.v7.widget.RecyclerView import org.mariotaku.kpreferences.get import org.mariotaku.twidere.Constants @@ -32,7 +33,8 @@ import org.mariotaku.twidere.model.util.ParcelableMediaUtils /** * Created by mariotaku on 15/4/6. */ -class StatusAdapterLinkClickHandler(context: Context, preferences: SharedPreferencesWrapper) : OnLinkClickHandler(context, null, preferences), Constants { +class StatusAdapterLinkClickHandler(context: Context, preferences: SharedPreferences) : + OnLinkClickHandler(context, null, preferences), Constants { private var adapter: IStatusesAdapter? = null diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/TaskServiceRunner.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/TaskServiceRunner.kt index c736bc54b..637d80261 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/TaskServiceRunner.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/TaskServiceRunner.kt @@ -1,12 +1,13 @@ package org.mariotaku.twidere.util import android.content.Context +import android.content.SharedPreferences import android.support.annotation.StringDef import android.util.Log import com.squareup.otto.Bus import org.mariotaku.abstask.library.AbstractTask import org.mariotaku.abstask.library.TaskStarter -import org.mariotaku.kpreferences.KPreferences +import org.mariotaku.kpreferences.get import org.mariotaku.ktextension.mapToArray import org.mariotaku.ktextension.toNulls import org.mariotaku.twidere.TwidereConstants.LOGTAG @@ -29,7 +30,7 @@ import org.mariotaku.twidere.task.twitter.message.GetMessagesTask class TaskServiceRunner( val context: Context, - val preferences: KPreferences, + val preferences: SharedPreferences, val bus: Bus ) { @@ -59,14 +60,16 @@ class TaskServiceRunner( when (action) { ACTION_REFRESH_HOME_TIMELINE -> { val task = GetHomeTimelineTask(context) - task.params = AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshHomeTimelineEnabled) { accountKeys -> + task.params = AutoRefreshTaskParam(context, preferences, + AccountPreferences::isAutoRefreshHomeTimelineEnabled) { accountKeys -> DataStoreUtils.getNewestStatusIds(context, Statuses.CONTENT_URI, accountKeys.toNulls()) } return task } ACTION_REFRESH_NOTIFICATIONS -> { val task = GetActivitiesAboutMeTask(context) - task.params = AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshMentionsEnabled) { accountKeys -> + task.params = AutoRefreshTaskParam(context, preferences, + AccountPreferences::isAutoRefreshMentionsEnabled) { accountKeys -> DataStoreUtils.getRefreshNewestActivityMaxPositions(context, Activities.AboutMe.CONTENT_URI, accountKeys.toNulls()) } @@ -76,7 +79,8 @@ class TaskServiceRunner( val task = GetMessagesTask(context) task.params = object : GetMessagesTask.RefreshNewTaskParam(context) { override val accountKeys: Array by lazy { - AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)).filter { + AccountPreferences.getAccountPreferences(context, preferences, + DataStoreUtils.getAccountKeys(context)).filter { it.isAutoRefreshEnabled && it.isAutoRefreshDirectMessagesEnabled }.mapToArray(AccountPreferences::accountKey) } @@ -98,11 +102,13 @@ class TaskServiceRunner( class AutoRefreshTaskParam( val context: Context, + val preferences: SharedPreferences, val refreshable: (AccountPreferences) -> Boolean, val getSinceIds: (Array) -> Array? ) : SimpleRefreshTaskParam() { override val accountKeys: Array by lazy { - return@lazy AccountPreferences.getAccountPreferences(context, DataStoreUtils.getAccountKeys(context)).filter { + return@lazy AccountPreferences.getAccountPreferences(context, preferences, + DataStoreUtils.getAccountKeys(context)).filter { it.isAutoRefreshEnabled && refreshable(it) }.mapToArray(AccountPreferences::accountKey) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/ApplicationModule.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/ApplicationModule.kt index ba44b17c7..782ed37eb 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/ApplicationModule.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/ApplicationModule.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.util.dagger import android.content.Context +import android.content.SharedPreferences import android.location.LocationManager import android.net.ConnectivityManager import android.os.Build @@ -45,7 +46,6 @@ import org.mariotaku.mediaviewer.library.FileCache import org.mariotaku.mediaviewer.library.MediaDownloader import org.mariotaku.restfu.http.RestHttpClient import org.mariotaku.twidere.Constants -import org.mariotaku.twidere.constant.SharedPreferenceConstants import org.mariotaku.twidere.constant.SharedPreferenceConstants.KEY_CACHE_SIZE_LIMIT import org.mariotaku.twidere.constant.autoRefreshCompatibilityModeKey import org.mariotaku.twidere.model.DefaultFeatures @@ -86,7 +86,7 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun externalThemeManager(preferences: SharedPreferencesWrapper): ExternalThemeManager { + fun externalThemeManager(preferences: SharedPreferences): ExternalThemeManager { return ExternalThemeManager(context, preferences) } @@ -98,14 +98,13 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun sharedPreferences(): SharedPreferencesWrapper { - return SharedPreferencesWrapper.getInstance(context, Constants.SHARED_PREFERENCES_NAME, - Context.MODE_PRIVATE, SharedPreferenceConstants::class.java) + fun sharedPreferences(): SharedPreferences { + return context.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) } @Provides @Singleton - fun kPreferences(sharedPreferences: SharedPreferencesWrapper): KPreferences { + fun kPreferences(sharedPreferences: SharedPreferences): KPreferences { return KPreferences(sharedPreferences) } @@ -129,7 +128,7 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun restHttpClient(prefs: SharedPreferencesWrapper, dns: Dns, + fun restHttpClient(prefs: SharedPreferences, dns: Dns, connectionPool: ConnectionPool, cache: Cache): RestHttpClient { val conf = HttpClientFactory.HttpClientConfiguration(prefs) return HttpClientFactory.createRestHttpClient(conf, dns, connectionPool, cache) @@ -161,7 +160,7 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun asyncTwitterWrapper(bus: Bus, preferences: SharedPreferencesWrapper, + fun asyncTwitterWrapper(bus: Bus, preferences: SharedPreferences, asyncTaskManager: AsyncTaskManager, notificationManagerWrapper: NotificationManagerWrapper): AsyncTwitterWrapper { return AsyncTwitterWrapper(context, bus, preferences, asyncTaskManager, notificationManagerWrapper) } @@ -175,13 +174,14 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton fun contentNotificationManager(activityTracker: ActivityTracker, userColorNameManager: UserColorNameManager, - notificationManagerWrapper: NotificationManagerWrapper, preferences: SharedPreferencesWrapper): ContentNotificationManager { + notificationManagerWrapper: NotificationManagerWrapper, + preferences: SharedPreferences): ContentNotificationManager { return ContentNotificationManager(context, activityTracker, userColorNameManager, notificationManagerWrapper, preferences) } @Provides @Singleton - fun mediaLoaderWrapper(preferences: SharedPreferencesWrapper): MediaPreloader { + fun mediaLoaderWrapper(preferences: SharedPreferences): MediaPreloader { val preloader = MediaPreloader(context) preloader.reloadOptions(preferences) val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager @@ -191,13 +191,13 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun dns(preferences: SharedPreferencesWrapper): Dns { + fun dns(preferences: SharedPreferences): Dns { return TwidereDns(context, preferences) } @Provides @Singleton - fun mediaDownloader(preferences: SharedPreferencesWrapper, client: RestHttpClient, + fun mediaDownloader(preferences: SharedPreferences, client: RestHttpClient, thumbor: ThumborWrapper): MediaDownloader { return TwidereMediaDownloader(context, client, thumbor) } @@ -222,7 +222,7 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun thumborWrapper(preferences: SharedPreferencesWrapper): ThumborWrapper { + fun thumborWrapper(preferences: SharedPreferences): ThumborWrapper { val thumbor = ThumborWrapper() thumbor.reloadSettings(preferences) return thumbor @@ -259,13 +259,13 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun taskCreator(kPreferences: KPreferences, bus: Bus): TaskServiceRunner { - return TaskServiceRunner(context, kPreferences, bus) + fun taskCreator(preferences: SharedPreferences, bus: Bus): TaskServiceRunner { + return TaskServiceRunner(context, preferences, bus) } @Provides @Singleton - fun defaultFeatures(preferences: SharedPreferencesWrapper): DefaultFeatures { + fun defaultFeatures(preferences: SharedPreferences): DefaultFeatures { val features = DefaultFeatures() features.load(preferences) return features @@ -294,7 +294,7 @@ class ApplicationModule(private val context: Context) { } @Provides - fun okHttpClient(preferences: SharedPreferencesWrapper, dns: Dns, connectionPool: ConnectionPool, + fun okHttpClient(preferences: SharedPreferences, dns: Dns, connectionPool: ConnectionPool, cache: Cache): OkHttpClient { val conf = HttpClientFactory.HttpClientConfiguration(preferences) val builder = OkHttpClient.Builder() @@ -304,7 +304,7 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun dataSourceFactory(preferences: SharedPreferencesWrapper, dns: Dns, connectionPool: ConnectionPool, + fun dataSourceFactory(preferences: SharedPreferences, dns: Dns, connectionPool: ConnectionPool, cache: Cache): DataSource.Factory { val conf = HttpClientFactory.HttpClientConfiguration(preferences) val builder = OkHttpClient.Builder() @@ -315,7 +315,7 @@ class ApplicationModule(private val context: Context) { @Provides @Singleton - fun cache(preferences: SharedPreferencesWrapper): Cache { + fun cache(preferences: SharedPreferences): Cache { val cacheSizeMB = preferences.getInt(KEY_CACHE_SIZE_LIMIT, 300).coerceIn(100..500) // Convert to bytes return Cache(getCacheDir("network", cacheSizeMB * 1048576L), cacheSizeMB * 1048576L) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/DependencyHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/DependencyHolder.kt index fa5dc5840..19830bab8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/DependencyHolder.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/DependencyHolder.kt @@ -20,6 +20,7 @@ package org.mariotaku.twidere.util.dagger import android.content.Context +import android.content.SharedPreferences import com.twitter.Validator import okhttp3.Cache import okhttp3.ConnectionPool @@ -27,7 +28,10 @@ import okhttp3.Dns import org.mariotaku.kpreferences.KPreferences import org.mariotaku.restfu.http.RestHttpClient import org.mariotaku.twidere.model.DefaultFeatures -import org.mariotaku.twidere.util.* +import org.mariotaku.twidere.util.ActivityTracker +import org.mariotaku.twidere.util.ExternalThemeManager +import org.mariotaku.twidere.util.ReadStateManager +import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.media.MediaPreloader import org.mariotaku.twidere.util.media.ThumborWrapper import org.mariotaku.twidere.util.sync.TimelineSyncManager @@ -56,7 +60,7 @@ class DependencyHolder internal constructor(context: Context) { lateinit var validator: Validator internal set @Inject - lateinit var preferences: SharedPreferencesWrapper + lateinit var preferences: SharedPreferences internal set @Inject lateinit var connectionPool: ConnectionPool diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TwidereDns.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TwidereDns.kt index 83bc0aab8..afb7f2b0b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TwidereDns.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/net/TwidereDns.kt @@ -28,7 +28,6 @@ import org.mariotaku.ktextension.toIntOr import org.mariotaku.twidere.BuildConfig import org.mariotaku.twidere.TwidereConstants.HOST_MAPPING_PREFERENCES_NAME import org.mariotaku.twidere.constant.SharedPreferenceConstants.* -import org.mariotaku.twidere.util.SharedPreferencesWrapper import org.xbill.DNS.* import java.io.IOException import java.net.InetAddress @@ -39,15 +38,14 @@ import javax.inject.Singleton @Singleton class TwidereDns(context: Context, private val preferences: SharedPreferences) : Dns { - private val hostMapping: SharedPreferences - private val systemHosts: SystemHosts + private val hostMapping = context.getSharedPreferences(HOST_MAPPING_PREFERENCES_NAME, + Context.MODE_PRIVATE) + private val systemHosts = SystemHosts() private var resolver: Resolver? = null private var useResolver: Boolean = false init { - hostMapping = SharedPreferencesWrapper.getInstance(context, HOST_MAPPING_PREFERENCES_NAME, Context.MODE_PRIVATE) - systemHosts = SystemHosts() reloadDnsSettings() } diff --git a/twidere/src/main/res-localized/values-ar/strings.xml b/twidere/src/main/res-localized/values-ar/strings.xml index 7dcdd3684..d5c5cacb2 100644 --- a/twidere/src/main/res-localized/values-ar/strings.xml +++ b/twidere/src/main/res-localized/values-ar/strings.xml @@ -680,7 +680,7 @@ ساعدنا كي نحسن تويدر! تم حظر هذا المستخدم. المستخدم : %s - لائحة + لائحة تفاصيل القائمة الوصف diff --git a/twidere/src/main/res-localized/values-ast/strings.xml b/twidere/src/main/res-localized/values-ast/strings.xml index c111830d1..b7bc331ed 100644 --- a/twidere/src/main/res-localized/values-ast/strings.xml +++ b/twidere/src/main/res-localized/values-ast/strings.xml @@ -1029,7 +1029,7 @@ Convertilu a un tuit normal amiesta una caráuter estra. ¡Ayúdamos a ameyorar Twidere! Bloquióse a esti usuariu. Usuariu: %s - Llistáu + Llistáu Detalles del llistáu Descripción diff --git a/twidere/src/main/res-localized/values-ca/strings.xml b/twidere/src/main/res-localized/values-ca/strings.xml index 638c8d693..2569aefcd 100644 --- a/twidere/src/main/res-localized/values-ca/strings.xml +++ b/twidere/src/main/res-localized/values-ca/strings.xml @@ -750,7 +750,7 @@ Ajuda\'ns a millorar Twidere! S\'ha bloquejat aquest usuari. Usuari: %s - Llista + Llista Detalls de la llista Descripció diff --git a/twidere/src/main/res-localized/values-cs/strings.xml b/twidere/src/main/res-localized/values-cs/strings.xml index 63698acf5..5f25f7ac0 100644 --- a/twidere/src/main/res-localized/values-cs/strings.xml +++ b/twidere/src/main/res-localized/values-cs/strings.xml @@ -410,7 +410,7 @@ Statistiky využití Blokovat tohoto uživatele. Uživatel: %s - Seznam + Seznam Popis diff --git a/twidere/src/main/res-localized/values-da/strings.xml b/twidere/src/main/res-localized/values-da/strings.xml index 6bdbe1a33..e8571306a 100644 --- a/twidere/src/main/res-localized/values-da/strings.xml +++ b/twidere/src/main/res-localized/values-da/strings.xml @@ -297,7 +297,7 @@ Tryk for at komponere Afinstallér Bloker denne bruger. - Liste + Liste Beskrivelse diff --git a/twidere/src/main/res-localized/values-de/strings.xml b/twidere/src/main/res-localized/values-de/strings.xml index 6cf624d8b..8c9b9e01c 100644 --- a/twidere/src/main/res-localized/values-de/strings.xml +++ b/twidere/src/main/res-localized/values-de/strings.xml @@ -1034,7 +1034,7 @@ Hilf uns Twidere zu verbessern! Dieser Benutzer wurde blockiert. Benutzer: %s - Liste + Liste Listendetails Beschreibung diff --git a/twidere/src/main/res-localized/values-es/strings.xml b/twidere/src/main/res-localized/values-es/strings.xml index af3a939a9..60de02e6b 100644 --- a/twidere/src/main/res-localized/values-es/strings.xml +++ b/twidere/src/main/res-localized/values-es/strings.xml @@ -1049,7 +1049,7 @@ Ayúdanos a mejorar Twidere! Bloquear a este usuario. Usuario: %s - Lista + Lista Detalles de la lista Descripción diff --git a/twidere/src/main/res-localized/values-fa/strings.xml b/twidere/src/main/res-localized/values-fa/strings.xml index 7e8576aba..5923e37f3 100644 --- a/twidere/src/main/res-localized/values-fa/strings.xml +++ b/twidere/src/main/res-localized/values-fa/strings.xml @@ -905,7 +905,7 @@ کمک کنید تویدر را بهتر کنیم! این کاربر مسدود شده است. کاربر: %s - فهرست + فهرست فهرست کردن جزییات توصیف diff --git a/twidere/src/main/res-localized/values-fi/strings.xml b/twidere/src/main/res-localized/values-fi/strings.xml index 7467761c5..ed9d3eb78 100644 --- a/twidere/src/main/res-localized/values-fi/strings.xml +++ b/twidere/src/main/res-localized/values-fi/strings.xml @@ -736,7 +736,7 @@ Auta meitä kehittämään Twidereä! Käyttäjä on estetty. Käyttäjä: %s - Lista + Lista Listaa lisätiedot Kuvaus diff --git a/twidere/src/main/res-localized/values-fr/strings.xml b/twidere/src/main/res-localized/values-fr/strings.xml index 3ba8d177a..80852ab31 100644 --- a/twidere/src/main/res-localized/values-fr/strings.xml +++ b/twidere/src/main/res-localized/values-fr/strings.xml @@ -1028,7 +1028,7 @@ Aidez-nous à améliorer Twidere ! Utilisateur bloqué. Utilisateur : %s - Liste + Liste Détails de la liste Description diff --git a/twidere/src/main/res-localized/values-gl/strings.xml b/twidere/src/main/res-localized/values-gl/strings.xml index 7e3924e07..82be1aeab 100644 --- a/twidere/src/main/res-localized/values-gl/strings.xml +++ b/twidere/src/main/res-localized/values-gl/strings.xml @@ -1051,7 +1051,7 @@ Axúdanos a mellorar Twidere! Este usuario foi bloqueado. Usuario: %s - Lista + Lista Detalles da lista Descrición diff --git a/twidere/src/main/res-localized/values-hr/strings.xml b/twidere/src/main/res-localized/values-hr/strings.xml index 1c3212559..388f1be89 100644 --- a/twidere/src/main/res-localized/values-hr/strings.xml +++ b/twidere/src/main/res-localized/values-hr/strings.xml @@ -645,7 +645,7 @@ Pomozite nam poboljšati Twidere! Ovaj korisnik je blokiran. Korisnik: %s - Lista + Lista Detalji o listi Opis diff --git a/twidere/src/main/res-localized/values-hu/strings.xml b/twidere/src/main/res-localized/values-hu/strings.xml index 51e967cc3..e776f47e7 100644 --- a/twidere/src/main/res-localized/values-hu/strings.xml +++ b/twidere/src/main/res-localized/values-hu/strings.xml @@ -756,7 +756,7 @@ Segíts fejleszteni a Twidere-t! Felhasználó blokkolva. Felhasználó: %s - Lista + Lista Részletek listázása Leírás diff --git a/twidere/src/main/res-localized/values-in/strings.xml b/twidere/src/main/res-localized/values-in/strings.xml index 91b3f4295..0d3bb2f70 100644 --- a/twidere/src/main/res-localized/values-in/strings.xml +++ b/twidere/src/main/res-localized/values-in/strings.xml @@ -816,7 +816,7 @@ Bantu kami memperbaiki Twidere! Unlock pengguna ini. Pengguna: %s - Daftar + Daftar Daftar rincian Deskripsi diff --git a/twidere/src/main/res-localized/values-it/strings.xml b/twidere/src/main/res-localized/values-it/strings.xml index eba35eeba..659f70456 100644 --- a/twidere/src/main/res-localized/values-it/strings.xml +++ b/twidere/src/main/res-localized/values-it/strings.xml @@ -733,7 +733,7 @@ Aiutaci a migliorare Twidere! Blocca questo utente. Utente: %s - Lista + Lista Dettagli della lista Descrizione diff --git a/twidere/src/main/res-localized/values-iw/strings.xml b/twidere/src/main/res-localized/values-iw/strings.xml index 64a538ff8..572ec3c1b 100644 --- a/twidere/src/main/res-localized/values-iw/strings.xml +++ b/twidere/src/main/res-localized/values-iw/strings.xml @@ -443,7 +443,7 @@ סטטיסטיקות שימוש משתמש זה נחסם. משתמש: %s - רשימה + רשימה תיאור diff --git a/twidere/src/main/res-localized/values-ja/strings.xml b/twidere/src/main/res-localized/values-ja/strings.xml index 04d6b3eae..febf4ae02 100644 --- a/twidere/src/main/res-localized/values-ja/strings.xml +++ b/twidere/src/main/res-localized/values-ja/strings.xml @@ -1060,7 +1060,7 @@ Twidereの機能向上にご協力ください このユーザーをブロックしました。 ユーザー: %s - リスト + リスト リストの詳細 リストの説明 diff --git a/twidere/src/main/res-localized/values-ko/strings.xml b/twidere/src/main/res-localized/values-ko/strings.xml index b91db6f27..09e880b77 100644 --- a/twidere/src/main/res-localized/values-ko/strings.xml +++ b/twidere/src/main/res-localized/values-ko/strings.xml @@ -937,7 +937,7 @@ Twidere를 보완하는데 도와주세요! 사용자 차단 사용자: %s - 리스트 + 리스트 리스트 상세 정보 설명 diff --git a/twidere/src/main/res-localized/values-ms/strings.xml b/twidere/src/main/res-localized/values-ms/strings.xml index 521bf8208..2c951dc4b 100644 --- a/twidere/src/main/res-localized/values-ms/strings.xml +++ b/twidere/src/main/res-localized/values-ms/strings.xml @@ -188,7 +188,7 @@ Pengguna Trend - Senarai + Senarai Uraian diff --git a/twidere/src/main/res-localized/values-nl/strings.xml b/twidere/src/main/res-localized/values-nl/strings.xml index 1763bc0de..54aeec84d 100644 --- a/twidere/src/main/res-localized/values-nl/strings.xml +++ b/twidere/src/main/res-localized/values-nl/strings.xml @@ -754,7 +754,7 @@ Help ons om Twidere te verbeteren! Deze gebruiker is geblokkeerd. Gebruiker:%s - Lijst + Lijst Lijstdetails Beschrijving diff --git a/twidere/src/main/res-localized/values-no/strings.xml b/twidere/src/main/res-localized/values-no/strings.xml index a2a45ee78..6e61e5b3a 100644 --- a/twidere/src/main/res-localized/values-no/strings.xml +++ b/twidere/src/main/res-localized/values-no/strings.xml @@ -667,7 +667,7 @@ Hjelp oss å forbedre Twidere! Blokkerte denne brukeren. Bruker: %s - Liste + Liste Listedetaljer Beskrivelse diff --git a/twidere/src/main/res-localized/values-pl/strings.xml b/twidere/src/main/res-localized/values-pl/strings.xml index f4ee56348..f29c24d09 100644 --- a/twidere/src/main/res-localized/values-pl/strings.xml +++ b/twidere/src/main/res-localized/values-pl/strings.xml @@ -730,7 +730,7 @@ Pomóż nam ulepszyć Twidere! Zablokowano tego użytkownika. Użytkownik: %s - Lista + Lista Opis diff --git a/twidere/src/main/res-localized/values-pt/strings.xml b/twidere/src/main/res-localized/values-pt/strings.xml index 105eead8a..83b3f835c 100644 --- a/twidere/src/main/res-localized/values-pt/strings.xml +++ b/twidere/src/main/res-localized/values-pt/strings.xml @@ -798,7 +798,7 @@ Ajude-nos a melhorar o Twidere! Usuário bloqueado. Usuário: %s - Lista + Lista Lista de detalhes Descrição diff --git a/twidere/src/main/res-localized/values-ru/strings.xml b/twidere/src/main/res-localized/values-ru/strings.xml index 166a75349..043c2e9f8 100644 --- a/twidere/src/main/res-localized/values-ru/strings.xml +++ b/twidere/src/main/res-localized/values-ru/strings.xml @@ -838,7 +838,7 @@ Помогите нам улучшить Twidere! Заблокировать этого пользователя. Пользователь:%s - Список + Список Детали списка Описание diff --git a/twidere/src/main/res-localized/values-sv/strings.xml b/twidere/src/main/res-localized/values-sv/strings.xml index 1ad7867ff..512386d47 100644 --- a/twidere/src/main/res-localized/values-sv/strings.xml +++ b/twidere/src/main/res-localized/values-sv/strings.xml @@ -1027,7 +1027,7 @@ Hjälp oss förbättra Twidere! Användaren är blockerad. Användare: %s - Lista + Lista Lista deajer Beskrivning diff --git a/twidere/src/main/res-localized/values-te/strings.xml b/twidere/src/main/res-localized/values-te/strings.xml index 7b318f997..a5516475d 100644 --- a/twidere/src/main/res-localized/values-te/strings.xml +++ b/twidere/src/main/res-localized/values-te/strings.xml @@ -127,7 +127,7 @@ పోకడలు గుర్తుతెలియని భాష - జాబితా + జాబితా జాబితా వివరాలు diff --git a/twidere/src/main/res-localized/values-th/strings.xml b/twidere/src/main/res-localized/values-th/strings.xml index 146fe7653..20acfd513 100644 --- a/twidere/src/main/res-localized/values-th/strings.xml +++ b/twidere/src/main/res-localized/values-th/strings.xml @@ -1043,7 +1043,7 @@ มาช่วยเราปรับปรุง Twidere! บล็อคผู้ใช้นี้แล้ว ผู้ใช้: %s - รายการ + รายการ รายละเอียดลิสต์ คำอธิบาย diff --git a/twidere/src/main/res-localized/values-tr/strings.xml b/twidere/src/main/res-localized/values-tr/strings.xml index 96aad884b..4df67d8bd 100644 --- a/twidere/src/main/res-localized/values-tr/strings.xml +++ b/twidere/src/main/res-localized/values-tr/strings.xml @@ -759,7 +759,7 @@ Twidere\'yi geliştirmemize yardımcı ol! Bu kullanıcıyı engellediniz. Kullanıcı: %s - Liste + Liste Liste ayrıntıları Açıklama diff --git a/twidere/src/main/res-localized/values-uk/strings.xml b/twidere/src/main/res-localized/values-uk/strings.xml index 7b5850cd1..7c230f276 100644 --- a/twidere/src/main/res-localized/values-uk/strings.xml +++ b/twidere/src/main/res-localized/values-uk/strings.xml @@ -761,7 +761,7 @@ Допоможіть нам покращити Twidere! Заблокував цього користувача. Користувач: %s - Список + Список Дані списку Опис diff --git a/twidere/src/main/res-localized/values-zh-rCN/strings.xml b/twidere/src/main/res-localized/values-zh-rCN/strings.xml index 03597347c..24fa89087 100644 --- a/twidere/src/main/res-localized/values-zh-rCN/strings.xml +++ b/twidere/src/main/res-localized/values-zh-rCN/strings.xml @@ -1051,7 +1051,7 @@ 帮助我们改进 Twidere! 您阻止了这位用户 用户:%s - 列表 + 列表 列表详情 简介 diff --git a/twidere/src/main/res-localized/values-zh-rHK/strings.xml b/twidere/src/main/res-localized/values-zh-rHK/strings.xml index ca578dc99..47643c7b3 100644 --- a/twidere/src/main/res-localized/values-zh-rHK/strings.xml +++ b/twidere/src/main/res-localized/values-zh-rHK/strings.xml @@ -1054,7 +1054,7 @@ 幫助我們改進Twidere! 您封鎖了這個使用者 使用者:%s - 列表 + 列表 列表詳情 簡介 diff --git a/twidere/src/main/res-localized/values-zh/strings.xml b/twidere/src/main/res-localized/values-zh/strings.xml index ca578dc99..47643c7b3 100644 --- a/twidere/src/main/res-localized/values-zh/strings.xml +++ b/twidere/src/main/res-localized/values-zh/strings.xml @@ -1054,7 +1054,7 @@ 幫助我們改進Twidere! 您封鎖了這個使用者 使用者:%s - 列表 + 列表 列表詳情 簡介 diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index f4ea395a9..1b4a4e1c8 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -1230,6 +1230,7 @@ Sync settings User User colors + List Belongs to Created Subscriptions @@ -1297,7 +1298,6 @@ Blocked this user. User: %s - List List details Description