mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2023-12-13 20:50:18 +01:00
save data to db
This commit is contained in:
parent
e334719bb3
commit
2d8a2a7db5
|
@ -117,14 +117,21 @@ public class ExploreIssuesAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
|
||||
RepositoryContext repo = new RepositoryContext(repoOwner, repoName, context);
|
||||
|
||||
repo.saveToDB(context);
|
||||
|
||||
Intent intentIssueDetail = new IssueContext(issue, repo).getIntent(context, IssueDetailActivity.class);
|
||||
intentIssueDetail.putExtra("openedFromLink", "true");
|
||||
|
||||
itemView.setOnClickListener(v -> context.startActivity(intentIssueDetail));
|
||||
frameLabels.setOnClickListener(v -> context.startActivity(intentIssueDetail));
|
||||
frameLabelsDots.setOnClickListener(v -> context.startActivity(intentIssueDetail));
|
||||
itemView.setOnClickListener(v -> {
|
||||
repo.saveToDB(context);
|
||||
context.startActivity(intentIssueDetail);
|
||||
});
|
||||
frameLabels.setOnClickListener(v -> {
|
||||
repo.saveToDB(context);
|
||||
context.startActivity(intentIssueDetail);
|
||||
});
|
||||
frameLabelsDots.setOnClickListener(v -> {
|
||||
repo.saveToDB(context);
|
||||
context.startActivity(intentIssueDetail);
|
||||
});
|
||||
}, 200);
|
||||
|
||||
issueAssigneeAvatar.setOnClickListener(v -> {
|
||||
|
|
|
@ -19,12 +19,13 @@ public class RepositoriesApi extends BaseApi {
|
|||
repositoriesDao = gitnexDatabase.repositoriesDao();
|
||||
}
|
||||
|
||||
public long insertRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
|
||||
public long insertRepository(int repoAccountId, String repositoryOwner, String repositoryName, int mostVisited) {
|
||||
|
||||
Repository repository = new Repository();
|
||||
repository.setRepoAccountId(repoAccountId);
|
||||
repository.setRepositoryOwner(repositoryOwner);
|
||||
repository.setRepositoryName(repositoryName);
|
||||
repository.setMostVisited(mostVisited);
|
||||
|
||||
return insertRepositoryAsyncTask(repository);
|
||||
}
|
||||
|
@ -69,4 +70,7 @@ public class RepositoriesApi extends BaseApi {
|
|||
executorService.execute(() -> repositoriesDao.deleteRepository(repositoryId));
|
||||
}
|
||||
|
||||
public void updateRepositoryMostVisited(int mostVisited, int repositoryId) {
|
||||
executorService.execute(() -> repositoriesDao.updateRepositoryMostVisited(mostVisited, repositoryId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,4 +44,6 @@ public interface RepositoriesDao {
|
|||
@Query("DELETE FROM Repositories WHERE repoAccountId = :repoAccountId")
|
||||
void deleteRepositoriesByAccount(int repoAccountId);
|
||||
|
||||
@Query("UPDATE Repositories SET mostVisited = :mostVisited WHERE repositoryId = :repositoryId")
|
||||
void updateRepositoryMostVisited(int mostVisited, int repositoryId);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,11 @@ import org.mian.gitnex.database.models.UserAccount;
|
|||
*/
|
||||
|
||||
@Database(entities = {Draft.class, Repository.class, UserAccount.class},
|
||||
version = 5, exportSchema = false)
|
||||
version = 6, exportSchema = false)
|
||||
public abstract class GitnexDatabase extends RoomDatabase {
|
||||
|
||||
private static final String DB_NAME = "gitnex";
|
||||
private static GitnexDatabase gitnexDatabase;
|
||||
private static volatile GitnexDatabase gitnexDatabase;
|
||||
|
||||
public abstract DraftsDao draftsDao();
|
||||
public abstract RepositoriesDao repositoriesDao();
|
||||
|
@ -61,6 +61,14 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
|||
}
|
||||
};
|
||||
|
||||
private static final Migration MIGRATION_5_6 = new Migration(5, 6) {
|
||||
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE 'Repositories' ADD COLUMN 'mostVisited' INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
};
|
||||
|
||||
public static GitnexDatabase getDatabaseInstance(Context context) {
|
||||
|
||||
if (gitnexDatabase == null) {
|
||||
|
@ -68,9 +76,9 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
|||
if(gitnexDatabase == null) {
|
||||
|
||||
gitnexDatabase = Room.databaseBuilder(context, GitnexDatabase.class, DB_NAME)
|
||||
// .fallbackToDestructiveMigration()
|
||||
//.fallbackToDestructiveMigration()
|
||||
.allowMainThreadQueries()
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5)
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6)
|
||||
.build();
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class Repository implements Serializable {
|
|||
private int repoAccountId;
|
||||
private String repositoryOwner;
|
||||
private String repositoryName;
|
||||
private int mostVisited;
|
||||
|
||||
public int getRepositoryId() {
|
||||
return repositoryId;
|
||||
|
@ -56,4 +57,12 @@ public class Repository implements Serializable {
|
|||
public void setRepositoryName(String repositoryName) {
|
||||
this.repositoryName = repositoryName;
|
||||
}
|
||||
|
||||
public int getMostVisited() {
|
||||
return mostVisited;
|
||||
}
|
||||
|
||||
public void setMostVisited(int mostVisited) {
|
||||
this.mostVisited = mostVisited;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,15 +244,17 @@ public class RepositoryContext implements Serializable {
|
|||
|
||||
assert repositoryData != null;
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, getOwner(), getName());
|
||||
Repository getMostVisitedValue = repositoryData.getRepository(currentActiveAccountId, getOwner(), getName());
|
||||
|
||||
if(count == 0) {
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, getOwner(), getName());
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, getOwner(), getName(), getMostVisitedValue.getMostVisited() + 1);
|
||||
setRepositoryId((int) id);
|
||||
return (int) id;
|
||||
}
|
||||
else {
|
||||
Repository data = repositoryData.getRepository(currentActiveAccountId, getOwner(), getName());
|
||||
setRepositoryId(data.getRepositoryId());
|
||||
repositoryData.updateRepositoryMostVisited(getMostVisitedValue.getMostVisited() + 1, data.getRepositoryId());
|
||||
return data.getRepositoryId();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue