Clean some activities

This commit is contained in:
tom79 2020-04-08 13:01:28 +02:00
parent 0fc0b19e6f
commit 007d6b85fc
6 changed files with 530 additions and 757 deletions

View File

@ -130,4 +130,5 @@ dependencies {
implementation 'com.github.smarteist:autoimageslider:1.3.2'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.2'
implementation 'com.jaredrummler:cyanea:1.0.2'
}

View File

@ -20,7 +20,6 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@ -63,7 +62,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.PlaybackControlView;
import com.google.android.exoplayer2.ui.SimpleExoPlayerView;
@ -130,7 +128,6 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private RelativeLayout loader;
private TextView peertube_view_count, peertube_playlist, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_share, peertube_download, peertube_description, peertube_title;
private ScrollView peertube_information_container;
private int stopPosition;
private Peertube peertube;
private TextView toolbar_title;
private SimpleExoPlayerView playerView;
@ -139,7 +136,6 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private Dialog fullScreenDialog;
private AppCompatImageView fullScreenIcon;
private TextView resolution;
private DefaultTrackSelector trackSelector;
private int mode;
private LinearLayout write_comment_container;
private ImageView send;
@ -150,8 +146,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
private List<Playlist> playlists;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null && activity.getWindow().getDecorView() != null) {
if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView();
InputMethodManager imm = (InputMethodManager) activity.getSystemService(INPUT_METHOD_SERVICE);
assert imm != null;
imm.hideSoftInputFromWindow(activity.getWindow().getDecorView().getWindowToken(), 0);
}
}
@ -193,16 +191,13 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
add_comment_write = findViewById(R.id.add_comment_write);
peertube_playlist = findViewById(R.id.peertube_playlist);
send = findViewById(R.id.send);
add_comment_read.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
add_comment_read.setVisibility(View.GONE);
add_comment_write.setVisibility(View.VISIBLE);
send.setVisibility(View.VISIBLE);
add_comment_write.requestFocus();
add_comment_write.setSelection(add_comment_write.getText().length());
add_comment_read.setOnClickListener(v -> {
add_comment_read.setVisibility(View.GONE);
add_comment_write.setVisibility(View.VISIBLE);
send.setVisibility(View.VISIBLE);
add_comment_write.requestFocus();
add_comment_write.setSelection(add_comment_write.getText().length());
}
});
Helper.changeDrawableColor(PeertubeActivity.this, send, R.color.cyanea_accent);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
@ -213,18 +208,15 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
peertube_bookmark.setVisibility(View.GONE);
}
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String comment = add_comment_write.getText().toString();
if (comment.trim().length() > 0) {
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
add_comment_write.setText("");
add_comment_read.setVisibility(View.VISIBLE);
add_comment_write.setVisibility(View.GONE);
send.setVisibility(View.GONE);
add_comment_read.requestFocus();
}
send.setOnClickListener(v -> {
String comment = add_comment_write.getText().toString();
if (comment.trim().length() > 0) {
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
add_comment_write.setText("");
add_comment_read.setVisibility(View.VISIBLE);
add_comment_write.setVisibility(View.GONE);
send.setVisibility(View.GONE);
add_comment_read.requestFocus();
}
});
@ -250,12 +242,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbar_close.setOnClickListener(v -> finish());
}
@ -271,27 +258,24 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
MastalabWebChromeClient mastalabWebChromeClient = new MastalabWebChromeClient(PeertubeActivity.this, webview_video, webview_container, videoLayout);
mastalabWebChromeClient.setOnToggledFullscreen(new MastalabWebChromeClient.ToggledFullscreenCallback() {
@Override
public void toggledFullscreen(boolean fullscreen) {
mastalabWebChromeClient.setOnToggledFullscreen(fullscreen -> {
if (fullscreen) {
videoLayout.setVisibility(View.VISIBLE);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
peertube_information_container.setVisibility(View.GONE);
} else {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
videoLayout.setVisibility(View.GONE);
peertube_information_container.setVisibility(View.VISIBLE);
}
if (fullscreen) {
videoLayout.setVisibility(View.VISIBLE);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
peertube_information_container.setVisibility(View.GONE);
} else {
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
videoLayout.setVisibility(View.GONE);
peertube_information_container.setVisibility(View.VISIBLE);
}
});
String user_agent = sharedpreferences.getString(Helper.SET_CUSTOM_USER_AGENT, null);
@ -443,22 +427,14 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
LinearLayout.LayoutParams.WRAP_CONTENT);
input.setLayoutParams(lp);
builderInner.setView(input);
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.validate, (dialog, which) -> {
String comment = input.getText().toString();
if (comment.trim().length() > 0) {
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
});
builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String comment = input.getText().toString();
if (comment.trim().length() > 0) {
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.PEERTUBECOMMENT, peertube.getId(), null, comment, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
}
});
builderInner.show();
}
return true;
@ -496,54 +472,48 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
peertube_playlist.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (playlists != null && peertube.getId() != null) {
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
peertube_playlist.setOnClickListener(v -> {
if (playlists != null && peertube.getId() != null) {
PopupMenu popup = new PopupMenu(PeertubeActivity.this, peertube_playlist);
for (Playlist playlist : playlists) {
String title = null;
for (String id : playlistForVideo) {
if (playlist.getId().equals(id)) {
title = "" + playlist.getDisplayName();
break;
}
for (Playlist playlist : playlists) {
String title = null;
for (String id : playlistForVideo) {
if (playlist.getId().equals(id)) {
title = "" + playlist.getDisplayName();
break;
}
if (title == null) {
title = playlist.getDisplayName();
}
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
}
if (title == null) {
title = playlist.getDisplayName();
}
MenuItem item = popup.getMenu().add(0, 0, Menu.NONE, title);
item.setOnMenuItemClickListener(item1 -> {
item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item1.setActionView(new View(PeertubeActivity.this));
item1.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
item.setActionView(new View(PeertubeActivity.this));
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
return false;
}
public boolean onMenuItemActionExpand(MenuItem item1) {
return false;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
return false;
}
});
if (playlistForVideo.contains(playlist.getId())) {
item.setTitle(playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.remove(playlist.getId());
} else {
item.setTitle("" + playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.add(playlist.getId());
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item1) {
return false;
}
});
popup.show();
}
if (playlistForVideo.contains(playlist.getId())) {
item1.setTitle(playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.DELETE_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.remove(playlist.getId());
} else {
item1.setTitle("" + playlist.getDisplayName());
new ManagePlaylistsAsyncTask(PeertubeActivity.this, ManagePlaylistsAsyncTask.action.ADD_VIDEOS, playlist, peertube.getId(), null, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
playlistForVideo.add(playlist.getId());
}
return false;
});
popup.show();
}
}
});
@ -574,54 +544,40 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
initResolution();
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
peertube_like_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
}
peertube_like_count.setOnClickListener(v -> {
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
});
peertube_dislike_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
}
peertube_dislike_count.setOnClickListener(v -> {
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
new PostActionAsyncTask(PeertubeActivity.this, API.StatusAction.RATEVIDEO, peertube.getId(), null, newState, PeertubeActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
peertube.setMyRating(newState);
changeColor();
});
} else {
peertube_like_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
Status status = new Status();
status.setUri("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
CrossActions.doCrossAction(PeertubeActivity.this, RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.FAVOURITE, null, PeertubeActivity.this, true);
peertube.setMyRating(newState);
changeColor();
}
peertube_like_count.setOnClickListener(v -> {
String newState = peertube.getMyRating().equals("like") ? "none" : "like";
Status status = new Status();
status.setUri("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
CrossActions.doCrossAction(PeertubeActivity.this, RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.FAVOURITE, null, PeertubeActivity.this, true);
peertube.setMyRating(newState);
changeColor();
});
peertube_dislike_count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
Status status = new Status();
status.setUri("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
CrossActions.doCrossAction(PeertubeActivity.this, RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.UNFAVOURITE, null, PeertubeActivity.this, true);
peertube.setMyRating(newState);
changeColor();
}
peertube_dislike_count.setOnClickListener(v -> {
String newState = peertube.getMyRating().equals("dislike") ? "none" : "dislike";
Status status = new Status();
status.setUri("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid());
CrossActions.doCrossAction(PeertubeActivity.this, RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE, status, null, API.StatusAction.UNFAVOURITE, null, PeertubeActivity.this, true);
peertube.setMyRating(newState);
changeColor();
});
}
try {
HttpsURLConnection.setDefaultSSLSocketFactory(new TLSSocketFactory(instance));
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
} catch (KeyManagementException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
@ -642,18 +598,15 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
peertube_download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
} else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, peertube.isStreamService()));
}
peertube_download.setOnClickListener(v -> {
if (Build.VERSION.SDK_INT >= 23) {
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
} else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, peertube.isStreamService()));
}
} else {
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, peertube.isStreamService()));
}
});
SQLiteDatabase db = Sqlite.getInstance(PeertubeActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
@ -667,52 +620,45 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube);
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null);
peertube_bookmark.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Peertube> peertubes = new PeertubeFavoritesDAO(PeertubeActivity.this, db).getSinglePeertube(peertube);
if (peertubes == null || peertubes.size() == 0) {
new PeertubeFavoritesDAO(PeertubeActivity.this, db).insert(peertube);
Toasty.success(PeertubeActivity.this, getString(R.string.bookmark_add_peertube), Toast.LENGTH_SHORT).show();
} else {
new PeertubeFavoritesDAO(PeertubeActivity.this, db).remove(peertube);
Toasty.success(PeertubeActivity.this, getString(R.string.bookmark_remove_peertube), Toast.LENGTH_SHORT).show();
}
if (peertubes != null && peertubes.size() > 0) //Was initially in cache
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border), null, null);
else
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube), null, null);
peertube_bookmark.setOnClickListener(v -> {
List<Peertube> peertubes1 = new PeertubeFavoritesDAO(PeertubeActivity.this, db).getSinglePeertube(peertube);
if (peertubes1 == null || peertubes1.size() == 0) {
new PeertubeFavoritesDAO(PeertubeActivity.this, db).insert(peertube);
Toasty.success(PeertubeActivity.this, getString(R.string.bookmark_add_peertube), Toast.LENGTH_SHORT).show();
} else {
new PeertubeFavoritesDAO(PeertubeActivity.this, db).remove(peertube);
Toasty.success(PeertubeActivity.this, getString(R.string.bookmark_remove_peertube), Toast.LENGTH_SHORT).show();
}
if (peertubes1 != null && peertubes1.size() > 0) //Was initially in cache
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border), null, null);
else
peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube), null, null);
});
peertube_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
String url;
peertube_share.setOnClickListener(v -> {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.shared_via));
String url;
url = "https://" + peertube.getInstance() + "/videos/watch/" + peertube.getUuid();
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
String extra_text;
if (share_details) {
extra_text = "@" + peertube.getAccount().getAcct();
extra_text += "\r\n\r\n" + peertube.getName();
extra_text += "\n\n" + Helper.shortnameToUnicode(":link:", true) + " " + url + "\r\n-\n";
final String contentToot;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
contentToot = Html.fromHtml(peertube.getDescription(), Html.FROM_HTML_MODE_LEGACY).toString();
else
//noinspection deprecation
contentToot = Html.fromHtml(peertube.getDescription()).toString();
extra_text += contentToot;
} else {
extra_text = url;
}
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_with)));
url = "https://" + peertube.getInstance() + "/videos/watch/" + peertube.getUuid();
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
String extra_text;
if (share_details) {
extra_text = "@" + peertube.getAccount().getAcct();
extra_text += "\r\n\r\n" + peertube.getName();
extra_text += "\n\n" + Helper.shortnameToUnicode(":link:", true) + " " + url + "\r\n-\n";
final String contentToot;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
contentToot = Html.fromHtml(peertube.getDescription(), Html.FROM_HTML_MODE_LEGACY).toString();
else
contentToot = Html.fromHtml(peertube.getDescription()).toString();
extra_text += contentToot;
} else {
extra_text = url;
}
sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share_with)));
});
}
@ -731,7 +677,6 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
change();
} else {
final ViewGroup videoLayout = findViewById(R.id.videoLayout);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setFullscreen(FullScreenMediaController.fullscreen.ON);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
@ -822,44 +767,36 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
}
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PeertubeActivity.this, style);
builderSingle.setTitle(R.string.pickup_resolution);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PeertubeActivity.this, android.R.layout.select_dialog_item);
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(PeertubeActivity.this, android.R.layout.select_dialog_item);
for (String resolution : peertube.getResolution())
arrayAdapter.add(resolution + "p");
builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String res = arrayAdapter.getItem(which).substring(0, arrayAdapter.getItem(which).length() - 1);
builderSingle.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderSingle.setAdapter(arrayAdapter, (dialog, which) -> {
String res = Objects.requireNonNull(arrayAdapter.getItem(which)).substring(0, Objects.requireNonNull(arrayAdapter.getItem(which)).length() - 1);
if (playerView != null) {
loader.setVisibility(View.VISIBLE);
long position = player.getCurrentPosition();
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%sp", res));
if (mode == Helper.VIDEO_MODE_DIRECT) {
if (player != null)
player.release();
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
playerView.setPlayer(player);
loader.setVisibility(View.GONE);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, "Mastalab"), null);
if (playerView != null) {
loader.setVisibility(View.VISIBLE);
long position = player.getCurrentPosition();
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%sp", res));
if (mode == Helper.VIDEO_MODE_DIRECT) {
if (player != null)
player.release();
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
playerView.setPlayer(player);
loader.setVisibility(View.GONE);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(PeertubeActivity.this,
Util.getUserAgent(PeertubeActivity.this, "Mastalab"), null);
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
player.prepare(videoSource);
player.seekTo(0, position);
player.setPlayWhenReady(true);
}
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
player.prepare(videoSource);
player.seekTo(0, position);
player.setPlayWhenReady(true);
}
}
});
builderSingle.show();
}
@ -908,14 +845,11 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
fullScreenIcon = controlView.findViewById(R.id.exo_fullscreen_icon);
View fullScreenButton = controlView.findViewById(R.id.exo_fullscreen_button);
fullScreenButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!fullScreenMode)
openFullscreenDialog();
else
closeFullscreenDialog();
}
fullScreenButton.setOnClickListener(v -> {
if (!fullScreenMode)
openFullscreenDialog();
else
closeFullscreenDialog();
});
}
@ -923,12 +857,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
PlaybackControlView controlView = playerView.findViewById(R.id.exo_controller);
resolution = controlView.findViewById(R.id.resolution);
resolution.setText(String.format("%sp", peertube.getResolution().get(0)));
resolution.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
displayResolution();
}
});
resolution.setOnClickListener(v -> displayResolution());
}

