投稿画面でホームボタンを押した際にも下書きを保存する

This commit is contained in:
tateisu 2017-07-04 21:49:17 +09:00
parent 7b48ebd747
commit 9f2e4b0cfb
2 changed files with 54 additions and 46 deletions

View File

@ -3445,6 +3445,7 @@ public class ActMain extends AppCompatActivity
float density = dm.density; float density = dm.density;
int column_w_min = (int) ( 0.5f + column_w_min_dp * density ); int column_w_min = (int) ( 0.5f + column_w_min_dp * density );
if( column_w_min < 1) column_w_min =1;
if( sw < column_w_min * 2 ){ if( sw < column_w_min * 2 ){
// 最小幅で2つ表示できないのなら1カラム表示 // 最小幅で2つ表示できないのなら1カラム表示
@ -3453,9 +3454,7 @@ public class ActMain extends AppCompatActivity
// カラム最小幅から計算した表示カラム数 // カラム最小幅から計算した表示カラム数
nScreenColumn = sw / column_w_min; nScreenColumn = sw / column_w_min;
if( nScreenColumn <= 0 ){ if( nScreenColumn < 1 ) nScreenColumn = 1;
nScreenColumn = 1;
}
// データのカラム数より大きくならないようにする // データのカラム数より大きくならないようにする
// (でも最小は1) // (でも最小は1)

View File

@ -246,11 +246,20 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
@Override protected void onPause(){ @Override protected void onPause(){
super.onPause(); super.onPause();
MyClickableSpan.link_callback = null; MyClickableSpan.link_callback = null;
// 編集中にホーム画面を押したり他アプリに移動する場合は下書きを保存する
// やや過剰な気がするが自アプリに戻ってくるときにランチャーからアイコンタップされると
// メイン画面より上にあるアクティビティはすべて消されてしまうので
// このタイミングで保存するしかない
if( ! isPostComplete ){
saveDraft();
}
} }
SharedPreferences pref; SharedPreferences pref;
ArrayList< PostAttachment > attachment_list; ArrayList< PostAttachment > attachment_list;
AppState app_state; AppState app_state;
boolean isPostComplete;
@Override @Override
protected void onCreate( @Nullable Bundle savedInstanceState ){ protected void onCreate( @Nullable Bundle savedInstanceState ){
@ -486,6 +495,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
handler.removeCallbacks( proc_text_changed ); handler.removeCallbacks( proc_text_changed );
closeAcctPopup(); closeAcctPopup();
super.onDestroy(); super.onDestroy();
} }
@Override @Override
@ -559,11 +569,11 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
setContentView( R.layout.act_post ); setContentView( R.layout.act_post );
if( Pref.pref(this).getBoolean( Pref.KEY_POST_BUTTON_BAR_AT_TOP ,false)){ if( Pref.pref( this ).getBoolean( Pref.KEY_POST_BUTTON_BAR_AT_TOP, false ) ){
View bar = findViewById( R.id.llFooterBar ); View bar = findViewById( R.id.llFooterBar );
ViewGroup parent = (ViewGroup) bar.getParent(); ViewGroup parent = (ViewGroup) bar.getParent();
parent.removeView( bar ); parent.removeView( bar );
parent.addView( bar,0 ); parent.addView( bar, 0 );
} }
Styler.fixHorizontalMargin( findViewById( R.id.scrollView ) ); Styler.fixHorizontalMargin( findViewById( R.id.scrollView ) );
@ -731,7 +741,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
int end = etContent.getSelectionEnd(); int end = etContent.getSelectionEnd();
String src = etContent.getText().toString(); String src = etContent.getText().toString();
int last_sharp = src.lastIndexOf( '#',end-1 ); int last_sharp = src.lastIndexOf( '#', end - 1 );
if( last_sharp == - 1 || end - last_sharp < 3 ){ if( last_sharp == - 1 || end - last_sharp < 3 ){
closeAcctPopup(); closeAcctPopup();
@ -817,32 +827,32 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
.setItems( caption_list, new DialogInterface.OnClickListener() { .setItems( caption_list, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick( DialogInterface dialog, int which ){ public void onClick( DialogInterface dialog, int which ){
if( which <0 || which >= tmp_account_list.size() ){ if( which < 0 || which >= tmp_account_list.size() ){
// 範囲外 // 範囲外
return; return;
} }
SavedAccount a = tmp_account_list.get( which ); SavedAccount a = tmp_account_list.get( which );
if( ! a.host.equals( account.host ) ){ if( ! a.host.equals( account.host ) ){
// 別タンスへの移動 // 別タンスへの移動
if( in_reply_to_id != -1L ){ if( in_reply_to_id != - 1L ){
// 別タンスのアカウントならin_reply_toの変換が必要 // 別タンスのアカウントならin_reply_toの変換が必要
startReplyConversion(a); startReplyConversion( a );
} }
} }
// リプライがないか同タンスへの移動 // リプライがないか同タンスへの移動
setAccountWithVisibilityConversion(a); setAccountWithVisibilityConversion( a );
} }
} ) } )
.setNegativeButton( R.string.cancel, null ) .setNegativeButton( R.string.cancel, null )
.show(); .show();
} }
void setAccountWithVisibilityConversion(@NonNull SavedAccount a){ void setAccountWithVisibilityConversion( @NonNull SavedAccount a ){
setAccount( a ); setAccount( a );
try{ try{
if( account.visibility != null && TootStatus.compareVisibility( visibility, a.visibility ) > 0 ){ if( account.visibility != null && TootStatus.compareVisibility( visibility, a.visibility ) > 0 ){
@ -855,7 +865,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
} }
} }
private void startReplyConversion( @NonNull final SavedAccount access_info ){ private void startReplyConversion( @NonNull final SavedAccount access_info ){
if( in_reply_to_url == null ){ if( in_reply_to_url == null ){
// 下書きが古い形式の場合URLがないので別タンスへの移動ができない // 下書きが古い形式の場合URLがないので別タンスへの移動ができない
new AlertDialog.Builder( ActPost.this ) new AlertDialog.Builder( ActPost.this )
@ -904,7 +914,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
@Override protected void onPostExecute( TootApiResult result ){ @Override protected void onPostExecute( TootApiResult result ){
try{ try{
progress.dismiss(); progress.dismiss();
}catch(Throwable ex){ }catch( Throwable ex ){
ex.printStackTrace(); ex.printStackTrace();
} }
if( isCancelled() ) return; if( isCancelled() ) return;
@ -915,7 +925,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
in_reply_to_id = target_status.id; in_reply_to_id = target_status.id;
setAccountWithVisibilityConversion( access_info ); setAccountWithVisibilityConversion( access_info );
}else{ }else{
Utils.showToast( ActPost.this, true, getString(R.string.in_reply_to_id_conversion_failed ) +"\n"+result.error ); Utils.showToast( ActPost.this, true, getString( R.string.in_reply_to_id_conversion_failed ) + "\n" + result.error );
} }
} }
}.executeOnExecutor( App1.task_executor ); }.executeOnExecutor( App1.task_executor );
@ -1454,7 +1464,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
getString( R.string.recommended_plugin ) getString( R.string.recommended_plugin )
, new Runnable() { , new Runnable() {
@Override public void run(){ @Override public void run(){
showRecommendedPlugin(null); showRecommendedPlugin( null );
} }
} }
); );
@ -1656,6 +1666,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
data.putExtra( EXTRA_POSTED_STATUS_ID, status.id ); data.putExtra( EXTRA_POSTED_STATUS_ID, status.id );
setResult( RESULT_OK, data ); setResult( RESULT_OK, data );
isPostComplete = true;
ActPost.this.finish(); ActPost.this.finish();
}else{ }else{
Utils.showToast( ActPost.this, true, result.error ); Utils.showToast( ActPost.this, true, result.error );
@ -1715,7 +1726,6 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
static final String DRAFT_REPLY_IMAGE = "reply_image"; static final String DRAFT_REPLY_IMAGE = "reply_image";
static final String DRAFT_REPLY_URL = "reply_url"; static final String DRAFT_REPLY_URL = "reply_url";
private void saveDraft(){ private void saveDraft(){
String content = etContent.getText().toString(); String content = etContent.getText().toString();
String content_warning = etContentWarning.getText().toString(); String content_warning = etContentWarning.getText().toString();
@ -1877,7 +1887,7 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
boolean content_warning_checked = draft.optBoolean( DRAFT_CONTENT_WARNING_CHECK ); boolean content_warning_checked = draft.optBoolean( DRAFT_CONTENT_WARNING_CHECK );
boolean nsfw_checked = draft.optBoolean( DRAFT_NSFW_CHECK ); boolean nsfw_checked = draft.optBoolean( DRAFT_NSFW_CHECK );
JSONArray tmp_attachment_list = draft.optJSONArray( DRAFT_ATTACHMENT_LIST ); JSONArray tmp_attachment_list = draft.optJSONArray( DRAFT_ATTACHMENT_LIST );
long reply_id = draft.optLong( DRAFT_REPLY_ID, -1L ); long reply_id = draft.optLong( DRAFT_REPLY_ID, - 1L );
String reply_text = draft.optString( DRAFT_REPLY_TEXT, null ); String reply_text = draft.optString( DRAFT_REPLY_TEXT, null );
String reply_image = draft.optString( DRAFT_REPLY_IMAGE, null ); String reply_image = draft.optString( DRAFT_REPLY_IMAGE, null );
String reply_url = draft.optString( DRAFT_REPLY_URL, null ); String reply_url = draft.optString( DRAFT_REPLY_URL, null );
@ -1997,18 +2007,17 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
// Verify the intent will resolve to at least one activity // Verify the intent will resolve to at least one activity
if( intent.resolveActivity( getPackageManager() ) == null ){ if( intent.resolveActivity( getPackageManager() ) == null ){
showRecommendedPlugin(getString( R.string.plugin_not_installed )); showRecommendedPlugin( getString( R.string.plugin_not_installed ) );
return; return;
} }
startActivityForResult( chooser, REQUEST_CODE_MUSHROOM ); startActivityForResult( chooser, REQUEST_CODE_MUSHROOM );
}catch( Throwable ex ){ }catch( Throwable ex ){
ex.printStackTrace(); ex.printStackTrace();
showRecommendedPlugin(getString( R.string.plugin_not_installed )); showRecommendedPlugin( getString( R.string.plugin_not_installed ) );
} }
} }
private void applyMushroomResult( String text ){ private void applyMushroomResult( String text ){
if( mushroom_input == 1 ){ if( mushroom_input == 1 ){
applyMushroomText( etContentWarning, text ); applyMushroomText( etContentWarning, text );
@ -2017,55 +2026,55 @@ public class ActPost extends AppCompatActivity implements View.OnClickListener,
} }
} }
private void showRecommendedPlugin(String title){ private void showRecommendedPlugin( String title ){
String language_code = getString(R.string.language_code); String language_code = getString( R.string.language_code );
int res_id; int res_id;
if( "ja".equals( language_code )){ if( "ja".equals( language_code ) ){
res_id = R.raw.recommended_plugin_ja; res_id = R.raw.recommended_plugin_ja;
}else if ( "fr".equals( language_code )){ }else if( "fr".equals( language_code ) ){
res_id = R.raw.recommended_plugin_fr; res_id = R.raw.recommended_plugin_fr;
}else{ }else{
res_id = R.raw.recommended_plugin_en; res_id = R.raw.recommended_plugin_en;
} }
try{ try{
InputStream is = getResources().openRawResource(res_id ); InputStream is = getResources().openRawResource( res_id );
try{ try{
ByteArrayOutputStream bao = new ByteArrayOutputStream( ); ByteArrayOutputStream bao = new ByteArrayOutputStream();
IOUtils.copy( is,bao ); IOUtils.copy( is, bao );
String text = Utils.decodeUTF8(bao.toByteArray()); String text = Utils.decodeUTF8( bao.toByteArray() );
View viewRoot = getLayoutInflater().inflate( R.layout.dlg_plugin_missing,null,false ); View viewRoot = getLayoutInflater().inflate( R.layout.dlg_plugin_missing, null, false );
TextView tvText = (TextView)viewRoot. findViewById(R.id.tvText); TextView tvText = (TextView) viewRoot.findViewById( R.id.tvText );
LinkClickContext lcc = new LinkClickContext() { LinkClickContext lcc = new LinkClickContext() {
@Override public AcctColor findAcctColor( String url ){ @Override public AcctColor findAcctColor( String url ){
return null; return null;
} }
}; };
CharSequence sv = HTMLDecoder.decodeHTML( lcc,text,false,null ); CharSequence sv = HTMLDecoder.decodeHTML( lcc, text, false, null );
tvText.setText(sv ); tvText.setText( sv );
tvText.setMovementMethod( LinkMovementMethod.getInstance() ); tvText.setMovementMethod( LinkMovementMethod.getInstance() );
TextView tvTitle = (TextView)viewRoot. findViewById(R.id.tvTitle); TextView tvTitle = (TextView) viewRoot.findViewById( R.id.tvTitle );
if( TextUtils.isEmpty( title )){ if( TextUtils.isEmpty( title ) ){
tvTitle.setVisibility( View.GONE ); tvTitle.setVisibility( View.GONE );
}else{ }else{
tvTitle.setText( title ); tvTitle.setText( title );
} }
new AlertDialog.Builder(this) new AlertDialog.Builder( this )
.setView(viewRoot ) .setView( viewRoot )
.setCancelable( true ) .setCancelable( true )
.setNeutralButton( R.string.close, null ) .setNeutralButton( R.string.close, null )
.show(); .show();
}finally{ }finally{
IOUtils.closeQuietly( is ); IOUtils.closeQuietly( is );
} }
}catch(Throwable ex){ }catch( Throwable ex ){
ex.printStackTrace( ); ex.printStackTrace();
} }
} }