- 内蔵ビューアの静止画表示に画像のピクセル数を記載

- 添付メディアのアップロード中は投稿ボタンを押すとエラーにする
This commit is contained in:
tateisu 2017-12-30 13:41:25 +09:00
parent c775088d5f
commit bcc14d1de0
10 changed files with 83 additions and 83 deletions

View File

@ -10,8 +10,8 @@ android {
applicationId "jp.juggler.subwaytooter" applicationId "jp.juggler.subwaytooter"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 26 targetSdkVersion 26
versionCode 194 versionCode 195
versionName "1.9.4" versionName "1.9.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }

View File

@ -162,22 +162,19 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
findViewById( R.id.btnDownload ).setOnClickListener( this ); findViewById( R.id.btnDownload ).setOnClickListener( this );
findViewById( R.id.btnMore ).setOnClickListener( this ); findViewById( R.id.btnMore ).setOnClickListener( this );
// findViewById( R.id.btnBrowser ).setOnClickListener( this );
// findViewById( R.id.btnShare ).setOnClickListener( this );
// findViewById( R.id.btnCopy ).setOnClickListener( this );
pbvImage.setCallback( new PinchBitmapView.Callback() { pbvImage.setCallback( new PinchBitmapView.Callback() {
@Override public void onSwipe( int delta ){ @Override public void onSwipe( int delta ){
if( isDestroyed() ) return; if( isDestroyed() ) return;
loadDelta( delta ); loadDelta( delta );
} }
@Override public void onMove( final float tx, final float ty, final float scale ){ @Override
public void onMove( final float bitmap_w, final float bitmap_h, final float tx, final float ty, final float scale ){
App1.app_state.handler.post( new Runnable() { App1.app_state.handler.post( new Runnable() {
@Override public void run(){ @Override public void run(){
if( isDestroyed() ) return; if( isDestroyed() ) return;
if( tvStatus.getVisibility() == View.VISIBLE ){ if( tvStatus.getVisibility() == View.VISIBLE ){
tvStatus.setText( getString(R.string.zooming_of,scale )); tvStatus.setText( getString( R.string.zooming_of,(int) bitmap_w, (int)bitmap_h, scale ) );
} }
} }
} ); } );
@ -189,7 +186,7 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
exoView.setPlayer( exoPlayer ); exoView.setPlayer( exoPlayer );
} }
void loadDelta( int delta ){ void loadDelta( int delta ){
if( media_list.size() < 2 ) return; if( media_list.size() < 2 ) return;
int size = media_list.size(); int size = media_list.size();
@ -289,7 +286,7 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
} }
tvStatus.setVisibility( View.VISIBLE ); tvStatus.setVisibility( View.VISIBLE );
tvStatus.setText(null); tvStatus.setText( null );
pbvImage.setVisibility( View.VISIBLE ); pbvImage.setVisibility( View.VISIBLE );
pbvImage.setBitmap( null ); pbvImage.setBitmap( null );
@ -343,16 +340,15 @@ public class ActMediaViewer extends AppCompatActivity implements View.OnClickLis
try{ try{
//noinspection ConstantConditions //noinspection ConstantConditions
data = ProgressResponseBody.bytes( response,new ProgressResponseBody.Callback() { data = ProgressResponseBody.bytes( response, new ProgressResponseBody.Callback() {
@Override public void progressBytes( long bytesRead, long bytesTotal ){ @Override public void progressBytes( long bytesRead, long bytesTotal ){
// 50MB以上のデータはキャンセルする // 50MB以上のデータはキャンセルする
if( Math.max(bytesRead,bytesTotal) >= 50000000 ){ if( Math.max( bytesRead, bytesTotal ) >= 50000000 ){
throw new RuntimeException( "media attachment is larger than 50000000" ); throw new RuntimeException( "media attachment is larger than 50000000" );
} }
publishApiProgressRatio( (int) bytesRead, (int) bytesTotal ); publishApiProgressRatio( (int) bytesRead, (int) bytesTotal );
} }
} ); } );
return new TootApiResult( "" ); return new TootApiResult( "" );
}catch( Throwable ex ){ }catch( Throwable ex ){

View File

@ -263,7 +263,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
} }
SharedPreferences pref; SharedPreferences pref;
ArrayList< PostAttachment > attachment_list; @NonNull ArrayList< PostAttachment > attachment_list = new ArrayList<>( );
AppState app_state; AppState app_state;
boolean isPostComplete; boolean isPostComplete;
PostHelper post_helper; PostHelper post_helper;
@ -318,7 +318,9 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
}else if( ! TextUtils.isEmpty( sv ) ){ }else if( ! TextUtils.isEmpty( sv ) ){
// state から復元する // state から復元する
this.attachment_list = app_state.attachment_list = new ArrayList<>(); app_state.attachment_list = this.attachment_list;
this.attachment_list.clear();
try{ try{
JSONArray array = new JSONArray( sv ); JSONArray array = new JSONArray( sv );
for( int i = 0, ie = array.length() ; i < ie ; ++ i ){ for( int i = 0, ie = array.length() ; i < ie ; ++ i ){
@ -341,7 +343,8 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
this.in_reply_to_image = savedInstanceState.getString( KEY_IN_REPLY_TO_IMAGE ); this.in_reply_to_image = savedInstanceState.getString( KEY_IN_REPLY_TO_IMAGE );
this.in_reply_to_url = savedInstanceState.getString( KEY_IN_REPLY_TO_URL ); this.in_reply_to_url = savedInstanceState.getString( KEY_IN_REPLY_TO_URL );
}else{ }else{
this.attachment_list = app_state.attachment_list = null; app_state.attachment_list = this.attachment_list;
this.attachment_list.clear();
Intent intent = getIntent(); Intent intent = getIntent();
long account_db_id = intent.getLongExtra( KEY_ACCOUNT_DB_ID, SavedAccount.INVALID_ID ); long account_db_id = intent.getLongExtra( KEY_ACCOUNT_DB_ID, SavedAccount.INVALID_ID );
@ -536,10 +539,10 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
outState.putString( KEY_VISIBILITY, visibility ); outState.putString( KEY_VISIBILITY, visibility );
} }
if( attachment_list != null && ! attachment_list.isEmpty() ){ if( ! attachment_list.isEmpty() ){
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
for( PostAttachment pa : attachment_list ){ for( PostAttachment pa : attachment_list ){
if( pa.status == PostAttachment.ATTACHMENT_UPLOADED ){ if( pa.status == PostAttachment.STATUS_UPLOADED ){
// アップロード完了したものだけ保持する // アップロード完了したものだけ保持する
array.put( pa.attachment.json ); array.put( pa.attachment.json );
} }
@ -775,7 +778,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
private void performAccountChooser(){ private void performAccountChooser(){
if( attachment_list != null && ! attachment_list.isEmpty() ){ if( ! attachment_list.isEmpty() ){
// 添付ファイルがあったら確認の上添付ファイルを捨てないと切り替えられない // 添付ファイルがあったら確認の上添付ファイルを捨てないと切り替えられない
Utils.showToast( this, false, R.string.cant_change_account_when_attachment_specified ); Utils.showToast( this, false, R.string.cant_change_account_when_attachment_specified );
return; return;
@ -905,7 +908,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
if( isFinishing() ) return; if( isFinishing() ) return;
if( attachment_list == null || attachment_list.isEmpty() ){ if( attachment_list.isEmpty() ){
llAttachment.setVisibility( View.GONE ); llAttachment.setVisibility( View.GONE );
}else{ }else{
llAttachment.setVisibility( View.VISIBLE ); llAttachment.setVisibility( View.VISIBLE );
@ -921,7 +924,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
}else{ }else{
iv.setVisibility( View.VISIBLE ); iv.setVisibility( View.VISIBLE );
PostAttachment a = attachment_list.get( idx ); PostAttachment a = attachment_list.get( idx );
if( a.attachment != null && a.status == PostAttachment.ATTACHMENT_UPLOADED ){ if( a.attachment != null && a.status == PostAttachment.STATUS_UPLOADED ){
iv.setImageUrl( pref, 16f, a.attachment.preview_url ); iv.setImageUrl( pref, 16f, a.attachment.preview_url );
}else{ }else{
iv.setImageUrl( pref, 16f, null ); iv.setImageUrl( pref, 16f, null );
@ -1075,7 +1078,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
private void performAttachment(){ private void performAttachment(){
if( attachment_list != null && attachment_list.size() >= 4 ){ if( attachment_list.size() >= 4 ){
Utils.showToast( this, false, R.string.attachment_too_many ); Utils.showToast( this, false, R.string.attachment_too_many );
return; return;
} }
@ -1203,7 +1206,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
static HashSet< String > acceptable_mime_types; static HashSet< String > acceptable_mime_types;
@SuppressLint("StaticFieldLeak") void addAttachment( final Uri uri, final String mime_type ){ @SuppressLint("StaticFieldLeak") void addAttachment( final Uri uri, final String mime_type ){
if( attachment_list != null && attachment_list.size() >= 4 ){ if( attachment_list.size() >= 4 ){
Utils.showToast( this, false, R.string.attachment_too_many ); Utils.showToast( this, false, R.string.attachment_too_many );
return; return;
} }
@ -1233,9 +1236,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
return; return;
} }
if( attachment_list == null ){ app_state.attachment_list = this.attachment_list;
this.attachment_list = app_state.attachment_list = new ArrayList<>();
}
final PostAttachment pa = new PostAttachment( this ); final PostAttachment pa = new PostAttachment( this );
attachment_list.add( pa ); attachment_list.add( pa );
@ -1322,12 +1323,12 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
@Override protected void handleResult( TootApiResult result ){ @Override protected void handleResult( TootApiResult result ){
if( pa.attachment == null ){ if( pa.attachment == null ){
pa.status = PostAttachment.ATTACHMENT_UPLOAD_FAILED; pa.status = PostAttachment.STATUS_UPLOAD_FAILED;
if( result != null ){ if( result != null ){
Utils.showToast( ActPost.this, true, result.error ); Utils.showToast( ActPost.this, true, result.error );
} }
}else{ }else{
pa.status = PostAttachment.ATTACHMENT_UPLOADED; pa.status = PostAttachment.STATUS_UPLOADED;
} }
// 投稿中に画面回転があった場合新しい画面のコールバックを呼び出す必要がある // 投稿中に画面回転があった場合新しい画面のコールバックを呼び出す必要がある
pa.callback.onPostAttachmentComplete( pa ); pa.callback.onPostAttachmentComplete( pa );
@ -1338,31 +1339,35 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
// 添付メディア投稿が完了したら呼ばれる // 添付メディア投稿が完了したら呼ばれる
@Override public void onPostAttachmentComplete( PostAttachment pa ){ @Override public void onPostAttachmentComplete( PostAttachment pa ){
if( pa.status != PostAttachment.ATTACHMENT_UPLOADED ){ if( ! attachment_list.contains( pa ) ){
if( attachment_list != null ){ // この添付メディアはリストにない
attachment_list.remove( pa ); return;
showMediaAttachment(); }
if( pa.status == PostAttachment.STATUS_UPLOAD_FAILED ){
// アップロード失敗
attachment_list.remove( pa );
showMediaAttachment();
}else if( pa.status == PostAttachment.STATUS_UPLOADED ){
// アップロード完了
Utils.showToast( ActPost.this, false, R.string.attachment_uploaded );
// 投稿欄の末尾に追記する
int selStart = etContent.getSelectionStart();
int selEnd = etContent.getSelectionEnd();
Editable e = etContent.getEditableText();
int len = e.length();
char last_char = ( len <= 0 ? ' ' : e.charAt( len - 1 ) );
if( ! EmojiDecoder.isWhitespaceBeforeEmoji( last_char ) ){
e.append( " " ).append( pa.attachment.text_url );
}else{
e.append( pa.attachment.text_url );
} }
etContent.setSelection( selStart, selEnd );
showMediaAttachment();
}else{ }else{
if( attachment_list != null && attachment_list.contains( pa ) ){ // アップロード中
Utils.showToast( ActPost.this, false, R.string.attachment_uploaded );
// 投稿欄の末尾に追記する
int selStart = etContent.getSelectionStart();
int selEnd = etContent.getSelectionEnd();
Editable e = etContent.getEditableText();
int len = e.length();
char last_char = ( len <= 0 ? ' ' : e.charAt( len - 1 ) );
if( ! EmojiDecoder.isWhitespaceBeforeEmoji( last_char ) ){
e.append( " " ).append( pa.attachment.text_url );
}else{
e.append( pa.attachment.text_url );
}
etContent.setSelection( selStart, selEnd );
showMediaAttachment();
}
} }
} }
@ -1548,10 +1553,8 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
@Override public void run(){ @Override public void run(){
etContent.setText( "" ); etContent.setText( "" );
etContentWarning.setText( "" ); etContentWarning.setText( "" );
if( attachment_list != null ){ attachment_list.clear();
attachment_list.clear(); showMediaAttachment();
showMediaAttachment();
}
} }
} }
); );
@ -1571,6 +1574,15 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
// post // post
private void performPost(){ private void performPost(){
// アップロード中は投稿できない
for( PostAttachment pa : attachment_list ){
if( pa.status == PostAttachment.STATUS_UPLOADING ){
Utils.showToast( this,false,R.string.media_attachment_still_uploading );
return;
}
}
post_helper.content = etContent.getText().toString().trim(); post_helper.content = etContent.getText().toString().trim();
if( ! cbEnquete.isChecked() ){ if( ! cbEnquete.isChecked() ){
@ -1676,10 +1688,8 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
try{ try{
JSONArray tmp_attachment_list = new JSONArray(); JSONArray tmp_attachment_list = new JSONArray();
if( attachment_list != null ){ for( PostAttachment pa : attachment_list ){
for( PostAttachment pa : attachment_list ){ if( pa.attachment != null ) tmp_attachment_list.put( pa.attachment.json );
if( pa.attachment != null ) tmp_attachment_list.put( pa.attachment.json );
}
} }
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
@ -1871,11 +1881,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
if( account != null ) setAccount( account ); if( account != null ) setAccount( account );
if( tmp_attachment_list.length() > 0 ){ if( tmp_attachment_list.length() > 0 ){
if( attachment_list != null ){ attachment_list.clear();
attachment_list.clear();
}else{
attachment_list = new ArrayList<>();
}
for( int i = 0, ie = tmp_attachment_list.length() ; i < ie ; ++ i ){ for( int i = 0, ie = tmp_attachment_list.length() ; i < ie ; ++ i ){
TootAttachment ta = TootAttachment.parse( tmp_attachment_list.optJSONObject( i ) ); TootAttachment ta = TootAttachment.parse( tmp_attachment_list.optJSONObject( i ) );
if( ta != null ){ if( ta != null ){

View File

@ -114,13 +114,6 @@ public class Styler {
// 被フォローリクエスト状態の時に followed_by 真と偽の両方がありえるようなので // 被フォローリクエスト状態の時に followed_by 真と偽の両方がありえるようなので
// Relationshipだけを見ても被フォローリクエスト状態は分からないっぽい // Relationshipだけを見ても被フォローリクエスト状態は分からないっぽい
// 仕方ないので馬鹿正直に followed_byが真ならバッジをつけるしかできない // 仕方ないので馬鹿正直に followed_byが真ならバッジをつけるしかできない
// if( column_type == Column.TYPE_FOLLOW_REQUESTS ){
// // フォローリクエストされてる状態でも followed_by はtrueになる
// int color = Styler.getAttributeColor( context,R.attr.colorRegexFilterError );
// Drawable d = Styler.getAttributeDrawable( context,R.attr.ic_followed_by ).mutate();
// d.setColorFilter( color, PorterDuff.Mode.SRC_ATOP );
// iv.setImageDrawable( d );
// }
} }
// follow button // follow button

View File

@ -8,9 +8,9 @@ public class PostAttachment {
void onPostAttachmentComplete(PostAttachment pa); void onPostAttachmentComplete(PostAttachment pa);
} }
public static final int ATTACHMENT_UPLOADING = 1; public static final int STATUS_UPLOADING = 1;
public static final int ATTACHMENT_UPLOADED = 2; public static final int STATUS_UPLOADED = 2;
public static final int ATTACHMENT_UPLOAD_FAILED = 3; public static final int STATUS_UPLOAD_FAILED = 3;
public int status; public int status;
public TootAttachment attachment; public TootAttachment attachment;
@ -18,11 +18,11 @@ public class PostAttachment {
public PostAttachment(Callback callback){ public PostAttachment(Callback callback){
this.status = ATTACHMENT_UPLOADING; this.status = STATUS_UPLOADING;
this.callback = callback; this.callback = callback;
} }
public PostAttachment( TootAttachment a ){ public PostAttachment( TootAttachment a ){
this.status = ATTACHMENT_UPLOADED; this.status = STATUS_UPLOADED;
this.attachment = a; this.attachment = a;
} }
} }

View File

@ -47,7 +47,7 @@ public class PinchBitmapView extends View {
// ページめくり操作のコールバック // ページめくり操作のコールバック
public interface Callback { public interface Callback {
void onSwipe( int delta ); void onSwipe( int delta );
void onMove(float tx,float ty,float scale); void onMove(float bitmap_w,float bitmap_h,float tx,float ty,float scale);
} }
@Nullable Callback callback; @Nullable Callback callback;
@ -131,13 +131,14 @@ public class PinchBitmapView extends View {
current_trans_y = ( view_h - draw_h ) / 2f; current_trans_y = ( view_h - draw_h ) / 2f;
if( callback != null ) callback.onMove( bitmap_w,bitmap_h, current_trans_x,current_trans_y,current_scale );
}else{ }else{
current_trans_x = current_trans_y = 0f; current_trans_x = current_trans_y = 0f;
current_scale = 1f; current_scale = 1f;
if( callback != null ) callback.onMove( 0f,0f, current_trans_x,current_trans_y,current_scale );
} }
if( callback != null ) callback.onMove( current_trans_x,current_trans_y,current_scale );
// 画像がnullに変化した時も再描画が必要 // 画像がnullに変化した時も再描画が必要
invalidate(); invalidate();
} }
@ -405,7 +406,7 @@ public class PinchBitmapView extends View {
current_trans_y = clipTranslate( view_h, bitmap_h, current_scale, start_image_trans_y + move_y ); current_trans_y = clipTranslate( view_h, bitmap_h, current_scale, start_image_trans_y + move_y );
} }
if( callback != null ) callback.onMove( current_trans_x,current_trans_y,current_scale ); if( callback != null ) callback.onMove( bitmap_w,bitmap_h,current_trans_x,current_trans_y,current_scale );
invalidate(); invalidate();
} }

View File

@ -117,6 +117,7 @@
android:gravity="start|bottom" android:gravity="start|bottom"
android:textSize="12sp" android:textSize="12sp"
android:alpha="0.5" android:alpha="0.5"
android:textColor="#ffffff"
/> />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>

View File

@ -585,7 +585,8 @@
<string name="media_attachment_type_error">The type of media attachment is \"%1$s\". ST can\'t handle it, but you can try open in browser.</string> <string name="media_attachment_type_error">The type of media attachment is \"%1$s\". ST can\'t handle it, but you can try open in browser.</string>
<string name="video_buffering">Buffering…</string> <string name="video_buffering">Buffering…</string>
<string name="dont_repeat_download_to_same_url">Can\'t repeat downloading same URL in a short time.</string> <string name="dont_repeat_download_to_same_url">Can\'t repeat downloading same URL in a short time.</string>
<string name="zooming_of">×%1$,.1f</string> <string name="zooming_of">×%3$.1f\n%1$d×%2$d</string>
<string name="media_attachment_still_uploading">Media uploading has not completed yet.</string>
<!--<string name="abc_action_bar_home_description">Revenir à l\'accueil</string>--> <!--<string name="abc_action_bar_home_description">Revenir à l\'accueil</string>-->
<!--<string name="abc_action_bar_home_description_format">%1$s, %2$s</string>--> <!--<string name="abc_action_bar_home_description_format">%1$s, %2$s</string>-->

View File

@ -872,6 +872,7 @@
<string name="media_attachment_type_error">添付メディアの種類\"%1$s\"はこのアプリでは開けません。下の「…」にある「ブラウザで開く」を試すことができます</string> <string name="media_attachment_type_error">添付メディアの種類\"%1$s\"はこのアプリでは開けません。下の「…」にある「ブラウザで開く」を試すことができます</string>
<string name="video_buffering">バッファ中…</string> <string name="video_buffering">バッファ中…</string>
<string name="dont_repeat_download_to_same_url">同じURLを数秒以内に繰り返しダウンロードすることはできません</string> <string name="dont_repeat_download_to_same_url">同じURLを数秒以内に繰り返しダウンロードすることはできません</string>
<string name="zooming_of">×%1$,.1f</string> <string name="zooming_of">×%3$.1f\n%1$d×%2$d</string>
<string name="media_attachment_still_uploading">添付メディアのアップロードが終わってません</string>
</resources> </resources>

View File

@ -575,5 +575,6 @@
<string name="media_attachment_type_error">The type of media attachment is \"%1$s\". ST can\'t handle it, but you can try open in browser.</string> <string name="media_attachment_type_error">The type of media attachment is \"%1$s\". ST can\'t handle it, but you can try open in browser.</string>
<string name="video_buffering">Buffering…</string> <string name="video_buffering">Buffering…</string>
<string name="dont_repeat_download_to_same_url">Can\'t repeat downloading same URL in a few second.</string> <string name="dont_repeat_download_to_same_url">Can\'t repeat downloading same URL in a few second.</string>
<string name="zooming_of">×%1$,.1f</string> <string name="zooming_of">×%3$.1f\n%1$d×%2$d</string>
<string name="media_attachment_still_uploading">Media uploading has not completed yet.</string>
</resources> </resources>