Merge branch 'bug_fixes' into develop
This commit is contained in:
commit
51a95faa3d
|
@ -206,6 +206,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
private int style;
|
||||
private Activity activity;
|
||||
private HashMap<String, Integer> tabPosition = new HashMap<>();
|
||||
private FloatingActionButton federatedTimelines;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -339,7 +341,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}else {
|
||||
style = R.style.Dialog;
|
||||
}
|
||||
FloatingActionButton federatedTimelines = findViewById(R.id.federated_timeline);
|
||||
federatedTimelines = findViewById(R.id.federated_timeline);
|
||||
|
||||
delete_instance.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -2362,81 +2364,15 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}else if( position == 1) {
|
||||
notificationsFragment = new DisplayNotificationsFragment();
|
||||
return notificationsFragment;
|
||||
}else if( position == 2 && display_direct) {
|
||||
}else {
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
boolean old_direct_timeline = sharedpreferences.getBoolean(Helper.SET_OLD_DIRECT_TIMELINE, false);
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.6");
|
||||
if( old_direct_timeline)
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||
else if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.CONVERSATION);
|
||||
} else {
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||
}
|
||||
}else{
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.DIRECT);
|
||||
bundle.putSerializable("type", Helper.timelineType(getApplicationContext(), position));
|
||||
if( Helper.timelineType(getApplicationContext(), position) == RetrieveFeedsAsyncTask.Type.TAG){
|
||||
if( tabLayout.getTabAt(position) != null && tabLayout.getTabAt(position).getText() != null)
|
||||
bundle.putString("tag", tabLayout.getTabAt(position).getText().toString());
|
||||
}
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
}else if(position == 2 && display_local ){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
}else if(position == 2 && display_global ){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
}else if(position == 2 && display_art ){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.ART);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
} else if (position == 3 && display_local && display_direct){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
}else if (position == 3 && display_global && (display_direct && !display_local) || (!display_direct && display_local)){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
} else if (position == 3 && display_art){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.ART);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
}
|
||||
else if (position == 4 && display_global && display_local && display_direct){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
} else if (position == 4 && display_art){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.ART);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
} else if (position == 5 && countPage == 6){
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.ART);
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
}
|
||||
else{ //Here it's a search fragment
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.TAG);
|
||||
if( tabLayout.getTabAt(position) != null && tabLayout.getTabAt(position).getText() != null)
|
||||
bundle.putString("tag", tabLayout.getTabAt(position).getText().toString());
|
||||
statusFragment.setArguments(bundle);
|
||||
return statusFragment;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2727,6 +2663,24 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
|
||||
}
|
||||
|
||||
public void manageFloatingButton(boolean display){
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean displayFollowInstance = sharedpreferences.getBoolean(Helper.SET_DISPLAY_FOLLOW_INSTANCE, true);
|
||||
if(display){
|
||||
toot.show();
|
||||
if( !displayFollowInstance)
|
||||
federatedTimelines.hide();
|
||||
else
|
||||
federatedTimelines.show();
|
||||
}else{
|
||||
toot.hide();
|
||||
federatedTimelines.hide();
|
||||
}
|
||||
}
|
||||
public boolean getFloatingVisibility(){
|
||||
return toot.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
public void refreshButton(){
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
FloatingActionButton federatedTimelines = findViewById(R.id.federated_timeline);
|
||||
|
|
|
@ -420,9 +420,9 @@ public class LoginActivity extends BaseActivity {
|
|||
parameters.put(Helper.CLIENT_SECRET, sharedpreferences.getString(Helper.CLIENT_SECRET, null));
|
||||
parameters.put("grant_type", "password");
|
||||
try {
|
||||
parameters.put("username",URLEncoder.encode(login_uid.getText().toString().trim(), "UTF-8"));
|
||||
parameters.put("username",URLEncoder.encode(login_uid.getText().toString().trim().toLowerCase(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
parameters.put("username",login_uid.getText().toString().trim());
|
||||
parameters.put("username",login_uid.getText().toString().trim().toLowerCase());
|
||||
}
|
||||
try {
|
||||
parameters.put("password",URLEncoder.encode(login_passwd.getText().toString(), "UTF-8"));
|
||||
|
|
|
@ -189,7 +189,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
private AlertDialog dialogTrans;
|
||||
private AlertDialog alertDialogEmoji;
|
||||
private String mentionAccount;
|
||||
private String idRedirect;
|
||||
private Status idRedirect;
|
||||
private String userId, instance;
|
||||
private Account account;
|
||||
private ArrayList<String> splitToot;
|
||||
|
@ -327,7 +327,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
sharedContentIni = b.getString("sharedContent", null);
|
||||
sharedSubject = b.getString("sharedSubject", null);
|
||||
mentionAccount = b.getString("mentionAccount", null);
|
||||
idRedirect = b.getString("idRedirect");
|
||||
idRedirect = b.getParcelable("idRedirect");
|
||||
removed = b.getBoolean("removed");
|
||||
visibility = b.getString("visibility", null);
|
||||
restoredScheduled = b.getBoolean("restoredScheduled", false);
|
||||
|
@ -1690,7 +1690,7 @@ public class TootActivity extends BaseActivity implements OnRetrieveSearcAccount
|
|||
if( idRedirect == null)
|
||||
b.putParcelable("status", status);
|
||||
else {
|
||||
b.putString("status", idRedirect);
|
||||
b.putParcelable("status", idRedirect);
|
||||
}
|
||||
intent.putExtras(b);
|
||||
startActivity(intent);
|
||||
|
|
|
@ -1103,19 +1103,21 @@ public class API {
|
|||
apiResponseReply.setStatuses(new ArrayList<>());
|
||||
if( apiResponse.getStatuses() != null && apiResponse.getStatuses().size() > 0){
|
||||
for( Status status: apiResponse.getStatuses()){
|
||||
if( status.getMedia_attachments().size() > 1){
|
||||
String statusSerialized = Helper.statusToStringStorage(status);
|
||||
for(Attachment attachment: status.getMedia_attachments()){
|
||||
ArrayList<Attachment> attachments = new ArrayList<>();
|
||||
attachments.add(attachment);
|
||||
Status newStatus = Helper.restoreStatusFromString(statusSerialized);
|
||||
if( newStatus == null)
|
||||
break;
|
||||
newStatus.setMedia_attachments(attachments);
|
||||
apiResponseReply.getStatuses().add(newStatus);
|
||||
if( status.getMedia_attachments() != null ) {
|
||||
if (status.getMedia_attachments().size() > 1) {
|
||||
String statusSerialized = Helper.statusToStringStorage(status);
|
||||
for (Attachment attachment : status.getMedia_attachments()) {
|
||||
ArrayList<Attachment> attachments = new ArrayList<>();
|
||||
attachments.add(attachment);
|
||||
Status newStatus = Helper.restoreStatusFromString(statusSerialized);
|
||||
if (newStatus == null)
|
||||
break;
|
||||
newStatus.setMedia_attachments(attachments);
|
||||
apiResponseReply.getStatuses().add(newStatus);
|
||||
}
|
||||
} else if (status.getMedia_attachments().size() == 1) {
|
||||
apiResponseReply.getStatuses().add(status);
|
||||
}
|
||||
}else if (status.getMedia_attachments().size() == 1) {
|
||||
apiResponseReply.getStatuses().add(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3526,7 +3528,8 @@ public class API {
|
|||
String errorM = jsonObject.get("error").toString();
|
||||
message = "Error " + statusCode + " : " + errorM;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
String errorM = error.getMessage().split(".")[0];
|
||||
message = "Error " + statusCode + " : " + errorM;
|
||||
}
|
||||
APIError.setError(message);
|
||||
apiResponse.setError(APIError);
|
||||
|
|
|
@ -57,7 +57,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.HashTagActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.PeertubeActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
|
@ -65,9 +64,6 @@ import fr.gouv.etalab.mastodon.helper.CrossActions;
|
|||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_REMOTE;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.SEARCH_URL;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_DARK;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
|
||||
|
@ -134,16 +130,16 @@ public class Status implements Parcelable{
|
|||
in_reply_to_id = in.readString();
|
||||
conversationId = in.readString();
|
||||
in_reply_to_account_id = in.readString();
|
||||
content = in.readString();
|
||||
contentCW = in.readString();
|
||||
created_at = (java.util.Date) in.readSerializable();
|
||||
visibility = in.readString();
|
||||
media_attachments = in.readArrayList(Attachment.class.getClassLoader());
|
||||
reblog = in.readParcelable(Status.class.getClassLoader());
|
||||
card = in.readParcelable(Card.class.getClassLoader());
|
||||
account = in.readParcelable(Account.class.getClassLoader());
|
||||
application = in.readParcelable(Application.class.getClassLoader());
|
||||
mentions = in.readArrayList(Mention.class.getClassLoader());
|
||||
media_attachments = in.readArrayList(Attachment.class.getClassLoader());
|
||||
emojis = in.readArrayList(Emojis.class.getClassLoader());
|
||||
tags = in.readArrayList(Tag.class.getClassLoader());
|
||||
content = in.readString();
|
||||
created_at = (java.util.Date) in.readSerializable();
|
||||
contentTranslated = in.readString();
|
||||
reblogs_count = in.readInt();
|
||||
itemViewType = in.readInt();
|
||||
|
@ -153,8 +149,6 @@ public class Status implements Parcelable{
|
|||
favourited = in.readByte() != 0;
|
||||
muted = in.readByte() != 0;
|
||||
sensitive = in.readByte() != 0;
|
||||
contentCW = in.readString();
|
||||
visibility = in.readString();
|
||||
language = in.readString();
|
||||
attachmentShown = in.readByte() != 0;
|
||||
spoilerShown = in.readByte() != 0;
|
||||
|
@ -162,6 +156,8 @@ public class Status implements Parcelable{
|
|||
isTranslationShown = in.readByte() != 0;
|
||||
isNew = in.readByte() != 0;
|
||||
pinned = in.readByte() != 0;
|
||||
emojis = in.readArrayList(Emojis.class.getClassLoader());
|
||||
card = in.readParcelable(Card.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -172,16 +168,16 @@ public class Status implements Parcelable{
|
|||
dest.writeString(in_reply_to_id);
|
||||
dest.writeString(conversationId);
|
||||
dest.writeString(in_reply_to_account_id);
|
||||
dest.writeString(content);
|
||||
dest.writeString(contentCW);
|
||||
dest.writeSerializable(created_at);
|
||||
dest.writeString(visibility);
|
||||
dest.writeList(media_attachments);
|
||||
dest.writeParcelable(reblog, flags);
|
||||
dest.writeParcelable(card, flags);
|
||||
dest.writeParcelable(account, flags);
|
||||
dest.writeParcelable(application, flags);
|
||||
dest.writeList(mentions);
|
||||
dest.writeList(media_attachments);
|
||||
dest.writeList(emojis);
|
||||
dest.writeList(tags);
|
||||
dest.writeString(content);
|
||||
dest.writeSerializable(created_at);
|
||||
dest.writeString(contentTranslated);
|
||||
dest.writeInt(reblogs_count);
|
||||
dest.writeInt(itemViewType);
|
||||
|
@ -191,8 +187,6 @@ public class Status implements Parcelable{
|
|||
dest.writeByte((byte) (favourited ? 1 : 0));
|
||||
dest.writeByte((byte) (muted ? 1 : 0));
|
||||
dest.writeByte((byte) (sensitive ? 1 : 0));
|
||||
dest.writeString(contentCW);
|
||||
dest.writeString(visibility);
|
||||
dest.writeString(language);
|
||||
dest.writeByte((byte) (attachmentShown ? 1 : 0));
|
||||
dest.writeByte((byte) (spoilerShown ? 1 : 0));
|
||||
|
@ -200,6 +194,8 @@ public class Status implements Parcelable{
|
|||
dest.writeByte((byte) (isTranslationShown ? 1 : 0));
|
||||
dest.writeByte((byte) (isNew ? 1 : 0));
|
||||
dest.writeByte((byte) (pinned ? 1 : 0));
|
||||
dest.writeList(emojis);
|
||||
dest.writeParcelable(card, flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -491,11 +487,16 @@ public class Status implements Parcelable{
|
|||
if( (status.getReblog() != null && status.getReblog().getContent() == null) || (status.getReblog() == null && status.getContent() == null))
|
||||
return;
|
||||
spannableStringContent = new SpannableString(status.getReblog() != null ?status.getReblog().getContent():status.getContent());
|
||||
String spoilerText = "";
|
||||
if( status.getReblog() != null && status.getReblog().getSpoiler_text() != null)
|
||||
spoilerText = status.getReblog().getSpoiler_text();
|
||||
else if( status.getSpoiler_text() != null)
|
||||
spoilerText = status.getSpoiler_text();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
spannableStringCW = new SpannableString(Html.fromHtml(status.getReblog() != null ?status.getReblog().getSpoiler_text():status.getSpoiler_text(), Html.FROM_HTML_MODE_LEGACY));
|
||||
spannableStringCW = new SpannableString(Html.fromHtml(spoilerText, Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
//noinspection deprecation
|
||||
spannableStringCW = new SpannableString(Html.fromHtml(status.getReblog() != null ?status.getReblog().getSpoiler_text():status.getSpoiler_text()));
|
||||
spannableStringCW = new SpannableString(Html.fromHtml(spoilerText));
|
||||
if( spannableStringContent.length() > 0)
|
||||
status.setContentSpan(treatment(context, spannableStringContent, status));
|
||||
if( spannableStringCW.length() > 0)
|
||||
|
@ -879,10 +880,15 @@ public class Status implements Parcelable{
|
|||
Pattern link = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/(@[\\w._-]*[0-9]*)(\\/[0-9]{1,})?$");
|
||||
Matcher matcherLink = link.matcher(url);
|
||||
if( matcherLink.find()){
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.putExtra(INTENT_ACTION, SEARCH_REMOTE);
|
||||
intent.putExtra(SEARCH_URL, url);
|
||||
context.startActivity(intent);
|
||||
if( matcherLink.group(3) != null && matcherLink.group(3).length() > 0 ){ //It's a toot
|
||||
CrossActions.doCrossConversation(context, finalUrl);
|
||||
}else{//It's an account
|
||||
Account account = status.getAccount();
|
||||
account.setAcct(matcherLink.group(2));
|
||||
account.setInstance(matcherLink.group(1));
|
||||
CrossActions.doCrossProfile(context, account);
|
||||
}
|
||||
|
||||
}else {
|
||||
link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/watch\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$");
|
||||
matcherLink = link.matcher(url);
|
||||
|
|
|
@ -303,7 +303,8 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
changeDrawableColor(context, R.drawable.ic_remove_red_eye,R.color.black);
|
||||
changeDrawableColor(context, holder.notification_delete,R.color.black);
|
||||
}
|
||||
|
||||
holder.spark_button_fav.pressOnTouch(false);
|
||||
holder.spark_button_reblog.pressOnTouch(false);
|
||||
holder.spark_button_fav.setActiveImageTint(R.color.marked_icon);
|
||||
holder.spark_button_reblog.setActiveImageTint(R.color.boost_icon);
|
||||
holder.spark_button_fav.setDisableCircle(true);
|
||||
|
@ -594,20 +595,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
}
|
||||
});
|
||||
|
||||
holder.status_favorite_count.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossAction(context, null, status, null, status.isFavourited()? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, notificationsListAdapter, NotificationsListAdapter.this, true);
|
||||
}
|
||||
});
|
||||
|
||||
holder.status_reblog_count.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
CrossActions.doCrossAction(context, null, status, null, status.isReblogged()? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, notificationsListAdapter, NotificationsListAdapter.this, true);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
holder.status_reply.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -617,7 +605,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
});
|
||||
|
||||
if( !status.getVisibility().equals("direct"))
|
||||
holder.status_favorite_count.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
holder.spark_button_fav.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
CrossActions.doCrossAction(context, null, status, null, status.isFavourited()? API.StatusAction.UNFAVOURITE:API.StatusAction.FAVOURITE, notificationsListAdapter, NotificationsListAdapter.this, false);
|
||||
|
@ -633,7 +621,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
}
|
||||
});
|
||||
if( !status.getVisibility().equals("direct"))
|
||||
holder.status_reblog_count.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
holder.spark_button_reblog.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
CrossActions.doCrossAction(context, null, status, null, status.isReblogged()? API.StatusAction.UNREBLOG:API.StatusAction.REBLOG, notificationsListAdapter, NotificationsListAdapter.this, false);
|
||||
|
|
|
@ -441,12 +441,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int position) {
|
||||
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.ART) {
|
||||
final ViewHolderArt holder = (ViewHolderArt) viewHolder;
|
||||
final Status status = statuses.get(position);
|
||||
final Status status = statuses.get(viewHolder.getAdapterPosition());
|
||||
|
||||
if( !status.isClickable())
|
||||
Status.transform(context, status);
|
||||
|
@ -502,7 +502,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
}else if( viewHolder.getItemViewType() == DISPLAYED_STATUS || viewHolder.getItemViewType() == FOCUSED_STATUS || viewHolder.getItemViewType() == COMPACT_STATUS){
|
||||
final ViewHolder holder = (ViewHolder) viewHolder;
|
||||
final Status status = statuses.get(position);
|
||||
final Status status = statuses.get(viewHolder.getAdapterPosition());
|
||||
|
||||
|
||||
status.setItemViewType(viewHolder.getItemViewType());
|
||||
|
@ -552,14 +552,14 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.status_privacy.getLayoutParams().width = (int) Helper.convertDpToPixel((20*iconSizePercent/100), context);
|
||||
|
||||
|
||||
if( isCompactMode && type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) != FOCUSED_STATUS && position != 0 ){
|
||||
if( isCompactMode && type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(viewHolder.getAdapterPosition()) != FOCUSED_STATUS && viewHolder.getAdapterPosition() != 0 ){
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
params.setMargins((int)Helper.convertDpToPixel(25, context), 0, 0, 0);
|
||||
holder.main_container.setLayoutParams(params);
|
||||
}else if(isCompactMode && type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(position) == FOCUSED_STATUS && position != 0 ){
|
||||
}else if(isCompactMode && type == RetrieveFeedsAsyncTask.Type.CONTEXT && getItemViewType(viewHolder.getAdapterPosition()) == FOCUSED_STATUS && viewHolder.getAdapterPosition() != 0 ){
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
|
@ -569,7 +569,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
|
||||
|
||||
if( getItemViewType(position) == FOCUSED_STATUS ) {
|
||||
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);
|
||||
|
@ -604,7 +604,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
else
|
||||
changeDrawableColor(context, R.drawable.ic_fiber_new,R.color.mastodonC4);
|
||||
|
||||
if( getItemViewType(position) == COMPACT_STATUS )
|
||||
if( getItemViewType(viewHolder.getAdapterPosition()) == COMPACT_STATUS )
|
||||
holder.status_privacy.setVisibility(View.GONE);
|
||||
else
|
||||
holder.status_privacy.setVisibility(View.VISIBLE);
|
||||
|
@ -713,6 +713,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
//Redraws top icons (boost/reply)
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
holder.spark_button_fav.pressOnTouch(false);
|
||||
holder.spark_button_reblog.pressOnTouch(false);
|
||||
holder.spark_button_fav.setActiveImage(R.drawable.ic_star);
|
||||
holder.spark_button_fav.setInactiveImage(R.drawable.ic_star_border);
|
||||
holder.spark_button_fav.setDisableCircle(true);
|
||||
|
@ -755,13 +757,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams((int)Helper.convertDpToPixel(60, context), LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
if( status.getReblog() == null && !isCompactMode && getItemViewType(position) != FOCUSED_STATUS){
|
||||
if( status.getReblog() == null && !isCompactMode && getItemViewType(viewHolder.getAdapterPosition()) != FOCUSED_STATUS){
|
||||
params.setMargins(0,-(int)Helper.convertDpToPixel(10, context),0,0);
|
||||
if (status.getSpoiler_text() != null && status.getSpoiler_text().trim().length() > 0 )
|
||||
paramsB.setMargins(0,0,0,0);
|
||||
else
|
||||
paramsB.setMargins(0,(int)Helper.convertDpToPixel(15, context),0,0);
|
||||
}else if( !isCompactMode && getItemViewType(position) != FOCUSED_STATUS){
|
||||
}else if( !isCompactMode && getItemViewType(viewHolder.getAdapterPosition()) != FOCUSED_STATUS){
|
||||
if( status.getContent() == null || status.getContent().trim().equals(""))
|
||||
params.setMargins(0,-(int)Helper.convertDpToPixel(20, context),0,0);
|
||||
else
|
||||
|
@ -787,7 +789,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
});
|
||||
//Click on a conversation
|
||||
if( (getItemViewType(position) == DISPLAYED_STATUS || getItemViewType(position) == COMPACT_STATUS)) {
|
||||
if( (getItemViewType(viewHolder.getAdapterPosition()) == DISPLAYED_STATUS || getItemViewType(viewHolder.getAdapterPosition()) == COMPACT_STATUS)) {
|
||||
holder.status_content.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -1000,7 +1002,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.status_mention_spoiler.setText(Helper.makeMentionsClick(context,status.getMentions()), TextView.BufferType.SPANNABLE);
|
||||
holder.status_mention_spoiler.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
if( getItemViewType(position) != COMPACT_STATUS ) {
|
||||
if( getItemViewType(viewHolder.getAdapterPosition()) != COMPACT_STATUS ) {
|
||||
if( status.getReblog() == null)
|
||||
holder.status_favorite_count.setText(String.valueOf(status.getFavourites_count()));
|
||||
else
|
||||
|
@ -1010,7 +1012,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
else
|
||||
holder.status_reblog_count.setText(String.valueOf(status.getReblog().getReblogs_count()));
|
||||
}
|
||||
if( getItemViewType(position) == FOCUSED_STATUS) {
|
||||
if( getItemViewType(viewHolder.getAdapterPosition()) == FOCUSED_STATUS) {
|
||||
String fullDate_tmp = Helper.dateDiffFull(status.getCreated_at());
|
||||
String fullDate = "";
|
||||
if( !fullDate_tmp.equals(""))
|
||||
|
@ -1088,15 +1090,15 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
else
|
||||
differentLanguage = status.getReblog().getLanguage() != null && !status.getReblog().getLanguage().trim().equals(currentLocale);
|
||||
|
||||
if( ( getItemViewType(position) != COMPACT_STATUS ) && (trans_forced || (translator != Helper.TRANS_NONE && currentLocale != null && differentLanguage))){
|
||||
if( ( getItemViewType(viewHolder.getAdapterPosition()) != COMPACT_STATUS ) && (trans_forced || (translator != Helper.TRANS_NONE && currentLocale != null && differentLanguage))){
|
||||
if( status.getSpoiler_text() != null && status.getSpoiler_text().length() > 0) {
|
||||
if (status.isSpoilerShown() || getItemViewType(position) == FOCUSED_STATUS) {
|
||||
if (status.isSpoilerShown() || getItemViewType(viewHolder.getAdapterPosition()) == FOCUSED_STATUS) {
|
||||
holder.status_translate.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.status_translate.setVisibility(View.GONE);
|
||||
}
|
||||
}else if( status.getReblog() != null && status.getReblog().getSpoiler_text() != null && status.getReblog().getSpoiler_text().length() > 0) {
|
||||
if (status.isSpoilerShown() || getItemViewType(position) == FOCUSED_STATUS) {
|
||||
if (status.isSpoilerShown() || getItemViewType(viewHolder.getAdapterPosition()) == FOCUSED_STATUS) {
|
||||
holder.status_translate.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.status_translate.setVisibility(View.GONE);
|
||||
|
@ -1250,6 +1252,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.status_content_translated_container.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
//TODO:It sounds that sometimes this value is null - need deeper investigation
|
||||
if( status.getVisibility() == null)
|
||||
status.setVisibility("public");
|
||||
|
||||
switch (status.getVisibility()){
|
||||
case "direct":
|
||||
holder.status_reblog_count.setVisibility(View.GONE);
|
||||
|
@ -1384,14 +1390,14 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
holder.webview_preview.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if( (type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition ) || display_card || display_video_preview){
|
||||
if( (type == RetrieveFeedsAsyncTask.Type.CONTEXT && viewHolder.getAdapterPosition() == conversationPosition ) || display_card || display_video_preview){
|
||||
|
||||
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT & position == conversationPosition)
|
||||
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT & viewHolder.getAdapterPosition() == conversationPosition)
|
||||
holder.status_cardview_content.setVisibility(View.VISIBLE);
|
||||
else
|
||||
holder.status_cardview_content.setVisibility(View.GONE);
|
||||
|
||||
if( position == conversationPosition || display_card || display_video_preview){
|
||||
if( viewHolder.getAdapterPosition() == conversationPosition || display_card || display_video_preview){
|
||||
Card card = status.getReblog()!= null?status.getReblog().getCard():status.getCard();
|
||||
if( card != null){
|
||||
holder.status_cardview_content.setText(card.getDescription());
|
||||
|
@ -1406,7 +1412,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
.into(holder.status_cardview_image);
|
||||
}else
|
||||
holder.status_cardview_image.setVisibility(View.GONE);
|
||||
if( !card.getType().equals("video") && ( display_card || position == conversationPosition)) {
|
||||
if( !card.getType().equals("video") && ( display_card || viewHolder.getAdapterPosition() == conversationPosition)) {
|
||||
holder.status_cardview.setVisibility(View.VISIBLE);
|
||||
holder.status_cardview_video.setVisibility(View.GONE);
|
||||
holder.status_cardview.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -1415,7 +1421,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
Helper.openBrowser(context, card.getUrl());
|
||||
}
|
||||
});
|
||||
}else if(card.getType().equals("video") && ( display_video_preview || position == conversationPosition)){
|
||||
}else if(card.getType().equals("video") && ( display_video_preview || viewHolder.getAdapterPosition() == conversationPosition)){
|
||||
Glide.with(holder.status_cardview_image.getContext())
|
||||
.load(card.getImage())
|
||||
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(10)))
|
||||
|
@ -1501,7 +1507,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
});
|
||||
|
||||
if( !status.getVisibility().equals("direct"))
|
||||
holder.status_favorite_count.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
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);
|
||||
|
@ -1509,7 +1515,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
}
|
||||
});
|
||||
if( !status.getVisibility().equals("direct"))
|
||||
holder.status_reblog_count.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
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);
|
||||
|
@ -2037,7 +2043,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
});
|
||||
}
|
||||
|
||||
if( getItemViewType(position) == FOCUSED_STATUS && status.getApplication() != null && status.getApplication().getName() != null && status.getApplication().getName().length() > 0){
|
||||
if( getItemViewType(viewHolder.getAdapterPosition()) == FOCUSED_STATUS && status.getApplication() != null && status.getApplication().getName() != null && status.getApplication().getName().length() > 0){
|
||||
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) {
|
||||
|
|
|
@ -178,6 +178,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
|
||||
{
|
||||
if (type != RetrieveFeedsAsyncTask.Type.ART && context instanceof BaseMainActivity ) {
|
||||
if( dy < 0 && !((BaseMainActivity)context).getFloatingVisibility() )
|
||||
((BaseMainActivity) context).manageFloatingButton(true);
|
||||
if( dy > 0 && ((BaseMainActivity)context).getFloatingVisibility() )
|
||||
((BaseMainActivity) context).manageFloatingButton(false);
|
||||
}
|
||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||
if(dy > 0){
|
||||
int visibleItemCount = mLayoutManager.getChildCount();
|
||||
|
|
|
@ -128,7 +128,13 @@ public class CrossActions {
|
|||
}else {
|
||||
style = R.style.Dialog;
|
||||
}
|
||||
|
||||
boolean confirmation = false;
|
||||
if (doAction == API.StatusAction.UNFAVOURITE || doAction == API.StatusAction.FAVOURITE)
|
||||
confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false);
|
||||
else if (doAction == API.StatusAction.UNREBLOG || doAction == API.StatusAction.REBLOG)
|
||||
confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
|
||||
else if (doAction == API.StatusAction.FOLLOW || doAction == API.StatusAction.UNFOLLOW)
|
||||
confirmation = false;
|
||||
if(type != null && type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && limitedToOwner){
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
@ -136,13 +142,7 @@ public class CrossActions {
|
|||
new PostActionAsyncTask(context, currentAccount, status, doAction, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else if (accounts.size() == 1 || undoAction) {
|
||||
|
||||
boolean confirmation = false;
|
||||
if (doAction == API.StatusAction.UNFAVOURITE || doAction == API.StatusAction.FAVOURITE)
|
||||
confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION_FAV, false);
|
||||
else if (doAction == API.StatusAction.UNREBLOG || doAction == API.StatusAction.REBLOG)
|
||||
confirmation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
|
||||
else if (doAction == API.StatusAction.FOLLOW || doAction == API.StatusAction.UNFOLLOW)
|
||||
confirmation = false;
|
||||
|
||||
if (confirmation)
|
||||
displayConfirmationDialog(context, doAction, status, baseAdapter, onPostActionInterface);
|
||||
else {
|
||||
|
@ -169,6 +169,7 @@ public class CrossActions {
|
|||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
boolean finalConfirmation = confirmation;
|
||||
builderSingle.setAdapter(accountsSearchAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -176,32 +177,39 @@ public class CrossActions {
|
|||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account loggedAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if( targetedAccount == null){
|
||||
if(loggedAccount.getInstance().equals(selectedAccount.getInstance())){
|
||||
new PostActionAsyncTask(context, selectedAccount, doAction, status.getId(), onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else{ //Account is from another instance
|
||||
new PostActionAsyncTask(context, selectedAccount, status, doAction, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
if( selectedAccount.getInstance().equals(loggedAccount.getInstance()) && selectedAccount.getId().equals(loggedAccount.getId())) {
|
||||
if (doAction == API.StatusAction.REBLOG) {
|
||||
status.setReblogged(true);
|
||||
} else if (doAction == API.StatusAction.FAVOURITE) {
|
||||
status.setFavourited(true);
|
||||
} else if (doAction == API.StatusAction.PIN) {
|
||||
status.setPinned(true);
|
||||
if (finalConfirmation)
|
||||
displayConfirmationDialogCrossAction(context, selectedAccount, targetedAccount, doAction, type, status, baseAdapter, onPostActionInterface);
|
||||
else {
|
||||
if( targetedAccount == null){
|
||||
if(loggedAccount.getInstance().equals(selectedAccount.getInstance())){
|
||||
new PostActionAsyncTask(context, selectedAccount, doAction, status.getId(), onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else{ //Account is from another instance
|
||||
new PostActionAsyncTask(context, selectedAccount, status, doAction, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
baseAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}else{
|
||||
new PostActionAsyncTask(context, selectedAccount, targetedAccount, doAction, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( selectedAccount.getInstance().equals(loggedAccount.getInstance()) && selectedAccount.getId().equals(loggedAccount.getId())) {
|
||||
if (doAction == API.StatusAction.FOLLOW) {
|
||||
targetedAccount.setFollowing(true);
|
||||
if( selectedAccount.getInstance().equals(loggedAccount.getInstance()) && selectedAccount.getId().equals(loggedAccount.getId())) {
|
||||
if (doAction == API.StatusAction.REBLOG) {
|
||||
status.setReblogged(true);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
|
||||
status.setBoostAnimated(true);
|
||||
} else if (doAction == API.StatusAction.FAVOURITE) {
|
||||
status.setFavourited(true);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
|
||||
status.setFavAnimated(true);
|
||||
} else if (doAction == API.StatusAction.PIN) {
|
||||
status.setPinned(true);
|
||||
}
|
||||
baseAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}else{
|
||||
new PostActionAsyncTask(context, selectedAccount, targetedAccount, doAction, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( selectedAccount.getInstance().equals(loggedAccount.getInstance()) && selectedAccount.getId().equals(loggedAccount.getId())) {
|
||||
if (doAction == API.StatusAction.FOLLOW) {
|
||||
targetedAccount.setFollowing(true);
|
||||
}
|
||||
baseAdapter.notifyDataSetChanged();
|
||||
}
|
||||
baseAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
@ -326,6 +334,44 @@ public class CrossActions {
|
|||
}
|
||||
|
||||
|
||||
public static void doCrossConversation(final Context context, String url){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(context, db).getAccountByID(userId);
|
||||
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
private WeakReference<Context> contextReference = new WeakReference<>(context);
|
||||
Results response;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
Toasty.info(contextReference.get(), contextReference.get().getString(R.string.retrieve_remote_conversation), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
|
||||
response = api.search(url);
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
if( response == null){
|
||||
return;
|
||||
}
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses = response.getStatuses();
|
||||
if( statuses != null && statuses.size() > 0) {
|
||||
Intent intent = new Intent(context, ShowConversationActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putParcelable("status", statuses.get(0));
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR );
|
||||
}
|
||||
|
||||
public static void doCrossBookmark(final Context context, final Status status, StatusListAdapter statusListAdapter ){
|
||||
List<Account> accounts = connectedAccounts(context, status, false);
|
||||
|
||||
|
@ -672,6 +718,87 @@ public class CrossActions {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Display a validation message
|
||||
* @param action int
|
||||
* @param status Status
|
||||
*/
|
||||
private static void displayConfirmationDialogCrossAction(final Context context,Account selectedAccount, Account targetedAccount, final API.StatusAction action, RetrieveFeedsAsyncTask.Type type, final Status status, final RecyclerView.Adapter baseAdapter, final OnPostActionInterface onPostActionInterface){
|
||||
|
||||
String title = null;
|
||||
if( action == API.StatusAction.FAVOURITE){
|
||||
title = context.getString(R.string.favourite_add);
|
||||
}else if( action == API.StatusAction.UNFAVOURITE){
|
||||
title = context.getString(R.string.favourite_remove);
|
||||
}else if( action == API.StatusAction.REBLOG){
|
||||
title = context.getString(R.string.reblog_add);
|
||||
}else if(action == API.StatusAction.UNREBLOG){
|
||||
title = context.getString(R.string.reblog_remove);
|
||||
}else if ( action == API.StatusAction.PIN) {
|
||||
title = context.getString(R.string.pin_add);
|
||||
}else if (action == API.StatusAction.UNPIN) {
|
||||
title = context.getString(R.string.pin_remove);
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, style);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
builder.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
//noinspection deprecation
|
||||
builder.setMessage(Html.fromHtml(status.getContent()));
|
||||
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setTitle(title)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account loggedAccount = new AccountDAO(context, db).getAccountByID(userId);
|
||||
if( targetedAccount == null){
|
||||
if(loggedAccount.getInstance().equals(selectedAccount.getInstance())){
|
||||
new PostActionAsyncTask(context, selectedAccount, action, status.getId(), onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else{ //Account is from another instance
|
||||
new PostActionAsyncTask(context, selectedAccount, status, action, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
if( selectedAccount.getInstance().equals(loggedAccount.getInstance()) && selectedAccount.getId().equals(loggedAccount.getId())) {
|
||||
if (action == API.StatusAction.REBLOG) {
|
||||
status.setReblogged(true);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
|
||||
status.setBoostAnimated(true);
|
||||
} else if (action == API.StatusAction.FAVOURITE) {
|
||||
status.setFavourited(true);
|
||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
|
||||
status.setFavAnimated(true);
|
||||
} else if (action == API.StatusAction.PIN) {
|
||||
status.setPinned(true);
|
||||
}
|
||||
baseAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}else{
|
||||
new PostActionAsyncTask(context, selectedAccount, targetedAccount, action, onPostActionInterface).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( selectedAccount.getInstance().equals(loggedAccount.getInstance()) && selectedAccount.getId().equals(loggedAccount.getId())) {
|
||||
if (action == API.StatusAction.FOLLOW) {
|
||||
targetedAccount.setFollowing(true);
|
||||
}
|
||||
baseAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Follow/Unfollow an account
|
||||
* @param account Account
|
||||
|
|
|
@ -388,7 +388,8 @@ public class Helper {
|
|||
|
||||
public static final Pattern hashtagPattern = Pattern.compile("(#[\\w_A-zÀ-ÿ]+)");
|
||||
public static final Pattern twitterPattern = Pattern.compile("((@[\\w]+)@twitter\\.com)");
|
||||
private static final Pattern mentionPattern = Pattern.compile("(@[\\w]+)");
|
||||
private static final Pattern mentionPattern = Pattern.compile("(@[\\w_]+(\\s|$))");
|
||||
private static final Pattern mentionLongPattern = Pattern.compile("(@[\\w_-]+@[a-z0-9.\\-]+[.][a-z]{2,10})");
|
||||
|
||||
//Event Type
|
||||
public enum EventStreaming{
|
||||
|
@ -2345,7 +2346,7 @@ public class Helper {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if( url == null) {
|
||||
if( url == null || url.contains("missing.png")) {
|
||||
try {
|
||||
Glide.with(imageView.getContext())
|
||||
.load(R.drawable.missing)
|
||||
|
@ -2648,13 +2649,36 @@ public class Helper {
|
|||
String[] splitContent = content.split("(\\.\\s){1}");
|
||||
ArrayList<String> splitToot = new ArrayList<>();
|
||||
StringBuilder tempContent = new StringBuilder(splitContent[0]);
|
||||
ArrayList<String> mentions = new ArrayList<>();
|
||||
Matcher matcher = mentionLongPattern.matcher(content);
|
||||
while (matcher.find()) {
|
||||
String mentionLong = matcher.group(1);
|
||||
mentions.add(mentionLong);
|
||||
}
|
||||
matcher = mentionPattern.matcher(content);
|
||||
while (matcher.find()) {
|
||||
String mentionLong = matcher.group(1);
|
||||
mentions.add(mentionLong);
|
||||
}
|
||||
StringBuilder mentionString = new StringBuilder();
|
||||
for(String mention: mentions){
|
||||
mentionString.append(mention).append(" ");
|
||||
}
|
||||
int mentionLength = mentionString.length();
|
||||
int maxCharsMention = maxChars - mentionLength;
|
||||
for(int i= 0 ; i < splitContent.length ; i++){
|
||||
if( i < (splitContent.length-1) && (tempContent.length() + splitContent[i+1].length()) < (maxChars-10)) {
|
||||
if (i < (splitContent.length - 1) && (tempContent.length() + splitContent[i + 1].length()) < (maxChars - 10)) {
|
||||
tempContent.append(". ").append(splitContent[i + 1]);
|
||||
}else {
|
||||
} else {
|
||||
splitToot.add(tempContent.toString());
|
||||
if( i < (splitContent.length-1) )
|
||||
tempContent = new StringBuilder(splitContent[i+1]);
|
||||
if (i < (splitContent.length - 1)) {
|
||||
if( maxCharsMention > 0){
|
||||
maxChars = maxCharsMention;
|
||||
tempContent = new StringBuilder(mentionString+splitContent[i + 1]);
|
||||
}else{
|
||||
tempContent = new StringBuilder(splitContent[i + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int i=1;
|
||||
|
@ -2919,6 +2943,60 @@ public class Helper {
|
|||
|
||||
}
|
||||
|
||||
public static RetrieveFeedsAsyncTask.Type timelineType(Context context, int position){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean display_direct = sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true);
|
||||
boolean display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true);
|
||||
boolean display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true);
|
||||
boolean display_art = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true);
|
||||
if (position == 0) {
|
||||
return RetrieveFeedsAsyncTask.Type.HOME;
|
||||
}else if(position == 2) {
|
||||
if( display_direct) {
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context));
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.6");
|
||||
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||
boolean old_direct_timeline = sharedpreferences.getBoolean(Helper.SET_OLD_DIRECT_TIMELINE, false);
|
||||
if( !old_direct_timeline)
|
||||
return RetrieveFeedsAsyncTask.Type.CONVERSATION;
|
||||
else
|
||||
return RetrieveFeedsAsyncTask.Type.DIRECT;
|
||||
} else {
|
||||
return RetrieveFeedsAsyncTask.Type.DIRECT;
|
||||
}
|
||||
}else{
|
||||
return RetrieveFeedsAsyncTask.Type.DIRECT;
|
||||
}
|
||||
}if( display_local)
|
||||
return RetrieveFeedsAsyncTask.Type.LOCAL;
|
||||
if( display_global)
|
||||
return RetrieveFeedsAsyncTask.Type.PUBLIC;
|
||||
if( display_art)
|
||||
return RetrieveFeedsAsyncTask.Type.ART;
|
||||
}else if( position == 3){
|
||||
if( display_direct && display_local)
|
||||
return RetrieveFeedsAsyncTask.Type.LOCAL;
|
||||
if( display_global)
|
||||
return RetrieveFeedsAsyncTask.Type.PUBLIC;
|
||||
if( display_art)
|
||||
return RetrieveFeedsAsyncTask.Type.ART;
|
||||
}else if (position == 4){
|
||||
if( display_direct && display_local && display_global)
|
||||
return RetrieveFeedsAsyncTask.Type.PUBLIC;
|
||||
if( display_art)
|
||||
return RetrieveFeedsAsyncTask.Type.ART;
|
||||
}else if (position == 5){
|
||||
if( display_direct && display_local && display_global && display_art)
|
||||
return RetrieveFeedsAsyncTask.Type.ART;
|
||||
}
|
||||
return RetrieveFeedsAsyncTask.Type.TAG;
|
||||
}
|
||||
|
||||
public static boolean containsCaseInsensitive(String s, List<String> l){
|
||||
for (String string : l){
|
||||
if (string.equalsIgnoreCase(s)){
|
||||
|
|
|
@ -43,8 +43,10 @@ import com.bumptech.glide.request.RequestListener;
|
|||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.koushikdutta.async.ByteBufferList;
|
||||
import com.koushikdutta.async.DataEmitter;
|
||||
import com.koushikdutta.async.callback.CompletedCallback;
|
||||
import com.koushikdutta.async.future.Future;
|
||||
import com.koushikdutta.async.callback.DataCallback;
|
||||
import com.koushikdutta.async.http.AsyncHttpClient;
|
||||
import com.koushikdutta.async.http.AsyncHttpRequest;
|
||||
import com.koushikdutta.async.http.Headers;
|
||||
|
@ -57,7 +59,6 @@ import java.security.KeyManagementException;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
|
@ -91,7 +92,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
boolean backgroundProcess;
|
||||
private static Thread thread;
|
||||
private NetworkStateReceiver networkStateReceiver;
|
||||
private static HashMap<String, Future<WebSocket>> webSocketFutures = new HashMap<>();
|
||||
private static HashMap<String, WebSocket> webSocketFutures = new HashMap<>();
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -168,6 +169,7 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
restartServiceIntent.setPackage(getPackageName());
|
||||
PendingIntent restartServicePendingIntent = PendingIntent.getService(getApplicationContext(), 1, restartServiceIntent, PendingIntent.FLAG_ONE_SHOT);
|
||||
AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
|
||||
assert alarmService != null;
|
||||
alarmService.set(
|
||||
AlarmManager.ELAPSED_REALTIME,
|
||||
SystemClock.elapsedRealtime() + 1000,
|
||||
|
@ -186,11 +188,9 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
AsyncHttpRequest.setDefaultHeaders(headers, url);
|
||||
if( webSocketFutures.containsKey(urlKey) ){
|
||||
try {
|
||||
if( webSocketFutures.get(urlKey) != null && webSocketFutures.get(urlKey).get() != null)
|
||||
webSocketFutures.get(urlKey).get().close();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
if( webSocketFutures.get(urlKey) != null && webSocketFutures.get(urlKey).isOpen())
|
||||
webSocketFutures.get(urlKey).close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -204,9 +204,10 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Future<WebSocket> webSocketFuture = AsyncHttpClient.getDefaultInstance().websocket("wss://" + account.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + account.getToken(), "wss", new AsyncHttpClient.WebSocketConnectCallback() {
|
||||
AsyncHttpClient.getDefaultInstance().websocket("wss://" + account.getInstance() + "/api/v1/streaming/?stream=user&access_token=" + account.getToken(), "wss", new AsyncHttpClient.WebSocketConnectCallback() {
|
||||
@Override
|
||||
public void onCompleted(Exception ex, WebSocket webSocket) {
|
||||
webSocketFutures.put(account.getAcct()+"@"+account.getInstance(), webSocket);
|
||||
if (ex != null) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
|
@ -223,8 +224,10 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
webSocket.setClosedCallback(new CompletedCallback() {
|
||||
@Override
|
||||
public void onCompleted(Exception ex) {
|
||||
if( ex != null){
|
||||
webSocket.close();
|
||||
try {
|
||||
if (ex != null)
|
||||
webSocket.close();
|
||||
} finally {
|
||||
if( webSocketFutures != null && webSocketFutures.containsKey(urlKey))
|
||||
webSocketFutures.remove(urlKey);
|
||||
taks(account);
|
||||
|
@ -233,12 +236,17 @@ public class LiveNotificationService extends Service implements NetworkStateRece
|
|||
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
webSocket.setDataCallback(new DataCallback() {
|
||||
public void onDataAvailable(DataEmitter emitter, ByteBufferList byteBufferList) {
|
||||
// note that this data has been read
|
||||
byteBufferList.recycle();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
webSocketFutures.put(urlKey, webSocketFuture);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue