Manages media with sensitive toots

This commit is contained in:
tom79 2017-06-07 15:47:05 +02:00
parent ce2133f091
commit ebe994d508
7 changed files with 39 additions and 7 deletions

View File

@ -63,9 +63,9 @@ public class SearchResultActivity extends AppCompatActivity implements OnRetriev
if( search != null)
new RetrieveSearchAsyncTask(getApplicationContext(), search.trim(), SearchResultActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show();
Toast.makeText(this,R.string.toast_error_search,Toast.LENGTH_LONG).show();
}else{
Toast.makeText(this,R.string.toast_error_loading_account,Toast.LENGTH_LONG).show();
Toast.makeText(this,R.string.toast_error_search,Toast.LENGTH_LONG).show();
}
if( getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

View File

@ -37,6 +37,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
@ -96,6 +98,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private DisplayImageOptions options;
private LinearLayout toot_picture_container;
private List<Attachment> attachments;
private boolean isSensitive = false;
private ImageButton toot_visibility;
private Button toot_it;
private EditText toot_content, toot_cw_content;
@ -105,6 +108,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
private BroadcastReceiver search_validate;
private Status tootReply = null;
private String sharedContent;
private CheckBox toot_sensitive;
private String pattern = "^.*(@([a-zA-Z0-9_]{2,}))$";
@Override
@ -128,7 +132,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_reply_content_container = (LinearLayout) findViewById(R.id.toot_reply_content_container);
toot_show_accounts = (RelativeLayout) findViewById(R.id.toot_show_accounts);
toot_lv_accounts = (ListView) findViewById(R.id.toot_lv_accounts);
toot_sensitive = (CheckBox) findViewById(R.id.toot_sensitive);
Bundle b = getIntent().getExtras();
if(b != null) {
@ -249,6 +253,12 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
toot_visibility.setImageResource(R.drawable.ic_action_globe);
}
toot_sensitive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isSensitive = isChecked;
}
});
toot_space_left.setText(String.valueOf((maxChar - (charsInToot + charsInCw))));
toot_cw.setOnClickListener(new View.OnClickListener() {
@ -285,6 +295,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
return;
}
Status toot = new Status();
toot.setSensitive(isSensitive);
toot.setMedia_attachments(attachments);
if( toot_cw_content.getText().toString().trim().length() > 0)
toot.setSpoiler_text(toot_cw_content.getText().toString().trim());
@ -434,6 +445,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
attachments.add(attachment);
if( attachments.size() < 4)
toot_picture.setEnabled(true);
toot_sensitive.setVisibility(View.VISIBLE);
}
}
@ -463,6 +475,11 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
View namebar = findViewById(viewId);
((ViewGroup) namebar.getParent()).removeView(namebar);
dialog.dismiss();
if( attachments.size() == 0 ) {
toot_sensitive.setVisibility(View.GONE);
isSensitive = false;
toot_sensitive.setChecked(false);
}
}
});
dialog.show();
@ -534,6 +551,8 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
attachments.removeAll(tmp_attachment);
tmp_attachment.clear();
}
isSensitive = false;
toot_sensitive.setVisibility(View.GONE);
Toast.makeText(TootActivity.this,R.string.toot_sent, Toast.LENGTH_LONG).show();
}else {
Toast.makeText(TootActivity.this,R.string.toast_error, Toast.LENGTH_LONG).show();

View File

@ -1151,7 +1151,7 @@ public class API {
status.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString()));
status.setIn_reply_to_id(resobj.get("in_reply_to_id").toString());
status.setIn_reply_to_account_id(resobj.get("in_reply_to_account_id").toString());
status.setSensitive(Boolean.getBoolean(resobj.get("sensitive").toString()));
status.setSensitive(Boolean.parseBoolean(resobj.get("sensitive").toString()));
status.setSpoiler_text(resobj.get("spoiler_text").toString());
status.setVisibility(resobj.get("visibility").toString());

View File

@ -240,16 +240,19 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
holder.status_toot_date.setText(Helper.dateDiff(context, status.getCreated_at()));
imageLoader.displayImage(ppurl, holder.status_account_profile, options);
if( status.getMedia_attachments().size() < 1) {
holder.status_document_container.setVisibility(View.GONE);
holder.status_show_more.setVisibility(View.GONE);
}else{
if(behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || ( behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi)){
//If medias are loaded without any conditions or if device is on wifi
if(! status.isSensitive() && (behaviorWithAttachments == Helper.ATTACHMENT_ALWAYS || ( behaviorWithAttachments == Helper.ATTACHMENT_WIFI && isOnWifi)) ){
loadAttachments(status);
holder.status_show_more.setVisibility(View.GONE);
status.setAttachmentShown(true);
}else{
//Text depending if toots is sensitive or not
String textShowMore = (status.isSensitive())?context.getString(R.string.load_sensitive_attachment):context.getString(R.string.load_attachment);
holder.status_show_more.setText(textShowMore);
if( !status.isAttachmentShown() ) {
holder.status_show_more.setVisibility(View.VISIBLE);
holder.status_document_container.setVisibility(View.GONE);

View File

@ -248,7 +248,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( apiResponse.getError() != null){
//Discards 404 - error which can often happen due to toots which have been deleted
if( apiResponse.getError() != null && !apiResponse.getError().getError().startsWith("404 -")){
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
if( show_error_messages)

View File

@ -165,5 +165,11 @@
android:layout_height="wrap_content" />
</LinearLayout>
<CheckBox
android:text="@string/toot_sensitive"
android:visibility="gone"
android:id="@+id/toot_sensitive"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

View File

@ -135,6 +135,7 @@
<string name="toot_visibility_tilte">Visibilité du pouet</string>
<string name="toot_sent">Le pouet a été envoyé !</string>
<string name="toot_reply_content_title">Vous répondez à ce pouet :</string>
<string name="toot_sensitive">Contenu sensible ?</string>
<string-array name="toot_visibility">
<item>Afficher dans les fils publics</item>
<item>Ne pas afficher dans les fils publics</item>
@ -201,6 +202,7 @@
<string name="toast_unstatus">Le pouet a été supprimé !</string>
<string name="toast_error">Oups ! Une erreur s\'est produite !</string>
<string name="toast_error_loading_account">Une erreur s\'est produite en chargeant le compte !</string>
<string name="toast_error_search">Une erreur s\'est produite lors de la recherche !</string>
<string name="toast_error_login">Impossible de vous connecter !</string>
<string name="toast_update_credential_ok">Les données du profil ont été sauvegardées !</string>
<string name="nothing_to_do">Aucune action ne peut être réalisée</string>
@ -214,6 +216,7 @@
<string name="set_attachment_ask">Demander</string>
<string name="set_attachment_action">Charger les médias</string>
<string name="load_attachment">Charger les images</string>
<string name="load_sensitive_attachment">Charger les images sensibles</string>
<string name="set_display_reply">Afficher le message précédent lors d\'une réponse</string>
<string name="settings_title_notifications">Gestion des notifications</string>