Skip to content

Commit 8d4cf62

Browse files
committed
Merge branch 'tusky_master' into merge_upstream
# Conflicts: # app/src/main/java/tech/bigfig/roma/fragment/NotificationsFragment.java # app/src/main/res/layout/item_conversation.xml # app/src/main/res/layout/item_status.xml
2 parents 4c44b55 + 84f561a commit 8d4cf62

27 files changed

+1377
-62
lines changed

app/schemas/tech.bigfig.roma.db.AppDatabase/14.json

Lines changed: 662 additions & 0 deletions
Large diffs are not rendered by default.

app/src/main/java/tech/bigfig/roma/PreferencesActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ class PreferencesActivity : BaseActivity(), SharedPreferences.OnSharedPreference
143143
"absoluteTimeView" -> {
144144
restartActivitiesOnExit = true
145145
}
146+
"showBotOverlay" -> {
147+
restartActivitiesOnExit = true
148+
}
146149
"language" -> {
147150
restartActivitiesOnExit = true
148151
this.restartCurrentActivity()

app/src/main/java/tech/bigfig/roma/RomaApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ public void onCreate() {
9292
.addMigrations(AppDatabase.MIGRATION_2_3, AppDatabase.MIGRATION_3_4, AppDatabase.MIGRATION_4_5,
9393
AppDatabase.MIGRATION_5_6, AppDatabase.MIGRATION_6_7, AppDatabase.MIGRATION_7_8,
9494
AppDatabase.MIGRATION_8_9, AppDatabase.MIGRATION_9_10, AppDatabase.MIGRATION_10_11,
95-
AppDatabase.MIGRATION_11_12, AppDatabase.MIGRATION_12_13, AppDatabase.MIGRATION_10_13)
95+
AppDatabase.MIGRATION_11_12, AppDatabase.MIGRATION_12_13, AppDatabase.MIGRATION_10_13,
96+
AppDatabase.MIGRATION_13_14)
9697
.build();
9798
accountManager = new AccountManager(appDatabase);
9899
serviceLocator = new ServiceLocator() {

app/src/main/java/tech/bigfig/roma/adapter/AccountViewHolder.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import android.content.Context;
44
import androidx.recyclerview.widget.RecyclerView;
5+
6+
import android.preference.PreferenceManager;
57
import android.view.View;
68
import android.widget.ImageView;
79
import android.widget.TextView;
@@ -17,13 +19,17 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
1719
private TextView username;
1820
private TextView displayName;
1921
private ImageView avatar;
22+
private ImageView avatarInset;
2023
private String accountId;
24+
private boolean showBotOverlay;
2125

2226
AccountViewHolder(View itemView) {
2327
super(itemView);
2428
username = itemView.findViewById(R.id.account_username);
2529
displayName = itemView.findViewById(R.id.account_display_name);
2630
avatar = itemView.findViewById(R.id.account_avatar);
31+
avatarInset = itemView.findViewById(R.id.account_avatar_inset);
32+
showBotOverlay = PreferenceManager.getDefaultSharedPreferences(itemView.getContext()).getBoolean("showBotOverlay", true);
2733
}
2834

2935
void setupWithAccount(Account account) {
@@ -38,6 +44,13 @@ void setupWithAccount(Account account) {
3844
.load(account.getAvatar())
3945
.placeholder(R.drawable.avatar_default)
4046
.into(avatar);
47+
if (showBotOverlay && account.getBot()) {
48+
avatarInset.setVisibility(View.VISIBLE);
49+
avatarInset.setImageResource(R.drawable.ic_bot_24dp);
50+
avatarInset.setBackgroundColor(0x50ffffff);
51+
} else {
52+
avatarInset.setVisibility(View.GONE);
53+
}
4154
}
4255

4356
void setupActionListener(final AccountActionListener listener) {

app/src/main/java/tech/bigfig/roma/adapter/NotificationsAdapter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,25 @@ public NotificationsAdapter(AdapterDataSource<NotificationViewData> dataSource,
9999
@NonNull
100100
@Override
101101
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
102+
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
102103
switch (viewType) {
103104
case VIEW_TYPE_MENTION: {
104-
View view = LayoutInflater.from(parent.getContext())
105+
View view = inflater
105106
.inflate(R.layout.item_status, parent, false);
106107
return new StatusViewHolder(view, useAbsoluteTime);
107108
}
108109
case VIEW_TYPE_STATUS_NOTIFICATION: {
109-
View view = LayoutInflater.from(parent.getContext())
110+
View view = inflater
110111
.inflate(R.layout.item_status_notification, parent, false);
111112
return new StatusNotificationViewHolder(view, useAbsoluteTime);
112113
}
113114
case VIEW_TYPE_FOLLOW: {
114-
View view = LayoutInflater.from(parent.getContext())
115+
View view = inflater
115116
.inflate(R.layout.item_follow, parent, false);
116117
return new FollowViewHolder(view);
117118
}
118119
case VIEW_TYPE_PLACEHOLDER: {
119-
View view = LayoutInflater.from(parent.getContext())
120+
View view = inflater
120121
.inflate(R.layout.item_status_placeholder, parent, false);
121122
return new PlaceholderViewHolder(view);
122123
}

app/src/main/java/tech/bigfig/roma/adapter/StatusBaseViewHolder.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.graphics.drawable.Drawable;
5+
import android.preference.PreferenceManager;
56
import android.text.Spanned;
67
import android.text.TextUtils;
78
import android.view.View;
@@ -63,6 +64,7 @@ public static class Key {
6364
private View sensitiveMediaShow;
6465
protected TextView mediaLabel;
6566
private ToggleButton contentWarningButton;
67+
protected ImageView avatarInset;
6668

6769
public ImageView avatar;
6870
public TextView timestampInfo;
@@ -72,6 +74,7 @@ public static class Key {
7274
private boolean useAbsoluteTime;
7375
private SimpleDateFormat shortSdf;
7476
private SimpleDateFormat longSdf;
77+
private boolean showBotOverlay;
7578

7679
private final NumberFormat numberFormat = NumberFormat.getNumberInstance();
7780

@@ -83,7 +86,7 @@ protected StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) {
8386
content = itemView.findViewById(R.id.status_content);
8487
avatar = itemView.findViewById(R.id.status_avatar);
8588
replyButton = itemView.findViewById(R.id.status_reply);
86-
reblogButton = itemView.findViewById(R.id.status_reblog);
89+
reblogButton = itemView.findViewById(R.id.status_inset);
8790
favouriteButton = itemView.findViewById(R.id.status_favourite);
8891
moreButton = itemView.findViewById(R.id.status_more);
8992
reblogged = false;
@@ -105,10 +108,12 @@ protected StatusBaseViewHolder(View itemView, boolean useAbsoluteTime) {
105108
mediaLabel = itemView.findViewById(R.id.status_media_label);
106109
contentWarningDescription = itemView.findViewById(R.id.status_content_warning_description);
107110
contentWarningButton = itemView.findViewById(R.id.status_content_warning_button);
111+
avatarInset = itemView.findViewById(R.id.status_avatar_inset);
108112

109113
this.useAbsoluteTime = useAbsoluteTime;
110114
shortSdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
111115
longSdf = new SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault());
116+
showBotOverlay = PreferenceManager.getDefaultSharedPreferences(itemView.getContext()).getBoolean("showBotOverlay", true);
112117
}
113118

114119
protected abstract int getMediaPreviewHeight(Context context);
@@ -174,7 +179,7 @@ private void setTextVisible(boolean expanded,
174179
}
175180
}
176181

177-
protected void setAvatar(String url, @Nullable String rebloggedUrl) {
182+
protected void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) {
178183
if (TextUtils.isEmpty(url)) {
179184
avatar.setImageResource(R.drawable.avatar_default);
180185
} else {
@@ -183,6 +188,14 @@ protected void setAvatar(String url, @Nullable String rebloggedUrl) {
183188
.placeholder(R.drawable.avatar_default)
184189
.into(avatar);
185190
}
191+
192+
if (showBotOverlay && isBot && TextUtils.isEmpty(rebloggedUrl)) {
193+
avatarInset.setVisibility(View.VISIBLE);
194+
avatarInset.setImageResource(R.drawable.ic_bot_24dp);
195+
avatarInset.setBackgroundColor(0x50ffffff);
196+
} else {
197+
avatarInset.setVisibility(View.GONE);
198+
}
186199
}
187200

188201
protected void setCreatedAt(@Nullable Date createdAt) {
@@ -556,7 +569,7 @@ protected void setupWithStatus(StatusViewData.Concrete status, final StatusActio
556569
setUsername(status.getNickname());
557570
setCreatedAt(status.getCreatedAt());
558571
setIsReply(status.getInReplyToId() != null);
559-
setAvatar(status.getAvatar(), status.getRebloggedAvatar());
572+
setAvatar(status.getAvatar(), status.getRebloggedAvatar(), status.isBot());
560573
setReblogged(status.isReblogged());
561574
setFavourited(status.isFavourited());
562575
List<Attachment> attachments = status.getAttachments();

app/src/main/java/tech/bigfig/roma/adapter/StatusViewHolder.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import android.content.Context;
1919
import android.text.InputFilter;
20+
import android.text.TextUtils;
2021
import android.view.View;
2122
import android.widget.ImageView;
2223
import android.widget.TextView;
@@ -36,35 +37,28 @@ public class StatusViewHolder extends StatusBaseViewHolder {
3637
private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE};
3738
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
3839

39-
private ImageView avatarReblog;
4040
private TextView rebloggedBar;
4141
private ToggleButton contentCollapseButton;
4242

4343
StatusViewHolder(View itemView, boolean useAbsoluteTime) {
4444
super(itemView, useAbsoluteTime);
45-
avatarReblog = itemView.findViewById(R.id.status_avatar_reblog);
4645
rebloggedBar = itemView.findViewById(R.id.status_reblogged);
4746
contentCollapseButton = itemView.findViewById(R.id.button_toggle_content);
4847
}
4948

5049
@Override
51-
protected void setAvatar(String url, @Nullable String rebloggedUrl) {
52-
super.setAvatar(url, rebloggedUrl);
53-
50+
protected void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) {
51+
super.setAvatar(url, rebloggedUrl, isBot);
5452
Context context = avatar.getContext();
55-
boolean hasReblog = rebloggedUrl != null && !rebloggedUrl.isEmpty();
56-
int padding = hasReblog ? Utils.dpToPx(context, 12) : 0;
57-
58-
avatar.setPaddingRelative(0, 0, padding, padding);
5953

60-
if (hasReblog) {
61-
avatarReblog.setVisibility(View.VISIBLE);
54+
if (!TextUtils.isEmpty(rebloggedUrl)) {
55+
int padding = Utils.dpToPx(context, 12);
56+
avatar.setPaddingRelative(0, 0, padding, padding);
57+
avatarInset.setVisibility(View.VISIBLE);
6258
Picasso.with(context)
6359
.load(rebloggedUrl)
6460
.placeholder(R.drawable.avatar_default)
65-
.into(avatarReblog);
66-
} else {
67-
avatarReblog.setVisibility(View.GONE);
61+
.into(avatarInset);
6862
}
6963
}
7064

app/src/main/java/tech/bigfig/roma/db/AccountEntity.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ data class AccountEntity(@field:PrimaryKey(autoGenerate = true) var id: Long,
5151
var lastNotificationId: String = "0",
5252
var activeNotifications: String = "[]",
5353
var emojis: List<Emoji> = emptyList(),
54-
var tabPreferences: List<TabData> = defaultTabs()) {
54+
var tabPreferences: List<TabData> = defaultTabs(),
55+
var notificationsFilter: String = "[]") {
5556

5657
val identifier: String
5758
get() = "$domain:$accountId"

app/src/main/java/tech/bigfig/roma/db/AppDatabase.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
@Database(entities = {TootEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class,
3232
TimelineAccountEntity.class, ConversationEntity.class
33-
}, version = 13)
33+
}, version = 14)
3434
public abstract class AppDatabase extends RoomDatabase {
3535

3636
public abstract TootDao tootDao();
@@ -256,6 +256,13 @@ public void migrate(@NonNull SupportSQLiteDatabase database) {
256256
}
257257
};
258258

259+
public static final Migration MIGRATION_13_14 = new Migration(13, 14) {
260+
@Override
261+
public void migrate(@NonNull SupportSQLiteDatabase database) {
262+
database.execSQL("ALTER TABLE `AccountEntity` ADD COLUMN `notificationsFilter` TEXT NOT NULL DEFAULT '[]'");
263+
}
264+
};
265+
259266
public static final Migration MIGRATION_10_13 = new Migration(10, 13) {
260267
@Override
261268
public void migrate(@NonNull SupportSQLiteDatabase database) {

app/src/main/java/tech/bigfig/roma/entity/Notification.kt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515

1616
package tech.bigfig.roma.entity
1717

18-
import com.google.gson.JsonDeserializationContext
19-
import com.google.gson.JsonDeserializer
20-
import com.google.gson.JsonElement
21-
import com.google.gson.JsonParseException
18+
import com.google.gson.*
2219
import com.google.gson.annotations.JsonAdapter
2320

2421
data class Notification(
@@ -28,26 +25,28 @@ data class Notification(
2825
val status: Status?) {
2926

3027
@JsonAdapter(NotificationTypeAdapter::class)
31-
enum class Type {
32-
UNKNOWN,
33-
MENTION,
34-
REBLOG,
35-
FAVOURITE,
36-
FOLLOW;
28+
enum class Type(val presentation: String) {
29+
UNKNOWN("unknown"),
30+
MENTION("mention"),
31+
REBLOG("reblog"),
32+
FAVOURITE("favourite"),
33+
FOLLOW("follow");
3734

3835
companion object {
3936

4037
@JvmStatic
4138
fun byString(s: String): Type {
42-
return when (s) {
43-
"mention" -> MENTION
44-
"reblog" -> REBLOG
45-
"favourite" -> FAVOURITE
46-
"follow" -> FOLLOW
47-
else -> UNKNOWN
39+
values().forEach {
40+
if (s == it.presentation)
41+
return it
4842
}
43+
return UNKNOWN
4944
}
45+
val asList = listOf(MENTION,REBLOG,FAVOURITE,FOLLOW)
46+
}
5047

48+
override fun toString(): String {
49+
return presentation
5150
}
5251
}
5352

0 commit comments

Comments
 (0)