View File

@ -15,7 +15,6 @@ package app.fedilab.android.activities;
* see <http://www.gnu.org/licenses>. */
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
@ -117,12 +116,7 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbar_close.setOnClickListener(v -> finish());
toolbar_title.setText(R.string.update_video);
}
setContentView(R.layout.activity_peertube_edit);
@ -142,37 +136,26 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
set_upload_enable_comments = findViewById(R.id.set_upload_enable_comments);
set_upload_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builderInner;
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int style;
if (theme == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
} else {
style = R.style.Dialog;
}
builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this, style);
builderInner.setMessage(getString(R.string.delete_video_confirmation));
builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new PostActionAsyncTask(PeertubeEditUploadActivity.this, API.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
dialog.dismiss();
}
});
builderInner.show();
set_upload_delete.setOnClickListener(v -> {
AlertDialog.Builder builderInner;
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
int theme1 = sharedpreferences1.getInt(Helper.SET_THEME, Helper.THEME_DARK);
int style;
if (theme1 == Helper.THEME_DARK) {
style = R.style.DialogDark;
} else if (theme1 == Helper.THEME_BLACK) {
style = R.style.DialogBlack;
} else {
style = R.style.Dialog;
}
builderInner = new AlertDialog.Builder(PeertubeEditUploadActivity.this, style);
builderInner.setMessage(getString(R.string.delete_video_confirmation));
builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builderInner.setPositiveButton(R.string.yes, (dialog, which) -> {
new PostActionAsyncTask(PeertubeEditUploadActivity.this, API.StatusAction.PEERTUBEDELETEVIDEO, videoId, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
dialog.dismiss();
});
builderInner.show();
});
//Get params from the API
LinkedHashMap<Integer, String> categories = new LinkedHashMap<>(peertubeInformation.getCategories());
@ -359,9 +342,6 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
LinkedHashMap<Integer, String> licences = new LinkedHashMap<>(peertubeInformation.getLicences());
LinkedHashMap<Integer, String> privacies = new LinkedHashMap<>(peertubeInformation.getPrivacies());
LinkedHashMap<String, String> languages = new LinkedHashMap<>(peertubeInformation.getLanguages());
LinkedHashMap<String, String> translations = null;
if (peertubeInformation.getTranslations() != null)
translations = new LinkedHashMap<>(peertubeInformation.getTranslations());
int languagePosition = 0;
@ -532,27 +512,24 @@ public class PeertubeEditUploadActivity extends BaseActivity implements OnRetrie
});
set_upload_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String title = p_video_title.getText().toString().trim();
String description = p_video_description.getText().toString().trim();
boolean isNSFW = set_upload_nsfw.isChecked();
boolean commentEnabled = set_upload_enable_comments.isChecked();
peertube.setName(title);
peertube.setDescription(description);
peertube.setSensitive(isNSFW);
peertube.setCommentsEnabled(commentEnabled);
peertube.setCategory(categoryToSend);
peertube.setLicense(licenseToSend);
peertube.setLanguage(languageToSend);
peertube.setChannelForUpdate(channelToSend);
peertube.setPrivacy(privacyToSend);
List<String> tags = p_video_tags.getTags();
peertube.setTags(tags);
set_upload_submit.setEnabled(false);
new PostPeertubeAsyncTask(PeertubeEditUploadActivity.this, peertube, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
}
set_upload_submit.setOnClickListener(v -> {
String title1 = p_video_title.getText().toString().trim();
String description = p_video_description.getText().toString().trim();
boolean isNSFW1 = set_upload_nsfw.isChecked();
boolean commentEnabled1 = set_upload_enable_comments.isChecked();
peertube.setName(title1);
peertube.setDescription(description);
peertube.setSensitive(isNSFW1);
peertube.setCommentsEnabled(commentEnabled1);
peertube.setCategory(categoryToSend);
peertube.setLicense(licenseToSend);
peertube.setLanguage(languageToSend);
peertube.setChannelForUpdate(channelToSend);
peertube.setPrivacy(privacyToSend);
List<String> tags = p_video_tags.getTags();
peertube.setTags(tags);
set_upload_submit.setEnabled(false);
new PostPeertubeAsyncTask(PeertubeEditUploadActivity.this, peertube, PeertubeEditUploadActivity.this).executeOnExecutor(THREAD_POOL_EXECUTOR);
});
set_upload_privacy.setSelection(privacyPosition);

