ExoPlayer improvements, added error handling, bug fix

This commit is contained in:
nuclearfog 2023-04-11 23:25:57 +02:00
parent 9eb448fe5c
commit fcfeeb6408
No known key found for this signature in database
GPG Key ID: 03488A185C476379
39 changed files with 333 additions and 147 deletions

View File

@ -113,7 +113,9 @@ public class MastodonAccount implements Account {
@NonNull
@Override
public String toString() {
return user.toString();
if (getUser() != null)
return getUser().toString();
return "";
}
@ -121,6 +123,9 @@ public class MastodonAccount implements Account {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Account))
return false;
return user.equals(((Account) obj).getUser());
Account account = (Account) obj;
if (account.getUser() != null && getUser() != null)
return getUser().equals(account.getUser());
return false;
}
}

View File

@ -2,6 +2,8 @@ package org.nuclearfog.twidda.backend.api.mastodon.impl;
import android.util.Patterns;
import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
import org.nuclearfog.twidda.model.Card;
@ -58,4 +60,11 @@ public class MastodonCard implements Card {
public String getImageUrl() {
return imageLink;
}
@NonNull
@Override
public String toString() {
return "title=\"" + getTitle() + " \" description=\"" + getDescription() + "\"";
}
}

View File

@ -54,20 +54,20 @@ public class MastodonEmoji implements Emoji {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Emoji))
return false;
return ((Emoji) obj).getCode().equals(code);
return ((Emoji) obj).getCode().equals(getCode());
}
@NonNull
@Override
public String toString() {
return "code=\"" + code + "\" category=\"" + category + "\" url=\"" + url + "\"";
return "code=\"" + getCode() + "\" category=\"" + getCategory() + "\" url=\"" + getUrl() + "\"";
}
@Override
public int compareTo(Emoji emoji) {
return String.CASE_INSENSITIVE_ORDER.compare(code, emoji.getCode());
return String.CASE_INSENSITIVE_ORDER.compare(getCode(), emoji.getCode());
}
/**

View File

@ -100,13 +100,13 @@ public class MastodonList implements UserList {
@NonNull
@Override
public String toString() {
return "id=" + id + " title=\"" + title + "\"";
return "id=" + getId() + " title=\"" + getTitle() + "\"";
}
@Override
public int compareTo(UserList userlist) {
return Long.compare(userlist.getId(), id);
return Long.compare(userlist.getId(), getId());
}
@ -114,6 +114,6 @@ public class MastodonList implements UserList {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof UserList))
return false;
return ((UserList) obj).getId() == id;
return ((UserList) obj).getId() == getId();
}
}

View File

@ -3,6 +3,7 @@ package org.nuclearfog.twidda.backend.api.mastodon.impl;
import android.util.Patterns;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;
@ -94,9 +95,15 @@ public class MastodonMedia implements Media {
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Media && ((Media) obj).getKey().equals(getKey());
}
@Override
public int compareTo(Media o) {
return String.CASE_INSENSITIVE_ORDER.compare(key, o.getKey());
return String.CASE_INSENSITIVE_ORDER.compare(getKey(), o.getKey());
}
@ -104,7 +111,7 @@ public class MastodonMedia implements Media {
@Override
public String toString() {
String tostring;
switch (type) {
switch (getMediaType()) {
case PHOTO:
tostring = "photo:";
break;
@ -121,7 +128,6 @@ public class MastodonMedia implements Media {
tostring = "none:";
break;
}
tostring += "url=\"" + url + "\"";
return tostring;
return tostring + "url=\"" + getUrl() + "\"";
}
}

View File

@ -112,23 +112,23 @@ public class MastodonNotification implements Notification {
}
@NonNull
@Override
public String toString() {
return "id=" + id + " " + user;
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Notification))
return false;
return ((Notification) obj).getId() == getId();
}
@Override
public int compareTo(Notification notification) {
return Long.compare(notification.getTimestamp(), timestamp);
return Long.compare(notification.getTimestamp(), getTimestamp());
}
@NonNull
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Notification))
return false;
return ((Notification) obj).getId() == id;
public String toString() {
return "id=" + getId() + " " + getUser();
}
}

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.backend.api.mastodon.impl;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
@ -111,8 +112,8 @@ public class MastodonPoll implements Poll {
@Override
public int compareTo(Poll o) {
return Long.compare(id, o.getId());
public boolean equals(Object o) {
return o instanceof Poll && ((Poll)o).getId() == getId();
}
@ -120,15 +121,13 @@ public class MastodonPoll implements Poll {
@Override
public String toString() {
StringBuilder optionsBuf = new StringBuilder();
optionsBuf.append("id=").append(id).append(" voted=").append(voted);
if (options.length > 0) {
if (getOptions().length > 0) {
optionsBuf.append(" options=(");
for (Option option : options) {
for (Option option : getOptions())
optionsBuf.append(option).append(',');
}
optionsBuf.deleteCharAt(optionsBuf.length() - 1).append(')');
}
return optionsBuf.toString();
return "id=" + getId() + " expired=" + expirationTime() + optionsBuf;
}
/**
@ -164,7 +163,7 @@ public class MastodonPoll implements Poll {
@Override
public boolean selected() {
public boolean isSelected() {
return selected;
}
@ -172,7 +171,13 @@ public class MastodonPoll implements Poll {
@NonNull
@Override
public String toString() {
return "title=\"" + title + "\" votes=" + voteCount + " selected=" + selected;
return "title=\"" + getTitle() + "\" votes=" + getVotes() + " selected=" + isSelected();
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Option && ((Option) obj).getTitle().equals(getTitle());
}
/**

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.backend.api.mastodon.impl;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;
@ -69,7 +70,7 @@ public class MastodonRelation implements Relation {
@Override
public boolean canDm() {
public boolean privateMessagingEnabled() {
return false;
}
@ -89,10 +90,20 @@ public class MastodonRelation implements Relation {
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Relation))
return false;
Relation relation = (Relation) obj;
return relation.getId() == getId() && relation.isBlocked() == isBlocked() && relation.isFollower() == isFollower()
&& relation.isFollowing() == isFollowing() && relation.isMuted() == isMuted() && relation.privateMessagingEnabled() == privateMessagingEnabled();
}
@NonNull
@Override
public String toString() {
return "following=" + isFollowing + " follower=" + isFollower +
" blocked=" + isBlocked + " muted=" + isMuted;
return "following=" + isFollowing() + " follower=" + isFollower() +
" blocked=" + isBlocked() + " muted=" + isMuted() + " dm open=" + privateMessagingEnabled();
}
}

View File

@ -1,5 +1,7 @@
package org.nuclearfog.twidda.backend.api.mastodon.impl;
import androidx.annotation.NonNull;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.nuclearfog.twidda.model.Translation;
@ -48,4 +50,11 @@ public class MastodonTranslation implements Translation {
public String getOriginalLanguage() {
return language;
}
@NonNull
@Override
public String toString() {
return "language=\"" + getOriginalLanguage() + "\" source=\"" + getSource() + "\"";
}
}

View File

@ -59,19 +59,19 @@ public class MastodonTrend implements Trend {
@Override
public int compareTo(Trend trend) {
if (trend.getPopularity() > 0 && popularity > 0)
return Integer.compare(trend.getPopularity(), popularity);
if (trend.getPopularity() > 0 && getPopularity() > 0)
return Integer.compare(trend.getPopularity(), getPopularity());
if (trend.getPopularity() > 0)
return 1;
if (popularity > 0)
if (getPopularity() > 0)
return -1;
return String.CASE_INSENSITIVE_ORDER.compare(name, trend.getName());
return String.CASE_INSENSITIVE_ORDER.compare(getName(), trend.getName());
}
@NonNull
@Override
public String toString() {
return "name=\"" + name;
return "name=\"" + getName() + "\"";
}
}

View File

@ -120,7 +120,9 @@ public class AccountV1 implements Account {
@NonNull
@Override
public String toString() {
return user.toString();
if (getUser() != null)
return getUser().toString();
return "";
}
@ -128,6 +130,9 @@ public class AccountV1 implements Account {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Account))
return false;
return user.equals(((Account) obj).getUser());
Account account = (Account) obj;
if (account.getUser() != null && getUser() != null)
return getUser().equals(account.getUser());
return false;
}
}

View File

@ -100,21 +100,19 @@ public class LocationV1 implements Location {
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Location))
return false;
return ((Location) obj).getId() == id;
return obj instanceof Location && ((Location) obj).getId() == getId();
}
@Override
public int compareTo(Location o) {
return Long.compare(id, o.getId());
return Long.compare(getId(), o.getId());
}
@NonNull
@Override
public String toString() {
return "id=" + id + " name=\"" + getFullName() + "\"";
return "id=" + getId() + " name=\"" + getFullName() + "\"";
}
}

View File

@ -3,6 +3,7 @@ package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
import android.util.Patterns;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
@ -126,9 +127,15 @@ public class MediaV1 implements Media {
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Media && ((Media) obj).getKey().equals(getKey());
}
@Override
public int compareTo(Media o) {
return String.CASE_INSENSITIVE_ORDER.compare(key, o.getKey());
return String.CASE_INSENSITIVE_ORDER.compare(getKey(), o.getKey());
}
@ -136,7 +143,7 @@ public class MediaV1 implements Media {
@Override
public String toString() {
String tostring;
switch (type) {
switch (getMediaType()) {
case PHOTO:
tostring = "photo:";
break;
@ -153,7 +160,6 @@ public class MediaV1 implements Media {
tostring = "none:";
break;
}
tostring += "url=\"" + url + "\"";
return tostring;
return tostring + "url=\"" + getUrl() + "\"";
}
}

View File

@ -99,20 +99,20 @@ public class MessageV1 implements Message {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Message))
return false;
return ((Message) obj).getId() == id;
return ((Message) obj).getId() == getId();
}
@NonNull
@Override
public String toString() {
return "from=" + sender + " message=\"" + text + "\"";
return getSender() + " message=\"" + getText() + "\"";
}
@Override
public int compareTo(Message message) {
return Long.compare(message.getTimestamp(), timestamp);
return Long.compare(message.getTimestamp(), getTimestamp());
}
/**

View File

@ -56,19 +56,11 @@ public class NotificationV1 implements Notification {
}
@NonNull
@Override
public String toString() {
return "type=mention " + status;
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Notification))
return false;
Notification notification = ((Notification) obj);
return status.equals(notification.getStatus());
return ((Notification) obj).getId() == getId();
}
@ -76,4 +68,11 @@ public class NotificationV1 implements Notification {
public int compareTo(Notification notification) {
return Long.compare(notification.getTimestamp(), getTimestamp());
}
@NonNull
@Override
public String toString() {
return "id=" + getId() + " " + getUser();
}
}

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.v1.impl;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;
@ -76,7 +77,7 @@ public class RelationV1 implements Relation {
@Override
public boolean canDm() {
public boolean privateMessagingEnabled() {
return canDm;
}
@ -96,10 +97,20 @@ public class RelationV1 implements Relation {
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Relation))
return false;
Relation relation = (Relation) obj;
return relation.getId() == getId() && relation.isBlocked() == isBlocked() && relation.isFollower() == isFollower()
&& relation.isFollowing() == isFollowing() && relation.isMuted() == isMuted() && relation.privateMessagingEnabled() == privateMessagingEnabled();
}
@NonNull
@Override
public String toString() {
return "following=" + isFollowing + " follower=" + isFollower +
" blocked=" + isBlocked + " muted=" + isMuted + " dm open=" + canDm;
return "following=" + isFollowing() + " follower=" + isFollower() +
" blocked=" + isBlocked() + " muted=" + isMuted() + " dm open=" + privateMessagingEnabled();
}
}

View File

@ -58,13 +58,13 @@ public class TrendV1 implements Trend {
@Override
public int compareTo(Trend trend) {
return Integer.compare(rank, trend.getRank());
return Integer.compare(getRank(), trend.getRank());
}
@NonNull
@Override
public String toString() {
return "rank=" + rank + " name=\"" + name + "\"";
return "name=\"" + getName() + "\"";
}
}

View File

@ -117,24 +117,24 @@ public class UserListV1 implements UserList {
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof UserList))
return false;
return ((UserList) obj).getId() == id;
}
@NonNull
@Override
public String toString() {
return "title=\"" + title + "\" description=\"" + description + "\"";
return "id=" + getId() + " title=\"" + getTitle() + "\"";
}
@Override
public int compareTo(UserList userlist) {
return Long.compare(userlist.getTimestamp(), timestamp);
return Long.compare(userlist.getId(), getId());
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof UserList))
return false;
return ((UserList) obj).getId() == getId();
}
/**

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
@ -94,15 +95,21 @@ public class LocationV2 implements Location {
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Location && ((Location) obj).getId() == getId();
}
@Override
public int compareTo(Location o) {
return Long.compare(id, o.getId());
return Long.compare(getId(), o.getId());
}
@NonNull
@Override
public String toString() {
return "id=\"" + id + " full_name=" + fullName + " country=\"" + country + "\"";
return "id=" + getId() + " name=\"" + getFullName() + "\"";
}
}

View File

@ -3,6 +3,7 @@ package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
import android.util.Patterns;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
@ -132,9 +133,15 @@ public class MediaV2 implements Media {
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Media && ((Media) obj).getKey().equals(getKey());
}
@Override
public int compareTo(Media o) {
return String.CASE_INSENSITIVE_ORDER.compare(key, o.getKey());
return String.CASE_INSENSITIVE_ORDER.compare(getKey(), o.getKey());
}
@ -142,7 +149,7 @@ public class MediaV2 implements Media {
@Override
public String toString() {
String tostring;
switch (type) {
switch (getMediaType()) {
case PHOTO:
tostring = "photo:";
break;
@ -159,7 +166,6 @@ public class MediaV2 implements Media {
tostring = "none:";
break;
}
tostring += "url=\"" + url + "\"";
return tostring;
return tostring + "url=\"" + getUrl() + "\"";
}
}

View File

@ -66,7 +66,7 @@ public class MetricsV2 implements Metrics {
@NonNull
@Override
public String toString() {
return "impressions=" + impressions + " profile_clicks=" + profileClicks +
" link_clicks=" + linkClicks + " quotes=" + quotes + "video_views=" + videoViews;
return "impressions=" + getViews() + " profile_clicks=" + getProfileClicks() +
" link_clicks=" + getLinkClicks() + " quotes=" + getQuoteCount() + "video_views=" + getVideoViews();
}
}

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.backend.api.twitter.v2.impl;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
@ -98,20 +99,22 @@ public class PollV2 implements Poll {
@Override
public int compareTo(Poll o) {
return Long.compare(id, o.getId());
public boolean equals(Object o) {
return o instanceof Poll && ((Poll)o).getId() == getId();
}
@NonNull
@Override
public String toString() {
StringBuilder optionsBuf = new StringBuilder(" options=(");
for (Option option : options) {
optionsBuf.append(option).append(',');
StringBuilder optionsBuf = new StringBuilder();
if (getOptions().length > 0) {
optionsBuf.append(" options=(");
for (Option option : getOptions())
optionsBuf.append(option).append(',');
optionsBuf.deleteCharAt(optionsBuf.length() - 1).append(')');
}
optionsBuf.deleteCharAt(optionsBuf.length() - 1).append(')');
return "id=" + id + " expired=" + expired + " options=" + optionsBuf;
return "id=" + getId() + " expired=" + expirationTime() + optionsBuf;
}
/**
@ -148,7 +151,7 @@ public class PollV2 implements Poll {
@Override
public boolean selected() {
public boolean isSelected() {
return selected;
}
@ -156,7 +159,13 @@ public class PollV2 implements Poll {
@NonNull
@Override
public String toString() {
return "title=\"" + title + "\" votes=" + voteCount + " selected=" + selected;
return "title=\"" + getTitle() + "\" votes=" + getVotes() + " selected=" + isSelected();
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Option && ((Option) obj).getTitle().equals(getTitle());
}
}
}

View File

@ -70,6 +70,6 @@ public class TwitterCard implements Card {
@NonNull
@Override
public String toString() {
return "title=\"" + title + "\" description=\"" + description + "\" url=\"" + url + "\"";
return "title=\"" + getTitle() + " \" description=\"" + getDescription() + "\"";
}
}

View File

@ -147,10 +147,22 @@ public class ConfigAccount implements Account {
@NonNull
@Override
public String toString() {
return "date=" + timestamp + " host=\"" + hostname;
if (getUser() != null)
return getUser().toString();
return "";
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Account))
return false;
Account account = (Account) obj;
if (account.getUser() != null && getUser() != null)
return getUser().equals(account.getUser());
return false;
}
/**
* override hostname
*

View File

@ -1,6 +1,7 @@
package org.nuclearfog.twidda.config.impl;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.model.Location;
@ -61,15 +62,21 @@ public class ConfigLocation implements Location {
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Location && ((Location) obj).getId() == getId();
}
@Override
public int compareTo(Location o) {
return Long.compare(id, o.getId());
return Long.compare(getId(), o.getId());
}
@NonNull
@Override
public String toString() {
return "id=" + id + " name=\"" + name + "\"";
return "id=" + getId() + " name=\"" + getFullName() + "\"";
}
}

View File

@ -148,7 +148,20 @@ public class DatabaseAccount implements Account, AccountTable {
@NonNull
@Override
public String toString() {
return "date=" + loginDate + " host=\"" + host + "\" user=" + user;
if (getUser() != null)
return getUser().toString();
return "";
}
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Account))
return false;
Account account = (Account) obj;
if (account.getUser() != null && getUser() != null)
return getUser().equals(account.getUser());
return false;
}
/**

View File

@ -64,19 +64,19 @@ public class DatabaseEmoji implements Emoji, EmojiTable {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Emoji))
return false;
return ((Emoji) obj).getCode().equals(code);
return ((Emoji) obj).getCode().equals(getCode());
}
@NonNull
@Override
public String toString() {
return "code=\"" + code + "\" category=\"" + category + "\" url=\"" + url + "\"";
return "code=\"" + getCode() + "\" category=\"" + getCategory() + "\" url=\"" + getUrl() + "\"";
}
@Override
public int compareTo(Emoji emoji) {
return String.CASE_INSENSITIVE_ORDER.compare(code, emoji.getCode());
return String.CASE_INSENSITIVE_ORDER.compare(getCode(), emoji.getCode());
}
}

View File

@ -78,21 +78,19 @@ public class DatabaseLocation implements Location, LocationTable {
@Override
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Location))
return false;
return ((Location) obj).getId() == id;
return obj instanceof Location && ((Location) obj).getId() == getId();
}
@Override
public int compareTo(Location o) {
return Long.compare(id, o.getId());
return Long.compare(getId(), o.getId());
}
@NonNull
@Override
public String toString() {
return "id=" + id + " name=\"" + name + "\"";
return "id=" + getId() + " name=\"" + getFullName() + "\"";
}
}

View File

@ -3,6 +3,7 @@ package org.nuclearfog.twidda.database.impl;
import android.database.Cursor;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.database.DatabaseAdapter.MediaTable;
import org.nuclearfog.twidda.model.Media;
@ -68,9 +69,15 @@ public class DatabaseMedia implements Media, MediaTable {
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Media && ((Media) obj).getKey().equals(getKey());
}
@Override
public int compareTo(Media o) {
return String.CASE_INSENSITIVE_ORDER.compare(key, o.getKey());
return String.CASE_INSENSITIVE_ORDER.compare(getKey(), o.getKey());
}
@ -78,7 +85,7 @@ public class DatabaseMedia implements Media, MediaTable {
@Override
public String toString() {
String tostring;
switch (mediaType) {
switch (getMediaType()) {
case PHOTO:
tostring = "photo:";
break;
@ -95,7 +102,6 @@ public class DatabaseMedia implements Media, MediaTable {
tostring = "none:";
break;
}
tostring += "url=\"" + url + "\"";
return tostring;
return tostring + "url=\"" + getUrl() + "\"";
}
}

View File

@ -92,20 +92,20 @@ public class DatabaseMessage implements Message, MessageTable {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Message))
return false;
return ((Message) obj).getId() == id;
return ((Message) obj).getId() == getId();
}
@NonNull
@Override
public String toString() {
return "from=" + sender + " message=\"" + text + "\"";
return getSender() + " message=\"" + getText() + "\"";
}
@Override
public int compareTo(Message message) {
return Long.compare(message.getTimestamp(), time);
return Long.compare(message.getTimestamp(), getTimestamp());
}
/**

View File

@ -93,19 +93,19 @@ public class DatabaseNotification implements Notification, NotificationTable {
public boolean equals(@Nullable Object obj) {
if (!(obj instanceof Notification))
return false;
return ((Notification) obj).getId() == id;
return ((Notification) obj).getId() == getId();
}
@Override
public int compareTo(Notification notification) {
return Long.compare(notification.getTimestamp(), timestamp);
return Long.compare(notification.getTimestamp(), getTimestamp());
}
@NonNull
@Override
public String toString() {
return "id=" + id + " " + user;
return "id=" + getId() + " " + getUser();
}
}

View File

@ -2,6 +2,9 @@ package org.nuclearfog.twidda.database.impl;
import android.database.Cursor;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.nuclearfog.twidda.database.DatabaseAdapter.PollTable;
import org.nuclearfog.twidda.model.Poll;
@ -86,8 +89,22 @@ public class DatabasePoll implements Poll, PollTable {
@Override
public int compareTo(Poll o) {
return 0;
public boolean equals(Object o) {
return o instanceof Poll && ((Poll)o).getId() == getId();
}
@NonNull
@Override
public String toString() {
StringBuilder optionsBuf = new StringBuilder();
if (getOptions().length > 0) {
optionsBuf.append(" options=(");
for (Option option : getOptions())
optionsBuf.append(option).append(',');
optionsBuf.deleteCharAt(optionsBuf.length() - 1).append(')');
}
return "id=" + getId() + " expired=" + expirationTime() + optionsBuf;
}
/**
@ -118,8 +135,21 @@ public class DatabasePoll implements Poll, PollTable {
@Override
public boolean selected() {
public boolean isSelected() {
return false;
}
@NonNull
@Override
public String toString() {
return "title=\"" + getTitle() + "\" votes=" + getVotes() + " selected=" + isSelected();
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Option && ((Option) obj).getTitle().equals(getTitle());
}
}
}

View File

@ -64,23 +64,21 @@ public class DatabaseTrend implements Trend, TrendTable {
}
@Override
public int compareTo(Trend trend) {
if (trend.getPopularity() > 0 && getPopularity() > 0)
return Integer.compare(trend.getPopularity(), getPopularity());
if (trend.getPopularity() > 0)
return 1;
if (getPopularity() > 0)
return -1;
return String.CASE_INSENSITIVE_ORDER.compare(getName(), trend.getName());
}
@NonNull
@Override
public String toString() {
return "rank=" + rank + " name=\"" + name + "\"";
}
@Override
public int compareTo(Trend trend) {
if (trend.getRank() > 0 && rank > 0)
return Integer.compare(rank, trend.getRank());
if (trend.getPopularity() > 0 && popularity > 0)
return Integer.compare(trend.getPopularity(), popularity);
if (trend.getPopularity() > 0)
return 1;
if (popularity > 0)
return -1;
return String.CASE_INSENSITIVE_ORDER.compare(name, trend.getName());
return "name=\"" + getName() + "\"";
}
}

View File

@ -7,7 +7,7 @@ import java.io.Serializable;
*
* @author nuclearfog
*/
public interface Poll extends Serializable, Comparable<Poll> {
public interface Poll extends Serializable {
/**
* @return ID of the poll
@ -63,6 +63,6 @@ public interface Poll extends Serializable, Comparable<Poll> {
/**
* @return true if option is selected
*/
boolean selected();
boolean isSelected();
}
}

