diff --git a/app/build.gradle b/app/build.gradle index 17d0c36f3..52bcaebc8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -69,41 +69,28 @@ task gitPushReleaseNotes(type: Exec, dependsOn: 'copyAllReleaseNotes') { ['sh', '-c', "git push"].execute().text.trim() } -ext.supportLibraryVersion = '29.0.2' -ext.glideLibraryVersion = '4.9.0' -ext.conscryptLibraryVersion = '2.2.1' -ext.evernoteLibraryVersion = '1.2.6' -ext.gsonLibraryVersion = '2.8.2' -ext.guavaLibraryVersion = '28.2-android' -ext.photoViewLibraryVersion = '2.3.0' -ext.ratethisappLibraryVersion = '1.2.0' -ext.uploadServiceVersion = "3.5.2" -ext.torrentstreamVersion = "2.5.0" -ext.netCipherVersion = "2.0.0-alpha1" -ext.acraVersion = "5.4.0" dependencies { - implementation 'com.android.support:appcompat-v7:29.0.2' implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.0.0' + implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.browser:browser:1.2.0' implementation 'androidx.exifinterface:exifinterface:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' - implementation "com.github.bumptech.glide:glide:$glideLibraryVersion" - implementation ("com.github.bumptech.glide:recyclerview-integration:$glideLibraryVersion") { + implementation "com.github.bumptech.glide:glide:4.11.0" + implementation ("com.github.bumptech.glide:recyclerview-integration:4.11.0") { // Excludes the support library because it's already included by Glide. transitive = false } - annotationProcessor "com.github.bumptech.glide:compiler:$glideLibraryVersion" + annotationProcessor "com.github.bumptech.glide:compiler:4.11.0" annotationProcessor 'com.android.support:support-annotations:28.0.0' - implementation "org.conscrypt:conscrypt-android:$conscryptLibraryVersion" - implementation "com.evernote:android-job:$evernoteLibraryVersion" - implementation "com.google.code.gson:gson:$gsonLibraryVersion" - implementation "com.google.guava:guava:$guavaLibraryVersion" - implementation "com.github.chrisbanes:PhotoView:$photoViewLibraryVersion" + implementation "org.conscrypt:conscrypt-android:2.2.1" + implementation "com.evernote:android-job:1.2.6" + implementation "com.google.code.gson:gson:2.8.5" + implementation "com.google.guava:guava:28.2-android" + implementation "com.github.chrisbanes:PhotoView:2.3.0" implementation 'com.r0adkll:slidableactivity:2.1.0' implementation 'com.github.stom79:country-picker-android:1.2.0' implementation 'com.github.stom79:mytransl:2.0' @@ -121,21 +108,21 @@ dependencies { implementation "com.tonyodev.fetch2:fetch2:2.3.6" implementation 'com.github.stom79:horizontalbargraph:1.6' implementation 'jp.wasabeef:glide-transformations:4.0.0' - playstoreImplementation "io.github.kobakei:ratethisapp:$ratethisappLibraryVersion" + playstoreImplementation "io.github.kobakei:ratethisapp:1.2.0" implementation 'ja.burhanrashid52:photoeditor:0.4.0' api 'com.theartofdev.edmodo:android-image-cropper:2.8.+' - implementation "net.gotev:uploadservice:$uploadServiceVersion" - implementation "net.gotev:uploadservice-okhttp:$uploadServiceVersion" - implementation "info.guardianproject.netcipher:netcipher:$netCipherVersion" - implementation "info.guardianproject.netcipher:netcipher-okhttp3:$netCipherVersion" + implementation "net.gotev:uploadservice:3.5.2" + implementation "net.gotev:uploadservice-okhttp:3.5.2" + implementation "info.guardianproject.netcipher:netcipher:2.0.0-alpha1" + implementation "info.guardianproject.netcipher:netcipher-okhttp3:2.0.0-alpha1" implementation 'com.github.adrielcafe:AndroidAudioRecorder:0.3.0' implementation 'yogesh.firzen:MukkiyaSevaigal:1.0.6' implementation 'com.iceteck.silicompressorr:silicompressor:2.2.2' - implementation "ch.acra:acra-mail:$acraVersion" - implementation "ch.acra:acra-limiter:$acraVersion" - implementation "ch.acra:acra-notification:$acraVersion" + implementation "ch.acra:acra-mail:5.4.0" + implementation "ch.acra:acra-limiter:5.4.0" + implementation "ch.acra:acra-notification:5.4.0" implementation 'com.github.stom79:Android-WYSIWYG-Editor:3.2.1' implementation 'com.github.duanhong169:colorpicker:1.1.6' implementation 'com.github.penfeizhou.android.animation:apng:1.1.0' diff --git a/app/src/main/assets/changelogs/350.txt b/app/src/main/assets/changelogs/350.txt index 6f838f0a0..42668d30b 100644 --- a/app/src/main/assets/changelogs/350.txt +++ b/app/src/main/assets/changelogs/350.txt @@ -1,13 +1,5 @@ -Added: -- CatalĂ  language -- Push notifications for Friendica & GNU Social -- Add follow/unfollow buttons for Pixelfed -- View your own story (need to wait the endpoint) -- Increase max bio chars to 500 for Pleroma + Fixed: -- Proxy not applied with embedded videos -- Fix no toots that remains displayed on Nitter timelines -- Avoid to lose composed message when not sent -- Notifications not pushed -- Fix some crashes \ No newline at end of file +- Peertube videos crashes +- Color of the compose menu for the light theme \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index 81a6e58cc..4f4ef845f 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -584,7 +584,11 @@ public class API { }else { status.setUri(resobj.get("id").toString()); } - status.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString())); + if( resobj.has("created_at")) { + status.setCreated_at(Helper.mstStringToDate(context, resobj.get("created_at").toString())); + }else{ + status.setCreated_at(new Date()); + } status.setIn_reply_to_id(resobj.get("in_reply_to_id").toString()); status.setIn_reply_to_account_id(resobj.get("in_reply_to_account_id").toString()); status.setSensitive(Boolean.parseBoolean(resobj.get("sensitive").toString())); diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java index c9cf02145..3d6e82292 100644 --- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java @@ -31,9 +31,7 @@ import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.CountDownTimer; -import android.os.Environment; import android.os.Handler; -import android.os.Looper; import android.text.Html; import android.text.InputType; import android.text.Spannable; @@ -53,10 +51,8 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; -import android.webkit.URLUtil; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; @@ -111,7 +107,6 @@ import java.util.Iterator; import java.util.List; import java.util.Timer; import java.util.TimerTask; -import java.util.concurrent.ExecutionException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -151,7 +146,6 @@ import app.fedilab.android.client.Entities.Relationship; import app.fedilab.android.client.Entities.Status; import app.fedilab.android.client.Entities.StoredStatus; import app.fedilab.android.client.Entities.TagTimeline; -import app.fedilab.android.client.Glide.GlideApp; import app.fedilab.android.fragments.DisplayStatusFragment; import app.fedilab.android.helper.CrossActions; import app.fedilab.android.helper.CustomTextView; @@ -198,9 +192,9 @@ import static app.fedilab.android.activities.BaseMainActivity.social; */ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostActionInterface, OnRetrieveFeedsInterface, OnRetrieveImageInterface, OnRetrieveEmojiInterface, OnRetrieveRepliesInterface, OnRetrieveCardInterface, OnPollInterface, OnRefreshCachedStatusInterface, OnRetrieveSearcAccountshInterface, OnRetrieveSearchInterface, OnPostStatusActionInterface, OnRetrieveRelationshipQuickReplyInterface { - public static final int HIDDEN_STATUS = 0; + private static final int HIDDEN_STATUS = 0; public static final int DISPLAYED_STATUS = 1; - public static final int FOCUSED_STATUS = 2; + private static final int FOCUSED_STATUS = 2; public static final int COMPACT_STATUS = 3; public static final int CONSOLE_STATUS = 4; public static boolean fetch_all_more = false; @@ -224,7 +218,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct private String in_reply_to_status; private TextView warning_message; private Status tootReply; - private long currentToId = -1; + private long currentToId; private RecyclerView mRecyclerView; private List lstHolders; private List emojisPicker; @@ -409,36 +403,33 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct 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 = 15; - if (currentCursorPosition < 15) { //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(TootActivity.countLength(social, toot_content, toot_cw_content))); - toot_content.setSelection(newPosition); - AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(context, 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 = 15; + if (currentCursorPosition < 15) { //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(TootActivity.countLength(social, toot_content, toot_cw_content))); + toot_content.setSelection(newPosition); + AccountsSearchAdapter accountsListAdapter1 = new AccountsSearchAdapter(context, new ArrayList<>()); + toot_content.setThreshold(1); + toot_content.setAdapter(accountsListAdapter1); }); } } @@ -462,37 +453,34 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct final String oldContent = toot_content.getText().toString(); String[] searchA = oldContent.substring(0, currentCursorPosition).split(":"); 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 = 15; - if (currentCursorPosition < 15) { //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(TootActivity.countLength(social, toot_content, toot_cw_content))); - toot_content.setSelection(newPosition); - EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(context, 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 = 15; + if (currentCursorPosition < 15) { //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(TootActivity.countLength(social, toot_content, toot_cw_content))); + toot_content.setSelection(newPosition); + EmojisSearchAdapter emojisSearchAdapter1 = new EmojisSearchAdapter(context, new ArrayList<>()); + toot_content.setThreshold(1); + toot_content.setAdapter(emojisSearchAdapter1); }); } } @@ -517,39 +505,36 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct 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 = 15; - if (currentCursorPosition < 15) { //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(TootActivity.countLength(social, toot_content, toot_cw_content))); - toot_content.setSelection(newPosition); - TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(context, 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 = 15; + if (currentCursorPosition < 15) { //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(TootActivity.countLength(social, toot_content, toot_cw_content))); + toot_content.setSelection(newPosition); + TagsSearchAdapter tagsSearchAdapter1 = new TagsSearchAdapter(context, new ArrayList<>()); + toot_content.setThreshold(1); + toot_content.setAdapter(tagsSearchAdapter1); }); } } @@ -882,52 +867,44 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.single_choice.setVisibility(View.VISIBLE); } holder.submit_vote.setVisibility(View.VISIBLE); - holder.submit_vote.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - int[] choice; - if (poll.isMultiple()) { - ArrayList choices = new ArrayList<>(); - int choicesCount = holder.multiple_choice.getChildCount(); - for (int i = 0; i < choicesCount; i++) { - if (holder.multiple_choice.getChildAt(i) != null && holder.multiple_choice.getChildAt(i) instanceof CheckBox) { - if (((CheckBox) holder.multiple_choice.getChildAt(i)).isChecked()) { - choices.add(i); - } + holder.submit_vote.setOnClickListener(v -> { + int[] choice; + if (poll.isMultiple()) { + ArrayList choices = new ArrayList<>(); + int choicesCount = holder.multiple_choice.getChildCount(); + for (int i1 = 0; i1 < choicesCount; i1++) { + if (holder.multiple_choice.getChildAt(i1) != null && holder.multiple_choice.getChildAt(i1) instanceof CheckBox) { + if (((CheckBox) holder.multiple_choice.getChildAt(i1)).isChecked()) { + choices.add(i1); } } - choice = new int[choices.size()]; - Iterator iterator = choices.iterator(); - for (int i = 0; i < choice.length; i++) { - choice[i] = iterator.next().intValue(); - } - if (choice.length == 0) - return; - } else { - choice = new int[1]; - choice[0] = -1; - int choicesCount = holder.radio_group.getChildCount(); - for (int i = 0; i < choicesCount; i++) { - if (holder.radio_group.getChildAt(i) != null && holder.radio_group.getChildAt(i) instanceof RadioButton) { - if (((RadioButton) holder.radio_group.getChildAt(i)).isChecked()) { - choice[0] = i; - } - } - } - if (choice[0] == -1) - return; } - new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.SUBMIT, status, choice, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + choice = new int[choices.size()]; + Iterator iterator = choices.iterator(); + for (int i1 = 0; i1 < choice.length; i1++) { + choice[i1] = iterator.next(); + } + if (choice.length == 0) + return; + } else { + choice = new int[1]; + choice[0] = -1; + int choicesCount = holder.radio_group.getChildCount(); + for (int i1 = 0; i1 < choicesCount; i1++) { + if (holder.radio_group.getChildAt(i1) != null && holder.radio_group.getChildAt(i1) instanceof RadioButton) { + if (((RadioButton) holder.radio_group.getChildAt(i1)).isChecked()) { + choice[0] = i1; + } + } + } + if (choice[0] == -1) + return; } + new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.SUBMIT, status, choice, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }); } - holder.refresh_poll.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.REFRESH, status, null, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - }); + holder.refresh_poll.setOnClickListener(v -> new ManagePollAsyncTask(context, ManagePollAsyncTask.type_s.REFRESH, status, null, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)); holder.poll_container.setVisibility(View.VISIBLE); holder.number_votes.setText(context.getResources().getQuantityString(R.plurals.number_of_voters, poll.getVoters_count(), poll.getVoters_count())); if( poll.isExpired()){ @@ -943,80 +920,57 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { holder.status_action_container.setVisibility(View.GONE); holder.status_peertube_container.setVisibility(View.VISIBLE); - holder.status_peertube_reply.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AlertDialog.Builder builderInner; - int style; - if (theme == Helper.THEME_DARK) { - style = R.style.DialogDark; - } else if (theme == Helper.THEME_BLACK) { - style = R.style.DialogDark; - } else { - style = R.style.Dialog; - } - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(R.string.comment); - EditText input = new EditText(context); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - 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) { - 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(context, PeertubeActivity.video_id, comment, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - dialog.dismiss(); - } - } - }); - builderInner.show(); + holder.status_peertube_reply.setOnClickListener(v -> { + AlertDialog.Builder builderInner; + int style; + if (theme == Helper.THEME_DARK) { + style = R.style.DialogDark; + } else if (theme == Helper.THEME_BLACK) { + style = R.style.DialogDark; + } else { + style = R.style.Dialog; } + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(R.string.comment); + EditText input = new EditText(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + builderInner.setView(input); + 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(context, PeertubeActivity.video_id, comment, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + dialog.dismiss(); + } + }); + builderInner.show(); }); if (status.getAccount().getId().equals(userId)) holder.status_peertube_delete.setVisibility(View.VISIBLE); else holder.status_peertube_delete.setVisibility(View.GONE); - holder.status_peertube_delete.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AlertDialog.Builder builderInner; - 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(context, style); - builderInner.setTitle(R.string.delete_comment); - builderInner.setMessage(R.string.delete_comment_confirm); - 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(context, API.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, null, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - dialog.dismiss(); - } - }); - builderInner.show(); + holder.status_peertube_delete.setOnClickListener(v -> { + AlertDialog.Builder builderInner; + 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(context, style); + builderInner.setTitle(R.string.delete_comment); + builderInner.setMessage(R.string.delete_comment_confirm); + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { + new PostActionAsyncTask(context, API.StatusAction.PEERTUBEDELETECOMMENT, PeertubeActivity.video_id, null, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + dialog.dismiss(); + }); + builderInner.show(); }); } @@ -1038,22 +992,15 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct int paddingPixel = 15; float density = context.getResources().getDisplayMetrics().density; int paddingDp = (int) (paddingPixel * density); - builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); + builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); builder.setTitle(R.string.insert_emoji); if (emojisPicker != null && emojisPicker.size() > 0) { GridView gridView = new GridView(context); gridView.setAdapter(new CustomEmojiAdapter(emojisPicker)); gridView.setNumColumns(5); - gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - holder.quick_reply_text.getText().insert(holder.quick_reply_text.getSelectionStart(), " :" + emojisPicker.get(position).getShortcode() + ": "); - alertDialogEmoji.dismiss(); - } + gridView.setOnItemClickListener((parent, view1, position, id) -> { + holder.quick_reply_text.getText().insert(holder.quick_reply_text.getSelectionStart(), " :" + emojisPicker.get(position).getShortcode() + ": "); + alertDialogEmoji.dismiss(); }); gridView.setPadding(paddingDp, paddingDp, paddingDp, paddingDp); builder.setView(gridView); @@ -1073,30 +1020,30 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.new_element.setVisibility(View.GONE); - holder.status_reply.getLayoutParams().height = (int) Helper.convertDpToPixel((20 * iconSizePercent / 100), context); - holder.status_reply.getLayoutParams().width = (int) Helper.convertDpToPixel((20 * iconSizePercent / 100), context); - holder.status_more.getLayoutParams().height = (int) Helper.convertDpToPixel((20 * iconSizePercent / 100), context); - holder.status_more.getLayoutParams().width = (int) Helper.convertDpToPixel((20 * iconSizePercent / 100), context); - holder.status_privacy.getLayoutParams().height = (int) Helper.convertDpToPixel((20 * iconSizePercent / 100), context); - holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel((20 * iconSizePercent / 100), context); + holder.status_reply.getLayoutParams().height = (int) Helper.convertDpToPixel(((float)(20 * iconSizePercent) / 100), context); + holder.status_reply.getLayoutParams().width = (int) Helper.convertDpToPixel(((float)(20 * iconSizePercent) / 100), context); + holder.status_more.getLayoutParams().height = (int) Helper.convertDpToPixel(((float)(20 * iconSizePercent) / 100), context); + holder.status_more.getLayoutParams().width = (int) Helper.convertDpToPixel(((float)(20 * iconSizePercent) / 100), context); + holder.status_privacy.getLayoutParams().height = (int) Helper.convertDpToPixel(((float)(20 * iconSizePercent) / 100), context); + holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel(((float)(20 * iconSizePercent) / 100), context); if (getItemViewType(viewHolder.getAdapterPosition()) == FOCUSED_STATUS) { - holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16 * textSizePercent / 100); - holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16 * textSizePercent / 100); - holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100); - holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100); - holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16 * textSizePercent / 100); + holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(16 * textSizePercent) / 100); + holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(16 * textSizePercent) / 100); + holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(14 * textSizePercent) / 100); + holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(14 * textSizePercent) / 100); + holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(16 * textSizePercent) / 100); } else { - holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100); - holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12 * textSizePercent / 100); - holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100); - holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12 * textSizePercent / 100); - holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100); + holder.status_account_displayname.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(14 * textSizePercent) / 100); + holder.status_account_username.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(12 * textSizePercent) / 100); + holder.status_content.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(14 * textSizePercent) / 100); + holder.status_toot_date.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(12 * textSizePercent) / 100); + holder.status_content_translated.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(14 * textSizePercent) / 100); } boolean disableAnimatedEmoji = sharedpreferences.getBoolean(Helper.SET_DISABLE_ANIMATED_EMOJI, false); - holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14 * textSizePercent / 100); + holder.status_spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, (float)(14 * textSizePercent) / 100); switch (translator) { case Helper.TRANS_NONE: @@ -1179,12 +1126,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } else { holder.cached_status.setVisibility(View.GONE); } - holder.cached_status.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - new ManageCachedStatusAsyncTask(context, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - }); + holder.cached_status.setOnClickListener(v -> new ManageCachedStatusAsyncTask(context, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)); } if (holder.fedilab_features != null && !fedilab_features_button) @@ -1192,14 +1134,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if (holder.fedilab_features != null && fedilab_features_button) { TooltipCompat.setTooltipText(holder.fedilab_features, context.getString(R.string.app_features)); - holder.fedilab_features.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - boolean state = status.isCustomFeaturesDisplayed(); - closePanels(); - status.setCustomFeaturesDisplayed(!state); - notifyStatusChanged(status); - } + holder.fedilab_features.setOnClickListener(v -> { + boolean state = status.isCustomFeaturesDisplayed(); + closePanels(); + status.setCustomFeaturesDisplayed(!state); + notifyStatusChanged(status); }); @@ -1298,11 +1237,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.spark_button_reblog.setInActiveImageTintColor(iconColor); holder.spark_button_fav.setColors(R.color.marked_icon, R.color.marked_icon); holder.spark_button_fav.setImageSize((int) (20 * iconSizePercent / 100 * scale + 0.5f)); - holder.spark_button_fav.setMinimumWidth((int) Helper.convertDpToPixel((20 * iconSizePercent / 100 * scale + 0.5f), context)); + holder.spark_button_fav.setMinimumWidth((int) Helper.convertDpToPixel(((float) (20 * iconSizePercent) / 100 * scale + 0.5f), context)); holder.spark_button_reblog.setColors(R.color.boost_icon, R.color.boost_icon); holder.spark_button_reblog.setImageSize((int) (20 * iconSizePercent / 100 * scale + 0.5f)); - holder.spark_button_reblog.setMinimumWidth((int) Helper.convertDpToPixel((20 * iconSizePercent / 100 * scale + 0.5f), context)); + holder.spark_button_reblog.setMinimumWidth((int) Helper.convertDpToPixel(((float)(20 * iconSizePercent) / 100 * scale + 0.5f), context)); Drawable imgConversation = null; if( social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) { @@ -1374,7 +1313,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); else - //noinspection deprecation contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString(); extra_text += contentToot; sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text); @@ -1385,82 +1323,65 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } } - holder.status_content.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) { - try { - view.requestFocus(); - } catch (Exception ignored) { - } + holder.status_content.setOnTouchListener((view, motionEvent) -> { + if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) { + try { + view.requestFocus(); + } catch (Exception ignored) { } - return false; } + return false; }); - holder.status_spoiler.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) { - try { - view.requestFocus(); - } catch (Exception ignored) { - } + holder.status_spoiler.setOnTouchListener((view, motionEvent) -> { + if (motionEvent.getAction() == MotionEvent.ACTION_UP && !view.hasFocus()) { + try { + view.requestFocus(); + } catch (Exception ignored) { } - return false; } + return false; }); //Click on a conversation if (( instanceType == null || instanceType.compareTo("NITTER") != 0) && (getItemViewType(viewHolder.getAdapterPosition()) == DISPLAYED_STATUS || getItemViewType(viewHolder.getAdapterPosition()) == COMPACT_STATUS || getItemViewType(viewHolder.getAdapterPosition()) == CONSOLE_STATUS)) { - holder.status_spoiler.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS) { - Intent intent = new Intent(context, ShowConversationActivity.class); - int position = closePanels(); - /* if( holder.getAdapterPosition() == position && type == RetrieveFeedsAsyncTask.Type.CONTEXT) - return;*/ - Bundle b = new Bundle(); - if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - b.putString("conversationId", status.getConversationId()); - if (status.getReblog() == null) - b.putParcelable("status", status); - else - b.putParcelable("status", status.getReblog()); - intent.putExtras(b); - if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) - ((Activity) context).finish(); - context.startActivity(intent); - } else { - if (social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) - CrossActions.doCrossConversation(context, status); - } + holder.status_spoiler.setOnClickListener(v -> { + if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS) { + Intent intent = new Intent(context, ShowConversationActivity.class); + int position = closePanels(); + Bundle b = new Bundle(); + if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) + b.putString("conversationId", status.getConversationId()); + if (status.getReblog() == null) + b.putParcelable("status", status); + else + b.putParcelable("status", status.getReblog()); + intent.putExtras(b); + if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) + ((Activity) context).finish(); + context.startActivity(intent); + } else { + if (social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) + CrossActions.doCrossConversation(context, status); } }); - holder.status_content.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS) { - Intent intent = new Intent(context, ShowConversationActivity.class); - int position = closePanels(); - /* if( holder.getAdapterPosition() == position && type == RetrieveFeedsAsyncTask.Type.CONTEXT) - return;*/ - Bundle b = new Bundle(); - if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) - b.putString("conversationId", status.getConversationId()); - if (status.getReblog() == null) - b.putParcelable("status", status); - else - b.putParcelable("status", status.getReblog()); - intent.putExtras(b); - if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) - ((Activity) context).finish(); - context.startActivity(intent); - } else { - if (social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) - CrossActions.doCrossConversation(context, status); - } + holder.status_content.setOnClickListener(v -> { + if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS) { + Intent intent = new Intent(context, ShowConversationActivity.class); + Bundle b = new Bundle(); + if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) + b.putString("conversationId", status.getConversationId()); + if (status.getReblog() == null) + b.putParcelable("status", status); + else + b.putParcelable("status", status.getReblog()); + intent.putExtras(b); + if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) + ((Activity) context).finish(); + context.startActivity(intent); + } else { + if (social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) + CrossActions.doCrossConversation(context, status); } }); holder.main_container.setOnClickListener(new View.OnClickListener() { @@ -1468,9 +1389,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct public void onClick(View v) { if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS) { Intent intent = new Intent(context, ShowConversationActivity.class); - int position = closePanels(); - /*if( holder.getAdapterPosition() == position && type == RetrieveFeedsAsyncTask.Type.CONTEXT) - return;*/ Bundle b = new Bundle(); if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) b.putString("conversationId", status.getConversationId()); @@ -1614,13 +1532,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if (status.getNumberLines() == -1) { status.setNumberLines(-2); holder.status_show_more_content.setVisibility(View.GONE); - holder.status_content.post(new Runnable() { - @Override - public void run() { - status.setNumberLines(holder.status_content.getLineCount()); - if (status.getNumberLines() > truncate_toots_size) { - notifyStatusChanged(status); - } + holder.status_content.post(() -> { + status.setNumberLines(holder.status_content.getLineCount()); + if (status.getNumberLines() > truncate_toots_size) { + notifyStatusChanged(status); } }); } else if (status.getNumberLines() > truncate_toots_size) { @@ -1648,12 +1563,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance()); //-------- END -> Manages translations - if (status.getAccount() == null) { - final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null); - Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - status.setAccount(account); - } //Displays name & emoji in toot header final Account accountForUrl; if (status.getReblog() != null) { @@ -1910,16 +1819,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } - /*if (expand_cw) - holder.status_spoiler_button.setVisibility(View.GONE);*/ - /*String contentCheck = ""; - String content = status.getReblog() == null?status.getContent():status.getReblog().getContent(); - if( content != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - contentCheck = Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY).toString(); - else - contentCheck = Html.fromHtml(content).toString(); - }*/ if (status.getReblog() == null) { if (status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0) { holder.status_spoiler_container.setVisibility(View.VISIBLE); @@ -2071,56 +1970,40 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } } } - holder.status_show_more.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - status.setAttachmentShown(true); - notifyStatusChanged(status); - /* - Added a Countdown Timer, so that Sensitive (NSFW) - images only get displayed for user set time, - giving the user time to click on them to expand them, - if they want. Images are then hidden again. - -> Default value is set to 5 seconds - */ - final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5); - if (timeout > 0) { - new CountDownTimer((timeout * 1000), 1000) { - public void onTick(long millisUntilFinished) { - } + holder.status_show_more.setOnClickListener(v -> { + status.setAttachmentShown(true); + notifyStatusChanged(status); + final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5); + if (timeout > 0) { + new CountDownTimer((timeout * 1000), 1000) { + public void onTick(long millisUntilFinished) { + } - public void onFinish() { - status.setAttachmentShown(false); - notifyStatusChanged(status); - } - }.start(); - } + public void onFinish() { + status.setAttachmentShown(false); + notifyStatusChanged(status); + } + }.start(); } }); if (!fullAttachement) - holder.hide_preview.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - status.setAttachmentShown(!status.isAttachmentShown()); - if (status.getReblog() != null) - status.getReblog().setSensitive(true); - else - status.setSensitive(true); - notifyStatusChanged(status); - } + holder.hide_preview.setOnClickListener(v -> { + status.setAttachmentShown(!status.isAttachmentShown()); + if (status.getReblog() != null) + status.getReblog().setSensitive(true); + else + status.setSensitive(true); + notifyStatusChanged(status); }); else - holder.hide_preview_h.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - status.setAttachmentShown(!status.isAttachmentShown()); - if (status.getReblog() != null) - status.getReblog().setSensitive(true); - else - status.setSensitive(true); - notifyStatusChanged(status); - } + holder.hide_preview_h.setOnClickListener(v -> { + status.setAttachmentShown(!status.isAttachmentShown()); + if (status.getReblog() != null) + status.getReblog().setSensitive(true); + else + status.setSensitive(true); + notifyStatusChanged(status); }); //Toot was translated and user asked to see it @@ -2271,31 +2154,29 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct android.widget.PopupMenu popup = new android.widget.PopupMenu(context, holder.quick_reply_button); popup.getMenuInflater() .inflate(R.menu.main_content_type, popup.getMenu()); - popup.setOnMenuItemClickListener(new android.widget.PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - String contentType = null; - switch (item.getItemId()) { - case R.id.action_plain_text: - contentType = "text/plain"; - break; - case R.id.action_html: - contentType = "text/html"; - break; - case R.id.action_markdown: - contentType = "text/markdown"; - break; - case R.id.action_bbcode: - contentType = "text/bbcode"; - break; - } - popup.dismiss(); - sendToot(status, contentType); - status.setShortReply(false); - holder.quick_reply_container.setVisibility(View.GONE); - InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(holder.quick_reply_button.getWindowToken(), 0); - return false; + popup.setOnMenuItemClickListener(item -> { + String contentType = null; + switch (item.getItemId()) { + case R.id.action_plain_text: + contentType = "text/plain"; + break; + case R.id.action_html: + contentType = "text/html"; + break; + case R.id.action_markdown: + contentType = "text/markdown"; + break; + case R.id.action_bbcode: + contentType = "text/bbcode"; + break; } + popup.dismiss(); + sendToot(status, contentType); + status.setShortReply(false); + holder.quick_reply_container.setVisibility(View.GONE); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(holder.quick_reply_button.getWindowToken(), 0); + return false; }); popup.show(); return false; @@ -2316,35 +2197,27 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct dialog.setTitle(R.string.toot_visibility_tilte); final String[] stringArray = context.getResources().getStringArray(R.array.toot_visibility); final ArrayAdapter arrayAdapter = new ArrayAdapter<>(context, 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.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int position) { - switch (position) { - case 0: - status.setQuickReplyPrivacy("public"); - holder.quick_reply_privacy.setImageResource(R.drawable.ic_public_toot); - break; - case 1: - status.setQuickReplyPrivacy("unlisted"); - holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_open_toot); - break; - case 2: - status.setQuickReplyPrivacy("private"); - holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_outline_toot); - break; - case 3: - status.setQuickReplyPrivacy("direct"); - holder.quick_reply_privacy.setImageResource(R.drawable.ic_mail_outline_toot); - break; - } - dialog.dismiss(); + dialog.setNegativeButton(R.string.cancel, (dialog1, position) -> dialog1.dismiss()); + dialog.setAdapter(arrayAdapter, (dialog12, position) -> { + switch (position) { + case 0: + status.setQuickReplyPrivacy("public"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_public_toot); + break; + case 1: + status.setQuickReplyPrivacy("unlisted"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_open_toot); + break; + case 2: + status.setQuickReplyPrivacy("private"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_outline_toot); + break; + case 3: + status.setQuickReplyPrivacy("direct"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_mail_outline_toot); + break; } + dialog12.dismiss(); }); dialog.show(); }); @@ -2460,192 +2333,189 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.quick_reply_container.setOnClickListener(view -> { }); - holder.status_reply.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + holder.status_reply.setOnClickListener(v -> { - if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED || (quick_reply && type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS)) { + if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED || (quick_reply && type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS)) { - if (social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { - holder.quick_reply_switch_to_full.setVisibility(View.GONE); + if (social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { + holder.quick_reply_switch_to_full.setVisibility(View.GONE); + } + if (context instanceof BaseMainActivity) { + FloatingActionButton toot = ((BaseMainActivity) context).findViewById(R.id.toot); + if (toot != null) { + toot.hide(); } - if (context instanceof BaseMainActivity) { - FloatingActionButton toot = ((BaseMainActivity) context).findViewById(R.id.toot); - if (toot != null) { - toot.hide(); + } + holder.warning_message.setVisibility(View.GONE); + if (status.getWarningFetched() == -1) { + warning_message = holder.warning_message; + new RetrieveRelationshipQuickReplyAsyncTask(context, status, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + } else if (status.getWarningFetched() == 1) { + holder.warning_message.setVisibility(View.VISIBLE); + } + + boolean shown = status.isShortReply(); + if (!shown) { + for (Status s : statuses) { + if (s.isShortReply() && !s.getId().equals(status.getId())) { + s.setShortReply(false); + notifyStatusChanged(s); } } - holder.warning_message.setVisibility(View.GONE); - if (status.getWarningFetched() == -1) { - warning_message = holder.warning_message; - new RetrieveRelationshipQuickReplyAsyncTask(context, status, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - } else if (status.getWarningFetched() == 1) { - holder.warning_message.setVisibility(View.VISIBLE); + status.setShortReply(true); + statusForQuickReply = status; + holder.quick_reply_container.setVisibility(View.VISIBLE); + InputMethodManager inputMethodManager = + (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + inputMethodManager.toggleSoftInputFromWindow( + holder.quick_reply_text.getApplicationWindowToken(), + InputMethodManager.SHOW_FORCED, 0); + holder.quick_reply_text.requestFocus(); + EditText content_cw = new EditText(context); + content_cw.setText(status.getReblog() != null ? status.getReblog().getSpoiler_text() : status.getSpoiler_text()); + if (status.getQuickReplyContent() == null) { + TootActivity.manageMentions(context, social, userId, + holder.quick_reply_text, content_cw, holder.toot_space_left, status.getReblog() != null ? status.getReblog() : status); + } else { + holder.quick_reply_text.setText(status.getQuickReplyContent()); } + TextWatcher textWatcher = TootActivity.initializeTextWatcher(context, social, status, holder.quick_reply_text, content_cw, holder.toot_space_left, null, null, StatusListAdapter.this, StatusListAdapter.this, StatusListAdapter.this); - boolean shown = status.isShortReply(); - if (!shown) { - for (Status s : statuses) { - if (s.isShortReply() && !s.getId().equals(status.getId())) { - s.setShortReply(false); - notifyStatusChanged(s); - } - } - status.setShortReply(true); - statusForQuickReply = status; - holder.quick_reply_container.setVisibility(View.VISIBLE); - InputMethodManager inputMethodManager = - (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); - inputMethodManager.toggleSoftInputFromWindow( - holder.quick_reply_text.getApplicationWindowToken(), - InputMethodManager.SHOW_FORCED, 0); - holder.quick_reply_text.requestFocus(); - EditText content_cw = new EditText(context); - content_cw.setText(status.getReblog() != null ? status.getReblog().getSpoiler_text() : status.getSpoiler_text()); - if (status.getQuickReplyContent() == null) { - TootActivity.manageMentions(context, social, userId, - holder.quick_reply_text, content_cw, holder.toot_space_left, status.getReblog() != null ? status.getReblog() : status); - } else { - holder.quick_reply_text.setText(status.getQuickReplyContent()); - } - TextWatcher textWatcher = TootActivity.initializeTextWatcher(context, social, status, holder.quick_reply_text, content_cw, holder.toot_space_left, null, null, StatusListAdapter.this, StatusListAdapter.this, StatusListAdapter.this); + toot_content = holder.quick_reply_text; + int newInputType = toot_content.getInputType() & (toot_content.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE); + toot_content.setInputType(newInputType); + toot_cw_content = content_cw; + toot_space_left = holder.toot_space_left; + in_reply_to_status = status.getReblog() != null ? status.getReblog().getId() : status.getId(); + tootReply = status; - toot_content = holder.quick_reply_text; - int newInputType = toot_content.getInputType() & (toot_content.getInputType() ^ InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE); - toot_content.setInputType(newInputType); - toot_cw_content = content_cw; - toot_space_left = holder.toot_space_left; - in_reply_to_status = status.getReblog() != null ? status.getReblog().getId() : status.getId(); - tootReply = status; + final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null); + Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null); - Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - - String defaultVisibility = account.isLocked() ? "private" : "public"; - String settingsVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), defaultVisibility); - int initialTootVisibility = 0; - int ownerTootVisibility = 0; - switch (status.getReblog() != null ? status.getReblog().getVisibility() : status.getVisibility()) { + String defaultVisibility = account.isLocked() ? "private" : "public"; + String settingsVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), defaultVisibility); + int initialTootVisibility = 0; + int ownerTootVisibility = 0; + switch (status.getReblog() != null ? status.getReblog().getVisibility() : status.getVisibility()) { + case "public": + initialTootVisibility = 4; + break; + case "unlisted": + initialTootVisibility = 3; + break; + case "private": + status.setQuickReplyPrivacy("private"); + initialTootVisibility = 2; + break; + case "direct": + status.setQuickReplyPrivacy("direct"); + initialTootVisibility = 1; + break; + } + if (settingsVisibility != null) { + switch (settingsVisibility) { case "public": - initialTootVisibility = 4; + ownerTootVisibility = 4; break; case "unlisted": - initialTootVisibility = 3; + ownerTootVisibility = 3; break; case "private": status.setQuickReplyPrivacy("private"); - initialTootVisibility = 2; + ownerTootVisibility = 2; break; case "direct": status.setQuickReplyPrivacy("direct"); - initialTootVisibility = 1; + ownerTootVisibility = 1; break; } - if (settingsVisibility != null) { - switch (settingsVisibility) { - case "public": - ownerTootVisibility = 4; - break; - case "unlisted": - ownerTootVisibility = 3; - break; - case "private": - status.setQuickReplyPrivacy("private"); - ownerTootVisibility = 2; - break; - case "direct": - status.setQuickReplyPrivacy("direct"); - ownerTootVisibility = 1; - break; - } - } - int tootVisibility; - if (ownerTootVisibility >= initialTootVisibility) { - tootVisibility = initialTootVisibility; - } else { - tootVisibility = ownerTootVisibility; - } + } + int tootVisibility; + if (ownerTootVisibility >= initialTootVisibility) { + tootVisibility = initialTootVisibility; + } else { + tootVisibility = ownerTootVisibility; + } - switch (tootVisibility) { - case 4: - status.setQuickReplyPrivacy("public"); + switch (tootVisibility) { + case 4: + status.setQuickReplyPrivacy("public"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_public_toot); + break; + case 3: + status.setQuickReplyPrivacy("unlisted"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_open_toot); + break; + case 2: + status.setQuickReplyPrivacy("private"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_outline_toot); + break; + case 1: + status.setQuickReplyPrivacy("direct"); + holder.quick_reply_privacy.setImageResource(R.drawable.ic_mail_outline_toot); + break; + } + if (status.getQuickReplyPrivacy() != null) { + switch (status.getQuickReplyPrivacy()) { + case "public": holder.quick_reply_privacy.setImageResource(R.drawable.ic_public_toot); break; - case 3: - status.setQuickReplyPrivacy("unlisted"); + case "unlisted": holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_open_toot); break; - case 2: - status.setQuickReplyPrivacy("private"); + case "private": holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_outline_toot); break; - case 1: - status.setQuickReplyPrivacy("direct"); + case "direct": holder.quick_reply_privacy.setImageResource(R.drawable.ic_mail_outline_toot); break; } - if (status.getQuickReplyPrivacy() != null) { - switch (status.getQuickReplyPrivacy()) { - case "public": - holder.quick_reply_privacy.setImageResource(R.drawable.ic_public_toot); - break; - case "unlisted": - holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_open_toot); - break; - case "private": - holder.quick_reply_privacy.setImageResource(R.drawable.ic_lock_outline_toot); - break; - case "direct": - holder.quick_reply_privacy.setImageResource(R.drawable.ic_mail_outline_toot); - break; - } - } - holder.quick_reply_text.addTextChangedListener(textWatcher); - - - } else { - status.setShortReply(false); - holder.quick_reply_container.setVisibility(View.GONE); - InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(holder.quick_reply_text.getWindowToken(), 0); } - holder.quick_reply_switch_to_full.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - status.setShortReply(false); - holder.quick_reply_container.setVisibility(View.GONE); - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - if (status != null && status.getReblog() != null) { - b.putParcelable("tootReply", status.getReblog()); - } else { - b.putParcelable("tootReply", status); - } + holder.quick_reply_text.addTextChangedListener(textWatcher); - b.putString("quickmessagevisibility", status.getQuickReplyPrivacy()); - b.putString("quickmessagecontent", status.getQuickReplyContent()); - intent.putExtras(b); //Put your id to your next Intent - context.startActivity(intent); - if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) { - try { - //Avoid to open multi activities when replying in a conversation - ((ShowConversationActivity) context).finish(); - } catch (Exception ignored) { - } - } - } - }); } else { - CrossActions.doCrossReply(context, status, type, true); - if (status.isShortReply()) { + status.setShortReply(false); + holder.quick_reply_container.setVisibility(View.GONE); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(holder.quick_reply_text.getWindowToken(), 0); + } + holder.quick_reply_switch_to_full.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { status.setShortReply(false); holder.quick_reply_container.setVisibility(View.GONE); - InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(holder.quick_reply_text.getWindowToken(), 0); + Intent intent = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + if (status != null && status.getReblog() != null) { + b.putParcelable("tootReply", status.getReblog()); + } else { + b.putParcelable("tootReply", status); + } + + b.putString("quickmessagevisibility", status.getQuickReplyPrivacy()); + b.putString("quickmessagecontent", status.getQuickReplyContent()); + intent.putExtras(b); //Put your id to your next Intent + context.startActivity(intent); + if (type == RetrieveFeedsAsyncTask.Type.CONTEXT) { + try { + //Avoid to open multi activities when replying in a conversation + ((ShowConversationActivity) context).finish(); + } catch (Exception ignored) { + } + + } } + }); + } else { + CrossActions.doCrossReply(context, status, type, true); + if (status.isShortReply()) { + status.setShortReply(false); + holder.quick_reply_container.setVisibility(View.GONE); + InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(holder.quick_reply_text.getWindowToken(), 0); } } }); @@ -2663,49 +2533,35 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct CrossActions.doCrossAction(context, type, status, null, (status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, true); } }); - holder.spark_button_fav.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!status.isFavourited() && confirmFav) - status.setFavAnimated(true); - if (!status.isFavourited() && !confirmFav) { - status.setFavAnimated(true); - notifyStatusChanged(status); - } - CrossActions.doCrossAction(context, type, status, null, (status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, true); + holder.spark_button_fav.setOnClickListener(v -> { + if (!status.isFavourited() && confirmFav) + status.setFavAnimated(true); + if (!status.isFavourited() && !confirmFav) { + status.setFavAnimated(true); + notifyStatusChanged(status); } + CrossActions.doCrossAction(context, type, status, null, (status.isFavourited() || (status.getReblog() != null && status.getReblog().isFavourited())) ? API.StatusAction.UNFAVOURITE : API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, true); }); - holder.status_reblog_count.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!status.isReblogged() && confirmBoost) - status.setBoostAnimated(true); - if (!status.isReblogged() && !confirmBoost) { - status.setBoostAnimated(true); - notifyStatusChanged(status); - } - CrossActions.doCrossAction(context, type, status, null, (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, true); + holder.status_reblog_count.setOnClickListener(v -> { + if (!status.isReblogged() && confirmBoost) + status.setBoostAnimated(true); + if (!status.isReblogged() && !confirmBoost) { + status.setBoostAnimated(true); + notifyStatusChanged(status); } + CrossActions.doCrossAction(context, type, status, null, (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, true); }); - holder.spark_button_reblog.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (!status.isReblogged() && confirmBoost) - status.setBoostAnimated(true); - if (!status.isReblogged() && !confirmBoost) { - status.setBoostAnimated(true); - notifyStatusChanged(status); - } - CrossActions.doCrossAction(context, type, status, null, (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, true); - } - }); - holder.status_pin.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CrossActions.doCrossAction(context, type, status, null, (status.isPinned() || (status.getReblog() != null && status.getReblog().isPinned())) ? API.StatusAction.UNPIN : API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true); + holder.spark_button_reblog.setOnClickListener(v -> { + if (!status.isReblogged() && confirmBoost) + status.setBoostAnimated(true); + if (!status.isReblogged() && !confirmBoost) { + status.setBoostAnimated(true); + notifyStatusChanged(status); } + CrossActions.doCrossAction(context, type, status, null, (status.isReblogged() || (status.getReblog() != null && status.getReblog().isReblogged())) ? API.StatusAction.UNREBLOG : API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, true); }); + holder.status_pin.setOnClickListener(v -> CrossActions.doCrossAction(context, type, status, null, (status.isPinned() || (status.getReblog() != null && status.getReblog().isPinned())) ? API.StatusAction.UNPIN : API.StatusAction.PIN, statusListAdapter, StatusListAdapter.this, true)); int style; if (theme == Helper.THEME_DARK) { style = R.style.DialogDark; @@ -2714,121 +2570,94 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } else { style = R.style.Dialog; } - holder.status_remove.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); - AlertDialog.Builder builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[0]); - API.StatusAction doAction = API.StatusAction.UNSTATUS; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); + holder.status_remove.setOnClickListener(v -> { + String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); + AlertDialog.Builder builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[0]); + API.StatusAction doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + builderInner.setMessage(Html.fromHtml(status.getContent())); - //Text for report - EditText input = null; - if (doAction == API.StatusAction.REPORT) { - input = new EditText(context); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - 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) { - dialog.dismiss(); - } - }); - final EditText finalInput = input; - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String targetedId = status.getId(); - new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - if (redraft) { - if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) { - toot = new Status(); - toot.setIn_reply_to_id(status.getIn_reply_to_id()); - toot.setSensitive(status.isSensitive()); - toot.setMedia_attachments(status.getMedia_attachments()); - if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) - toot.setSpoiler_text(status.getSpoiler_text().trim()); - toot.setContent(context, status.getContent()); - toot.setVisibility(status.getVisibility()); - new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - toot = new Status(); - toot.setSensitive(status.isSensitive()); - toot.setMedia_attachments(status.getMedia_attachments()); - if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) - toot.setSpoiler_text(status.getSpoiler_text().trim()); - toot.setVisibility(status.getVisibility()); - toot.setContent(context, status.getContent()); - final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - long id = new StatusStoredDAO(context, db).insertStatus(toot, null); - Intent intentToot = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - b.putLong("restored", id); - b.putBoolean("removed", true); - intentToot.putExtras(b); - context.startActivity(intentToot); - } - } - dialog.dismiss(); - } - }); - builderInner.show(); + //Text for report + EditText input = null; + if (doAction == API.StatusAction.REPORT) { + input = new EditText(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT); + input.setLayoutParams(lp); + builderInner.setView(input); } + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + final EditText finalInput = input; + builderInner.setPositiveButton(R.string.yes, (dialog, which) -> { + String targetedId = status.getId(); + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (redraft) { + if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) { + toot = new Status(); + toot.setIn_reply_to_id(status.getIn_reply_to_id()); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setContent(context, status.getContent()); + toot.setVisibility(status.getVisibility()); + new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + toot = new Status(); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setVisibility(status.getVisibility()); + toot.setContent(context, status.getContent()); + final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + long id = new StatusStoredDAO(context, db).insertStatus(toot, null); + Intent intentToot = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + b.putLong("restored", id); + b.putBoolean("removed", true); + intentToot.putExtras(b); + context.startActivity(intentToot); + } + } + dialog.dismiss(); + }); + builderInner.show(); }); if (!status.getVisibility().equals("direct")) - holder.spark_button_fav.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - CrossActions.doCrossAction(context, type, status, null, API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false); - return true; - } + holder.spark_button_fav.setOnLongClickListener(view -> { + CrossActions.doCrossAction(context, type, status, null, API.StatusAction.FAVOURITE, statusListAdapter, StatusListAdapter.this, false); + return true; }); if (!status.getVisibility().equals("direct")) - holder.spark_button_reblog.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - CrossActions.doCrossAction(context, type, status, null, API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false); - return true; - } + holder.spark_button_reblog.setOnLongClickListener(view -> { + CrossActions.doCrossAction(context, type, status, null, API.StatusAction.REBLOG, statusListAdapter, StatusListAdapter.this, false); + return true; }); if (!status.getVisibility().equals("direct")) - holder.status_reply.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - CrossActions.doCrossReply(context, status, type, false); - return true; - } + holder.status_reply.setOnLongClickListener(view -> { + CrossActions.doCrossReply(context, status, type, false); + return true; }); - holder.yandex_translate.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://translate.yandex.com/")); - context.startActivity(browserIntent); - } + holder.yandex_translate.setOnClickListener(v -> { + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://translate.yandex.com/")); + context.startActivity(browserIntent); }); //Spoiler opens - holder.status_spoiler_button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (expand_cw && !status.isSpoilerShown()) { - status.setAutoHiddenCW(true); - } else { - status.setAutoHiddenCW(false); - } - status.setSpoilerShown(!status.isSpoilerShown()); - notifyStatusChanged(status); + holder.status_spoiler_button.setOnClickListener(v -> { + if (expand_cw && !status.isSpoilerShown()) { + status.setAutoHiddenCW(true); + } else { + status.setAutoHiddenCW(false); } + status.setSpoilerShown(!status.isSpoilerShown()); + notifyStatusChanged(status); }); @@ -2836,456 +2665,445 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_more.setVisibility(View.GONE); final View attached = holder.status_more; - holder.status_more.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - PopupMenu popup = new PopupMenu(context, attached); - final boolean isOwner = status.getReblog() != null ? status.getReblog().getAccount().getId().equals(userId) : status.getAccount().getId().equals(userId); - popup.getMenuInflater() - .inflate(R.menu.option_toot, popup.getMenu()); - if (status.getVisibility().equals("private") || status.getVisibility().equals("direct")) { - popup.getMenu().findItem(R.id.action_mention).setVisible(false); - } - if (status.isBookmarked()) - popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_remove); - else - popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_add); - if (status.isMuted()) - popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.unmute_conversation); - else - popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.mute_conversation); + holder.status_more.setOnClickListener(v -> { + PopupMenu popup = new PopupMenu(context, attached); + final boolean isOwner1 = status.getReblog() != null ? status.getReblog().getAccount().getId().equals(userId) : status.getAccount().getId().equals(userId); + popup.getMenuInflater() + .inflate(R.menu.option_toot, popup.getMenu()); + if (status.getVisibility().equals("private") || status.getVisibility().equals("direct")) { + popup.getMenu().findItem(R.id.action_mention).setVisible(false); + } + if (status.isBookmarked()) + popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_remove); + else + popup.getMenu().findItem(R.id.action_bookmark).setTitle(R.string.bookmark_add); + if (status.isMuted()) + popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.unmute_conversation); + else + popup.getMenu().findItem(R.id.action_mute_conversation).setTitle(R.string.mute_conversation); - final String[] stringArrayConf; - if (status.getVisibility().equals("direct") || (status.getVisibility().equals("private") && !isOwner)) - popup.getMenu().findItem(R.id.action_schedule_boost).setVisible(false); - if (isOwner) { - popup.getMenu().findItem(R.id.action_block).setVisible(false); - popup.getMenu().findItem(R.id.action_mute).setVisible(false); - popup.getMenu().findItem(R.id.action_report).setVisible(false); - popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false); - popup.getMenu().findItem(R.id.action_block_domain).setVisible(false); - stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); - if (social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { - popup.getMenu().findItem(R.id.action_stats).setVisible(false); - } - } else { + final String[] stringArrayConf; + if (status.getVisibility().equals("direct") || (status.getVisibility().equals("private") && !isOwner1)) + popup.getMenu().findItem(R.id.action_schedule_boost).setVisible(false); + if (isOwner1) { + popup.getMenu().findItem(R.id.action_block).setVisible(false); + popup.getMenu().findItem(R.id.action_mute).setVisible(false); + popup.getMenu().findItem(R.id.action_report).setVisible(false); + popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false); + popup.getMenu().findItem(R.id.action_block_domain).setVisible(false); + stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm); + if (social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { popup.getMenu().findItem(R.id.action_stats).setVisible(false); - popup.getMenu().findItem(R.id.action_redraft).setVisible(false); - //popup.getMenu().findItem(R.id.action_mute_conversation).setVisible(false); - if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA && (isAdmin || isModerator)) { - popup.getMenu().findItem(R.id.action_remove).setVisible(true); - } else { - popup.getMenu().findItem(R.id.action_remove).setVisible(false); - } - //Same instance - if (status.getAccount().getAcct().split("@").length < 2) - popup.getMenu().findItem(R.id.action_block_domain).setVisible(false); - stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm); } - if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { - popup.getMenu().findItem(R.id.action_info).setVisible(false); - popup.getMenu().findItem(R.id.action_report).setVisible(false); - popup.getMenu().findItem(R.id.action_block_domain).setVisible(false); - popup.getMenu().findItem(R.id.action_mute_conversation).setVisible(false); - } - if (holder.getItemViewType() == DISPLAYED_STATUS && fedilab_features_button) { - popup.getMenu().findItem(R.id.action_translate).setVisible(false); - popup.getMenu().findItem(R.id.action_bookmark).setVisible(false); - popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false); - popup.getMenu().findItem(R.id.action_schedule_boost).setVisible(false); - popup.getMenu().findItem(R.id.action_mention).setVisible(false); - } - if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { - popup.getMenu().findItem(R.id.action_admin).setVisible(false); + } else { + popup.getMenu().findItem(R.id.action_stats).setVisible(false); + popup.getMenu().findItem(R.id.action_redraft).setVisible(false); + if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA && (isAdmin || isModerator)) { + popup.getMenu().findItem(R.id.action_remove).setVisible(true); } else { - boolean display_admin_statuses = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ADMIN_STATUSES + userId + Helper.getLiveInstance(context), false); - if (!display_admin_statuses) { - popup.getMenu().findItem(R.id.action_admin).setVisible(false); - } + popup.getMenu().findItem(R.id.action_remove).setVisible(false); } + //Same instance + if (status.getAccount().getAcct().split("@").length < 2) + popup.getMenu().findItem(R.id.action_block_domain).setVisible(false); + stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm); + } + if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { + popup.getMenu().findItem(R.id.action_info).setVisible(false); + popup.getMenu().findItem(R.id.action_report).setVisible(false); + popup.getMenu().findItem(R.id.action_block_domain).setVisible(false); + popup.getMenu().findItem(R.id.action_mute_conversation).setVisible(false); + } + if (holder.getItemViewType() == DISPLAYED_STATUS && fedilab_features_button) { + popup.getMenu().findItem(R.id.action_translate).setVisible(false); + popup.getMenu().findItem(R.id.action_bookmark).setVisible(false); + popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false); + popup.getMenu().findItem(R.id.action_schedule_boost).setVisible(false); + popup.getMenu().findItem(R.id.action_mention).setVisible(false); + } + if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.MASTODON && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { + popup.getMenu().findItem(R.id.action_admin).setVisible(false); + } else { + boolean display_admin_statuses = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ADMIN_STATUSES + userId + Helper.getLiveInstance(context), false); + if (!display_admin_statuses) { + popup.getMenu().findItem(R.id.action_admin).setVisible(false); + } + } - boolean custom_sharing = sharedpreferences.getBoolean(Helper.SET_CUSTOM_SHARING, false); - if (custom_sharing && status.getVisibility().equals("public")) - popup.getMenu().findItem(R.id.action_custom_sharing).setVisible(true); - MenuItem itemBookmark = popup.getMenu().findItem(R.id.action_bookmark); - if (itemBookmark.getActionView() != null) - itemBookmark.getActionView().setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - CrossActions.doCrossBookmark(context, status, statusListAdapter, true); - return true; - } - }); - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem item) { - AlertDialog.Builder builderInner; - final API.StatusAction doAction; - switch (item.getItemId()) { - case R.id.action_redraft: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[1]); - redraft = true; - doAction = API.StatusAction.UNSTATUS; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_schedule_boost: - scheduleBoost(status); - return true; - case R.id.action_admin: - String account_id = status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId(); - String acct = status.getReblog() != null ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct(); - Intent intent = new Intent(context, AccountReportActivity.class); - Bundle b = new Bundle(); - if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) { - b.putString("account_id", account_id); - } else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { - b.putString("account_id", acct); - } - intent.putExtras(b); - context.startActivity(intent); - return true; - case R.id.action_info: - tootInformation(status); - return true; - case R.id.action_open_browser: - Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); - return true; - case R.id.action_remove: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[0]); - doAction = API.StatusAction.UNSTATUS; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_block_domain: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[3]); - doAction = API.StatusAction.BLOCK_DOMAIN; - String domain = status.getAccount().getAcct().split("@")[1]; - builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain)); - break; - case R.id.action_mute: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[0]); - builderInner.setMessage(status.getAccount().getAcct()); - doAction = API.StatusAction.MUTE; - break; - case R.id.action_mute_conversation: - if (status.isMuted()) - doAction = API.StatusAction.UNMUTE_CONVERSATION; - else - doAction = API.StatusAction.MUTE_CONVERSATION; - - new PostActionAsyncTask(context, doAction, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - return true; - case R.id.action_bookmark: - if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) { - status.setBookmarked(!status.isBookmarked()); - final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - try { - if (status.isBookmarked()) { - new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status); - Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show(); - } else { - new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status); - Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); - } - notifyStatusChanged(status); - } catch (Exception e) { - e.printStackTrace(); - Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); - } - } else { - int position = 0; - for (Status statustmp : statuses) { - if (statustmp.getId().equals(status.getId())) { - statuses.remove(status); - statusListAdapter.notifyItemRemoved(position); - final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp); - Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); - break; - } - position++; - } - } - return true; - case R.id.action_stats: - intent = new Intent(context, OwnerNotificationChartsActivity.class); - b = new Bundle(); - b.putString("status_id", status.getReblog() != null ? status.getReblog().getId() : status.getId()); - intent.putExtras(b); - context.startActivity(intent); - return true; - case R.id.action_timed_mute: - timedMuteAction(status); - return true; - case R.id.action_block: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[1]); - doAction = API.StatusAction.BLOCK; - break; - case R.id.action_translate: - if (translator == Helper.TRANS_NONE) - Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show(); - else - translateToot(status); - return true; - case R.id.action_report: - builderInner = new AlertDialog.Builder(context, style); - builderInner.setTitle(stringArrayConf[2]); - doAction = API.StatusAction.REPORT; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); - else - //noinspection deprecation - builderInner.setMessage(Html.fromHtml(status.getContent())); - break; - case R.id.action_copy: - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - final String content; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - //noinspection deprecation - content = Html.fromHtml(status.getContent()).toString(); - ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); - if (clipboard != null) { - clipboard.setPrimaryClip(clip); - Toasty.info(context, context.getString(R.string.clipboard), Toast.LENGTH_LONG).show(); - } - return true; - case R.id.action_copy_link: - clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - - clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); - if (clipboard != null) { - clipboard.setPrimaryClip(clip); - Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); - } - return true; - case R.id.action_share: - Intent sendIntent = new Intent(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); - String url; - - if (status.getReblog() != null) { - if (status.getReblog().getUri().startsWith("http")) - url = status.getReblog().getUri(); - else - url = status.getReblog().getUrl(); - } else { - if (status.getUri().startsWith("http")) - url = status.getUri(); - else - url = status.getUrl(); - } - String extra_text; - - if (share_details) { - extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct(); - if (extra_text.split("@").length == 1) - extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context); - else - extra_text = "@" + extra_text; - extra_text += " " + Helper.shortnameToUnicode(":link:", true) + " " + url + "\r\n-\n"; - final String contentToot; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); - else - //noinspection deprecation - contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString(); - extra_text += contentToot; - } else { - extra_text = url; - } - sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text); - sendIntent.setType("text/plain"); - context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); - return true; - case R.id.action_custom_sharing: - Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); - Bundle bCustomSharing = new Bundle(); - if (status.getReblog() != null) { - bCustomSharing.putParcelable("status", status.getReblog()); - } else { - bCustomSharing.putParcelable("status", status); - } - intentCustomSharing.putExtras(bCustomSharing); - context.startActivity(intentCustomSharing); - return true; - case R.id.action_mention: - mention(status); - return true; - default: - return true; - } - - //Text for report - EditText input = null; - if (doAction == API.StatusAction.REPORT) { - input = new EditText(context); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, - 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) { - dialog.dismiss(); - } - }); - final EditText finalInput = input; - builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (doAction == API.StatusAction.UNSTATUS) { - String targetedId = status.getId(); - new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - if (redraft) { - if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) { - toot = new Status(); - toot.setIn_reply_to_id(status.getIn_reply_to_id()); - toot.setSensitive(status.isSensitive()); - toot.setMedia_attachments(status.getMedia_attachments()); - if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) - toot.setSpoiler_text(status.getSpoiler_text().trim()); - toot.setContent(context, status.getContent()); - toot.setVisibility(status.getVisibility()); - if (status.getPoll() != null) { - toot.setPoll(status.getPoll()); - } else if (status.getReblog() != null && status.getReblog().getPoll() != null) { - toot.setPoll(status.getPoll()); - } - new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - toot = new Status(); - toot.setSensitive(status.isSensitive()); - toot.setMedia_attachments(status.getMedia_attachments()); - if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) - toot.setSpoiler_text(status.getSpoiler_text().trim()); - toot.setVisibility(status.getVisibility()); - toot.setContent(context, status.getContent()); - if (status.getPoll() != null) { - toot.setPoll(status.getPoll()); - } else if (status.getReblog() != null && status.getReblog().getPoll() != null) { - toot.setPoll(status.getPoll()); - } - final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - long id = new StatusStoredDAO(context, db).insertStatus(toot, null); - Intent intentToot = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - b.putLong("restored", id); - b.putBoolean("removed", true); - intentToot.putExtras(b); - context.startActivity(intentToot); - } - } - } else if (doAction == API.StatusAction.REPORT) { - String comment = null; - if (finalInput.getText() != null) - comment = finalInput.getText().toString(); - new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - String targetedId; - if (item.getItemId() == R.id.action_block_domain) { - targetedId = status.getAccount().getAcct().split("@")[1]; - } else { - targetedId = status.getAccount().getId(); - } - new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - dialog.dismiss(); - } - }); - builderInner.show(); + boolean custom_sharing = sharedpreferences.getBoolean(Helper.SET_CUSTOM_SHARING, false); + if (custom_sharing && status.getVisibility().equals("public")) + popup.getMenu().findItem(R.id.action_custom_sharing).setVisible(true); + MenuItem itemBookmark = popup.getMenu().findItem(R.id.action_bookmark); + if (itemBookmark.getActionView() != null) + itemBookmark.getActionView().setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + CrossActions.doCrossBookmark(context, status, statusListAdapter, true); return true; } }); - popup.show(); - } + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + AlertDialog.Builder builderInner; + final API.StatusAction doAction; + switch (item.getItemId()) { + case R.id.action_redraft: + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[1]); + redraft = true; + doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_schedule_boost: + scheduleBoost(status); + return true; + case R.id.action_admin: + String account_id = status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId(); + String acct = status.getReblog() != null ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct(); + Intent intent = new Intent(context, AccountReportActivity.class); + Bundle b = new Bundle(); + if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON) { + b.putString("account_id", account_id); + } else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { + b.putString("account_id", acct); + } + intent.putExtras(b); + context.startActivity(intent); + return true; + case R.id.action_info: + tootInformation(status); + return true; + case R.id.action_open_browser: + Helper.openBrowser(context, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); + return true; + case R.id.action_remove: + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[0]); + doAction = API.StatusAction.UNSTATUS; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_block_domain: + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[3]); + doAction = API.StatusAction.BLOCK_DOMAIN; + String domain = status.getAccount().getAcct().split("@")[1]; + builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain)); + break; + case R.id.action_mute: + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[0]); + builderInner.setMessage(status.getAccount().getAcct()); + doAction = API.StatusAction.MUTE; + break; + case R.id.action_mute_conversation: + if (status.isMuted()) + doAction = API.StatusAction.UNMUTE_CONVERSATION; + else + doAction = API.StatusAction.MUTE_CONVERSATION; + + new PostActionAsyncTask(context, doAction, status.getId(), StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + return true; + case R.id.action_bookmark: + if (type != RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS) { + status.setBookmarked(!status.isBookmarked()); + final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + try { + if (status.isBookmarked()) { + new StatusCacheDAO(context, db).insertStatus(StatusCacheDAO.BOOKMARK_CACHE, status); + Toasty.success(context, context.getString(R.string.status_bookmarked), Toast.LENGTH_LONG).show(); + } else { + new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, status); + Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); + } + notifyStatusChanged(status); + } catch (Exception e) { + e.printStackTrace(); + Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show(); + } + } else { + int position = 0; + for (Status statustmp : statuses) { + if (statustmp.getId().equals(status.getId())) { + statuses.remove(status); + statusListAdapter.notifyItemRemoved(position); + final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + new StatusCacheDAO(context, db).remove(StatusCacheDAO.BOOKMARK_CACHE, statustmp); + Toasty.success(context, context.getString(R.string.status_unbookmarked), Toast.LENGTH_LONG).show(); + break; + } + position++; + } + } + return true; + case R.id.action_stats: + intent = new Intent(context, OwnerNotificationChartsActivity.class); + b = new Bundle(); + b.putString("status_id", status.getReblog() != null ? status.getReblog().getId() : status.getId()); + intent.putExtras(b); + context.startActivity(intent); + return true; + case R.id.action_timed_mute: + timedMuteAction(status); + return true; + case R.id.action_block: + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[1]); + doAction = API.StatusAction.BLOCK; + break; + case R.id.action_translate: + if (translator == Helper.TRANS_NONE) + Toasty.info(context, R.string.toast_error_translations_disabled, Toast.LENGTH_SHORT).show(); + else + translateToot(status); + return true; + case R.id.action_report: + builderInner = new AlertDialog.Builder(context, style); + builderInner.setTitle(stringArrayConf[2]); + doAction = API.StatusAction.REPORT; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); + else + //noinspection deprecation + builderInner.setMessage(Html.fromHtml(status.getContent())); + break; + case R.id.action_copy: + ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + final String content; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); + else + //noinspection deprecation + content = Html.fromHtml(status.getContent()).toString(); + ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); + if (clipboard != null) { + clipboard.setPrimaryClip(clip); + Toasty.info(context, context.getString(R.string.clipboard), Toast.LENGTH_LONG).show(); + } + return true; + case R.id.action_copy_link: + clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); + + clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); + if (clipboard != null) { + clipboard.setPrimaryClip(clip); + Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); + } + return true; + case R.id.action_share: + Intent sendIntent = new Intent(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); + String url; + + if (status.getReblog() != null) { + if (status.getReblog().getUri().startsWith("http")) + url = status.getReblog().getUri(); + else + url = status.getReblog().getUrl(); + } else { + if (status.getUri().startsWith("http")) + url = status.getUri(); + else + url = status.getUrl(); + } + String extra_text; + + if (share_details) { + extra_text = (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct(); + if (extra_text.split("@").length == 1) + extra_text = "@" + extra_text + "@" + Helper.getLiveInstance(context); + else + extra_text = "@" + extra_text; + extra_text += " " + Helper.shortnameToUnicode(":link:", true) + " " + url + "\r\n-\n"; + final String contentToot; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); + else + contentToot = Html.fromHtml((status.getReblog() != null) ? status.getReblog().getContent() : status.getContent()).toString(); + extra_text += contentToot; + } else { + extra_text = url; + } + sendIntent.putExtra(Intent.EXTRA_TEXT, extra_text); + sendIntent.setType("text/plain"); + context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); + return true; + case R.id.action_custom_sharing: + Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); + Bundle bCustomSharing = new Bundle(); + if (status.getReblog() != null) { + bCustomSharing.putParcelable("status", status.getReblog()); + } else { + bCustomSharing.putParcelable("status", status); + } + intentCustomSharing.putExtras(bCustomSharing); + context.startActivity(intentCustomSharing); + return true; + case R.id.action_mention: + mention(status); + return true; + default: + return true; + } + + //Text for report + EditText input = null; + if (doAction == API.StatusAction.REPORT) { + input = new EditText(context); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + 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) { + dialog.dismiss(); + } + }); + final EditText finalInput = input; + builderInner.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (doAction == API.StatusAction.UNSTATUS) { + String targetedId = status.getId(); + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (redraft) { + if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().trim().equals("null")) { + toot = new Status(); + toot.setIn_reply_to_id(status.getIn_reply_to_id()); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setContent(context, status.getContent()); + toot.setVisibility(status.getVisibility()); + if (status.getPoll() != null) { + toot.setPoll(status.getPoll()); + } else if (status.getReblog() != null && status.getReblog().getPoll() != null) { + toot.setPoll(status.getPoll()); + } + new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.ONESTATUS, status.getIn_reply_to_id(), null, false, false, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + toot = new Status(); + toot.setSensitive(status.isSensitive()); + toot.setMedia_attachments(status.getMedia_attachments()); + if (status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) + toot.setSpoiler_text(status.getSpoiler_text().trim()); + toot.setVisibility(status.getVisibility()); + toot.setContent(context, status.getContent()); + if (status.getPoll() != null) { + toot.setPoll(status.getPoll()); + } else if (status.getReblog() != null && status.getReblog().getPoll() != null) { + toot.setPoll(status.getPoll()); + } + final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + long id = new StatusStoredDAO(context, db).insertStatus(toot, null); + Intent intentToot = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + b.putLong("restored", id); + b.putBoolean("removed", true); + intentToot.putExtras(b); + context.startActivity(intentToot); + } + } + } else if (doAction == API.StatusAction.REPORT) { + String comment = null; + if (finalInput.getText() != null) + comment = finalInput.getText().toString(); + new PostActionAsyncTask(context, doAction, status.getId(), status, comment, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + String targetedId; + if (item.getItemId() == R.id.action_block_domain) { + targetedId = status.getAccount().getAcct().split("@")[1]; + } else { + targetedId = status.getAccount().getId(); + } + new PostActionAsyncTask(context, doAction, targetedId, StatusListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + dialog.dismiss(); + } + }); + builderInner.show(); + return true; + } + }); + popup.show(); }); if (type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS) { - holder.status_account_profile.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (status.getReblog() != null) { - if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putParcelable("account", status.getReblog().getAccount()); - intent.putExtras(b); - context.startActivity(intent); - } - } else { - if (targetedId == null || !targetedId.equals(status.getAccount().getId())) { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putParcelable("account", status.getAccount()); - intent.putExtras(b); - context.startActivity(intent); - } + holder.status_account_profile.setOnClickListener(v -> { + if (status.getReblog() != null) { + if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) { + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putParcelable("account", status.getReblog().getAccount()); + intent.putExtras(b); + context.startActivity(intent); + } + } else { + if (targetedId == null || !targetedId.equals(status.getAccount().getId())) { + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putParcelable("account", status.getAccount()); + intent.putExtras(b); + context.startActivity(intent); } } }); } else if( instanceType == null || instanceType.compareTo("NITTER") != 0){ - holder.status_account_profile.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + holder.status_account_profile.setOnClickListener(v -> { - if (status.getReblog() != null) { - if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) { - Account account = status.getReblog().getAccount(); - Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})"); - Matcher matcher = instanceHost.matcher(status.getUrl()); - String instance = null; - while (matcher.find()) { - instance = matcher.group(1); - } - account.setInstance(instance); - if (BaseMainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) - CrossActions.doCrossProfile(context, account); - else { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putParcelable("account", status.getAccount()); - b.putBoolean("peertubeaccount", true); - intent.putExtras(b); - context.startActivity(intent); - } + if (status.getReblog() != null) { + if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) { + Account account = status.getReblog().getAccount(); + Pattern instanceHost = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})"); + Matcher matcher = instanceHost.matcher(status.getUrl()); + String instance = null; + while (matcher.find()) { + instance = matcher.group(1); } - } else { - if (targetedId == null || !targetedId.equals(status.getAccount().getId())) { - Account account = status.getAccount(); - Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})"); - Matcher matcher = instanceHost.matcher(status.getUrl()); - String instance = null; - while (matcher.find()) { - instance = matcher.group(1); - } - account.setInstance(instance); - if (BaseMainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) - CrossActions.doCrossProfile(context, account); - else { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putParcelable("account", status.getAccount()); - b.putBoolean("peertubeaccount", true); - intent.putExtras(b); - context.startActivity(intent); - } + account.setInstance(instance); + if (BaseMainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) + CrossActions.doCrossProfile(context, account); + else { + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putParcelable("account", status.getAccount()); + b.putBoolean("peertubeaccount", true); + intent.putExtras(b); + context.startActivity(intent); + } + } + } else { + if (targetedId == null || !targetedId.equals(status.getAccount().getId())) { + Account account = status.getAccount(); + Pattern instanceHost = Pattern.compile("https?://([\\da-z.-]+\\.[a-z.]{2,10})"); + Matcher matcher = instanceHost.matcher(status.getUrl()); + String instance = null; + while (matcher.find()) { + instance = matcher.group(1); + } + account.setInstance(instance); + if (BaseMainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) + CrossActions.doCrossProfile(context, account); + else { + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putParcelable("account", status.getAccount()); + b.putBoolean("peertubeaccount", true); + intent.putExtras(b); + context.startActivity(intent); } } } @@ -3297,12 +3115,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct Application application = status.getApplication(); holder.status_toot_app.setText(application.getName()); if (application.getWebsite() != null && !application.getWebsite().trim().equals("null") && application.getWebsite().trim().length() > 0) { - holder.status_toot_app.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Helper.openBrowser(context, application.getWebsite()); - } - }); + holder.status_toot_app.setOnClickListener(v -> Helper.openBrowser(context, application.getWebsite())); } holder.status_toot_app.setVisibility(View.VISIBLE); } else { @@ -3512,21 +3325,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct .asBitmap() .load(!attachment.getType().toLowerCase().equals("audio") ? url : R.drawable.ic_audio_wave) .thumbnail(0.1f) - //.override(640, 480) .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10))) .into(new SimpleTarget() { @Override public void onResourceReady(@NonNull Bitmap resource, Transition transition) { DrawableTransitionOptions.withCrossFade(); - int width = resource.getWidth(); - int height = resource.getHeight(); - - /*if (height < Helper.convertDpToPixel(200, context)) { - double ratio = ((double) Helper.convertDpToPixel(200, context) / (double) height); - width = (int) (ratio * width); - height = (int) Helper.convertDpToPixel(200, context); - resource = Bitmap.createScaledBitmap(resource, width, height, false); - }*/ imageView.setImageBitmap(resource); status.setMedia_height(container.getHeight()); } @@ -3536,21 +3339,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct .asBitmap() .load(!attachment.getType().toLowerCase().equals("audio") ? url : R.drawable.ic_audio_wave) .thumbnail(0.1f) - // .override(640, 480) .apply(new RequestOptions().transforms(new BlurTransformation(50, 3), new RoundedCorners(10))) .into(new SimpleTarget() { @Override public void onResourceReady(@NonNull Bitmap resource, Transition transition) { DrawableTransitionOptions.withCrossFade(); - int width = resource.getWidth(); - int height = resource.getHeight(); - - /*if (height < Helper.convertDpToPixel(200, context)) { - double ratio = ((double) Helper.convertDpToPixel(200, context) / (double) height); - width = (int) (ratio * width); - height = (int) Helper.convertDpToPixel(200, context); - resource = Bitmap.createScaledBitmap(resource, width, height, false); - }*/ imageView.setImageBitmap(resource); } }); @@ -3580,60 +3373,47 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct final int finalPosition = position; if (attachment.getDescription() != null && !attachment.getDescription().equals("null")) imageView.setContentDescription(attachment.getDescription()); - imageView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (status.isAttachmentShown()) { + imageView.setOnClickListener(v -> { + if (status.isAttachmentShown()) { - ArrayList attachmentArrayList; - if (status.getReblog() == null) - attachmentArrayList = status.getMedia_attachments(); - else - attachmentArrayList = status.getReblog().getMedia_attachments(); - if (attachment.getType().equals("web")) { - Helper.openBrowser(context, attachment.getUrl()); - } else { - Intent intent = new Intent(context, SlideMediaActivity.class); - Bundle b = new Bundle(); - intent.putParcelableArrayListExtra("mediaArray", attachmentArrayList); - b.putInt("position", finalPosition); - intent.putExtras(b); - context.startActivity(intent); - } + ArrayList attachmentArrayList; + if (status.getReblog() == null) + attachmentArrayList = status.getMedia_attachments(); + else + attachmentArrayList = status.getReblog().getMedia_attachments(); + if (attachment.getType().equals("web")) { + Helper.openBrowser(context, attachment.getUrl()); } else { - status.setAttachmentShown(true); - notifyStatusChanged(status); - /* - Added a Countdown Timer, so that Sensitive (NSFW) - images only get displayed for user set time, - giving the user time to click on them to expand them, - if they want. Images are then hidden again. - -> Default value is set to 5 seconds - */ - final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5); - if (timeout > 0) { - new CountDownTimer((timeout * 1000), 1000) { - public void onTick(long millisUntilFinished) { - } + Intent intent = new Intent(context, SlideMediaActivity.class); + Bundle b = new Bundle(); + intent.putParcelableArrayListExtra("mediaArray", attachmentArrayList); + b.putInt("position", finalPosition); + intent.putExtras(b); + context.startActivity(intent); + } + } else { + status.setAttachmentShown(true); + notifyStatusChanged(status); + final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5); + if (timeout > 0) { + new CountDownTimer((timeout * 1000), 1000) { + public void onTick(long millisUntilFinished) { + } - public void onFinish() { - status.setAttachmentShown(false); - notifyStatusChanged(status); - } - }.start(); - } + public void onFinish() { + status.setAttachmentShown(false); + notifyStatusChanged(status); + } + }.start(); } } }); boolean long_press_media = sharedpreferences.getBoolean(Helper.SET_LONG_PRESS_MEDIA, true); if (long_press_media) { String finalUrl = url; - imageView.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - Helper.manageMove(context, finalUrl, false); - return true; - } + imageView.setOnLongClickListener(v -> { + Helper.manageMove(context, finalUrl, false); + return true; }); } i++; @@ -3687,72 +3467,56 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct 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) { + 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_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_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(); + } + Calendar calendar = new GregorianCalendar(datePicker.getYear(), + datePicker.getMonth(), + datePicker.getDayOfMonth(), + hour, + minute); + long time = calendar.getTimeInMillis(); + if ((time - new Date().getTime()) < 60000) { + Toasty.error(context, context.getString(R.string.timed_mute_date_error), Toast.LENGTH_LONG).show(); + } else { + //Store the toot as draft first + String targeted_id = status.getAccount().getId(); + Date date_mute = new Date(time); + SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); + new TempMuteDAO(context, db).insert(account, targeted_id, new Date(time)); + if (mutedAccount != null && !mutedAccount.contains(account.getId())) + mutedAccount.add(targeted_id); + else if (mutedAccount == null) { + mutedAccount = new ArrayList<>(); + mutedAccount.add(targeted_id); + } + Toasty.success(context, context.getString(R.string.timed_mute_date, status.getAccount().getAcct(), Helper.dateToString(date_mute)), Toast.LENGTH_LONG).show(); alertDialog.dismiss(); - } - }); - 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(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(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 { - //noinspection deprecation - hour = timePicker.getCurrentHour(); - //noinspection deprecation - minute = timePicker.getCurrentMinute(); - } - Calendar calendar = new GregorianCalendar(datePicker.getYear(), - datePicker.getMonth(), - datePicker.getDayOfMonth(), - hour, - minute); - long time = calendar.getTimeInMillis(); - if ((time - new Date().getTime()) < 60000) { - Toasty.error(context, context.getString(R.string.timed_mute_date_error), Toast.LENGTH_LONG).show(); - } else { - //Store the toot as draft first - String targeted_id = status.getAccount().getId(); - Date date_mute = new Date(time); - SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, null); - String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - Account account = new AccountDAO(context, db).getUniqAccount(userId, instance); - new TempMuteDAO(context, db).insert(account, targeted_id, new Date(time)); - if (mutedAccount != null && !mutedAccount.contains(account.getId())) - mutedAccount.add(targeted_id); - else if (mutedAccount == null) { - mutedAccount = new ArrayList<>(); - mutedAccount.add(targeted_id); - } - Toasty.success(context, context.getString(R.string.timed_mute_date, status.getAccount().getAcct(), Helper.dateToString(date_mute)), Toast.LENGTH_LONG).show(); - alertDialog.dismiss(); - send_delete_statuses(targeted_id); - } + send_delete_statuses(targeted_id); } }); alertDialog.show(); @@ -3802,95 +3566,60 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct final ImageButton date_time_setBoost = dialogViewBoost.findViewById(R.id.date_time_set); //Buttons management - date_time_cancelBoost.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + date_time_cancelBoost.setOnClickListener(v -> alertDialogBoost.dismiss()); + date_time_nextBoost.setOnClickListener(v -> { + datePickerBoost.setVisibility(View.GONE); + timePickerBoost.setVisibility(View.VISIBLE); + date_time_previousBoost.setVisibility(View.VISIBLE); + date_time_nextBoost.setVisibility(View.GONE); + date_time_setBoost.setVisibility(View.VISIBLE); + }); + date_time_previousBoost.setOnClickListener(v -> { + datePickerBoost.setVisibility(View.VISIBLE); + timePickerBoost.setVisibility(View.GONE); + date_time_previousBoost.setVisibility(View.GONE); + date_time_nextBoost.setVisibility(View.VISIBLE); + date_time_setBoost.setVisibility(View.GONE); + }); + date_time_setBoost.setOnClickListener(v -> { + int hour, minute; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + hour = timePickerBoost.getHour(); + minute = timePickerBoost.getMinute(); + } else { + hour = timePickerBoost.getCurrentHour(); + minute = timePickerBoost.getCurrentMinute(); + } + Calendar calendar = new GregorianCalendar(datePickerBoost.getYear(), + datePickerBoost.getMonth(), + datePickerBoost.getDayOfMonth(), + hour, + minute); + long time = calendar.getTimeInMillis(); + if ((time - new Date().getTime()) < 60000) { + Toasty.warning(context, context.getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show(); + } else { + //Schedules the toot + ScheduledBoostsSyncJob.schedule(context, status, time); + //Clear content + Toasty.info(context, context.getString(R.string.boost_scheduled), Toast.LENGTH_LONG).show(); alertDialogBoost.dismiss(); } }); - date_time_nextBoost.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - datePickerBoost.setVisibility(View.GONE); - timePickerBoost.setVisibility(View.VISIBLE); - date_time_previousBoost.setVisibility(View.VISIBLE); - date_time_nextBoost.setVisibility(View.GONE); - date_time_setBoost.setVisibility(View.VISIBLE); - } - }); - date_time_previousBoost.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - datePickerBoost.setVisibility(View.VISIBLE); - timePickerBoost.setVisibility(View.GONE); - date_time_previousBoost.setVisibility(View.GONE); - date_time_nextBoost.setVisibility(View.VISIBLE); - date_time_setBoost.setVisibility(View.GONE); - } - }); - date_time_setBoost.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - int hour, minute; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - hour = timePickerBoost.getHour(); - minute = timePickerBoost.getMinute(); - } else { - //noinspection deprecation - hour = timePickerBoost.getCurrentHour(); - //noinspection deprecation - minute = timePickerBoost.getCurrentMinute(); - } - Calendar calendar = new GregorianCalendar(datePickerBoost.getYear(), - datePickerBoost.getMonth(), - datePickerBoost.getDayOfMonth(), - hour, - minute); - long time = calendar.getTimeInMillis(); - if ((time - new Date().getTime()) < 60000) { - Toasty.warning(context, context.getString(R.string.toot_scheduled_date), Toast.LENGTH_LONG).show(); - } else { - //Schedules the toot - ScheduledBoostsSyncJob.schedule(context, status, time); - //Clear content - Toasty.info(context, context.getString(R.string.boost_scheduled), Toast.LENGTH_LONG).show(); - alertDialogBoost.dismiss(); - } - } - }); alertDialogBoost.show(); } private void mention(Status status) { // Get a handler that can be used to post to the main thread final Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - /*String name = "@" + (status.getReblog() != null ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct()); - if (name.split("@", -1).length - 1 == 1) - name = name + "@" + getLiveInstance(context); - Bitmap bitmap = Helper.convertTootIntoBitmap(context, name, holder.status_content);*/ - Intent intent = new Intent(context, TootActivity.class); - Bundle b = new Bundle(); - /*String fname = "tootmention_" + status.getId() + ".jpg"; - File file = new File(context.getCacheDir() + "/", fname); - if (file.exists()) //noinspection ResultOfMethodCallIgnored - file.delete(); - try { - FileOutputStream out = new FileOutputStream(file); - assert bitmap != null; - bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); - out.flush(); - out.close(); - } catch (Exception ignored) { - } - b.putString("fileMention", fname);*/ - b.putString("tootMention", (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct()); - b.putString("urlMention", (status.getReblog() != null) ? status.getReblog().getUrl() : status.getUrl()); - intent.putExtras(b); - context.startActivity(intent); - } + handler.postDelayed(() -> { + Intent intent = new Intent(context, TootActivity.class); + Bundle b = new Bundle(); + + b.putString("tootMention", (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct()); + b.putString("urlMention", (status.getReblog() != null) ? status.getReblog().getUrl() : status.getUrl()); + intent.putExtras(b); + context.startActivity(intent); }, 500); } @@ -3956,38 +3685,29 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct textView.setText(""); final SwitchCompat report_mention = preview.findViewById(R.id.report_mention); int finalSplit_toot_size = split_toot_size; - report_mention.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - splitToot = Helper.splitToots(toot_content.getText().toString().trim(), finalSplit_toot_size, isChecked); - textView.setText(""); - int inc = 0; - for (String prev : splitToot) { - if (inc < splitToot.size() - 1) { - textView.setText(textView.getText() + prev + "\n----------\n"); - } + report_mention.setOnCheckedChangeListener((buttonView, isChecked) -> { + splitToot = Helper.splitToots(toot_content.getText().toString().trim(), finalSplit_toot_size, isChecked); + textView.setText(""); + int inc = 0; + for (String prev : splitToot) { + if (inc < splitToot.size() - 1) { + String text = textView.getText() + prev + "\n----------\n"; + textView.setText(text); } } }); int inc = 0; for (String prev : splitToot) { if (inc < splitToot.size() - 1) { - textView.setText(textView.getText() + prev + "\n----------\n"); + String text = textView.getText() + prev + "\n----------\n"; + textView.setText(text); } } - builderInner.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - builderInner.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - createAndSendToot(status, splitToot.get(0), content_type, userId, instance); - dialog.dismiss(); - } + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { + createAndSendToot(status, splitToot.get(0), content_type, userId, instance); + dialog.dismiss(); }); AlertDialog alertDialog = builderInner.create(); alertDialog.show(); @@ -4043,7 +3763,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct @Override public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) { - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); if (error != null) { Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show(); return; @@ -4173,9 +3892,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct String api_key; - if (trans == Helper.TRANS_YANDEX) { - et = MyTransL.translatorEngine.YANDEX; - } else if (trans == Helper.TRANS_DEEPL) { + if (trans == Helper.TRANS_DEEPL) { et = MyTransL.translatorEngine.DEEPL; } else if (trans == Helper.TRANS_SYSTRAN) { et = MyTransL.translatorEngine.SYSTRAN; @@ -4263,7 +3980,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct } } - private class ViewHolderEmpty extends RecyclerView.ViewHolder { + private static class ViewHolderEmpty extends RecyclerView.ViewHolder { ViewHolderEmpty(View itemView) { super(itemView); } @@ -4371,6 +4088,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct View translation_border_view; TextView translation_label; + @SuppressLint("SetJavaScriptEnabled") ViewHolder(View itemView) { super(itemView); fetch_more = itemView.findViewById(R.id.fetch_more); @@ -4438,7 +4156,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status_cardview_content = itemView.findViewById(R.id.status_cardview_content); status_cardview_url = itemView.findViewById(R.id.status_cardview_url); status_cardview_video = itemView.findViewById(R.id.status_cardview_video); - //status_cardview_webview = itemView.findViewById(R.id.status_cardview_webview); status_cardview_webview = Helper.initializeWebview((Activity) context, R.id.status_cardview_webview, itemView); status_cardview_webview.getSettings().setJavaScriptEnabled(true); hide_preview = itemView.findViewById(R.id.hide_preview); @@ -4494,9 +4211,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct status_reply_indicator_diag_top = itemView.findViewById(R.id.status_reply_indicator_diag_top); status_reply_indicator_diag_bottom = itemView.findViewById(R.id.status_reply_indicator_diag_bottom); reply_indicator_dot = itemView.findViewById(R.id.reply_indicator_dot); - Context context = itemView.getContext(); - final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); main_card_container = itemView.findViewById(R.id.main_card_container); main_linear_container = itemView.findViewById(R.id.main_linear_container); translation_border_view = itemView.findViewById(R.id.translation_border_view); diff --git a/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java b/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java index b609a9a9c..110154013 100644 --- a/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java @@ -25,7 +25,6 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -49,6 +48,8 @@ import com.bumptech.glide.RequestBuilder; import com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader; import com.bumptech.glide.util.FixedPreloadSizeProvider; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -97,7 +98,7 @@ import es.dmoral.toasty.Toasty; public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsInterface, OnRetrieveMissingFeedsInterface, OnRetrieveFeedsAfterBookmarkInterface, OnListActionInterface { - LinearLayoutManager mLayoutManager; + private LinearLayoutManager mLayoutManager; private boolean flag_loading; private Context context; private AsyncTask asyncTask; @@ -122,7 +123,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private SharedPreferences sharedpreferences; private boolean isSwipped; private String remoteInstance; - private List mutedAccount; private String instanceType; private String search_peertube, remote_channel_name; private String initialBookMark; @@ -206,9 +206,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn ListPreloader.PreloadSizeProvider sizeProvider = new FixedPreloadSizeProvider(640, 480); ListPreloader.PreloadModelProvider modelProvider = new MyPreloadModelProvider(); - RecyclerViewPreloader preloader = - new RecyclerViewPreloader<>( - Glide.with(context), modelProvider, sizeProvider, 20 ); + RecyclerViewPreloader preloader = + new RecyclerViewPreloader<>(Glide.with(context), modelProvider, sizeProvider, 20 ); lv_status.addOnScrollListener(preloader); mainLoader = rootView.findViewById(R.id.loader); @@ -359,55 +358,46 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if (instanceType == null || (!instanceType.equals("PEERTUBE") && !instanceType.equals("NITTER"))) { - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - if (type == RetrieveFeedsAsyncTask.Type.HOME || type == RetrieveFeedsAsyncTask.Type.PF_HOME) - MainActivity.countNewStatus = 0; - isSwipped = true; - if (type != RetrieveFeedsAsyncTask.Type.CONVERSATION) + swipeRefreshLayout.setOnRefreshListener(() -> { + if (type == RetrieveFeedsAsyncTask.Type.HOME || type == RetrieveFeedsAsyncTask.Type.PF_HOME) + MainActivity.countNewStatus = 0; + isSwipped = true; + if (type != RetrieveFeedsAsyncTask.Type.CONVERSATION) + retrieveMissingToots(null); + else { + if (statuses.size() > 0) + retrieveMissingToots(statuses.get(0).getId()); + else retrieveMissingToots(null); - else { - if (statuses.size() > 0) - retrieveMissingToots(statuses.get(0).getId()); - else - retrieveMissingToots(null); - } - } + }); }else if(instanceType.equals("PEERTUBE")){ - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - if (peertubes.size() > 0) { - int size = peertubes.size(); - isSwipped = true; - peertubes.clear(); - peertubes = new ArrayList<>(); - max_id = "0"; - peertubeAdapater.notifyItemRangeRemoved(0, size); - if (search_peertube == null) { //Not a Peertube search - asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, "0", DisplayStatusFragment.this).execute(); - } else { - asyncTask = new RetrievePeertubeSearchAsyncTask(context, remoteInstance, search_peertube, DisplayStatusFragment.this).execute(); - } + swipeRefreshLayout.setOnRefreshListener(() -> { + if (peertubes.size() > 0) { + int size = peertubes.size(); + isSwipped = true; + peertubes.clear(); + peertubes = new ArrayList<>(); + max_id = "0"; + peertubeAdapater.notifyItemRangeRemoved(0, size); + if (search_peertube == null) { //Not a Peertube search + asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, "0", DisplayStatusFragment.this).execute(); + } else { + asyncTask = new RetrievePeertubeSearchAsyncTask(context, remoteInstance, search_peertube, DisplayStatusFragment.this).execute(); } } }); }else { - swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - if (statuses.size() > 0) { - int size = statuses.size(); - isSwipped = true; - statuses.clear(); - statuses = new ArrayList<>(); - max_id = null; - statusListAdapter.notifyItemRangeRemoved(0, size); - asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).execute(); - } + swipeRefreshLayout.setOnRefreshListener(() -> { + if (statuses.size() > 0) { + int size = statuses.size(); + isSwipped = true; + statuses.clear(); + statuses = new ArrayList<>(); + max_id = null; + statusListAdapter.notifyItemRangeRemoved(0, size); + asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).execute(); } }); @@ -417,12 +407,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn //Load data depending of the value manageAsyncTask(false); } else { - new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { - @Override - public void run() { - if (context != null) { - manageAsyncTask(false); - } + new Handler(Looper.getMainLooper()).postDelayed(() -> { + if (context != null) { + manageAsyncTask(false); } }, 500); } @@ -466,7 +453,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn @Override - public void onAttach(Context context) { + public void onAttach(@NotNull Context context) { super.onAttach(context); this.context = context; } @@ -532,7 +519,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn max_id = "0"; //max_id needs to work like an offset int tootPerPage = sharedpreferences.getInt(Helper.SET_TOOT_PER_PAGE, Helper.TOOTS_PER_PAGE); - max_id = String.valueOf(Integer.valueOf(max_id) + tootPerPage); + max_id = String.valueOf(Integer.parseInt(max_id) + tootPerPage); if (apiResponse.getPeertubes() == null) { return; } @@ -608,11 +595,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if (max_id == null) max_id = "1"; //max_id needs to work like an offset - max_id = String.valueOf(Integer.valueOf(max_id) + 1); + max_id = String.valueOf(Integer.parseInt(max_id) + 1); } else if (type == RetrieveFeedsAsyncTask.Type.SEARCH && !tag.contains("_cache_")) { if (max_id == null) max_id = "0"; - max_id = String.valueOf(Integer.valueOf(max_id) + 20); + max_id = String.valueOf(Integer.parseInt(max_id) + 20); } else { max_id = apiResponse.getMax_id(); } @@ -677,7 +664,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn return; if (status.getId() != null && statuses != null && statuses.size() > 0 && statuses.get(0) != null && status.getCreated_at().after(statuses.get(0).getCreated_at())) { - List tempTootResult = new ArrayList(); + List tempTootResult = new ArrayList<>(); tempTootResult.add(status); if (tempTootResult.size() > 0) status = tempTootResult.get(0); @@ -809,7 +796,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn Iterator s = statuses.iterator(); int i = 0; while (s.hasNext() && i < firstVisible) { - Status status = s.next(); + s.next(); s.remove(); statusListAdapter.notifyItemRemoved(0); statusListAdapter.notifyItemChanged(0); @@ -950,12 +937,20 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn Status status = it.next(); for (Status status1 : statuses) { if (status.getConversationId() != null && status.getConversationId().equals(status1.getConversationId())) { - if (instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") || instanceType.equals("NITTER")|| instanceType.equals("GNU")) - statusListAdapter.notifyItemRemoved(position); - else if (instanceType.equals("PIXELFED")) - pixelfedListAdapter.notifyItemRemoved(position); - else if (instanceType.equals("ART")) - artListAdapter.notifyItemRemoved(position); + switch (instanceType) { + case "MASTODON": + case "MISSKEY": + case "NITTER": + case "GNU": + statusListAdapter.notifyItemRemoved(position); + break; + case "PIXELFED": + pixelfedListAdapter.notifyItemRemoved(position); + break; + case "ART": + artListAdapter.notifyItemRemoved(position); + break; + } it.remove(); } } @@ -1186,9 +1181,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if (isSwipped) { if (previousPosition > 0) { - for (int i = 0; i < previousPosition; i++) { - this.statuses.remove(0); - } + this.statuses.subList(0, previousPosition).clear(); statusListAdapter.notifyItemRangeRemoved(0, previousPosition); } isSwipped = false; @@ -1214,6 +1207,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn isSwipped = true; int lenght = statuses.size(); statuses.clear(); + assert instanceType != null; switch (instanceType) { case "MASTODON": case "MISSKEY": diff --git a/build.gradle b/build.gradle index 07aecfa23..2d1d9aae1 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.2' + classpath 'com.android.tools.build:gradle:3.6.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b2b7e6643..f9fed6430 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Aug 23 15:40:43 CEST 2019 +#Fri Mar 06 19:14:19 CET 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip