diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java index e1445564d..eb42a8b16 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java @@ -186,6 +186,7 @@ public interface IntentConstants { String EXTRA_RECREATE_ACTIVITY = "recreate_activity"; String EXTRA_SHOULD_RECREATE = "should_recreate"; String EXTRA_SHOULD_RESTART = "should_restart"; + String EXTRA_SHOULD_TERMINATE = "should_terminate"; String EXTRA_FROM_USER = "from_user"; String EXTRA_SHOW_MEDIA_PREVIEW = "show_media_preview"; String EXTRA_SHOW_EXTRA_TYPE = "show_extra_type"; diff --git a/twidere/src/main/AndroidManifest.xml b/twidere/src/main/AndroidManifest.xml index dc8090365..2e3dac36b 100644 --- a/twidere/src/main/AndroidManifest.xml +++ b/twidere/src/main/AndroidManifest.xml @@ -511,11 +511,12 @@ diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/AccountsListPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/AccountsListPreference.java index 16586ac7b..17e52ec11 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/AccountsListPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/AccountsListPreference.java @@ -28,7 +28,6 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.internal.widget.PreferenceImageView; import android.support.v7.preference.Preference; -import android.support.v7.preference.PreferenceCategory; import android.support.v7.preference.PreferenceManager; import android.support.v7.preference.PreferenceViewHolder; import android.support.v7.widget.SwitchCompat; @@ -46,22 +45,14 @@ import org.mariotaku.twidere.util.dagger.GeneralComponentHelper; import javax.inject.Inject; -public abstract class AccountsListPreference extends PreferenceCategory implements Constants { +public abstract class AccountsListPreference extends TintedPreferenceCategory implements Constants { @Nullable private final String mSwitchKey; private final boolean mSwitchDefault; - public AccountsListPreference(final Context context) { - this(context, null); - } - public AccountsListPreference(final Context context, final AttributeSet attrs) { - this(context, attrs, R.attr.preferenceCategoryStyle); - } - - public AccountsListPreference(final Context context, final AttributeSet attrs, final int defStyle) { - super(context, attrs, defStyle); + super(context, attrs); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AccountsListPreference); mSwitchKey = a.getString(R.styleable.AccountsListPreference_switchKey); mSwitchDefault = a.getBoolean(R.styleable.AccountsListPreference_switchDefault, false); diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/AutoRefreshAccountsListPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/AutoRefreshAccountsListPreference.java index cfcdf4c6c..b507a856b 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/AutoRefreshAccountsListPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/AutoRefreshAccountsListPreference.java @@ -28,18 +28,10 @@ import org.mariotaku.twidere.model.AccountDetails; public class AutoRefreshAccountsListPreference extends AccountsListPreference { - public AutoRefreshAccountsListPreference(final Context context) { - super(context); - } - public AutoRefreshAccountsListPreference(final Context context, final AttributeSet attrs) { super(context, attrs); } - public AutoRefreshAccountsListPreference(final Context context, final AttributeSet attrs, final int defStyle) { - super(context, attrs, defStyle); - } - @Override protected void setupPreference(final AccountItemPreference preference, final AccountDetails account) { preference.setFragment(AccountRefreshSettingsFragment.class.getName()); diff --git a/twidere/src/main/java/org/mariotaku/twidere/preference/NotificationAccountsListPreference.java b/twidere/src/main/java/org/mariotaku/twidere/preference/NotificationAccountsListPreference.java index 0316d396b..d59c783ab 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/preference/NotificationAccountsListPreference.java +++ b/twidere/src/main/java/org/mariotaku/twidere/preference/NotificationAccountsListPreference.java @@ -28,18 +28,10 @@ import org.mariotaku.twidere.model.AccountDetails; public class NotificationAccountsListPreference extends AccountsListPreference { - public NotificationAccountsListPreference(final Context context) { - super(context); - } - public NotificationAccountsListPreference(final Context context, final AttributeSet attrs) { super(context, attrs); } - public NotificationAccountsListPreference(final Context context, final AttributeSet attrs, final int defStyle) { - super(context, attrs, defStyle); - } - @Override protected void setupPreference(final AccountItemPreference preference, final AccountDetails account) { preference.setFragment(AccountNotificationSettingsFragment.class.getName()); diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SettingsActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SettingsActivity.kt index 2e2d10e0d..91cf19fad 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SettingsActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/SettingsActivity.kt @@ -40,6 +40,8 @@ import android.view.ViewGroup import android.widget.* import android.widget.AdapterView.OnItemClickListener import kotlinx.android.synthetic.main.activity_settings.* +import org.mariotaku.ktextension.Bundle +import org.mariotaku.ktextension.set import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.KeyboardShortcutConstants.ACTION_NAVIGATION_BACK @@ -55,16 +57,23 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF var shouldRecreate: Boolean = false var shouldRestart: Boolean = false + var shouldTerminate: Boolean = false private lateinit var entriesAdapter: EntriesAdapter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_settings) + entriesAdapter = EntriesAdapter(this) if (savedInstanceState != null) { shouldRecreate = savedInstanceState.getBoolean(EXTRA_SHOULD_RECREATE, shouldRecreate) shouldRestart = savedInstanceState.getBoolean(EXTRA_SHOULD_RESTART, shouldRestart) + shouldTerminate = savedInstanceState.getBoolean(EXTRA_SHOULD_TERMINATE, shouldTerminate) + } else if (intent.getBooleanExtra(EXTRA_SHOULD_TERMINATE, false)) { + finishNoRestart() + System.exit(0) + return } val backgroundAlpha = currentThemeBackgroundAlpha @@ -74,7 +83,7 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF slidingPane.setShadowResourceLeft(R.drawable.sliding_pane_shadow_left) slidingPane.setShadowResourceRight(R.drawable.sliding_pane_shadow_right) slidingPane.sliderFadeColor = 0 - entriesAdapter = EntriesAdapter(this) + initEntries() entriesList.adapter = entriesAdapter entriesList.choiceMode = AbsListView.CHOICE_MODE_SINGLE @@ -110,6 +119,7 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF if (resultCode == RESULT_SETTINGS_CHANGED && data != null) { shouldRecreate = data.getBooleanExtra(EXTRA_SHOULD_RECREATE, false) shouldRestart = data.getBooleanExtra(EXTRA_SHOULD_RESTART, false) + shouldTerminate = data.getBooleanExtra(EXTRA_SHOULD_TERMINATE, false) } super.onActivityResult(requestCode, resultCode, data) } @@ -243,12 +253,13 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF } private fun notifyUnsavedChange(): Boolean { - if (isTopSettings && (shouldRecreate || shouldRestart)) { + if (isTopSettings && (shouldRecreate || shouldRestart || shouldTerminate)) { val df = RestartConfirmDialogFragment() - val args = Bundle() - args.putBoolean(EXTRA_SHOULD_RECREATE, shouldRecreate) - args.putBoolean(EXTRA_SHOULD_RESTART, shouldRestart) - df.arguments = args + df.arguments = Bundle { + this[EXTRA_SHOULD_RECREATE] = shouldRecreate + this[EXTRA_SHOULD_RESTART] = shouldRestart + this[EXTRA_SHOULD_TERMINATE] = shouldTerminate + } df.show(supportFragmentManager, "restart_confirm") return true } @@ -364,9 +375,14 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF class RestartConfirmDialogFragment : BaseDialogFragment(), DialogInterface.OnClickListener { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val builder = AlertDialog.Builder(activity) - builder.setMessage(R.string.app_restart_confirm) + if (arguments.getBoolean(EXTRA_SHOULD_TERMINATE)) { + builder.setMessage(R.string.app_terminate_confirm) + builder.setNegativeButton(R.string.action_dont_terminate, this) + } else { + builder.setMessage(R.string.app_restart_confirm) + builder.setNegativeButton(R.string.action_dont_restart, this) + } builder.setPositiveButton(android.R.string.ok, this) - builder.setNegativeButton(R.string.dont_restart, this) val dialog = builder.create() dialog.setOnShowListener { it as AlertDialog @@ -379,7 +395,14 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF val activity = activity as SettingsActivity when (which) { DialogInterface.BUTTON_POSITIVE -> { - activity.finish() + if (arguments.getBoolean(EXTRA_SHOULD_TERMINATE)) { + val intent = Intent(context, SettingsActivity::class.java) + intent.putExtra(EXTRA_SHOULD_TERMINATE, true) + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) + activity.startActivity(intent) + } else { + activity.finish() + } } DialogInterface.BUTTON_NEGATIVE -> { activity.finishNoRestart() @@ -403,6 +426,11 @@ class SettingsActivity : BaseActivity(), OnItemClickListener, OnPreferenceStartF if (activity !is SettingsActivity) return activity.shouldRestart = true } + + fun setShouldTerminate(activity: Activity) { + if (activity !is SettingsActivity) return + activity.shouldTerminate = true + } } 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 81df3a71a..da1ca0f77 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt @@ -9,6 +9,7 @@ import org.mariotaku.twidere.BuildConfig import org.mariotaku.twidere.Constants.* import org.mariotaku.twidere.TwidereConstants.KEY_MEDIA_PRELOAD import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.annotation.PreviewStyle import org.mariotaku.twidere.constant.SharedPreferenceConstants.VALUE_MEDIA_PREVIEW_STYLE_REAL_SIZE import org.mariotaku.twidere.extension.getNonEmptyString import org.mariotaku.twidere.model.CustomAPIConfig @@ -17,7 +18,6 @@ import org.mariotaku.twidere.model.account.cred.Credentials import org.mariotaku.twidere.model.sync.SyncProviderInfo import org.mariotaku.twidere.preference.ThemeBackgroundPreference import org.mariotaku.twidere.util.sync.SyncProviderInfoFactory -import org.mariotaku.twidere.annotation.PreviewStyle import org.mariotaku.twidere.view.ProfileImageView /** @@ -63,6 +63,7 @@ val lightFontKey = KBooleanKey("light_font", false) val extraFeaturesNoticeVersionKey = KIntKey("extra_features_notice_version", 0) val mediaPreloadKey = KBooleanKey(KEY_MEDIA_PRELOAD, false) val mediaPreloadOnWifiOnlyKey = KBooleanKey(KEY_PRELOAD_WIFI_ONLY, true) +val autoRefreshCompatibilityModeKey = KBooleanKey("auto_refresh_compatibility_mode", Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) object themeBackgroundAlphaKey : KSimpleKey(KEY_THEME_BACKGROUND_ALPHA, 0xFF) { override fun read(preferences: SharedPreferences): Int { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SettingsDetailsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SettingsDetailsFragment.kt index fb3899540..d75b9ab99 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SettingsDetailsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/SettingsDetailsFragment.kt @@ -25,6 +25,7 @@ import android.os.Bundle import android.support.v7.preference.PreferenceScreen import org.mariotaku.twidere.Constants.* import org.mariotaku.twidere.activity.SettingsActivity +import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SHOULD_TERMINATE import org.mariotaku.twidere.util.Utils class SettingsDetailsFragment : BasePreferenceFragment(), OnSharedPreferenceChangeListener { @@ -74,6 +75,8 @@ class SettingsDetailsFragment : BasePreferenceFragment(), OnSharedPreferenceChan SettingsActivity.setShouldRestart(activity) } else if (extras.containsKey(EXTRA_SHOULD_RECREATE)) { SettingsActivity.setShouldRecreate(activity) + }else if (extras.containsKey(EXTRA_SHOULD_TERMINATE)) { + SettingsActivity.setShouldTerminate(activity) } if (extras.containsKey(EXTRA_RECREATE_ACTIVITY)) { activity.recreate() diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt index c84b550a5..28c25753b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt @@ -22,7 +22,6 @@ package org.mariotaku.twidere.loader import android.content.Context import android.database.sqlite.SQLiteDatabase import android.support.annotation.WorkerThread -import android.text.TextUtils import org.mariotaku.commons.parcel.ParcelUtils import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException @@ -117,11 +116,7 @@ class ConversationLoader( } query.sinceId(sinceId ?: status.id) try { - for (item in twitter.search(query)) { - if (TextUtils.equals(item.inReplyToStatusId, status.id)) { - statuses.add(item) - } - } + twitter.search(query).filterTo(statuses) { it.inReplyToStatusId == status.id } } catch (e: MicroBlogException) { // Ignore for now } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/preference/HiddenSettingEntryPreference.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/HiddenSettingEntryPreference.kt index dc207a279..cd09838c8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/preference/HiddenSettingEntryPreference.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/HiddenSettingEntryPreference.kt @@ -3,7 +3,6 @@ package org.mariotaku.twidere.preference import android.content.Context import android.content.Intent import android.support.v7.preference.Preference -import android.support.v7.preference.PreferenceCategory import android.support.v7.preference.PreferenceManager import android.util.AttributeSet import org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_HIDDEN_SETTINGS_ENTRY @@ -11,11 +10,10 @@ import org.mariotaku.twidere.constant.IntentConstants.INTENT_ACTION_HIDDEN_SETTI /** * Created by mariotaku on 2016/12/12. */ -class HiddenSettingEntryPreference @JvmOverloads constructor( +class HiddenSettingEntryPreference( context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = android.support.v7.preference.R.attr.preferenceCategoryStyle -) : PreferenceCategory(context, attrs, defStyleAttr) { + attrs: AttributeSet? = null +) : TintedPreferenceCategory(context, attrs) { override fun onAttachedToHierarchy(preferenceManager: PreferenceManager?, id: Long) { super.onAttachedToHierarchy(preferenceManager, id) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/preference/TintedPreferenceCategory.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/TintedPreferenceCategory.kt index 76e45aa8d..4497217a4 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/preference/TintedPreferenceCategory.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/preference/TintedPreferenceCategory.kt @@ -12,7 +12,7 @@ import org.mariotaku.chameleon.ChameleonUtils * Created by mariotaku on 2017/2/5. */ -class TintedPreferenceCategory(context: Context, attrs: AttributeSet? = null) : PreferenceCategory(context, attrs) { +open class TintedPreferenceCategory(context: Context, attrs: AttributeSet? = null) : PreferenceCategory(context, attrs) { override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) val theme = Chameleon.getOverrideTheme(context, ChameleonUtils.getActivity(context)) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/JobTaskService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/JobTaskService.kt index 5ce5faa2a..1098ead25 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/JobTaskService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/JobTaskService.kt @@ -24,7 +24,9 @@ import android.annotation.TargetApi import android.app.job.JobParameters import android.app.job.JobService import android.os.Build +import org.mariotaku.kpreferences.KPreferences import org.mariotaku.twidere.annotation.AutoRefreshType +import org.mariotaku.twidere.constant.autoRefreshCompatibilityModeKey import org.mariotaku.twidere.util.TaskServiceRunner import org.mariotaku.twidere.util.dagger.GeneralComponentHelper import org.mariotaku.twidere.util.support.JobServiceSupport @@ -39,6 +41,8 @@ class JobTaskService : JobService() { @Inject internal lateinit var taskServiceRunner: TaskServiceRunner + @Inject + internal lateinit var kPreferences: KPreferences override fun onCreate() { super.onCreate() @@ -46,6 +50,7 @@ class JobTaskService : JobService() { } override fun onStartJob(params: JobParameters): Boolean { + if (kPreferences[autoRefreshCompatibilityModeKey]) return false val action = getTaskAction(params.jobId) ?: return false return taskServiceRunner.runTask(action) { this.jobFinished(params, false) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/LegacyTaskService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/LegacyTaskService.kt index d32096265..ae8dcc434 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/LegacyTaskService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/LegacyTaskService.kt @@ -21,8 +21,11 @@ package org.mariotaku.twidere.service import android.app.Service import android.content.Intent +import android.os.Build import android.os.IBinder +import org.mariotaku.kpreferences.KPreferences import org.mariotaku.twidere.annotation.AutoRefreshType +import org.mariotaku.twidere.constant.autoRefreshCompatibilityModeKey import org.mariotaku.twidere.util.TaskServiceRunner import org.mariotaku.twidere.util.TaskServiceRunner.Companion.ACTION_REFRESH_DIRECT_MESSAGES import org.mariotaku.twidere.util.TaskServiceRunner.Companion.ACTION_REFRESH_HOME_TIMELINE @@ -34,6 +37,8 @@ class LegacyTaskService : Service() { @Inject internal lateinit var taskServiceRunner: TaskServiceRunner + @Inject + internal lateinit var kPreferences: KPreferences override fun onBind(intent: Intent): IBinder? = null @@ -43,6 +48,8 @@ class LegacyTaskService : Service() { } override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && + !kPreferences[autoRefreshCompatibilityModeKey]) return START_NOT_STICKY val action = intent?.action ?: return START_NOT_STICKY taskServiceRunner.runTask(action) { stopSelfResult(startId) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt index 59e3c8eec..d725a1ad7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt @@ -12,7 +12,8 @@ import org.mariotaku.microblog.library.twitter.model.DirectMessage import org.mariotaku.microblog.library.twitter.model.ErrorInfo import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.ResponseList -import org.mariotaku.twidere.TwidereConstants +import org.mariotaku.twidere.TwidereConstants.LOGTAG +import org.mariotaku.twidere.TwidereConstants.QUERY_PARAM_NOTIFY import org.mariotaku.twidere.constant.loadItemLimitKey import org.mariotaku.twidere.model.RefreshTaskParam import org.mariotaku.twidere.model.UserKey @@ -88,7 +89,7 @@ abstract class GetDirectMessagesTask( } else if (e.isCausedByNetworkIssue) { errorInfoStore[ErrorInfoStore.KEY_DIRECT_MESSAGES, accountKey] = ErrorInfoStore.CODE_NETWORK_ERROR } - DebugLog.w(TwidereConstants.LOGTAG, tr = e) + DebugLog.w(LOGTAG, tr = e) result.add(TwitterWrapper.MessageListResponse(accountKey, e)) } @@ -111,7 +112,7 @@ abstract class GetDirectMessagesTask( // Insert previously fetched items. - val insertUri = UriUtils.appendQueryParameters(uri, TwidereConstants.QUERY_PARAM_NOTIFY, notify) + val insertUri = UriUtils.appendQueryParameters(uri, QUERY_PARAM_NOTIFY, notify) ContentResolverUtils.bulkInsert(context.contentResolver, insertUri, valuesArray) return false } 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 d56745bcf..80df575ed 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 @@ -48,6 +48,7 @@ import org.mariotaku.twidere.BuildConfig 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 import org.mariotaku.twidere.util.* import org.mariotaku.twidere.util.imageloader.ReadOnlyDiskLRUNameCache @@ -249,7 +250,7 @@ class ApplicationModule(private val application: Application) { @Provides @Singleton fun autoRefreshController(kPreferences: KPreferences): AutoRefreshController { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !kPreferences[autoRefreshCompatibilityModeKey]) { return JobSchedulerAutoRefreshController(application, kPreferences) } return LegacyAutoRefreshController(application, kPreferences) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/AutoRefreshController.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/AutoRefreshController.kt index fafd7eb2a..8f51c8541 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/AutoRefreshController.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/AutoRefreshController.kt @@ -19,12 +19,12 @@ abstract class AutoRefreshController( abstract fun unschedule(@AutoRefreshType type: String) - fun reschedule(@AutoRefreshType type: String) { + open fun reschedule(@AutoRefreshType type: String) { unschedule(type) schedule(type) } - fun rescheduleAll() { + open fun rescheduleAll() { AutoRefreshType.ALL.forEach { reschedule(it) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/LegacyAutoRefreshController.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/LegacyAutoRefreshController.kt index 1de890efe..1b86931f9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/LegacyAutoRefreshController.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/refresh/LegacyAutoRefreshController.kt @@ -1,14 +1,18 @@ package org.mariotaku.twidere.util.refresh +import android.annotation.TargetApi import android.app.AlarmManager import android.app.PendingIntent +import android.app.job.JobScheduler import android.content.Context import android.content.Intent +import android.os.Build import android.os.SystemClock import android.support.v4.util.ArrayMap import org.mariotaku.kpreferences.KPreferences import org.mariotaku.twidere.annotation.AutoRefreshType import org.mariotaku.twidere.constant.refreshIntervalKey +import org.mariotaku.twidere.service.JobTaskService.Companion.JOB_IDS_REFRESH import org.mariotaku.twidere.service.LegacyTaskService import org.mariotaku.twidere.util.TaskServiceRunner.Companion.ACTION_REFRESH_FILTERS_SUBSCRIPTIONS import java.util.concurrent.TimeUnit @@ -35,6 +39,13 @@ class LegacyAutoRefreshController( rescheduleFiltersSubscriptionsRefresh() } + override fun rescheduleAll() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + removeAllJobs(context) + } + super.rescheduleAll() + } + override fun unschedule(type: String) { val pendingIntent = pendingIntents[type] ?: return alarmManager.cancel(pendingIntent) @@ -58,4 +69,15 @@ class LegacyAutoRefreshController( PendingIntent.getService(context, 0, intent, 0)) } + private companion object { + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + fun removeAllJobs(context: Context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return + val jobService = context.getSystemService(Context.JOB_SCHEDULER_SERVICE) as JobScheduler + JOB_IDS_REFRESH.forEach { id -> + jobService.cancel(id) + } + } + } + } \ No newline at end of file diff --git a/twidere/src/main/res-localized/values-ast/strings.xml b/twidere/src/main/res-localized/values-ast/strings.xml index 4f984d52d..c24a61cca 100644 --- a/twidere/src/main/res-localized/values-ast/strings.xml +++ b/twidere/src/main/res-localized/values-ast/strings.xml @@ -272,7 +272,7 @@ Amuesa na llinia temporal conteníos sensibles ensin avisar Sirvidor DNS Afita\'l sirvidor DNS pa solicitúes de rede. - Nun reaniciar + Nun reaniciar Guardóse\'l borrador Equí guardaránse los tos tuits ensin unviar Alternancia de caxones diff --git a/twidere/src/main/res-localized/values-ca/strings.xml b/twidere/src/main/res-localized/values-ca/strings.xml index 543d6ceea..a938a15d2 100644 --- a/twidere/src/main/res-localized/values-ca/strings.xml +++ b/twidere/src/main/res-localized/values-ca/strings.xml @@ -248,7 +248,7 @@ Mostra continguts sensibles a la cronologia sense previ avís Servidor DNS Estableix el servidor DNS per a convertir les URL a adreces IP. - No reiniciïs + No reiniciïs S\'ha desat l\'esborrany Els esborranys de piulada es desaran aquí Barra lateral diff --git a/twidere/src/main/res-localized/values-de/strings.xml b/twidere/src/main/res-localized/values-de/strings.xml index 815c5de70..03a7647e2 100644 --- a/twidere/src/main/res-localized/values-de/strings.xml +++ b/twidere/src/main/res-localized/values-de/strings.xml @@ -276,7 +276,7 @@ Zeige heiklen Inhalt ohne Warnung in der Zeitleiste DNS-Server DNS-Server für Netzwerkanfragen einstellen. - Nicht neustarten + Nicht neustarten Entwurf gespeichert Nicht gesendete Tweets werden hier gespeichert Drawer-Schalter diff --git a/twidere/src/main/res-localized/values-es/strings.xml b/twidere/src/main/res-localized/values-es/strings.xml index 95d4e83e0..0126028e4 100644 --- a/twidere/src/main/res-localized/values-es/strings.xml +++ b/twidere/src/main/res-localized/values-es/strings.xml @@ -272,7 +272,7 @@ Mostrar contenidos sensibles en la cronología sin aviso Servidor DNS Configure el servidor DNS para peticiones de red. - No reinicie + No reinicie Borrador guardado Tus tweets sin enviar se guardarán aquí Barra lateral diff --git a/twidere/src/main/res-localized/values-fa/strings.xml b/twidere/src/main/res-localized/values-fa/strings.xml index b498883d5..c2b833ca3 100644 --- a/twidere/src/main/res-localized/values-fa/strings.xml +++ b/twidere/src/main/res-localized/values-fa/strings.xml @@ -256,7 +256,7 @@ نمایش بدون هشدار محتوای حسّاسیت‌برانگیر در خط زمانی کارگزار DNS تنظیم کارساز نام دامنه برای درخواست‌های شبکه. - عدم شروع مجدّد + عدم شروع مجدّد چرک‌نویس ذخیره شد توییت‌های فرستاده نشده‌تان این‌حا ذخیره می‌شوند تغییر وضعیت کشو diff --git a/twidere/src/main/res-localized/values-fi/strings.xml b/twidere/src/main/res-localized/values-fi/strings.xml index bc3f11d7c..7d85d66ff 100644 --- a/twidere/src/main/res-localized/values-fi/strings.xml +++ b/twidere/src/main/res-localized/values-fi/strings.xml @@ -252,7 +252,7 @@ Näytä arkaluontoinen sisältö ilman aikajanan varoituksia DNS-palvelin Aseta verkkopyynnöille DNS-palvelin. - Älä käynnistä uudelleen + Älä käynnistä uudelleen Luonnos tallennettu Twiittiluonnoksesi tallennetaan tänne Muokkaa API:a diff --git a/twidere/src/main/res-localized/values-fr/strings.xml b/twidere/src/main/res-localized/values-fr/strings.xml index e6ed21e0e..1419e1ffe 100644 --- a/twidere/src/main/res-localized/values-fr/strings.xml +++ b/twidere/src/main/res-localized/values-fr/strings.xml @@ -276,7 +276,7 @@ Afficher le contenu qui peut être sensible sans avertissement dans votre fil d\'actualité Serveur DNS Définir le serveur DNS pour les résolutions. - Ne pas redémarrer + Ne pas redémarrer Brouillon sauvegardé Vos tweets non-envoyés sont sauvés ici Afficher le bouton du menu latéral diff --git a/twidere/src/main/res-localized/values-gl/strings.xml b/twidere/src/main/res-localized/values-gl/strings.xml index a24f4acce..10bc497c8 100644 --- a/twidere/src/main/res-localized/values-gl/strings.xml +++ b/twidere/src/main/res-localized/values-gl/strings.xml @@ -249,7 +249,7 @@ Amosa contidos sensibles na liña de tempo sen advertencia Servidor DNS Introduce o Servidor DNS para peticións de rede. - Non reiniciar + Non reiniciar Borrador gardado Aquí gárdanse os teus chíos non enviados Conmutar caixón diff --git a/twidere/src/main/res-localized/values-hr/strings.xml b/twidere/src/main/res-localized/values-hr/strings.xml index 6ad4e2be4..cead13332 100644 --- a/twidere/src/main/res-localized/values-hr/strings.xml +++ b/twidere/src/main/res-localized/values-hr/strings.xml @@ -201,7 +201,7 @@ Prikaži osvjetljive sadržaje Prikaži osjetljive sadržaje bez obavijesti u timelineu DNS Server - Nemoj ponovno pokrenuti + Nemoj ponovno pokrenuti Skica spremljena Vaši neposlani tweetevi bit će spremljeni ovdje Uredi API diff --git a/twidere/src/main/res-localized/values-hu/strings.xml b/twidere/src/main/res-localized/values-hu/strings.xml index d19cb9651..27829596f 100644 --- a/twidere/src/main/res-localized/values-hu/strings.xml +++ b/twidere/src/main/res-localized/values-hu/strings.xml @@ -258,7 +258,7 @@ Érzékeny információk megjelenítése a kezdőlapon figyelmeztetés nélkül DNS kiszolgáló DNS szerver kijelölése a hálózati lekérésekhez. - Ne induljon újra + Ne induljon újra Piszkozat elmentve Ide lesznek mentve az el nem küldött tweetjeid API szerkesztése diff --git a/twidere/src/main/res-localized/values-in/strings.xml b/twidere/src/main/res-localized/values-in/strings.xml index b7f745ab0..8726cf9a0 100644 --- a/twidere/src/main/res-localized/values-in/strings.xml +++ b/twidere/src/main/res-localized/values-in/strings.xml @@ -268,7 +268,7 @@ Tampilkan konten yang sensitif di timeline tanpa pemberitahuan. Server DNS Atur DNS Server untuk permintaan jaringan. - Jangan memulai ulang + Jangan memulai ulang Draft tersimpan Tweet Anda yang belum terkirim akan tersimpan disini Tombol laci diff --git a/twidere/src/main/res-localized/values-it/strings.xml b/twidere/src/main/res-localized/values-it/strings.xml index 81f94f073..251489a68 100644 --- a/twidere/src/main/res-localized/values-it/strings.xml +++ b/twidere/src/main/res-localized/values-it/strings.xml @@ -248,7 +248,7 @@ Mostra contenuti sensibili senza preavviso in timeline DNS Server Imposta il server DNS per le richieste di rete. - Non riavviare + Non riavviare Progetto salvato I tuoi tweet non inviati saranno salvati qui Edit API diff --git a/twidere/src/main/res-localized/values-ja/strings.xml b/twidere/src/main/res-localized/values-ja/strings.xml index a6ad905da..a46644eb6 100644 --- a/twidere/src/main/res-localized/values-ja/strings.xml +++ b/twidere/src/main/res-localized/values-ja/strings.xml @@ -276,7 +276,7 @@ プロンプトを表示せずに不適切な可能性のある内容を表示します。 DNS サーバー ネットワーク要件に使用されるDNSサーバーを設定します。 - 再起動しない + 再起動しない 下書きを保存 未送信のツイートが保存されます ドロワーの切り替え diff --git a/twidere/src/main/res-localized/values-ko/strings.xml b/twidere/src/main/res-localized/values-ko/strings.xml index 73732562f..107b15270 100644 --- a/twidere/src/main/res-localized/values-ko/strings.xml +++ b/twidere/src/main/res-localized/values-ko/strings.xml @@ -248,7 +248,7 @@ 타임라인에서 경고 없이 민감한 콘텐츠 표시 DNS 서버 네트워크 요청을 위해 DNS 서버를 설정. - 재시작하지 않기 + 재시작하지 않기 임시 저장됨 전송되지 않은 트윗은 여기에 보관됩니다 대시보드 아이콘 보이기 diff --git a/twidere/src/main/res-localized/values-nl/strings.xml b/twidere/src/main/res-localized/values-nl/strings.xml index d757f8af2..602bc20a5 100644 --- a/twidere/src/main/res-localized/values-nl/strings.xml +++ b/twidere/src/main/res-localized/values-nl/strings.xml @@ -248,7 +248,7 @@ Toon gevoelige inhoud zonder kennisgeving in tijdlijn DNS-server Stel DNS-server in voor netwerkverkeer. - Niet herstarten + Niet herstarten Concept opgeslagen Je niet-verzonden tweets worden hier opgeslagen Knop voor navigatiemenu diff --git a/twidere/src/main/res-localized/values-no/strings.xml b/twidere/src/main/res-localized/values-no/strings.xml index 8ffbcd426..b0498c3cc 100644 --- a/twidere/src/main/res-localized/values-no/strings.xml +++ b/twidere/src/main/res-localized/values-no/strings.xml @@ -226,7 +226,7 @@ Vis sensitivt innhold Vis sensitivt innhold i tidslinjen uten forvarsel DNS-server - Ikke start på nytt + Ikke start på nytt Utkast lagret Dine usendte tweets lagres her Endre API diff --git a/twidere/src/main/res-localized/values-pl/strings.xml b/twidere/src/main/res-localized/values-pl/strings.xml index f81ef6c4f..0344521b2 100644 --- a/twidere/src/main/res-localized/values-pl/strings.xml +++ b/twidere/src/main/res-localized/values-pl/strings.xml @@ -182,7 +182,7 @@ Wyświetlaj wrażliwą zawartość bez powiadomienia w strumieniu DNS Server Ręcznie ustaw adres serwera DNS. - Nie uruchamiaj ponownie + Nie uruchamiaj ponownie Edytuj API Edytuj szkic Edytuj zakładkę diff --git a/twidere/src/main/res-localized/values-pt/strings.xml b/twidere/src/main/res-localized/values-pt/strings.xml index 54c3f6c6e..62e532ca1 100644 --- a/twidere/src/main/res-localized/values-pt/strings.xml +++ b/twidere/src/main/res-localized/values-pt/strings.xml @@ -254,7 +254,7 @@ Exibir conteúdo sensível sem avisar Servidor DNS Definir o Servidor de DNS para solicitações de rede. - Não reiniciar + Não reiniciar Rascunho salvo Os teus tweets não enviados vão ser guardados aqui Alternador de gaveta diff --git a/twidere/src/main/res-localized/values-ru/strings.xml b/twidere/src/main/res-localized/values-ru/strings.xml index 2d2d21e93..a4490142e 100644 --- a/twidere/src/main/res-localized/values-ru/strings.xml +++ b/twidere/src/main/res-localized/values-ru/strings.xml @@ -270,7 +270,7 @@ Показывать особый контент в ленте без предупреждения DNS-сервер Укажите DNS-сервер для сетевых запросов. - Не перезапускать + Не перезапускать Черновик сохранен Здесь сохраняются ваши неотправленные твиты Отобразить шторку diff --git a/twidere/src/main/res-localized/values-th/strings.xml b/twidere/src/main/res-localized/values-th/strings.xml index ebbcd2931..29e65ba7b 100644 --- a/twidere/src/main/res-localized/values-th/strings.xml +++ b/twidere/src/main/res-localized/values-th/strings.xml @@ -252,7 +252,7 @@ แสดงเนื้อหาล่อแหลมโดยไม่ต้องแจ้งเตือนบนไทม์ไลน์ เซิร์ฟเวอร์ DNS ตั้งค่าเซิร์ฟเวอร์ DNS สำหรับการร้องขอเครือข่าย - อย่าเพิ่งสิ + อย่าเพิ่งสิ บันทึกข้อความร่างแล้ว ข้อความร่างของคุณถูกบันทึกไว้ที่นี่ สลับลิ้นชัก diff --git a/twidere/src/main/res-localized/values-tr/strings.xml b/twidere/src/main/res-localized/values-tr/strings.xml index 47d5d1e7f..7e46324a4 100644 --- a/twidere/src/main/res-localized/values-tr/strings.xml +++ b/twidere/src/main/res-localized/values-tr/strings.xml @@ -251,7 +251,7 @@ Hassas içeriği uyarmadan zaman akışında görüntüle DNS Sunucusu Ağ istekleri için DNS sunucusu ayarlayın. - Yeniden başlatma + Yeniden başlatma Taslak kaydedildi Gönderilmemiş tweetleri buradan kurtarabilirsiniz Çekmeceyi aç/kapat diff --git a/twidere/src/main/res-localized/values-uk/strings.xml b/twidere/src/main/res-localized/values-uk/strings.xml index e98373425..bfc953920 100644 --- a/twidere/src/main/res-localized/values-uk/strings.xml +++ b/twidere/src/main/res-localized/values-uk/strings.xml @@ -252,7 +252,7 @@ Відображати делікатний вміст без попередження у стрічці DNS сервер Встановлення DNS серверу для мережевих запитів. - Не перезаванатажувати + Не перезаванатажувати Чернетку збережено Тут зберігаються невідправлені твіти Перемикач бічної панелі 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 1c8b38ec0..8280eb881 100644 --- a/twidere/src/main/res-localized/values-zh-rCN/strings.xml +++ b/twidere/src/main/res-localized/values-zh-rCN/strings.xml @@ -276,7 +276,7 @@ 显示色情等敏感内容而不发出提示 DNS 服务器 设置网络请求所用的 DNS 服务器 - 不重启 + 不重启 草稿已保存 您未发送的推文会被保存在这里 抽屉按钮 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 63fe8fc80..58ed75f8b 100644 --- a/twidere/src/main/res-localized/values-zh-rHK/strings.xml +++ b/twidere/src/main/res-localized/values-zh-rHK/strings.xml @@ -275,7 +275,7 @@ 顯示色情等敏感內容而不發出提示 DNS 伺服器 設置用於網絡查詢的DNS伺服器 - 不重啟 + 不重啟 草稿已儲存 您未發送的推文會被儲存在這裡 選單切換 diff --git a/twidere/src/main/res-localized/values-zh/strings.xml b/twidere/src/main/res-localized/values-zh/strings.xml index 63fe8fc80..58ed75f8b 100644 --- a/twidere/src/main/res-localized/values-zh/strings.xml +++ b/twidere/src/main/res-localized/values-zh/strings.xml @@ -275,7 +275,7 @@ 顯示色情等敏感內容而不發出提示 DNS 伺服器 設置用於網絡查詢的DNS伺服器 - 不重啟 + 不重啟 草稿已儲存 您未發送的推文會被儲存在這裡 選單切換 diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 0493f5e2b..c06554d7c 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -252,6 +252,7 @@ Twidere Twidere will restart to apply settings. + Twidere will quit to apply settings. Appearance @@ -391,7 +392,8 @@ DNS Server Set DNS Server for network requests. - Don\'t restart + Don\'t restart + Don\'t quit Draft saved @@ -868,11 +870,15 @@ Randomize account name Disallow other apps to get your name by reading accounts, improves privacy. Rename existing accounts? + Enable if auto refresh not working properly, may increase power usage on Android 5.0+ + Stop auto refresh when battery is low Open links in in-app browser (Powered by Chrome) Upper limit of items stored in databases for each account, set to a smaller value to save space and increase loading speed. Preload media only on free networks like Wi-Fi Accounts Advanced + Compatibility mode + Power saving mode In-app browser Database size limit Manage @@ -1137,8 +1143,6 @@ Retweet - Stop auto refresh when battery is low - Streaming Style diff --git a/twidere/src/main/res/xml/preferences_refresh.xml b/twidere/src/main/res/xml/preferences_refresh.xml index c6a8b32d7..f3eba2fe0 100644 --- a/twidere/src/main/res/xml/preferences_refresh.xml +++ b/twidere/src/main/res/xml/preferences_refresh.xml @@ -24,7 +24,19 @@ + android:summary="@string/preference_summary_auto_refresh_power_saving" + android:title="@string/preference_title_auto_refresh_power_saving"/> + + + +