diff --git a/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java b/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java index 1b1263210..63ab1ea47 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java +++ b/twidere/src/main/java/org/mariotaku/twidere/util/ErrorInfoStore.java @@ -23,6 +23,7 @@ public class ErrorInfoStore { public static final int CODE_NO_DM_PERMISSION = 1; public static final int CODE_NO_ACCESS_FOR_CREDENTIALS = 2; public static final int CODE_NETWORK_ERROR = 3; + public static final int CODE_TIMESTAMP_ERROR = 4; private final SharedPreferences mPreferences; @@ -47,20 +48,20 @@ public class ErrorInfoStore { } } - public void put(String key, int code) { + public void set(String key, int code) { mPreferences.edit().putInt(key, code).apply(); } - public void put(String key, String extraId, int code) { - put(key + "_" + extraId, code); + public void set(String key, String extraId, int code) { + set(key + "_" + extraId, code); } - public void put(String key, UserKey extraId, int code) { + public void set(String key, UserKey extraId, int code) { final String host = extraId.getHost(); if (host == null) { - put(key, extraId.getId(), code); + set(key, extraId.getId(), code); } else { - put(key + "_" + extraId.getId() + "_" + host, code); + set(key + "_" + extraId.getId() + "_" + host, code); } } @@ -79,6 +80,10 @@ public class ErrorInfoStore { return new DisplayErrorInfo(code, R.drawable.ic_info_error_generic, context.getString(R.string.network_error)); } + case CODE_TIMESTAMP_ERROR: { + return new DisplayErrorInfo(code, R.drawable.ic_info_error_generic, + context.getString(R.string.error_info_oauth_timestamp_error)); + } } return null; } 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 756936e64..63255947a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/ComposeActivity.kt @@ -1027,8 +1027,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener } } - mentions.filterNot { it.equals(status.user_screen_name, ignoreCase = true) - || it.equals(accountUser.screen_name, ignoreCase = true) } + mentions.filterNot { + it.equals(status.user_screen_name, ignoreCase = true) + || it.equals(accountUser.screen_name, ignoreCase = true) + } .forEach { editText.append("@$it ") } val selectionEnd = editText.length() editText.setSelection(selectionStart, selectionEnd) @@ -1776,7 +1778,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener override fun onClick(v: View) { when (v.id) { R.id.remove -> { - adapter?.remove(layoutPosition) + val adapter = this.adapter ?: return + if (layoutPosition >= 0 && layoutPosition < adapter.itemCount) { + adapter.remove(layoutPosition) + } } R.id.edit -> { itemView.parent.showContextMenuForChild(itemView) @@ -1796,7 +1801,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener (activity as ComposeActivity).setMediaAltText(arguments.getInt(EXTRA_POSITION), ParseUtils.parseString(editText.text)) } - builder.setNeutralButton(R.string.clear) { dialogInterface, i -> (activity as ComposeActivity).setMediaAltText(arguments.getInt(EXTRA_POSITION), null) } + builder.setNeutralButton(R.string.clear) { dialogInterface, i -> + (activity as ComposeActivity).setMediaAltText(arguments.getInt(EXTRA_POSITION), null) + } val dialog = builder.create() dialog.setOnShowListener { dialog -> val materialDialog = dialog as Dialog diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt index ec0126a7c..fe63af5a1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorActivitiesFragment.kt @@ -61,7 +61,7 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() { showContent() } else if (accountKeys.isNotEmpty()) { val errorInfo = ErrorInfoStore.getErrorInfo(context, - errorInfoStore.get(errorInfoKey, accountKeys[0])) + errorInfoStore[errorInfoKey, accountKeys[0]]) if (errorInfo != null) { showEmpty(errorInfo.icon, errorInfo.message) } else { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt index f5ca33f0e..a44fb731a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/CursorStatusesFragment.kt @@ -109,7 +109,7 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() { showContent() } else if (accountKeys.isNotEmpty()) { val errorInfo = ErrorInfoStore.getErrorInfo(context, - errorInfoStore.get(errorInfoKey, accountKeys[0])) + errorInfoStore[errorInfoKey, accountKeys[0]]) if (errorInfo != null) { showEmpty(errorInfo.icon, errorInfo.message) } else { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DirectMessagesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DirectMessagesFragment.kt index 448da56e4..dd071944f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DirectMessagesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/DirectMessagesFragment.kt @@ -167,7 +167,7 @@ class DirectMessagesFragment : AbsContentListRecyclerViewFragment { - if (accountKey == null || statusId == null) return SingleResponse.getInstance() + if (accountKey == null || statusId == null) { + return SingleResponse(exception = IllegalArgumentException()) + } val details = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true) if (!omitIntentExtra && extras != null) { - val cache = extras.getParcelable(IntentConstants.EXTRA_STATUS) + val cache: ParcelableStatus? = extras.getParcelable(IntentConstants.EXTRA_STATUS) if (cache != null) { - val response = SingleResponse.getInstance(cache) - val extras = response.extras - extras.putParcelable(EXTRA_ACCOUNT, details) + val response = SingleResponse(cache) + response.extras[EXTRA_ACCOUNT] = details return response } } + if (details == null) return SingleResponse(exception = MicroBlogException("No account")) try { - if (details == null) return SingleResponse.getInstance() val status = findStatus(context, accountKey, statusId) ParcelableStatusUtils.updateExtraInformation(status, details, userColorNameManager) - val response = SingleResponse.getInstance(status) - val extras = response.extras - extras.putParcelable(EXTRA_ACCOUNT, details) + val response = SingleResponse(status) + response.extras[EXTRA_ACCOUNT] = details return response } catch (e: MicroBlogException) { if (e.errorCode == ErrorInfo.STATUS_NOT_FOUND) { @@ -84,7 +85,7 @@ class ParcelableStatusLoader( statusId, null) DataStoreUtils.deleteActivityStatus(cr, accountKey, statusId, null) } - return SingleResponse.getInstance(e) + return SingleResponse(exception = e) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/service/RefreshService.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/service/RefreshService.kt index fe8265781..40e85e4cc 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/service/RefreshService.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/service/RefreshService.kt @@ -90,21 +90,21 @@ class RefreshService : Service() { when (refreshType) { AutoRefreshType.HOME_TIMELINE -> { val task = GetHomeTimelineTask(context) - task.params = RefreshService.AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshHomeTimelineEnabled) { accountKeys -> + task.params = AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshHomeTimelineEnabled) { accountKeys -> DataStoreUtils.getNewestStatusIds(context, Statuses.CONTENT_URI, accountKeys) } return task } AutoRefreshType.INTERACTIONS_TIMELINE -> { val task = GetActivitiesAboutMeTask(context) - task.params = RefreshService.AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshMentionsEnabled) { accountKeys -> + task.params = AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshMentionsEnabled) { accountKeys -> DataStoreUtils.getNewestActivityMaxPositions(context, Activities.AboutMe.CONTENT_URI, accountKeys) } return task } AutoRefreshType.DIRECT_MESSAGES -> { val task = GetReceivedDirectMessagesTask(context) - task.params = RefreshService.AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshDirectMessagesEnabled) { accountKeys -> + task.params = AutoRefreshTaskParam(context, AccountPreferences::isAutoRefreshDirectMessagesEnabled) { accountKeys -> DataStoreUtils.getNewestMessageIds(context, DirectMessages.Inbox.CONTENT_URI, accountKeys) } return task 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 c72e46d78..d5e599777 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/GetDirectMessagesTask.kt @@ -86,11 +86,9 @@ abstract class GetDirectMessagesTask( errorInfoStore.remove(ErrorInfoStore.KEY_DIRECT_MESSAGES, accountKey) } catch (e: MicroBlogException) { if (e.errorCode == ErrorInfo.NO_DIRECT_MESSAGE_PERMISSION) { - errorInfoStore.put(ErrorInfoStore.KEY_DIRECT_MESSAGES, accountKey, - ErrorInfoStore.CODE_NO_DM_PERMISSION) + errorInfoStore[ErrorInfoStore.KEY_DIRECT_MESSAGES, accountKey] = ErrorInfoStore.CODE_NO_DM_PERMISSION } else if (e.isCausedByNetworkIssue) { - errorInfoStore.put(ErrorInfoStore.KEY_DIRECT_MESSAGES, accountKey, - ErrorInfoStore.CODE_NETWORK_ERROR) + errorInfoStore[ErrorInfoStore.KEY_DIRECT_MESSAGES, accountKey] = ErrorInfoStore.CODE_NETWORK_ERROR } if (BuildConfig.DEBUG) { Log.w(TwidereConstants.LOGTAG, e) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt index b19a91515..215a29306 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetActivitiesTask.kt @@ -107,11 +107,9 @@ abstract class GetActivitiesTask( Log.w(LOGTAG, e) } if (e.errorCode == 220) { - errorInfoStore.put(errorInfoKey, accountKey, - ErrorInfoStore.CODE_NO_ACCESS_FOR_CREDENTIALS) + errorInfoStore[errorInfoKey, accountKey] = ErrorInfoStore.CODE_NO_ACCESS_FOR_CREDENTIALS } else if (e.isCausedByNetworkIssue) { - errorInfoStore.put(errorInfoKey, accountKey, - ErrorInfoStore.CODE_NETWORK_ERROR) + errorInfoStore[errorInfoKey, accountKey] = ErrorInfoStore.CODE_NETWORK_ERROR } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt index 1c3a8f4e1..ec8948521 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/task/twitter/GetStatusesTask.kt @@ -143,8 +143,9 @@ abstract class GetStatusesTask( Log.w(LOGTAG, e) } if (e.isCausedByNetworkIssue) { - errorInfoStore.put(errorInfoKey, accountKey.id, - ErrorInfoStore.CODE_NETWORK_ERROR) + errorInfoStore[errorInfoKey, accountKey.id] = ErrorInfoStore.CODE_NETWORK_ERROR + } else if (e.statusCode == 401) { + // Unauthorized } result.add(TwitterWrapper.StatusListResponse(accountKey, e)) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/LegacyAutoRefreshController.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/LegacyAutoRefreshController.kt index 503041e7b..4077c88ac 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/LegacyAutoRefreshController.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/LegacyAutoRefreshController.kt @@ -4,6 +4,7 @@ import android.app.AlarmManager import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.os.SystemClock import android.support.v4.util.ArrayMap import org.mariotaku.kpreferences.KPreferences import org.mariotaku.twidere.annotation.AutoRefreshType @@ -46,8 +47,8 @@ class LegacyAutoRefreshController( val pendingIntent = pendingIntents[type] ?: return val interval = TimeUnit.MINUTES.toMillis(kPreferences[refreshIntervalKey]) if (interval > 0) { - val triggerAt = System.currentTimeMillis() + interval - alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, triggerAt, interval, pendingIntent) + val triggerAt = SystemClock.elapsedRealtime() + interval + alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, triggerAt, interval, pendingIntent) } } diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 1fe12b2a7..5fedb0101 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -818,4 +818,5 @@ Disallow other apps to get your name by reading accounts, improves privacy. Rename existing accounts? Enable auto refresh to get new tweets automatically? + Please check your system date & time settings. \ No newline at end of file