This commit is contained in:
Mariotaku Lee 2017-04-27 21:23:35 +08:00
parent bab999a151
commit 809c386f78
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
9 changed files with 141 additions and 21 deletions

View File

@ -173,6 +173,7 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
String OAUTH_CALLBACK_OOB = "oob"; String OAUTH_CALLBACK_OOB = "oob";
String OAUTH_CALLBACK_URL = PROTOCOL_TWIDERE + "com.twitter.oauth/"; String OAUTH_CALLBACK_URL = PROTOCOL_TWIDERE + "com.twitter.oauth/";
String MASTODON_CALLBACK_URL = "https://org.mariotaku.twidere/auth/callback/mastodon"; String MASTODON_CALLBACK_URL = "https://org.mariotaku.twidere/auth/callback/mastodon";
String GITHUB_CALLBACK_URL = "https://org.mariotaku.twidere/auth/callback/github";
int REQUEST_TAKE_PHOTO = 1; int REQUEST_TAKE_PHOTO = 1;
int REQUEST_PICK_MEDIA = 2; int REQUEST_PICK_MEDIA = 2;

View File

@ -560,6 +560,10 @@
<activity <activity
android:name=".activity.content.FavoriteConfirmDialogActivity" android:name=".activity.content.FavoriteConfirmDialogActivity"
android:theme="@style/Theme.Twidere.NoDisplay"/> android:theme="@style/Theme.Twidere.NoDisplay"/>
<activity
android:name=".activity.UserFeedbackActivity"
android:label="@string/title_user_feedback"
android:theme="@style/Theme.Twidere"/>
<service <service
android:name=".service.LegacyTaskService" android:name=".service.LegacyTaskService"

View File

@ -1,7 +1,9 @@
package org.mariotaku.ktextension package org.mariotaku.ktextension
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream
import java.nio.charset.Charset import java.nio.charset.Charset
import java.util.*
/** /**
* Created by mariotaku on 2016/12/7. * Created by mariotaku on 2016/12/7.
@ -12,3 +14,31 @@ fun InputStream.toString(charset: Charset, close: Boolean = false): String {
if (close) return r.use { it.readText() } if (close) return r.use { it.readText() }
return r.readText() return r.readText()
} }
fun OutputStream.writeLine(string: String = "", charset: Charset = Charset.defaultCharset(),
crlf: Boolean = false) {
write(string.toByteArray(charset))
if (crlf) {
write("\r\n".toByteArray(charset))
} else {
write("\n".toByteArray(charset))
}
}
fun InputStream.expectLine(string: String = "", charset: Charset = Charset.defaultCharset(),
crlf: Boolean = false): Boolean {
if (!expectBytes(string.toByteArray(charset))) return false
if (crlf) {
if (!expectBytes("\r\n".toByteArray(charset))) return false
} else {
if (!expectBytes("\n".toByteArray(charset))) return false
}
return true
}
fun InputStream.expectBytes(bytes: ByteArray): Boolean {
val readBytes = ByteArray(bytes.size)
read(readBytes)
return Arrays.equals(readBytes, bytes)
}

View File

@ -169,17 +169,25 @@ class BrowserSignInActivity : BaseActivity() {
@Suppress("Deprecation", "OverridingDeprecatedMember") @Suppress("Deprecation", "OverridingDeprecatedMember")
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean { override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
val uri = Uri.parse(url)
val data = Intent() val data = Intent()
data.putExtra(EXTRA_EXTRAS, activity.intent.getBundleExtra(EXTRA_EXTRAS)) data.putExtra(EXTRA_EXTRAS, activity.intent.getBundleExtra(EXTRA_EXTRAS))
if (url.startsWith(OAUTH_CALLBACK_URL)) { when {
val oauthVerifier = uri.getQueryParameter("oauth_verifier") ?: return false url.startsWith(OAUTH_CALLBACK_URL) -> {
data.putExtra(EXTRA_OAUTH_VERIFIER, oauthVerifier) val uri = Uri.parse(url)
} else if (url.startsWith(MASTODON_CALLBACK_URL)) { val oauthVerifier = uri.getQueryParameter("oauth_verifier") ?: return false
val code = uri.getQueryParameter("code") ?: return false data.putExtra(EXTRA_OAUTH_VERIFIER, oauthVerifier)
data.putExtra(EXTRA_CODE, code) }
} else { url.startsWith(MASTODON_CALLBACK_URL) -> {
return false val uri = Uri.parse(url)
val code = uri.getQueryParameter("code") ?: return false
data.putExtra(EXTRA_CODE, code)
}
url.startsWith(GITHUB_CALLBACK_URL) -> {
val uri = Uri.parse(url)
val code = uri.getQueryParameter("code") ?: return false
data.putExtra(EXTRA_CODE, code)
}
else -> return false
} }
activity.setResult(Activity.RESULT_OK, data) activity.setResult(Activity.RESULT_OK, data)
activity.finish() activity.finish()

View File

@ -0,0 +1,36 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.activity
import android.os.Bundle
import org.mariotaku.twidere.R
/**
* Created by mariotaku on 2017/4/27.
*/
class UserFeedbackActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_user_feedback)
}
}

View File

