added language selector for status editor, layout fix

This commit is contained in:
nuclearfog 2023-06-03 14:05:15 +02:00
parent 78d877cdf3
commit e8e510daaf
No known key found for this signature in database
GPG Key ID: 03488A185C476379
12 changed files with 147 additions and 35 deletions

View File

@ -650,6 +650,8 @@ public class Mastodon implements Connection {
params.add("spoiler_text=true");
if (update.getText() != null)
params.add("status=" + StringUtils.encode(update.getText()));
if (update.getLanguageCode() != null)
params.add("language=" + update.getLanguageCode());
if (update.getReplyId() != 0)
params.add("in_reply_to_id=" + update.getReplyId());
if (update.getVisibility() == Status.VISIBLE_DIRECT)

View File

@ -78,6 +78,7 @@ public class StatusUpdate implements Serializable, Closeable {
private boolean spoiler = false;
private int visibility = Status.VISIBLE_PUBLIC;
private String text;
private String languageCode;
// attachment attributes
@Nullable
@ -119,6 +120,7 @@ public class StatusUpdate implements Serializable, Closeable {
sensitive = status.isSensitive();
spoiler = status.isSpoiler();
visibility = status.getVisibility();
languageCode = status.getLanguage();
if (status.getPoll() != null) {
poll = new PollUpdate(status.getPoll());
}
@ -153,6 +155,15 @@ public class StatusUpdate implements Serializable, Closeable {
this.text = text;
}
/**
* add status language
*
* @param languageCode ISO 639 language code
*/
public void addLanguage(String languageCode) {
this.languageCode = languageCode;
}
/**
* Add file uri and check if file is valid
*
@ -327,6 +338,16 @@ public class StatusUpdate implements Serializable, Closeable {
return text;
}
/**
* get status language
*
* @return ISO 639 language code
*/
@Nullable
public String getLanguageCode() {
return languageCode;
}
/**
* get type of attachment
* currently there is only one type of media used at once

View File

@ -128,7 +128,7 @@ public class LoginActivity extends AppCompatActivity implements ActivityResultCa
connectionDialog = new ConnectionDialog(this);
loginAsync = new LoginAction(this);
adapter.addItems(R.array.networks);
adapter.setItems(R.array.networks);
hostSelector.setAdapter(adapter);
if (savedInstanceState != null) {
Serializable data = savedInstanceState.getSerializable(KEY_SAVE);

View File

@ -191,10 +191,10 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
AppStyles.setTheme(root);
AppStyles.setOverflowIcon(toolbar, settings.getIconColor());
fontAdapter.addFonts(GlobalSettings.FONT_TYPES);
fontAdapter.addItems(GlobalSettings.FONT_NAMES);
scaleAdapter.addItems(R.array.scales);
locationAdapter.addItem(settings.getTrendLocation().getFullName());
fontAdapter.setFonts(GlobalSettings.FONT_TYPES);
fontAdapter.setItems(GlobalSettings.FONT_NAMES);
scaleAdapter.setItems(R.array.scales);
locationAdapter.setItem(settings.getTrendLocation().getFullName());
location_dropdown.setAdapter(locationAdapter);
fontSelector.setAdapter(fontAdapter);
@ -664,7 +664,7 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
position = i;
}
}
locationAdapter.addItems(items);
locationAdapter.setItems(items);
// set item of a previously selection if exists
if (position >= 0) {
location_dropdown.setSelection(position, false);

View File

@ -16,7 +16,11 @@ import org.nuclearfog.twidda.config.GlobalSettings;
import java.util.Arrays;
/**
* Dropdown list adapter used for spinners
*
* @author nuclearfog
*/
public class DropdownAdapter extends BaseAdapter {
private GlobalSettings settings;
@ -25,7 +29,9 @@ public class DropdownAdapter extends BaseAdapter {
private String[] items = {};
private Typeface[] fonts = {};
/**
*
*/
public DropdownAdapter(Context context) {
settings = GlobalSettings.getInstance(context);
this.context = context;
@ -71,31 +77,52 @@ public class DropdownAdapter extends BaseAdapter {
return convertView;
}
public void addItem(String item) {
/**
* set single item
*
* @param item item string
*/
public void setItem(String item) {
this.items = new String[] {item};
notifyDataSetChanged();
}
public void addItems(@ArrayRes int arrayRes) {
/**
* set items from string array resource
*
* @param arrayRes array resource containing strings
*/
public void setItems(@ArrayRes int arrayRes) {
TypedArray tArray = context.getResources().obtainTypedArray(arrayRes);
items = new String[tArray.length()];
for (int i = 0; i < tArray.length(); i++) {
items[i] = tArray.getString(i);
String item = tArray.getString(i);
if (item != null) {
items[i] = item;
} else {
items[i] = "";
}
}
tArray.recycle();
notifyDataSetChanged();
}
public void addItems(String[] items) {
/**
* set items from string array
*
* @param items string array containing items
*/
public void setItems(String[] items) {
this.items = Arrays.copyOf(items, items.length);
notifyDataSetChanged();
}
public void addFonts(Typeface[] fonts) {
/**
* set font for items
*
* @param fonts font array
*/
public void setFonts(Typeface[] fonts) {
this.fonts = Arrays.copyOf(fonts, fonts.length);
}
}

View File

@ -59,7 +59,7 @@ public class PollDialog extends Dialog implements OnClickListener {
hide_votes = findViewById(R.id.dialog_poll_hide_total);
DropdownAdapter adapter = new DropdownAdapter(context);
adapter.addItems(R.array.timeunits);
adapter.setItems(R.array.timeunits);
timeUnitSelector.setAdapter(adapter);
timeUnitSelector.setSelection(2);

View File

@ -19,6 +19,8 @@ import org.nuclearfog.twidda.config.GlobalSettings;
import org.nuclearfog.twidda.model.Status;
import org.nuclearfog.twidda.ui.adapter.DropdownAdapter;
import java.util.Locale;
/**
* status editor preference dialog used to set additional status information
*
@ -30,6 +32,8 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
private StatusUpdate statusUpdate;
private Locale[] languages;
/**
* @param statusUpdate status information from status editor
*/
@ -42,23 +46,37 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
SwitchButton spoilerCheck = findViewById(R.id.dialog_status_spoiler);
View statusVisibility = findViewById(R.id.dialog_status_visibility_container);
View statusSpoiler = findViewById(R.id.dialog_status_spoiler_container);
Spinner languageSelector = findViewById(R.id.dialog_status_language);
visibilitySelector = findViewById(R.id.dialog_status_visibility);
GlobalSettings settings = GlobalSettings.getInstance(context);
AppStyles.setTheme(rootView);
DropdownAdapter adapter = new DropdownAdapter(context);
visibilitySelector.setAdapter(adapter);
DropdownAdapter visibility_adapter = new DropdownAdapter(context);
DropdownAdapter language_adapter = new DropdownAdapter(context);
languageSelector.setAdapter(language_adapter);
languageSelector.setSelected(false);
visibilitySelector.setAdapter(visibility_adapter);
visibilitySelector.setSelection(0, false);
visibilitySelector.setSelected(false);
AppStyles.setTheme(rootView);
languages = Locale.getAvailableLocales();
String[] language_names = new String[languages.length + 1];
language_names[0] = context.getString(R.string.dialog_status_language_empty);
for (int i = 0 ; i < languages.length ; i++) {
language_names[i + 1] = languages[i].getDisplayLanguage() + " " + languages[i].getCountry();
}
language_adapter.setItems(language_names);
if (!settings.getLogin().getConfiguration().statusVisibilitySupported()) {
statusVisibility.setVisibility(View.GONE);
}
if (!settings.getLogin().getConfiguration().statusSpoilerSupported()) {
statusSpoiler.setVisibility(View.GONE);
}
adapter.addItems(R.array.visibility);
visibility_adapter.setItems(R.array.visibility);
sensitiveCheck.setOnCheckedChangeListener(this);
spoilerCheck.setOnCheckedChangeListener(this);
languageSelector.setOnItemSelectedListener(this);
visibilitySelector.setOnItemSelectedListener(this);
}
@ -118,6 +136,11 @@ public class StatusPreferenceDialog extends Dialog implements OnCheckedChangeLis
statusUpdate.setVisibility(Status.VISIBLE_UNLISTED);
break;
}
} else if (parent.getId() == R.id.dialog_status_language) {
if (position > 0) {
Locale language = languages[position - 1];
statusUpdate.addLanguage(language.getLanguage());
}
}
}

View File

@ -82,7 +82,7 @@ public class WebPushDialog extends Dialog implements OnCheckedChangeListener, On
policySelector.setSelection(2);
break;
}
adapter.addItems(R.array.push_policy);
adapter.setItems(R.array.push_policy);
AppStyles.setTheme(root);
mention.setOnCheckedChangeListener(this);

View File

@ -10,7 +10,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_status_title"
android:textSize="@dimen/dialog_status_title_textsize"
android:textSize="@dimen/dialog_status_textsize_title"
android:layout_marginBottom="@dimen/dialog_status_layout_margins"
android:lines="1" />
@ -18,7 +18,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="@dimen/dialog_status_layout_margins">
android:layout_marginBottom="@dimen/dialog_status_layout_margins"
android:gravity="center_vertical">
<com.kyleduo.switchbutton.SwitchButton
android:id="@+id/dialog_status_sensitive"
@ -30,7 +31,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_status_sensitive"
android:lines="1" />
android:lines="1"
android:textSize="@dimen/dialog_status_textsize_small" />
</LinearLayout>
<LinearLayout
@ -38,7 +41,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="@dimen/dialog_status_layout_margins">
android:layout_marginBottom="@dimen/dialog_status_layout_margins"
android:gravity="center_vertical">
<com.kyleduo.switchbutton.SwitchButton
android:id="@+id/dialog_status_spoiler"
@ -50,6 +54,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dialog_status_spoiler"
android:textSize="@dimen/dialog_status_textsize_small"
android:lines="1" />
</LinearLayout>
@ -57,7 +62,9 @@
android:id="@+id/dialog_status_visibility_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="horizontal"
android:layout_marginBottom="@dimen/dialog_status_layout_margins"
android:gravity="center_vertical">
<TextView
android:layout_width="0dp"
@ -66,13 +73,39 @@
android:layout_marginEnd="@dimen/dialog_status_layout_margins"
android:layout_weight="2"
android:gravity="end"
android:textSize="@dimen/dialog_status_textsize_small"
android:lines="1" />
<Spinner
android:id="@+id/dialog_status_visibility"
android:layout_width="0dp"
android:layout_height="@dimen/dialog_status_dropdown_height"
android:layout_weight="3" />
android:layout_weight="5" />
</LinearLayout>
<LinearLayout
android:id="@+id/dialog_status_language_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/dialog_status_language"
android:layout_marginEnd="@dimen/dialog_status_layout_margins"
android:layout_weight="2"
android:textSize="@dimen/dialog_status_textsize_small"
android:gravity="end"
android:lines="1" />
<Spinner
android:id="@+id/dialog_status_language"
android:layout_width="0dp"
android:layout_height="@dimen/dialog_status_dropdown_height"
android:layout_weight="5" />
</LinearLayout>

View File

@ -29,6 +29,7 @@
<string name="info_database_cleared">Datenbank gelöscht</string>
<string name="info_notification_dismiss">Nachricht verworfen</string>
<string name="info_domain_blocked">Domain gesperrt!</string>
<string name="info_webpush_update">Push-Konfiguration wurde aktualisiert</string>
<string name="info_error">Fehler!</string>
<string name="menu_status_edit">bearbeiten</string>
<string name="menu_status_delete">löschen</string>
@ -318,6 +319,12 @@
<string name="notification_favorite">%1$s hat einen Status favorisiert</string>
<string name="notification_repost">%1$s hat einen Status geteilt</string>
<string name="notification_follow">%1$s folgt dir jetzt</string>
<string name="notification_status">%1$s hat was gepostet</string>
<string name="notification_edit">Ein Status von dir wurde geteilt.</string>
<string name="notification_poll">Eine Umfrage wurde beendet</string>
<string name="notification_request">%1$s folgt dir jetzt</string>
<string name="notification_mention">%1$s hat dich erwähnt</string>
<string name="notification_new">Neue Benachrichtigungen</string>
<string name="dialog_status_language">Sprache</string>
<string name="dialog_status_language_empty">keine Auswahl</string>
</resources>

View File

@ -296,7 +296,8 @@
<dimen name="item_option_edit_layout_margin">5dp</dimen>
<!--dimens of dialog_status.xml-->
<dimen name="dialog_status_title_textsize">20sp</dimen>
<dimen name="dialog_status_textsize_title">20sp</dimen>
<dimen name="dialog_status_textsize_small">11sp</dimen>
<dimen name="dialog_status_layout_padding">10dp</dimen>
<dimen name="dialog_status_layout_margins">5dp</dimen>
<dimen name="dialog_status_dropdown_height">22sp</dimen>

View File

@ -69,7 +69,7 @@
<string name="info_domain_removed">domain removed from the list</string>
<string name="info_hashtag_followed">hashtag followed</string>
<string name="info_domain_blocked">domain blocked!</string>
<string name="info_webpush_update">Push configuration updated!</string>
<string name="info_webpush_update">Push configuration updated</string>
<string name="info_error">Error</string>
<!-- toast messages for error information -->
@ -177,10 +177,6 @@
<string name="app_info_icons">svg icons from:</string>
<string name="app_info_icons_links" translatable="false">www.svgrepo.com www.entypo.com</string>
<!--network names-->
<string name="twitter" translatable="false">Twitter</string>
<string name="mastodon" translatable="false">Mastodon</string>
<string name="profile_image">Profile image</string>
<string name="login_pin">enter PIN</string>
<string name="login_key_enable">add keys</string>
@ -332,6 +328,8 @@
<string name="dialog_status_sensitive">mark content as sensitive</string>
<string name="dialog_status_spoiler">mark content as spoiler</string>
<string name="dialog_status_visibility">Visibility</string>
<string name="dialog_status_language">Language</string>
<string name="dialog_status_language_empty">nothing selected</string>
<string name="dialog_push_repost">on repost</string>
<string name="dialog_push_favorite">on favorite</string>
<string name="dialog_push_mention">on mention</string>