アカウント設定に「投稿の最大文字数」を追加。

This commit is contained in:
tateisu 2019-08-12 12:32:39 +09:00
parent b9dd76b2f0
commit bcee7f0ec8
9 changed files with 102 additions and 14 deletions

View File

@ -40,7 +40,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -21,8 +21,8 @@ android {
targetSdkVersion target_sdk_version
minSdkVersion min_sdk_version
versionCode 361
versionName "3.6.1"
versionCode 362
versionName "3.6.2"
applicationId "jp.juggler.subwaytooter"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@ -150,6 +150,8 @@ class ActAccountSetting
private lateinit var listFieldValueInvalidator : List<NetworkEmojiInvalidator>
private lateinit var btnFields : View
private lateinit var etMaxTootChars : EditText
///////////////////////////////////////////////////
internal var visibility = TootVisibility.Public
@ -296,6 +298,7 @@ class ActAccountSetting
btnProfileHeader = findViewById(R.id.btnProfileHeader)
etDisplayName = findViewById(R.id.etDisplayName)
etDefaultText = findViewById(R.id.etDefaultText)
etMaxTootChars = findViewById(R.id.etMaxTootChars)
btnDisplayName = findViewById(R.id.btnDisplayName)
etNote = findViewById(R.id.etNote)
btnNote = findViewById(R.id.btnNote)
@ -362,7 +365,7 @@ class ActAccountSetting
name_invalidator = NetworkEmojiInvalidator(handler, etDisplayName)
note_invalidator = NetworkEmojiInvalidator(handler, etNote)
default_text_invalidator = NetworkEmojiInvalidator(handler, etDefaultText)
listFieldNameInvalidator = listEtFieldName.map {
NetworkEmojiInvalidator(handler, it)
}
@ -393,6 +396,40 @@ class ActAccountSetting
}
})
etMaxTootChars.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(
s : CharSequence?,
start : Int,
count : Int,
after : Int
) {
}
override fun onTextChanged(
s : CharSequence?,
start : Int,
before : Int,
count : Int
) {
}
override fun afterTextChanged(s : Editable?) {
val num = etMaxTootChars.parseInt()
if( num != null && num >= 0){
saveUIToData()
}
}
})
}
private fun EditText.parseInt():Int?{
val sv = this.text?.toString() ?: return null
return try{
Integer.parseInt(sv,10)
}catch(ex:Throwable){
null
}
}
private fun loadUIFromData(a : SavedAccount) {
@ -431,7 +468,8 @@ class ActAccountSetting
notification_sound_uri = a.sound_uri
etDefaultText.setText(a.default_text)
etMaxTootChars.setText(a.max_toot_chars.toString())
loading = false
val enabled = ! a.isPseudo
@ -502,7 +540,14 @@ class ActAccountSetting
account.confirm_unfavourite = cbConfirmUnfavourite.isChecked
account.confirm_post = cbConfirmToot.isChecked
account.default_text = etDefaultText.text.toString()
val num = etMaxTootChars.parseInt()
account.max_toot_chars = if( num != null && num >= 0){
num
}else{
0
}
account.saveSetting()
}
@ -1303,7 +1348,7 @@ class ActAccountSetting
private fun openPicker(permission_request_code : Int) {
val permissionCheck = ContextCompat.checkSelfPermission(
this,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
if(permissionCheck != PackageManager.PERMISSION_GRANTED) {
preparePermission(permission_request_code)

View File

@ -844,9 +844,9 @@ class ActPost : AppCompatActivity(),
val decodeOptions = DecodeOptions(this, mentionFullAcct = true)
var text : CharSequence = if( account.isMisskey){
var text : CharSequence = if(account.isMisskey) {
base_status.content ?: ""
}else{
} else {
decodeOptions.decodeHTML(base_status.content)
}
etContent.setText(text)
@ -1250,10 +1250,11 @@ class ActPost : AppCompatActivity(),
}
else -> {
val info = account.instance
// 情報がないか古いなら再取得
// インスタンス情報を確認する
val info = account.instance
if(info == null || System.currentTimeMillis() - info.time_parse >= 300000L) {
// 情報がないか古いなら再取得
// 同時に実行するタスクは1つまで
var lastTask = lastInstanceTask
@ -1293,7 +1294,13 @@ class ActPost : AppCompatActivity(),
if(max != null && max > 0) return max
}
}
return 500
// アカウント設定で指定した値があるならそれを使う
val forceMaxTootChars = account?.max_toot_chars
return when {
forceMaxTootChars != null && forceMaxTootChars > 0 -> forceMaxTootChars
else -> 500
}
}
private fun updateTextCount() {

View File

@ -115,8 +115,8 @@ class App1 : Application() {
// 2018/12/6 v317 35 => 36 ContentWarningテーブルの作り直し。
// 2019/6/4 v351 36 => 37 SavedAccount テーブルに項目追加。
// 2019/6/4 v351 37 => 38 SavedAccount テーブルに項目追加。
internal const val DB_VERSION = 38
// 2019/8/12 v362 38 => 39 SavedAccount テーブルに項目追加。
internal const val DB_VERSION = 39
private val tableList = arrayOf(
LogData,

View File

@ -64,6 +64,8 @@ class SavedAccount(
var default_sensitive = false
var expand_cw = false
var max_toot_chars = 0
private val refInstance = AtomicReference<TootInstance>(null)
// DBには保存しない
@ -158,6 +160,7 @@ class SavedAccount(
this.default_sensitive = cursor.getBoolean(COL_DEFAULT_SENSITIVE)
this.expand_cw = cursor.getBoolean(COL_EXPAND_CW)
this.max_toot_chars = cursor.getInt(COL_MAX_TOOT_CHARS)
}
@ -219,6 +222,7 @@ class SavedAccount(
cv.put(COL_DEFAULT_SENSITIVE, default_sensitive.b2i())
cv.put(COL_EXPAND_CW, expand_cw.b2i())
cv.put(COL_MAX_TOOT_CHARS,max_toot_chars)
// UIからは更新しない
// notification_tag
@ -430,6 +434,7 @@ class SavedAccount(
private const val COL_DEFAULT_SENSITIVE = "default_sensitive"
private const val COL_EXPAND_CW = "expand_cw"
private const val COL_MAX_TOOT_CHARS = "max_toot_chars"
/////////////////////////////////
// login information
@ -503,6 +508,9 @@ class SavedAccount(
+ ",$COL_DEFAULT_SENSITIVE integer default 0"
+ ",$COL_EXPAND_CW integer default 0"
// スキーマ39から
+ ",$COL_MAX_TOOT_CHARS integer default 0"
+ ")"
)
db.execSQL("create index if not exists ${table}_user on ${table}(u)")
@ -663,6 +671,14 @@ class SavedAccount(
}
}
if(oldVersion < 39 && newVersion >= 39) {
try {
db.execSQL("alter table $table add column $COL_MAX_TOOT_CHARS integer default 0")
} catch(ex : Throwable) {
log.trace(ex)
}
}
}
// 横断検索用の、何とも紐ついていないアカウント

View File

@ -723,6 +723,24 @@
<View style="@style/setting_divider"/>
<TextView
style="@style/setting_row_label"
android:text="@string/max_toot_chars"
/>
<LinearLayout style="@style/setting_row_form">
<EditText
android:id="@+id/etMaxTootChars"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
/>
</LinearLayout>
<View style="@style/setting_divider"/>
<!--<View style="@style/setting_divider"/>-->
<!--<TextView-->

View File

@ -922,5 +922,6 @@
<string name="top"></string>
<string name="bottom"></string>
<string name="switch_button_color">スイッチボタンの色</string>
<string name="max_toot_chars">投稿の最大文字数(0:デフォルト。サーバがmax_toot_charsを提供する場合はこの設定は無視されます)</string>
</resources>

View File

@ -915,5 +915,6 @@
<string name="top">Top</string>
<string name="bottom">Bottom</string>
<string name="switch_button_color">Switch button color</string>
<string name="max_toot_chars">maximum character count in status (0:default. if server provides max_toot_chars, this setting is ignored.)</string>
</resources>