View File

@ -37,5 +37,5 @@ public interface Relation extends Serializable {
/**
* @return true if this user accepts direct messages from the current user
*/
boolean canDm();
boolean privateMessagingEnabled();
}

View File

@ -377,7 +377,7 @@ public class ProfileActivity extends AppCompatActivity implements ActivityResult
MenuItem muteIcon = m.findItem(R.id.profile_mute);
muteIcon.setTitle(R.string.menu_unmute_user);
}
if (relation.canDm()) {
if (relation.privateMessagingEnabled()) {
MenuItem dmIcon = m.findItem(R.id.profile_message);
dmIcon.setVisible(true);
}

View File

@ -20,13 +20,18 @@ import androidx.appcompat.widget.Toolbar;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.ext.okhttp.OkHttpDataSource;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorsFactory;
import com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor;
import com.google.android.exoplayer2.extractor.mp4.Mp4Extractor;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.android.exoplayer2.upstream.ContentDataSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSource;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.utils.AppStyles;
@ -39,7 +44,7 @@ import okhttp3.Call;
*
* @author nuclearfog
*/
public class VideoViewer extends AppCompatActivity {
public class VideoViewer extends AppCompatActivity implements Player.Listener {
/**
* key for an Uri array with local links
@ -53,6 +58,11 @@ public class VideoViewer extends AppCompatActivity {
*/
public static final String ENABLE_VIDEO_CONTROLS = "enable_controls";
/**
* online video cache size
*/
private static final int CACHE_SIZE = 64000000;
private ExoPlayer player;
private Toolbar toolbar;
@ -72,6 +82,7 @@ public class VideoViewer extends AppCompatActivity {
toolbar = findViewById(R.id.page_video_toolbar);
player = new ExoPlayer.Builder(this).build();
player.addListener(this);
toolbar.setTitle("");
setSupportActionBar(toolbar);
@ -82,16 +93,34 @@ public class VideoViewer extends AppCompatActivity {
playerView.setUseController(false);
player.setRepeatMode(Player.REPEAT_MODE_ONE);
}
DataSource.Factory dataSourceFactory;
MediaItem mediaItem = MediaItem.fromUri(data);
// initialize online source
if (data.getScheme().startsWith("http")) {
dataSourceFactory = new OkHttpDataSource.Factory((Call.Factory) ConnectionBuilder.create(this, 128000));
} else {
dataSourceFactory = new DefaultDataSource.Factory(this);
toolbar.setVisibility(View.GONE);
// configure with okhttp connection of the app
dataSourceFactory = new OkHttpDataSource.Factory((Call.Factory) ConnectionBuilder.create(this, CACHE_SIZE));
}
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItem);
// initialize local source
else {
toolbar.setVisibility(View.GONE);
dataSourceFactory = new DataSource.Factory() {
@NonNull
@Override
public DataSource createDataSource() {
return new ContentDataSource(getApplicationContext());
}
};
}
// initialize video extractor
ExtractorsFactory customExtractor = new ExtractorsFactory() {
@NonNull
@Override
public Extractor[] createExtractors() {
return new Extractor[] {new Mp4Extractor(), new MatroskaExtractor()};
}
};
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory, customExtractor).createMediaSource(mediaItem);
player.setMediaSource(mediaSource);
playerView.setPlayer(player);
@ -143,4 +172,11 @@ public class VideoViewer extends AppCompatActivity {
}
return super.onOptionsItemSelected(item);
}
@Override
public void onPlayerError(PlaybackException error) {
Toast.makeText(getApplicationContext(), "ExoPlayer: " + error.getErrorCodeName(), Toast.LENGTH_SHORT).show();
finish();
}
}

View File

@ -84,7 +84,7 @@ public class OptionsAdapter extends RecyclerView.Adapter<Optionholder> implement
options = poll.getOptions();
for (int i = 0; i < options.length; i++) {
Poll.Option option = options[i];
if (option.selected()) {
if (option.isSelected()) {
selection.add(i);
}
}

View File

@ -74,7 +74,7 @@ public class Optionholder extends ViewHolder implements OnClickListener {
* @param totalCount total vote count
*/
public void setContent(Option option, boolean selected, int totalCount) {
if (option.selected() | selected) {
if (option.isSelected() | selected) {
checkIcon.setImageResource(R.drawable.check);
} else {
checkIcon.setImageResource(R.drawable.circle);