forked from mirrors/Fedilab
Fix some issues + some improvements
This commit is contained in:
parent
c772fa797b
commit
e3933ae3eb
9 changed files with 186 additions and 139 deletions
|
@ -66,7 +66,9 @@ import androidx.navigation.ui.NavigationUI;
|
|||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
||||
import com.bumptech.glide.load.resource.gif.GifDrawable;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
@ -652,6 +654,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
|
|||
Helper.loadPP(headerMainBinding.accountProfilePicture, account);
|
||||
Glide.with(BaseMainActivity.this)
|
||||
.load(account.mastodon_account.header)
|
||||
.apply(new RequestOptions().transform(new CenterCrop()))
|
||||
.into(new CustomTarget<Drawable>() {
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
|
|
|
@ -117,6 +117,22 @@ public class StatusCache {
|
|||
return idReturned;
|
||||
}
|
||||
|
||||
/**
|
||||
* update a status if presents in db
|
||||
*
|
||||
* @param statusCache {@link StatusCache}
|
||||
* @throws DBException exception with database
|
||||
*/
|
||||
public void updateIfExists(StatusCache statusCache) throws DBException {
|
||||
if (db == null) {
|
||||
throw new DBException("db is null. Wrong initialization.");
|
||||
}
|
||||
boolean exists = statusExist(statusCache);
|
||||
if (exists) {
|
||||
updateStatus(statusCache);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a status exists in db
|
||||
*
|
||||
|
|
|
@ -282,6 +282,10 @@ public class Helper {
|
|||
"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,10}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))",
|
||||
|
||||
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL);
|
||||
|
||||
public static final Pattern aLink = Pattern.compile("<a((?!href).)*href=\"([^\"]*)\"[^>]*(((?!</a).)*)</a>");
|
||||
public static final Pattern imgPattern = Pattern.compile("<img [^>]*src=\"([^\"]+)\"[^>]*>");
|
||||
|
||||
// --- Static Map of patterns used in spannable status content
|
||||
public static final Map<PatternType, Pattern> patternHashMap;
|
||||
public static final int NOTIFICATION_MEDIA = 451;
|
||||
|
@ -679,6 +683,8 @@ public class Helper {
|
|||
} else {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://") && !url.toLowerCase().startsWith("gemini://"))
|
||||
url = "http://" + url;
|
||||
intent.setData(Uri.parse(url));
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
|
|
|
@ -103,6 +103,20 @@ public class SpannableHelper {
|
|||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
Matcher matcherALink = Helper.aLink.matcher(text);
|
||||
//We stock details
|
||||
HashMap<String, String> urlDetails = new HashMap<>();
|
||||
while (matcherALink.find()) {
|
||||
String urlText = matcherALink.group(3);
|
||||
String url = matcherALink.group(2);
|
||||
if (urlText != null) {
|
||||
urlText = urlText.substring(1);
|
||||
}
|
||||
if (url != null && urlText != null && !url.equals(urlText) && !urlText.contains("<span")) {
|
||||
urlDetails.put(url, urlText);
|
||||
text = text.replaceAll(Pattern.quote(matcherALink.group()), Matcher.quoteReplacement(url));
|
||||
}
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
initialContent = new SpannableString(Html.fromHtml(text, Html.FROM_HTML_MODE_LEGACY));
|
||||
else
|
||||
|
@ -110,8 +124,10 @@ public class SpannableHelper {
|
|||
|
||||
SpannableStringBuilder content = new SpannableStringBuilder(initialContent);
|
||||
URLSpan[] urls = content.getSpans(0, (content.length() - 1), URLSpan.class);
|
||||
for (URLSpan span : urls)
|
||||
for (URLSpan span : urls) {
|
||||
content.removeSpan(span);
|
||||
}
|
||||
|
||||
//--- EMOJI ----
|
||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean disableGif = sharedpreferences.getBoolean(context.getString(R.string.SET_DISABLE_GIF), false);
|
||||
|
@ -184,14 +200,15 @@ public class SpannableHelper {
|
|||
}
|
||||
|
||||
//--- URLs ----
|
||||
Matcher matcherALink = Patterns.WEB_URL.matcher(content);
|
||||
Matcher matcherLink = Patterns.WEB_URL.matcher(content);
|
||||
int offSetTruncate = 0;
|
||||
while (matcherALink.find()) {
|
||||
int matchStart = matcherALink.start() - offSetTruncate;
|
||||
int matchEnd = matchStart + matcherALink.group().length();
|
||||
while (matcherLink.find()) {
|
||||
int matchStart = matcherLink.start() - offSetTruncate;
|
||||
int matchEnd = matchStart + matcherLink.group().length();
|
||||
if (matchEnd > content.toString().length()) {
|
||||
matchEnd = content.toString().length();
|
||||
}
|
||||
|
||||
if (content.toString().length() < matchEnd || matchStart < 0 || matchStart > matchEnd) {
|
||||
continue;
|
||||
}
|
||||
|
@ -202,20 +219,27 @@ public class SpannableHelper {
|
|||
content.replace(matchStart, matchEnd, newURL);
|
||||
offSetTruncate += (newURL.length() - url.length());
|
||||
matchEnd = matchStart + newURL.length();
|
||||
//The transformed URL was in the list of URLs having a different names
|
||||
if (urlDetails.containsKey(url)) {
|
||||
urlDetails.put(newURL, urlDetails.get(url));
|
||||
}
|
||||
}
|
||||
//Truncate URL if needed
|
||||
//TODO: add an option to disable truncated URLs
|
||||
String urlText = newURL;
|
||||
if (newURL.length() > 30) {
|
||||
if (newURL.length() > 30 && !urlDetails.containsKey(urlText)) {
|
||||
urlText = urlText.substring(0, 30);
|
||||
urlText += "…";
|
||||
content.replace(matchStart, matchEnd, urlText);
|
||||
matchEnd = matchStart + 31;
|
||||
offSetTruncate += (newURL.length() - urlText.length());
|
||||
} else if (urlDetails.containsKey(urlText) && urlDetails.get(urlText) != null) {
|
||||
urlText = urlDetails.get(urlText);
|
||||
if (urlText != null) {
|
||||
content.replace(matchStart, matchEnd, urlText);
|
||||
matchEnd = matchStart + urlText.length();
|
||||
offSetTruncate += (newURL.length() - urlText.length());
|
||||
}
|
||||
|
||||
if (!urlText.startsWith("http")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matchEnd <= content.length() && matchEnd >= matchStart) {
|
||||
|
@ -409,6 +433,7 @@ public class SpannableHelper {
|
|||
Pattern pattern = entry.getValue();
|
||||
Matcher matcher = pattern.matcher(content);
|
||||
while (matcher.find()) {
|
||||
|
||||
int matchStart = matcher.start();
|
||||
int matchEnd = matcher.end();
|
||||
String word = content.toString().substring(matchStart, matchEnd);
|
||||
|
|
|
@ -96,6 +96,7 @@ import app.fedilab.android.R;
|
|||
import app.fedilab.android.activities.ComposeActivity;
|
||||
import app.fedilab.android.activities.ContextActivity;
|
||||
import app.fedilab.android.activities.CustomSharingActivity;
|
||||
import app.fedilab.android.activities.MainActivity;
|
||||
import app.fedilab.android.activities.MediaActivity;
|
||||
import app.fedilab.android.activities.ProfileActivity;
|
||||
import app.fedilab.android.activities.ReportActivity;
|
||||
|
@ -104,6 +105,7 @@ import app.fedilab.android.client.entities.api.Attachment;
|
|||
import app.fedilab.android.client.entities.api.Notification;
|
||||
import app.fedilab.android.client.entities.api.Poll;
|
||||
import app.fedilab.android.client.entities.api.Status;
|
||||
import app.fedilab.android.client.entities.app.StatusCache;
|
||||
import app.fedilab.android.client.entities.app.StatusDraft;
|
||||
import app.fedilab.android.client.entities.app.Timeline;
|
||||
import app.fedilab.android.databinding.DrawerFetchMoreBinding;
|
||||
|
@ -114,6 +116,7 @@ import app.fedilab.android.databinding.DrawerStatusNotificationBinding;
|
|||
import app.fedilab.android.databinding.DrawerStatusReportBinding;
|
||||
import app.fedilab.android.databinding.LayoutMediaBinding;
|
||||
import app.fedilab.android.databinding.LayoutPollItemBinding;
|
||||
import app.fedilab.android.exception.DBException;
|
||||
import app.fedilab.android.helper.CrossActionHelper;
|
||||
import app.fedilab.android.helper.Helper;
|
||||
import app.fedilab.android.helper.LongClickLinkMovementMethod;
|
||||
|
@ -192,6 +195,81 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Methode that will deal with results of actions (bookmark, favourite, boost)
|
||||
* @param context Context
|
||||
* @param adapter RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
* @param statusList List<Status> used by the reycler
|
||||
* @param notificationList List<Notification>
|
||||
* @param typeOfAction CrossActionHelper.TypeOfCrossAction
|
||||
* @param statusToDeal Status that received the action
|
||||
* @param statusReturned Status returned by the API
|
||||
* @param remote boolean - it's a remote message
|
||||
*/
|
||||
private static void manageAction(Context context,
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
|
||||
List<Status> statusList,
|
||||
List<Notification> notificationList,
|
||||
CrossActionHelper.TypeOfCrossAction typeOfAction,
|
||||
Status statusToDeal,
|
||||
Status statusReturned,
|
||||
boolean remote) {
|
||||
if (statusReturned == null) {
|
||||
Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
boolean isOK = true;
|
||||
switch (typeOfAction) {
|
||||
case BOOKMARK_ACTION:
|
||||
isOK = statusReturned.bookmarked;
|
||||
break;
|
||||
case REBLOG_ACTION:
|
||||
isOK = statusReturned.reblogged;
|
||||
break;
|
||||
case FAVOURITE_ACTION:
|
||||
isOK = statusReturned.favourited;
|
||||
break;
|
||||
case UNBOOKMARK_ACTION:
|
||||
isOK = !statusReturned.bookmarked;
|
||||
break;
|
||||
case UNREBLOG_ACTION:
|
||||
isOK = !statusReturned.reblogged;
|
||||
break;
|
||||
case UNFAVOURITE_ACTION:
|
||||
isOK = !statusReturned.favourited;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isOK) {
|
||||
Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
//Update elements
|
||||
statusToDeal.favourited = statusReturned.favourited;
|
||||
statusToDeal.reblogged = statusReturned.reblogged;
|
||||
statusToDeal.bookmarked = statusReturned.bookmarked;
|
||||
statusToDeal.reblogs_count = statusReturned.reblogs_count;
|
||||
statusToDeal.favourites_count = statusReturned.favourites_count;
|
||||
//Update status in cache if not a remote instance
|
||||
if (!remote) {
|
||||
new Thread(() -> {
|
||||
StatusCache statusCache = new StatusCache();
|
||||
statusCache.instance = MainActivity.currentInstance;
|
||||
statusCache.user_id = MainActivity.currentUserID;
|
||||
statusCache.status = statusToDeal;
|
||||
statusCache.status_id = statusToDeal.id;
|
||||
try {
|
||||
new StatusCache(context).updateIfExists(statusCache);
|
||||
} catch (DBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage status, this method is also reused in notifications timelines
|
||||
*
|
||||
|
@ -396,13 +474,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
Status fetchedStatus = statusList.get(0);
|
||||
statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.bookmarked = _status.bookmarked;
|
||||
} else {
|
||||
statusToDeal.bookmarked = true;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.BOOKMARK_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
|
||||
|
@ -412,25 +484,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (statusToDeal.bookmarked) {
|
||||
statusesVM.unBookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.bookmarked = _status.bookmarked;
|
||||
} else {
|
||||
statusToDeal.bookmarked = false;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.UNBOOKMARK_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
((SparkButton) v).playAnimation();
|
||||
statusesVM.bookmark(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.bookmarked = _status.bookmarked;
|
||||
} else {
|
||||
statusToDeal.bookmarked = true;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.BOOKMARK_ACTION, statusToDeal, _status, remote);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -521,15 +582,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
Status fetchedStatus = results.statuses.get(0);
|
||||
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.reblogged = _status.reblogged;
|
||||
statusToDeal.reblogs_count = _status.reblogs_count;
|
||||
} else {
|
||||
statusToDeal.reblogged = true;
|
||||
statusToDeal.reblogs_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
|
||||
|
@ -539,29 +592,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (statusToDeal.reblogged) {
|
||||
statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.reblogged = _status.reblogged;
|
||||
statusToDeal.reblogs_count = _status.reblogs_count;
|
||||
} else {
|
||||
statusToDeal.reblogged = false;
|
||||
statusToDeal.reblogs_count -= 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.UNREBLOG_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
((SparkButton) v).playAnimation();
|
||||
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id, null)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.reblogged = _status.reblogged;
|
||||
statusToDeal.reblogs_count = _status.reblogs_count;
|
||||
} else {
|
||||
statusToDeal.reblogged = true;
|
||||
statusToDeal.reblogs_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -579,15 +616,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
Status fetchedStatus = results.statuses.get(0);
|
||||
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id, null)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.reblogged = _status.reblogged;
|
||||
statusToDeal.reblogs_count = _status.reblogs_count;
|
||||
} else {
|
||||
statusToDeal.reblogged = true;
|
||||
statusToDeal.reblogs_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
|
||||
|
@ -597,29 +626,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (statusToDeal.reblogged) {
|
||||
statusesVM.unReblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.reblogged = _status.reblogged;
|
||||
statusToDeal.reblogs_count = _status.reblogs_count;
|
||||
} else {
|
||||
statusToDeal.reblogged = false;
|
||||
statusToDeal.reblogs_count -= 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.UNREBLOG_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
((SparkButton) v).playAnimation();
|
||||
statusesVM.reblog(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id, null)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.reblogged = _status.reblogged;
|
||||
statusToDeal.reblogs_count = _status.reblogs_count;
|
||||
} else {
|
||||
statusToDeal.reblogged = true;
|
||||
statusToDeal.reblogs_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.REBLOG_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -651,15 +664,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
Status fetchedStatus = results.statuses.get(0);
|
||||
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.favourited = _status.favourited;
|
||||
statusToDeal.favourites_count = _status.favourites_count;
|
||||
} else {
|
||||
statusToDeal.favourited = true;
|
||||
statusToDeal.favourites_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
|
||||
|
@ -669,28 +674,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (status.favourited) {
|
||||
statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.favourited = _status.favourited;
|
||||
statusToDeal.favourites_count = _status.favourites_count;
|
||||
} else {
|
||||
statusToDeal.favourited = false;
|
||||
statusToDeal.favourites_count -= 1;
|
||||
}
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.UNFAVOURITE_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
((SparkButton) v).playAnimation();
|
||||
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.favourited = _status.favourited;
|
||||
statusToDeal.favourites_count = _status.favourites_count;
|
||||
} else {
|
||||
statusToDeal.favourited = true;
|
||||
statusToDeal.favourites_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -708,15 +698,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
Status fetchedStatus = results.statuses.get(0);
|
||||
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, fetchedStatus.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.favourited = _status.favourited;
|
||||
statusToDeal.favourites_count = _status.favourites_count;
|
||||
} else {
|
||||
statusToDeal.favourited = true;
|
||||
statusToDeal.favourites_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
Toasty.info(context, context.getString(R.string.toast_error_search), Toasty.LENGTH_SHORT).show();
|
||||
|
@ -726,28 +708,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
if (statusToDeal.favourited) {
|
||||
statusesVM.unFavourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.favourited = _status.favourited;
|
||||
statusToDeal.favourites_count = _status.favourites_count;
|
||||
} else {
|
||||
statusToDeal.favourited = false;
|
||||
statusToDeal.favourites_count -= 1;
|
||||
}
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.UNFAVOURITE_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
} else {
|
||||
((SparkButton) v).playAnimation();
|
||||
statusesVM.favourite(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, statusToDeal.id)
|
||||
.observe((LifecycleOwner) context, _status -> {
|
||||
if (_status != null) {
|
||||
statusToDeal.favourited = _status.favourited;
|
||||
statusToDeal.favourites_count = _status.favourites_count;
|
||||
} else {
|
||||
statusToDeal.favourited = true;
|
||||
statusToDeal.favourites_count += 1;
|
||||
}
|
||||
sendAction(context, Helper.ARG_STATUS_ACTION, statusToDeal, null);
|
||||
adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
|
||||
manageAction(context, adapter, statusList, notificationList, CrossActionHelper.TypeOfCrossAction.FAVOURITE_ACTION, statusToDeal, _status, remote);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -962,6 +929,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
// start the new activity
|
||||
context.startActivity(mediaIntent, options.toBundle());
|
||||
});
|
||||
if (statusToDeal.media_attachments.get(0).type != null && statusToDeal.media_attachments.get(0).type.equalsIgnoreCase("video")) {
|
||||
layoutMediaBinding.playVideo.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
layoutMediaBinding.playVideo.setVisibility(View.GONE);
|
||||
}
|
||||
if (!mediaObfuscated(statusToDeal) || expand_media) {
|
||||
layoutMediaBinding.viewHide.setImageResource(R.drawable.ic_baseline_visibility_24);
|
||||
Glide.with(layoutMediaBinding.media.getContext())
|
||||
|
@ -995,6 +967,11 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
lp = new RelativeLayout.LayoutParams((int) Helper.convertDpToPixel(200, context), (int) Helper.convertDpToPixel(200, context));
|
||||
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
}
|
||||
if (attachment.type != null && attachment.type.equalsIgnoreCase("video")) {
|
||||
layoutMediaBinding.playVideo.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
layoutMediaBinding.playVideo.setVisibility(View.GONE);
|
||||
}
|
||||
lp.setMargins(0, 0, (int) Helper.convertDpToPixel(5, context), 0);
|
||||
if (!mediaObfuscated(statusToDeal) || expand_media) {
|
||||
layoutMediaBinding.viewHide.setImageResource(R.drawable.ic_baseline_visibility_24);
|
||||
|
|
|
@ -378,7 +378,7 @@ public class AccountsVM extends AndroidViewModel {
|
|||
try {
|
||||
Response<List<Account>> followersResponse = followersCall.execute();
|
||||
if (followersResponse.isSuccessful()) {
|
||||
accountList = followersResponse.body();
|
||||
accountList = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), followersResponse.body());
|
||||
pagination = MastodonHelper.getPagination(followersResponse.headers());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
@ -414,7 +414,7 @@ public class AccountsVM extends AndroidViewModel {
|
|||
try {
|
||||
Response<List<Account>> followingResponse = followingCall.execute();
|
||||
if (followingResponse.isSuccessful()) {
|
||||
accountList = followingResponse.body();
|
||||
accountList = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), followingResponse.body());
|
||||
pagination = MastodonHelper.getPagination(followingResponse.headers());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -117,6 +117,8 @@ public class SearchVM extends AndroidViewModel {
|
|||
}
|
||||
if (results.accounts == null) {
|
||||
results.accounts = new ArrayList<>();
|
||||
} else {
|
||||
results.accounts = SpannableHelper.convertAccounts(getApplication().getApplicationContext(), results.accounts);
|
||||
}
|
||||
if (results.hashtags == null) {
|
||||
results.hashtags = new ArrayList<>();
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM10,16.5v-9l6,4.5 -6,4.5z" />
|
||||
</vector>
|
|
@ -12,6 +12,14 @@
|
|||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/play_video"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:src="@drawable/ic_baseline_play_circle_filled_24"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/view_hide"
|
||||
android:layout_width="24dp"
|
||||
|
|
Loading…
Reference in a new issue