GitNex/app/src/main/java/org/mian/gitnex/database/api/RepositoriesApi.java

141 lines
3.6 KiB
Java
Raw Normal View History

Implement drafts, introduce Room persistence library for db (#139) Fix no draft message translation updates format improvements typo update some renaming refactors Use better naming convention remove duplicate source arrange draft titles enhance click listener area Launch drafts from reply screen and clean up Add message draft saved update repositories tasks Update user accounts repository with thread, remove async tasks remove async task in drafts update layout, change async to thread in drafts Merge branch 'master' into pull_139 # Conflicts: # app/build.gradle # app/src/main/java/org/mian/gitnex/activities/LoginActivity.java Merge branch 'master' into pull_139 # Conflicts: # app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139 # Conflicts: # app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java Merge branch 'master' into pull_139 # Conflicts: # app/src/main/java/org/mian/gitnex/activities/LoginActivity.java # app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java # app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java Merge branch 'master' into pull_139 Merge branch 'master' into pull_139 Merge branch 'master' into pull_139 and fix conflicts # Conflicts: # app/build.gradle # app/src/main/java/org/mian/gitnex/activities/LoginActivity.java # app/src/main/java/org/mian/gitnex/activities/MainActivity.java # app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java # app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java # app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java # app/src/main/res/values/strings.xml Code Format Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft # Conflicts: # app/src/main/java/org/mian/gitnex/activities/MainActivity.java # app/src/main/res/values/strings.xml Go to draft, save on type and other fixes delete all drafts, added messages where needed delete draft Force logout Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft # Conflicts: # app/src/main/java/org/mian/gitnex/activities/MainActivity.java # app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java check if account data is null, we need to log the user out for the 1st time. Merge branch 'master' into 15-comments-draft fix repo owner, name sequence Add comments for test, show drafts list Add repos to db Add account to db and other refactors to the code Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft # Conflicts: # app/build.gradle # app/src/main/AndroidManifest.xml Merge branch 'master' into 15-comments-draft merge more queries, added dao repositories, layout update Added queries in dao some refactor. added models, dao, entities (accounts, repositories, drafts) WIP on implementing drafts, introduced Room persistence library for db. Co-authored-by: M M Arif <mmarif@swatian.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139 Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
package org.mian.gitnex.database.api;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.LiveData;
import org.mian.gitnex.database.dao.RepositoriesDao;
import org.mian.gitnex.database.db.GitnexDatabase;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import java.util.List;
/**
* Author M M Arif
*/
public class RepositoriesApi {
private static RepositoriesDao repositoriesDao;
private static long repositoryId;
private static Repository repository;
private static Integer checkRepository;
public RepositoriesApi(Context context) {
GitnexDatabase db;
db = GitnexDatabase.getDatabaseInstance(context);
repositoriesDao = db.repositoriesDao();
}
public long insertRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
Repository repository = new Repository();
repository.setRepoAccountId(repoAccountId);
repository.setRepositoryOwner(repositoryOwner);
repository.setRepositoryName(repositoryName);
return insertRepositoryAsyncTask(repository);
}
public long insertRepositoryAsyncTask(Repository repository) {
try {
Thread thread = new Thread(() -> repositoryId = repositoriesDao.newRepository(repository));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repositoryId;
}
public Repository getRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
try {
Thread thread = new Thread(() -> repository = repositoriesDao.getSingleRepositoryDao(repoAccountId, repositoryOwner, repositoryName));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repository;
}
public LiveData<List<Repository>> getAllRepositories() {
return repositoriesDao.fetchAllRepositories();
}
public LiveData<List<Repository>> getAllRepositoriesByAccount(int repoAccountId) {
return repositoriesDao.getAllRepositoriesByAccountDao(repoAccountId);
}
public Integer checkRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
try {
Thread thread = new Thread(() -> checkRepository = repositoriesDao.checkRepositoryDao(repoAccountId, repositoryOwner, repositoryName));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return checkRepository;
}
public Repository fetchRepositoryById(int repositoryId) {
try {
Thread thread = new Thread(() -> repository = repositoriesDao.fetchRepositoryByIdDao(repositoryId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repository;
}
public Repository fetchRepositoryByAccountIdByRepositoryId(int repositoryId, int repoAccountId) {
try {
Thread thread = new Thread(() -> repository = repositoriesDao.fetchRepositoryByAccountIdByRepositoryIdDao(repositoryId, repoAccountId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repository;
}
public static void deleteRepositoriesByAccount(final int repoAccountId) {
new Thread(() -> repositoriesDao.deleteRepositoriesByAccount(repoAccountId)).start();
}
public static void deleteRepository(final int repositoryId) {
new Thread(() -> repositoriesDao.deleteRepository(repositoryId)).start();
}
}