@ -1,6 +1,7 @@
package org.mariotaku.twidere.preference.sync package org.mariotaku.twidere.preference.sync
import android.content.Context import android.content.Context
import android.content.SharedPreferences
import android.support.v7.preference.SwitchPreferenceCompat import android.support.v7.preference.SwitchPreferenceCompat
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
@ -20,7 +21,10 @@ class SyncItemPreference(
attrs: AttributeSet attrs: AttributeSet
) : SwitchPreferenceCompat(context, attrs) { ) : SwitchPreferenceCompat(context, attrs) {
@Inject @Inject
protected lateinit var syncPreferences: SyncPreferences lateinit var syncPreferences: SyncPreferences
@Inject
lateinit var preferences: SharedPreferences
val syncType: String val syncType: String
init { init {
@ -29,19 +33,21 @@ class SyncItemPreference(
syncType = a.getString(R.styleable.SyncItemPreference_syncType) syncType = a.getString(R.styleable.SyncItemPreference_syncType)
key = SyncPreferences.getSyncEnabledKey(syncType) key = SyncPreferences.getSyncEnabledKey(syncType)
a.recycle() a.recycle()
} }
override fun syncSummaryView(view: View?) { override fun syncSummaryView(view: View?) {
if (view is TextView) { if (view !is TextView) return
view.visibility = View.VISIBLE if (summary != null || summaryOn != null || summaryOff != null) {
val lastSynced = syncPreferences.getLastSynced(syncType) return super.syncSummaryView(view)
if (lastSynced > 0) { }
view.text = context.getString(R.string.message_sync_last_synced_time, view.visibility = View.VISIBLE
Utils.formatToLongTimeString(context, lastSynced)) val lastSynced = syncPreferences.getLastSynced(syncType)
} else { if (lastSynced > 0) {
view.text = null view.text = context.getString(R.string.message_sync_last_synced_time,
} Utils.formatToLongTimeString(context, lastSynced))
} else {
view.text = null
} }
} }
} }

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Twidere - Twitter client for Android
~
~ Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</ScrollView>

View File

@ -726,6 +726,7 @@
<string name="message_toast_search_saved">Search saved</string> <string name="message_toast_search_saved">Search saved</string>
<string name="message_toast_select_file_no_storage_permission">Storage permission is needed to select file</string> <string name="message_toast_select_file_no_storage_permission">Storage permission is needed to select file</string>
<string name="message_toast_share_media_no_storage_permission">Some apps requires storage permission to share media</string> <string name="message_toast_share_media_no_storage_permission">Some apps requires storage permission to share media</string>
<string name="message_toast_ssl_tls_error">TLS error, please check your clock or proxy settings</string>
<string name="message_toast_status_deleted">Tweet deleted</string> <string name="message_toast_status_deleted">Tweet deleted</string>
<string name="message_toast_status_favorited">Tweet favorited</string> <string name="message_toast_status_favorited">Tweet favorited</string>
<string name="message_toast_status_like_removed">Like removed</string> <string name="message_toast_status_like_removed">Like removed</string>
@ -878,6 +879,7 @@
<string name="preference_summary_media_preload_non_metered_network">Preload media only on free networks like Wi-Fi</string> <string name="preference_summary_media_preload_non_metered_network">Preload media only on free networks like Wi-Fi</string>
<string name="preference_summary_streaming_non_metered_network">Streaming only on free networks like Wi-Fi</string> <string name="preference_summary_streaming_non_metered_network">Streaming only on free networks like Wi-Fi</string>
<string name="preference_summary_streaming_power_saving">Streaming only when charging</string> <string name="preference_summary_streaming_power_saving">Streaming only when charging</string>
<string name="preference_summary_sync_timeline_positions">When \"Remember position\" enabled</string>
<string name="preference_summary_trends_location">Now you can set location separately in tab settings.</string> <string name="preference_summary_trends_location">Now you can set location separately in tab settings.</string>
<string name="preference_title_accounts">Accounts</string> <string name="preference_title_accounts">Accounts</string>
<string name="preference_title_advanced">Advanced</string> <string name="preference_title_advanced">Advanced</string>
@ -1252,6 +1254,7 @@
<string name="title_sync_settings">Sync settings</string> <string name="title_sync_settings">Sync settings</string>
<string name="title_user">User</string> <string name="title_user">User</string>
<string name="title_user_colors">User colors</string> <string name="title_user_colors">User colors</string>
<string name="title_user_feedback">Feedback</string>
<string name="title_user_list">List</string> <string name="title_user_list">List</string>
<string name="title_user_list_memberships">Belongs to</string> <string name="title_user_list_memberships">Belongs to</string>
<string name="title_user_list_ownerships">Created</string> <string name="title_user_list_ownerships">Created</string>
@ -1342,5 +1345,4 @@
<string name="users_blocked">Blocked these users.</string> <string name="users_blocked">Blocked these users.</string>
<string name="users_lists_with_name"><xliff:g id="name">%s</xliff:g>\'s lists</string> <string name="users_lists_with_name"><xliff:g id="name">%s</xliff:g>\'s lists</string>
<string name="users_statuses">User\'s tweets</string> <string name="users_statuses">User\'s tweets</string>
<string name="message_toast_ssl_tls_error">TLS error, please check your clock or proxy settings</string>
</resources> </resources>

View File

@ -21,6 +21,7 @@
app:syncType="user_colors"/> app:syncType="user_colors"/>
<org.mariotaku.twidere.preference.sync.SyncItemPreference <org.mariotaku.twidere.preference.sync.SyncItemPreference
android:defaultValue="true" android:defaultValue="true"
android:summary="@string/preference_summary_sync_timeline_positions"
android:title="@string/preference_title_timeline_positions" android:title="@string/preference_title_timeline_positions"
app:syncType="timeline_positions"/> app:syncType="timeline_positions"/>
</PreferenceScreen> </PreferenceScreen>