diff --git a/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java b/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java index 736ae75b3..9565fd15c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java +++ b/app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java @@ -74,7 +74,8 @@ public class TuskyApplication extends Application implements HasActivityInjector AppDatabase.MIGRATION_5_6, AppDatabase.MIGRATION_6_7, AppDatabase.MIGRATION_7_8, AppDatabase.MIGRATION_8_9, AppDatabase.MIGRATION_9_10, AppDatabase.MIGRATION_10_11, AppDatabase.MIGRATION_11_12, AppDatabase.MIGRATION_12_13, AppDatabase.MIGRATION_10_13, - AppDatabase.MIGRATION_13_14, AppDatabase.MIGRATION_14_15, AppDatabase.MIGRATION_15_16) + AppDatabase.MIGRATION_13_14, AppDatabase.MIGRATION_14_15, AppDatabase.MIGRATION_15_16, + AppDatabase.MIGRATION_16_17) .build(); accountManager = new AccountManager(appDatabase); serviceLocator = new ServiceLocator() { diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 7ab9d40ba..a92452140 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -218,7 +218,34 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { } } - protected void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) { + private void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) { + + if(TextUtils.isEmpty(rebloggedUrl)) { + avatar.setPaddingRelative(0, 0, 0, 0); + + if(showBotOverlay && isBot) { + avatarInset.setVisibility(View.VISIBLE); + avatarInset.setBackgroundColor(0x50ffffff); + Glide.with(avatarInset) + .load(R.drawable.ic_bot_24dp) + .into(avatarInset); + + } else { + avatarInset.setVisibility(View.GONE); + } + + } else { + int padding = Utils.convertDpToPx(avatar.getContext(), 12); + avatar.setPaddingRelative(0, 0, padding, padding); + + avatarInset.setVisibility(View.VISIBLE); + avatarInset.setBackground(null); + Glide.with(avatarInset) + .load(rebloggedUrl) + .placeholder(R.drawable.avatar_default) + .into(avatarInset); + } + if (TextUtils.isEmpty(url)) { avatar.setImageResource(R.drawable.avatar_default); } else { @@ -228,14 +255,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder { .into(avatar); } - if (showBotOverlay && isBot && TextUtils.isEmpty(rebloggedUrl)) { - avatarInset.setVisibility(View.VISIBLE); - avatarInset.setImageResource(R.drawable.ic_bot_24dp); - avatarInset.setBackgroundColor(0x50ffffff); - } else { - avatarInset.setBackground(null); - avatarInset.setVisibility(View.GONE); - } } protected void setCreatedAt(@Nullable Date createdAt) { diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java index f28fcdaa1..2474d394c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java @@ -21,7 +21,6 @@ import android.view.View; import android.widget.TextView; import android.widget.ToggleButton; -import com.bumptech.glide.Glide; import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.interfaces.StatusActionListener; import com.keylesspalace.tusky.util.SmartLengthInputFilter; @@ -45,25 +44,6 @@ public class StatusViewHolder extends StatusBaseViewHolder { contentCollapseButton = itemView.findViewById(R.id.button_toggle_content); } - @Override - protected void setAvatar(String url, @Nullable String rebloggedUrl, boolean isBot) { - super.setAvatar(url, rebloggedUrl, isBot); - Context context = avatar.getContext(); - - boolean hasReblog = rebloggedUrl != null && !rebloggedUrl.isEmpty(); - int padding = hasReblog ? Utils.dpToPx(context, 12) : 0; - - avatar.setPaddingRelative(0, 0, padding, padding); - - if (hasReblog) { - avatarInset.setVisibility(View.VISIBLE); - Glide.with(context) - .load(rebloggedUrl) - .placeholder(R.drawable.avatar_default) - .into(avatarInset); - } - } - @Override protected int getMediaPreviewHeight(Context context) { return context.getResources().getDimensionPixelSize(R.dimen.status_media_preview_height); diff --git a/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java b/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java index ad3b3ec4f..c64127831 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java +++ b/app/src/main/java/com/keylesspalace/tusky/db/AppDatabase.java @@ -30,7 +30,7 @@ import androidx.annotation.NonNull; @Database(entities = {TootEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class, TimelineAccountEntity.class, ConversationEntity.class - }, version = 16) + }, version = 17) public abstract class AppDatabase extends RoomDatabase { public abstract TootDao tootDao(); @@ -286,4 +286,11 @@ public abstract class AppDatabase extends RoomDatabase { } }; + public static final Migration MIGRATION_16_17 = new Migration(16, 17) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE `TimelineAccountEntity` ADD COLUMN `bot` INTEGER NOT NULL DEFAULT 0"); + } + }; + } \ No newline at end of file diff --git a/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt b/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt index ce5e000ed..a35a1bd17 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt +++ b/app/src/main/java/com/keylesspalace/tusky/db/TimelineDao.kt @@ -6,7 +6,6 @@ import androidx.room.OnConflictStrategy.IGNORE import androidx.room.OnConflictStrategy.REPLACE import androidx.room.Query import androidx.room.Transaction -import com.keylesspalace.tusky.entity.Poll import io.reactivex.Single @Dao @@ -30,11 +29,12 @@ s.spoilerText, s.visibility, s.mentions, s.application, s.reblogServerId,s.reblo s.content, s.attachments, s.poll, a.serverId as 'a_serverId', a.timelineUserId as 'a_timelineUserId', a.localUsername as 'a_localUsername', a.username as 'a_username', -a.displayName as 'a_displayName', a.url as 'a_url', a.avatar as 'a_avatar', a.emojis as 'a_emojis', +a.displayName as 'a_displayName', a.url as 'a_url', a.avatar as 'a_avatar', +a.emojis as 'a_emojis', a.bot as 'a_bot', rb.serverId as 'rb_serverId', rb.timelineUserId 'rb_timelineUserId', rb.localUsername as 'rb_localUsername', rb.username as 'rb_username', rb.displayName as 'rb_displayName', rb.url as 'rb_url', rb.avatar as 'rb_avatar', -rb.emojis as'rb_emojis' +rb.emojis as'rb_emojis', rb.bot as 'rb_bot' FROM TimelineStatusEntity s LEFT JOIN TimelineAccountEntity a ON (s.timelineUserId = a.timelineUserId AND s.authorServerId = a.serverId) LEFT JOIN TimelineAccountEntity rb ON (s.timelineUserId = rb.timelineUserId AND s.reblogAccountId = rb.serverId) diff --git a/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt b/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt index 1dfe1d1fe..731920032 100644 --- a/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/db/TimelineStatusEntity.kt @@ -64,7 +64,8 @@ data class TimelineAccountEntity( val displayName: String, val url: String, val avatar: String, - val emojis: String + val emojis: String, + val bot: Boolean ) diff --git a/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt b/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt index 5800d4c60..73b8417f0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt +++ b/app/src/main/java/com/keylesspalace/tusky/repository/TimelineRepository.kt @@ -296,7 +296,8 @@ fun Account.toEntity(accountId: Long, gson: Gson): TimelineAccountEntity { displayName = displayName, url = url, avatar = avatar, - emojis = gson.toJson(emojis) + emojis = gson.toJson(emojis), + bot = bot ) } @@ -315,7 +316,7 @@ fun TimelineAccountEntity.toAccount(gson: Gson): Account { followersCount = 0, statusesCount = 0, source = null, - bot = false, + bot = bot, emojis = gson.fromJson(this.emojis, emojisListTypeToken.type), fields = null, moved = null