Browse Source

Implement multi-session notification polling and additional improvements/refactors/cleanups/fixes (#875)

Merge branch 'master' of https://codeberg.org/gitnex/GitNex into notifications-performance-improvements

 Conflicts:
	app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java
	app/src/main/java/org/mian/gitnex/adapters/NotificationsAdapter.java
	app/src/main/java/org/mian/gitnex/adapters/UserAccountsAdapter.java
	app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java
	app/src/main/res/layout/bottom_sheet_repository_in_list.xml
	app/src/main/res/layout/list_files.xml

Merge branch 'master' into notifications-performance-improvements

Merge branch 'master' into notifications-performance-improvements

Merge branch 'master' of https://codeberg.org/gitnex/GitNex into notifications-performance-improvements

 Conflicts:
	app/src/main/res/values-it/strings.xml

Add ripple effect to buttons.

Run syntax highlighting on separate thread. (#859)

Initial commit.

Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/875
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-Authored-By: opyale <opyale@noreply.codeberg.org>
Co-Committed-By: opyale <opyale@noreply.codeberg.org>
pull/900/head
opyale 4 months ago
committed by M M Arif
parent
commit
d72f097012
  1. 12
      app/src/main/java/org/mian/gitnex/activities/AddNewAccountActivity.java
  2. 18
      app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java
  3. 21
      app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
  4. 91
      app/src/main/java/org/mian/gitnex/activities/MainActivity.java
  5. 7
      app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java
  6. 8
      app/src/main/java/org/mian/gitnex/activities/SettingsNotificationsActivity.java
  7. 5
      app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java
  8. 3
      app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java
  9. 3
      app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
  10. 11
      app/src/main/java/org/mian/gitnex/adapters/NotificationsAdapter.java
  11. 3
      app/src/main/java/org/mian/gitnex/adapters/RepoForksAdapter.java
  12. 3
      app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java
  13. 3
      app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java
  14. 3
      app/src/main/java/org/mian/gitnex/adapters/SearchIssuesAdapter.java
  15. 3
      app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java
  16. 17
      app/src/main/java/org/mian/gitnex/adapters/UserAccountsAdapter.java
  17. 18
      app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java
  18. 32
      app/src/main/java/org/mian/gitnex/core/MainApplication.java
  19. 57
      app/src/main/java/org/mian/gitnex/database/api/BaseApi.java
  20. 82
      app/src/main/java/org/mian/gitnex/database/api/DraftsApi.java
  21. 105
      app/src/main/java/org/mian/gitnex/database/api/RepositoriesApi.java
  22. 105
      app/src/main/java/org/mian/gitnex/database/api/UserAccountsApi.java
  23. 19
      app/src/main/java/org/mian/gitnex/database/dao/UserAccountsDao.java
  24. 39
      app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java
  25. 5
      app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java
  26. 5
      app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java
  27. 3
      app/src/main/java/org/mian/gitnex/fragments/RepositoriesFragment.java
  28. 3
      app/src/main/java/org/mian/gitnex/fragments/UserAccountsFragment.java
  29. 38
      app/src/main/java/org/mian/gitnex/helpers/AppUtil.java
  30. 6
      app/src/main/java/org/mian/gitnex/helpers/Authorization.java
  31. 5
      app/src/main/java/org/mian/gitnex/helpers/Constants.java
  32. 2
      app/src/main/java/org/mian/gitnex/helpers/Version.java
  33. 0
      app/src/main/java/org/mian/gitnex/helpers/highlightjs/HighlightJsView.java
  34. 74
      app/src/main/java/org/mian/gitnex/helpers/views/SyntaxHighlightedArea.java
  35. 50
      app/src/main/java/org/mian/gitnex/notifications/Notifications.java
  36. 108
      app/src/main/java/org/mian/gitnex/notifications/NotificationsWorker.java
  37. 3
      app/src/main/res/layout/activity_add_collaborator_to_repository.xml
  38. 3
      app/src/main/res/layout/activity_add_new_team_member.xml
  39. 3
      app/src/main/res/layout/activity_admin_cron_tasks.xml
  40. 3
      app/src/main/res/layout/activity_admin_get_users.xml
  41. 3
      app/src/main/res/layout/activity_commits.xml
  42. 3
      app/src/main/res/layout/activity_create_file.xml
  43. 3
      app/src/main/res/layout/activity_create_issue.xml
  44. 3
      app/src/main/res/layout/activity_create_label.xml
  45. 3
      app/src/main/res/layout/activity_create_milestone.xml
  46. 3
      app/src/main/res/layout/activity_create_new_user.xml
  47. 3
      app/src/main/res/layout/activity_create_organization.xml
  48. 3
      app/src/main/res/layout/activity_create_pr.xml
  49. 3
      app/src/main/res/layout/activity_create_release.xml
  50. 3
      app/src/main/res/layout/activity_create_repo.xml
  51. 3
      app/src/main/res/layout/activity_create_team_by_org.xml
  52. 3
      app/src/main/res/layout/activity_edit_issue.xml
  53. 3
      app/src/main/res/layout/activity_file_diff.xml
  54. 3
      app/src/main/res/layout/activity_file_view.xml
  55. 3
      app/src/main/res/layout/activity_merge_pull_request.xml
  56. 3
      app/src/main/res/layout/activity_org_team_members.xml
  57. 3
      app/src/main/res/layout/activity_profile_email.xml
  58. 3
      app/src/main/res/layout/activity_repo_forks.xml
  59. 3
      app/src/main/res/layout/activity_repo_stargazers.xml
  60. 3
      app/src/main/res/layout/activity_repo_watchers.xml
  61. 59
      app/src/main/res/layout/activity_repository_settings.xml
  62. 80
      app/src/main/res/layout/activity_settings_appearance.xml
  63. 41
      app/src/main/res/layout/activity_settings_drafts.xml
  64. 58
      app/src/main/res/layout/activity_settings_general.xml
  65. 101
      app/src/main/res/layout/activity_settings_notifications.xml
  66. 36
      app/src/main/res/layout/activity_settings_reports.xml
  67. 101
      app/src/main/res/layout/activity_settings_security.xml
  68. 33
      app/src/main/res/layout/activity_settings_translation.xml
  69. 11
      app/src/main/res/layout/bottom_sheet_admin_users.xml
  70. 11
      app/src/main/res/layout/bottom_sheet_drafts.xml
  71. 17
      app/src/main/res/layout/bottom_sheet_file_viewer.xml
  72. 42
      app/src/main/res/layout/bottom_sheet_issue_comments.xml
  73. 14
      app/src/main/res/layout/bottom_sheet_issues_filter.xml
  74. 16
      app/src/main/res/layout/bottom_sheet_labels_in_list.xml
  75. 14
      app/src/main/res/layout/bottom_sheet_milestones_filter.xml
  76. 14
      app/src/main/res/layout/bottom_sheet_milestones_in_list.xml
  77. 21
      app/src/main/res/layout/bottom_sheet_notifications.xml
  78. 14
      app/src/main/res/layout/bottom_sheet_notifications_filter.xml
  79. 28
      app/src/main/res/layout/bottom_sheet_organization.xml
  80. 7
      app/src/main/res/layout/bottom_sheet_organization_teams.xml
  81. 7
      app/src/main/res/layout/bottom_sheet_profile.xml
  82. 14
      app/src/main/res/layout/bottom_sheet_pull_request_filter.xml
  83. 8
      app/src/main/res/layout/bottom_sheet_reply_layout.xml
  84. 85
      app/src/main/res/layout/bottom_sheet_repo.xml
  85. 81
      app/src/main/res/layout/bottom_sheet_single_issue.xml
  86. 11
      app/src/main/res/layout/fragment_profile.xml
  87. 12
      app/src/main/res/layout/fragment_repo_info.xml
  88. 76
      app/src/main/res/layout/fragment_settings.xml
  89. 2
      app/src/main/res/values-ar/strings.xml
  90. 2
      app/src/main/res/values-cs/strings.xml
  91. 2
      app/src/main/res/values-de/strings.xml
  92. 2
      app/src/main/res/values-es/strings.xml
  93. 2
      app/src/main/res/values-fa/strings.xml
  94. 2
      app/src/main/res/values-fi/strings.xml
  95. 2
      app/src/main/res/values-fr/strings.xml
  96. 6
      app/src/main/res/values-it/strings.xml
  97. 2
      app/src/main/res/values-lv/strings.xml
  98. 2
      app/src/main/res/values-pl/strings.xml
  99. 2
      app/src/main/res/values-pt/strings.xml
  100. 2
      app/src/main/res/values-ru/strings.xml

12
app/src/main/java/org/mian/gitnex/activities/AddNewAccountActivity.java

@ -12,6 +12,7 @@ import org.gitnex.tea4j.models.GiteaVersion;
import org.gitnex.tea4j.models.UserInfo;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.databinding.ActivityAddNewAccountBinding;
import org.mian.gitnex.helpers.AppUtil;
@ -114,9 +115,7 @@ public class AddNewAccountActivity extends BaseActivity {
private void versionCheck(final String instanceUrl, final String loginToken) {
Call<GiteaVersion> callVersion;
callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken("token " + loginToken);
callVersion.enqueue(new Callback<GiteaVersion>() {
@Override
@ -205,14 +204,15 @@ public class AddNewAccountActivity extends BaseActivity {
assert userDetails != null;
// insert new account to db if does not exist
String accountName = userDetails.getUsername() + "@" + instanceUrl;
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
int checkAccount = userAccountsApi.getCount(accountName);
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
boolean userAccountExists = userAccountsApi.userAccountExists(accountName);
if(checkAccount == 0) {
if(!userAccountExists) {
userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
userAccountsApi.createNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
Toasty.success(ctx, getResources().getString(R.string.accountAddedMessage));
finish();
}
else {

18
app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java

@ -13,11 +13,13 @@ import org.gitnex.tea4j.models.PullRequests;
import org.gitnex.tea4j.models.UserRepositories;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.databinding.ActivityDeeplinksBinding;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.UrlHelper;
import java.net.URI;
import java.util.List;
@ -65,7 +67,7 @@ public class DeepLinksActivity extends BaseActivity {
}
// check for the links(URI) to be in the db
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
List<UserAccount> userAccounts = userAccountsApi.usersAccounts();
for(UserAccount userAccount : userAccounts) {
@ -79,13 +81,9 @@ public class DeepLinksActivity extends BaseActivity {
accountFound = true;
tinyDB.putString("loginUid", userAccount.getUserName());
tinyDB.putString("userLogin", userAccount.getUserName());
tinyDB.putString(userAccount.getUserName() + "-token", userAccount.getToken());
tinyDB.putString("instanceUrl", userAccount.getInstanceUrl());
tinyDB.putInt("currentActiveAccountId", userAccount.getAccountId());
AppUtil.switchToAccount(ctx, userAccount);
break;
}
}
@ -112,7 +110,7 @@ public class DeepLinksActivity extends BaseActivity {
final String repoName = restOfUrl[restOfUrl.length - 3];
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(ctx);
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
@ -344,7 +342,7 @@ public class DeepLinksActivity extends BaseActivity {
tinyDB.putString("repoFullName", repoOwner + "/" + repoName);
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(ctx);
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
@ -415,7 +413,7 @@ public class DeepLinksActivity extends BaseActivity {
tinyDB.putString("repoBranch", repoInfo.getDefault_branch());
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(ctx);
RepositoriesApi repositoryData = BaseApi.getInstance(ctx, RepositoriesApi.class);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

21
app/src/main/java/org/mian/gitnex/activities/LoginActivity.java

@ -17,6 +17,7 @@ import org.gitnex.tea4j.models.UserInfo;
import org.gitnex.tea4j.models.UserTokens;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.databinding.ActivityLoginBinding;
@ -358,19 +359,19 @@ public class LoginActivity extends BaseActivity {
// insert new account to db if does not exist
String accountName = userDetails.getUsername() + "@" + TinyDB.getInstance(ctx).getString("instanceUrl");
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
int checkAccount = userAccountsApi.getCount(accountName);
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
boolean userAccountExists = userAccountsApi.userAccountExists(accountName);
long accountId;
if(checkAccount == 0) {
if(!userAccountExists) {
accountId = userAccountsApi.insertNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), loginToken, "");
accountId = userAccountsApi.createNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), loginToken, "");
tinyDB.putInt("currentActiveAccountId", (int) accountId);
}
else {
userAccountsApi.updateTokenByAccountName(accountName, loginToken);
UserAccount data = userAccountsApi.getAccountData(accountName);
UserAccount data = userAccountsApi.getAccountByName(accountName);
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
}
@ -546,20 +547,20 @@ public class LoginActivity extends BaseActivity {
// insert new account to db if does not exist
String accountName = userDetails.getUsername() + "@" + TinyDB.getInstance(ctx).getString("instanceUrl");
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
int checkAccount = userAccountsApi.getCount(accountName);
UserAccountsApi userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
boolean userAccountExists = userAccountsApi.userAccountExists(accountName);
long accountId;
if(checkAccount == 0) {
if(!userAccountExists) {
accountId = userAccountsApi
.insertNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), newToken.getSha1(), "");
.createNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), newToken.getSha1(), "");
tinyDB.putInt("currentActiveAccountId", (int) accountId);
}
else {
userAccountsApi.updateTokenByAccountName(accountName, newToken.getSha1());
UserAccount data = userAccountsApi.getAccountData(accountName);
UserAccount data = userAccountsApi.getAccountByName(accountName);
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
}

91
app/src/main/java/org/mian/gitnex/activities/MainActivity.java

@ -20,7 +20,6 @@ import androidx.appcompat.widget.Toolbar;
import androidx.biometric.BiometricPrompt;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
@ -34,6 +33,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.adapters.UserAccountsNavAdapter;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.databinding.ActivityMainBinding;
@ -90,37 +90,24 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
ActivityMainBinding activityMainBinding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(activityMainBinding.getRoot());
tinyDB.putBoolean("noConnection", false);
String currentVersion = tinyDB.getString("giteaVersion");
Intent mainIntent = getIntent();
String launchFragment = mainIntent.getStringExtra("launchFragment");
loginUid = tinyDB.getString("loginUid");
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
if(tinyDB.getString("dateFormat").isEmpty()) {
// DO NOT MOVE
if(mainIntent.hasExtra("switchAccountId") &&
AppUtil.switchToAccount(ctx, BaseApi.getInstance(ctx, UserAccountsApi.class)
.getAccountById(mainIntent.getIntExtra("switchAccountId", 0)))) {
tinyDB.putString("dateFormat", "pretty");
}
if(tinyDB.getString("codeBlockStr").isEmpty()) {
tinyDB.putInt("codeBlockColor", ResourcesCompat.getColor(getResources(), R.color.colorLightGreen, null));
tinyDB.putInt("codeBlockBackground", ResourcesCompat.getColor(getResources(), R.color.black, null));
}
if(tinyDB.getString("enableCounterIssueBadgeInit").isEmpty()) {
mainIntent.removeExtra("switchAccountId");
recreate();
return;
tinyDB.putBoolean("enableCounterIssueBadge", true);
}
// DO NOT MOVE
if(tinyDB.getString("homeScreenStr").isEmpty()) {
tinyDB.putBoolean("noConnection", false);
tinyDB.putString("homeScreenStr", "yes");
tinyDB.putInt("homeScreenId", 0);
}
loginUid = tinyDB.getString("loginUid");
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
@ -130,9 +117,10 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
return;
}
if(tinyDB.getInt("currentActiveAccountId") <= 0) {
AlertDialogs.forceLogoutDialog(ctx, getResources().getString(R.string.forceLogoutDialogHeader), getResources().getString(R.string.forceLogoutDialogDescription), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
if(tinyDB.getInt("currentActiveAccountId", -1) <= 0) {
AlertDialogs.forceLogoutDialog(ctx,
getResources().getString(R.string.forceLogoutDialogHeader),
getResources().getString(R.string.forceLogoutDialogDescription), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
Toolbar toolbar = activityMainBinding.toolbar;
@ -141,17 +129,17 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
switch(tinyDB.getInt("customFontId", -1)) {
case 0:
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
break;
case 2:
case 2:
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodeproregular.ttf");
break;
default:
default:
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/manroperegular.ttf");
break;
}
// biometric auth
@ -198,43 +186,33 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
Fragment fragmentById = fm.findFragmentById(R.id.fragment_container);
if(fragmentById instanceof SettingsFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
}
else if(fragmentById instanceof MyRepositoriesFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
}
else if(fragmentById instanceof StarredRepositoriesFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
}
else if(fragmentById instanceof OrganizationsFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
}
else if(fragmentById instanceof ExploreFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
}
else if(fragmentById instanceof NotificationsFragment) {
toolbarTitle.setText(R.string.pageTitleNotifications);
}
else if(fragmentById instanceof ProfileFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
}
else if(fragmentById instanceof DraftsFragment) {
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
}
else if(fragmentById instanceof AdministrationFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
}
else if(fragmentById instanceof UserAccountsFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleUserAccounts));
}
@ -275,7 +253,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
List<UserAccount> userAccountsList = new ArrayList<>();
UserAccountsApi userAccountsApi;
userAccountsApi = new UserAccountsApi(ctx);
userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class);
RecyclerView navRecyclerViewUserAccounts = hView.findViewById(R.id.userAccounts);
UserAccountsNavAdapter adapterUserAccounts;
@ -294,12 +272,10 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
userFullName.setTypeface(myTypeface);
if(!userEmailNav.equals("")) {
userEmail.setText(userEmailNav);
}
if(!userFullNameNav.equals("")) {
userFullName.setText(Html.fromHtml(userFullNameNav));
}
@ -347,7 +323,8 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
navigationView.getMenu().findItem(R.id.nav_administration).setVisible(tinyDB.getBoolean("userIsAdmin"));
navigationView.getMenu().findItem(R.id.nav_notifications).setVisible(new Version(currentVersion).higherOrEqual("1.12.3"));
navigationView.getMenu().findItem(R.id.nav_notifications).setVisible(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.3"));
}
@Override
@ -361,6 +338,8 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
toggle.syncState();
toolbar.setNavigationIcon(R.drawable.ic_menu);
String launchFragment = mainIntent.getStringExtra("launchFragment");
if(launchFragment != null) {
mainIntent.removeExtra("launchFragment");
@ -368,13 +347,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
switch(launchFragment) {
case "drafts":
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
navigationView.setCheckedItem(R.id.nav_comments_draft);
return;
case "notifications":
case "notifications":
toolbarTitle.setText(getResources().getString(R.string.pageTitleNotifications));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
navigationView.setCheckedItem(R.id.nav_notifications);
@ -415,9 +393,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
if(savedInstanceState == null) {
if(!new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.3")) {
if(tinyDB.getInt("homeScreenId") == 7) {
tinyDB.putInt("homeScreenId", 0);
}
}
@ -658,29 +634,22 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
private void giteaVersion() {
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
Call<GiteaVersion> callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken(token);
Call<GiteaVersion> callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken(Authorization.get(ctx));
callVersion.enqueue(new Callback<GiteaVersion>() {
@Override
public void onResponse(@NonNull final Call<GiteaVersion> callVersion, @NonNull retrofit2.Response<GiteaVersion> responseVersion) {
if(responseVersion.code() == 200) {
GiteaVersion version = responseVersion.body();
assert version != null;
if(responseVersion.code() == 200 && responseVersion.body() != null) {
String version = responseVersion.body().getVersion();
tinyDb.putString("giteaVersion", version.getVersion());
tinyDB.putString("giteaVersion", version);
BaseApi.getInstance(ctx, UserAccountsApi.class).updateServerVersion(version, tinyDB.getInt("currentActiveAccountId"));
}
}
@Override
public void onFailure(@NonNull Call<GiteaVersion> callVersion, @NonNull Throwable t) {
Log.e("onFailure-version", t.toString());
}
});

7
app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java

@ -14,6 +14,7 @@ import org.gitnex.tea4j.models.RepositoryTransfer;
import org.gitnex.tea4j.models.UserRepositories;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.databinding.ActivityRepositorySettingsBinding;
import org.mian.gitnex.databinding.CustomRepositoryDeleteDialogBinding;
@ -139,7 +140,7 @@ public class RepositorySettingsActivity extends BaseActivity {
Toasty.success(ctx, getString(R.string.repoTransferSuccess));
finish();
RepositoriesApi.deleteRepository((int) tinyDB.getLong("repositoryId", 0));
BaseApi.getInstance(ctx, RepositoriesApi.class).deleteRepository((int) tinyDB.getLong("repositoryId", 0));
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
RepositorySettingsActivity.this.startActivity(intent);
}
@ -220,7 +221,7 @@ public class RepositorySettingsActivity extends BaseActivity {
Toasty.success(ctx, getString(R.string.repoDeletionSuccess));
finish();
RepositoriesApi.deleteRepository((int) tinyDB.getLong("repositoryId", 0));
BaseApi.getInstance(ctx, RepositoriesApi.class).deleteRepository((int) tinyDB.getLong("repositoryId", 0));
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
RepositorySettingsActivity.this.startActivity(intent);
}
@ -383,7 +384,7 @@ public class RepositorySettingsActivity extends BaseActivity {
if(!repositoryName.equals(repoName)) {
finish();
RepositoriesApi.updateRepositoryOwnerAndName(repositoryOwner, repoName, (int) tinyDB.getLong("repositoryId", 0));
BaseApi.getInstance(ctx, RepositoriesApi.class).updateRepositoryOwnerAndName(repositoryOwner, repoName, (int) tinyDB.getLong("repositoryId", 0));
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
RepositorySettingsActivity.this.startActivity(intent);
}

8
app/src/main/java/org/mian/gitnex/activities/SettingsNotificationsActivity.java

@ -43,7 +43,13 @@ public class SettingsNotificationsActivity extends BaseActivity {
viewBinding.enableNotificationsMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
tinyDB.putBoolean("notificationsEnabled", isChecked);
if(!isChecked) Notifications.stopWorker(ctx);
if(isChecked) {
Notifications.startWorker(ctx);
} else {
Notifications.stopWorker(ctx);
}
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
});

5
app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java

@ -17,6 +17,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.IssueDetailActivity;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.DraftsApi;
import org.mian.gitnex.database.models.DraftWithRepository;
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
@ -56,8 +57,10 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
int getDraftId = draftWithRepository.getDraftId();
deleteDraft(getAdapterPosition());
DraftsApi draftsApi = new DraftsApi(context);
DraftsApi draftsApi = BaseApi.getInstance(context, DraftsApi.class);
draftsApi.deleteSingleDraft(getDraftId);
});
itemView.setOnClickListener(itemEdit -> {

3
app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java

@ -19,6 +19,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
@ -98,7 +99,7 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

3
app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java

@ -21,6 +21,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
@ -96,7 +97,7 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

11
app/src/main/java/org/mian/gitnex/adapters/NotificationsAdapter.java

@ -13,6 +13,7 @@ import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.RecyclerView;
import org.gitnex.tea4j.models.NotificationThread;
import org.mian.gitnex.R;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.TinyDB;
@ -87,8 +88,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
if(notificationThread.isPinned()) {
holder.pinned.setVisibility(View.VISIBLE);
}
else {
} else {
holder.pinned.setVisibility(View.GONE);
}
@ -123,17 +123,14 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
if(count == 0) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
}
else {
} else {
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
}

3
app/src/main/java/org/mian/gitnex/adapters/RepoForksAdapter.java

@ -20,6 +20,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
@ -220,7 +221,7 @@ public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

3
app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java

@ -21,6 +21,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
@ -96,7 +97,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

3
app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java

@ -21,6 +21,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
@ -96,7 +97,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

3
app/src/main/java/org/mian/gitnex/adapters/SearchIssuesAdapter.java

@ -15,6 +15,7 @@ import org.gitnex.tea4j.models.Issues;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.IssueDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
@ -80,7 +81,7 @@ public class SearchIssuesAdapter extends RecyclerView.Adapter<SearchIssuesAdapte
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

3
app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java

@ -21,6 +21,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.AppUtil;
@ -96,7 +97,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
RepositoriesApi repositoryData = BaseApi.getInstance(context, RepositoriesApi.class);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);

17
app/src/main/java/org/mian/gitnex/adapters/UserAccountsAdapter.java

@ -14,6 +14,7 @@ import androidx.appcompat.content.res.AppCompatResources;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.helpers.AppUtil;
@ -63,7 +64,7 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
.setPositiveButton(context.getResources().getString(R.string.removeButton), (dialog, which) -> {
updateLayoutByPosition(getAdapterPosition());
UserAccountsApi userAccountsApi = new UserAccountsApi(context);
UserAccountsApi userAccountsApi = BaseApi.getInstance(context, UserAccountsApi.class);
userAccountsApi.deleteAccount(Integer.parseInt(String.valueOf(accountId)));
}).setNeutralButton(context.getResources().getString(R.string.cancelButton), null)
.show();
@ -71,25 +72,19 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
itemView.setOnClickListener(switchAccount -> {
UserAccountsApi userAccountsApi = new UserAccountsApi(context);
UserAccount userAccount = userAccountsApi.getAccountData(accountName);
UserAccountsApi userAccountsApi = BaseApi.getInstance(context, UserAccountsApi.class);
UserAccount userAccount = userAccountsApi.getAccountByName(accountName);
if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
if(AppUtil.switchToAccount(context, userAccount)) {
String url = UrlBuilder.fromString(userAccount.getInstanceUrl())
.withPath("/")
.toString();
tinyDB.putString("loginUid", userAccount.getUserName());
tinyDB.putString("userLogin", userAccount.getUserName());
tinyDB.putString(userAccount.getUserName() + "-token", userAccount.getToken());
tinyDB.putString("instanceUrl", userAccount.getInstanceUrl());
tinyDB.putInt("currentActiveAccountId", userAccount.getAccountId());
Toasty.success(context, context.getResources().getString(R.string.switchAccountSuccess, userAccount.getUserName(), url));
((Activity) context).recreate();
}
}
});
}

18
app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java

@ -18,12 +18,10 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.fragments.UserAccountsFragment;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import java.util.List;
import io.mikael.urlbuilder.UrlBuilder;
@ -103,7 +101,6 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNav
private void customDialogUserAccountsList(List<UserAccount> allAccountsList) {
TinyDB tinyDB = TinyDB.getInstance(context);
Dialog dialog = new Dialog(context, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
dialog.setContentView(R.layout.custom_user_accounts_dialog);
@ -120,6 +117,7 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNav
AppCompatActivity activity = (AppCompatActivity) context;
activity.getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new UserAccountsFragment()).commit();
dialog.dismiss();
});
UserAccountsListDialogAdapter arrayAdapter = new UserAccountsListDialogAdapter(context, R.layout.custom_user_accounts_list, allAccountsList);
@ -127,27 +125,21 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNav
listView.setOnItemClickListener((adapterView, view, which, l) -> {
String accountNameSwitch = allAccountsList.get(which).getAccountName();
UserAccountsApi userAccountsApi = new UserAccountsApi(context);
UserAccount userAccount = userAccountsApi.getAccountData(accountNameSwitch);
UserAccount userAccount = allAccountsList.get(which);
if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
if(AppUtil.switchToAccount(context, userAccount)) {
String url = UrlBuilder.fromString(userAccount.getInstanceUrl())
.withPath("/")
.toString();
tinyDB.putString("loginUid", userAccount.getUserName());
tinyDB.putString("userLogin", userAccount.getUserName());
tinyDB.putString(userAccount.getUserName() + "-token", userAccount.getToken());
tinyDB.putString("instanceUrl", userAccount.getInstanceUrl());
tinyDB.putInt("currentActiveAccountId", userAccount.getAccountId());
Toasty.success(context, context.getResources().getString(R.string.switchAccountSuccess, userAccount.getUserName(), url));
((Activity) context).recreate();
dialog.dismiss();
}
});
dialog.show();
}

32
app/src/main/java/org/mian/gitnex/core/MainApplication.java

@ -3,6 +3,7 @@ package org.mian.gitnex.core;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import androidx.core.content.res.ResourcesCompat;
import org.acra.ACRA;
import org.acra.BuildConfig;
import org.acra.ReportField;
@ -34,7 +35,6 @@ import org.mian.gitnex.notifications.Notifications;
public class MainApplication extends Application {
private Context appCtx;
private TinyDB tinyDB;
@Override
@ -42,7 +42,7 @@ public class MainApplication extends Application {
super.onCreate();
appCtx = getApplicationContext();
Context appCtx = getApplicationContext();
tinyDB = TinyDB.getInstance(appCtx);
setDefaults();
@ -76,6 +76,7 @@ public class MainApplication extends Application {
@Override
protected void attachBaseContext(Context context) {
super.attachBaseContext(context);
tinyDB = TinyDB.getInstance(context);
@ -97,46 +98,59 @@ public class MainApplication extends Application {
// enabling counter badges by default
if(tinyDB.getString("enableCounterBadgesInit").isEmpty()) {
tinyDB.putBoolean("enableCounterBadges", true);
tinyDB.putString("enableCounterBadgesInit", "yes");
}
// enable crash reports by default
if(tinyDB.getString("crashReportingEnabledInit").isEmpty()) {
tinyDB.putBoolean("crashReportingEnabled", true);
tinyDB.putString("crashReportingEnabledInit", "yes");
}
// default cache setter
if(tinyDB.getString("cacheSizeStr").isEmpty()) {
tinyDB.putString("cacheSizeStr", getResources().getString(R.string.cacheSizeDataSelectionSelectedText));
}
if(tinyDB.getString("cacheSizeImagesStr").isEmpty()) {
tinyDB.putString("cacheSizeImagesStr", getResources().getString(R.string.cacheSizeImagesSelectionSelectedText));
}
// enable comment drafts by default
if(tinyDB.getString("draftsCommentsDeletionEnabledInit").isEmpty()) {
tinyDB.putBoolean("draftsCommentsDeletionEnabled", true);
tinyDB.putString("draftsCommentsDeletionEnabledInit", "yes");
}
// setting default polling delay
if(tinyDB.getInt("pollingDelayMinutes", 0) <= 0) {
tinyDB.putInt("pollingDelayMinutes", Constants.defaultPollingDelay);
}
// disable biometric by default
if(tinyDB.getString("biometricStatusInit").isEmpty()) {
tinyDB.putBoolean("biometricStatus", false);
tinyDB.putString("biometricStatusInit", "yes");
}
// set default date format
if(tinyDB.getString("dateFormat").isEmpty()) {
tinyDB.putString("dateFormat", "pretty");
}
if(tinyDB.getString("codeBlockStr").isEmpty()) {
tinyDB.putInt("codeBlockColor", ResourcesCompat.getColor(getResources(), R.color.colorLightGreen, null));
tinyDB.putInt("codeBlockBackground", ResourcesCompat.getColor(getResources(), R.color.black, null));
}
if(tinyDB.getString("enableCounterIssueBadgeInit").isEmpty()) {
tinyDB.putBoolean("enableCounterIssueBadge", true);
}
if(tinyDB.getString("homeScreenStr").isEmpty()) {
tinyDB.putString("homeScreenStr", "yes");
tinyDB.putInt("homeScreenId", 0);
}
}
}

57
app/src/main/java/org/mian/gitnex/database/api/BaseApi.java

@ -0,0 +1,57 @@
package org.mian.gitnex.database.api;
import android.content.Context;
import androidx.annotation.NonNull;
import org.mian.gitnex.database.db.GitnexDatabase;
import org.mian.gitnex.helpers.Constants;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author opyale
*/
public abstract class BaseApi {
private static final Map<Class<? extends BaseApi>, Object> instances = new HashMap<>();
protected static final ExecutorService executorService = Executors.newCachedThreadPool();
protected final GitnexDatabase gitnexDatabase;
protected BaseApi(Context context) {
gitnexDatabase = GitnexDatabase.getDatabaseInstance(context);
}
public static <T extends BaseApi> T getInstance(@NonNull Context context, @NonNull Class<T> clazz) {
try {
if(!instances.containsKey(clazz)) {
synchronized(BaseApi.class) {
if(!instances.containsKey(clazz)) {
T instance = clazz
.getDeclaredConstructor(Context.class)
.newInstance(context);
instances.put(clazz, instance);
return instance;
}
}
}
return (T) instances.get(clazz);
} catch(NoSuchMethodException | IllegalAccessException |
InvocationTargetException | InstantiationException ignored) {}
return null;
}
}

82
app/src/main/java/org/mian/gitnex/database/api/DraftsApi.java

@ -1,30 +1,23 @@
package org.mian.gitnex.database.api;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.LiveData;
import org.mian.gitnex.database.dao.DraftsDao;
import org.mian.gitnex.database.db.GitnexDatabase;
import org.mian.gitnex.database.models.Draft;
import org.mian.gitnex.database.models.DraftWithRepository;
import org.mian.gitnex.helpers.Constants;
import java.util.List;
/**
* Author M M Arif
*/
public class DraftsApi {
public class DraftsApi extends BaseApi {
private static DraftsDao draftsDao;
private static long draftId;
private static Integer checkDraftFlag;
private final DraftsDao draftsDao;
public DraftsApi(Context context) {
GitnexDatabase db;
db = GitnexDatabase.getDatabaseInstance(context);
draftsDao = db.draftsDao();
DraftsApi(Context context) {
super(context);
draftsDao = gitnexDatabase.draftsDao();
}
public long insertDraft(int repositoryId, int draftAccountId, int issueId, String draftText, String draftType, String commentId, String issueType) {
@ -41,87 +34,44 @@ public class DraftsApi {
return insertDraftAsyncTask(draft);
}
private static long insertDraftAsyncTask(final Draft draft) {
try {
Thread thread = new Thread(() -> draftId = draftsDao.insertDraft(draft));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(Constants.draftsApi, e.toString());
}
return draftId;
private long insertDraftAsyncTask(final Draft draft) {
return draftsDao.insertDraft(draft);
}
public long getDraftIdAsync(int issueId, int draftRepositoryId) {
try {
Thread thread = new Thread(() -> draftId = draftsDao.getDraftId(issueId, draftRepositoryId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(Constants.draftsApi, e.toString());
}
return draftId;
return draftsDao.getDraftId(issueId, draftRepositoryId);
}
public Integer checkDraft(int issueId, int draftRepositoryId, String commentId) {
try {
Thread thread = new Thread(() -> checkDraftFlag = draftsDao.checkDraftDao(issueId, draftRepositoryId, commentId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(Constants.draftsApi, e.toString());
}
return checkDraftFlag;
return draftsDao.checkDraftDao(issueId, draftRepositoryId, commentId);
}
public LiveData<List<DraftWithRepository>> getDrafts(int accountId) {
return draftsDao.fetchAllDrafts(accountId);
}
public LiveData<Draft> getDraftByIssueId(int issueId) {
return draftsDao.fetchDraftByIssueId(issueId);
}
public void deleteSingleDraft(final int draftId) {
final LiveData<Draft> draft = draftsDao.fetchDraftById(draftId);
if(draft != null) {
new Thread(() -> draftsDao.deleteByDraftId(draftId)).start();
executorService.execute(() -> draftsDao.deleteByDraftId(draftId));
}
}
public static void deleteAllDrafts(final int accountId) {
new Thread(() -> draftsDao.deleteAllDrafts(accountId)).start();
public void deleteAllDrafts(final int accountId) {
executorService.execute(() -> draftsDao.deleteAllDrafts(accountId));
}
public static void updateDraft(final String draftText, final int draftId, final String commentId) {
new Thread(() -> draftsDao.updateDraft(draftText, draftId, commentId)).start();
public void updateDraft(final String draftText, final int draftId, final String commentId) {
executorService.execute(() -> draftsDao.updateDraft(draftText, draftId, commentId));
}
public static void updateDraftByIssueIdAsyncTask(final String draftText, final int issueId, final int draftRepositoryId, final String commentId) {
new Thread(() -> draftsDao.updateDraftByIssueId(draftText, issueId, draftRepositoryId, commentId)).start();
public void updateDraftByIssueIdAsyncTask(final String draftText, final int issueId, final int draftRepositoryId, final String commentId) {
executorService.execute(() -> draftsDao.updateDraftByIssueId(draftText, issueId, draftRepositoryId, commentId));
}
}

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

@ -1,30 +1,22 @@
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.Constants;
import java.util.List;
/**
* Author M M Arif
*/
public class RepositoriesApi {
public class RepositoriesApi extends BaseApi {
private static RepositoriesDao repositoriesDao;
private static long repositoryId;
private static Repository repository;
private static Integer checkRepository;
private final RepositoriesDao repositoriesDao;
public RepositoriesApi(Context context) {
GitnexDatabase db;
db = GitnexDatabase.getDatabaseInstance(context);
repositoriesDao = db.repositoriesDao();
RepositoriesApi(Context context) {
super(context);
repositoriesDao = gitnexDatabase.repositoriesDao();
}
public long insertRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
@ -38,108 +30,43 @@ public class RepositoriesApi {
}
public long insertRepositoryAsyncTask(Repository repository) {
try {
Thread thread = new Thread(() -> repositoryId = repositoriesDao.newRepository(repository));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(Constants.repositoriesApi, e.toString());
}
return repositoryId;
return repositoriesDao.newRepository(repository);
}
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(Constants.repositoriesApi, e.toString());
}
return repository;
return repositoriesDao.getSingleRepositoryDao(repoAccountId, repositoryOwner, repositoryName);
}
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(Constants.repositoriesApi, e.toString());
}
return checkRepository;
return repositoriesDao.checkRepositoryDao(repoAccountId, repositoryOwner, repositoryName);
}
public Repository fetchRepositoryById(int repositoryId) {
try {
Thread thread = new Thread(() -> repository = repositoriesDao.fetchRepositoryByIdDao(repositoryId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(Constants.repositoriesApi, e.toString());
}
return repository;
return repositoriesDao.fetchRepositoryByIdDao(repositoryId);
}
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(Constants.repositoriesApi, e.toString());
}
return repository;
return repositoriesDao.fetchRepositoryByAccountIdByRepositoryIdDao(repositoryId, repoAccountId);
}
public static void updateRepositoryOwnerAndName(String repositoryOwner, String repositoryName, int repositoryId) {
new Thread(() -> repositoriesDao.updateRepositoryOwnerAndName(repositoryOwner, repositoryName, repositoryId)).start();
public void updateRepositoryOwnerAndName(String repositoryOwner, String repositoryName, int repositoryId) {
executorService.execute(() -> repositoriesDao.updateRepositoryOwnerAndName(repositoryOwner, repositoryName, repositoryId));
}
public static void deleteRepositoriesByAccount(final int repoAccountId) {
new Thread(() -> repositoriesDao.deleteRepositoriesByAccount(repoAccountId)).start();
public void deleteRepositoriesByAccount(final int repoAccountId) {
executorService.execute(() -> repositoriesDao.deleteRepositoriesByAccount(repoAccountId));
}
public static void deleteRepository(final int repositoryId) {
new Thread(() -> repositoriesDao.deleteRepository(repositoryId)).start();
public void deleteRepository(final int repositoryId) {
executorService.execute(() -> repositoriesDao.deleteRepository(repositoryId));
}
}

105
app/src/main/java/org/mian/gitnex/database/api/UserAccountsApi.java

@ -1,34 +1,25 @@
package org.mian.gitnex.database.api;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.LiveData;
import org.mian.gitnex.database.dao.UserAccountsDao;
import org.mian.gitnex.database.db.GitnexDatabase;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.helpers.Constants;
import java.util.List;
/**
* Author M M Arif
*/
public class UserAccountsApi {
public class UserAccountsApi extends BaseApi {
private static UserAccountsDao userAccountsDao;
private static UserAccount userAccount;
private static List<UserAccount> userAccounts;
private static Integer checkAccount;
private static long accountId;
private final UserAccountsDao userAccountsDao;