Add links in toots for media as an option in settings

This commit is contained in:
tom79 2017-08-15 09:02:46 +02:00
parent e10364fd5f
commit 838e4c9791
7 changed files with 45 additions and 15 deletions

View File

@ -782,12 +782,16 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
imParams.height = (int) Helper.convertDpToPixel(100, getApplicationContext());
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//Adds the url at the end of the toot
int selectionBefore = toot_content.getSelectionStart();
toot_content.setText(toot_content.getText().toString()+"\n"+attachment.getUrl());
//Moves the cursor
if( selectionBefore >= 0 )
toot_content.setSelection(selectionBefore);
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean show_media_urls = sharedpreferences.getBoolean(Helper.SET_MEDIA_URLS, true);
if( show_media_urls) {
//Adds the url at the end of the toot
int selectionBefore = toot_content.getSelectionStart();
toot_content.setText(toot_content.getText().toString() + "\n" + attachment.getUrl());
//Moves the cursor
if (selectionBefore >= 0)
toot_content.setSelection(selectionBefore);
}
toot_picture_container.addView(imageView, attachments.size(), imParams);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
@ -826,12 +830,16 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
for(Attachment attachment: attachments){
if( Integer.valueOf(attachment.getId()) == viewId){
attachments.remove(attachment);
//Adds the url at the end of the toot
int selectionBefore = toot_content.getSelectionStart();
toot_content.setText(toot_content.getText().toString().replace(attachment.getUrl(),""));
//Moves the cursor
if( selectionBefore >= 0 )
toot_content.setSelection(selectionBefore);
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean show_media_urls = sharedpreferences.getBoolean(Helper.SET_MEDIA_URLS, true);
if( show_media_urls) {
//Adds the url at the end of the toot
int selectionBefore = toot_content.getSelectionStart();
toot_content.setText(toot_content.getText().toString().replace(attachment.getUrl(), ""));
//Moves the cursor
if (selectionBefore >= 0)
toot_content.setSelection(selectionBefore);
}
((ViewGroup) namebar.getParent()).removeView(namebar);
break;
}

View File

@ -113,6 +113,18 @@ public class SettingsFragment extends Fragment {
}
});
boolean show_media_urls = sharedpreferences.getBoolean(Helper.SET_MEDIA_URLS, true);
final CheckBox set_auto_add_media_url = (CheckBox) rootView.findViewById(R.id.set_auto_add_media_url);
set_auto_add_media_url.setChecked(show_media_urls);
set_auto_add_media_url.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_MEDIA_URLS, set_auto_add_media_url.isChecked());
editor.apply();
}
});
boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
final CheckBox set_share_validation = (CheckBox) rootView.findViewById(R.id.set_share_validation);

View File

@ -193,6 +193,7 @@ public class Helper {
public static final String SET_POPUP_PUSH = "set_popup_push";
public static final String SET_NSFW_TIMEOUT = "set_nsfw_timeout";
public static final String SET_TABS = "set_tabs";
public static final String SET_MEDIA_URLS = "set_media_urls";
public static final int ATTACHMENT_ALWAYS = 1;
public static final int ATTACHMENT_WIFI = 2;
public static final int ATTACHMENT_ASK = 3;

View File

@ -46,9 +46,13 @@
android:text="@string/set_show_error_messages"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_auto_add_media_url"
android:layout_width="wrap_content"
android:text="@string/set_auto_add_media_url"
android:layout_height="wrap_content" />
<CheckBox
android:layout_marginTop="10dp"
android:id="@+id/set_auto_store"
android:layout_width="wrap_content"
android:text="@string/set_auto_store_toot"

View File

@ -46,9 +46,13 @@
android:text="@string/set_show_error_messages"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_auto_add_media_url"
android:layout_width="wrap_content"
android:text="@string/set_auto_add_media_url"
android:layout_height="wrap_content" />
<CheckBox
android:layout_marginTop="10dp"
android:id="@+id/set_auto_store"
android:layout_width="wrap_content"
android:text="@string/set_auto_store_toot"

View File

@ -270,7 +270,7 @@
<string name="set_display_reply">Afficher le message précédent lors d\'une réponse</string>
<string name="set_folder_title">Destination : </string>
<string name="set_auto_store_toot">Enregistrer les brouillons automatiquement</string>
<string name="set_auto_add_media_url">Ajouter l\'URL des médias dans les pouets</string>
<string name="settings_title_notifications">Gestion des notifications</string>
<string name="set_notif_follow">Notifier lorsque quelquun me suit</string>
<string name="set_notif_follow_ask">Notifier lorsque quelqu\'un demande à me suivre</string>

View File

@ -276,6 +276,7 @@
<string name="set_display_reply">Display previous message in responses</string>
<string name="set_folder_title">Path: </string>
<string name="set_auto_store_toot">Save drafts automatically</string>
<string name="set_auto_add_media_url">Add URL of media in toots</string>
<string name="settings_title_notifications">Manage notifications</string>
<string name="set_notif_follow">Notify when someone follows you</string>
<string name="set_notif_follow_ask">Notify when someone requests to follow you</string>