Create polls (#1452)
* add AddPollDialog * add support for pleroma poll options * add PollPreviewView * add Poll support to drafts * add license header, cleanup * rename drawable files to correct size * fix tests * fix bug with Poll having wrong duration after delete&redraft * add input validation * grey out poll button when its disabled * code cleanup & small improvements
This commit is contained in:
parent
444df322a7
commit
51c6852492
61 changed files with 1540 additions and 76 deletions
|
@ -30,7 +30,7 @@ import androidx.annotation.NonNull;
|
|||
|
||||
@Database(entities = {TootEntity.class, AccountEntity.class, InstanceEntity.class, TimelineStatusEntity.class,
|
||||
TimelineAccountEntity.class, ConversationEntity.class
|
||||
}, version = 18)
|
||||
}, version = 19)
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
|
||||
public abstract TootDao tootDao();
|
||||
|
@ -300,4 +300,14 @@ public abstract class AppDatabase extends RoomDatabase {
|
|||
}
|
||||
};
|
||||
|
||||
public static final Migration MIGRATION_18_19 = new Migration(18, 19) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE `InstanceEntity` ADD COLUMN `maxPollOptions` INTEGER");
|
||||
database.execSQL("ALTER TABLE `InstanceEntity` ADD COLUMN `maxPollOptionLength` INTEGER");
|
||||
|
||||
database.execSQL("ALTER TABLE `TootEntity` ADD COLUMN `poll` TEXT");
|
||||
}
|
||||
};
|
||||
|
||||
}
|
|
@ -25,4 +25,7 @@ import com.keylesspalace.tusky.entity.Emoji
|
|||
data class InstanceEntity(
|
||||
@field:PrimaryKey var instance: String,
|
||||
val emojiList: List<Emoji>?,
|
||||
val maximumTootCharacters: Int?)
|
||||
val maximumTootCharacters: Int?,
|
||||
val maxPollOptions: Int?,
|
||||
val maxPollOptionLength: Int?
|
||||
)
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
package com.keylesspalace.tusky.db;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.keylesspalace.tusky.entity.NewPoll;
|
||||
import com.keylesspalace.tusky.entity.Status;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
@ -60,9 +62,13 @@ public class TootEntity {
|
|||
@ColumnInfo(name = "visibility")
|
||||
private final Status.Visibility visibility;
|
||||
|
||||
@Nullable
|
||||
@ColumnInfo(name = "poll")
|
||||
private final NewPoll poll;
|
||||
|
||||
public TootEntity(int uid, String text, String urls, String descriptions, String contentWarning, String inReplyToId,
|
||||
@Nullable String inReplyToText, @Nullable String inReplyToUsername,
|
||||
Status.Visibility visibility) {
|
||||
Status.Visibility visibility, @Nullable NewPoll poll) {
|
||||
this.uid = uid;
|
||||
this.text = text;
|
||||
this.urls = urls;
|
||||
|
@ -72,6 +78,7 @@ public class TootEntity {
|
|||
this.inReplyToText = inReplyToText;
|
||||
this.inReplyToUsername = inReplyToUsername;
|
||||
this.visibility = visibility;
|
||||
this.poll = poll;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
|
@ -112,8 +119,15 @@ public class TootEntity {
|
|||
return visibility;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public NewPoll getPoll() {
|
||||
return poll;
|
||||
}
|
||||
|
||||
public static final class Converters {
|
||||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
@TypeConverter
|
||||
public Status.Visibility visibilityFromInt(int number) {
|
||||
return Status.Visibility.byNum(number);
|
||||
|
@ -123,5 +137,15 @@ public class TootEntity {
|
|||
public int intFromVisibility(Status.Visibility visibility) {
|
||||
return visibility == null ? Status.Visibility.UNKNOWN.getNum() : visibility.getNum();
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public String pollToString(NewPoll poll) {
|
||||
return gson.toJson(poll);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public NewPoll stringToPoll(String poll) {
|
||||
return gson.fromJson(poll, NewPoll.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue