diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index ef6562d62..360f8d7e4 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -64,7 +64,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; -import java.util.Set; import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.TimeUnit; @@ -79,7 +78,6 @@ import app.fedilab.android.client.entities.api.Mention; import app.fedilab.android.client.entities.api.ScheduledStatus; import app.fedilab.android.client.entities.api.Status; import app.fedilab.android.client.entities.app.BaseAccount; -import app.fedilab.android.client.entities.app.Languages; import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.databinding.ActivityPaginationBinding; import app.fedilab.android.databinding.PopupContactBinding; @@ -383,61 +381,6 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana } else { Toasty.info(ComposeActivity.this, getString(R.string.toot_error_no_content), Toasty.LENGTH_SHORT).show(); } - } else if (item.getItemId() == R.id.action_language) { - final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(ComposeActivity.this); - Set storedLanguages = sharedpreferences.getStringSet(getString(R.string.SET_SELECTED_LANGUAGE), null); - - String[] codesArr = new String[0]; - String[] languagesArr = new String[0]; - String currentCode = sharedpreferences.getString(getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, null); - int selection = 0; - if (storedLanguages != null && storedLanguages.size() > 0) { - int i = 0; - codesArr = new String[storedLanguages.size()]; - languagesArr = new String[storedLanguages.size()]; - for (String language : storedLanguages) { - codesArr[i] = language; - languagesArr[i] = language; - if (currentCode != null && currentCode.equalsIgnoreCase(language)) { - selection = i; - } - i++; - } - } else { - List languages = Languages.get(ComposeActivity.this); - if (languages != null) { - codesArr = new String[languages.size()]; - languagesArr = new String[languages.size()]; - int i = 0; - for (Languages.Language language : languages) { - codesArr[i] = language.code; - languagesArr[i] = language.language; - if (currentCode != null && currentCode.equalsIgnoreCase(language.code)) { - selection = i; - } - i++; - } - } - } - - SharedPreferences.Editor editor = sharedpreferences.edit(); - AlertDialog.Builder builder = new AlertDialog.Builder(ComposeActivity.this, Helper.dialogStyle()); - builder.setTitle(getString(R.string.message_language)); - - builder.setSingleChoiceItems(languagesArr, selection, null); - String[] finalCodesArr = codesArr; - builder.setPositiveButton(R.string.validate, (dialog, which) -> { - int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); - editor.putString(getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, finalCodesArr[selectedPosition]); - editor.apply(); - dialog.dismiss(); - }); - builder.setNegativeButton(R.string.reset, (dialog, which) -> { - editor.putString(getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, null); - editor.apply(); - dialog.dismiss(); - }); - builder.create().show(); } return true; } @@ -672,6 +615,9 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana if (statusReply.spoiler_text != null) { statusDraftList.get(0).spoiler_text = statusReply.spoiler_text; } + if (statusReply.language != null && !statusReply.language.isEmpty()) { + statusDraftList.get(0).language = statusReply.language; + } //StatusDraftList at this point should only have one element statusList.addAll(statusDraftList); composeAdapter = new ComposeAdapter(statusList, statusCount, account, accountMention, visibility, editMessageId); diff --git a/app/src/main/java/app/fedilab/android/client/entities/app/Languages.java b/app/src/main/java/app/fedilab/android/client/entities/app/Languages.java index 23445a9a3..7855d851c 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/app/Languages.java +++ b/app/src/main/java/app/fedilab/android/client/entities/app/Languages.java @@ -14,7 +14,7 @@ package app.fedilab.android.client.entities.app; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ -import androidx.appcompat.app.AppCompatActivity; +import android.content.Context; import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; @@ -32,9 +32,9 @@ public class Languages implements Serializable { @SerializedName("languages") public List languages; - public static List get(AppCompatActivity activity) { + public static List get(Context context) { try { - InputStream is = activity.getAssets().open("languages/iso_639_1.json"); + InputStream is = context.getAssets().open("languages/iso_639_1.json"); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index 589d8242c..8e4a13690 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -87,6 +87,7 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Objects; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -101,6 +102,7 @@ import app.fedilab.android.client.entities.api.Poll; import app.fedilab.android.client.entities.api.Status; import app.fedilab.android.client.entities.api.Tag; import app.fedilab.android.client.entities.app.BaseAccount; +import app.fedilab.android.client.entities.app.Languages; import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.databinding.ComposeAttachmentItemBinding; import app.fedilab.android.databinding.ComposePollBinding; @@ -745,6 +747,7 @@ public class ComposeAdapter extends RecyclerView.Adapter max_car) { @@ -760,7 +763,7 @@ public class ComposeAdapter extends RecyclerView.Adapter { try { displayEmojiPicker(holder); @@ -1361,6 +1365,75 @@ public class ComposeAdapter extends RecyclerView.Adapter { + Set storedLanguages = sharedpreferences.getStringSet(context.getString(R.string.SET_SELECTED_LANGUAGE), null); + String[] codesArr = new String[0]; + String[] languagesArr = new String[0]; + + int selection = 0; + if (storedLanguages != null && storedLanguages.size() > 0) { + int i = 0; + codesArr = new String[storedLanguages.size()]; + languagesArr = new String[storedLanguages.size()]; + for (String language : storedLanguages) { + codesArr[i] = language; + languagesArr[i] = language; + if (statusDraft.language.equalsIgnoreCase(language)) { + selection = i; + } + i++; + } + } else { + + List languages = Languages.get(context); + if (languages != null) { + codesArr = new String[languages.size()]; + languagesArr = new String[languages.size()]; + int i = 0; + for (Languages.Language language : languages) { + codesArr[i] = language.code; + languagesArr[i] = language.language; + if (statusDraft.language.equalsIgnoreCase(language.code)) { + selection = i; + } + i++; + } + } + } + + SharedPreferences.Editor editor = sharedpreferences.edit(); + AlertDialog.Builder builder = new AlertDialog.Builder(context, Helper.dialogStyle()); + builder.setTitle(context.getString(R.string.message_language)); + + builder.setSingleChoiceItems(languagesArr, selection, null); + String[] finalCodesArr = codesArr; + builder.setPositiveButton(R.string.validate, (dialog, which) -> { + int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); + editor.putString(context.getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, finalCodesArr[selectedPosition]); + editor.apply(); + notifyItemChanged(holder.getLayoutPosition()); + dialog.dismiss(); + }); + builder.setNegativeButton(R.string.reset, (dialog, which) -> { + editor.putString(context.getString(R.string.SET_COMPOSE_LANGUAGE) + account.user_id + account.instance, null); + editor.apply(); + notifyItemChanged(holder.getLayoutPosition()); + dialog.dismiss(); + }); + builder.create().show(); + }); } } diff --git a/app/src/main/res/menu/menu_compose.xml b/app/src/main/res/menu/menu_compose.xml index 7845538a8..8fc21461c 100644 --- a/app/src/main/res/menu/menu_compose.xml +++ b/app/src/main/res/menu/menu_compose.xml @@ -11,11 +11,6 @@ android:icon="@drawable/ic_baseline_contact_page_24" android:title="@string/contact" app:showAsAction="ifRoom" /> -