From 3f30ffbf0f5ed504337e4310b2643fa850e1c97d Mon Sep 17 00:00:00 2001 From: tom79 Date: Fri, 21 Feb 2020 09:53:16 +0100 Subject: [PATCH] Fix issue #404 --- .../activities/PixelfedComposeActivity.java | 16 ++++ .../android/activities/TootActivity.java | 94 ++++++++++--------- 2 files changed, 66 insertions(+), 44 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/PixelfedComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/PixelfedComposeActivity.java index bb40e4db4..212f0d633 100644 --- a/app/src/main/java/app/fedilab/android/activities/PixelfedComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/PixelfedComposeActivity.java @@ -29,6 +29,7 @@ import android.content.pm.PackageManager; import android.content.res.ColorStateList; import android.database.sqlite.SQLiteDatabase; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.AsyncTask; @@ -41,7 +42,9 @@ import android.provider.MediaStore; import android.text.Editable; import android.text.Html; import android.text.InputType; +import android.text.SpannableString; import android.text.TextWatcher; +import android.text.style.ForegroundColorSpan; import android.util.Patterns; import android.view.LayoutInflater; import android.view.Menu; @@ -156,6 +159,7 @@ import es.dmoral.toasty.Toasty; import static app.fedilab.android.helper.Helper.ALPHA; import static app.fedilab.android.helper.Helper.MORSE; +import static app.fedilab.android.helper.Helper.THEME_LIGHT; import static app.fedilab.android.helper.Helper.countWithEmoji; @@ -1365,6 +1369,18 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (restoredScheduled || pixelfed_story.isChecked()) itemSchedule.setVisible(false); } + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + if( theme == THEME_LIGHT){ + //Hack for colors in compose menu + for(int i = 0 ; i < menu.size(); i++){ + MenuItem item = menu.getItem(i); + SpannableString s = new SpannableString(item.getTitle()); + s.setSpan(new ForegroundColorSpan(Color.BLACK), 0, s.length(), 0); + item.setTitle(s); + } + + } return true; } diff --git a/app/src/main/java/app/fedilab/android/activities/TootActivity.java b/app/src/main/java/app/fedilab/android/activities/TootActivity.java index c38fb1fd4..f8aabcce0 100644 --- a/app/src/main/java/app/fedilab/android/activities/TootActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/TootActivity.java @@ -42,7 +42,9 @@ import android.text.Editable; import android.text.Html; import android.text.InputFilter; import android.text.InputType; +import android.text.SpannableString; import android.text.TextWatcher; +import android.text.style.ForegroundColorSpan; import android.util.Patterns; import android.view.LayoutInflater; import android.view.Menu; @@ -132,6 +134,7 @@ import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import java.util.TimeZone; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -301,7 +304,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, JSONObject response = null; ArrayList successfullyUploadedFiles = null; try { - response = new JSONObject(intent.getStringExtra("response")); + response = new JSONObject(Objects.requireNonNull(intent.getStringExtra("response"))); } catch (JSONException e) { e.printStackTrace(); } @@ -693,6 +696,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, Matcher matcherALink = Patterns.WEB_URL.matcher(contentCount); while (matcherALink.find()) { final String url = matcherALink.group(1); + assert url != null; contentCount = contentCount.replace(url, "abcdefghijklmnopkrstuvw"); } } @@ -742,50 +746,41 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ImageView close_toot = actionBar.getCustomView().findViewById(R.id.close_toot); - close_toot.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); - assert inputMethodManager != null; - inputMethodManager.hideSoftInputFromWindow(toot_content.getWindowToken(), 0); - boolean storeToot = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true); - if (!storeToot) { - if (toot_content.getText().toString().trim().length() == 0 && (attachments == null || attachments.size() < 1) && toot_cw_content.getText().toString().trim().length() == 0) { - finish(); - } else if (!displayWYSIWYG() && initialContent.trim().equals(toot_content.getText().toString().trim())) { - finish(); - } else if (displayWYSIWYG() && initialContent.trim().equals(wysiwyg.getContentAsHTML().trim())) { - finish(); - } else { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TootActivity.this, style); - dialogBuilder.setMessage(R.string.save_draft); - dialogBuilder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - if (accountReply == null) { - storeToot(true, false); - } else { - storeToot(false, false); - } - dialog.dismiss(); - finish(); - } - }); - dialogBuilder.setNegativeButton(R.string.discard, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - finish(); - } - }); - AlertDialog alertDialog = dialogBuilder.create(); - alertDialog.setCancelable(false); - alertDialog.show(); - } - - } else { + close_toot.setOnClickListener(v -> { + InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); + assert inputMethodManager != null; + inputMethodManager.hideSoftInputFromWindow(toot_content.getWindowToken(), 0); + boolean storeToot = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true); + if (!storeToot) { + if (toot_content.getText().toString().trim().length() == 0 && (attachments == null || attachments.size() < 1) && toot_cw_content.getText().toString().trim().length() == 0) { finish(); + } else if (!displayWYSIWYG() && initialContent.trim().equals(toot_content.getText().toString().trim())) { + finish(); + } else if (displayWYSIWYG() && initialContent.trim().equals(wysiwyg.getContentAsHTML().trim())) { + finish(); + } else { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TootActivity.this, style); + dialogBuilder.setMessage(R.string.save_draft); + dialogBuilder.setPositiveButton(R.string.save, (dialog, id) -> { + if (accountReply == null) { + storeToot(true, false); + } else { + storeToot(false, false); + } + dialog.dismiss(); + finish(); + }); + dialogBuilder.setNegativeButton(R.string.discard, (dialog, id) -> { + dialog.dismiss(); + finish(); + }); + AlertDialog alertDialog = dialogBuilder.create(); + alertDialog.setCancelable(false); + alertDialog.show(); } + + } else { + finish(); } }); @@ -2409,7 +2404,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); final List emojis = new CustomEmojiDAO(getApplicationContext(), db).getAllEmojis(); //Displays button only if custom emojis - if (emojis != null && emojis.size() > 0 && (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion))) { + if (emojis != null && emojis.size() > 0 && (currentVersion.compareTo(minVersion) == 0 || currentVersion.equals(minVersion))) { itemEmoji.setVisible(true); } else { itemEmoji.setVisible(false); @@ -2430,6 +2425,17 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (itemContacts != null) itemContacts.setVisible(false); } + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + if( theme == THEME_LIGHT){ + //Hack for colors in compose menu + for(int i = 0 ; i < menu.size(); i++){ + MenuItem item = menu.getItem(i); + SpannableString s = new SpannableString(item.getTitle()); + s.setSpan(new ForegroundColorSpan(Color.BLACK), 0, s.length(), 0); + item.setTitle(s); + } + + } return true; }