From 51a098397d238128b73f481c3456885ce09445f8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 14 Jul 2020 12:00:58 +0200 Subject: [PATCH] move some code --- app/build.gradle | 1 - .../activities/PixelfedComposeActivity.java | 172 +----- .../android/activities/TootActivity.java | 27 +- .../activities/BaseFragmentActivity.java | 20 +- .../activities/PixelfedComposeActivity.java | 31 +- .../android/activities/TootActivity.java | 55 +- .../helper/MastalabAutoCompleteTextView.java | 99 +++- .../BasePixelfedComposeActivity.java | 193 ++++--- .../android/activities/BaseTootActivity.java | 493 ++++++------------ .../activities/MainBaseFragmentActivity.java | 37 +- 10 files changed, 461 insertions(+), 667 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a7e581d6c..645bcfdbd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -161,7 +161,6 @@ dependencies { //Playstore playstoreImplementation "io.github.kobakei:ratethisapp:1.2.0" playstoreImplementation "org.conscrypt:conscrypt-android:2.4.0" - playstoreImplementation 'com.github.stom79:country-picker-android:1.2.0' playstoreImplementation 'com.vanniktech:emoji-one:0.6.0' playstoreImplementation 'ja.burhanrashid52:photoeditor:0.4.0' diff --git a/app/src/common/java/app/fedilab/android/activities/PixelfedComposeActivity.java b/app/src/common/java/app/fedilab/android/activities/PixelfedComposeActivity.java index 7c9906310..7e9af64a2 100644 --- a/app/src/common/java/app/fedilab/android/activities/PixelfedComposeActivity.java +++ b/app/src/common/java/app/fedilab/android/activities/PixelfedComposeActivity.java @@ -1,33 +1,11 @@ package app.fedilab.android.activities; -import android.content.Context; -import android.content.DialogInterface; + import android.content.Intent; -import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.DialogFragment; - -import com.github.stom79.localepicker.CountryPicker; -import com.github.stom79.mytransl.MyTransL; -import com.github.stom79.mytransl.client.HttpsConnectionException; -import com.github.stom79.mytransl.translate.Translate; import com.vanniktech.emoji.EmojiPopup; -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import app.fedilab.android.R; -import app.fedilab.android.helper.Helper; -import es.dmoral.toasty.Toasty; /* Copyright 2020 Thomas Schneider * @@ -43,156 +21,12 @@ import es.dmoral.toasty.Toasty; * * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ -public class TootActivity extends BaseTootActivity{ - @Override - protected boolean actionTranslateClick() { - - SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - final CountryPicker picker = CountryPicker.newInstance(getString(R.string.which_language)); // dialog title - if (theme == Helper.THEME_LIGHT) { - picker.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog); - } else { - picker.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogDark); - } - if (toot_content.getText().length() == 0 && toot_cw_content.getText().length() == 0) - return true; - String dateString = sharedpreferences.getString(Helper.LAST_TRANSLATION_TIME, null); - if (dateString != null) { - Date dateCompare = Helper.stringToDate(TootActivity.this, dateString); - Date date = new Date(); - if (date.before(dateCompare)) { - Toasty.info(TootActivity.this, getString(R.string.please_wait), Toast.LENGTH_SHORT).show(); - return true; - } - } - picker.setListener((name, locale, flagDrawableResID) -> { - picker.dismiss(); - AlertDialog.Builder transAlert = new AlertDialog.Builder(TootActivity.this, style); - transAlert.setTitle(R.string.translate_toot); - - popup_trans = getLayoutInflater().inflate(R.layout.popup_translate, new LinearLayout(TootActivity.this), false); - transAlert.setView(popup_trans); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_TRANSLATION_TIME, Helper.dateToString(new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(Helper.SECONDES_BETWEEN_TRANSLATE)))); - editor.apply(); - TextView yandex_translate = popup_trans.findViewById(R.id.yandex_translate); - yandex_translate.setOnClickListener(v -> { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://translate.yandex.com/")); - startActivity(browserIntent); - }); - MyTransL myTransL = MyTransL.getInstance(MyTransL.translatorEngine.YANDEX); - myTransL.setYandexAPIKey(Helper.YANDEX_KEY); - myTransL.setObfuscation(true); - myTransL.setTimeout(60); - if (toot_cw_content.getText().toString().length() > 0) - myTransL.translate(toot_cw_content.getText().toString(), locale, new com.github.stom79.mytransl.client.Results() { - @Override - public void onSuccess(Translate translate) { - try { - if (translate.getTranslatedContent() == null) - return; - if (popup_trans != null) { - ProgressBar trans_progress_cw = popup_trans.findViewById(R.id.trans_progress_cw); - ProgressBar trans_progress_toot = popup_trans.findViewById(R.id.trans_progress_toot); - if (trans_progress_cw != null) - trans_progress_cw.setVisibility(View.GONE); - LinearLayout trans_container = popup_trans.findViewById(R.id.trans_container); - if (trans_container != null) { - TextView cw_trans = popup_trans.findViewById(R.id.cw_trans); - if (cw_trans != null) { - cw_trans.setVisibility(View.VISIBLE); - cw_trans.setText(translate.getTranslatedContent()); - } - } else { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - if (trans_progress_cw != null && trans_progress_toot != null && trans_progress_cw.getVisibility() == View.GONE && trans_progress_toot.getVisibility() == View.GONE) - if (dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE) != null) - dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(true); - } - } catch (IllegalArgumentException e) { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - - } - - @Override - public void onFail(HttpsConnectionException e) { - e.printStackTrace(); - } - }); - else { - ProgressBar trans_progress_cw = popup_trans.findViewById(R.id.trans_progress_cw); - trans_progress_cw.setVisibility(View.GONE); - } - if (toot_content.getText().toString().length() > 0) - myTransL.translate(toot_content.getText().toString(), locale, new com.github.stom79.mytransl.client.Results() { - @Override - public void onSuccess(Translate translate) { - try { - if (translate.getTranslatedContent() == null) - return; - if (popup_trans != null) { - ProgressBar trans_progress_cw = popup_trans.findViewById(R.id.trans_progress_cw); - ProgressBar trans_progress_toot = popup_trans.findViewById(R.id.trans_progress_toot); - if (trans_progress_toot != null) - trans_progress_toot.setVisibility(View.GONE); - LinearLayout trans_container = popup_trans.findViewById(R.id.trans_container); - if (trans_container != null) { - TextView toot_trans = popup_trans.findViewById(R.id.toot_trans); - if (toot_trans != null) { - toot_trans.setVisibility(View.VISIBLE); - toot_trans.setText(translate.getTranslatedContent()); - } - } else { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - if (trans_progress_cw != null && trans_progress_toot != null && trans_progress_cw.getVisibility() == View.GONE && trans_progress_toot.getVisibility() == View.GONE) - if (dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE) != null) - dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(true); - } - } catch (IllegalArgumentException e) { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - } - - @Override - public void onFail(HttpsConnectionException e) { - e.printStackTrace(); - } - }); - - transAlert.setPositiveButton(R.string.close, (dialog, whichButton) -> dialog.dismiss()); - transAlert.setNegativeButton(R.string.validate, (dialog, whichButton) -> { - TextView toot_trans = popup_trans.findViewById(R.id.toot_trans); - TextView cw_trans = popup_trans.findViewById(R.id.cw_trans); - if (toot_trans != null) { - toot_content.setText(toot_trans.getText().toString()); - toot_content.setSelection(toot_content.getText().length()); - } - if (cw_trans != null) - toot_cw_content.setText(cw_trans.getText().toString()); - dialog.dismiss(); - }); - dialogTrans = transAlert.create(); - transAlert.show(); - - dialogTrans.setOnShowListener(dialog -> { - Button negativeButton = ((AlertDialog) dialog) - .getButton(AlertDialog.BUTTON_NEGATIVE); - if (negativeButton != null) - negativeButton.setEnabled(false); - }); - - }); - picker.show(getSupportFragmentManager(), "COUNTRY_PICKER"); - return true; - } +public class PixelfedComposeActivity extends BasePixelfedComposeActivity{ @Override protected void launchPhotoEditor(Uri uri) { - Intent intent = new Intent(TootActivity.this, PhotoEditorActivity.class); + Intent intent = new Intent(PixelfedComposeActivity.this, PhotoEditorActivity.class); Bundle b = new Bundle(); intent.putExtra("imageUri", uri.toString()); intent.putExtras(b); diff --git a/app/src/common/java/app/fedilab/android/activities/TootActivity.java b/app/src/common/java/app/fedilab/android/activities/TootActivity.java index 248d8805b..7c9906310 100644 --- a/app/src/common/java/app/fedilab/android/activities/TootActivity.java +++ b/app/src/common/java/app/fedilab/android/activities/TootActivity.java @@ -5,6 +5,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; +import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; @@ -15,9 +16,11 @@ import android.widget.Toast; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import com.github.stom79.localepicker.CountryPicker; import com.github.stom79.mytransl.MyTransL; import com.github.stom79.mytransl.client.HttpsConnectionException; import com.github.stom79.mytransl.translate.Translate; +import com.vanniktech.emoji.EmojiPopup; import java.util.Date; import java.util.concurrent.TimeUnit; @@ -142,14 +145,14 @@ public class TootActivity extends BaseTootActivity{ toot_trans.setText(translate.getTranslatedContent()); } } else { - Toasty.error(BaseTootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); + Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); } if (trans_progress_cw != null && trans_progress_toot != null && trans_progress_cw.getVisibility() == View.GONE && trans_progress_toot.getVisibility() == View.GONE) if (dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE) != null) dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(true); } } catch (IllegalArgumentException e) { - Toasty.error(BaseTootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); + Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); } } @@ -183,5 +186,25 @@ public class TootActivity extends BaseTootActivity{ }); picker.show(getSupportFragmentManager(), "COUNTRY_PICKER"); + return true; + } + + + @Override + protected void launchPhotoEditor(Uri uri) { + Intent intent = new Intent(TootActivity.this, PhotoEditorActivity.class); + Bundle b = new Bundle(); + intent.putExtra("imageUri", uri.toString()); + intent.putExtras(b); + startActivity(intent); + } + + @Override + protected void displayEmojiPopup() { + final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content); + + toot_emoji.setOnClickListener(v -> { + emojiPopup.toggle(); // Toggles visibility of the Popup. + }); } } diff --git a/app/src/lite/java/app/fedilab/android/activities/BaseFragmentActivity.java b/app/src/lite/java/app/fedilab/android/activities/BaseFragmentActivity.java index 88dc3d677..1ae1e3aac 100644 --- a/app/src/lite/java/app/fedilab/android/activities/BaseFragmentActivity.java +++ b/app/src/lite/java/app/fedilab/android/activities/BaseFragmentActivity.java @@ -1,4 +1,20 @@ package app.fedilab.android.activities; -public class BaseFragmentActivity { -} + +/* Copyright 2020 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + + +public class BaseFragmentActivity extends MainBaseFragmentActivity{} diff --git a/app/src/lite/java/app/fedilab/android/activities/PixelfedComposeActivity.java b/app/src/lite/java/app/fedilab/android/activities/PixelfedComposeActivity.java index 204142159..7085d448b 100644 --- a/app/src/lite/java/app/fedilab/android/activities/PixelfedComposeActivity.java +++ b/app/src/lite/java/app/fedilab/android/activities/PixelfedComposeActivity.java @@ -1,31 +1,6 @@ package app.fedilab.android.activities; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; import android.net.Uri; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.DialogFragment; - -import com.github.stom79.mytransl.MyTransL; -import com.github.stom79.mytransl.client.HttpsConnectionException; -import com.github.stom79.mytransl.translate.Translate; - -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import app.fedilab.android.R; -import app.fedilab.android.helper.Helper; -import es.dmoral.toasty.Toasty; /* Copyright 2020 Thomas Schneider * @@ -41,11 +16,7 @@ import es.dmoral.toasty.Toasty; * * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ -public class TootActivity extends BaseTootActivity{ - @Override - protected boolean actionTranslateClick() { - return true; - } +public class PixelfedComposeActivity extends BasePixelfedComposeActivity{ @Override protected void launchPhotoEditor(Uri uri) {} diff --git a/app/src/lite/java/app/fedilab/android/activities/TootActivity.java b/app/src/lite/java/app/fedilab/android/activities/TootActivity.java index f41bb833d..204142159 100644 --- a/app/src/lite/java/app/fedilab/android/activities/TootActivity.java +++ b/app/src/lite/java/app/fedilab/android/activities/TootActivity.java @@ -1,4 +1,57 @@ package app.fedilab.android.activities; -public class TootActivity { +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; + +import com.github.stom79.mytransl.MyTransL; +import com.github.stom79.mytransl.client.HttpsConnectionException; +import com.github.stom79.mytransl.translate.Translate; + +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import app.fedilab.android.R; +import app.fedilab.android.helper.Helper; +import es.dmoral.toasty.Toasty; + +/* Copyright 2020 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ +public class TootActivity extends BaseTootActivity{ + @Override + protected boolean actionTranslateClick() { + return true; + } + + @Override + protected void launchPhotoEditor(Uri uri) {} + + @Override + protected void displayEmojiPopup() {} + + } diff --git a/app/src/lite/java/app/fedilab/android/helper/MastalabAutoCompleteTextView.java b/app/src/lite/java/app/fedilab/android/helper/MastalabAutoCompleteTextView.java index a2ecf029d..c629e56af 100644 --- a/app/src/lite/java/app/fedilab/android/helper/MastalabAutoCompleteTextView.java +++ b/app/src/lite/java/app/fedilab/android/helper/MastalabAutoCompleteTextView.java @@ -1,33 +1,104 @@ package app.fedilab.android.helper; -/* Copyright 2020 Thomas Schneider - * - * This file is a part of Fedilab - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Fedilab; if not, - * see . */ import android.content.Context; +import android.os.Build; +import android.os.Bundle; import android.util.AttributeSet; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputConnection; + +import androidx.core.view.inputmethod.EditorInfoCompat; +import androidx.core.view.inputmethod.InputConnectionCompat; +import androidx.core.view.inputmethod.InputContentInfoCompat; + public class MastalabAutoCompleteTextView extends androidx.appcompat.widget.AppCompatAutoCompleteTextView { + + private String[] imgTypeString; + private KeyBoardInputCallbackListener keyBoardInputCallbackListener; + final InputConnectionCompat.OnCommitContentListener callback = + new InputConnectionCompat.OnCommitContentListener() { + @Override + public boolean onCommitContent(InputContentInfoCompat inputContentInfo, + int flags, Bundle opts) { + + // read and display inputContentInfo asynchronously + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && (flags & + InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) { + try { + inputContentInfo.requestPermission(); + } catch (Exception e) { + return false; // return false if failed + } + } + boolean supported = false; + for (final String mimeType : imgTypeString) { + if (inputContentInfo.getDescription().hasMimeType(mimeType)) { + supported = true; + break; + } + } + if (!supported) { + return false; + } + + if (keyBoardInputCallbackListener != null) { + keyBoardInputCallbackListener.onCommitContent(inputContentInfo, flags, opts); + } + return true; // return true if succeeded + } + }; + + public MastalabAutoCompleteTextView(Context context) { super(context); + initView(); } public MastalabAutoCompleteTextView(Context context, AttributeSet attrs) { super(context, attrs); + setText(getText()); + initView(); } public MastalabAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); + initView(); + } + + @Override + public InputConnection onCreateInputConnection(EditorInfo outAttrs) { + final InputConnection ic = super.onCreateInputConnection(outAttrs); + EditorInfoCompat.setContentMimeTypes(outAttrs, + imgTypeString); + return InputConnectionCompat.createWrapper(ic, outAttrs, callback); + } + + private void initView() { + imgTypeString = new String[]{"image/png", + "image/gif", + "image/jpeg", + "image/webp"}; + } + + public void setKeyBoardInputCallbackListener(KeyBoardInputCallbackListener keyBoardInputCallbackListener) { + this.keyBoardInputCallbackListener = keyBoardInputCallbackListener; + } + + @SuppressWarnings("unused") + public String[] getImgTypeString() { + return imgTypeString; + } + + @SuppressWarnings("unused") + public void setImgTypeString(String[] imgTypeString) { + this.imgTypeString = imgTypeString; + } + + + public interface KeyBoardInputCallbackListener { + void onCommitContent(InputContentInfoCompat inputContentInfo, + int flags, Bundle opts); } } diff --git a/app/src/main/java/app/fedilab/android/activities/BasePixelfedComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/BasePixelfedComposeActivity.java index 8e66d2a9a..d774ec0cd 100644 --- a/app/src/main/java/app/fedilab/android/activities/BasePixelfedComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BasePixelfedComposeActivity.java @@ -82,7 +82,6 @@ import com.bumptech.glide.request.transition.Transition; import com.smarteist.autoimageslider.IndicatorAnimations; import com.smarteist.autoimageslider.SliderAnimations; import com.smarteist.autoimageslider.SliderView; -import com.vanniktech.emoji.EmojiPopup; import net.gotev.uploadservice.MultipartUploadRequest; import net.gotev.uploadservice.ServerResponse; @@ -168,7 +167,7 @@ import static app.fedilab.android.helper.Helper.countWithEmoji; * Toot activity class */ -public class PixelfedComposeActivity extends BaseActivity implements UploadStatusDelegate, OnPostActionInterface, OnRetrieveSearcAccountshInterface, OnPostStatusActionInterface, OnRetrieveSearchInterface, OnRetrieveEmojiInterface, OnDownloadInterface, OnRetrieveAttachmentInterface { +public abstract class BasePixelfedComposeActivity extends BaseActivity implements UploadStatusDelegate, OnPostActionInterface, OnRetrieveSearcAccountshInterface, OnPostStatusActionInterface, OnRetrieveSearchInterface, OnRetrieveEmojiInterface, OnDownloadInterface, OnRetrieveAttachmentInterface { public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 754; @@ -188,7 +187,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu private boolean isSensitive = false; private ImageButton toot_visibility; private Button toot_it; - private MastalabAutoCompleteTextView toot_content; + protected MastalabAutoCompleteTextView toot_content; private CheckBox toot_sensitive; private long restored; private TextView title; @@ -212,13 +211,14 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu private SliderView imageSlider; private SliderAdapter sliderAdapter; private CheckBox pixelfed_story; - + protected ImageButton toot_emoji; + protected LinearLayout drawer_layout; private BroadcastReceiver imageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String imgpath = intent.getStringExtra("imgpath"); if (imgpath != null) { - prepareUpload(PixelfedComposeActivity.this, Uri.fromFile(new File(imgpath)), null, uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, Uri.fromFile(new File(imgpath)), null, uploadReceiver); } } }; @@ -557,8 +557,8 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (actionBar != null) { LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); assert inflater != null; - View view = inflater.inflate(R.layout.toot_action_bar, new LinearLayout(PixelfedComposeActivity.this), false); - view.setBackground(new ColorDrawable(ContextCompat.getColor(PixelfedComposeActivity.this, R.color.cyanea_primary))); + View view = inflater.inflate(R.layout.toot_action_bar, new LinearLayout(BasePixelfedComposeActivity.this), false); + view.setBackground(new ColorDrawable(ContextCompat.getColor(BasePixelfedComposeActivity.this, R.color.cyanea_primary))); actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ImageView close_toot = actionBar.getCustomView().findViewById(R.id.close_toot); @@ -574,7 +574,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu } else if (initialContent.trim().equals(toot_content.getText().toString().trim())) { finish(); } else { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PixelfedComposeActivity.this, style); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BasePixelfedComposeActivity.this, style); dialogBuilder.setMessage(R.string.save_draft); dialogBuilder.setPositiveButton(R.string.save, (dialog, id) -> { if (accountReply == null) { @@ -610,7 +610,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu toot_it = findViewById(R.id.toot_it); attachments = new ArrayList<>(); imageSlider = findViewById(R.id.imageSlider); - sliderAdapter = new SliderAdapter(new WeakReference<>(PixelfedComposeActivity.this), true, attachments); + sliderAdapter = new SliderAdapter(new WeakReference<>(BasePixelfedComposeActivity.this), true, attachments); imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM); imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION); imageSlider.setSliderAdapter(sliderAdapter); @@ -626,16 +626,12 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu //There is no media the button is hidden upload_media.setVisibility(View.INVISIBLE); toot_sensitive = findViewById(R.id.toot_sensitive); - LinearLayout drawer_layout = findViewById(R.id.drawer_layout); + drawer_layout = findViewById(R.id.drawer_layout); ImageButton toot_emoji = findViewById(R.id.toot_emoji); LinearLayout bottom_bar_tooting = findViewById(R.id.bottom_bar_tooting); isScheduled = false; if (sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, false)) { - final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content); - - toot_emoji.setOnClickListener(v -> { - emojiPopup.toggle(); // Toggles visibility of the Popup. - }); + displayEmojiPopup(); } else { toot_emoji.setVisibility(View.GONE); } @@ -653,11 +649,11 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(PixelfedComposeActivity.this); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(BasePixelfedComposeActivity.this); int iconColor = prefs.getInt("theme_icons_color", -1); if (iconColor != -1) { - Helper.changeDrawableColor(PixelfedComposeActivity.this, toot_visibility, iconColor); - Helper.changeDrawableColor(PixelfedComposeActivity.this, toot_emoji, iconColor); + Helper.changeDrawableColor(BasePixelfedComposeActivity.this, toot_visibility, iconColor); + Helper.changeDrawableColor(BasePixelfedComposeActivity.this, toot_emoji, iconColor); toot_sensitive.setButtonTintList(ColorStateList.valueOf(iconColor)); toot_sensitive.setTextColor(iconColor); } @@ -674,7 +670,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (accountReplyToken != null) { String[] val = accountReplyToken.split("\\|"); if (val.length == 2) { - accountReply = new AccountDAO(PixelfedComposeActivity.this, db).getUniqAccount(val[0], val[1]); + accountReply = new AccountDAO(BasePixelfedComposeActivity.this, db).getUniqAccount(val[0], val[1]); } } removed = b.getBoolean("removed"); @@ -715,7 +711,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu instanceReply = accountReply.getInstance(); } if (accountReply == null) - account = new AccountDAO(PixelfedComposeActivity.this, db).getUniqAccount(userIdReply, instanceReply); + account = new AccountDAO(BasePixelfedComposeActivity.this, db).getUniqAccount(userIdReply, instanceReply); else account = accountReply; @@ -725,7 +721,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu toot_content.requestFocus(); - Helper.loadGiF(PixelfedComposeActivity.this, account, pp_actionBar); + Helper.loadGiF(BasePixelfedComposeActivity.this, account, pp_actionBar); if (visibility == null) { @@ -760,9 +756,9 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu pickup_picture.setOnClickListener(v -> { - if (ContextCompat.checkSelfPermission(PixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != + if (ContextCompat.checkSelfPermission(BasePixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(PixelfedComposeActivity.this, + ActivityCompat.requestPermissions(BasePixelfedComposeActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); return; @@ -789,9 +785,9 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu upload_media.setOnClickListener(v -> { - if (ContextCompat.checkSelfPermission(PixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != + if (ContextCompat.checkSelfPermission(BasePixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(PixelfedComposeActivity.this, + ActivityCompat.requestPermissions(BasePixelfedComposeActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); return; @@ -817,7 +813,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu }); - TextWatcher textWatcher = initializeTextWatcher(PixelfedComposeActivity.this, social, toot_content, toot_space_left, pp_actionBar, pp_progress, PixelfedComposeActivity.this, PixelfedComposeActivity.this, PixelfedComposeActivity.this); + TextWatcher textWatcher = initializeTextWatcher(BasePixelfedComposeActivity.this, social, toot_content, toot_space_left, pp_actionBar, pp_progress, BasePixelfedComposeActivity.this, BasePixelfedComposeActivity.this, BasePixelfedComposeActivity.this); toot_content.addTextChangedListener(textWatcher); @@ -879,7 +875,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu } } } else { - Toasty.success(PixelfedComposeActivity.this, getString(R.string.added_to_story), Toast.LENGTH_LONG).show(); + Toasty.success(BasePixelfedComposeActivity.this, getString(R.string.added_to_story), Toast.LENGTH_LONG).show(); } } @@ -900,7 +896,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (mToast != null) { mToast.cancel(); } - mToast = Toasty.error(PixelfedComposeActivity.this, message, Toast.LENGTH_SHORT); + mToast = Toasty.error(BasePixelfedComposeActivity.this, message, Toast.LENGTH_SHORT); mToast.show(); } @@ -914,16 +910,16 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu break; } try { - prepareUpload(PixelfedComposeActivity.this, fileUri, null, uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, fileUri, null, uploadReceiver); count++; } catch (Exception e) { e.printStackTrace(); - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); upload_media.setEnabled(true); toot_it.setEnabled(true); } } else { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); } } } @@ -937,7 +933,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu try { photoFile = createImageFile(); } catch (IOException ignored) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); } // Continue only if the File was successfully created if (photoFile != null) { @@ -978,13 +974,13 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu boolean photo_editor = sharedpreferences.getBoolean(Helper.SET_PHOTO_EDITOR, true); if (requestCode == PICK_IMAGE && resultCode == RESULT_OK) { if (data == null) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); return; } ClipData clipData = data.getClipData(); if (data.getData() == null && clipData == null) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); return; } if (clipData != null) { @@ -996,40 +992,32 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu } uploadSharedImage(mArrayUri); } else { - String filename = Helper.getFileName(PixelfedComposeActivity.this, data.getData()); + String filename = Helper.getFileName(BasePixelfedComposeActivity.this, data.getData()); ContentResolver cr = getContentResolver(); String mime = cr.getType(data.getData()); if (mime != null && (mime.toLowerCase().contains("video") || mime.toLowerCase().contains("gif"))) { - prepareUpload(PixelfedComposeActivity.this, data.getData(), filename, uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, data.getData(), filename, uploadReceiver); } else if (mime != null && mime.toLowerCase().contains("image")) { if (photo_editor) { - Intent intent = new Intent(PixelfedComposeActivity.this, PhotoEditorActivity.class); - Bundle b = new Bundle(); - intent.putExtra("imageUri", data.getData().toString()); - intent.putExtras(b); - startActivity(intent); + launchPhotoEditor(data.getData()); } else { - prepareUpload(PixelfedComposeActivity.this, data.getData(), filename, uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, data.getData(), filename, uploadReceiver); } } else if (mime != null && mime.toLowerCase().contains("audio")) { - prepareUpload(PixelfedComposeActivity.this, data.getData(), filename, uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, data.getData(), filename, uploadReceiver); } else { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); } } } else if (requestCode == SEND_VOICE_MESSAGE && resultCode == RESULT_OK) { Uri uri = Uri.fromFile(new File(getCacheDir() + "/fedilab_recorded_audio.wav")); - prepareUpload(PixelfedComposeActivity.this, uri, "fedilab_recorded_audio.wav", uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, uri, "fedilab_recorded_audio.wav", uploadReceiver); } else if (requestCode == TAKE_PHOTO && resultCode == RESULT_OK) { if (photo_editor) { - Intent intent = new Intent(PixelfedComposeActivity.this, PhotoEditorActivity.class); - Bundle b = new Bundle(); - intent.putExtra("imageUri", photoFileUri.toString()); - intent.putExtras(b); - startActivity(intent); + launchPhotoEditor(photoFileUri); } else { - prepareUpload(PixelfedComposeActivity.this, photoFileUri, null, uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, photoFileUri, null, uploadReceiver); } } } @@ -1037,7 +1025,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu private void prepareUpload(Activity activity, Uri uri, String filename, UploadServiceSingleBroadcastReceiver uploadReceiver) { pixelfed_story.setEnabled(false); if (uploadReceiver == null) { - uploadReceiver = new UploadServiceSingleBroadcastReceiver(PixelfedComposeActivity.this); + uploadReceiver = new UploadServiceSingleBroadcastReceiver(BasePixelfedComposeActivity.this); uploadReceiver.register(this); } new asyncPicture(activity, pixelfed_story.isChecked(), uri, filename, uploadReceiver).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -1046,9 +1034,9 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu @Override public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) { if (error != null) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); } else { - Toasty.success(PixelfedComposeActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + Toasty.success(BasePixelfedComposeActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); resetForNextToot(); } } @@ -1062,7 +1050,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu @Override public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, Exception exception) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); if (attachments.size() == 0) { pickup_picture.setVisibility(View.VISIBLE); imageSlider.setVisibility(View.GONE); @@ -1098,12 +1086,12 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (extras != null && extras.getString("imageUri") != null) { Uri imageUri = Uri.parse(extras.getString("imageUri")); if (imageUri == null) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); return; } - String filename = Helper.getFileName(PixelfedComposeActivity.this, imageUri); + String filename = Helper.getFileName(BasePixelfedComposeActivity.this, imageUri); - prepareUpload(PixelfedComposeActivity.this, imageUri, filename, uploadReceiver); + prepareUpload(BasePixelfedComposeActivity.this, imageUri, filename, uploadReceiver); } } @@ -1133,18 +1121,18 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu return true; case R.id.action_schedule: if (toot_content.getText().toString().trim().length() == 0) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); return true; } - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PixelfedComposeActivity.this, style); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BasePixelfedComposeActivity.this, style); LayoutInflater inflater = this.getLayoutInflater(); - View dialogView = inflater.inflate(R.layout.datetime_picker, new LinearLayout(PixelfedComposeActivity.this), false); + View dialogView = inflater.inflate(R.layout.datetime_picker, new LinearLayout(BasePixelfedComposeActivity.this), false); dialogBuilder.setView(dialogView); final AlertDialog alertDialog = dialogBuilder.create(); final DatePicker datePicker = dialogView.findViewById(R.id.date_picker); final TimePicker timePicker = dialogView.findViewById(R.id.time_picker); - if (android.text.format.DateFormat.is24HourFormat(PixelfedComposeActivity.this)) + if (android.text.format.DateFormat.is24HourFormat(BasePixelfedComposeActivity.this)) timePicker.setIs24HourView(true); Button date_time_cancel = dialogView.findViewById(R.id.date_time_cancel); final ImageButton date_time_previous = dialogView.findViewById(R.id.date_time_previous); @@ -1184,9 +1172,9 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu final long[] time = {calendar.getTimeInMillis()}; if ((time[0] - new Date().getTime()) < 60000) { - Toasty.warning(PixelfedComposeActivity.this, getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show(); + Toasty.warning(BasePixelfedComposeActivity.this, getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show(); } else { - AlertDialog.Builder builderSingle = new AlertDialog.Builder(PixelfedComposeActivity.this, style); + AlertDialog.Builder builderSingle = new AlertDialog.Builder(BasePixelfedComposeActivity.this, style); builderSingle.setTitle(getString(R.string.choose_schedule)); builderSingle.setNegativeButton(R.string.device_schedule, (dialog, which) -> { deviceSchedule(time[0]); @@ -1213,7 +1201,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu private void sendToot(String timestamp) { toot_it.setEnabled(false); if (toot_content.getText().toString().trim().length() == 0 && attachments.size() == 0) { - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); toot_it.setEnabled(true); return; } @@ -1225,20 +1213,20 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu toot.setSensitive(isSensitive); toot.setVisibility(visibility); toot.setMedia_attachments(attachments); - toot.setContent(PixelfedComposeActivity.this, tootContent); + toot.setContent(BasePixelfedComposeActivity.this, tootContent); if (timestamp == null) if (scheduledstatus == null) - new PostStatusAsyncTask(PixelfedComposeActivity.this, social, account, toot, PixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostStatusAsyncTask(BasePixelfedComposeActivity.this, social, account, toot, BasePixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else { toot.setScheduled_at(Helper.dateToString(scheduledstatus.getScheduled_date())); scheduledstatus.setStatus(toot); isScheduled = true; - new PostActionAsyncTask(PixelfedComposeActivity.this, API.StatusAction.DELETESCHEDULED, scheduledstatus, PixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - new PostStatusAsyncTask(PixelfedComposeActivity.this, social, account, toot, PixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostActionAsyncTask(BasePixelfedComposeActivity.this, API.StatusAction.DELETESCHEDULED, scheduledstatus, BasePixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostStatusAsyncTask(BasePixelfedComposeActivity.this, social, account, toot, BasePixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { toot.setScheduled_at(timestamp); - new PostStatusAsyncTask(PixelfedComposeActivity.this, social, account, toot, PixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostStatusAsyncTask(BasePixelfedComposeActivity.this, social, account, toot, BasePixelfedComposeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } @@ -1255,7 +1243,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu storeToot(false, false); isScheduled = true; //Schedules the toot - ScheduledTootsSyncJob.schedule(PixelfedComposeActivity.this, currentToId, time); + ScheduledTootsSyncJob.schedule(BasePixelfedComposeActivity.this, currentToId, time); resetForNextToot(); } @@ -1277,7 +1265,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu isSensitive = false; toot_sensitive.setVisibility(View.GONE); currentToId = -1; - Toasty.info(PixelfedComposeActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + Toasty.info(BasePixelfedComposeActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); } @Override @@ -1315,7 +1303,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu String filename = FileNameCleaner.cleanFileName(url); upload_media.setEnabled(false); toot_it.setEnabled(false); - upload(PixelfedComposeActivity.this, pixelfed_story.isChecked(), uri, filename, uploadReceiver); + upload(BasePixelfedComposeActivity.this, pixelfed_story.isChecked(), uri, filename, uploadReceiver); } } @@ -1342,10 +1330,10 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu private void tootVisibilityDialog() { - AlertDialog.Builder dialog = new AlertDialog.Builder(PixelfedComposeActivity.this, style); + AlertDialog.Builder dialog = new AlertDialog.Builder(BasePixelfedComposeActivity.this, style); dialog.setTitle(R.string.toot_visibility_tilte); final String[] stringArray = getResources().getStringArray(R.array.toot_visibility); - final ArrayAdapter arrayAdapter = new ArrayAdapter<>(PixelfedComposeActivity.this, android.R.layout.simple_list_item_1, stringArray); + final ArrayAdapter arrayAdapter = new ArrayAdapter<>(BasePixelfedComposeActivity.this, android.R.layout.simple_list_item_1, stringArray); dialog.setNegativeButton(R.string.cancel, (dialog12, position) -> dialog12.dismiss()); dialog.setAdapter(arrayAdapter, (dialog1, position) -> { switch (position) { @@ -1401,7 +1389,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu } else if (initialContent.trim().equals(toot_content.getText().toString().trim())) { finish(); } else { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PixelfedComposeActivity.this, style); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BasePixelfedComposeActivity.this, style); dialogBuilder.setMessage(R.string.save_draft); dialogBuilder.setPositiveButton(R.string.save, (dialog, id) -> { if (accountReply == null) { @@ -1453,10 +1441,10 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (apiResponse.getError() == null || apiResponse.getError().getStatusCode() != -33) { if (restored != -1) { SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - new StatusStoredDAO(PixelfedComposeActivity.this, db).remove(restored); + new StatusStoredDAO(BasePixelfedComposeActivity.this, db).remove(restored); } else if (currentToId != -1) { SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - new StatusStoredDAO(PixelfedComposeActivity.this, db).remove(currentToId); + new StatusStoredDAO(BasePixelfedComposeActivity.this, db).remove(currentToId); } } //Clear the toot @@ -1479,17 +1467,17 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (scheduledstatus == null && !isScheduled) { boolean display_confirm = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CONFIRM, true); if (display_confirm) { - Toasty.success(PixelfedComposeActivity.this, getString(R.string.toot_sent), Toast.LENGTH_LONG).show(); + Toasty.success(BasePixelfedComposeActivity.this, getString(R.string.toot_sent), Toast.LENGTH_LONG).show(); } } else - Toasty.success(PixelfedComposeActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + Toasty.success(BasePixelfedComposeActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); } else { if (apiResponse.getError().getStatusCode() == -33) - Toasty.info(PixelfedComposeActivity.this, getString(R.string.toast_toot_saved_error), Toast.LENGTH_LONG).show(); + Toasty.info(BasePixelfedComposeActivity.this, getString(R.string.toast_toot_saved_error), Toast.LENGTH_LONG).show(); } toot_it.setEnabled(true); //It's a reply, so the user will be redirect to its answer - Intent intent = new Intent(PixelfedComposeActivity.this, MainActivity.class); + Intent intent = new Intent(BasePixelfedComposeActivity.this, MainActivity.class); intent.putExtra(Helper.INTENT_ACTION, Helper.HOME_TIMELINE_INTENT); startActivity(intent); finish(); @@ -1507,7 +1495,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu final List accounts = apiResponse.getAccounts(); if (accounts != null && accounts.size() > 0) { int currentCursorPosition = toot_content.getSelectionStart(); - AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(PixelfedComposeActivity.this, accounts); + AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(BasePixelfedComposeActivity.this, accounts); toot_content.setThreshold(1); toot_content.setAdapter(accountsListAdapter); final String oldContent = toot_content.getText().toString(); @@ -1540,7 +1528,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu toot_content.setText(newContent); toot_space_left.setText(String.valueOf(countLength(social, toot_content))); toot_content.setSelection(newPosition); - AccountsSearchAdapter accountsListAdapter1 = new AccountsSearchAdapter(PixelfedComposeActivity.this, new ArrayList<>()); + AccountsSearchAdapter accountsListAdapter1 = new AccountsSearchAdapter(BasePixelfedComposeActivity.this, new ArrayList<>()); toot_content.setThreshold(1); toot_content.setAdapter(accountsListAdapter1); }); @@ -1572,7 +1560,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (emojis != null && emojis.size() > 0) { int currentCursorPosition = toot_content.getSelectionStart(); - EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(PixelfedComposeActivity.this, emojis); + EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(BasePixelfedComposeActivity.this, emojis); toot_content.setThreshold(1); toot_content.setAdapter(emojisSearchAdapter); final String oldContent = toot_content.getText().toString(); @@ -1604,7 +1592,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu toot_content.setText(newContent); toot_space_left.setText(String.valueOf(countLength(social, toot_content))); toot_content.setSelection(newPosition); - EmojisSearchAdapter emojisSearchAdapter1 = new EmojisSearchAdapter(PixelfedComposeActivity.this, new ArrayList<>()); + EmojisSearchAdapter emojisSearchAdapter1 = new EmojisSearchAdapter(BasePixelfedComposeActivity.this, new ArrayList<>()); toot_content.setThreshold(1); toot_content.setAdapter(emojisSearchAdapter1); @@ -1627,7 +1615,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu final List tags = results.getHashtags(); if (tags != null && tags.size() > 0) { int currentCursorPosition = toot_content.getSelectionStart(); - TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(PixelfedComposeActivity.this, tags); + TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(BasePixelfedComposeActivity.this, tags); toot_content.setThreshold(1); toot_content.setAdapter(tagsSearchAdapter); final String oldContent = toot_content.getText().toString(); @@ -1664,7 +1652,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu toot_content.setText(newContent); toot_space_left.setText(String.valueOf(countLength(social, toot_content))); toot_content.setSelection(newPosition); - TagsSearchAdapter tagsSearchAdapter1 = new TagsSearchAdapter(PixelfedComposeActivity.this, new ArrayList<>()); + TagsSearchAdapter tagsSearchAdapter1 = new TagsSearchAdapter(BasePixelfedComposeActivity.this, new ArrayList<>()); toot_content.setThreshold(1); toot_content.setAdapter(tagsSearchAdapter1); @@ -1674,13 +1662,13 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu private void restoreToot(long id) { SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - StoredStatus draft = new StatusStoredDAO(PixelfedComposeActivity.this, db).getStatus(id); + StoredStatus draft = new StatusStoredDAO(BasePixelfedComposeActivity.this, db).getStatus(id); if (draft == null) return; Status status = draft.getStatus(); //Retrieves attachments if (removed) { - new StatusStoredDAO(PixelfedComposeActivity.this, db).remove(draft.getId()); + new StatusStoredDAO(BasePixelfedComposeActivity.this, db).remove(draft.getId()); } restored = id; attachments = status.getMedia_attachments(); @@ -1700,7 +1688,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu content = Html.fromHtml(content).toString(); } if (attachments != null && attachments.size() > 0) { - sliderAdapter = new SliderAdapter(new WeakReference<>(PixelfedComposeActivity.this), true, attachments); + sliderAdapter = new SliderAdapter(new WeakReference<>(BasePixelfedComposeActivity.this), true, attachments); imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM); imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION); imageSlider.setSliderAdapter(sliderAdapter); @@ -1768,7 +1756,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu if (position > attachments.size()) { position = attachments.size(); } - sliderAdapter = new SliderAdapter(new WeakReference<>(PixelfedComposeActivity.this), true, attachments); + sliderAdapter = new SliderAdapter(new WeakReference<>(BasePixelfedComposeActivity.this), true, attachments); imageSlider.setIndicatorAnimation(IndicatorAnimations.WORM); imageSlider.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION); imageSlider.setSliderAdapter(sliderAdapter); @@ -1795,7 +1783,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu String url = attachment.getPreview_url(); if (url == null || url.trim().equals("")) url = attachment.getUrl(); - final ImageView imageView = new ImageView(PixelfedComposeActivity.this); + final ImageView imageView = new ImageView(BasePixelfedComposeActivity.this); Random rand = new Random(); int n = rand.nextInt(10000000); imageView.setId(n); @@ -1803,7 +1791,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu LinearLayout.LayoutParams imParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); imParams.setMargins(20, 5, 20, 5); - imParams.height = (int) Helper.convertDpToPixel(100, PixelfedComposeActivity.this); + imParams.height = (int) Helper.convertDpToPixel(100, BasePixelfedComposeActivity.this); imageView.setAdjustViewBounds(true); imageView.setScaleType(ImageView.ScaleType.FIT_XY); @@ -1886,27 +1874,27 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu toot.setSensitive(isSensitive); toot.setMedia_attachments(attachments); toot.setVisibility(visibility); - toot.setContent(PixelfedComposeActivity.this, currentContent); + toot.setContent(BasePixelfedComposeActivity.this, currentContent); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); try { if (currentToId == -1) { - currentToId = new StatusStoredDAO(PixelfedComposeActivity.this, db).insertStatus(toot, null); + currentToId = new StatusStoredDAO(BasePixelfedComposeActivity.this, db).insertStatus(toot, null); } else { - StoredStatus storedStatus = new StatusStoredDAO(PixelfedComposeActivity.this, db).getStatus(currentToId); + StoredStatus storedStatus = new StatusStoredDAO(BasePixelfedComposeActivity.this, db).getStatus(currentToId); if (storedStatus != null) { - new StatusStoredDAO(PixelfedComposeActivity.this, db).updateStatus(currentToId, toot); + new StatusStoredDAO(BasePixelfedComposeActivity.this, db).updateStatus(currentToId, toot); } else { //Might have been deleted, so it needs insertion - new StatusStoredDAO(PixelfedComposeActivity.this, db).insertStatus(toot, null); + new StatusStoredDAO(BasePixelfedComposeActivity.this, db).insertStatus(toot, null); } } if (message) - Toasty.success(PixelfedComposeActivity.this, getString(R.string.toast_toot_saved), Toast.LENGTH_LONG).show(); + Toasty.success(BasePixelfedComposeActivity.this, getString(R.string.toast_toot_saved), Toast.LENGTH_LONG).show(); } catch (Exception e) { if (message) - Toasty.error(PixelfedComposeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + Toasty.error(BasePixelfedComposeActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); } } @@ -1981,4 +1969,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu } } + protected abstract void launchPhotoEditor(Uri uri); + protected abstract void displayEmojiPopup(); + } diff --git a/app/src/main/java/app/fedilab/android/activities/BaseTootActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseTootActivity.java index 6b702a6e8..4e6c05db9 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseTootActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseTootActivity.java @@ -22,7 +22,6 @@ import android.content.BroadcastReceiver; import android.content.ClipData; import android.content.ContentResolver; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; @@ -85,7 +84,6 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; -import androidx.fragment.app.DialogFragment; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; @@ -97,11 +95,6 @@ import com.bumptech.glide.request.transition.Transition; import com.github.irshulx.Editor; import com.github.irshulx.EditorListener; import com.github.irshulx.models.EditorTextStyle; -import com.github.stom79.localepicker.CountryPicker; -import com.github.stom79.mytransl.MyTransL; -import com.github.stom79.mytransl.client.HttpsConnectionException; -import com.github.stom79.mytransl.translate.Translate; -import com.vanniktech.emoji.EmojiPopup; import net.gotev.uploadservice.MultipartUploadRequest; import net.gotev.uploadservice.ServerResponse; @@ -136,7 +129,6 @@ import java.util.Map; import java.util.Objects; import java.util.Random; import java.util.UUID; -import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -215,7 +207,7 @@ import static app.fedilab.android.helper.Helper.isValidContextForGlide; * Toot activity class */ -public class TootActivity extends BaseActivity implements UploadStatusDelegate, OnPostActionInterface, OnRetrieveSearcAccountshInterface, OnPostStatusActionInterface, OnRetrieveSearchInterface, OnRetrieveAccountsReplyInterface, OnRetrieveEmojiInterface, OnDownloadInterface, OnRetrieveAttachmentInterface, OnRetrieveRelationshipInterface { +public abstract class BaseTootActivity extends BaseActivity implements UploadStatusDelegate, OnPostActionInterface, OnRetrieveSearcAccountshInterface, OnPostStatusActionInterface, OnRetrieveSearchInterface, OnRetrieveAccountsReplyInterface, OnRetrieveEmojiInterface, OnDownloadInterface, OnRetrieveAttachmentInterface, OnRetrieveRelationshipInterface { public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 754; @@ -240,8 +232,8 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, private boolean isSensitive = false; private ImageButton toot_visibility; private Button toot_it; - private MastalabAutoCompleteTextView toot_content; - private EditText toot_cw_content; + protected MastalabAutoCompleteTextView toot_content; + protected EditText toot_cw_content; private Status tootReply = null; private String tootMention = null; private String urlMention = null; @@ -252,13 +244,12 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, private ImageView pp_actionBar; private ProgressBar pp_progress; private Toast mToast; - private LinearLayout drawer_layout; + protected LinearLayout drawer_layout; private HorizontalScrollView picture_scrollview; private TextView toot_space_left; private String initialContent; private Account accountReply; - private View popup_trans; - private AlertDialog dialogTrans; + protected ImageButton toot_emoji; private AlertDialog alertDialogEmoji; private String mentionAccount; private Status idRedirect; @@ -268,7 +259,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, private int stepSpliToot; private boolean removed; private boolean restoredScheduled; - private int style; + protected int style; private StoredStatus scheduledstatus; private boolean isScheduled; private List checkedValues; @@ -292,10 +283,11 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, public void onReceive(Context context, Intent intent) { String imgpath = intent.getStringExtra("imgpath"); if (imgpath != null) { - prepareUpload(TootActivity.this, Uri.fromFile(new File(imgpath)), null, uploadReceiver); + prepareUpload(BaseTootActivity.this, Uri.fromFile(new File(imgpath)), null, uploadReceiver); } } }; + protected int theme; private BroadcastReceiver add_new_media = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -329,7 +321,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, final int[] currentCursorPosition = {toot_content.getSelectionStart()}; final String[] newContent = {null}; final int[] searchLength = {searchDeep}; - TextWatcher textw = null; + TextWatcher textw; textw = new TextWatcher() { @Override @@ -698,7 +690,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, super.onCreate(savedInstanceState); SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(TootActivity.this)); + instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(BaseTootActivity.this)); final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); switch (theme) { case Helper.THEME_LIGHT: @@ -727,8 +719,8 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (actionBar != null) { LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); assert inflater != null; - View view = inflater.inflate(R.layout.toot_action_bar, new LinearLayout(TootActivity.this), false); - view.setBackground(new ColorDrawable(ContextCompat.getColor(TootActivity.this, R.color.cyanea_primary))); + View view = inflater.inflate(R.layout.toot_action_bar, new LinearLayout(BaseTootActivity.this), false); + view.setBackground(new ColorDrawable(ContextCompat.getColor(BaseTootActivity.this, R.color.cyanea_primary))); actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ImageView close_toot = actionBar.getCustomView().findViewById(R.id.close_toot); @@ -746,7 +738,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } else if (displayWYSIWYG() && initialContent.trim().equals(wysiwyg.getContentAsHTML().trim())) { finish(); } else { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseTootActivity.this, style); dialogBuilder.setMessage(R.string.save_draft); dialogBuilder.setPositiveButton(R.string.save, (dialog, id) -> { if (accountReply == null) { @@ -798,7 +790,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, picture_scrollview = findViewById(R.id.picture_scrollview); toot_sensitive = findViewById(R.id.toot_sensitive); drawer_layout = findViewById(R.id.drawer_layout); - ImageButton toot_emoji = findViewById(R.id.toot_emoji); + toot_emoji = findViewById(R.id.toot_emoji); warning_message = findViewById(R.id.warning_message); poll_action = findViewById(R.id.poll_action); @@ -809,45 +801,37 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (inputContentInfo != null) { Uri uri = inputContentInfo.getContentUri(); - String filename = Helper.getFileName(TootActivity.this, uri); + String filename = Helper.getFileName(BaseTootActivity.this, uri); ContentResolver cr = getContentResolver(); String mime = cr.getType(uri); if (mime != null && (mime.toLowerCase().contains("video") || mime.toLowerCase().contains("gif"))) { - prepareUpload(TootActivity.this, uri, filename, uploadReceiver); + prepareUpload(BaseTootActivity.this, uri, filename, uploadReceiver); } else if (mime != null && mime.toLowerCase().contains("image")) { if (photo_editor) { - Intent intent = new Intent(TootActivity.this, PhotoEditorActivity.class); - Bundle b = new Bundle(); - intent.putExtra("imageUri", uri.toString()); - intent.putExtras(b); - startActivity(intent); + launchPhotoEditor(uri); } else { - prepareUpload(TootActivity.this, uri, filename, uploadReceiver); + prepareUpload(BaseTootActivity.this, uri, filename, uploadReceiver); } } else if (mime != null && mime.toLowerCase().contains("audio")) { - prepareUpload(TootActivity.this, uri, filename, uploadReceiver); + prepareUpload(BaseTootActivity.this, uri, filename, uploadReceiver); } else { - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); } } }); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(TootActivity.this); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(BaseTootActivity.this); int iconColor = prefs.getInt("theme_icons_color", -1); if (iconColor != -1) { - Helper.changeDrawableColor(TootActivity.this, toot_emoji, iconColor); - Helper.changeDrawableColor(TootActivity.this, toot_visibility, iconColor); - Helper.changeDrawableColor(TootActivity.this, poll_action, iconColor); - Helper.changeDrawableColor(TootActivity.this, toot_picture, iconColor); + Helper.changeDrawableColor(BaseTootActivity.this, toot_emoji, iconColor); + Helper.changeDrawableColor(BaseTootActivity.this, toot_visibility, iconColor); + Helper.changeDrawableColor(BaseTootActivity.this, poll_action, iconColor); + Helper.changeDrawableColor(BaseTootActivity.this, toot_picture, iconColor); } isScheduled = false; if (sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, false)) { - final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content); - - toot_emoji.setOnClickListener(v -> { - emojiPopup.toggle(); // Toggles visibility of the Popup. - }); + displayEmojiPopup(); } else { toot_emoji.setVisibility(View.GONE); } @@ -907,7 +891,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, pp_progress.setVisibility(View.VISIBLE); pp_actionBar.setVisibility(View.GONE); } - new RetrieveSearchAccountsAsyncTask(TootActivity.this, search, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveSearchAccountsAsyncTask(BaseTootActivity.this, search, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { mt = tPattern.matcher(searchIn); if (mt.matches()) { @@ -916,7 +900,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, pp_progress.setVisibility(View.VISIBLE); pp_actionBar.setVisibility(View.GONE); } - new RetrieveSearchAsyncTask(TootActivity.this, search, true, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveSearchAsyncTask(BaseTootActivity.this, search, true, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { mt = ePattern.matcher(searchIn); if (mt.matches()) { @@ -925,7 +909,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, pp_progress.setVisibility(View.VISIBLE); pp_actionBar.setVisibility(View.GONE); } - new RetrieveEmojiAsyncTask(TootActivity.this, shortcode, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveEmojiAsyncTask(BaseTootActivity.this, shortcode, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } } @@ -949,15 +933,15 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, drawer_layout.getViewTreeObserver().addOnGlobalLayoutListener(() -> { int heightDiff = drawer_layout.getRootView().getHeight() - drawer_layout.getHeight(); - if (heightDiff > Helper.convertDpToPixel(200, TootActivity.this)) { + if (heightDiff > Helper.convertDpToPixel(200, BaseTootActivity.this)) { ViewGroup.LayoutParams params = toot_picture_container.getLayoutParams(); - params.height = (int) Helper.convertDpToPixel(50, TootActivity.this); - params.width = (int) Helper.convertDpToPixel(50, TootActivity.this); + params.height = (int) Helper.convertDpToPixel(50, BaseTootActivity.this); + params.width = (int) Helper.convertDpToPixel(50, BaseTootActivity.this); toot_picture_container.setLayoutParams(params); } else { ViewGroup.LayoutParams params = toot_picture_container.getLayoutParams(); - params.height = (int) Helper.convertDpToPixel(100, TootActivity.this); - params.width = (int) Helper.convertDpToPixel(100, TootActivity.this); + params.height = (int) Helper.convertDpToPixel(100, BaseTootActivity.this); + params.width = (int) Helper.convertDpToPixel(100, BaseTootActivity.this); toot_picture_container.setLayoutParams(params); } }); @@ -974,7 +958,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (accountReplyToken != null) { String[] val = accountReplyToken.split("\\|"); if (val.length == 2) { - accountReply = new AccountDAO(TootActivity.this, db).getUniqAccount(val[0], val[1]); + accountReply = new AccountDAO(BaseTootActivity.this, db).getUniqAccount(val[0], val[1]); } } tootMention = b.getString("tootMention", null); @@ -1011,7 +995,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, warning_message.setVisibility(View.VISIBLE); } assert tootReply.getAccount() != null; - new RetrieveRelationshipAsyncTask(TootActivity.this, tootReply.getAccount().getId(), TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveRelationshipAsyncTask(BaseTootActivity.this, tootReply.getAccount().getId(), BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } if (scheduledstatus != null) toot_it.setText(R.string.modify); @@ -1028,7 +1012,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, instanceReply = accountReply.getInstance(); } if (accountReply == null) - account = new AccountDAO(TootActivity.this, db).getUniqAccount(userIdReply, instanceReply); + account = new AccountDAO(BaseTootActivity.this, db).getUniqAccount(userIdReply, instanceReply); else account = accountReply; @@ -1095,7 +1079,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, initialContent = displayWYSIWYG() ? wysiwyg.getContentAsHTML() : toot_content.getText().toString(); - Helper.loadGiF(TootActivity.this, account, pp_actionBar); + Helper.loadGiF(BaseTootActivity.this, account, pp_actionBar); if (sharedContent != null) { //Shared content @@ -1121,7 +1105,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot_space_left.setText(String.valueOf(countLength(social, toot_content, toot_cw_content))); } if (image != null) { - new HttpsConnection(TootActivity.this, instance).download(image, TootActivity.this); + new HttpsConnection(BaseTootActivity.this, instance).download(image, BaseTootActivity.this); } int selectionBefore = toot_content.getSelectionStart(); toot_content.setText(String.format("\n%s", sharedContent)); @@ -1185,7 +1169,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA && !displayWYSIWYG()) toot_it.setOnLongClickListener(v -> { - PopupMenu popup = new PopupMenu(TootActivity.this, toot_it); + PopupMenu popup = new PopupMenu(BaseTootActivity.this, toot_it); popup.getMenuInflater() .inflate(R.menu.main_content_type, popup.getMenu()); popup.setOnMenuItemClickListener(item -> { @@ -1213,9 +1197,9 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot_picture.setOnClickListener(v -> { - if (ContextCompat.checkSelfPermission(TootActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != + if (ContextCompat.checkSelfPermission(BaseTootActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(TootActivity.this, + ActivityCompat.requestPermissions(BaseTootActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); return; @@ -1256,7 +1240,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } }); - TextWatcher textWatcher = initializeTextWatcher(TootActivity.this, social, null, toot_content, toot_cw_content, toot_space_left, pp_actionBar, pp_progress, TootActivity.this, TootActivity.this, TootActivity.this); + TextWatcher textWatcher = initializeTextWatcher(BaseTootActivity.this, social, null, toot_content, toot_cw_content, toot_space_left, pp_actionBar, pp_progress, BaseTootActivity.this, BaseTootActivity.this, BaseTootActivity.this); if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) toot_content.addTextChangedListener(textWatcher); @@ -1289,7 +1273,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, Attachment attachment; //response = new JSONObject(serverResponse.getBodyAsString()); if (response == null) { - Toasty.error(TootActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); return; } if (social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { @@ -1321,7 +1305,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, url = attachment.getUrl(); - final ImageView imageView = new ImageView(TootActivity.this); + final ImageView imageView = new ImageView(BaseTootActivity.this); Random rand = new Random(); int n = rand.nextInt(10000000); imageView.setId(n); @@ -1393,7 +1377,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, LinearLayout.LayoutParams imParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); imParams.setMargins(20, 5, 20, 5); - imParams.height = (int) Helper.convertDpToPixel(100, TootActivity.this); + imParams.height = (int) Helper.convertDpToPixel(100, BaseTootActivity.this); imageView.setAdjustViewBounds(true); imageView.setScaleType(ImageView.ScaleType.FIT_XY); final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); @@ -1455,7 +1439,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (mToast != null) { mToast.cancel(); } - mToast = Toasty.error(TootActivity.this, message, Toast.LENGTH_SHORT); + mToast = Toasty.error(BaseTootActivity.this, message, Toast.LENGTH_SHORT); mToast.show(); } @@ -1470,16 +1454,16 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } picture_scrollview.setVisibility(View.VISIBLE); try { - prepareUpload(TootActivity.this, fileUri, null, uploadReceiver); + prepareUpload(BaseTootActivity.this, fileUri, null, uploadReceiver); count++; } catch (Exception e) { e.printStackTrace(); - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); toot_picture.setEnabled(true); toot_it.setEnabled(true); } } else { - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); } } } @@ -1493,7 +1477,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, try { photoFile = createImageFile(); } catch (IOException ignored) { - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); } // Continue only if the File was successfully created if (photoFile != null) { @@ -1534,13 +1518,13 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, boolean photo_editor = sharedpreferences.getBoolean(Helper.SET_PHOTO_EDITOR, true); if (requestCode == PICK_IMAGE && resultCode == RESULT_OK) { if (data == null) { - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); return; } ClipData clipData = data.getClipData(); if (data.getData() == null && clipData == null) { - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); return; } @@ -1553,50 +1537,42 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } uploadSharedImage(mArrayUri); } else { - String filename = Helper.getFileName(TootActivity.this, data.getData()); + String filename = Helper.getFileName(BaseTootActivity.this, data.getData()); ContentResolver cr = getContentResolver(); String mime = cr.getType(data.getData()); if (mime != null && (mime.toLowerCase().contains("video") || mime.toLowerCase().contains("gif"))) { - prepareUpload(TootActivity.this, data.getData(), filename, uploadReceiver); + prepareUpload(BaseTootActivity.this, data.getData(), filename, uploadReceiver); } else if (mime != null && mime.toLowerCase().contains("image")) { if (photo_editor) { - Intent intent = new Intent(TootActivity.this, PhotoEditorActivity.class); - Bundle b = new Bundle(); - intent.putExtra("imageUri", data.getData().toString()); - intent.putExtras(b); - startActivity(intent); + launchPhotoEditor(data.getData()); } else { - prepareUpload(TootActivity.this, data.getData(), filename, uploadReceiver); + prepareUpload(BaseTootActivity.this, data.getData(), filename, uploadReceiver); } } else if (mime != null && mime.toLowerCase().contains("audio")) { - prepareUpload(TootActivity.this, data.getData(), filename, uploadReceiver); + prepareUpload(BaseTootActivity.this, data.getData(), filename, uploadReceiver); } else { - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); } } } else if (requestCode == SEND_VOICE_MESSAGE && resultCode == RESULT_OK) { Uri uri = Uri.fromFile(new File(getCacheDir() + "/fedilab_recorded_audio.wav")); - prepareUpload(TootActivity.this, uri, "fedilab_recorded_audio.wav", uploadReceiver); + prepareUpload(BaseTootActivity.this, uri, "fedilab_recorded_audio.wav", uploadReceiver); } else if (requestCode == TAKE_PHOTO && resultCode == RESULT_OK) { if (photo_editor) { - Intent intent = new Intent(TootActivity.this, PhotoEditorActivity.class); - Bundle b = new Bundle(); - intent.putExtra("imageUri", photoFileUri.toString()); - intent.putExtras(b); - startActivity(intent); + launchPhotoEditor(photoFileUri); } else { - prepareUpload(TootActivity.this, photoFileUri, null, uploadReceiver); + prepareUpload(BaseTootActivity.this, photoFileUri, null, uploadReceiver); } } else if (requestCode == wysiwyg.PICK_IMAGE_REQUEST && resultCode == Activity.RESULT_OK && data != null && data.getData() != null) { - String filename = Helper.getFileName(TootActivity.this, data.getData()); - prepareUpload(TootActivity.this, data.getData(), "fedilabins_" + filename, uploadReceiver); + String filename = Helper.getFileName(BaseTootActivity.this, data.getData()); + prepareUpload(BaseTootActivity.this, data.getData(), "fedilabins_" + filename, uploadReceiver); } } private void prepareUpload(Activity activity, android.net.Uri uri, String filename, UploadServiceSingleBroadcastReceiver uploadReceiver) { if (uploadReceiver == null) { - uploadReceiver = new UploadServiceSingleBroadcastReceiver(TootActivity.this); + uploadReceiver = new UploadServiceSingleBroadcastReceiver(BaseTootActivity.this); uploadReceiver.register(this); } new asyncPicture(activity, account, social, uri, filename, uploadReceiver).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -1605,9 +1581,9 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, @Override public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) { if (error != null) { - Toasty.error(TootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); } else { - Toasty.success(TootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + Toasty.success(BaseTootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); resetForNextToot(); } } @@ -1620,7 +1596,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, @Override public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, Exception exception) { - Toasty.error(TootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); if (attachments.size() == 0) toot_picture_container.setVisibility(View.GONE); toot_picture.setEnabled(true); @@ -1661,12 +1637,12 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (extras != null && extras.getString("imageUri") != null) { Uri imageUri = Uri.parse(extras.getString("imageUri")); if (imageUri == null) { - Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show(); return; } - String filename = Helper.getFileName(TootActivity.this, imageUri); + String filename = Helper.getFileName(BaseTootActivity.this, imageUri); - prepareUpload(TootActivity.this, imageUri, filename, uploadReceiver); + prepareUpload(BaseTootActivity.this, imageUri, filename, uploadReceiver); } } @@ -1677,7 +1653,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, final SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); int style; SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); if (theme == Helper.THEME_DARK) { style = R.style.DialogDark; } else if (theme == Helper.THEME_BLACK) { @@ -1691,9 +1667,9 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, finish(); return true; case R.id.action_view_reply: - AlertDialog.Builder alert = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder alert = new AlertDialog.Builder(BaseTootActivity.this, style); alert.setTitle(R.string.toot_reply_content_title); - final TextView input = new TextView(TootActivity.this); + final TextView input = new TextView(BaseTootActivity.this); //Set the padding input.setPadding(30, 30, 30, 30); alert.setView(input); @@ -1706,7 +1682,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, input.setText(Html.fromHtml(content)); alert.setPositiveButton(R.string.close, (dialog, whichButton) -> dialog.dismiss()); alert.setNegativeButton(R.string.accounts, (dialog, whichButton) -> { - new RetrieveAccountsForReplyAsyncTask(TootActivity.this, tootReply.getReblog() != null ? tootReply.getReblog() : tootReply, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveAccountsForReplyAsyncTask(BaseTootActivity.this, tootReply.getReblog() != null ? tootReply.getReblog() : tootReply, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); dialog.dismiss(); }); alert.show(); @@ -1716,151 +1692,13 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, displayPollPopup(); return false; case R.id.action_translate: - final CountryPicker picker = CountryPicker.newInstance(getString(R.string.which_language)); // dialog title - if (theme == Helper.THEME_LIGHT) { - picker.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog); - } else { - picker.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.DialogDark); - } - if (toot_content.getText().length() == 0 && toot_cw_content.getText().length() == 0) - return true; - String dateString = sharedpreferences.getString(Helper.LAST_TRANSLATION_TIME, null); - if (dateString != null) { - Date dateCompare = Helper.stringToDate(TootActivity.this, dateString); - Date date = new Date(); - if (date.before(dateCompare)) { - Toasty.info(TootActivity.this, getString(R.string.please_wait), Toast.LENGTH_SHORT).show(); - return true; - } - } - picker.setListener((name, locale, flagDrawableResID) -> { - picker.dismiss(); - AlertDialog.Builder transAlert = new AlertDialog.Builder(TootActivity.this, style); - transAlert.setTitle(R.string.translate_toot); - - popup_trans = getLayoutInflater().inflate(R.layout.popup_translate, new LinearLayout(TootActivity.this), false); - transAlert.setView(popup_trans); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.LAST_TRANSLATION_TIME, Helper.dateToString(new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(Helper.SECONDES_BETWEEN_TRANSLATE)))); - editor.apply(); - TextView yandex_translate = popup_trans.findViewById(R.id.yandex_translate); - yandex_translate.setOnClickListener(v -> { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://translate.yandex.com/")); - startActivity(browserIntent); - }); - MyTransL myTransL = MyTransL.getInstance(MyTransL.translatorEngine.YANDEX); - myTransL.setYandexAPIKey(Helper.YANDEX_KEY); - myTransL.setObfuscation(true); - myTransL.setTimeout(60); - if (toot_cw_content.getText().toString().length() > 0) - myTransL.translate(toot_cw_content.getText().toString(), locale, new com.github.stom79.mytransl.client.Results() { - @Override - public void onSuccess(Translate translate) { - try { - if (translate.getTranslatedContent() == null) - return; - if (popup_trans != null) { - ProgressBar trans_progress_cw = popup_trans.findViewById(R.id.trans_progress_cw); - ProgressBar trans_progress_toot = popup_trans.findViewById(R.id.trans_progress_toot); - if (trans_progress_cw != null) - trans_progress_cw.setVisibility(View.GONE); - LinearLayout trans_container = popup_trans.findViewById(R.id.trans_container); - if (trans_container != null) { - TextView cw_trans = popup_trans.findViewById(R.id.cw_trans); - if (cw_trans != null) { - cw_trans.setVisibility(View.VISIBLE); - cw_trans.setText(translate.getTranslatedContent()); - } - } else { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - if (trans_progress_cw != null && trans_progress_toot != null && trans_progress_cw.getVisibility() == View.GONE && trans_progress_toot.getVisibility() == View.GONE) - if (dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE) != null) - dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(true); - } - } catch (IllegalArgumentException e) { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - - } - - @Override - public void onFail(HttpsConnectionException e) { - e.printStackTrace(); - } - }); - else { - ProgressBar trans_progress_cw = popup_trans.findViewById(R.id.trans_progress_cw); - trans_progress_cw.setVisibility(View.GONE); - } - if (toot_content.getText().toString().length() > 0) - myTransL.translate(toot_content.getText().toString(), locale, new com.github.stom79.mytransl.client.Results() { - @Override - public void onSuccess(Translate translate) { - try { - if (translate.getTranslatedContent() == null) - return; - if (popup_trans != null) { - ProgressBar trans_progress_cw = popup_trans.findViewById(R.id.trans_progress_cw); - ProgressBar trans_progress_toot = popup_trans.findViewById(R.id.trans_progress_toot); - if (trans_progress_toot != null) - trans_progress_toot.setVisibility(View.GONE); - LinearLayout trans_container = popup_trans.findViewById(R.id.trans_container); - if (trans_container != null) { - TextView toot_trans = popup_trans.findViewById(R.id.toot_trans); - if (toot_trans != null) { - toot_trans.setVisibility(View.VISIBLE); - toot_trans.setText(translate.getTranslatedContent()); - } - } else { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - if (trans_progress_cw != null && trans_progress_toot != null && trans_progress_cw.getVisibility() == View.GONE && trans_progress_toot.getVisibility() == View.GONE) - if (dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE) != null) - dialogTrans.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(true); - } - } catch (IllegalArgumentException e) { - Toasty.error(TootActivity.this, getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); - } - } - - @Override - public void onFail(HttpsConnectionException e) { - e.printStackTrace(); - } - }); - - transAlert.setPositiveButton(R.string.close, (dialog, whichButton) -> dialog.dismiss()); - transAlert.setNegativeButton(R.string.validate, (dialog, whichButton) -> { - TextView toot_trans = popup_trans.findViewById(R.id.toot_trans); - TextView cw_trans = popup_trans.findViewById(R.id.cw_trans); - if (toot_trans != null) { - toot_content.setText(toot_trans.getText().toString()); - toot_content.setSelection(toot_content.getText().length()); - } - if (cw_trans != null) - toot_cw_content.setText(cw_trans.getText().toString()); - dialog.dismiss(); - }); - dialogTrans = transAlert.create(); - transAlert.show(); - - dialogTrans.setOnShowListener(dialog -> { - Button negativeButton = ((AlertDialog) dialog) - .getButton(AlertDialog.BUTTON_NEGATIVE); - if (negativeButton != null) - negativeButton.setEnabled(false); - }); - - }); - picker.show(getSupportFragmentManager(), "COUNTRY_PICKER"); - return true; + return actionTranslateClick(); case R.id.action_emoji: if (emojis != null) { emojis.clear(); emojis = null; } - emojis = new CustomEmojiDAO(TootActivity.this, db).getAllEmojis(account.getInstance()); + emojis = new CustomEmojiDAO(BaseTootActivity.this, db).getAllEmojis(account.getInstance()); final AlertDialog.Builder builder = new AlertDialog.Builder(this, style); int paddingPixel = 15; float density = getResources().getDisplayMetrics().density; @@ -1868,7 +1706,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builder.setTitle(R.string.insert_emoji); if (emojis != null && emojis.size() > 0) { - GridView gridView = new GridView(TootActivity.this); + GridView gridView = new GridView(BaseTootActivity.this); gridView.setAdapter(new CustomEmojiAdapter(emojis)); gridView.setNumColumns(5); gridView.setOnItemClickListener((parent, view, position, id) -> { @@ -1878,7 +1716,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, gridView.setPadding(paddingDp, paddingDp, paddingDp, paddingDp); builder.setView(gridView); } else { - TextView textView = new TextView(TootActivity.this); + TextView textView = new TextView(BaseTootActivity.this); textView.setText(getString(R.string.no_emoji)); textView.setPadding(paddingDp, paddingDp, paddingDp, paddingDp); builder.setView(textView); @@ -1892,17 +1730,17 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, return true; case R.id.action_contacts: - AlertDialog.Builder builderSingle = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder builderSingle = new AlertDialog.Builder(BaseTootActivity.this, style); builderSingle.setTitle(getString(R.string.select_accounts)); LayoutInflater inflater = getLayoutInflater(); - View dialogView = inflater.inflate(R.layout.popup_contact, new LinearLayout(TootActivity.this), false); + View dialogView = inflater.inflate(R.layout.popup_contact, new LinearLayout(BaseTootActivity.this), false); loader = dialogView.findViewById(R.id.loader); EditText search_account = dialogView.findViewById(R.id.search_account); lv_accounts_search = dialogView.findViewById(R.id.lv_accounts_search); loader.setVisibility(View.VISIBLE); - new RetrieveSearchAccountsAsyncTask(TootActivity.this, "a", true, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveSearchAccountsAsyncTask(BaseTootActivity.this, "a", true, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); search_account.addTextChangedListener(new TextWatcher() { @Override @@ -1921,7 +1759,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, @Override public void afterTextChanged(Editable s) { if (s != null && s.length() > 0) { - new RetrieveSearchAccountsAsyncTask(TootActivity.this, s.toString(), true, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveSearchAccountsAsyncTask(BaseTootActivity.this, s.toString(), true, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } }); @@ -1930,7 +1768,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (event.getAction() == MotionEvent.ACTION_UP) { if (search_account.length() > 0 && event.getRawX() >= (search_account.getRight() - search_account.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { search_account.setText(""); - new RetrieveSearchAccountsAsyncTask(TootActivity.this, "a", true, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveSearchAccountsAsyncTask(BaseTootActivity.this, "a", true, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } @@ -1968,18 +1806,18 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, storeToot(true, true); return true; case R.id.action_tags: - Intent intentTags = new Intent(TootActivity.this, TagCacheActivity.class); + Intent intentTags = new Intent(BaseTootActivity.this, TagCacheActivity.class); intentTags.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intentTags); return true; case R.id.action_restore: try { - final List drafts = new StatusStoredDAO(TootActivity.this, db).getAllDrafts(); + final List drafts = new StatusStoredDAO(BaseTootActivity.this, db).getAllDrafts(); if (drafts == null || drafts.size() == 0) { - Toasty.info(TootActivity.this, getString(R.string.no_draft), Toast.LENGTH_LONG).show(); + Toasty.info(BaseTootActivity.this, getString(R.string.no_draft), Toast.LENGTH_LONG).show(); return true; } - builderSingle = new AlertDialog.Builder(TootActivity.this, style); + builderSingle = new AlertDialog.Builder(BaseTootActivity.this, style); builderSingle.setTitle(getString(R.string.choose_toot)); final DraftsListAdapter draftsListAdapter = new DraftsListAdapter(drafts); final int[] ids = new int[drafts.size()]; @@ -1990,11 +1828,11 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builderSingle.setPositiveButton(R.string.delete_all, (dialog, which) -> { - AlertDialog.Builder builder1 = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder builder1 = new AlertDialog.Builder(BaseTootActivity.this, style); builder1.setTitle(R.string.delete_all); builder1.setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(R.string.yes, (dialogConfirm, which1) -> { - new StatusStoredDAO(TootActivity.this, db).removeAllDrafts(); + new StatusStoredDAO(BaseTootActivity.this, db).removeAllDrafts(); dialogConfirm.dismiss(); dialog.dismiss(); }) @@ -2010,24 +1848,24 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, }); builderSingle.show(); } catch (Exception e) { - Toasty.error(TootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); } return true; case R.id.action_schedule: if (toot_content.getText().toString().trim().length() == 0) { - Toasty.error(TootActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); return true; } - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseTootActivity.this, style); inflater = this.getLayoutInflater(); - dialogView = inflater.inflate(R.layout.datetime_picker, new LinearLayout(TootActivity.this), false); + dialogView = inflater.inflate(R.layout.datetime_picker, new LinearLayout(BaseTootActivity.this), false); dialogBuilder.setView(dialogView); final AlertDialog alertDialog = dialogBuilder.create(); final DatePicker datePicker = dialogView.findViewById(R.id.date_picker); final TimePicker timePicker = dialogView.findViewById(R.id.time_picker); - if (android.text.format.DateFormat.is24HourFormat(TootActivity.this)) + if (android.text.format.DateFormat.is24HourFormat(BaseTootActivity.this)) timePicker.setIs24HourView(true); Button date_time_cancel = dialogView.findViewById(R.id.date_time_cancel); final ImageButton date_time_previous = dialogView.findViewById(R.id.date_time_previous); @@ -2067,9 +1905,9 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, final long[] time = {calendar.getTimeInMillis()}; if ((time[0] - new Date().getTime()) < 60000) { - Toasty.warning(TootActivity.this, getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show(); + Toasty.warning(BaseTootActivity.this, getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show(); } else { - AlertDialog.Builder builderSingle1 = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder builderSingle1 = new AlertDialog.Builder(BaseTootActivity.this, style); builderSingle1.setTitle(getString(R.string.choose_schedule)); builderSingle1.setNegativeButton(R.string.device_schedule, (dialog, which) -> { deviceSchedule(time[0]); @@ -2094,12 +1932,12 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, private void sendToot(String timestamp, String content_type) { toot_it.setEnabled(false); if (!displayWYSIWYG() && toot_content.getText().toString().trim().length() == 0 && attachments.size() == 0) { - Toasty.error(TootActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); toot_it.setEnabled(true); return; } if (displayWYSIWYG() && wysiwyg.getContent().toString().trim().length() == 0 && attachments.size() == 0) { - Toasty.error(TootActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toot_error_no_content), Toast.LENGTH_LONG).show(); toot_it.setEnabled(true); return; } @@ -2129,10 +1967,10 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, stepSpliToot = 1; - AlertDialog.Builder builderInner = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder builderInner = new AlertDialog.Builder(BaseTootActivity.this, style); builderInner.setTitle(R.string.message_preview); - View preview = getLayoutInflater().inflate(R.layout.popup_message_preview, new LinearLayout(TootActivity.this), false); + View preview = getLayoutInflater().inflate(R.layout.popup_message_preview, new LinearLayout(BaseTootActivity.this), false); builderInner.setView(preview); //Text for report @@ -2193,7 +2031,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot.setVisibility(visibility); if (tootReply != null) toot.setIn_reply_to_id(tootReply.getId()); - toot.setContent(TootActivity.this, tootContent); + toot.setContent(BaseTootActivity.this, tootContent); if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) { if (poll != null) { toot.setPoll(poll); @@ -2208,17 +2046,17 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } if (timestamp == null) if (scheduledstatus == null) - new PostStatusAsyncTask(TootActivity.this, social, account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostStatusAsyncTask(BaseTootActivity.this, social, account, toot, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else { toot.setScheduled_at(Helper.dateToString(scheduledstatus.getScheduled_date())); scheduledstatus.setStatus(toot); isScheduled = true; - new PostActionAsyncTask(TootActivity.this, API.StatusAction.DELETESCHEDULED, scheduledstatus, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - new PostStatusAsyncTask(TootActivity.this, social, account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostActionAsyncTask(BaseTootActivity.this, API.StatusAction.DELETESCHEDULED, scheduledstatus, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostStatusAsyncTask(BaseTootActivity.this, social, account, toot, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { toot.setScheduled_at(timestamp); - new PostStatusAsyncTask(TootActivity.this, social, account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new PostStatusAsyncTask(BaseTootActivity.this, social, account, toot, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } @@ -2233,7 +2071,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, storeToot(false, false); isScheduled = true; //Schedules the toot - ScheduledTootsSyncJob.schedule(TootActivity.this, currentToId, time); + ScheduledTootsSyncJob.schedule(BaseTootActivity.this, currentToId, time); resetForNextToot(); } @@ -2255,7 +2093,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, isSensitive = false; toot_sensitive.setVisibility(View.GONE); currentToId = -1; - Toasty.info(TootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + Toasty.info(BaseTootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); } @Override @@ -2282,7 +2120,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); MenuItem itemEmoji = menu.findItem(R.id.action_emoji); SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - final List emojis = new CustomEmojiDAO(TootActivity.this, db).getAllEmojis(); + final List emojis = new CustomEmojiDAO(BaseTootActivity.this, db).getAllEmojis(); //Displays button only if custom emojis if (emojis != null && emojis.size() > 0) { itemEmoji.setVisible(true); @@ -2329,7 +2167,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot_picture_container.setVisibility(View.VISIBLE); toot_picture.setEnabled(false); toot_it.setEnabled(false); - upload(TootActivity.this, account, social, uri, filename, uploadReceiver); + upload(BaseTootActivity.this, account, social, uri, filename, uploadReceiver); } } @@ -2354,17 +2192,17 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } private void showAddDescription(final Attachment attachment) { - AlertDialog.Builder builderInner = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder builderInner = new AlertDialog.Builder(BaseTootActivity.this, style); builderInner.setTitle(R.string.upload_form_description); - View popup_media_description = getLayoutInflater().inflate(R.layout.popup_media_description, new LinearLayout(TootActivity.this), false); + View popup_media_description = getLayoutInflater().inflate(R.layout.popup_media_description, new LinearLayout(BaseTootActivity.this), false); builderInner.setView(popup_media_description); //Text for report final EditText input = popup_media_description.findViewById(R.id.media_description); input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)}); final ImageView media_picture = popup_media_description.findViewById(R.id.media_picture); - Glide.with(TootActivity.this) + Glide.with(BaseTootActivity.this) .asBitmap() .load(attachment.getUrl()) .into(new CustomTarget() { @@ -2388,7 +2226,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, input.setSelection(input.getText().length()); } builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { - new UpdateDescriptionAttachmentAsyncTask(TootActivity.this, attachment.getId(), input.getText().toString(), account, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new UpdateDescriptionAttachmentAsyncTask(BaseTootActivity.this, attachment.getId(), input.getText().toString(), account, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); attachment.setDescription(input.getText().toString()); addBorder(); dialog.dismiss(); @@ -2406,7 +2244,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, */ private void showRemove(final int viewId) { - AlertDialog.Builder dialog = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder dialog = new AlertDialog.Builder(BaseTootActivity.this, style); dialog.setMessage(R.string.toot_delete_media); dialog.setNegativeButton(R.string.cancel, (dialog1, which) -> dialog1.dismiss()); @@ -2445,10 +2283,10 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, private void tootVisibilityDialog() { - AlertDialog.Builder dialog = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder dialog = new AlertDialog.Builder(BaseTootActivity.this, style); dialog.setTitle(R.string.toot_visibility_tilte); final String[] stringArray = getResources().getStringArray(R.array.toot_visibility); - final ArrayAdapter arrayAdapter = new ArrayAdapter<>(TootActivity.this, android.R.layout.simple_list_item_1, stringArray); + final ArrayAdapter arrayAdapter = new ArrayAdapter<>(BaseTootActivity.this, android.R.layout.simple_list_item_1, stringArray); dialog.setNegativeButton(R.string.cancel, (dialog1, position) -> dialog1.dismiss()); dialog.setAdapter(arrayAdapter, (dialog12, position) -> { switch (position) { @@ -2502,7 +2340,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } else if (initialContent.trim().equals(toot_content.getText().toString().trim())) { finish(); } else { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseTootActivity.this, style); dialogBuilder.setMessage(R.string.save_draft); dialogBuilder.setPositiveButton(R.string.save, (dialog, id) -> { if (accountReply == null) { @@ -2562,18 +2400,18 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot.setVisibility(visibility); if (apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0) toot.setIn_reply_to_id(apiResponse.getStatuses().get(0).getId()); - toot.setContent(TootActivity.this, tootContent); - new PostStatusAsyncTask(TootActivity.this, social, account, toot, TootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + toot.setContent(BaseTootActivity.this, tootContent); + new PostStatusAsyncTask(BaseTootActivity.this, social, account, toot, BaseTootActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); return; } if (apiResponse.getError() == null || apiResponse.getError().getStatusCode() != -33) { if (restored != -1) { SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - new StatusStoredDAO(TootActivity.this, db).remove(restored); + new StatusStoredDAO(BaseTootActivity.this, db).remove(restored); } else if (currentToId != -1) { SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - new StatusStoredDAO(TootActivity.this, db).remove(currentToId); + new StatusStoredDAO(BaseTootActivity.this, db).remove(currentToId); } } //Clear the toot @@ -2597,13 +2435,13 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (scheduledstatus == null && !isScheduled) { boolean display_confirm = sharedpreferences.getBoolean(Helper.SET_DISPLAY_CONFIRM, true); if (display_confirm) { - Toasty.success(TootActivity.this, getString(R.string.toot_sent), Toast.LENGTH_LONG).show(); + Toasty.success(BaseTootActivity.this, getString(R.string.toot_sent), Toast.LENGTH_LONG).show(); } } else - Toasty.success(TootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + Toasty.success(BaseTootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); } else { if (apiResponse.getError().getStatusCode() == -33) - Toasty.info(TootActivity.this, getString(R.string.toast_toot_saved_error), Toast.LENGTH_LONG).show(); + Toasty.info(BaseTootActivity.this, getString(R.string.toast_toot_saved_error), Toast.LENGTH_LONG).show(); } toot_it.setEnabled(true); //It's a reply, so the user will be redirect to its answer @@ -2612,7 +2450,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (statuses != null && statuses.size() > 0) { Status status = statuses.get(0); if (status != null) { - Intent intent = new Intent(TootActivity.this, ShowConversationActivity.class); + Intent intent = new Intent(BaseTootActivity.this, ShowConversationActivity.class); Bundle b = new Bundle(); if (idRedirect == null) b.putParcelable("status", status); @@ -2625,7 +2463,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } } } else { - Intent intent = new Intent(TootActivity.this, MainActivity.class); + Intent intent = new Intent(BaseTootActivity.this, MainActivity.class); intent.putExtra(Helper.INTENT_ACTION, Helper.HOME_TIMELINE_INTENT); startActivity(intent); finish(); @@ -2645,7 +2483,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (accounts != null && accounts.size() > 0) { if (!displayWYSIWYG()) { int currentCursorPosition = toot_content.getSelectionStart(); - AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, accounts); + AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(BaseTootActivity.this, accounts); toot_content.setThreshold(1); toot_content.setAdapter(accountsListAdapter); final String oldContent = toot_content.getText().toString(); @@ -2678,7 +2516,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot_content.setText(newContent); toot_space_left.setText(String.valueOf(countLength(social, toot_content, toot_cw_content))); toot_content.setSelection(newPosition); - AccountsSearchAdapter accountsListAdapter1 = new AccountsSearchAdapter(TootActivity.this, new ArrayList<>()); + AccountsSearchAdapter accountsListAdapter1 = new AccountsSearchAdapter(BaseTootActivity.this, new ArrayList<>()); toot_content.setThreshold(1); toot_content.setAdapter(accountsListAdapter1); }); @@ -2752,7 +2590,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, this.checkedValues.add(toot_content.getText().toString().contains("@" + account.getAcct())); } this.loader.setVisibility(View.GONE); - AccountsReplyAdapter contactAdapter = new AccountsReplyAdapter(new WeakReference<>(TootActivity.this), this.contacts, this.checkedValues); + AccountsReplyAdapter contactAdapter = new AccountsReplyAdapter(new WeakReference<>(BaseTootActivity.this), this.contacts, this.checkedValues); this.lv_accounts_search.setAdapter(contactAdapter); } @@ -2776,7 +2614,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (emojis != null && emojis.size() > 0) { if (!displayWYSIWYG()) { int currentCursorPosition = toot_content.getSelectionStart(); - EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(TootActivity.this, emojis); + EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(BaseTootActivity.this, emojis); toot_content.setThreshold(1); toot_content.setAdapter(emojisSearchAdapter); final String oldContent = toot_content.getText().toString(); @@ -2808,7 +2646,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot_content.setText(newContent); toot_space_left.setText(String.valueOf(countLength(social, toot_content, toot_cw_content))); toot_content.setSelection(newPosition); - EmojisSearchAdapter emojisSearchAdapter1 = new EmojisSearchAdapter(TootActivity.this, new ArrayList<>()); + EmojisSearchAdapter emojisSearchAdapter1 = new EmojisSearchAdapter(BaseTootActivity.this, new ArrayList<>()); toot_content.setThreshold(1); toot_content.setAdapter(emojisSearchAdapter1); @@ -2885,7 +2723,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (tags != null && tags.size() > 0) { if (!displayWYSIWYG()) { int currentCursorPosition = toot_content.getSelectionStart(); - TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(TootActivity.this, tags); + TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(BaseTootActivity.this, tags); toot_content.setThreshold(1); toot_content.setAdapter(tagsSearchAdapter); final String oldContent = toot_content.getText().toString(); @@ -2922,7 +2760,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, toot_content.setText(newContent); toot_space_left.setText(String.valueOf(countLength(social, toot_content, toot_cw_content))); toot_content.setSelection(newPosition); - TagsSearchAdapter tagsSearchAdapter1 = new TagsSearchAdapter(TootActivity.this, new ArrayList<>()); + TagsSearchAdapter tagsSearchAdapter1 = new TagsSearchAdapter(BaseTootActivity.this, new ArrayList<>()); toot_content.setThreshold(1); toot_content.setAdapter(tagsSearchAdapter1); @@ -2985,13 +2823,13 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, private void restoreToot(long id) { SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - StoredStatus draft = new StatusStoredDAO(TootActivity.this, db).getStatus(id); + StoredStatus draft = new StatusStoredDAO(BaseTootActivity.this, db).getStatus(id); if (draft == null) return; Status status = draft.getStatus(); //Retrieves attachments if (removed) { - new StatusStoredDAO(TootActivity.this, db).remove(draft.getId()); + new StatusStoredDAO(BaseTootActivity.this, db).remove(draft.getId()); } restored = id; attachments = status.getMedia_attachments(); @@ -3044,12 +2882,12 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, String url = attachment.getPreview_url(); if (url == null || url.trim().equals("")) url = attachment.getUrl(); - final ImageView imageView = new ImageView(TootActivity.this); + final ImageView imageView = new ImageView(BaseTootActivity.this); imageView.setId(attachment.getViewId()); LinearLayout.LayoutParams imParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); imParams.setMargins(20, 5, 20, 5); - imParams.height = (int) Helper.convertDpToPixel(100, TootActivity.this); + imParams.height = (int) Helper.convertDpToPixel(100, BaseTootActivity.this); imageView.setAdjustViewBounds(true); imageView.setScaleType(ImageView.ScaleType.FIT_XY); toot_picture_container.addView(imageView, i, imParams); @@ -3192,12 +3030,12 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, String url = attachment.getPreview_url(); if (url == null || url.trim().equals("")) url = attachment.getUrl(); - final ImageView imageView = new ImageView(TootActivity.this); + final ImageView imageView = new ImageView(BaseTootActivity.this); imageView.setId(attachment.getViewId()); LinearLayout.LayoutParams imParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); imParams.setMargins(20, 5, 20, 5); - imParams.height = (int) Helper.convertDpToPixel(100, TootActivity.this); + imParams.height = (int) Helper.convertDpToPixel(100, BaseTootActivity.this); imageView.setAdjustViewBounds(true); imageView.setScaleType(ImageView.ScaleType.FIT_XY); toot_picture_container.addView(imageView, i, imParams); @@ -3373,7 +3211,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } if (tootReply != null) { - manageMentions(TootActivity.this, social, userIdReply, toot_content, toot_cw_content, toot_space_left, tootReply); + manageMentions(BaseTootActivity.this, social, userIdReply, toot_content, toot_cw_content, toot_space_left, tootReply); } boolean forwardTags = sharedpreferences.getBoolean(Helper.SET_FORWARD_TAGS_IN_REPLY, false); if (tootReply != null && forwardTags && tootReply.getTags() != null && tootReply.getTags().size() > 0) { @@ -3393,9 +3231,9 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } private void displayPollPopup() { - AlertDialog.Builder alertPoll = new AlertDialog.Builder(TootActivity.this, style); + AlertDialog.Builder alertPoll = new AlertDialog.Builder(BaseTootActivity.this, style); alertPoll.setTitle(R.string.create_poll); - View view = getLayoutInflater().inflate(R.layout.popup_poll, new LinearLayout(TootActivity.this), false); + View view = getLayoutInflater().inflate(R.layout.popup_poll, new LinearLayout(BaseTootActivity.this), false); alertPoll.setView(view); Spinner poll_choice = view.findViewById(R.id.poll_choice); Spinner poll_duration = view.findViewById(R.id.poll_duration); @@ -3423,7 +3261,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, int finalMax_length = max_length; add.setOnClickListener(v -> { if (pollCountItem < finalMax_entry) { - EditText poll_item = new EditText(TootActivity.this); + EditText poll_item = new EditText(BaseTootActivity.this); InputFilter[] fArray1 = new InputFilter[1]; fArray1[0] = new InputFilter.LengthFilter(finalMax_length); poll_item.setFilters(fArray1); @@ -3452,10 +3290,10 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, add.setVisibility(View.VISIBLE); }); - ArrayAdapter pollduration = ArrayAdapter.createFromResource(TootActivity.this, + ArrayAdapter pollduration = ArrayAdapter.createFromResource(BaseTootActivity.this, R.array.poll_duration, android.R.layout.simple_spinner_dropdown_item); - ArrayAdapter pollchoice = ArrayAdapter.createFromResource(TootActivity.this, + ArrayAdapter pollchoice = ArrayAdapter.createFromResource(BaseTootActivity.this, R.array.poll_choice_type, android.R.layout.simple_spinner_dropdown_item); poll_choice.setAdapter(pollchoice); poll_duration.setAdapter(pollduration); @@ -3471,7 +3309,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (pollOptions.getTitle() != null) choice_2.setText(pollOptions.getTitle()); } else { - EditText poll_item = new EditText(TootActivity.this); + EditText poll_item = new EditText(BaseTootActivity.this); fArray = new InputFilter[1]; fArray[0] = new InputFilter.LengthFilter(finalMax_length); poll_item.setFilters(fArray); @@ -3543,7 +3381,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, String choice2 = choice_2.getText().toString().trim(); if (choice1.isEmpty() && choice2.isEmpty()) { - Toasty.error(TootActivity.this, getString(R.string.poll_invalid_choices), Toast.LENGTH_SHORT).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.poll_invalid_choices), Toast.LENGTH_SHORT).show(); } else { poll = new Poll(); poll.setMultiple(poll_choice_pos != 0); @@ -3605,7 +3443,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, poll.setOptionsList(pollOptions); dialog.dismiss(); } else { - Toasty.error(TootActivity.this, getString(R.string.poll_duplicated_entry), Toast.LENGTH_SHORT).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.poll_duplicated_entry), Toast.LENGTH_SHORT).show(); } } poll_action.setVisibility(View.VISIBLE); @@ -3639,7 +3477,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, if (toot_cw_content.getText().toString().trim().length() > 0) toot.setSpoiler_text(toot_cw_content.getText().toString().trim()); toot.setVisibility(visibility); - toot.setContent(TootActivity.this, currentContent); + toot.setContent(BaseTootActivity.this, currentContent); if (poll != null) toot.setPoll(poll); @@ -3648,21 +3486,21 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); try { if (currentToId == -1) { - currentToId = new StatusStoredDAO(TootActivity.this, db).insertStatus(toot, tootReply); + currentToId = new StatusStoredDAO(BaseTootActivity.this, db).insertStatus(toot, tootReply); } else { - StoredStatus storedStatus = new StatusStoredDAO(TootActivity.this, db).getStatus(currentToId); + StoredStatus storedStatus = new StatusStoredDAO(BaseTootActivity.this, db).getStatus(currentToId); if (storedStatus != null) { - new StatusStoredDAO(TootActivity.this, db).updateStatus(currentToId, toot); + new StatusStoredDAO(BaseTootActivity.this, db).updateStatus(currentToId, toot); } else { //Might have been deleted, so it needs insertion - new StatusStoredDAO(TootActivity.this, db).insertStatus(toot, tootReply); + new StatusStoredDAO(BaseTootActivity.this, db).insertStatus(toot, tootReply); } } if (message) - Toasty.success(TootActivity.this, getString(R.string.toast_toot_saved), Toast.LENGTH_LONG).show(); + Toasty.success(BaseTootActivity.this, getString(R.string.toast_toot_saved), Toast.LENGTH_LONG).show(); } catch (Exception e) { if (message) - Toasty.error(TootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + Toasty.error(BaseTootActivity.this, getString(R.string.toast_error), Toast.LENGTH_LONG).show(); } } @@ -3675,8 +3513,8 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, checkedValues[i] = toot_content.getText().toString().contains("@" + account.getAcct()); i++; } - final AlertDialog.Builder builderSingle = new AlertDialog.Builder(TootActivity.this, style); - AccountsReplyAdapter accountsReplyAdapter = new AccountsReplyAdapter(new WeakReference<>(TootActivity.this), accounts, checkedValues); + final AlertDialog.Builder builderSingle = new AlertDialog.Builder(BaseTootActivity.this, style); + AccountsReplyAdapter accountsReplyAdapter = new AccountsReplyAdapter(new WeakReference<>(BaseTootActivity.this), accounts, checkedValues); builderSingle.setTitle(getString(R.string.select_accounts)).setAdapter(accountsReplyAdapter, null); builderSingle.setNegativeButton(R.string.validate, (dialog, which) -> { dialog.dismiss(); @@ -3713,13 +3551,13 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, for (Attachment attachment : attachments) { if (attachment.getType().toLowerCase().equals("image")) if (v.getTag().toString().trim().equals(attachment.getId().trim())) { - int borderSize = (int) Helper.convertDpToPixel(1, TootActivity.this); - int borderSizeTop = (int) Helper.convertDpToPixel(6, TootActivity.this); + int borderSize = (int) Helper.convertDpToPixel(1, BaseTootActivity.this); + int borderSizeTop = (int) Helper.convertDpToPixel(6, BaseTootActivity.this); v.setPadding(borderSize, borderSizeTop, borderSize, borderSizeTop); if (attachment.getDescription() == null || attachment.getDescription().trim().equals("null") || attachment.getDescription().trim().equals("")) { - v.setBackgroundColor(ContextCompat.getColor(TootActivity.this, R.color.red_1)); + v.setBackgroundColor(ContextCompat.getColor(BaseTootActivity.this, R.color.red_1)); } else - v.setBackgroundColor(ContextCompat.getColor(TootActivity.this, R.color.green_1)); + v.setBackgroundColor(ContextCompat.getColor(BaseTootActivity.this, R.color.green_1)); } } @@ -3786,7 +3624,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, findViewById(R.id.action_bulleted).setOnClickListener(v -> wysiwyg.insertList(false)); - findViewById(R.id.action_color).setOnClickListener(v -> new ColorPickerPopup.Builder(TootActivity.this) + findViewById(R.id.action_color).setOnClickListener(v -> new ColorPickerPopup.Builder(BaseTootActivity.this) .enableAlpha(false) .okTitle(getString(R.string.validate)) .cancelTitle(getString(R.string.cancel)) @@ -3908,4 +3746,9 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, } } } + + + protected abstract boolean actionTranslateClick(); + protected abstract void launchPhotoEditor(Uri uri); + protected abstract void displayEmojiPopup(); } diff --git a/app/src/main/java/app/fedilab/android/activities/MainBaseFragmentActivity.java b/app/src/main/java/app/fedilab/android/activities/MainBaseFragmentActivity.java index a4a2f6b0f..2843bfcfc 100644 --- a/app/src/main/java/app/fedilab/android/activities/MainBaseFragmentActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MainBaseFragmentActivity.java @@ -1,26 +1,19 @@ package app.fedilab.android.activities; - -import android.annotation.SuppressLint; +/* Copyright 2020 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ import androidx.appcompat.app.AppCompatActivity; -import com.vanniktech.emoji.EmojiManager; -import com.vanniktech.emoji.one.EmojiOneProvider; - -import app.fedilab.android.helper.Helper; - -/** - * Created by Thomas on 16/05/2020. - * Fragment base activity which updates security provider - */ - -@SuppressLint("Registered") -public class BaseFragmentActivity extends AppCompatActivity { - - - static { - Helper.installProvider(); - EmojiManager.install(new EmojiOneProvider()); - } - -} +public abstract class MainBaseFragmentActivity extends AppCompatActivity {}