Skip to content

Commit

Permalink
feat: export access_key (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mufanc committed Feb 4, 2024
1 parent 34bd5fd commit 6b2f41f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/me/iacn/biliroaming/SettingDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.app.Activity
import android.app.Activity.RESULT_CANCELED
import android.app.AlertDialog
import android.content.ActivityNotFoundException
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
Expand All @@ -33,6 +35,7 @@ import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.*
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.Toast
import androidx.documentfile.provider.DocumentFile
import kotlinx.coroutines.*
import me.iacn.biliroaming.BiliBiliPackage.Companion.instance
Expand Down Expand Up @@ -105,6 +108,7 @@ class SettingDialog(context: Context) : AlertDialog.Builder(context) {
findPreference("customize_dynamic")?.onPreferenceClickListener = this
findPreference("filter_search")?.onPreferenceClickListener = this
findPreference("filter_comment")?.onPreferenceClickListener = this
findPreference("copy_access_key")?.onPreferenceClickListener = this
checkCompatibleVersion()
searchItems = retrieve(preferenceScreen)
checkUpdate()
Expand Down Expand Up @@ -847,6 +851,16 @@ class SettingDialog(context: Context) : AlertDialog.Builder(context) {
}.show()
return true
}

private fun onCopyAccessKeyClick(): Boolean {
val manager = context.getSystemService(ClipboardManager::class.java)

manager.setPrimaryClip(ClipData.newPlainText("access_key", instance.accessKey))
Toast.makeText(context, R.string.copy_access_key_toast, Toast.LENGTH_SHORT).show()

return true
}

@Deprecated("Deprecated in Java")
override fun onPreferenceClick(preference: Preference) = when (preference.key) {
"version" -> onVersionClick()
Expand All @@ -867,6 +881,7 @@ class SettingDialog(context: Context) : AlertDialog.Builder(context) {
"default_speed" -> onDefaultSpeedClick()
"filter_search" -> onFilterSearchClick()
"filter_comment" -> onFilterCommentClick()
"copy_access_key" -> onCopyAccessKeyClick()
else -> false
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,7 @@
<string name="pegasus_cover_ratio_summary">自定义首页推荐小卡(双列显示的)封面比例</string>
<string name="fake_non_multiwindow_title">伪装处于非多窗口模式</string>
<string name="fake_non_multiwindow_summary">比如视频多窗口模式下全屏</string>
<string name="copy_access_key_title">复制 access_key</string>
<string name="copy_access_key_summary">请勿泄露给他人</string>
<string name="copy_access_key_toast">已复制</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/prefs_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@
android:dependency="hidden"
android:key="block_video_comment"
android:title="@string/block_video_comment_title" />

<Preference
android:key="copy_access_key"
android:title="@string/copy_access_key_title"
android:summary="@string/copy_access_key_summary" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/setting_category">
Expand Down

0 comments on commit 6b2f41f

Please sign in to comment.