Fix bot icon indicator again (#1249)

* fix handling of bot indicator in timeline

* write bot status into db cache

* remove log
This commit is contained in:
Konrad Pozniak 2019-05-07 07:37:00 +02:00 committed by GitHub
parent 5fb566f818
commit 40d3eb8759
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 46 additions and 37 deletions

View file

@ -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() {

View file

@ -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) {

View file

@ -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);

View file

@ -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");
}
};
}

View file

@ -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)

View file

@ -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
)

View file

@ -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