自動CWの表示を改善

This commit is contained in:
tateisu 2017-08-27 14:41:38 +09:00
parent 2718326e52
commit 6dd3a9d9ec
5 changed files with 35 additions and 16 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "jp.juggler.subwaytooter"
minSdkVersion 21
targetSdkVersion 26
versionCode 128
versionName "1.2.8"
versionCode 129
versionName "1.2.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

View File

@ -4425,22 +4425,23 @@ public class ActMain extends AppCompatActivity
int lv_pad = (int) ( 0.5f + 12 * density );
int icon_width = (int) ( 0.5f + 48 * density );
int icon_end = (int) ( 0.5f + 4 * density );
nAutoCwCellWidth = column_w - lv_pad - icon_width - icon_end;
nAutoCwCellWidth = column_w - lv_pad*2 - icon_width - icon_end;
}
// この後各カラムは再描画される
}
TootStatusLike.AutoCW checkAutoCW( @NonNull TootStatusLike status, @NonNull CharSequence text ){
void checkAutoCW( @NonNull TootStatusLike status, @NonNull CharSequence text ){
if( nAutoCwLines <= 0 || nAutoCwCellWidth <= 0 ){
// 設定が無効
status.auto_cw = null;
return null;
return;
}
TootStatusLike.AutoCW a = status.auto_cw;
if( a != null && a.refActivity.get() == ActMain.this && a.cell_width == nAutoCwCellWidth ){
// 以前に計算した値がまだ使える
return a;
return;
}
if( a == null ) a = status.auto_cw = new TootStatusLike.AutoCW();
// 計算時の条件(文字フォント文字サイズカラム幅を覚えておいて再利用時に同じか確認する
@ -4469,13 +4470,24 @@ public class ActMain extends AppCompatActivity
if( l != null ){
int line_count = l.getLineCount();
if( line_count > nAutoCwLines ){
SpannableStringBuilder sb = new SpannableStringBuilder( );
sb.append( getString(R.string.auto_cw_prefix));
sb.append( text,0, l.getLineEnd( nAutoCwLines-1 ) );
SpannableStringBuilder sb = new SpannableStringBuilder();
sb.append( getString( R.string.auto_cw_prefix ) );
sb.append( text, 0, l.getLineEnd( nAutoCwLines - 1 ) );
int last = sb.length();
while( last > 0 ){
char c = sb.charAt( last - 1 );
if( c == '\n' || Character.isWhitespace( c ) ){
-- last;
continue;
}
break;
}
if( last < sb.length() ){
sb.delete( last, sb.length() );
}
sb.append( '…' );
a.decoded_spoiler_text = sb;
}
}
return a;
}
}

View File

@ -450,7 +450,8 @@ class ItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
showContent( cw_shown );
}else{
// 自動CWを使うかもしれない
TootStatusLike.AutoCW r = activity.checkAutoCW( status, content );
activity.checkAutoCW( status, content );
TootStatusLike.AutoCW r = status.auto_cw;
if( r != null && r.decoded_spoiler_text != null ){
// 自動CWされた内容を表示
llContentWarning.setVisibility( View.VISIBLE );
@ -567,9 +568,15 @@ class ItemViewHolder implements View.OnClickListener, View.OnLongClickListener {
}
private void showContent( boolean shown ){
btnContentWarning.setText( shown ? R.string.hide : R.string.show );
llContents.setVisibility( shown ? View.VISIBLE : View.GONE );
btnContentWarning.setText( shown ? R.string.hide : R.string.show );
if(status!=null){
TootStatusLike.AutoCW r = status.auto_cw;
if( r != null && r.decoded_spoiler_text != null ){
// 自動CWの場合はContentWarningのテキストを切り替える
tvContentWarning.setText( shown ? activity.getString( R.string.auto_cw_prefix ) : r.decoded_spoiler_text );
}
}
}
private void setMedia( MyNetworkImageView iv, TootStatus status, int idx ){

View File

@ -455,7 +455,7 @@
<string name="make_enquete">Make enquete</string>
<string name="dont_use_action_button_with_quick_toot_bar">Disable IME Action button when using \"Quick Toot\" bar (app restart required)</string>
<string name="auto_cw">Automatically hide long sentences (set line counts greater than 0 to enable this option. app restart required)</string>
<string name="auto_cw">Automatically hide long text (set line counts greater than 0 to enable this option. app restart required)</string>
<string name="auto_cw_prefix">(Automatic CW)</string>
<!--<string name="abc_action_bar_home_description">Revenir à l\'accueil</string>-->

View File

@ -450,7 +450,7 @@
<string name="choice4">choice 4(optional)</string>
<string name="make_enquete">Make enquete</string>
<string name="dont_use_action_button_with_quick_toot_bar">Disable IME Action button when using \"Quick Toot\" bar (app restart required)</string>
<string name="auto_cw">Automatically hide long sentences (set line counts greater than 0 to enable this option. app restart required)</string>
<string name="auto_cw">Automatically hide long text (set line counts greater than 0 to enable this option. app restart required)</string>
<string name="auto_cw_prefix">(Automatic CW)</string>
</resources>