Improve drafts ui, add edited comments, create new ones on each call (#628)
Merge branch 'master' into 627-save-edit-draft # Conflicts: # app/src/main/java/org/mian/gitnex/actions/IssueActions.java Merge branch 'master' into 627-save-edit-draft Improve drafts, add edited comments, create new ones on each call. Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/628
This commit is contained in:
@@ -27,7 +27,7 @@ public class DraftsApi {
|
||||
draftsDao = db.draftsDao();
|
||||
}
|
||||
|
||||
public long insertDraft(int repositoryId, int draftAccountId, int issueId, String draftText, String draftType) {
|
||||
public long insertDraft(int repositoryId, int draftAccountId, int issueId, String draftText, String draftType, String commentId) {
|
||||
|
||||
Draft draft = new Draft();
|
||||
draft.setDraftRepositoryId(repositoryId);
|
||||
@@ -35,6 +35,7 @@ public class DraftsApi {
|
||||
draft.setIssueId(issueId);
|
||||
draft.setDraftText(draftText);
|
||||
draft.setDraftType(draftType);
|
||||
draft.setCommentId(draftType);
|
||||
|
||||
return insertDraftAsyncTask(draft);
|
||||
}
|
||||
@@ -71,11 +72,11 @@ public class DraftsApi {
|
||||
return draftId;
|
||||
}
|
||||
|
||||
public Integer checkDraft(int issueId, int draftRepositoryId) {
|
||||
public Integer checkDraft(int issueId, int draftRepositoryId, String commentId) {
|
||||
|
||||
try {
|
||||
|
||||
Thread thread = new Thread(() -> checkDraftFlag = draftsDao.checkDraftDao(issueId, draftRepositoryId));
|
||||
Thread thread = new Thread(() -> checkDraftFlag = draftsDao.checkDraftDao(issueId, draftRepositoryId, commentId));
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
@@ -112,14 +113,14 @@ public class DraftsApi {
|
||||
new Thread(() -> draftsDao.deleteAllDrafts(accountId)).start();
|
||||
}
|
||||
|
||||
public static void updateDraft(final String draftText, final int draftId) {
|
||||
public static void updateDraft(final String draftText, final int draftId, final String commentId) {
|
||||
|
||||
new Thread(() -> draftsDao.updateDraft(draftText, draftId)).start();
|
||||
new Thread(() -> draftsDao.updateDraft(draftText, draftId, commentId)).start();
|
||||
}
|
||||
|
||||
public static void updateDraftByIssueIdAsyncTask(final String draftText, final int issueId, final int draftRepositoryId) {
|
||||
public static void updateDraftByIssueIdAsyncTask(final String draftText, final int issueId, final int draftRepositoryId, final String commentId) {
|
||||
|
||||
new Thread(() -> draftsDao.updateDraftByIssueId(draftText, issueId, draftRepositoryId)).start();
|
||||
new Thread(() -> draftsDao.updateDraftByIssueId(draftText, issueId, draftRepositoryId, commentId)).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ public interface DraftsDao {
|
||||
@Query("SELECT * FROM Drafts WHERE issueId = :issueId")
|
||||
LiveData<Draft> fetchDraftByIssueId(int issueId);
|
||||
|
||||
@Query("SELECT count(draftId) FROM Drafts WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId")
|
||||
Integer checkDraftDao(int issueId, int draftRepositoryId);
|
||||
@Query("SELECT count(draftId) FROM Drafts WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId AND commentId = :commentId")
|
||||
Integer checkDraftDao(int issueId, int draftRepositoryId, String commentId);
|
||||
|
||||
@Query("UPDATE Drafts SET draftText= :draftText WHERE draftId = :draftId")
|
||||
void updateDraft(String draftText, int draftId);
|
||||
@Query("UPDATE Drafts SET draftText = :draftText, commentId = :commentId WHERE draftId = :draftId")
|
||||
void updateDraft(String draftText, int draftId, String commentId);
|
||||
|
||||
@Query("UPDATE Drafts SET draftText= :draftText WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId")
|
||||
void updateDraftByIssueId(String draftText, int issueId, int draftRepositoryId);
|
||||
@Query("UPDATE Drafts SET draftText = :draftText WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId AND commentId = :commentId")
|
||||
void updateDraftByIssueId(String draftText, int issueId, int draftRepositoryId, String commentId);
|
||||
|
||||
@Query("SELECT draftId FROM Drafts WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId")
|
||||
Integer getDraftId(int issueId, int draftRepositoryId);
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.mian.gitnex.database.models.UserAccount;
|
||||
*/
|
||||
|
||||
@Database(entities = {Draft.class, Repository.class, UserAccount.class},
|
||||
version = 1, exportSchema = false)
|
||||
version = 2, exportSchema = false)
|
||||
public abstract class GitnexDatabase extends RoomDatabase {
|
||||
|
||||
private static GitnexDatabase gitnexDatabase;
|
||||
@@ -30,7 +30,7 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
||||
String DB_NAME = "gitnex";
|
||||
gitnexDatabase = Room.databaseBuilder(context, GitnexDatabase.class, DB_NAME)
|
||||
//.fallbackToDestructiveMigration()
|
||||
//.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
|
||||
//database.execSQL("DROP TABLE Drafts");
|
||||
//database.execSQL("ALTER TABLE 'Drafts' ADD COLUMN 'draftType' TEXT");
|
||||
database.execSQL("ALTER TABLE 'Drafts' ADD COLUMN 'commentId' TEXT");
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -24,6 +24,8 @@ public class Draft implements Serializable {
|
||||
private String draftText;
|
||||
@Nullable
|
||||
private String draftType;
|
||||
@Nullable
|
||||
private String commentId;
|
||||
|
||||
public int getDraftId() {
|
||||
|
||||
@@ -86,4 +88,15 @@ public class Draft implements Serializable {
|
||||
this.draftType = draftType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getCommentId() {
|
||||
|
||||
return commentId;
|
||||
}
|
||||
|
||||
public void setCommentId(@Nullable String commentId) {
|
||||
|
||||
this.commentId = commentId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class DraftWithRepository {
|
||||
private int issueId;
|
||||
private String draftText;
|
||||
private String draftType;
|
||||
private String commentId;
|
||||
|
||||
public int getRepositoryId() {
|
||||
|
||||
@@ -119,4 +120,14 @@ public class DraftWithRepository {
|
||||
this.draftType = draftType;
|
||||
}
|
||||
|
||||
public String getCommentId() {
|
||||
|
||||
return commentId;
|
||||
}
|
||||
|
||||
public void setCommentId(String commentId) {
|
||||
|
||||
this.commentId = commentId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user