move some code

This commit is contained in:
Thomas 2020-07-14 12:00:58 +02:00
parent 5ec41ac145
commit 51a098397d
10 changed files with 461 additions and 667 deletions

View File

@ -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'

View File

@ -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 <http://www.gnu.org/licenses>. */
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);

View File

@ -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.
});
}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
public class BaseFragmentActivity extends MainBaseFragmentActivity{}

View File

@ -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 <http://www.gnu.org/licenses>. */
public class TootActivity extends BaseTootActivity{
@Override
protected boolean actionTranslateClick() {
return true;
}
public class PixelfedComposeActivity extends BasePixelfedComposeActivity{
@Override
protected void launchPhotoEditor(Uri uri) {}

View File

@ -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 <http://www.gnu.org/licenses>. */
public class TootActivity extends BaseTootActivity{
@Override
protected boolean actionTranslateClick() {
return true;
}
@Override
protected void launchPhotoEditor(Uri uri) {}
@Override
protected void displayEmojiPopup() {}
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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);
}
}

View File

@ -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<String> arrayAdapter = new ArrayAdapter<>(PixelfedComposeActivity.this, android.R.layout.simple_list_item_1, stringArray);
final ArrayAdapter<String> 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<Account> 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<String> 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();
}

View File

@ -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 <http://www.gnu.org/licenses>. */
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 {}