View File

@ -119,12 +119,7 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
toolbar_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbar_close.setOnClickListener(v -> finish());
toolbar_title.setText(R.string.upload_video);
}
setContentView(R.layout.activity_peertube_upload);
@ -335,52 +330,49 @@ public class PeertubeUploadActivity extends BaseActivity implements OnRetrievePe
}
});
set_upload_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (uri != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
String idChannel = channelM.getValue();
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
Integer idPrivacy = privacyM.getKey();
set_upload_submit.setOnClickListener(v -> {
if (uri != null) {
Map.Entry<String, String> channelM = channelToSend.entrySet().iterator().next();
String idChannel = channelM.getValue();
Map.Entry<Integer, String> privacyM = privacyToSend.entrySet().iterator().next();
Integer idPrivacy = privacyM.getKey();
try {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
Intent in = new Intent(PeertubeUploadActivity.this, PeertubeEditUploadActivity.class);
PendingIntent clickIntent = PendingIntent.getActivity(PeertubeUploadActivity.this, 1, in, PendingIntent.FLAG_UPDATE_CURRENT);
uploadConfig
.setClearOnActionForAllStatuses(true);
try {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
Intent in = new Intent(PeertubeUploadActivity.this, PeertubeEditUploadActivity.class);
PendingIntent clickIntent = PendingIntent.getActivity(PeertubeUploadActivity.this, 1, in, PendingIntent.FLAG_UPDATE_CURRENT);
uploadConfig
.setClearOnActionForAllStatuses(true);
uploadConfig.getProgress().message = getString(R.string.uploading);
uploadConfig.getCompleted().message = getString(R.string.upload_video_success);
uploadConfig.getError().message = getString(R.string.toast_error);
uploadConfig.getCancelled().message = getString(R.string.toast_cancelled);
uploadConfig.getCompleted().actions.add(new UploadNotificationAction(R.drawable.ic_check, getString(R.string.video_uploaded_action), clickIntent));
uploadConfig.getProgress().message = getString(R.string.uploading);
uploadConfig.getCompleted().message = getString(R.string.upload_video_success);
uploadConfig.getError().message = getString(R.string.toast_error);
uploadConfig.getCancelled().message = getString(R.string.toast_cancelled);
uploadConfig.getCompleted().actions.add(new UploadNotificationAction(R.drawable.ic_check, getString(R.string.video_uploaded_action), clickIntent));
if (video_title != null && video_title.getText() != null && video_title.getText().toString().trim().length() > 0) {
filename = video_title.getText().toString().trim();
}
String uploadId = UUID.randomUUID().toString();
uploadReceiver.setUploadID(uploadId);
new MultipartUploadRequest(PeertubeUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.addFileToUpload(uri.toString().replace("file://", ""), "videofile")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
.addParameter("name", filename)
.addParameter("channelId", idChannel)
.addParameter("privacy", String.valueOf(idPrivacy))
.addParameter("nsfw", "false")
.addParameter("commentsEnabled", "true")
.addParameter("waitTranscoding", "true")
.setMaxRetries(2)
.startUpload();
finish();
} catch (Exception exc) {
exc.printStackTrace();
if (video_title != null && video_title.getText() != null && video_title.getText().toString().trim().length() > 0) {
filename = video_title.getText().toString().trim();
}
String uploadId = UUID.randomUUID().toString();
uploadReceiver.setUploadID(uploadId);
new MultipartUploadRequest(PeertubeUploadActivity.this, uploadId, "https://" + Helper.getLiveInstance(PeertubeUploadActivity.this) + "/api/v1/videos/upload")
.addFileToUpload(uri.toString().replace("file://", ""), "videofile")
.addHeader("Authorization", "Bearer " + token)
.setNotificationConfig(uploadConfig)
.addParameter("name", filename)
.addParameter("channelId", idChannel)
.addParameter("privacy", String.valueOf(idPrivacy))
.addParameter("nsfw", "false")
.addParameter("commentsEnabled", "true")
.addParameter("waitTranscoding", "true")
.setMaxRetries(2)
.startUpload();
finish();
} catch (Exception exc) {
exc.printStackTrace();
}
}
});

View File

@ -16,7 +16,6 @@ package app.fedilab.android.activities;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
@ -225,12 +224,9 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorLi
public void onEditTextChangeListener(final View rootView, String text, int colorCode) {
TextEditorDialogFragment textEditorDialogFragment =
TextEditorDialogFragment.show(this, text, colorCode);
textEditorDialogFragment.setOnTextEditorListener(new TextEditorDialogFragment.TextEditor() {
@Override
public void onDone(String inputText, int colorCode) {
mPhotoEditor.editText(rootView, inputText, colorCode);
mTxtCurrentTool.setText(R.string.label_text);
}
textEditorDialogFragment.setOnTextEditorListener((inputText, colorCode1) -> {
mPhotoEditor.editText(rootView, inputText, colorCode1);
mTxtCurrentTool.setText(R.string.label_text);
});
}
@ -295,6 +291,7 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorLi
File file = new File(myDir + "/" + filename);
try {
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
SaveSettings saveSettings = new SaveSettings.Builder()
@ -446,25 +443,10 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorLi
}
AlertDialog.Builder builder = new AlertDialog.Builder(this, style);
builder.setMessage(getString(R.string.confirm_exit_editing));
builder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
saveImage();
}
});
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setPositiveButton(R.string.save, (dialog, which) -> saveImage());
builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss());
builder.setNegativeButton(R.string.discard, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.setNegativeButton(R.string.discard, (dialog, which) -> finish());
builder.create().show();
}
@ -484,12 +466,9 @@ public class PhotoEditorActivity extends BaseActivity implements OnPhotoEditorLi
break;
case TEXT:
TextEditorDialogFragment textEditorDialogFragment = TextEditorDialogFragment.show(this);
textEditorDialogFragment.setOnTextEditorListener(new TextEditorDialogFragment.TextEditor() {
@Override
public void onDone(String inputText, int colorCode) {
mPhotoEditor.addText(inputText, colorCode);
mTxtCurrentTool.setText(R.string.label_text);
}
textEditorDialogFragment.setOnTextEditorListener((inputText, colorCode) -> {
mPhotoEditor.addText(inputText, colorCode);
mTxtCurrentTool.setText(R.string.label_text);
});
break;
case ERASER:

View File

@ -21,7 +21,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;
@ -52,11 +51,9 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.ImageButton;
import android.widget.ImageView;
@ -113,6 +110,7 @@ import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.TimeZone;
import java.util.UUID;
import java.util.regex.Matcher;
@ -176,7 +174,6 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
public static boolean autocomplete;
public static Uri photoFileUri = null;
static boolean active = false;
private static String instance;
private static int searchDeep = 15;
private final int PICK_IMAGE = 56556;
private final int TAKE_PHOTO = 56532;
@ -198,7 +195,6 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
private TextView toot_space_left;
private String initialContent;
private Account accountReply;
private String userId;
private Account account;
private boolean removed;
private boolean restoredScheduled;
@ -228,9 +224,9 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
public void onReceive(Context context, Intent intent) {
pixelfed_story.setEnabled(true);
JSONObject response = null;
ArrayList<String> successfullyUploadedFiles = null;
ArrayList<String> successfullyUploadedFiles;
try {
response = new JSONObject(intent.getStringExtra("response"));
response = new JSONObject(Objects.requireNonNull(intent.getStringExtra("response")));
} catch (JSONException e) {
e.printStackTrace();
}
@ -293,22 +289,19 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = new Runnable() {
@Override
public void run() {
newContent[0] = newContent[0] + hugs.toString();
toot_content.setText(newContent[0]);
toot_content.setSelection(toot_content.getText().length());
// toot_content.addTextChangedListener(finalTextw);
autocomplete = false;
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
}
Runnable myRunnable = () -> {
newContent[0] = newContent[0] + hugs.toString();
toot_content.setText(newContent[0]);
toot_content.setSelection(toot_content.getText().length());
// toot_content.addTextChangedListener(finalTextw);
autocomplete = false;
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
};
mainHandler.post(myRunnable);
} else if (s.toString().contains(fedilabMorseTrigger)) {
newContent[0] = s.toString().replaceAll(fedilabMorseTrigger, "").trim();
List<String> mentions = new ArrayList<>();
String mentionPattern = "@[a-z0-9_]+(@[a-z0-9\\.\\-]+[a-z0-9]+)?";
String mentionPattern = "@[a-z0-9_]+(@[a-z0-9.\\-]+[a-z0-9]+)?";
final Pattern mPattern = Pattern.compile(mentionPattern, Pattern.CASE_INSENSITIVE);
Matcher matcherMentions = mPattern.matcher(newContent[0]);
while (matcherMentions.find()) {
@ -343,14 +336,11 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = new Runnable() {
@Override
public void run() {
toot_content.setText(newContent[0]);
toot_content.setSelection(toot_content.getText().length());
autocomplete = false;
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
}
Runnable myRunnable = () -> {
toot_content.setText(newContent[0]);
toot_content.setSelection(toot_content.getText().length());
autocomplete = false;
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
};
mainHandler.post(myRunnable);
}
@ -524,7 +514,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
String content = toot_content.getText().toString();
String contentCount = content;
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) {
contentCount = contentCount.replaceAll("(?i)(^|[^/\\w])@(([a-z0-9_]+)@[a-z0-9\\.\\-]+[a-z0-9]+)", "$1@$3");
contentCount = contentCount.replaceAll("(?i)(^|[^/\\w])@(([a-z0-9_]+)@[a-z0-9.\\-]+[a-z0-9]+)", "$1@$3");
Matcher matcherALink = Patterns.WEB_URL.matcher(contentCount);
while (matcherALink.find()) {
final String url = matcherALink.group(1);
@ -540,16 +530,11 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
protected void onCreate(Bundle savedInstanceState) {
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(PixelfedComposeActivity.this));
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
switch (theme) {
case Helper.THEME_LIGHT:
setTheme(R.style.AppTheme_Fedilab);
break;
case Helper.THEME_DARK:
setTheme(R.style.AppThemeDark);
break;
case Helper.THEME_BLACK:
setTheme(R.style.AppThemeBlack);
break;
@ -579,48 +564,39 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView close_toot = actionBar.getCustomView().findViewById(R.id.close_toot);
close_toot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
assert inputMethodManager != null;
inputMethodManager.hideSoftInputFromWindow(toot_content.getWindowToken(), 0);
boolean storeToot = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true);
if (!storeToot) {
if (toot_content.getText().toString().trim().length() == 0 && (attachments == null || attachments.size() < 1)) {
finish();
} else if (initialContent.trim().equals(toot_content.getText().toString().trim())) {
finish();
} else {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PixelfedComposeActivity.this, style);
dialogBuilder.setMessage(R.string.save_draft);
dialogBuilder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (accountReply == null) {
storeToot(true, false);
} else {
storeToot(false, false);
}
dialog.dismiss();
finish();
}
});
dialogBuilder.setNegativeButton(R.string.discard, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
finish();
}
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setCancelable(false);
alertDialog.show();
}
} else {
close_toot.setOnClickListener(v -> {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
assert inputMethodManager != null;
inputMethodManager.hideSoftInputFromWindow(toot_content.getWindowToken(), 0);
boolean storeToot = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true);
if (!storeToot) {
if (toot_content.getText().toString().trim().length() == 0 && (attachments == null || attachments.size() < 1)) {
finish();
} else if (initialContent.trim().equals(toot_content.getText().toString().trim())) {
finish();
} else {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PixelfedComposeActivity.this, style);
dialogBuilder.setMessage(R.string.save_draft);
dialogBuilder.setPositiveButton(R.string.save, (dialog, id) -> {
if (accountReply == null) {
storeToot(true, false);
} else {
storeToot(false, false);
}
dialog.dismiss();
finish();
});
dialogBuilder.setNegativeButton(R.string.discard, (dialog, id) -> {
dialog.dismiss();
finish();
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setCancelable(false);
alertDialog.show();
}
} else {
finish();
}
});
title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
@ -658,11 +634,8 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
if (sharedpreferences.getBoolean(Helper.SET_DISPLAY_EMOJI, false)) {
final EmojiPopup emojiPopup = EmojiPopup.Builder.fromRootView(drawer_layout).build(toot_content);
toot_emoji.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
emojiPopup.toggle(); // Toggles visibility of the Popup.
}
toot_emoji.setOnClickListener(v -> {
emojiPopup.toggle(); // Toggles visibility of the Popup.
});
} else {
toot_emoji.setVisibility(View.GONE);
@ -772,94 +745,73 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
break;
}
toot_sensitive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isSensitive = isChecked;
}
});
toot_sensitive.setOnCheckedChangeListener((buttonView, isChecked) -> isSensitive = isChecked);
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
toot_visibility.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tootVisibilityDialog();
toot_visibility.setOnClickListener(v -> tootVisibilityDialog());
toot_it.setOnClickListener(v -> sendToot(null));
pickup_picture.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(PixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PixelfedComposeActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
Intent intent;
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
String[] mimetypes = {"image/*", "video/*", "audio/mpeg", "audio/opus", "audio/flac", "audio/wav", "audio/ogg"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMAGE);
} else {
intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE);
}
});
toot_it.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendToot(null);
upload_media.setOnClickListener(v -> {
if (ContextCompat.checkSelfPermission(PixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PixelfedComposeActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
});
pickup_picture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(PixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PixelfedComposeActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
Intent intent;
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
String[] mimetypes = {"image/*", "video/*", "audio/mpeg", "audio/opus", "audio/flac", "audio/wav", "audio/ogg"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMAGE);
} else {
intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE);
}
Intent intent;
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
String[] mimetypes = {"image/*", "video/*", "audio/mpeg", "audio/opus", "audio/flac", "audio/wav", "audio/ogg"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMAGE);
} else {
intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE);
}
});
upload_media.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(PixelfedComposeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PixelfedComposeActivity.this,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
Intent intent;
intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
String[] mimetypes = {"image/*", "video/*", "audio/mpeg", "audio/opus", "audio/flac", "audio/wav", "audio/ogg"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
startActivityForResult(intent, PICK_IMAGE);
} else {
intent.setType("image/* video/* audio/mpeg audio/opus audio/flac audio/wav audio/ogg");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.toot_select_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, PICK_IMAGE);
}
}
});
@ -1184,7 +1136,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
}
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PixelfedComposeActivity.this, style);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.datetime_picker, null);
View dialogView = inflater.inflate(R.layout.datetime_picker, new LinearLayout(PixelfedComposeActivity.this), false);
dialogBuilder.setView(dialogView);
final AlertDialog alertDialog = dialogBuilder.create();
@ -1198,74 +1150,54 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
final ImageButton date_time_set = dialogView.findViewById(R.id.date_time_set);
//Buttons management
date_time_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
date_time_cancel.setOnClickListener(v -> alertDialog.dismiss());
date_time_next.setOnClickListener(v -> {
datePicker.setVisibility(View.GONE);
timePicker.setVisibility(View.VISIBLE);
date_time_previous.setVisibility(View.VISIBLE);
date_time_next.setVisibility(View.GONE);
date_time_set.setVisibility(View.VISIBLE);
});
date_time_next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
datePicker.setVisibility(View.GONE);
timePicker.setVisibility(View.VISIBLE);
date_time_previous.setVisibility(View.VISIBLE);
date_time_next.setVisibility(View.GONE);
date_time_set.setVisibility(View.VISIBLE);
}
date_time_previous.setOnClickListener(v -> {
datePicker.setVisibility(View.VISIBLE);
timePicker.setVisibility(View.GONE);
date_time_previous.setVisibility(View.GONE);
date_time_next.setVisibility(View.VISIBLE);
date_time_set.setVisibility(View.GONE);
});
date_time_previous.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
datePicker.setVisibility(View.VISIBLE);
timePicker.setVisibility(View.GONE);
date_time_previous.setVisibility(View.GONE);
date_time_next.setVisibility(View.VISIBLE);
date_time_set.setVisibility(View.GONE);
date_time_set.setOnClickListener(v -> {
int hour, minute;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
hour = timePicker.getHour();
minute = timePicker.getMinute();
} else {
hour = timePicker.getCurrentHour();
minute = timePicker.getCurrentMinute();
}
});
date_time_set.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int hour, minute;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
hour = timePicker.getHour();
minute = timePicker.getMinute();
} else {
hour = timePicker.getCurrentHour();
minute = timePicker.getCurrentMinute();
}
Calendar calendar = new GregorianCalendar(datePicker.getYear(),
datePicker.getMonth(),
datePicker.getDayOfMonth(),
hour,
minute);
final long[] time = {calendar.getTimeInMillis()};
Calendar calendar = new GregorianCalendar(datePicker.getYear(),
datePicker.getMonth(),
datePicker.getDayOfMonth(),
hour,
minute);
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();
} else {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PixelfedComposeActivity.this, style);
builderSingle.setTitle(getString(R.string.choose_schedule));
builderSingle.setNegativeButton(R.string.device_schedule, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
deviceSchedule(time[0]);
dialog.dismiss();
}
});
builderSingle.setPositiveButton(R.string.server_schedule, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
int offset = TimeZone.getDefault().getRawOffset();
calendar.add(Calendar.MILLISECOND, -offset);
final String date = Helper.dateToString(new Date(calendar.getTimeInMillis()));
serverSchedule(date);
}
});
builderSingle.show();
alertDialog.dismiss();
}
if ((time[0] - new Date().getTime()) < 60000) {
Toasty.warning(PixelfedComposeActivity.this, getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show();
} else {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(PixelfedComposeActivity.this, style);
builderSingle.setTitle(getString(R.string.choose_schedule));
builderSingle.setNegativeButton(R.string.device_schedule, (dialog, which) -> {
deviceSchedule(time[0]);
dialog.dismiss();
});
builderSingle.setPositiveButton(R.string.server_schedule, (dialog, which) -> {
int offset = TimeZone.getDefault().getRawOffset();
calendar.add(Calendar.MILLISECOND, -offset);
final String date = Helper.dateToString(new Date(calendar.getTimeInMillis()));
serverSchedule(date);
});
builderSingle.show();
alertDialog.dismiss();
}
});
alertDialog.show();
@ -1336,8 +1268,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
if (namebar != null && namebar.getParent() != null)
((ViewGroup) namebar.getParent()).removeView(namebar);
}
List<Attachment> tmp_attachment = new ArrayList<>();
tmp_attachment.addAll(attachments);
List<Attachment> tmp_attachment = new ArrayList<>(attachments);
attachments.removeAll(tmp_attachment);
tmp_attachment.clear();
}
@ -1413,36 +1344,28 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
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);
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
dialog.dismiss();
dialog.setNegativeButton(R.string.cancel, (dialog12, position) -> dialog12.dismiss());
dialog.setAdapter(arrayAdapter, (dialog1, position) -> {
switch (position) {
case 0:
visibility = "public";
toot_visibility.setImageResource(R.drawable.ic_public_toot);
break;
case 1:
visibility = "unlisted";
toot_visibility.setImageResource(R.drawable.ic_lock_open_toot);
break;
case 2:
visibility = "private";
toot_visibility.setImageResource(R.drawable.ic_lock_outline_toot);
break;
case 3:
visibility = "direct";
toot_visibility.setImageResource(R.drawable.ic_mail_outline_toot);
break;
}
});
dialog.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int position) {
switch (position) {
case 0:
visibility = "public";
toot_visibility.setImageResource(R.drawable.ic_public_toot);
break;
case 1:
visibility = "unlisted";
toot_visibility.setImageResource(R.drawable.ic_lock_open_toot);
break;
case 2:
visibility = "private";
toot_visibility.setImageResource(R.drawable.ic_lock_outline_toot);
break;
case 3:
visibility = "direct";
toot_visibility.setImageResource(R.drawable.ic_mail_outline_toot);
break;
}
dialog.dismiss();
}
dialog1.dismiss();
});
dialog.show();
}
@ -1478,24 +1401,18 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
} else {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PixelfedComposeActivity.this, style);
dialogBuilder.setMessage(R.string.save_draft);
dialogBuilder.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (accountReply == null) {
storeToot(true, false);
} else {
storeToot(false, false);
}
dialog.dismiss();
finish();
dialogBuilder.setPositiveButton(R.string.save, (dialog, id) -> {
if (accountReply == null) {
storeToot(true, false);
} else {
storeToot(false, false);
}
dialog.dismiss();
finish();
});
dialogBuilder.setNegativeButton(R.string.discard, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
finish();
}
dialogBuilder.setNegativeButton(R.string.discard, (dialog, id) -> {
dialog.dismiss();
finish();
});
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.setCancelable(false);
@ -1549,8 +1466,7 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
if (namebar != null && namebar.getParent() != null)
((ViewGroup) namebar.getParent()).removeView(namebar);
}
List<Attachment> tmp_attachment = new ArrayList<>();
tmp_attachment.addAll(attachments);
List<Attachment> tmp_attachment = new ArrayList<>(attachments);
attachments.removeAll(tmp_attachment);
tmp_attachment.clear();
}
@ -1597,37 +1513,34 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
String[] searchA = oldContent.substring(0, currentCursorPosition).split("@");
if (searchA.length > 0) {
final String search = searchA[searchA.length - 1];
toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Account account = accounts.get(position);
String deltaSearch = "";
int searchLength = searchDeep;
if (currentCursorPosition < searchDeep) { //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
else {
if (currentCursorPosition >= oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
}
if (!search.equals(""))
deltaSearch = deltaSearch.replace("@" + search, "");
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
newContent += deltaSearch;
newContent += "@" + account.getAcct() + " ";
int newPosition = newContent.length();
if (currentCursorPosition < oldContent.length())
newContent += oldContent.substring(currentCursorPosition);
toot_content.setText(newContent);
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
toot_content.setSelection(newPosition);
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(PixelfedComposeActivity.this, new ArrayList<>());
toot_content.setThreshold(1);
toot_content.setAdapter(accountsListAdapter);
toot_content.setOnItemClickListener((parent, view, position, id) -> {
Account account = accounts.get(position);
String deltaSearch = "";
int searchLength = searchDeep;
if (currentCursorPosition < searchDeep) { //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
else {
if (currentCursorPosition >= oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
}
if (!search.equals(""))
deltaSearch = deltaSearch.replace("@" + search, "");
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
newContent += deltaSearch;
newContent += "@" + account.getAcct() + " ";
int newPosition = newContent.length();
if (currentCursorPosition < oldContent.length())
newContent += oldContent.substring(currentCursorPosition);
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<>());
toot_content.setThreshold(1);
toot_content.setAdapter(accountsListAdapter1);
});
}
}
@ -1664,38 +1577,35 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
String[] searchA = oldContent.substring(0, currentCursorPosition).split(":");
if (searchA.length > 0) {
final String search = searchA[searchA.length - 1];
toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String shortcode = emojis.get(position).getShortcode();
String deltaSearch = "";
int searchLength = searchDeep;
if (currentCursorPosition < searchDeep) { //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
else {
if (currentCursorPosition >= oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
}
if (!search.equals(""))
deltaSearch = deltaSearch.replace(":" + search, "");
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
newContent += deltaSearch;
newContent += ":" + shortcode + ": ";
int newPosition = newContent.length();
if (currentCursorPosition < oldContent.length())
newContent += oldContent.substring(currentCursorPosition);
toot_content.setText(newContent);
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
toot_content.setSelection(newPosition);
EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(PixelfedComposeActivity.this, new ArrayList<>());
toot_content.setThreshold(1);
toot_content.setAdapter(emojisSearchAdapter);
toot_content.setOnItemClickListener((parent, view, position, id) -> {
String shortcode = emojis.get(position).getShortcode();
String deltaSearch = "";
int searchLength = searchDeep;
if (currentCursorPosition < searchDeep) { //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
else {
if (currentCursorPosition >= oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
}
if (!search.equals(""))
deltaSearch = deltaSearch.replace(":" + search, "");
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
newContent += deltaSearch;
newContent += ":" + shortcode + ": ";
int newPosition = newContent.length();
if (currentCursorPosition < oldContent.length())
newContent += oldContent.substring(currentCursorPosition);
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<>());
toot_content.setThreshold(1);
toot_content.setAdapter(emojisSearchAdapter1);
});
}
}
@ -1725,40 +1635,37 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
if (searchA.length < 1)
return;
final String search = searchA[searchA.length - 1];
toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position >= tags.size())
return;
String tag = tags.get(position);
String deltaSearch = "";
int searchLength = searchDeep;
if (currentCursorPosition < searchDeep) { //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
else {
if (currentCursorPosition >= oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
}
if (!search.equals(""))
deltaSearch = deltaSearch.replace("#" + search, "");
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
newContent += deltaSearch;
newContent += "#" + tag + " ";
int newPosition = newContent.length();
if (currentCursorPosition < oldContent.length())
newContent += oldContent.substring(currentCursorPosition);
toot_content.setText(newContent);
toot_space_left.setText(String.valueOf(countLength(social, toot_content)));
toot_content.setSelection(newPosition);
TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(PixelfedComposeActivity.this, new ArrayList<>());
toot_content.setThreshold(1);
toot_content.setAdapter(tagsSearchAdapter);
toot_content.setOnItemClickListener((parent, view, position, id) -> {
if (position >= tags.size())
return;
String tag = tags.get(position);
String deltaSearch = "";
int searchLength = searchDeep;
if (currentCursorPosition < searchDeep) { //Less than 15 characters are written before the cursor position
searchLength = currentCursorPosition;
}
if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
else {
if (currentCursorPosition >= oldContent.length())
deltaSearch = oldContent.substring(currentCursorPosition - searchLength);
}
if (!search.equals(""))
deltaSearch = deltaSearch.replace("#" + search, "");
String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
newContent += deltaSearch;
newContent += "#" + tag + " ";
int newPosition = newContent.length();
if (currentCursorPosition < oldContent.length())
newContent += oldContent.substring(currentCursorPosition);
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<>());
toot_content.setThreshold(1);
toot_content.setAdapter(tagsSearchAdapter1);
});
}
}
@ -1776,10 +1683,9 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
restored = id;
attachments = status.getMedia_attachments();
ArrayList<ImageView> toRemove = new ArrayList<>();
String content = status.getContent();
Pattern mentionLink = Pattern.compile("(<\\s?a\\s?href=\"https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/(@[\\/\\w._-]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)");
Pattern mentionLink = Pattern.compile("(<\\s?a\\s?href=\"https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[/\\w._-]*)\"\\s?[^.]*<\\s?/\\s?a\\s?>)");
Matcher matcher = mentionLink.matcher(content);
if (matcher.find()) {
content = matcher.replaceAll("$3@$2");
@ -1870,10 +1776,8 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
private void restoreServerSchedule(Status status) {
attachments = status.getMedia_attachments();
ArrayList<ImageView> toRemove = new ArrayList<>();
String content = status.getContent();
Pattern mentionLink = Pattern.compile("(<\\s?a\\s?href=\"https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/(@[\\/\\w._-]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)");
Pattern mentionLink = Pattern.compile("(<\\s?a\\s?href=\"https?://([\\da-z.-]+\\.[a-z.]{2,10})/(@[/\\w._-]*)\"\\s?[^.]*<\\s?/\\s?a\\s?>)");
Matcher matcher = mentionLink.matcher(content);
if (matcher.find()) {
content = matcher.replaceAll("$3@$2");
@ -1885,7 +1789,6 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
content = Html.fromHtml(content).toString();
}
if (attachments != null && attachments.size() > 0) {
int i = 0;
for (final Attachment attachment : attachments) {
String url = attachment.getPreview_url();
if (url == null || url.trim().equals(""))
@ -1910,17 +1813,10 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
});
imageView.setTag(attachment.getId());
imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
return false;
}
});
imageView.setOnLongClickListener(view -> false);
if (attachments.size() < max_media_count)
upload_media.setEnabled(true);
toot_sensitive.setVisibility(View.VISIBLE);
i++;
}
} else {
imageSlider.setVisibility(View.GONE);
@ -2025,7 +1921,6 @@ public class PixelfedComposeActivity extends BaseActivity implements UploadStatu
boolean error = false;
UploadServiceSingleBroadcastReceiver uploadReceiver;
String filename;
UpdateAccountInfoAsyncTask.SOCIAL social;
boolean pixelfedStory;
asyncPicture(Activity activity, boolean pixelfedStory, Uri uri, String filename, UploadServiceSingleBroadcastReceiver uploadReceiver) {