From 9d3cd49d23719236571392c2902e66148974a523 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Tue, 13 Apr 2021 16:19:42 +0200 Subject: [PATCH 1/2] New UI for multiple screens (#894) clean up Another round of ui improvements and some refactors Minor improvements. Hide user accounts frame while list is loading Remove unnecessary attribute Minor improvements. Define avatar size in lists globally. Improvemnts to some ui elements Improve layout of organizations and repositories. Update the UI across most of the screens Refactor org UI clean up repo layout Add archived msg instead of label Redesign repos UI Move archived to repo detail screen Co-authored-by: M M Arif Co-authored-by: opyale Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/894 Reviewed-by: opyale Co-Authored-By: M M Arif Co-Committed-By: M M Arif --- .../mian/gitnex/activities/MainActivity.java | 27 +- .../adapters/AdminCronTasksAdapter.java | 15 +- .../gitnex/adapters/AdminGetUsersAdapter.java | 17 +- .../gitnex/adapters/AssigneesListAdapter.java | 10 +- .../gitnex/adapters/CollaboratorsAdapter.java | 12 +- .../mian/gitnex/adapters/CommitsAdapter.java | 28 +- .../mian/gitnex/adapters/CreditsAdapter.java | 59 ---- .../mian/gitnex/adapters/DraftsAdapter.java | 21 +- .../adapters/ExploreRepositoriesAdapter.java | 221 ++++++--------- .../mian/gitnex/adapters/FilesAdapter.java | 23 +- .../gitnex/adapters/FilesDiffAdapter.java | 8 - .../gitnex/adapters/IssueCommentsAdapter.java | 22 +- .../mian/gitnex/adapters/IssuesAdapter.java | 42 +-- .../mian/gitnex/adapters/LabelsAdapter.java | 41 +-- .../gitnex/adapters/LabelsListAdapter.java | 12 +- .../gitnex/adapters/MembersByOrgAdapter.java | 13 +- .../gitnex/adapters/MilestonesAdapter.java | 56 +--- .../gitnex/adapters/MyReposListAdapter.java | 222 ++++++--------- .../gitnex/adapters/NotificationsAdapter.java | 32 +-- .../adapters/OrganizationsListAdapter.java | 43 +-- .../gitnex/adapters/ProfileEmailsAdapter.java | 16 +- .../adapters/ProfileFollowersAdapter.java | 15 +- .../adapters/ProfileFollowingAdapter.java | 15 +- .../gitnex/adapters/PullRequestsAdapter.java | 43 +-- .../mian/gitnex/adapters/ReleasesAdapter.java | 60 ++-- .../adapters/ReleasesDownloadsAdapter.java | 7 +- .../gitnex/adapters/RepoForksAdapter.java | 209 +++++--------- .../adapters/RepoStargazersAdapter.java | 27 +- .../gitnex/adapters/RepoWatchersAdapter.java | 27 +- .../gitnex/adapters/ReposListAdapter.java | 219 ++++++--------- .../adapters/RepositoriesByOrgAdapter.java | 236 ++++++---------- .../gitnex/adapters/SearchIssuesAdapter.java | 23 +- .../mian/gitnex/adapters/SponsorsAdapter.java | 59 ---- .../adapters/StarredReposListAdapter.java | 233 ++++++---------- .../adapters/TeamMembersByOrgAdapter.java | 20 +- .../gitnex/adapters/TeamsByOrgAdapter.java | 46 ++-- .../gitnex/adapters/UserAccountsAdapter.java | 45 +-- .../UserAccountsListDialogAdapter.java | 17 +- .../adapters/UserAccountsNavAdapter.java | 41 +-- .../gitnex/adapters/UserSearchAdapter.java | 105 +++---- .../UserSearchForTeamMemberAdapter.java | 64 ++--- .../fragments/BottomSheetReplyFragment.java | 6 +- .../mian/gitnex/fragments/IssuesFragment.java | 5 - .../fragments/ProfileEmailsFragment.java | 5 +- .../fragments/ProfileFollowersFragment.java | 39 ++- .../fragments/ProfileFollowingFragment.java | 39 ++- .../gitnex/fragments/ProfileFragment.java | 4 +- .../gitnex/fragments/RepoInfoFragment.java | 11 +- .../org/mian/gitnex/helpers/Markdown.java | 2 +- .../main/res/drawable/shape_files_diffs.xml | 14 + .../main/res/layout/activity_issue_detail.xml | 14 +- .../bottom_sheet_repository_in_list.xml | 103 ------- app/src/main/res/layout/credits.xml | 21 -- .../layout/custom_user_accounts_dialog.xml | 4 +- .../res/layout/custom_user_accounts_list.xml | 84 +++--- app/src/main/res/layout/fragment_drafts.xml | 3 +- .../main/res/layout/fragment_repo_info.xml | 12 + .../main/res/layout/list_admin_cron_tasks.xml | 2 +- app/src/main/res/layout/list_admin_users.xml | 18 +- .../res/layout/list_collaborators_search.xml | 31 +-- app/src/main/res/layout/list_commits.xml | 4 +- app/src/main/res/layout/list_drafts.xml | 7 +- app/src/main/res/layout/list_files.xml | 11 +- app/src/main/res/layout/list_files_diffs.xml | 16 +- .../main/res/layout/list_issue_comments.xml | 12 +- app/src/main/res/layout/list_issues.xml | 133 ++++----- app/src/main/res/layout/list_labels.xml | 32 +-- app/src/main/res/layout/list_milestones.xml | 26 +- .../main/res/layout/list_notifications.xml | 4 +- .../main/res/layout/list_organizations.xml | 77 +++--- app/src/main/res/layout/list_pr.xml | 129 ++++----- .../main/res/layout/list_profile_emails.xml | 19 +- .../res/layout/list_profile_followers.xml | 19 +- .../res/layout/list_profile_following.xml | 19 +- app/src/main/res/layout/list_releases.xml | 70 +++-- .../res/layout/list_releases_downloads.xml | 6 +- app/src/main/res/layout/list_repositories.xml | 256 +++++++----------- app/src/main/res/layout/list_teams_by_org.xml | 27 +- .../main/res/layout/list_user_accounts.xml | 107 ++++---- app/src/main/res/layout/nav_header.xml | 50 ++-- app/src/main/res/layout/nav_user_accounts.xml | 4 +- app/src/main/res/layout/sponsors.xml | 21 -- app/src/main/res/values/dimens.xml | 2 + app/src/main/res/values/strings.xml | 2 + 84 files changed, 1532 insertions(+), 2389 deletions(-) delete mode 100644 app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java delete mode 100644 app/src/main/java/org/mian/gitnex/adapters/SponsorsAdapter.java create mode 100644 app/src/main/res/drawable/shape_files_diffs.xml delete mode 100644 app/src/main/res/layout/bottom_sheet_repository_in_list.xml delete mode 100644 app/src/main/res/layout/credits.xml delete mode 100644 app/src/main/res/layout/sponsors.xml diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index e2ddc88e..29e8565f 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java @@ -18,6 +18,7 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; 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; @@ -71,10 +72,6 @@ import retrofit2.Callback; public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, BottomSheetDraftsFragment.BottomSheetListener { private DrawerLayout drawer; - private TextView userFullName; - private TextView userEmail; - private ImageView userAvatar; - private ImageView userAvatarBackground; private TextView toolbarTitle; private Typeface myTypeface; @@ -256,6 +253,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig drawer.addDrawerListener(toggle); drawer.addDrawerListener(new DrawerLayout.DrawerListener() { + @Override public void onDrawerOpened(@NonNull View drawerView) { @@ -269,27 +267,26 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig String userFullNameNav = tinyDB.getString("userFullname"); String userAvatarNav = tinyDB.getString("userAvatar"); - userEmail = hView.findViewById(R.id.userEmail); - userFullName = hView.findViewById(R.id.userFullname); - userAvatar = hView.findViewById(R.id.userAvatar); - userAvatarBackground = hView.findViewById(R.id.userAvatarBackground); + TextView userEmail = hView.findViewById(R.id.userEmail); + TextView userFullName = hView.findViewById(R.id.userFullname); + ImageView userAvatar = hView.findViewById(R.id.userAvatar); + ImageView userAvatarBackground = hView.findViewById(R.id.userAvatarBackground); + CardView navRecyclerViewFrame = hView.findViewById(R.id.userAccountsFrame); - List userAccountsList; - userAccountsList = new ArrayList<>(); + List userAccountsList = new ArrayList<>(); UserAccountsApi userAccountsApi; userAccountsApi = new UserAccountsApi(ctx); - RecyclerView navRecyclerViewUserAccounts = hView.findViewById(R.id.navRecyclerViewUserAccounts); + RecyclerView navRecyclerViewUserAccounts = hView.findViewById(R.id.userAccounts); UserAccountsNavAdapter adapterUserAccounts; adapterUserAccounts = new UserAccountsNavAdapter(ctx, userAccountsList, drawer, toolbarTitle); userAccountsApi.getAllAccounts().observe((AppCompatActivity) ctx, userAccounts -> { - if(userAccounts.size() > 0) { - userAccountsList.addAll(userAccounts); navRecyclerViewUserAccounts.setAdapter(adapterUserAccounts); + navRecyclerViewFrame.setVisibility(View.VISIBLE); } }); @@ -308,10 +305,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig if(!userAvatarNav.equals("")) { + int avatarRadius = AppUtil.getPixelsFromDensity(ctx, 3); + PicassoService.getInstance(ctx).get() .load(userAvatarNav) .placeholder(R.drawable.loader_animated) - .transform(new RoundedTransformation(8, 0)) + .transform(new RoundedTransformation(avatarRadius, 0)) .resize(160, 160) .centerCrop().into(userAvatar); diff --git a/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java index 5bce9a2e..cb53bff4 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java @@ -31,17 +31,13 @@ import retrofit2.Callback; public class AdminCronTasksAdapter extends RecyclerView.Adapter { private final List tasksList; - private final Context mCtx; private static TinyDB tinyDb; static class CronTasksViewHolder extends RecyclerView.ViewHolder { private CronTasks cronTasks; - private final ImageView runTask; private final TextView taskName; - private final LinearLayout cronTasksInfo; - private final LinearLayout cronTasksRun; private CronTasksViewHolder(View itemView) { @@ -51,10 +47,10 @@ public class AdminCronTasksAdapter extends RecyclerView.Adapter { @@ -96,10 +92,9 @@ public class AdminCronTasksAdapter extends RecyclerView.Adapter tasksListMain) { + public AdminCronTasksAdapter(Context ctx, List tasksListMain) { - tinyDb = TinyDB.getInstance(mCtx); - this.mCtx = mCtx; + tinyDb = TinyDB.getInstance(ctx); this.tasksList = tasksListMain; } diff --git a/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java index 4f7766d8..a01a1d3d 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java @@ -28,7 +28,7 @@ import java.util.List; public class AdminGetUsersAdapter extends RecyclerView.Adapter implements Filterable { private final List usersList; - private final Context mCtx; + private final Context context; private final List usersListFull; static class UsersViewHolder extends RecyclerView.ViewHolder { @@ -60,9 +60,9 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter usersListMain) { + public AdminGetUsersAdapter(Context ctx, List usersListMain) { - this.mCtx = mCtx; + this.context = ctx; this.usersList = usersListMain; usersListFull = new ArrayList<>(usersList); } @@ -79,17 +79,18 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter { - private final Context mCtx; + private final Context context; private final List assigneesList; private List assigneesStrings = new ArrayList<>(); private List currentAssignees; @@ -36,9 +37,9 @@ public class AssigneesListAdapter extends RecyclerView.Adapter data); } - public AssigneesListAdapter(Context mCtx, List dataMain, AssigneesListAdapterListener assigneesListener, List currentAssignees) { + public AssigneesListAdapter(Context ctx, List dataMain, AssigneesListAdapterListener assigneesListener, List currentAssignees) { - this.mCtx = mCtx; + this.context = ctx; this.assigneesList = dataMain; this.assigneesListener = assigneesListener; this.currentAssignees = currentAssignees; @@ -73,6 +74,7 @@ public class AssigneesListAdapter extends RecyclerView.Adapter collaboratorsList; - private final Context mCtx; + private final Context context; private static class ViewHolder { @@ -46,9 +46,9 @@ public class CollaboratorsAdapter extends BaseAdapter { } } - public CollaboratorsAdapter(Context mCtx, List collaboratorsListMain) { + public CollaboratorsAdapter(Context ctx, List collaboratorsListMain) { - this.mCtx = mCtx; + this.context = ctx; this.collaboratorsList = collaboratorsListMain; } @@ -75,7 +75,7 @@ public class CollaboratorsAdapter extends BaseAdapter { if (finalView == null) { - finalView = LayoutInflater.from(mCtx).inflate(R.layout.list_collaborators, null); + finalView = LayoutInflater.from(context).inflate(R.layout.list_collaborators, null); viewHolder = new ViewHolder(finalView); finalView.setTag(viewHolder); } @@ -90,8 +90,10 @@ public class CollaboratorsAdapter extends BaseAdapter { private void initData(ViewHolder viewHolder, int position) { + int imgRadius = AppUtil.getPixelsFromDensity(context, 3); + Collaborators currentItem = collaboratorsList.get(position); - PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.collaboratorAvatar); + PicassoService.getInstance(context).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(180, 180).centerCrop().into(viewHolder.collaboratorAvatar); viewHolder.userLoginId = currentItem.getLogin(); diff --git a/app/src/main/java/org/mian/gitnex/adapters/CommitsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/CommitsAdapter.java index 9c67fcde..46e58de1 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/CommitsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/CommitsAdapter.java @@ -26,7 +26,7 @@ import java.util.Locale; public class CommitsAdapter extends RecyclerView.Adapter { - private final Context ctx; + private final Context context; private final int TYPE_LOAD = 0; private List commitsList; private CommitsAdapter.OnLoadMoreListener loadMoreListener; @@ -35,7 +35,7 @@ public class CommitsAdapter extends RecyclerView.Adapter commitsListMain) { - this.ctx = ctx; + this.context = ctx; this.commitsList = commitsListMain; } @@ -44,7 +44,7 @@ public class CommitsAdapter extends RecyclerView.Adapter ctx.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(commitsModel.getHtml_url())))); - + commitHtmlUrl.setOnClickListener(v -> context.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(commitsModel.getHtml_url())))); } } @@ -138,32 +131,27 @@ public class CommitsAdapter extends RecyclerView.Adapter list) { diff --git a/app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java deleted file mode 100644 index 2ec35f66..00000000 --- a/app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.mian.gitnex.adapters; - -import android.text.SpannableStringBuilder; -import android.text.method.LinkMovementMethod; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import org.mian.gitnex.R; -import java.util.List; - -/** - * Author M M Arif - */ - -public class CreditsAdapter extends RecyclerView.Adapter { - - private List creditsList; - - static class CreditsViewHolder extends RecyclerView.ViewHolder { - - private TextView creditText; - - private CreditsViewHolder(View itemView) { - super(itemView); - - creditText = itemView.findViewById(R.id.creditText); - - } - } - - public CreditsAdapter(List creditsListMain) { - this.creditsList = creditsListMain; - } - - @NonNull - @Override - public CreditsAdapter.CreditsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.credits, parent, false); - return new CreditsAdapter.CreditsViewHolder(v); - } - - @Override - public void onBindViewHolder(@NonNull CreditsAdapter.CreditsViewHolder holder, int position) { - - SpannableStringBuilder strBuilder = new SpannableStringBuilder(creditsList.get(position)); - holder.creditText.setText((strBuilder)); - holder.creditText.setMovementMethod(LinkMovementMethod.getInstance()); - - } - - @Override - public int getItemCount() { - return creditsList.size(); - } - -} diff --git a/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java index a6db98d7..f054c635 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java @@ -33,7 +33,7 @@ public class DraftsAdapter extends RecyclerView.Adapter draftsList; private final FragmentManager fragmentManager; - private final Context mCtx; + private final Context context; class DraftsViewHolder extends RecyclerView.ViewHolder { @@ -56,9 +56,8 @@ public class DraftsAdapter extends RecyclerView.Adapter { @@ -76,24 +75,23 @@ public class DraftsAdapter extends RecyclerView.Adapter mCtx.startActivity(new Intent(mCtx, IssueDetailActivity.class))); + bottomSheetReplyFragment.setOnInteractedListener(() -> context.startActivity(new Intent(context, IssueDetailActivity.class))); bottomSheetReplyFragment.show(fragmentManager, "replyBottomSheet"); - }); } } - public DraftsAdapter(Context mCtx, FragmentManager fragmentManager, List draftsListMain) { - this.mCtx = mCtx; + public DraftsAdapter(Context ctx, FragmentManager fragmentManager, List draftsListMain) { + this.context = ctx; this.fragmentManager = fragmentManager; this.draftsList = draftsListMain; } @@ -103,8 +101,7 @@ public class DraftsAdapter extends RecyclerView.Adapter" + mCtx.getResources().getString(R.string.hash) + currentItem.getIssueId() + ""; + String issueNumber = "" + context.getResources().getString(R.string.hash) + currentItem.getIssueId() + ""; Spanned headTitle = HtmlCompat .fromHtml(issueNumber + " " + currentItem.getRepositoryOwner() + " / " + currentItem.getRepositoryName(), HtmlCompat.FROM_HTML_MODE_LEGACY); holder.repoInfo.setText(headTitle); holder.draftWithRepository = currentItem; - Markdown.render(mCtx, currentItem.getDraftText(), holder.draftText); + Markdown.render(context, currentItem.getDraftText(), holder.draftText); if(!currentItem.getCommentId().equalsIgnoreCase("new")) { holder.editCommentStatus.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java index b2af0601..88699632 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java @@ -1,8 +1,5 @@ package org.mian.gitnex.adapters; -import android.annotation.SuppressLint; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; @@ -11,30 +8,30 @@ import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; -import com.google.android.material.bottomsheet.BottomSheetDialog; import org.gitnex.tea4j.models.UserRepositories; import org.gitnex.tea4j.models.WatchInfo; import org.mian.gitnex.R; -import org.mian.gitnex.activities.OpenRepoInBrowserActivity; import org.mian.gitnex.activities.RepoDetailActivity; -import org.mian.gitnex.activities.RepoForksActivity; -import org.mian.gitnex.activities.RepoStargazersActivity; -import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.clients.PicassoService; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.database.api.RepositoriesApi; import org.mian.gitnex.database.models.Repository; +import org.mian.gitnex.helpers.AppUtil; +import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.RoundedTransformation; +import org.mian.gitnex.helpers.TimeHelper; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; +import org.ocpsoft.prettytime.PrettyTime; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.List; -import java.util.Objects; +import java.util.Locale; import retrofit2.Call; import retrofit2.Callback; @@ -44,65 +41,59 @@ import retrofit2.Callback; public class ExploreRepositoriesAdapter extends RecyclerView.Adapter { - private List searchedReposList; - private Context mCtx; + private final List reposList; + private final Context context; - public ExploreRepositoriesAdapter(List dataList, Context mCtx) { + public ExploreRepositoriesAdapter(List dataList, Context ctx) { - this.mCtx = mCtx; - this.searchedReposList = dataList; + this.context = ctx; + this.reposList = dataList; } static class ReposSearchViewHolder extends RecyclerView.ViewHolder { - private ImageView image; - private TextView repoName; - private TextView repoDescription; - private TextView fullName; + private UserRepositories userRepositories; + + private final ImageView image; + private final TextView repoName; + private final TextView orgName; + private final TextView repoDescription; private CheckBox isRepoAdmin; - private ImageView repoPrivatePublic; - private TextView repoStars; - private TextView repoForks; - private TextView repoOpenIssuesCount; - private TextView repoType; - private LinearLayout archiveRepo; - private TextView repoBranch; - private TextView htmlUrl; + private final TextView repoStars; + private final TextView repoLastUpdated; private ReposSearchViewHolder(View itemView) { super(itemView); - repoName = itemView.findViewById(R.id.repoName); + orgName = itemView.findViewById(R.id.orgName); repoDescription = itemView.findViewById(R.id.repoDescription); - image = itemView.findViewById(R.id.imageAvatar); - fullName = itemView.findViewById(R.id.repoFullName); isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin); - repoPrivatePublic = itemView.findViewById(R.id.imageRepoType); + image = itemView.findViewById(R.id.imageAvatar); repoStars = itemView.findViewById(R.id.repoStars); - repoForks = itemView.findViewById(R.id.repoForks); - repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount); - ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu); - repoType = itemView.findViewById(R.id.repoType); - archiveRepo = itemView.findViewById(R.id.archiveRepoFrame); - repoBranch = itemView.findViewById(R.id.repoBranch); - htmlUrl = itemView.findViewById(R.id.htmlUrl); + repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated); itemView.setOnClickListener(v -> { Context context = v.getContext(); - TextView repoFullName = v.findViewById(R.id.repoFullName); + TinyDB tinyDb = TinyDB.getInstance(context); Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", repoFullName.getText().toString()); + intent.putExtra("repoFullName", userRepositories.getFullName()); - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("repoFullName", repoFullName.getText().toString()); + tinyDb.putString("repoFullName", userRepositories.getFullName()); tinyDb.putBoolean("resumeIssues", true); tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked()); - tinyDb.putString("repoBranch", repoBranch.getText().toString()); + tinyDb.putString("repoBranch", userRepositories.getDefault_branch()); - String[] parts = fullName.getText().toString().split("/"); + if(userRepositories.getPrivateFlag()) { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPrivate)); + } + else { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPublic)); + } + + String[] parts = userRepositories.getFullName().split("/"); final String repoOwner = parts[0]; final String repoName = parts[1]; @@ -116,13 +107,11 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter { - - final Context context = v.getContext(); - - @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - - TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); - TextView repoStargazers = view.findViewById(R.id.repoStargazers); - TextView repoWatchers = view.findViewById(R.id.repoWatchers); - TextView repoForksList = view.findViewById(R.id.repoForksList); - TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl); - TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader); - - bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1])); - BottomSheetDialog dialog = new BottomSheetDialog(context); - dialog.setContentView(view); - dialog.show(); - - repoCopyUrl.setOnClickListener(openInBrowser -> { - - ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString()); - assert clipboard != null; - clipboard.setPrimaryClip(clip); - - Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg)); - dialog.dismiss(); - }); - - repoOpenInBrowser.setOnClickListener(openInBrowser -> { - - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - dialog.dismiss(); - - }); - - repoStargazers.setOnClickListener(stargazers -> { - - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - dialog.dismiss(); - - }); - - repoWatchers.setOnClickListener(watchers -> { - - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - repoForksList.setOnClickListener(forks -> { - - Intent intentW = new Intent(context, RepoForksActivity.class); - intentW.putExtra("repoFullNameForForks", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - }); - } } @@ -257,10 +177,16 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter originalFiles = new ArrayList<>(); private final List alteredFiles = new ArrayList<>(); - private final Context mCtx; + private final Context context; private final FilesAdapterListener filesListener; @@ -40,8 +40,7 @@ public class FilesAdapter extends RecyclerView.Adapter getOriginalFiles() { @@ -141,7 +139,6 @@ public class FilesAdapter extends RecyclerView.Adapter { if(((DiffTextView) v).getCurrentBackgroundColor() != COLOR_SELECTED) { @@ -197,7 +194,6 @@ public class FilesDiffAdapter extends BaseAdapter { stringBuilder.append(((DiffTextView) view).getText()); stringBuilder.append("\n"); - } stringBuilder.append("```\n\n"); @@ -209,7 +205,6 @@ public class FilesDiffAdapter extends BaseAdapter { bundle.putBoolean("cursorToEnd", true); BottomSheetReplyFragment.newInstance(bundle).show(fragmentManager, "replyBottomSheet"); - } return true; @@ -226,7 +221,6 @@ public class FilesDiffAdapter extends BaseAdapter { else { diffLines.addView(getMessageView(context.getResources().getString(R.string.fileTooLarge))); - } } @@ -248,13 +242,11 @@ public class FilesDiffAdapter extends BaseAdapter { textView.setText(message); return textView; - } private String[] getLines(String content) { return content.split("\\R"); - } } diff --git a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java index c52111c5..cded93f4 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java @@ -44,7 +44,7 @@ import retrofit2.Callback; public class IssueCommentsAdapter extends RecyclerView.Adapter { - private final Context ctx; + private final Context context; private final TinyDB tinyDB; private final Bundle bundle; private final List issuesComments; @@ -53,14 +53,13 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter issuesCommentsMain, FragmentManager fragmentManager, BottomSheetReplyFragment.OnInteractedListener onInteractedListener) { - this.ctx = ctx; + this.context = ctx; this.bundle = bundle; this.issuesComments = issuesCommentsMain; this.fragmentManager = fragmentManager; this.onInteractedListener = onInteractedListener; tinyDB = TinyDB.getInstance(ctx); - } class IssueCommentViewHolder extends RecyclerView.ViewHolder { @@ -318,39 +317,40 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter TimeHelper.customDateFormatForToastDateFormat(issueComment.getCreated_at())); } else if(timeFormat.equals("normal")) { - informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), Locale.getDefault(), "normal", ctx)); + informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), Locale.getDefault(), "normal", context)); } if(!issueComment.getCreated_at().equals(issueComment.getUpdated_at())) { if(informationBuilder != null) { - informationBuilder.append(ctx.getString(R.string.colorfulBulletSpan)).append(ctx.getString(R.string.modifiedText)); + informationBuilder.append(context.getString(R.string.colorfulBulletSpan)).append(context.getString(R.string.modifiedText)); } } } @@ -361,7 +361,7 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { diff --git a/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java index bb606f65..4a53a42c 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java @@ -7,7 +7,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.core.content.res.ResourcesCompat; @@ -41,11 +40,10 @@ public class IssuesAdapter extends RecyclerView.Adapter private OnLoadMoreListener loadMoreListener; private boolean isLoading = false, isMoreDataAvailable = true; - public IssuesAdapter(Context context, List issuesListMain) { + public IssuesAdapter(Context ctx, List issuesListMain) { - this.context = context; + this.context = ctx; this.issuesList = issuesListMain; - } @NonNull @@ -60,7 +58,6 @@ public class IssuesAdapter extends RecyclerView.Adapter else { return new LoadHolder(inflater.inflate(R.layout.row_load, parent, false)); } - } @Override @@ -70,15 +67,12 @@ public class IssuesAdapter extends RecyclerView.Adapter isLoading = true; loadMoreListener.onLoadMore(); - } if(getItemViewType(position) == TYPE_LOAD) { ((IssuesHolder) holder).bindData(issuesList.get(position)); - } - } @Override @@ -90,14 +84,12 @@ public class IssuesAdapter extends RecyclerView.Adapter else { return 1; } - } @Override public int getItemCount() { return issuesList.size(); - } class IssuesHolder extends RecyclerView.ViewHolder { @@ -112,16 +104,14 @@ public class IssuesAdapter extends RecyclerView.Adapter IssuesHolder(View itemView) { super(itemView); - issueAssigneeAvatar = itemView.findViewById(R.id.assigneeAvatar); issueTitle = itemView.findViewById(R.id.issueTitle); issueCommentsCount = itemView.findViewById(R.id.issueCommentsCount); - LinearLayout frameCommentsCount = itemView.findViewById(R.id.frameCommentsCount); issueCreatedTime = itemView.findViewById(R.id.issueCreatedTime); - issueTitle.setOnClickListener(title -> { + itemView.setOnClickListener(layoutView -> { - Context context = title.getContext(); + Context context = layoutView.getContext(); Intent intent = new Intent(context, IssueDetailActivity.class); intent.putExtra("issueNumber", issue.getNumber()); @@ -130,21 +120,6 @@ public class IssuesAdapter extends RecyclerView.Adapter tinyDb.putString("issueNumber", String.valueOf(issue.getNumber())); tinyDb.putString("issueType", "Issue"); context.startActivity(intent); - - }); - - frameCommentsCount.setOnClickListener(commentsCount -> { - - Context context = commentsCount.getContext(); - - Intent intent = new Intent(context, IssueDetailActivity.class); - intent.putExtra("issueNumber", issue.getNumber()); - - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("issueNumber", String.valueOf(issue.getNumber())); - tinyDb.putString("issueType", "Issue"); - context.startActivity(intent); - }); issueAssigneeAvatar.setOnClickListener(v -> { @@ -163,10 +138,12 @@ public class IssuesAdapter extends RecyclerView.Adapter String locale = tinyDb.getString("locale"); String timeFormat = tinyDb.getString("dateFormat"); + int imgRadius = AppUtil.getPixelsFromDensity(context, 3); + PicassoService.getInstance(context).get() .load(issue.getUser().getAvatar_url()) .placeholder(R.drawable.loader_animated) - .transform(new RoundedTransformation(8, 0)) + .transform(new RoundedTransformation(imgRadius, 0)) .resize(120, 120) .centerCrop() .into(issueAssigneeAvatar); @@ -209,32 +186,27 @@ public class IssuesAdapter extends RecyclerView.Adapter super(itemView); } - } public void setMoreDataAvailable(boolean moreDataAvailable) { isMoreDataAvailable = moreDataAvailable; - } public void notifyDataChanged() { notifyDataSetChanged(); isLoading = false; - } public interface OnLoadMoreListener { void onLoadMore(); - } public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) { this.loadMoreListener = loadMoreListener; - } public void updateList(List list) { diff --git a/app/src/main/java/org/mian/gitnex/adapters/LabelsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/LabelsAdapter.java index 2b546330..d584eaf3 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/LabelsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/LabelsAdapter.java @@ -20,7 +20,6 @@ import org.mian.gitnex.R; import org.mian.gitnex.activities.CreateLabelActivity; import org.mian.gitnex.helpers.AlertDialogs; import org.mian.gitnex.helpers.ColorInverter; -import java.util.ArrayList; import java.util.List; /** @@ -29,21 +28,17 @@ import java.util.List; public class LabelsAdapter extends RecyclerView.Adapter { - private List labelsList; - final private Context mCtx; - private ArrayList labelsArray = new ArrayList<>(); + private final List labelsList; private static String type; private static String orgName; static class LabelsViewHolder extends RecyclerView.ViewHolder { - private TextView labelTitle; - private TextView labelId; - private TextView labelColor; + private Labels labels; - private CardView labelView; - private ImageView labelIcon; - private TextView labelName; + private final CardView labelView; + private final ImageView labelIcon; + private final TextView labelName; private LabelsViewHolder(View itemView) { super(itemView); @@ -52,9 +47,6 @@ public class LabelsAdapter extends RecyclerView.Adapter { @@ -67,7 +59,7 @@ public class LabelsAdapter extends RecyclerView.Adapter { Intent intent = new Intent(context, CreateLabelActivity.class); - intent.putExtra("labelId", labelId.getText()); - intent.putExtra("labelTitle", labelTitle.getText()); - intent.putExtra("labelColor", labelColor.getText()); + intent.putExtra("labelId", String.valueOf(labels.getId())); + intent.putExtra("labelTitle", labels.getName()); + intent.putExtra("labelColor", labels.getColor()); intent.putExtra("labelAction", "edit"); intent.putExtra("type", type); intent.putExtra("orgName", orgName); context.startActivity(intent); dialog.dismiss(); - }); labelMenuDelete.setOnClickListener(deleteLabel -> { - AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(), + AlertDialogs.labelDeleteDialog(context, labels.getName(), String.valueOf(labels.getId()), context.getResources().getString(R.string.labelDeleteTitle), context.getResources().getString(R.string.labelDeleteMessage), context.getResources().getString(R.string.labelDeleteTitle), context.getResources().getString(R.string.labelDeleteNegativeButton), type, orgName); dialog.dismiss(); - }); }); @@ -103,10 +93,9 @@ public class LabelsAdapter extends RecyclerView.Adapter labelsMain, String type, String orgName) { + public LabelsAdapter(Context ctx, List labelsMain, String type, String orgName) { - this.mCtx = mCtx; - this.labelsList = labelsMain; + this.labelsList = labelsMain; LabelsAdapter.type = type; LabelsAdapter.orgName = orgName; } @@ -122,10 +111,7 @@ public class LabelsAdapter extends RecyclerView.Adapter { private List currentLabelsIds; - private List labels; - private List labelsStrings = new ArrayList<>(); + private final List labels; + private final List labelsStrings = new ArrayList<>(); private List labelsIds = new ArrayList<>(); - private LabelsListAdapterListener labelsListener; + private final LabelsListAdapterListener labelsListener; public interface LabelsListAdapterListener { @@ -43,9 +43,9 @@ public class LabelsListAdapter extends RecyclerView.Adapter membersList; - private final Context mCtx; + private final Context context; private final List membersListFull; private static class ViewHolder { @@ -50,9 +50,9 @@ public class MembersByOrgAdapter extends BaseAdapter implements Filterable { } } - public MembersByOrgAdapter(Context mCtx, List membersListMain) { + public MembersByOrgAdapter(Context ctx, List membersListMain) { - this.mCtx = mCtx; + this.context = ctx; this.membersList = membersListMain; membersListFull = new ArrayList<>(membersList); } @@ -80,7 +80,7 @@ public class MembersByOrgAdapter extends BaseAdapter implements Filterable { if (finalView == null) { - finalView = LayoutInflater.from(mCtx).inflate(R.layout.list_members_by_org, null); + finalView = LayoutInflater.from(context).inflate(R.layout.list_members_by_org, null); viewHolder = new ViewHolder(finalView); finalView.setTag(viewHolder); } @@ -96,7 +96,9 @@ public class MembersByOrgAdapter extends BaseAdapter implements Filterable { private void initData(MembersByOrgAdapter.ViewHolder viewHolder, int position) { UserInfo currentItem = membersList.get(position); - PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(viewHolder.memberAvatar); + int imgRadius = AppUtil.getPixelsFromDensity(context, 3); + + PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(viewHolder.memberAvatar); viewHolder.userLoginId = currentItem.getLogin(); @@ -108,7 +110,6 @@ public class MembersByOrgAdapter extends BaseAdapter implements Filterable { viewHolder.memberName.setText(currentItem.getLogin()); } - } @Override diff --git a/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java index 1439c862..f805e570 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java @@ -35,19 +35,17 @@ import java.util.Locale; public class MilestonesAdapter extends RecyclerView.Adapter { - private Context context; + private final Context context; private final int TYPE_LOAD = 0; private List dataList; private OnLoadMoreListener loadMoreListener; private boolean isLoading = false; private boolean isMoreDataAvailable = true; - private String TAG = Constants.tagMilestonesAdapter; - public MilestonesAdapter(Context context, List dataListMain) { + public MilestonesAdapter(Context ctx, List dataListMain) { - this.context = context; + this.context = ctx; this.dataList = dataListMain; - } @NonNull @@ -62,7 +60,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter { Context ctx = v.getContext(); - int milestoneId_ = Integer.parseInt(milestoneId.getText().toString()); + int milestoneId_ = Integer.parseInt(String.valueOf(milestones.getId())); @SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_milestones_in_list, null); @@ -122,17 +114,15 @@ public class MilestonesAdapter extends RecyclerView.Adapter { @@ -140,7 +130,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter { @@ -148,7 +137,6 @@ public class MilestonesAdapter extends RecyclerView.Adapter list) { diff --git a/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java index 64e284f8..a0fe9ab2 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java @@ -1,8 +1,5 @@ package org.mian.gitnex.adapters; -import android.annotation.SuppressLint; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; @@ -13,31 +10,31 @@ import android.widget.CheckBox; import android.widget.Filter; import android.widget.Filterable; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; -import com.google.android.material.bottomsheet.BottomSheetDialog; import org.gitnex.tea4j.models.UserRepositories; import org.gitnex.tea4j.models.WatchInfo; import org.mian.gitnex.R; -import org.mian.gitnex.activities.OpenRepoInBrowserActivity; import org.mian.gitnex.activities.RepoDetailActivity; -import org.mian.gitnex.activities.RepoForksActivity; -import org.mian.gitnex.activities.RepoStargazersActivity; -import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.clients.PicassoService; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.database.api.RepositoriesApi; import org.mian.gitnex.database.models.Repository; +import org.mian.gitnex.helpers.AppUtil; +import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.RoundedTransformation; +import org.mian.gitnex.helpers.TimeHelper; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; +import org.ocpsoft.prettytime.PrettyTime; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; -import java.util.Objects; +import java.util.Locale; import retrofit2.Call; import retrofit2.Callback; @@ -47,59 +44,54 @@ import retrofit2.Callback; public class MyReposListAdapter extends RecyclerView.Adapter implements Filterable { - private List reposList; - private Context mCtx; - private List reposListFull; + private final List reposList; + private final Context context; + private final List reposListFull; static class MyReposViewHolder extends RecyclerView.ViewHolder { - private ImageView imageAvatar; - private TextView repoName; - private TextView repoDescription; - private TextView repoFullName; - private ImageView repoPrivatePublic; - private TextView repoStars; - private TextView repoForks; - private TextView repoOpenIssuesCount; - private TextView repoType; + private UserRepositories userRepositories; + + private final ImageView image; + private final TextView repoName; + private final TextView orgName; + private final TextView repoDescription; private CheckBox isRepoAdmin; - private LinearLayout archiveRepo; - private TextView repoBranch; - private TextView htmlUrl; + private final TextView repoStars; + private final TextView repoLastUpdated; private MyReposViewHolder(View itemView) { super(itemView); repoName = itemView.findViewById(R.id.repoName); + orgName = itemView.findViewById(R.id.orgName); repoDescription = itemView.findViewById(R.id.repoDescription); - imageAvatar = itemView.findViewById(R.id.imageAvatar); - repoFullName = itemView.findViewById(R.id.repoFullName); - repoPrivatePublic = itemView.findViewById(R.id.imageRepoType); - repoStars = itemView.findViewById(R.id.repoStars); - repoForks = itemView.findViewById(R.id.repoForks); - repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount); - ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu); - repoType = itemView.findViewById(R.id.repoType); isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin); - archiveRepo = itemView.findViewById(R.id.archiveRepoFrame); - repoBranch = itemView.findViewById(R.id.repoBranch); - htmlUrl = itemView.findViewById(R.id.htmlUrl); + image = itemView.findViewById(R.id.imageAvatar); + repoStars = itemView.findViewById(R.id.repoStars); + repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated); itemView.setOnClickListener(v -> { Context context = v.getContext(); + TinyDB tinyDb = TinyDB.getInstance(context); Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", repoFullName.getText().toString()); + intent.putExtra("repoFullName", userRepositories.getFullName()); - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("repoFullName", repoFullName.getText().toString()); - tinyDb.putString("repoType", repoType.getText().toString()); + tinyDb.putString("repoFullName", userRepositories.getFullName()); //tinyDb.putBoolean("resumeIssues", true); tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked()); - tinyDb.putString("repoBranch", repoBranch.getText().toString()); + tinyDb.putString("repoBranch", userRepositories.getDefault_branch()); - String[] parts = repoFullName.getText().toString().split("/"); + if(userRepositories.getPrivateFlag()) { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPrivate)); + } + else { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPublic)); + } + + String[] parts = userRepositories.getFullName().split("/"); final String repoOwner = parts[0]; final String repoName = parts[1]; @@ -113,13 +105,11 @@ public class MyReposListAdapter extends RecyclerView.Adapter { - - final Context context = v.getContext(); - - @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - - TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); - TextView repoStargazers = view.findViewById(R.id.repoStargazers); - TextView repoWatchers = view.findViewById(R.id.repoWatchers); - TextView repoForksList = view.findViewById(R.id.repoForksList); - TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl); - TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader); - - bottomSheetHeader.setText(String.format("%s / %s", repoFullName.getText().toString().split("/")[0], repoFullName.getText().toString().split("/")[1])); - BottomSheetDialog dialog = new BottomSheetDialog(context); - dialog.setContentView(view); - dialog.show(); - - repoCopyUrl.setOnClickListener(openInBrowser -> { - - ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString()); - assert clipboard != null; - clipboard.setPrimaryClip(clip); - - Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg)); - dialog.dismiss(); - }); - - repoOpenInBrowser.setOnClickListener(openInBrowser -> { - - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", repoFullName.getText()); - context.startActivity(intentOpenInBrowser); - dialog.dismiss(); - - }); - - repoStargazers.setOnClickListener(stargazers -> { - - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", repoFullName.getText()); - context.startActivity(intent); - dialog.dismiss(); - - }); - - repoWatchers.setOnClickListener(watchers -> { - - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", repoFullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - repoForksList.setOnClickListener(forks -> { - - Intent intentW = new Intent(context, RepoForksActivity.class); - intentW.putExtra("repoFullNameForForks", repoFullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - }); - } } - public MyReposListAdapter(Context mCtx, List reposListMain) { + public MyReposListAdapter(Context ctx, List reposListMain) { - this.mCtx = mCtx; + this.context = ctx; this.reposList = reposListMain; reposListFull = new ArrayList<>(reposList); } @@ -262,10 +184,16 @@ public class MyReposListAdapter extends RecyclerView.Adapter { - private Context context; - private List notificationThreads; - private OnMoreClickedListener onMoreClickedListener; - private OnNotificationClickedListener onNotificationClickedListener; - private TinyDB tinyDb; + private final Context context; + private final List notificationThreads; + private final OnMoreClickedListener onMoreClickedListener; + private final OnNotificationClickedListener onNotificationClickedListener; + private final TinyDB tinyDb; public NotificationsAdapter(Context context, List notificationThreads, OnMoreClickedListener onMoreClickedListener, OnNotificationClickedListener onNotificationClickedListener) { @@ -37,19 +37,18 @@ public class NotificationsAdapter extends RecyclerView.Adapter onMoreClickedListener.onMoreClicked(notificationThread)); - } @Override diff --git a/app/src/main/java/org/mian/gitnex/adapters/OrganizationsListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/OrganizationsListAdapter.java index 73f79096..38bcc2d7 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/OrganizationsListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/OrganizationsListAdapter.java @@ -16,6 +16,7 @@ import org.gitnex.tea4j.models.UserOrganizations; import org.mian.gitnex.R; import org.mian.gitnex.activities.OrganizationDetailActivity; import org.mian.gitnex.clients.PicassoService; +import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.helpers.TinyDB; import java.util.ArrayList; @@ -27,42 +28,42 @@ import java.util.List; public class OrganizationsListAdapter extends RecyclerView.Adapter implements Filterable { - private List orgList; - private Context mCtx; - private List orgListFull; + private final List orgList; + private final Context context; + private final List orgListFull; static class OrganizationsViewHolder extends RecyclerView.ViewHolder { - private ImageView image; - private TextView mTextView1; - private TextView mTextView2; - private TextView organizationId; + private UserOrganizations userOrganizations; + + private final ImageView image; + private final TextView orgName; + private final TextView orgDescription; private OrganizationsViewHolder(View itemView) { super(itemView); - mTextView1 = itemView.findViewById(R.id.orgUsername); - mTextView2 = itemView.findViewById(R.id.orgDescription); + orgName = itemView.findViewById(R.id.orgName); + orgDescription = itemView.findViewById(R.id.orgDescription); image = itemView.findViewById(R.id.imageAvatar); - organizationId = itemView.findViewById(R.id.organizationId); itemView.setOnClickListener(v -> { Context context = v.getContext(); Intent intent = new Intent(context, OrganizationDetailActivity.class); - intent.putExtra("orgName", mTextView1.getText().toString()); + intent.putExtra("orgName", userOrganizations.getUsername()); TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("orgName", mTextView1.getText().toString()); - tinyDb.putString("organizationId", organizationId.getText().toString()); + tinyDb.putString("orgName", userOrganizations.getUsername()); + tinyDb.putString("organizationId", String.valueOf(userOrganizations.getId())); tinyDb.putBoolean("organizationAction", true); context.startActivity(intent); }); } } - public OrganizationsListAdapter(Context mCtx, List orgsListMain) { + public OrganizationsListAdapter(Context ctx, List orgsListMain) { - this.mCtx = mCtx; + this.context = ctx; this.orgList = orgsListMain; orgListFull = new ArrayList<>(orgList); } @@ -80,16 +81,16 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter { - private List emailsList; - private Context mCtx; + private final List emailsList; + private final Context context; static class EmailsViewHolder extends RecyclerView.ViewHolder { - private ImageView emailPrimary; - private TextView userEmail; + private final ImageView emailPrimary; + private final TextView userEmail; private EmailsViewHolder(View itemView) { super(itemView); @@ -37,8 +37,8 @@ public class ProfileEmailsAdapter extends RecyclerView.Adapter emailsListMain) { - this.mCtx = mCtx; + public ProfileEmailsAdapter(Context ctx, List emailsListMain) { + this.context = ctx; this.emailsList = emailsListMain; } @@ -59,12 +59,12 @@ public class ProfileEmailsAdapter extends RecyclerView.Adapter { private final List followersList; - private final Context mCtx; + private final Context context; static class FollowersViewHolder extends RecyclerView.ViewHolder { @@ -50,9 +50,9 @@ public class ProfileFollowersAdapter extends RecyclerView.Adapter followersListMain) { + public ProfileFollowersAdapter(Context ctx, List followersListMain) { - this.mCtx = mCtx; + this.context = ctx; this.followersList = followersListMain; } @@ -68,21 +68,20 @@ public class ProfileFollowersAdapter extends RecyclerView.Adapter { private final List followingList; - private final Context mCtx; + private final Context context; static class FollowingViewHolder extends RecyclerView.ViewHolder { @@ -50,9 +50,9 @@ public class ProfileFollowingAdapter extends RecyclerView.Adapter followingListMain) { + public ProfileFollowingAdapter(Context ctx, List followingListMain) { - this.mCtx = mCtx; + this.context = ctx; this.followingList = followingListMain; } @@ -68,21 +68,20 @@ public class ProfileFollowingAdapter extends RecyclerView.Adapter { - - Context context = v.getContext(); - - Intent intent = new Intent(context, IssueDetailActivity.class); - intent.putExtra("issueNumber", pullRequest.getNumber()); - intent.putExtra("prMergeable", pullRequest.isMergeable()); - intent.putExtra("prHeadBranch", pullRequest.getHead().getRef()); - - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("issueNumber", String.valueOf(pullRequest.getNumber())); - tinyDb.putString("prMergeable", String.valueOf(pullRequest.isMergeable())); - tinyDb.putString("prHeadBranch", pullRequest.getHead().getRef()); - - if(pullRequest.getHead() != null && pullRequest.getHead().getRepo() != null) { - tinyDb.putString("prIsFork", String.valueOf(pullRequest.getHead().getRepo().isFork())); - tinyDb.putString("prForkFullName", pullRequest.getHead().getRepo().getFull_name()); - } - else { - // pull was done from a deleted fork - tinyDb.putString("prIsFork", "true"); - tinyDb.putString("prForkFullName", context.getString(R.string.prDeletedFork)); - } - - tinyDb.putString("issueType", "Pull"); - context.startActivity(intent); - - }); - - frameCommentsCount.setOnClickListener(v -> { + itemView.setOnClickListener(v -> { Context context = v.getContext(); @@ -184,11 +149,12 @@ public class PullRequestsAdapter extends RecyclerView.Adapter list) { diff --git a/app/src/main/java/org/mian/gitnex/adapters/ReleasesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ReleasesAdapter.java index 58287007..03ea3a70 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ReleasesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ReleasesAdapter.java @@ -7,7 +7,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.core.text.HtmlCompat; @@ -16,6 +15,7 @@ import androidx.recyclerview.widget.RecyclerView; import org.gitnex.tea4j.models.Releases; import org.mian.gitnex.R; import org.mian.gitnex.clients.PicassoService; +import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.Markdown; import org.mian.gitnex.helpers.RoundedTransformation; @@ -30,25 +30,24 @@ import java.util.Locale; public class ReleasesAdapter extends RecyclerView.Adapter { - private List releasesList; - private Context mCtx; + private final List releasesList; + private final Context context; static class ReleasesViewHolder extends RecyclerView.ViewHolder { - private TextView releaseType; - private TextView releaseName; - private ImageView authorAvatar; - private TextView authorName; - private TextView releaseTag; - private TextView releaseCommitSha; - private TextView releaseDate; - private TextView releaseBodyContent; - private LinearLayout downloadFrame; - private RelativeLayout downloads; - private TextView releaseZipDownload; - private TextView releaseTarDownload; - private ImageView downloadDropdownIcon; - private RecyclerView downloadList; + private final TextView releaseType; + private final TextView releaseName; + private final ImageView authorAvatar; + private final TextView authorName; + private final TextView releaseTag; + private final TextView releaseDate; + private final TextView releaseBodyContent; + private final LinearLayout downloadFrame; + private final LinearLayout downloads; + private final TextView releaseZipDownload; + private final TextView releaseTarDownload; + private final ImageView downloadDropdownIcon; + private final RecyclerView downloadList; private ReleasesViewHolder(View itemView) { @@ -59,7 +58,7 @@ public class ReleasesAdapter extends RecyclerView.Adapter releasesMain) { - this.mCtx = mCtx; + public ReleasesAdapter(Context ctx, List releasesMain) { + this.context = ctx; this.releasesList = releasesMain; } @@ -90,9 +88,10 @@ public class ReleasesAdapter extends RecyclerView.Adapter" + mCtx.getResources().getString(R.string.zipArchiveDownloadReleasesTab) + " ", HtmlCompat.FROM_HTML_MODE_LEGACY)); + HtmlCompat.fromHtml("" + context.getResources().getString(R.string.zipArchiveDownloadReleasesTab) + " ", HtmlCompat.FROM_HTML_MODE_LEGACY)); holder.releaseZipDownload.setMovementMethod(LinkMovementMethod.getInstance()); holder.releaseTarDownload.setText( - HtmlCompat.fromHtml("" + mCtx.getResources().getString(R.string.tarArchiveDownloadReleasesTab) + " ", HtmlCompat.FROM_HTML_MODE_LEGACY)); + HtmlCompat.fromHtml("" + context.getResources().getString(R.string.tarArchiveDownloadReleasesTab) + " ", HtmlCompat.FROM_HTML_MODE_LEGACY)); holder.releaseTarDownload.setMovementMethod(LinkMovementMethod.getInstance()); ReleasesDownloadsAdapter adapter = new ReleasesDownloadsAdapter(currentItem.getAssets()); holder.downloadList.setAdapter(adapter); - } @Override diff --git a/app/src/main/java/org/mian/gitnex/adapters/ReleasesDownloadsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ReleasesDownloadsAdapter.java index da4cd67b..77a6e2e7 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ReleasesDownloadsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ReleasesDownloadsAdapter.java @@ -18,18 +18,16 @@ import java.util.List; public class ReleasesDownloadsAdapter extends RecyclerView.Adapter { - private List releasesDownloadsList; + private final List releasesDownloadsList; static class ReleasesDownloadsViewHolder extends RecyclerView.ViewHolder { - private TextView downloadName; + private final TextView downloadName; private ReleasesDownloadsViewHolder(View itemView) { super(itemView); - downloadName = itemView.findViewById(R.id.downloadName); - } } @@ -57,7 +55,6 @@ public class ReleasesDownloadsAdapter extends RecyclerView.Adapter { - private Context ctx; + private final Context context; private final int TYPE_LOAD = 0; private List forksList; private OnLoadMoreListener loadMoreListener; @@ -50,16 +51,15 @@ public class RepoForksAdapter extends RecyclerView.Adapter forksListMain) { - this.ctx = ctx; + this.context = ctx; this.forksList = forksListMain; - } @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - LayoutInflater inflater = LayoutInflater.from(ctx); + LayoutInflater inflater = LayoutInflater.from(context); if(viewType == TYPE_LOAD) { return new RepoForksAdapter.ForksHolder(inflater.inflate(R.layout.list_repositories, parent, false)); @@ -67,7 +67,6 @@ public class RepoForksAdapter extends RecyclerView.Adapter { Context context = v.getContext(); - TextView repoFullName = v.findViewById(R.id.repoFullName); - TextView repoType_ = v.findViewById(R.id.repoType); Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", repoFullName.getText().toString()); + intent.putExtra("repoFullName", userRepositories.getFullName()); - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("repoFullName", repoFullName.getText().toString()); - tinyDb.putString("repoType", repoType_.getText().toString()); + tinyDb.putString("repoFullName", userRepositories.getFullName()); //tinyDb.putBoolean("resumeIssues", true); tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked()); - tinyDb.putString("repoBranch", repoBranch.getText().toString()); + tinyDb.putString("repoBranch", userRepositories.getDefault_branch()); - String[] parts = repoFullName.getText().toString().split("/"); + if(userRepositories.getPrivateFlag()) { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPrivate)); + } + else { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPublic)); + } + + String[] parts = userRepositories.getFullName().split("/"); final String repoOwner = parts[0]; final String repoName = parts[1]; @@ -232,13 +229,11 @@ public class RepoForksAdapter extends RecyclerView.Adapter { - - final Context context = v.getContext(); - - @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - - TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); - TextView repoStargazers = view.findViewById(R.id.repoStargazers); - TextView repoWatchers = view.findViewById(R.id.repoWatchers); - TextView repoForksList = view.findViewById(R.id.repoForksList); - TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader); - - bottomSheetHeader - .setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1])); - BottomSheetDialog dialog = new BottomSheetDialog(context); - dialog.setContentView(view); - dialog.show(); - - repoOpenInBrowser.setOnClickListener(openInBrowser -> { - - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - dialog.dismiss(); - - }); - - repoStargazers.setOnClickListener(stargazers -> { - - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - dialog.dismiss(); - - }); - - repoWatchers.setOnClickListener(watchers -> { - - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - repoForksList.setOnClickListener(watchers -> { - - Intent intentW = new Intent(context, RepoForksActivity.class); - intentW.putExtra("repoFullNameForForks", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - }); - } } @@ -358,32 +296,27 @@ public class RepoForksAdapter extends RecyclerView.Adapter list) { diff --git a/app/src/main/java/org/mian/gitnex/adapters/RepoStargazersAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/RepoStargazersAdapter.java index 02e63c8b..1b3b6973 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/RepoStargazersAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/RepoStargazersAdapter.java @@ -12,6 +12,7 @@ import android.widget.TextView; import org.gitnex.tea4j.models.UserInfo; import org.mian.gitnex.R; import org.mian.gitnex.clients.PicassoService; +import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.helpers.TinyDB; import java.util.List; @@ -22,13 +23,13 @@ import java.util.List; public class RepoStargazersAdapter extends BaseAdapter { - private List stargazersList; - private Context mCtx; + private final List stargazersList; + private final Context context; private static class ViewHolder { - private ImageView memberAvatar; - private TextView memberName; + private final ImageView memberAvatar; + private final TextView memberName; ViewHolder(View v) { memberAvatar = v.findViewById(R.id.memberAvatar); @@ -36,8 +37,8 @@ public class RepoStargazersAdapter extends BaseAdapter { } } - public RepoStargazersAdapter(Context mCtx, List membersListMain) { - this.mCtx = mCtx; + public RepoStargazersAdapter(Context ctx, List membersListMain) { + this.context = ctx; this.stargazersList = membersListMain; } @@ -63,7 +64,7 @@ public class RepoStargazersAdapter extends BaseAdapter { RepoStargazersAdapter.ViewHolder viewHolder; if (finalView == null) { - finalView = LayoutInflater.from(mCtx).inflate(R.layout.list_repo_stargazers, null); + finalView = LayoutInflater.from(context).inflate(R.layout.list_repo_stargazers, null); viewHolder = new ViewHolder(finalView); finalView.setTag(viewHolder); } @@ -79,23 +80,25 @@ public class RepoStargazersAdapter extends BaseAdapter { private void initData(RepoStargazersAdapter.ViewHolder viewHolder, int position) { UserInfo currentItem = stargazersList.get(position); - PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar); + int imgRadius = AppUtil.getPixelsFromDensity(context, 3); - final TinyDB tinyDb = TinyDB.getInstance(mCtx); + PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar); + + final TinyDB tinyDb = TinyDB.getInstance(context); Typeface myTypeface; switch(tinyDb.getInt("customFontId", -1)) { case 0: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/roboto.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto.ttf"); break; case 2: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/sourcecodeproregular.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/sourcecodeproregular.ttf"); break; default: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/manroperegular.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/manroperegular.ttf"); break; } diff --git a/app/src/main/java/org/mian/gitnex/adapters/RepoWatchersAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/RepoWatchersAdapter.java index e774b42b..184a43a9 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/RepoWatchersAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/RepoWatchersAdapter.java @@ -12,6 +12,7 @@ import android.widget.TextView; import org.gitnex.tea4j.models.UserInfo; import org.mian.gitnex.R; import org.mian.gitnex.clients.PicassoService; +import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.helpers.TinyDB; import java.util.List; @@ -22,13 +23,13 @@ import java.util.List; public class RepoWatchersAdapter extends BaseAdapter { - private List watchersList; - private Context mCtx; + private final List watchersList; + private final Context context; private static class ViewHolder { - private ImageView memberAvatar; - private TextView memberName; + private final ImageView memberAvatar; + private final TextView memberName; ViewHolder(View v) { memberAvatar = v.findViewById(R.id.memberAvatar); @@ -36,8 +37,8 @@ public class RepoWatchersAdapter extends BaseAdapter { } } - public RepoWatchersAdapter(Context mCtx, List membersListMain) { - this.mCtx = mCtx; + public RepoWatchersAdapter(Context ctx, List membersListMain) { + this.context = ctx; this.watchersList = membersListMain; } @@ -63,7 +64,7 @@ public class RepoWatchersAdapter extends BaseAdapter { RepoWatchersAdapter.ViewHolder viewHolder; if (finalView == null) { - finalView = LayoutInflater.from(mCtx).inflate(R.layout.list_repo_watchers, null); + finalView = LayoutInflater.from(context).inflate(R.layout.list_repo_watchers, null); viewHolder = new ViewHolder(finalView); finalView.setTag(viewHolder); } @@ -79,23 +80,25 @@ public class RepoWatchersAdapter extends BaseAdapter { private void initData(RepoWatchersAdapter.ViewHolder viewHolder, int position) { UserInfo currentItem = watchersList.get(position); - PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar); + int imgRadius = AppUtil.getPixelsFromDensity(context, 3); - final TinyDB tinyDb = TinyDB.getInstance(mCtx); + PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar); + + final TinyDB tinyDb = TinyDB.getInstance(context); Typeface myTypeface; switch(tinyDb.getInt("customFontId", -1)) { case 0: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/roboto.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto.ttf"); break; case 2: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/sourcecodeproregular.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/sourcecodeproregular.ttf"); break; default: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/manroperegular.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/manroperegular.ttf"); break; } diff --git a/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java index 0069e224..360061f9 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java @@ -1,8 +1,5 @@ package org.mian.gitnex.adapters; -import android.annotation.SuppressLint; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; @@ -13,31 +10,31 @@ import android.widget.CheckBox; import android.widget.Filter; import android.widget.Filterable; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; -import com.google.android.material.bottomsheet.BottomSheetDialog; import org.gitnex.tea4j.models.UserRepositories; import org.gitnex.tea4j.models.WatchInfo; import org.mian.gitnex.R; -import org.mian.gitnex.activities.OpenRepoInBrowserActivity; import org.mian.gitnex.activities.RepoDetailActivity; -import org.mian.gitnex.activities.RepoForksActivity; -import org.mian.gitnex.activities.RepoStargazersActivity; -import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.clients.PicassoService; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.database.api.RepositoriesApi; import org.mian.gitnex.database.models.Repository; +import org.mian.gitnex.helpers.AppUtil; +import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.RoundedTransformation; +import org.mian.gitnex.helpers.TimeHelper; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; +import org.ocpsoft.prettytime.PrettyTime; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; -import java.util.Objects; +import java.util.Locale; import retrofit2.Call; import retrofit2.Callback; @@ -47,61 +44,54 @@ import retrofit2.Callback; public class ReposListAdapter extends RecyclerView.Adapter implements Filterable { - private List reposList; - private Context mCtx; - private List reposListFull; + private final List reposList; + private final Context context; + private final List reposListFull; static class ReposViewHolder extends RecyclerView.ViewHolder { - private ImageView image; - private TextView repoName; - private TextView repoDescription; - private TextView fullName; + private UserRepositories userRepositories; + + private final ImageView image; + private final TextView repoName; + private final TextView orgName; + private final TextView repoDescription; private CheckBox isRepoAdmin; - private ImageView repoPrivatePublic; - private TextView repoStars; - private TextView repoForks; - private TextView repoOpenIssuesCount; - private TextView repoType; - private LinearLayout archiveRepo; - private TextView repoBranch; - private TextView htmlUrl; + private final TextView repoStars; + private final TextView repoLastUpdated; private ReposViewHolder(View itemView) { super(itemView); repoName = itemView.findViewById(R.id.repoName); + orgName = itemView.findViewById(R.id.orgName); repoDescription = itemView.findViewById(R.id.repoDescription); isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin); image = itemView.findViewById(R.id.imageAvatar); - fullName = itemView.findViewById(R.id.repoFullName); - repoPrivatePublic = itemView.findViewById(R.id.imageRepoType); repoStars = itemView.findViewById(R.id.repoStars); - repoForks = itemView.findViewById(R.id.repoForks); - repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount); - ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu); - repoType = itemView.findViewById(R.id.repoType); - archiveRepo = itemView.findViewById(R.id.archiveRepoFrame); - repoBranch = itemView.findViewById(R.id.repoBranch); - htmlUrl = itemView.findViewById(R.id.htmlUrl); + repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated); itemView.setOnClickListener(v -> { Context context = v.getContext(); - TextView repoFullName = v.findViewById(R.id.repoFullName); - TextView repoType_ = v.findViewById(R.id.repoType); + TinyDB tinyDb = TinyDB.getInstance(context); Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", repoFullName.getText().toString()); + intent.putExtra("repoFullName", userRepositories.getFullName()); - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("repoFullName", repoFullName.getText().toString()); - tinyDb.putString("repoType", repoType_.getText().toString()); + tinyDb.putString("repoFullName", userRepositories.getFullName()); //tinyDb.putBoolean("resumeIssues", true); tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked()); - tinyDb.putString("repoBranch", repoBranch.getText().toString()); + tinyDb.putString("repoBranch", userRepositories.getDefault_branch()); - String[] parts = repoFullName.getText().toString().split("/"); + if(userRepositories.getPrivateFlag()) { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPrivate)); + } + else { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPublic)); + } + + String[] parts = userRepositories.getFullName().split("/"); final String repoOwner = parts[0]; final String repoName = parts[1]; @@ -115,13 +105,11 @@ public class ReposListAdapter extends RecyclerView.Adapter { - - final Context context = v.getContext(); - - @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - - TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); - TextView repoStargazers = view.findViewById(R.id.repoStargazers); - TextView repoWatchers = view.findViewById(R.id.repoWatchers); - TextView repoForksList = view.findViewById(R.id.repoForksList); - TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl); - TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader); - - bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1])); - BottomSheetDialog dialog = new BottomSheetDialog(context); - dialog.setContentView(view); - dialog.show(); - - repoCopyUrl.setOnClickListener(openInBrowser -> { - - ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString()); - assert clipboard != null; - clipboard.setPrimaryClip(clip); - - Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg)); - dialog.dismiss(); - }); - - repoOpenInBrowser.setOnClickListener(openInBrowser -> { - - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - dialog.dismiss(); - - }); - - repoStargazers.setOnClickListener(stargazers -> { - - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - dialog.dismiss(); - - }); - - repoWatchers.setOnClickListener(watchers -> { - - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - repoForksList.setOnClickListener(forks -> { - - Intent intentW = new Intent(context, RepoForksActivity.class); - intentW.putExtra("repoFullNameForForks", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - }); - } } - public ReposListAdapter(Context mCtx, List reposListMain) { + public ReposListAdapter(Context ctx, List reposListMain) { - this.mCtx = mCtx; + this.context = ctx; this.reposList = reposListMain; reposListFull = new ArrayList<>(reposList); } @@ -263,20 +183,26 @@ public class ReposListAdapter extends RecyclerView.Adapter implements Filterable { - private List reposList; - private Context mCtx; - private List reposListFull; + private final List reposList; + private final Context context; + private final List reposListFull; static class OrgReposViewHolder extends RecyclerView.ViewHolder { - private ImageView image; - private TextView repoName; - private TextView repoDescription; - private TextView fullName; - private CheckBox isRepoAdmin; - private ImageView repoPrivatePublic; - private TextView repoStars; - private TextView repoForks; - private TextView repoOpenIssuesCount; - private TextView repoType; - private LinearLayout archiveRepo; - private TextView repoBranch; - private TextView htmlUrl; + private UserRepositories userRepositories; + + private final ImageView image; + private final TextView repoName; + private final TextView orgName; + private final TextView repoDescription; + private CheckBox isRepoAdmin; + private final TextView repoStars; + private final TextView repoLastUpdated; private OrgReposViewHolder(View itemView) { - super(itemView); - repoName = itemView.findViewById(R.id.repoName); - repoDescription = itemView.findViewById(R.id.repoDescription); - isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin); - image = itemView.findViewById(R.id.imageAvatar); - fullName = itemView.findViewById(R.id.repoFullName); - repoPrivatePublic = itemView.findViewById(R.id.imageRepoType); - repoStars = itemView.findViewById(R.id.repoStars); - repoForks = itemView.findViewById(R.id.repoForks); - repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount); - ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu); - repoType = itemView.findViewById(R.id.repoType); - archiveRepo = itemView.findViewById(R.id.archiveRepoFrame); - repoBranch = itemView.findViewById(R.id.repoBranch); - htmlUrl = itemView.findViewById(R.id.htmlUrl); + + super(itemView); + repoName = itemView.findViewById(R.id.repoName); + orgName = itemView.findViewById(R.id.orgName); + repoDescription = itemView.findViewById(R.id.repoDescription); + isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin); + image = itemView.findViewById(R.id.imageAvatar); + repoStars = itemView.findViewById(R.id.repoStars); + repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated); itemView.setOnClickListener(v -> { Context context = v.getContext(); + TinyDB tinyDb = TinyDB.getInstance(context); Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", fullName.getText().toString()); + intent.putExtra("repoFullName", userRepositories.getFullName()); - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("repoFullName", fullName.getText().toString()); - tinyDb.putString("repoType", repoType.getText().toString()); + tinyDb.putString("repoFullName", userRepositories.getFullName()); //tinyDb.putBoolean("resumeIssues", true); tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked()); - tinyDb.putString("repoBranch", repoBranch.getText().toString()); + tinyDb.putString("repoBranch", userRepositories.getDefault_branch()); - String[] parts = fullName.getText().toString().split("/"); + if(userRepositories.getPrivateFlag()) { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPrivate)); + } + else { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPublic)); + } + + String[] parts = userRepositories.getFullName().split("/"); final String repoOwner = parts[0]; final String repoName = parts[1]; @@ -112,13 +105,11 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter { - - final Context context = v.getContext(); - - @SuppressLint("InflateParams") - View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - - TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); - TextView repoStargazers = view.findViewById(R.id.repoStargazers); - TextView repoWatchers = view.findViewById(R.id.repoWatchers); - TextView repoForksList = view.findViewById(R.id.repoForksList); - TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl); - TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader); - - bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1])); - BottomSheetDialog dialog = new BottomSheetDialog(context); - dialog.setContentView(view); - dialog.show(); - - repoCopyUrl.setOnClickListener(openInBrowser -> { - - ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString()); - assert clipboard != null; - clipboard.setPrimaryClip(clip); - - Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg)); - dialog.dismiss(); - }); - - repoOpenInBrowser.setOnClickListener(openInBrowser -> { - - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - dialog.dismiss(); - - }); - - repoStargazers.setOnClickListener(stargazers -> { - - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - dialog.dismiss(); - - }); - - repoWatchers.setOnClickListener(watchers -> { - - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - repoForksList.setOnClickListener(forks -> { - - Intent intentW = new Intent(context, RepoForksActivity.class); - intentW.putExtra("repoFullNameForForks", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - }); - } } - public RepositoriesByOrgAdapter(Context mCtx, List reposListMain) { - this.mCtx = mCtx; + public RepositoriesByOrgAdapter(Context ctx, List reposListMain) { + + this.context = ctx; this.reposList = reposListMain; reposListFull = new ArrayList<>(reposList); } @@ -249,6 +172,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter { private final List searchedList; - private final Context mCtx; + private final Context context; private final TinyDB tinyDb; - public SearchIssuesAdapter(List dataList, Context mCtx) { + public SearchIssuesAdapter(List dataList, Context ctx) { - this.mCtx = mCtx; + this.context = ctx; this.searchedList = dataList; - this.tinyDb = TinyDB.getInstance(mCtx); + this.tinyDb = TinyDB.getInstance(context); } class SearchViewHolder extends RecyclerView.ViewHolder { @@ -63,7 +63,7 @@ public class SearchIssuesAdapter extends RecyclerView.Adapter { + itemView.setOnClickListener(v -> { Context context = v.getContext(); @@ -121,19 +121,20 @@ public class SearchIssuesAdapter extends RecyclerView.Adapter" + currentItem.getRepository().getFull_name() + mCtx.getResources().getString(R.string.hash) + currentItem.getNumber() + ""; + String issueNumber_ = "" + currentItem.getRepository().getFull_name() + context.getResources().getString(R.string.hash) + currentItem.getNumber() + ""; holder.issue = currentItem; holder.issueTitle.setText(HtmlCompat.fromHtml(issueNumber_ + " " + currentItem.getTitle(), HtmlCompat.FROM_HTML_MODE_LEGACY)); @@ -144,17 +145,17 @@ public class SearchIssuesAdapter extends RecyclerView.Adapter { - - private List sponsorsList; - - static class SponsorsViewHolder extends RecyclerView.ViewHolder { - - private TextView sponsorText; - - private SponsorsViewHolder(View itemView) { - super(itemView); - - sponsorText = itemView.findViewById(R.id.sponsorText); - - } - } - - public SponsorsAdapter(List sponsorsListMain) { - this.sponsorsList = sponsorsListMain; - } - - @NonNull - @Override - public SponsorsAdapter.SponsorsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sponsors, parent, false); - return new SponsorsAdapter.SponsorsViewHolder(v); - } - - @Override - public void onBindViewHolder(@NonNull SponsorsAdapter.SponsorsViewHolder holder, int position) { - - SpannableStringBuilder strBuilder = new SpannableStringBuilder(sponsorsList.get(position)); - holder.sponsorText.setText((strBuilder)); - holder.sponsorText.setMovementMethod(LinkMovementMethod.getInstance()); - - } - - @Override - public int getItemCount() { - return sponsorsList.size(); - } - -} diff --git a/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java index 947f3d01..3ebf5bd8 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java @@ -1,8 +1,5 @@ package org.mian.gitnex.adapters; -import android.annotation.SuppressLint; -import android.content.ClipData; -import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; @@ -13,31 +10,31 @@ import android.widget.CheckBox; import android.widget.Filter; import android.widget.Filterable; import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; -import com.google.android.material.bottomsheet.BottomSheetDialog; import org.gitnex.tea4j.models.UserRepositories; import org.gitnex.tea4j.models.WatchInfo; import org.mian.gitnex.R; -import org.mian.gitnex.activities.OpenRepoInBrowserActivity; import org.mian.gitnex.activities.RepoDetailActivity; -import org.mian.gitnex.activities.RepoForksActivity; -import org.mian.gitnex.activities.RepoStargazersActivity; -import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.clients.PicassoService; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.database.api.RepositoriesApi; import org.mian.gitnex.database.models.Repository; +import org.mian.gitnex.helpers.AppUtil; +import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.RoundedTransformation; +import org.mian.gitnex.helpers.TimeHelper; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; +import org.ocpsoft.prettytime.PrettyTime; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; -import java.util.Objects; +import java.util.Locale; import retrofit2.Call; import retrofit2.Callback; @@ -47,58 +44,54 @@ import retrofit2.Callback; public class StarredReposListAdapter extends RecyclerView.Adapter implements Filterable { - private List reposList; - private Context mCtx; - private List reposListFull; + private final List reposList; + private final Context context; + private final List reposListFull; static class StarredReposViewHolder extends RecyclerView.ViewHolder { - private ImageView image; - private TextView repoName; - private TextView repoDescription; - private TextView fullName; - private CheckBox isRepoAdmin; - private ImageView repoPrivatePublic; - private TextView repoStars; - private TextView repoForks; - private TextView repoOpenIssuesCount; - private TextView repoType; - private LinearLayout archiveRepo; - private TextView repoBranch; - private TextView htmlUrl; + private UserRepositories userRepositories; + + private final ImageView image; + private final TextView repoName; + private final TextView orgName; + private final TextView repoDescription; + private CheckBox isRepoAdmin; + private final TextView repoStars; + private final TextView repoLastUpdated; private StarredReposViewHolder(View itemView) { - super(itemView); - repoName = itemView.findViewById(R.id.repoName); - repoDescription = itemView.findViewById(R.id.repoDescription); - isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin); - image = itemView.findViewById(R.id.imageAvatar); - fullName = itemView.findViewById(R.id.repoFullName); - repoPrivatePublic = itemView.findViewById(R.id.imageRepoType); - repoStars = itemView.findViewById(R.id.repoStars); - repoForks = itemView.findViewById(R.id.repoForks); - repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount); - ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu); - repoType = itemView.findViewById(R.id.repoType); - archiveRepo = itemView.findViewById(R.id.archiveRepoFrame); - repoBranch = itemView.findViewById(R.id.repoBranch); - htmlUrl = itemView.findViewById(R.id.htmlUrl); + + super(itemView); + repoName = itemView.findViewById(R.id.repoName); + orgName = itemView.findViewById(R.id.orgName); + repoDescription = itemView.findViewById(R.id.repoDescription); + isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin); + image = itemView.findViewById(R.id.imageAvatar); + repoStars = itemView.findViewById(R.id.repoStars); + repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated); itemView.setOnClickListener(v -> { Context context = v.getContext(); + TinyDB tinyDb = TinyDB.getInstance(context); Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", fullName.getText().toString()); + intent.putExtra("repoFullName", userRepositories.getFullName()); - TinyDB tinyDb = TinyDB.getInstance(context); - tinyDb.putString("repoFullName", fullName.getText().toString()); - tinyDb.putString("repoType", repoType.getText().toString()); + tinyDb.putString("repoFullName", userRepositories.getFullName()); //tinyDb.putBoolean("resumeIssues", true); tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked()); - tinyDb.putString("repoBranch", repoBranch.getText().toString()); + tinyDb.putString("repoBranch", userRepositories.getDefault_branch()); - String[] parts = fullName.getText().toString().split("/"); + if(userRepositories.getPrivateFlag()) { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPrivate)); + } + else { + tinyDb.putString("repoType", context.getResources().getString(R.string.strPublic)); + } + + String[] parts = userRepositories.getFullName().split("/"); final String repoOwner = parts[0]; final String repoName = parts[1]; @@ -112,13 +105,11 @@ public class StarredReposListAdapter extends RecyclerView.Adapter { - - final Context context = v.getContext(); - - @SuppressLint("InflateParams") - View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - - TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); - TextView repoStargazers = view.findViewById(R.id.repoStargazers); - TextView repoWatchers = view.findViewById(R.id.repoWatchers); - TextView repoForksList = view.findViewById(R.id.repoForksList); - TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl); - TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader); - - bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1])); - BottomSheetDialog dialog = new BottomSheetDialog(context); - dialog.setContentView(view); - dialog.show(); - - repoCopyUrl.setOnClickListener(openInBrowser -> { - - ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString()); - assert clipboard != null; - clipboard.setPrimaryClip(clip); - - Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg)); - dialog.dismiss(); - }); - - repoOpenInBrowser.setOnClickListener(openInBrowser -> { - - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - dialog.dismiss(); - - }); - - repoStargazers.setOnClickListener(stargazers -> { - - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - dialog.dismiss(); - - }); - - repoWatchers.setOnClickListener(watchers -> { - - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - repoForksList.setOnClickListener(forks -> { - - Intent intentW = new Intent(context, RepoForksActivity.class); - intentW.putExtra("repoFullNameForForks", fullName.getText()); - context.startActivity(intentW); - dialog.dismiss(); - - }); - - }); - } } - public StarredReposListAdapter(Context mCtx, List reposListMain) { - this.mCtx = mCtx; + public StarredReposListAdapter(Context ctx, List reposListMain) { + this.context = ctx; this.reposList = reposListMain; reposListFull = new ArrayList<>(reposList); } @@ -259,10 +181,16 @@ public class StarredReposListAdapter extends RecyclerView.Adapter filteredList = new ArrayList<>(); diff --git a/app/src/main/java/org/mian/gitnex/adapters/TeamMembersByOrgAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/TeamMembersByOrgAdapter.java index 78627007..b818f515 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/TeamMembersByOrgAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/TeamMembersByOrgAdapter.java @@ -25,7 +25,7 @@ import java.util.List; public class TeamMembersByOrgAdapter extends BaseAdapter { private final List teamMembersList; - private final Context mCtx; + private final Context context; private static class ViewHolder { @@ -48,9 +48,9 @@ public class TeamMembersByOrgAdapter extends BaseAdapter { } } - public TeamMembersByOrgAdapter(Context mCtx, List membersListMain) { + public TeamMembersByOrgAdapter(Context ctx, List membersListMain) { - this.mCtx = mCtx; + this.context = ctx; this.teamMembersList = membersListMain; } @@ -77,7 +77,7 @@ public class TeamMembersByOrgAdapter extends BaseAdapter { if (finalView == null) { - finalView = LayoutInflater.from(mCtx).inflate(R.layout.list_members_by_team_by_org, null); + finalView = LayoutInflater.from(context).inflate(R.layout.list_members_by_team_by_org, null); viewHolder = new ViewHolder(finalView); finalView.setTag(viewHolder); } @@ -93,25 +93,27 @@ public class TeamMembersByOrgAdapter extends BaseAdapter { private void initData(TeamMembersByOrgAdapter.ViewHolder viewHolder, int position) { UserInfo currentItem = teamMembersList.get(position); - PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar); + int imgRadius = AppUtil.getPixelsFromDensity(context, 3); + + PicassoService.getInstance(context).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar); viewHolder.userLoginId = currentItem.getLogin(); - final TinyDB tinyDb = TinyDB.getInstance(mCtx); + final TinyDB tinyDb = TinyDB.getInstance(context); Typeface myTypeface; switch(tinyDb.getInt("customFontId", -1)) { case 0: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/roboto.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto.ttf"); break; case 2: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/sourcecodeproregular.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/sourcecodeproregular.ttf"); break; default: - myTypeface = Typeface.createFromAsset(mCtx.getAssets(), "fonts/manroperegular.ttf"); + myTypeface = Typeface.createFromAsset(context.getAssets(), "fonts/manroperegular.ttf"); break; } diff --git a/app/src/main/java/org/mian/gitnex/adapters/TeamsByOrgAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/TeamsByOrgAdapter.java index 2582535d..25030a8c 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/TeamsByOrgAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/TeamsByOrgAdapter.java @@ -22,44 +22,41 @@ import java.util.List; public class TeamsByOrgAdapter extends RecyclerView.Adapter implements Filterable { - private List teamList; - private Context mCtx; - private List teamListFull; + private final List teamList; + private final Context context; + private final List teamListFull; static class OrgTeamsViewHolder extends RecyclerView.ViewHolder { - private TextView teamTitle; - private TextView teamId; - private TextView teamDescription; - private TextView teamPermission; + private Teams teams; + + private final TextView teamTitle; + private final TextView teamDescription; + private final TextView teamPermission; private OrgTeamsViewHolder(View itemView) { + super(itemView); teamTitle = itemView.findViewById(R.id.teamTitle); - teamId = itemView.findViewById(R.id.teamId); teamDescription = itemView.findViewById(R.id.teamDescription); teamPermission = itemView.findViewById(R.id.teamPermission); - itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + itemView.setOnClickListener(v -> { - Context context = v.getContext(); + Context context = v.getContext(); - Intent intent = new Intent(context, OrganizationTeamMembersActivity.class); - intent.putExtra("teamTitle", teamTitle.getText().toString()); - intent.putExtra("teamId", teamId.getText().toString()); - context.startActivity(intent); - - } + Intent intent = new Intent(context, OrganizationTeamMembersActivity.class); + intent.putExtra("teamTitle", teams.getName()); + intent.putExtra("teamId", String.valueOf(teams.getId())); + context.startActivity(intent); }); } } - public TeamsByOrgAdapter(Context mCtx, List teamListMain) { - this.mCtx = mCtx; + public TeamsByOrgAdapter(Context ctx, List teamListMain) { + this.context = ctx; this.teamList = teamListMain; teamListFull = new ArrayList<>(teamList); } @@ -75,8 +72,10 @@ public class TeamsByOrgAdapter extends RecyclerView.Adapter filteredList = new ArrayList<>(); diff --git a/app/src/main/java/org/mian/gitnex/adapters/UserAccountsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/UserAccountsAdapter.java index 6849e929..d698b997 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/UserAccountsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/UserAccountsAdapter.java @@ -16,6 +16,7 @@ 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.helpers.AppUtil; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; @@ -29,7 +30,7 @@ import io.mikael.urlbuilder.UrlBuilder; public class UserAccountsAdapter extends RecyclerView.Adapter { private final List userAccountsList; - private final Context mCtx; + private final Context context; private TinyDB tinyDB; class UserAccountsViewHolder extends RecyclerView.ViewHolder { @@ -55,22 +56,22 @@ public class UserAccountsAdapter extends RecyclerView.Adapter { - new AlertDialog.Builder(mCtx) - .setIcon(AppCompatResources.getDrawable(mCtx, R.drawable.ic_delete)) - .setTitle(mCtx.getResources().getString(R.string.removeAccountPopupTitle)) - .setMessage(mCtx.getResources().getString(R.string.removeAccountPopupMessage)) - .setPositiveButton(mCtx.getResources().getString(R.string.removeButton), (dialog, which) -> { + new AlertDialog.Builder(context) + .setIcon(AppCompatResources.getDrawable(context, R.drawable.ic_delete)) + .setTitle(context.getResources().getString(R.string.removeAccountPopupTitle)) + .setMessage(context.getResources().getString(R.string.removeAccountPopupMessage)) + .setPositiveButton(context.getResources().getString(R.string.removeButton), (dialog, which) -> { updateLayoutByPosition(getAdapterPosition()); - UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx); + UserAccountsApi userAccountsApi = new UserAccountsApi(context); userAccountsApi.deleteAccount(Integer.parseInt(String.valueOf(accountId))); - }).setNeutralButton(mCtx.getResources().getString(R.string.cancelButton), null) + }).setNeutralButton(context.getResources().getString(R.string.cancelButton), null) .show(); }); itemView.setOnClickListener(switchAccount -> { - UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx); + UserAccountsApi userAccountsApi = new UserAccountsApi(context); UserAccount userAccount = userAccountsApi.getAccountData(accountName); if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) { @@ -85,8 +86,8 @@ public class UserAccountsAdapter extends RecyclerView.Adapter userAccountsListMain) { + public UserAccountsAdapter(Context ctx, List userAccountsListMain) { - this.mCtx = mCtx; + this.context = ctx; this.userAccountsList = userAccountsListMain; } @@ -106,7 +107,7 @@ public class UserAccountsAdapter extends RecyclerView.Adapter { - private final Context mCtx; + private final Context context; private final TinyDB tinyDB; private final List userAccounts; - public UserAccountsListDialogAdapter(@NonNull Context mCtx, int resource, @NonNull List userAccounts) { + public UserAccountsListDialogAdapter(@NonNull Context ctx, int resource, @NonNull List userAccounts) { - super(mCtx, resource, userAccounts); + super(ctx, resource, userAccounts); - tinyDB = TinyDB.getInstance(mCtx); + tinyDB = TinyDB.getInstance(ctx); this.userAccounts = userAccounts; - this.mCtx = mCtx; - + this.context = ctx; } @NonNull @@ -42,7 +42,7 @@ public class UserAccountsListDialogAdapter extends ArrayAdapter { public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { if(convertView == null) { - convertView = LayoutInflater.from(mCtx).inflate(R.layout.custom_user_accounts_list, parent, false); + convertView = LayoutInflater.from(context).inflate(R.layout.custom_user_accounts_list, parent, false); } ImageView profileImage = convertView.findViewById(R.id.profileImage); @@ -51,6 +51,7 @@ public class UserAccountsListDialogAdapter extends ArrayAdapter { ImageView activeAccount = convertView.findViewById(R.id.activeAccount); UserAccount currentItem = userAccounts.get(position); + int imgRadius = AppUtil.getPixelsFromDensity(context, 3); String url = UrlBuilder.fromString(currentItem.getInstanceUrl()) .withPath("/") @@ -67,7 +68,7 @@ public class UserAccountsListDialogAdapter extends ArrayAdapter { } PicassoService - .getInstance(mCtx).get().load(url + "img/favicon.png").placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(profileImage); + .getInstance(context).get().load(url + "img/favicon.png").placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop().into(profileImage); return convertView; diff --git a/app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java index f09f6fa7..7db88c76 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java @@ -21,6 +21,7 @@ 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; @@ -34,13 +35,13 @@ import io.mikael.urlbuilder.UrlBuilder; public class UserAccountsNavAdapter extends RecyclerView.Adapter { private static DrawerLayout drawer; - private List userAccountsList; - private Context mCtx; - private TextView toolbarTitle; + private final List userAccountsList; + private final Context context; + private final TextView toolbarTitle; - public UserAccountsNavAdapter(Context mCtx, List userAccountsListMain, DrawerLayout drawerLayout, TextView toolbarTitle) { + public UserAccountsNavAdapter(Context ctx, List userAccountsListMain, DrawerLayout drawerLayout, TextView toolbarTitle) { - this.mCtx = mCtx; + this.context = ctx; this.userAccountsList = userAccountsListMain; drawer = drawerLayout; this.toolbarTitle = toolbarTitle; @@ -48,7 +49,7 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter { - customDialogUserAccountsList(userAccountsList); drawer.closeDrawers(); }); @@ -84,8 +84,15 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter allAccountsList) { - TinyDB tinyDB = TinyDB.getInstance(mCtx); - Dialog dialog = new Dialog(mCtx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert); + TinyDB tinyDB = TinyDB.getInstance(context); + Dialog dialog = new Dialog(context, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert); dialog.setContentView(R.layout.custom_user_accounts_dialog); ListView listView = dialog.findViewById(R.id.accountsList); @@ -109,19 +116,19 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter { - toolbarTitle.setText(mCtx.getResources().getString(R.string.pageTitleUserAccounts)); - AppCompatActivity activity = (AppCompatActivity) mCtx; + toolbarTitle.setText(context.getResources().getString(R.string.pageTitleUserAccounts)); + AppCompatActivity activity = (AppCompatActivity) context; activity.getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new UserAccountsFragment()).commit(); dialog.dismiss(); }); - UserAccountsListDialogAdapter arrayAdapter = new UserAccountsListDialogAdapter(mCtx, R.layout.custom_user_accounts_list, allAccountsList); + UserAccountsListDialogAdapter arrayAdapter = new UserAccountsListDialogAdapter(context, R.layout.custom_user_accounts_list, allAccountsList); listView.setAdapter(arrayAdapter); listView.setOnItemClickListener((adapterView, view, which, l) -> { String accountNameSwitch = allAccountsList.get(which).getAccountName(); - UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx); + UserAccountsApi userAccountsApi = new UserAccountsApi(context); UserAccount userAccount = userAccountsApi.getAccountData(accountNameSwitch); if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) { @@ -136,8 +143,8 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter { - private List usersSearchList; - private Context mCtx; + private final List usersSearchList; + private final Context context; - public UserSearchAdapter(List dataList, Context mCtx) { - this.mCtx = mCtx; + public UserSearchAdapter(List dataList, Context ctx) { + this.context = ctx; this.usersSearchList = dataList; } static class UserSearchViewHolder extends RecyclerView.ViewHolder { - private ImageView userAvatar; - private TextView userFullName; - private TextView userName; - private TextView userNameMain; - private ImageView addCollaboratorButtonAdd; - private ImageView addCollaboratorButtonRemove; + private UserInfo userInfo; - private String[] permissionList = {"Read", "Write", "Admin"}; + private final ImageView userAvatar; + private final TextView userFullName; + private final TextView userName; + private final ImageView addCollaboratorButtonAdd; + private final ImageView addCollaboratorButtonRemove; + + private final String[] permissionList = {"Read", "Write", "Admin"}; final private int permissionSelectedChoice = 0; private UserSearchViewHolder(View itemView) { + super(itemView); userAvatar = itemView.findViewById(R.id.userAvatar); userFullName = itemView.findViewById(R.id.userFullName); userName = itemView.findViewById(R.id.userName); - userNameMain = itemView.findViewById(R.id.userNameMain); addCollaboratorButtonAdd = itemView.findViewById(R.id.addCollaboratorButtonAdd); addCollaboratorButtonRemove = itemView.findViewById(R.id.addCollaboratorButtonRemove); - addCollaboratorButtonAdd.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + addCollaboratorButtonAdd.setOnClickListener(v -> { - final Context context = v.getContext(); + final Context context = v.getContext(); - AlertDialog.Builder pBuilder = new AlertDialog.Builder(context); + AlertDialog.Builder pBuilder = new AlertDialog.Builder(context); - pBuilder.setTitle(R.string.newTeamPermission); - pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { + pBuilder.setTitle(R.string.newTeamPermission); + pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, (dialogInterface, i) -> { - } - }) - .setCancelable(false) - .setNegativeButton(R.string.cancelButton, null) - .setPositiveButton(R.string.addButton, new DialogInterface.OnClickListener() { + }) + .setCancelable(false) + .setNegativeButton(R.string.cancelButton, null) + .setPositiveButton(R.string.addButton, (dialog, which) -> { - @Override - public void onClick(DialogInterface dialog, int which) { + ListView lw = ((AlertDialog)dialog).getListView(); + Object checkedItem = lw.getAdapter().getItem(lw.getCheckedItemPosition()); - ListView lw = ((AlertDialog)dialog).getListView(); - Object checkedItem = lw.getAdapter().getItem(lw.getCheckedItemPosition()); + CollaboratorActions.addCollaborator(context, String.valueOf(checkedItem).toLowerCase(), userInfo.getUsername()); + }); - CollaboratorActions.addCollaborator(context, String.valueOf(checkedItem).toLowerCase(), userNameMain.getText().toString()); - - } - }); - - AlertDialog pDialog = pBuilder.create(); - pDialog.show(); - - } + AlertDialog pDialog = pBuilder.create(); + pDialog.show(); }); - addCollaboratorButtonRemove.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + addCollaboratorButtonRemove.setOnClickListener(v -> { - Context context = v.getContext(); + Context context = v.getContext(); - AlertDialogs.collaboratorRemoveDialog(context, userNameMain.getText().toString(), - context.getResources().getString(R.string.removeCollaboratorTitle), - context.getResources().getString(R.string.removeCollaboratorMessage), - context.getResources().getString(R.string.removeButton), - context.getResources().getString(R.string.cancelButton), "fa"); - - } + AlertDialogs.collaboratorRemoveDialog(context, userInfo.getUsername(), + context.getResources().getString(R.string.removeCollaboratorTitle), + context.getResources().getString(R.string.removeCollaboratorMessage), + context.getResources().getString(R.string.removeButton), + context.getResources().getString(R.string.cancelButton), "fa"); }); } @@ -128,9 +113,9 @@ public class UserSearchAdapter extends RecyclerView.Adapter 0) { - TinyDB tinyDb = TinyDB.getInstance(mCtx); + TinyDB tinyDb = TinyDB.getInstance(context); final String loginUid = tinyDb.getString("loginUid"); String repoFullName = tinyDb.getString("repoFullName"); String[] parts = repoFullName.split("/"); @@ -157,8 +142,8 @@ public class UserSearchAdapter extends RecyclerView.Adapter call = RetrofitClient - .getApiInterface(mCtx) - .checkRepoCollaborator(Authorization.get(mCtx), repoOwner, repoName, currentItem.getUsername()); + .getApiInterface(context) + .checkRepoCollaborator(Authorization.get(context), repoOwner, repoName, currentItem.getUsername()); call.enqueue(new Callback() { diff --git a/app/src/main/java/org/mian/gitnex/adapters/UserSearchForTeamMemberAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/UserSearchForTeamMemberAdapter.java index 0be11de8..ad2ca677 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/UserSearchForTeamMemberAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/UserSearchForTeamMemberAdapter.java @@ -14,6 +14,7 @@ import org.mian.gitnex.R; import org.mian.gitnex.clients.PicassoService; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.helpers.AlertDialogs; +import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.Authorization; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.helpers.TinyDB; @@ -29,25 +30,25 @@ import retrofit2.Response; public class UserSearchForTeamMemberAdapter extends RecyclerView.Adapter { - private List usersSearchList; - private Context mCtx; - private int teamId; + private final List usersSearchList; + private final Context context; + private static int teamId; - public UserSearchForTeamMemberAdapter(List dataList, Context mCtx, int teamId) { - this.mCtx = mCtx; + public UserSearchForTeamMemberAdapter(List dataList, Context ctx, int teamId) { + this.context = ctx; this.usersSearchList = dataList; - this.teamId = teamId; + UserSearchForTeamMemberAdapter.teamId = teamId; } static class UserSearchViewHolder extends RecyclerView.ViewHolder { - private ImageView userAvatar; - private TextView userFullName; - private TextView userName; - private TextView userNameMain; - private ImageView addMemberButtonAdd; - private ImageView addMemberButtonRemove; - private TextView teamId_; + private UserInfo userInfo; + + private final ImageView userAvatar; + private final TextView userFullName; + private final TextView userName; + private final ImageView addMemberButtonAdd; + private final ImageView addMemberButtonRemove; private UserSearchViewHolder(View itemView) { @@ -55,35 +56,30 @@ public class UserSearchForTeamMemberAdapter extends RecyclerView.Adapter { Context context = v.getContext(); - AlertDialogs.addMemberDialog(context, userNameMain.getText().toString(), + AlertDialogs.addMemberDialog(context, userInfo.getLogin(), context.getResources().getString(R.string.addTeamMemberTitle), context.getResources().getString(R.string.addTeamMemberMessage), context.getResources().getString(R.string.addButton), - context.getResources().getString(R.string.cancelButton), Integer.parseInt(teamId_.getText().toString())); - + context.getResources().getString(R.string.cancelButton), Integer.parseInt(String.valueOf(teamId))); }); addMemberButtonRemove.setOnClickListener(v -> { Context context = v.getContext(); - AlertDialogs.removeMemberDialog(context, userNameMain.getText().toString(), + AlertDialogs.removeMemberDialog(context, userInfo.getLogin(), context.getResources().getString(R.string.removeTeamMemberTitle), context.getResources().getString(R.string.removeTeamMemberMessage), context.getResources().getString(R.string.removeButton), - context.getResources().getString(R.string.cancelButton), Integer.parseInt(teamId_.getText().toString())); - + context.getResources().getString(R.string.cancelButton), Integer.parseInt(String.valueOf(teamId))); }); - } } @@ -98,39 +94,36 @@ public class UserSearchForTeamMemberAdapter extends RecyclerView.Adapter 0) { - TinyDB tinyDb = TinyDB.getInstance(mCtx); + TinyDB tinyDb = TinyDB.getInstance(context); final String loginUid = tinyDb.getString("loginUid"); String repoFullName = tinyDb.getString("repoFullName"); String[] parts = repoFullName.split("/"); final String repoOwner = parts[0]; - final String instanceToken = "token " + tinyDb.getString(loginUid + "-token"); Call call = RetrofitClient - .getApiInterface(mCtx) - .checkTeamMember(Authorization.get(mCtx), teamId, currentItem.getLogin()); + .getApiInterface(context) + .checkTeamMember(Authorization.get(context), teamId, currentItem.getLogin()); call.enqueue(new Callback() { @@ -167,8 +160,7 @@ public class UserSearchForTeamMemberAdapter extends RecyclerView.Adapter call, @NonNull Throwable t) { - Toasty.error(mCtx, mCtx.getResources().getString(R.string.genericServerResponseError)); - + Toasty.error(context, context.getResources().getString(R.string.genericServerResponseError)); } }); diff --git a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java index df04d66e..851075dd 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java @@ -19,6 +19,7 @@ import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; +import com.vdurmont.emoji.EmojiParser; import org.mian.gitnex.R; import org.mian.gitnex.actions.ActionResult; import org.mian.gitnex.actions.IssueActions; @@ -61,7 +62,6 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment { repositoryId = (int) tinyDB.getLong("repositoryId", 0); currentActiveAccountId = tinyDB.getInt("currentActiveAccountId"); issueNumber = Integer.parseInt(tinyDB.getString("issueNumber")); - } @SuppressLint("ClickableViewAccessibility") @@ -87,7 +87,6 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment { send.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_save)); mode = Mode.EDIT; - } if(arguments.getString("draftId") != null) { @@ -97,7 +96,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment { if(!tinyDB.getString("issueTitle").isEmpty()) { - toolbarTitle.setText(tinyDB.getString("issueTitle")); + toolbarTitle.setText(EmojiParser.parseToUnicode(tinyDB.getString("issueTitle"))); } else if(arguments.getString("draftTitle") != null) { @@ -134,7 +133,6 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment { } return false; - }); comment.addTextChangedListener(new TextWatcher() { diff --git a/app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java b/app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java index 29c853dd..88095d88 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java @@ -168,7 +168,6 @@ public class IssuesFragment extends Fragment { loadInitial(Authorization.get(getContext()), repoOwner, repoName, resultLimit, requestType, tinyDb.getString("repoIssuesState")); tinyDb.putBoolean("resumeIssues", false); - } } @@ -191,14 +190,12 @@ public class IssuesFragment extends Fragment { issuesList.addAll(response.body()); adapter.notifyDataChanged(); noDataIssues.setVisibility(View.GONE); - } else { issuesList.clear(); adapter.notifyDataChanged(); noDataIssues.setVisibility(View.VISIBLE); - } mProgressBar.setVisibility(View.GONE); @@ -208,7 +205,6 @@ public class IssuesFragment extends Fragment { noDataIssues.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.GONE); - } else { Log.e(TAG, String.valueOf(response.code())); @@ -311,7 +307,6 @@ public class IssuesFragment extends Fragment { filter(newText); return false; - } }); diff --git a/app/src/main/java/org/mian/gitnex/fragments/ProfileEmailsFragment.java b/app/src/main/java/org/mian/gitnex/fragments/ProfileEmailsFragment.java index 181573ab..90101c4e 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/ProfileEmailsFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/ProfileEmailsFragment.java @@ -74,11 +74,10 @@ public class ProfileEmailsFragment extends Fragment { noDataEmails = fragmentProfileEmailsBinding.noDataEmails; mRecyclerView = fragmentProfileEmailsBinding.recyclerView; + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL); + mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), - DividerItemDecoration.VERTICAL); mRecyclerView.addItemDecoration(dividerItemDecoration); mProgressBar = fragmentProfileEmailsBinding.progressBar; diff --git a/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowersFragment.java b/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowersFragment.java index 58d8a066..68d3ebaa 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowersFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowersFragment.java @@ -10,20 +10,16 @@ import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import org.gitnex.tea4j.models.UserInfo; import org.mian.gitnex.adapters.ProfileFollowersAdapter; import org.mian.gitnex.databinding.FragmentProfileFollowersBinding; import org.mian.gitnex.helpers.Authorization; import org.mian.gitnex.viewmodels.ProfileFollowersViewModel; -import java.util.List; /** * Author M M Arif @@ -75,11 +71,10 @@ public class ProfileFollowersFragment extends Fragment { noDataFollowers = fragmentProfileFollowersBinding.noDataFollowers; mRecyclerView = fragmentProfileFollowersBinding.recyclerView; - mRecyclerView.setHasFixedSize(true); - mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), - DividerItemDecoration.VERTICAL); + mRecyclerView.setHasFixedSize(true); + mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mRecyclerView.addItemDecoration(dividerItemDecoration); mProgressBar = fragmentProfileFollowersBinding.progressBar; @@ -100,21 +95,21 @@ public class ProfileFollowersFragment extends Fragment { ProfileFollowersViewModel pfModel = new ViewModelProvider(this).get(ProfileFollowersViewModel.class); - pfModel.getFollowersList(instanceToken, getContext()).observe(getViewLifecycleOwner(), new Observer>() { - @Override - public void onChanged(@Nullable List pfListMain) { - adapter = new ProfileFollowersAdapter(getContext(), pfListMain); - if(adapter.getItemCount() > 0) { - mRecyclerView.setAdapter(adapter); - noDataFollowers.setVisibility(View.GONE); - } - else { - adapter.notifyDataSetChanged(); - mRecyclerView.setAdapter(adapter); - noDataFollowers.setVisibility(View.VISIBLE); - } - mProgressBar.setVisibility(View.GONE); + pfModel.getFollowersList(instanceToken, getContext()).observe(getViewLifecycleOwner(), pfListMain -> { + + adapter = new ProfileFollowersAdapter(getContext(), pfListMain); + + if(adapter.getItemCount() > 0) { + mRecyclerView.setAdapter(adapter); + noDataFollowers.setVisibility(View.GONE); } + else { + adapter.notifyDataSetChanged(); + mRecyclerView.setAdapter(adapter); + noDataFollowers.setVisibility(View.VISIBLE); + } + + mProgressBar.setVisibility(View.GONE); }); } diff --git a/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowingFragment.java b/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowingFragment.java index 8450fb89..7095e096 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowingFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/ProfileFollowingFragment.java @@ -10,21 +10,17 @@ import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; -import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import org.gitnex.tea4j.models.UserInfo; import org.mian.gitnex.adapters.ProfileFollowingAdapter; import org.mian.gitnex.databinding.FragmentProfileFollowingBinding; import org.mian.gitnex.helpers.Authorization; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.viewmodels.ProfileFollowingViewModel; -import java.util.List; /** * Author M M Arif @@ -78,11 +74,10 @@ public class ProfileFollowingFragment extends Fragment { noDataFollowing = fragmentProfileFollowingBinding.noDataFollowing; mRecyclerView = fragmentProfileFollowingBinding.recyclerView; - mRecyclerView.setHasFixedSize(true); - mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), - DividerItemDecoration.VERTICAL); + mRecyclerView.setHasFixedSize(true); + mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mRecyclerView.addItemDecoration(dividerItemDecoration); mProgressBar = fragmentProfileFollowingBinding.progressBar; @@ -103,21 +98,21 @@ public class ProfileFollowingFragment extends Fragment { ProfileFollowingViewModel pfModel = new ViewModelProvider(this).get(ProfileFollowingViewModel.class); - pfModel.getFollowingList(instanceToken, getContext()).observe(getViewLifecycleOwner(), new Observer>() { - @Override - public void onChanged(@Nullable List pfListMain) { - adapter = new ProfileFollowingAdapter(getContext(), pfListMain); - if(adapter.getItemCount() > 0) { - mRecyclerView.setAdapter(adapter); - noDataFollowing.setVisibility(View.GONE); - } - else { - adapter.notifyDataSetChanged(); - mRecyclerView.setAdapter(adapter); - noDataFollowing.setVisibility(View.VISIBLE); - } - mProgressBar.setVisibility(View.GONE); + pfModel.getFollowingList(instanceToken, getContext()).observe(getViewLifecycleOwner(), pfListMain -> { + + adapter = new ProfileFollowingAdapter(getContext(), pfListMain); + + if(adapter.getItemCount() > 0) { + mRecyclerView.setAdapter(adapter); + noDataFollowing.setVisibility(View.GONE); } + else { + adapter.notifyDataSetChanged(); + mRecyclerView.setAdapter(adapter); + noDataFollowing.setVisibility(View.VISIBLE); + } + + mProgressBar.setVisibility(View.GONE); }); } diff --git a/app/src/main/java/org/mian/gitnex/fragments/ProfileFragment.java b/app/src/main/java/org/mian/gitnex/fragments/ProfileFragment.java index d6c45a00..4df62072 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/ProfileFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/ProfileFragment.java @@ -83,9 +83,11 @@ public class ProfileFragment extends Fragment { userFullName.setText(Html.fromHtml(tinyDb.getString("userFullname"))); userLogin.setText(getString(R.string.usernameWithAt, tinyDb.getString("userLogin"))); + int avatarRadius = AppUtil.getPixelsFromDensity(ctx, 3); + PicassoService.getInstance(ctx).get() .load(tinyDb.getString("userAvatar")) - .transform(new RoundedTransformation(8, 0)) + .transform(new RoundedTransformation(avatarRadius, 0)) .placeholder(R.drawable.loader_animated) .resize(120, 120) .centerCrop().into(userAvatar); diff --git a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java index ec0274a1..8d824157 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java @@ -40,8 +40,8 @@ public class RepoInfoFragment extends Fragment { private Context ctx; private LinearLayout pageContent; - private static String repoNameF = "param2"; - private static String repoOwnerF = "param1"; + private static final String repoNameF = "param2"; + private static final String repoOwnerF = "param1"; private FragmentRepoInfoBinding binding; @@ -284,6 +284,13 @@ public class RepoInfoFragment extends Fragment { tinyDb.putBoolean("hasPullRequests", false); } + if(repoInfo.isArchived()) { + binding.repoIsArchived.setVisibility(View.VISIBLE); + } + else { + binding.repoIsArchived.setVisibility(View.GONE); + } + tinyDb.putString("repoHtmlUrl", repoInfo.getHtml_url()); binding.progressBar.setVisibility(View.GONE); diff --git a/app/src/main/java/org/mian/gitnex/helpers/Markdown.java b/app/src/main/java/org/mian/gitnex/helpers/Markdown.java index 067e0b96..986661c7 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/Markdown.java +++ b/app/src/main/java/org/mian/gitnex/helpers/Markdown.java @@ -45,7 +45,7 @@ public class Markdown { private static final int MAX_POOL_SIZE = 45; private static final int MAX_THREAD_KEEP_ALIVE_SECONDS = 120; - private static final int MAX_CLAIM_TIMEOUT_SECONDS = 5; + private static final int MAX_CLAIM_TIMEOUT_SECONDS = 120; private static final Timeout timeout = new Timeout(MAX_CLAIM_TIMEOUT_SECONDS, TimeUnit.SECONDS); diff --git a/app/src/main/res/drawable/shape_files_diffs.xml b/app/src/main/res/drawable/shape_files_diffs.xml new file mode 100644 index 00000000..e1b20bb8 --- /dev/null +++ b/app/src/main/res/drawable/shape_files_diffs.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/app/src/main/res/layout/activity_issue_detail.xml b/app/src/main/res/layout/activity_issue_detail.xml index 297b5e5b..91defef7 100644 --- a/app/src/main/res/layout/activity_issue_detail.xml +++ b/app/src/main/res/layout/activity_issue_detail.xml @@ -96,9 +96,9 @@ + android:textSize="16sp" /> + android:textSize="14sp" /> + android:textSize="12sp" /> diff --git a/app/src/main/res/layout/bottom_sheet_repository_in_list.xml b/app/src/main/res/layout/bottom_sheet_repository_in_list.xml deleted file mode 100644 index bd3ddd38..00000000 --- a/app/src/main/res/layout/bottom_sheet_repository_in_list.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/credits.xml b/app/src/main/res/layout/credits.xml deleted file mode 100644 index 00f39d97..00000000 --- a/app/src/main/res/layout/credits.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/custom_user_accounts_dialog.xml b/app/src/main/res/layout/custom_user_accounts_dialog.xml index 873444ff..97110672 100644 --- a/app/src/main/res/layout/custom_user_accounts_dialog.xml +++ b/app/src/main/res/layout/custom_user_accounts_dialog.xml @@ -9,13 +9,13 @@ + android:layout_height="wrap_content" + android:padding="16dp" /> diff --git a/app/src/main/res/layout/custom_user_accounts_list.xml b/app/src/main/res/layout/custom_user_accounts_list.xml index 4809bf39..989a37ff 100644 --- a/app/src/main/res/layout/custom_user_accounts_list.xml +++ b/app/src/main/res/layout/custom_user_accounts_list.xml @@ -1,60 +1,62 @@ - + android:gravity="center_vertical" + android:orientation="horizontal" + android:padding="8dp"> + android:layout_width="@dimen/list_avatar_size" + android:layout_height="@dimen/list_avatar_size" + android:layout_marginEnd="10dp" + android:contentDescription="@string/generalImgContentText" + android:visibility="visible" /> + android:orientation="vertical"> + + + + + + + + - - + android:textSize="14sp" /> - - - + diff --git a/app/src/main/res/layout/fragment_drafts.xml b/app/src/main/res/layout/fragment_drafts.xml index c44508c6..4a4cb6fb 100644 --- a/app/src/main/res/layout/fragment_drafts.xml +++ b/app/src/main/res/layout/fragment_drafts.xml @@ -16,7 +16,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/primaryBackgroundColor" - android:padding="4dp" android:scrollbars="vertical" /> @@ -25,7 +24,7 @@ android:id="@+id/noData" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_margin="15dp" + android:layout_margin="16dp" android:text="@string/draftsListEmpty" android:textColor="?attr/primaryTextColor" android:gravity="center" diff --git a/app/src/main/res/layout/fragment_repo_info.xml b/app/src/main/res/layout/fragment_repo_info.xml index ada90506..d34a5831 100644 --- a/app/src/main/res/layout/fragment_repo_info.xml +++ b/app/src/main/res/layout/fragment_repo_info.xml @@ -57,6 +57,18 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + @@ -43,28 +43,28 @@ android:id="@+id/userFullName" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginBottom="5dp" + android:layout_marginBottom="4dp" android:text="@string/userName" android:textColor="?attr/primaryTextColor" - android:textSize="16sp" /> + android:textSize="14sp" + android:textStyle="bold" /> + android:textSize="12sp" /> + android:textSize="12sp" /> diff --git a/app/src/main/res/layout/list_collaborators_search.xml b/app/src/main/res/layout/list_collaborators_search.xml index 574197c0..c6529f32 100644 --- a/app/src/main/res/layout/list_collaborators_search.xml +++ b/app/src/main/res/layout/list_collaborators_search.xml @@ -8,17 +8,11 @@ android:paddingEnd="20dp" android:background="?attr/primaryBackgroundColor" > - - @@ -36,7 +30,8 @@ android:layout_marginBottom="5dp" android:text="@string/userName" android:textColor="?attr/primaryTextColor" - android:textSize="16sp" /> + android:textSize="14sp" + android:textStyle="bold" /> + android:textSize="12sp" /> - - + android:orientation="vertical"> @@ -42,7 +43,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/sizeCopy" - android:textColor="?attr/primaryTextColor" + android:textColor="?attr/hintColor" android:textSize="12sp" android:visibility="gone" tools:visibility="visible" /> diff --git a/app/src/main/res/layout/list_files_diffs.xml b/app/src/main/res/layout/list_files_diffs.xml index c18429c9..22e1b3ea 100644 --- a/app/src/main/res/layout/list_files_diffs.xml +++ b/app/src/main/res/layout/list_files_diffs.xml @@ -1,7 +1,6 @@ @@ -10,7 +9,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/header" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="?attr/primaryBackgroundColor" + android:background="@drawable/shape_files_diffs" android:orientation="vertical" android:paddingLeft="15dp" android:paddingTop="7dp" @@ -24,7 +23,7 @@ xmlns:tools="http://schemas.android.com/tools" android:ellipsize="start" android:fontFamily="monospace" android:singleLine="true" - android:textColor="?attr/primaryTextColor" + android:textColor="@color/colorWhite" android:textSize="16sp" /> @@ -83,7 +82,8 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitXY" - android:visibility="gone" /> + android:visibility="gone" + android:contentDescription="@string/generalImgContentText" /> @@ -38,7 +38,7 @@ android:ellipsize="middle" android:singleLine="true" android:textColor="?attr/primaryTextColor" - android:textSize="15sp" + android:textSize="14sp" android:textStyle="bold" /> + android:textSize="12sp" /> + android:textSize="14sp" /> diff --git a/app/src/main/res/layout/list_issues.xml b/app/src/main/res/layout/list_issues.xml index 09dfead1..4cc3ceeb 100644 --- a/app/src/main/res/layout/list_issues.xml +++ b/app/src/main/res/layout/list_issues.xml @@ -1,86 +1,95 @@ - - - + android:background="?android:attr/selectableItemBackground" + android:focusable="true"> + android:layout_marginBottom="8dp" + android:orientation="horizontal" + tools:ignore="UseCompoundDrawables"> + + + + + + + + + + + android:layout_gravity="end" + android:layout_marginStart="10dp" + android:layout_marginEnd="6dp" + android:layout_weight="1" + android:gravity="end" + android:orientation="horizontal" + android:paddingLeft="5dp" + android:paddingRight="5dp" + tools:ignore="UseCompoundDrawables"> + + - - - - - - - - - - - - + android:textSize="14sp" + tools:text="50" /> - + diff --git a/app/src/main/res/layout/list_labels.xml b/app/src/main/res/layout/list_labels.xml index 2aeee088..496e342f 100644 --- a/app/src/main/res/layout/list_labels.xml +++ b/app/src/main/res/layout/list_labels.xml @@ -6,28 +6,7 @@ android:layout_height="wrap_content" android:background="?attr/primaryBackgroundColor" android:orientation="horizontal" - android:padding="10dp"> - - - - - - + android:padding="16dp"> @@ -79,7 +58,8 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical|end" android:contentDescription="@string/labelMenuContentDesc" - android:paddingLeft="10dp" + android:paddingStart="10dp" + android:paddingEnd="0dp" android:src="@drawable/ic_dotted_menu_horizontal" /> diff --git a/app/src/main/res/layout/list_milestones.xml b/app/src/main/res/layout/list_milestones.xml index 313e59e3..ec2ff429 100644 --- a/app/src/main/res/layout/list_milestones.xml +++ b/app/src/main/res/layout/list_milestones.xml @@ -7,27 +7,14 @@ android:layout_height="wrap_content" android:id="@+id/milestoneFrame" android:background="?attr/primaryBackgroundColor" + android:padding="16dp" android:orientation="vertical"> - - - - + android:textSize="16sp" /> + android:orientation="horizontal" + tools:ignore="UseCompoundDrawables"> + android:orientation="horizontal" + tools:ignore="UseCompoundDrawables"> + android:orientation="horizontal" + tools:ignore="UseCompoundDrawables"> + android:orientation="horizontal"> - + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:orientation="vertical" + android:padding="16dp"> - - - + android:layout_marginBottom="8dp" + android:gravity="center_vertical" + android:orientation="horizontal" + tools:ignore="UseCompoundDrawables"> + android:layout_width="@dimen/list_avatar_size" + android:layout_height="@dimen/list_avatar_size" + android:layout_marginStart="0dp" + android:layout_marginEnd="10dp" + android:contentDescription="@string/repoContentAvatar" + android:src="@drawable/ic_android" /> - + android:textColor="?attr/primaryTextColor" + android:textSize="14sp" + tools:text="@string/orgName" /> - + - + - - - - - + diff --git a/app/src/main/res/layout/list_pr.xml b/app/src/main/res/layout/list_pr.xml index a7f49b8d..9c4014c9 100644 --- a/app/src/main/res/layout/list_pr.xml +++ b/app/src/main/res/layout/list_pr.xml @@ -1,81 +1,88 @@ - - - + android:background="?android:attr/selectableItemBackground" + android:focusable="true"> + android:layout_marginBottom="8dp" + android:orientation="horizontal" + tools:ignore="UseCompoundDrawables"> + + + + + + + + + + + android:layout_gravity="end" + android:layout_marginStart="10dp" + android:layout_marginEnd="6dp" + android:layout_weight="1" + android:gravity="end" + android:orientation="horizontal" + android:paddingLeft="5dp" + android:paddingRight="5dp" + tools:ignore="UseCompoundDrawables"> + + - - - - - - - - - - - - @@ -83,4 +90,4 @@ - + diff --git a/app/src/main/res/layout/list_profile_emails.xml b/app/src/main/res/layout/list_profile_emails.xml index cd41d14a..107721df 100644 --- a/app/src/main/res/layout/list_profile_emails.xml +++ b/app/src/main/res/layout/list_profile_emails.xml @@ -1,10 +1,12 @@ - + android:gravity="center_vertical" + android:orientation="horizontal" + android:padding="16dp" + tools:ignore="UseCompoundDrawables"> + tools:src="@drawable/ic_verified_user" /> - + diff --git a/app/src/main/res/layout/list_profile_followers.xml b/app/src/main/res/layout/list_profile_followers.xml index 1ada0008..e00b9c1a 100644 --- a/app/src/main/res/layout/list_profile_followers.xml +++ b/app/src/main/res/layout/list_profile_followers.xml @@ -1,16 +1,15 @@ - + android:gravity="center_vertical" + android:padding="16dp"> @@ -18,7 +17,6 @@ android:id="@+id/userInfoSection" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_toEndOf="@+id/userAvatar" android:orientation="vertical"> + android:textSize="16sp" + android:textStyle="bold" /> - + diff --git a/app/src/main/res/layout/list_profile_following.xml b/app/src/main/res/layout/list_profile_following.xml index 1ada0008..e00b9c1a 100644 --- a/app/src/main/res/layout/list_profile_following.xml +++ b/app/src/main/res/layout/list_profile_following.xml @@ -1,16 +1,15 @@ - + android:gravity="center_vertical" + android:padding="16dp"> @@ -18,7 +17,6 @@ android:id="@+id/userInfoSection" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_toEndOf="@+id/userAvatar" android:orientation="vertical"> + android:textSize="16sp" + android:textStyle="bold" /> - + diff --git a/app/src/main/res/layout/list_releases.xml b/app/src/main/res/layout/list_releases.xml index bd64265e..3c3dd394 100644 --- a/app/src/main/res/layout/list_releases.xml +++ b/app/src/main/res/layout/list_releases.xml @@ -5,7 +5,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:padding="15dp"> + android:padding="16dp"> @@ -207,45 +207,71 @@ - - + tools:ignore="UseCompoundDrawables"> - + + + + + + + tools:ignore="UseCompoundDrawables"> + + + + + + - + diff --git a/app/src/main/res/layout/list_releases_downloads.xml b/app/src/main/res/layout/list_releases_downloads.xml index 851e4dc2..0a8a0cc5 100644 --- a/app/src/main/res/layout/list_releases_downloads.xml +++ b/app/src/main/res/layout/list_releases_downloads.xml @@ -10,8 +10,8 @@ tools:ignore="UseCompoundDrawables"> @@ -21,7 +21,7 @@ android:layout_height="wrap_content" android:layout_marginStart="8dp" android:textColor="?attr/primaryTextColor" - android:textSize="14sp" + android:textSize="12sp" tools:text="Source code (ZIP)" /> diff --git a/app/src/main/res/layout/list_repositories.xml b/app/src/main/res/layout/list_repositories.xml index 498c5785..13548e8d 100644 --- a/app/src/main/res/layout/list_repositories.xml +++ b/app/src/main/res/layout/list_repositories.xml @@ -1,194 +1,132 @@ - + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:orientation="vertical" + android:padding="16dp"> - - - - - - - + android:buttonTint="#FFFFFF" + android:checked="false" + android:visibility="gone" /> + + - + android:textColor="?attr/primaryTextColor" + android:textSize="14sp" + tools:text="@string/orgName" /> - + - + - + - + - - + - + - + + android:textSize="14sp" + tools:text="@string/repoStars" /> + + - - - - - - - - - - - - - - + android:textSize="14sp" + android:visibility="gone" + tools:text="Java" /> - + - + diff --git a/app/src/main/res/layout/list_teams_by_org.xml b/app/src/main/res/layout/list_teams_by_org.xml index 4228fbe8..b7ee6d62 100644 --- a/app/src/main/res/layout/list_teams_by_org.xml +++ b/app/src/main/res/layout/list_teams_by_org.xml @@ -1,23 +1,11 @@ - - - - - + android:background="?attr/primaryBackgroundColor" + xmlns:android="http://schemas.android.com/apk/res/android"> - - - - + diff --git a/app/src/main/res/layout/list_user_accounts.xml b/app/src/main/res/layout/list_user_accounts.xml index c0d60f4e..4b235af9 100644 --- a/app/src/main/res/layout/list_user_accounts.xml +++ b/app/src/main/res/layout/list_user_accounts.xml @@ -1,68 +1,73 @@ - + android:gravity="center_vertical" + android:orientation="horizontal" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:padding="16dp"> + android:layout_width="@dimen/list_avatar_size" + android:layout_height="@dimen/list_avatar_size" + android:layout_marginEnd="10dp" + android:contentDescription="@string/generalImgContentText" + android:visibility="visible" /> + android:orientation="vertical"> + + + + + + + + + + - - - - + android:textSize="14sp" /> - - - + diff --git a/app/src/main/res/layout/nav_header.xml b/app/src/main/res/layout/nav_header.xml index c607d16a..d132589a 100644 --- a/app/src/main/res/layout/nav_header.xml +++ b/app/src/main/res/layout/nav_header.xml @@ -1,5 +1,5 @@ - + android:padding="20dp"> - + android:orientation="horizontal"> + + + + + + + - - - + diff --git a/app/src/main/res/layout/nav_user_accounts.xml b/app/src/main/res/layout/nav_user_accounts.xml index 92340731..23d6cac6 100644 --- a/app/src/main/res/layout/nav_user_accounts.xml +++ b/app/src/main/res/layout/nav_user_accounts.xml @@ -1,8 +1,8 @@ - - - - - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index cc52fe7b..ef6bf313 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -2,4 +2,6 @@ 5dp 26dp 15dp + + 24dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0e9ff6e5..7a5401f5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -646,6 +646,7 @@ App version, build, user gitea version Archived + This repo is archived. You can view files, but cannot push or open issues/pull-requests. Account deleted successfully Remove Account @@ -754,4 +755,5 @@ Download manager Indicates the progress of ongoing downloads + Updated %s From d72f0970129daa4627ae1ab65a31faa188b45342 Mon Sep 17 00:00:00 2001 From: opyale Date: Tue, 13 Apr 2021 20:56:50 +0200 Subject: [PATCH 2/2] 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 Co-Authored-By: opyale Co-Committed-By: opyale --- .../activities/AddNewAccountActivity.java | 12 +- .../gitnex/activities/DeepLinksActivity.java | 18 ++- .../mian/gitnex/activities/LoginActivity.java | 21 ++-- .../mian/gitnex/activities/MainActivity.java | 97 +++++--------- .../RepositorySettingsActivity.java | 7 +- .../SettingsNotificationsActivity.java | 8 +- .../mian/gitnex/adapters/DraftsAdapter.java | 5 +- .../adapters/ExploreRepositoriesAdapter.java | 3 +- .../gitnex/adapters/MyReposListAdapter.java | 3 +- .../gitnex/adapters/NotificationsAdapter.java | 11 +- .../gitnex/adapters/RepoForksAdapter.java | 3 +- .../gitnex/adapters/ReposListAdapter.java | 3 +- .../adapters/RepositoriesByOrgAdapter.java | 3 +- .../gitnex/adapters/SearchIssuesAdapter.java | 3 +- .../adapters/StarredReposListAdapter.java | 3 +- .../gitnex/adapters/UserAccountsAdapter.java | 17 +-- .../adapters/UserAccountsNavAdapter.java | 18 +-- .../org/mian/gitnex/core/MainApplication.java | 32 +++-- .../org/mian/gitnex/database/api/BaseApi.java | 57 +++++++++ .../mian/gitnex/database/api/DraftsApi.java | 82 +++--------- .../gitnex/database/api/RepositoriesApi.java | 105 +++------------- .../gitnex/database/api/UserAccountsApi.java | 107 ++++------------ .../gitnex/database/dao/UserAccountsDao.java | 19 +-- .../gitnex/database/db/GitnexDatabase.java | 39 +++--- .../fragments/BottomSheetReplyFragment.java | 5 +- .../mian/gitnex/fragments/DraftsFragment.java | 5 +- .../fragments/RepositoriesFragment.java | 3 +- .../fragments/UserAccountsFragment.java | 3 +- .../java/org/mian/gitnex/helpers/AppUtil.java | 38 ++++-- .../mian/gitnex/helpers/Authorization.java | 6 +- .../org/mian/gitnex/helpers/Constants.java | 5 + .../java/org/mian/gitnex/helpers/Version.java | 2 +- .../helpers/highlightjs/HighlightJsView.java | 0 .../helpers/views/SyntaxHighlightedArea.java | 74 +++++++---- .../gitnex/notifications/Notifications.java | 58 +++------ .../notifications/NotificationsWorker.java | 118 +++++++++++------- ...ctivity_add_collaborator_to_repository.xml | 3 + .../layout/activity_add_new_team_member.xml | 3 + .../res/layout/activity_admin_cron_tasks.xml | 3 + .../res/layout/activity_admin_get_users.xml | 3 + app/src/main/res/layout/activity_commits.xml | 3 + .../main/res/layout/activity_create_file.xml | 3 + .../main/res/layout/activity_create_issue.xml | 3 + .../main/res/layout/activity_create_label.xml | 3 + .../res/layout/activity_create_milestone.xml | 3 + .../res/layout/activity_create_new_user.xml | 3 + .../layout/activity_create_organization.xml | 3 + .../main/res/layout/activity_create_pr.xml | 3 + .../res/layout/activity_create_release.xml | 3 + .../main/res/layout/activity_create_repo.xml | 3 + .../layout/activity_create_team_by_org.xml | 3 + .../main/res/layout/activity_edit_issue.xml | 3 + .../main/res/layout/activity_file_diff.xml | 3 + .../main/res/layout/activity_file_view.xml | 3 + .../layout/activity_merge_pull_request.xml | 3 + .../res/layout/activity_org_team_members.xml | 3 + .../res/layout/activity_profile_email.xml | 3 + .../main/res/layout/activity_repo_forks.xml | 3 + .../res/layout/activity_repo_stargazers.xml | 3 + .../res/layout/activity_repo_watchers.xml | 3 + .../layout/activity_repository_settings.xml | 59 +++++---- .../layout/activity_settings_appearance.xml | 80 +++++++----- .../res/layout/activity_settings_drafts.xml | 41 +++--- .../res/layout/activity_settings_general.xml | 58 +++++---- .../activity_settings_notifications.xml | 101 ++++++++------- .../res/layout/activity_settings_reports.xml | 36 +++--- .../res/layout/activity_settings_security.xml | 101 ++++++++------- .../layout/activity_settings_translation.xml | 33 +++-- .../res/layout/bottom_sheet_admin_users.xml | 11 +- .../main/res/layout/bottom_sheet_drafts.xml | 11 +- .../res/layout/bottom_sheet_file_viewer.xml | 17 ++- .../layout/bottom_sheet_issue_comments.xml | 42 +++++-- .../res/layout/bottom_sheet_issues_filter.xml | 14 ++- .../layout/bottom_sheet_labels_in_list.xml | 16 ++- .../layout/bottom_sheet_milestones_filter.xml | 14 ++- .../bottom_sheet_milestones_in_list.xml | 14 ++- .../res/layout/bottom_sheet_notifications.xml | 21 +++- .../bottom_sheet_notifications_filter.xml | 14 ++- .../res/layout/bottom_sheet_organization.xml | 28 +++-- .../bottom_sheet_organization_teams.xml | 7 +- .../main/res/layout/bottom_sheet_profile.xml | 7 +- .../bottom_sheet_pull_request_filter.xml | 14 ++- .../res/layout/bottom_sheet_reply_layout.xml | 8 +- app/src/main/res/layout/bottom_sheet_repo.xml | 85 ++++++++++--- .../res/layout/bottom_sheet_single_issue.xml | 81 ++++++++---- app/src/main/res/layout/fragment_profile.xml | 11 +- .../main/res/layout/fragment_repo_info.xml | 12 ++ app/src/main/res/layout/fragment_settings.xml | 76 ++++++++--- app/src/main/res/values-ar/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fa/strings.xml | 2 +- app/src/main/res/values-fi/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 6 +- app/src/main/res/values-lv/strings.xml | 2 +- app/src/main/res/values-pl/strings.xml | 2 +- app/src/main/res/values-pt/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values-sr/strings.xml | 2 +- app/src/main/res/values-tr/strings.xml | 2 +- app/src/main/res/values-uk/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 2 +- app/src/main/res/values/themes.xml | 2 +- gradle.properties | 1 + 108 files changed, 1211 insertions(+), 908 deletions(-) create mode 100644 app/src/main/java/org/mian/gitnex/database/api/BaseApi.java delete mode 100644 app/src/main/java/org/mian/gitnex/helpers/highlightjs/HighlightJsView.java diff --git a/app/src/main/java/org/mian/gitnex/activities/AddNewAccountActivity.java b/app/src/main/java/org/mian/gitnex/activities/AddNewAccountActivity.java index 016e1002..8724df32 100644 --- a/app/src/main/java/org/mian/gitnex/activities/AddNewAccountActivity.java +++ b/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 callVersion; - callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken("token " + loginToken); - callVersion.enqueue(new Callback() { @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 { diff --git a/app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java b/app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java index 42be2a54..8e0a85bd 100644 --- a/app/src/main/java/org/mian/gitnex/activities/DeepLinksActivity.java +++ b/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 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); diff --git a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java b/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java index 4c3698cd..2f86521b 100644 --- a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java +++ b/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()); } diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index 29e8565f..37dc223a 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/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,38 +90,25 @@ 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"); + + // DO NOT MOVE + if(mainIntent.hasExtra("switchAccountId") && + AppUtil.switchToAccount(ctx, BaseApi.getInstance(ctx, UserAccountsApi.class) + .getAccountById(mainIntent.getIntExtra("switchAccountId", 0)))) { + + mainIntent.removeExtra("switchAccountId"); + recreate(); + return; + + } + // DO NOT MOVE + + tinyDB.putBoolean("noConnection", false); loginUid = tinyDB.getString("loginUid"); instanceToken = "token " + tinyDB.getString(loginUid + "-token"); - 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); - } - boolean connToInternet = AppUtil.hasNetworkConnection(appCtx); if(!tinyDB.getBoolean("loggedInMode")) { @@ -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 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 callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken(token); - + Call callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken(Authorization.get(ctx)); callVersion.enqueue(new Callback() { @Override public void onResponse(@NonNull final Call callVersion, @NonNull retrofit2.Response responseVersion) { - if(responseVersion.code() == 200) { + if(responseVersion.code() == 200 && responseVersion.body() != null) { + String version = responseVersion.body().getVersion(); - GiteaVersion version = responseVersion.body(); - assert version != null; - - 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 callVersion, @NonNull Throwable t) { - Log.e("onFailure-version", t.toString()); } }); diff --git a/app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java b/app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java index 54e62e0d..1d5abfb6 100644 --- a/app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java +++ b/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); } diff --git a/app/src/main/java/org/mian/gitnex/activities/SettingsNotificationsActivity.java b/app/src/main/java/org/mian/gitnex/activities/SettingsNotificationsActivity.java index 1c378fd5..01d59a9c 100644 --- a/app/src/main/java/org/mian/gitnex/activities/SettingsNotificationsActivity.java +++ b/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)); }); diff --git a/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java index f054c635..36374a24 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/DraftsAdapter.java +++ b/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 { diff --git a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java index 88699632..8dc78c31 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java +++ b/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 { 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 { - 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(); - } + } }); } diff --git a/app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java index 7db88c76..c315ff41 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/UserAccountsNavAdapter.java +++ b/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 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 { - 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(); } diff --git a/app/src/main/java/org/mian/gitnex/core/MainApplication.java b/app/src/main/java/org/mian/gitnex/core/MainApplication.java index 5fd91d2c..cb921174 100644 --- a/app/src/main/java/org/mian/gitnex/core/MainApplication.java +++ b/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); + } + } } diff --git a/app/src/main/java/org/mian/gitnex/database/api/BaseApi.java b/app/src/main/java/org/mian/gitnex/database/api/BaseApi.java new file mode 100644 index 00000000..ac5beaa8 --- /dev/null +++ b/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, 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 getInstance(@NonNull Context context, @NonNull Class 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; + } + +} diff --git a/app/src/main/java/org/mian/gitnex/database/api/DraftsApi.java b/app/src/main/java/org/mian/gitnex/database/api/DraftsApi.java index 8a4307f0..24b8b688 100644 --- a/app/src/main/java/org/mian/gitnex/database/api/DraftsApi.java +++ b/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> getDrafts(int accountId) { - return draftsDao.fetchAllDrafts(accountId); } public LiveData getDraftByIssueId(int issueId) { - return draftsDao.fetchDraftByIssueId(issueId); } public void deleteSingleDraft(final int draftId) { - final LiveData 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)); } } diff --git a/app/src/main/java/org/mian/gitnex/database/api/RepositoriesApi.java b/app/src/main/java/org/mian/gitnex/database/api/RepositoriesApi.java index ef5e1f5d..effc415d 100644 --- a/app/src/main/java/org/mian/gitnex/database/api/RepositoriesApi.java +++ b/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> getAllRepositories() { - return repositoriesDao.fetchAllRepositories(); } public LiveData> 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)); } } diff --git a/app/src/main/java/org/mian/gitnex/database/api/UserAccountsApi.java b/app/src/main/java/org/mian/gitnex/database/api/UserAccountsApi.java index 482da27b..80b5d920 100644 --- a/app/src/main/java/org/mian/gitnex/database/api/UserAccountsApi.java +++ b/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 userAccounts; - private static Integer checkAccount; - private static long accountId; + private final UserAccountsDao userAccountsDao; - public UserAccountsApi(Context context) { - - GitnexDatabase db; - db = GitnexDatabase.getDatabaseInstance(context); - userAccountsDao = db.userAccountsDao(); + UserAccountsApi(Context context) { + super(context); + userAccountsDao = gitnexDatabase.userAccountsDao(); } - public long insertNewAccount(String accountName, String instanceUrl, String userName, String token, String serverVersion) { + public long createNewAccount(String accountName, String instanceUrl, String userName, String token, String serverVersion) { UserAccount userAccount = new UserAccount(); userAccount.setAccountName(accountName); @@ -37,96 +28,48 @@ public class UserAccountsApi { userAccount.setToken(token); userAccount.setServerVersion(serverVersion); - return insertNewAccountAsync(userAccount); + return userAccountsDao.createAccount(userAccount); + } - private static long insertNewAccountAsync(final UserAccount userAccount) { - - try { - - Thread thread = new Thread(() -> accountId = userAccountsDao.newAccount(userAccount)); - thread.start(); - thread.join(); - } - catch(InterruptedException e) { - - Log.e(Constants.userAccountsApi, e.toString()); - } - - return accountId; - } - - public static void updateServerVersion(final String serverVersion, final int accountId) { - - new Thread(() -> userAccountsDao.updateServerVersion(serverVersion, accountId)).start(); + public void updateServerVersion(final String serverVersion, final int accountId) { + executorService.execute(() -> userAccountsDao.updateServerVersion(serverVersion, accountId)); } public void updateToken(final int accountId, final String token) { - - new Thread(() -> userAccountsDao.updateAccountToken(accountId, token)).start(); + executorService.execute(() -> userAccountsDao.updateAccountToken(accountId, token)); } public void updateTokenByAccountName(final String accountName, final String token) { - - new Thread(() -> userAccountsDao.updateAccountTokenByAccountName(accountName, token)).start(); + executorService.execute(() -> userAccountsDao.updateAccountTokenByAccountName(accountName, token)); } - public UserAccount getAccountData(String accountName) { - - try { - - Thread thread = new Thread(() -> userAccount = userAccountsDao.fetchRowByAccount_(accountName)); - thread.start(); - thread.join(); - } - catch(InterruptedException e) { - - Log.e(Constants.userAccountsApi, e.toString()); - } - - return userAccount; + public UserAccount getAccountByName(String accountName) { + return userAccountsDao.getAccountByName(accountName); } - public Integer getCount(String accountName) { + public UserAccount getAccountById(int accountId) { + return userAccountsDao.getAccountById(accountId); + } - try { + public Integer getCount() { + return userAccountsDao.getCount(); + } - Thread thread = new Thread(() -> checkAccount = userAccountsDao.getCount(accountName)); - thread.start(); - thread.join(); - } - catch(InterruptedException e) { - - Log.e(Constants.userAccountsApi, e.toString()); - } - - return checkAccount; + public Boolean userAccountExists(String accountName) { + return userAccountsDao.userAccountExists(accountName); } public LiveData> getAllAccounts() { - - return userAccountsDao.fetchAllAccounts(); + return userAccountsDao.getAllAccounts(); } public List usersAccounts() { - - try { - - Thread thread = new Thread(() -> userAccounts = userAccountsDao.userAccounts()); - thread.start(); - thread.join(); - } - catch(InterruptedException e) { - - Log.e(Constants.userAccountsApi, e.toString()); - } - - return userAccounts; + return userAccountsDao.userAccounts(); } public void deleteAccount(final int accountId) { - - new Thread(() -> userAccountsDao.deleteAccount(accountId)).start(); + executorService.execute(() -> userAccountsDao.deleteAccount(accountId)); } } diff --git a/app/src/main/java/org/mian/gitnex/database/dao/UserAccountsDao.java b/app/src/main/java/org/mian/gitnex/database/dao/UserAccountsDao.java index 9abad2db..fd1e249b 100644 --- a/app/src/main/java/org/mian/gitnex/database/dao/UserAccountsDao.java +++ b/app/src/main/java/org/mian/gitnex/database/dao/UserAccountsDao.java @@ -15,22 +15,25 @@ import java.util.List; public interface UserAccountsDao { @Insert - long newAccount(UserAccount userAccounts); + long createAccount(UserAccount userAccounts); @Query("SELECT * FROM UserAccounts ORDER BY accountId ASC") - LiveData> fetchAllAccounts(); + LiveData> getAllAccounts(); @Query("SELECT * FROM UserAccounts ORDER BY accountId ASC") List userAccounts(); - @Query("SELECT COUNT(accountId) FROM UserAccounts WHERE accountName = :accountName") - Integer getCount(String accountName); + @Query("SELECT COUNT(accountId) FROM UserAccounts") + Integer getCount(); - @Query("SELECT * FROM UserAccounts WHERE accountName = :accountName") - UserAccount fetchRowByAccount_(String accountName); + @Query("SELECT COUNT(accountId) FROM UserAccounts WHERE accountName = :accountName LIMIT 1") + Boolean userAccountExists(String accountName); - @Query("SELECT * FROM UserAccounts WHERE accountId = :accountId") - UserAccount fetchRowByAccountId(int accountId); + @Query("SELECT * FROM UserAccounts WHERE accountName = :accountName LIMIT 1") + UserAccount getAccountByName(String accountName); + + @Query("SELECT * FROM UserAccounts WHERE accountId = :accountId LIMIT 1") + UserAccount getAccountById(int accountId); @Query("UPDATE UserAccounts SET serverVersion = :serverVersion WHERE accountId = :accountId") void updateServerVersion(String serverVersion, int accountId); diff --git a/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java b/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java index 3669d8ea..b0fa21ac 100644 --- a/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java +++ b/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java @@ -22,32 +22,16 @@ import org.mian.gitnex.database.models.UserAccount; version = 3, exportSchema = false) public abstract class GitnexDatabase extends RoomDatabase { + private static final String DB_NAME = "gitnex"; private static GitnexDatabase gitnexDatabase; - public static GitnexDatabase getDatabaseInstance(Context context) { - - if (gitnexDatabase == null) { - - String DB_NAME = "gitnex"; - gitnexDatabase = Room.databaseBuilder(context, GitnexDatabase.class, DB_NAME) - //.fallbackToDestructiveMigration() - .addMigrations(MIGRATION_1_2, MIGRATION_2_3) - .build(); - } - - return gitnexDatabase; - } - public abstract DraftsDao draftsDao(); - public abstract RepositoriesDao repositoriesDao(); - public abstract UserAccountsDao userAccountsDao(); private static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(@NonNull SupportSQLiteDatabase database) { - //database.execSQL("DROP TABLE Drafts"); database.execSQL("ALTER TABLE 'Drafts' ADD COLUMN 'commentId' TEXT"); } @@ -56,8 +40,27 @@ public abstract class GitnexDatabase extends RoomDatabase { private static final Migration MIGRATION_2_3 = new Migration(2, 3) { @Override public void migrate(@NonNull SupportSQLiteDatabase database) { - database.execSQL("ALTER TABLE 'Drafts' ADD COLUMN 'issueType' TEXT"); } }; + + public static GitnexDatabase getDatabaseInstance(Context context) { + + if (gitnexDatabase == null) { + synchronized(GitnexDatabase.class) { + if(gitnexDatabase == null) { + + gitnexDatabase = Room.databaseBuilder(context, GitnexDatabase.class, DB_NAME) + // .fallbackToDestructiveMigration() + .allowMainThreadQueries() + .addMigrations(MIGRATION_1_2, MIGRATION_2_3) + .build(); + + } + } + } + + return gitnexDatabase; + + } } diff --git a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java index 851075dd..7fc9a84a 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetReplyFragment.java @@ -24,6 +24,7 @@ import org.mian.gitnex.R; import org.mian.gitnex.actions.ActionResult; import org.mian.gitnex.actions.IssueActions; import org.mian.gitnex.activities.MainActivity; +import org.mian.gitnex.database.api.BaseApi; import org.mian.gitnex.database.api.DraftsApi; import org.mian.gitnex.databinding.BottomSheetReplyLayoutBinding; import org.mian.gitnex.helpers.Constants; @@ -57,7 +58,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment { super.onAttach(context); tinyDB = TinyDB.getInstance(context); - draftsApi = new DraftsApi(context); + draftsApi = BaseApi.getInstance(context, DraftsApi.class); repositoryId = (int) tinyDB.getLong("repositoryId", 0); currentActiveAccountId = tinyDB.getInt("currentActiveAccountId"); @@ -281,7 +282,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment { } else { - DraftsApi.updateDraft(text, (int) draftId, "TODO"); + draftsApi.updateDraft(text, (int) draftId, "TODO"); } draftsHint.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java b/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java index 6a63f49f..f53f6d1e 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java @@ -22,6 +22,7 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import org.mian.gitnex.R; import org.mian.gitnex.activities.MainActivity; import org.mian.gitnex.adapters.DraftsAdapter; +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.databinding.FragmentDraftsBinding; @@ -59,7 +60,7 @@ public class DraftsFragment extends Fragment { TinyDB tinyDb = TinyDB.getInstance(ctx); draftsList_ = new ArrayList<>(); - draftsApi = new DraftsApi(ctx); + draftsApi = BaseApi.getInstance(ctx, DraftsApi.class); noData = fragmentDraftsBinding.noData; mRecyclerView = fragmentDraftsBinding.recyclerView; @@ -123,7 +124,7 @@ public class DraftsFragment extends Fragment { if(draftsList_.size() > 0) { - DraftsApi.deleteAllDrafts(accountId); + BaseApi.getInstance(ctx, DraftsApi.class).deleteAllDrafts(accountId); draftsList_.clear(); adapter.notifyDataSetChanged(); Toasty.success(ctx, getResources().getString(R.string.draftsDeleteSuccess)); diff --git a/app/src/main/java/org/mian/gitnex/fragments/RepositoriesFragment.java b/app/src/main/java/org/mian/gitnex/fragments/RepositoriesFragment.java index d1eb44e5..7cf70021 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/RepositoriesFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/RepositoriesFragment.java @@ -63,8 +63,7 @@ public class RepositoriesFragment extends Fragment { mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), - DividerItemDecoration.VERTICAL); + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL); mRecyclerView.addItemDecoration(dividerItemDecoration); createNewRepo = fragmentRepositoriesBinding.addNewRepo; diff --git a/app/src/main/java/org/mian/gitnex/fragments/UserAccountsFragment.java b/app/src/main/java/org/mian/gitnex/fragments/UserAccountsFragment.java index b83985b0..4f13a352 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/UserAccountsFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/UserAccountsFragment.java @@ -18,6 +18,7 @@ import org.mian.gitnex.R; import org.mian.gitnex.activities.AddNewAccountActivity; import org.mian.gitnex.activities.MainActivity; import org.mian.gitnex.adapters.UserAccountsAdapter; +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.FragmentUserAccountsBinding; @@ -48,7 +49,7 @@ public class UserAccountsFragment extends Fragment { ((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.pageTitleUserAccounts)); userAccountsList = new ArrayList<>(); - userAccountsApi = new UserAccountsApi(ctx); + userAccountsApi = BaseApi.getInstance(ctx, UserAccountsApi.class); mRecyclerView = fragmentUserAccountsBinding.recyclerView; final SwipeRefreshLayout swipeRefresh = fragmentUserAccountsBinding.pullToRefresh; diff --git a/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java b/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java index 0a539feb..c714b294 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java +++ b/app/src/main/java/org/mian/gitnex/helpers/AppUtil.java @@ -13,6 +13,7 @@ import android.util.TypedValue; import android.view.View; import androidx.annotation.ColorInt; import androidx.core.content.pm.PackageInfoCompat; +import org.mian.gitnex.database.models.UserAccount; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -69,7 +70,6 @@ public class AppUtil { } public static boolean hasNetworkConnection(Context context) { - return NetworkStatusObserver.getInstance(context).hasNetworkConnection(); } @@ -274,32 +274,27 @@ public class AppUtil { } public static String getLastCharactersOfWord(String str, int count) { - return str.substring(str.length() - count); } public static void setMultiVisibility(int visibility, View... views) { - for(View view : views) { - view.setVisibility(visibility); } } public static int getPixelsFromDensity(Context context, int dp) { - return (int) (context.getResources().getDisplayMetrics().density * dp); } public static int getPixelsFromScaledDensity(Context context, int sp) { - return (int) (context.getResources().getDisplayMetrics().scaledDensity * sp); } - public static int getLineCount(String s) { + public static long getLineCount(String s) { - int lines = 0; + long lines = 0; Pattern pattern = Pattern.compile("(\r\n|\r|\n)"); Matcher matcher = pattern.matcher(s); @@ -307,6 +302,11 @@ public class AppUtil { while(matcher.find()) lines++; + // Sometimes there may be text, but no line breaks. + // This should still count as one line. + if(s.length() > 0 && lines == 0) + return 1; + return lines; } @@ -320,5 +320,27 @@ public class AppUtil { clipboard.setPrimaryClip(clip); Toasty.info(ctx, message); + } + + public static boolean switchToAccount(Context context, UserAccount userAccount) { + + TinyDB tinyDB = TinyDB.getInstance(context); + + if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) { + + 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()); + + return true; + + } + + return false; + + } + } diff --git a/app/src/main/java/org/mian/gitnex/helpers/Authorization.java b/app/src/main/java/org/mian/gitnex/helpers/Authorization.java index e97dd246..30cf1126 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/Authorization.java +++ b/app/src/main/java/org/mian/gitnex/helpers/Authorization.java @@ -1,6 +1,7 @@ package org.mian.gitnex.helpers; import android.content.Context; +import org.mian.gitnex.database.models.UserAccount; import okhttp3.Credentials; /** @@ -24,11 +25,14 @@ public class Authorization { } + public static String get(UserAccount userAccount) { + return "token " + userAccount.getToken(); + } + public static String getWeb(Context context) { TinyDB tinyDb = TinyDB.getInstance(context); return Credentials.basic("", tinyDb.getString(tinyDb.getString("loginUid") + "-token")); - } } diff --git a/app/src/main/java/org/mian/gitnex/helpers/Constants.java b/app/src/main/java/org/mian/gitnex/helpers/Constants.java index ddb0e23b..c9683935 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/Constants.java +++ b/app/src/main/java/org/mian/gitnex/helpers/Constants.java @@ -56,6 +56,11 @@ public class Constants { public static final String mainNotificationChannelId = "main_channel"; public static final String downloadNotificationChannelId = "dl_channel"; + public static final long[] defaultVibrationPattern = new long[] { 1000, 1000 }; + public static final String[] fallbackReactions = new String[]{"+1", "-1", "laugh", "hooray", "confused", "heart", "rocket", "eyes"}; + // work managers + public static final String notificationsWorkerId = "notifications_worker"; + } diff --git a/app/src/main/java/org/mian/gitnex/helpers/Version.java b/app/src/main/java/org/mian/gitnex/helpers/Version.java index 50bc6c4c..a6b1da91 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/Version.java +++ b/app/src/main/java/org/mian/gitnex/helpers/Version.java @@ -50,7 +50,7 @@ public class Version { final Pattern pattern_number_dot_number = Pattern.compile("^\\d+(\\.(\\d)+)*"); if(!valid(raw)) { - throw new IllegalArgumentException("Invalid version format"); + throw new IllegalArgumentException("Invalid version format: " + raw); } if(raw.charAt(0) == 'v' || raw.charAt(0) == 'V') { diff --git a/app/src/main/java/org/mian/gitnex/helpers/highlightjs/HighlightJsView.java b/app/src/main/java/org/mian/gitnex/helpers/highlightjs/HighlightJsView.java deleted file mode 100644 index e69de29b..00000000 diff --git a/app/src/main/java/org/mian/gitnex/helpers/views/SyntaxHighlightedArea.java b/app/src/main/java/org/mian/gitnex/helpers/views/SyntaxHighlightedArea.java index f7a65575..ff3c0e9b 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/views/SyntaxHighlightedArea.java +++ b/app/src/main/java/org/mian/gitnex/helpers/views/SyntaxHighlightedArea.java @@ -1,5 +1,6 @@ package org.mian.gitnex.helpers.views; +import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; @@ -36,19 +37,16 @@ public class SyntaxHighlightedArea extends LinearLayout { private LinesView linesView; public SyntaxHighlightedArea(@NonNull Context context) { - super(context); setup(); } public SyntaxHighlightedArea(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); setup(); } public SyntaxHighlightedArea(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); setup(); } @@ -62,9 +60,10 @@ public class SyntaxHighlightedArea extends LinearLayout { sourceView = new TextView(getContext()); sourceView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); - sourceView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); sourceView.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/sourcecodeproregular.ttf")); + sourceView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); sourceView.setTextColor(prism4jTheme.textColor()); + sourceView.setTextIsSelectable(true); int padding = AppUtil.getPixelsFromDensity(getContext(), 5); sourceView.setPadding(padding, 0, padding, 0); @@ -97,34 +96,57 @@ public class SyntaxHighlightedArea extends LinearLayout { public void setContent(@NonNull String source, @NonNull String extension) { if(source.length() > 0) { - linesView.setLineCount(AppUtil.getLineCount(source)); - try { + Thread highlightingThread = new Thread(() -> { - MainGrammarLocator mainGrammarLocator = MainGrammarLocator.getInstance(); - Prism4j prism4j = new Prism4j(mainGrammarLocator); + try { - CharSequence highlightedSource = Prism4jSyntaxHighlight.create(prism4j, prism4jTheme, MainGrammarLocator.DEFAULT_FALLBACK_LANGUAGE) - .highlight(mainGrammarLocator.fromExtension(extension), source); + MainGrammarLocator mainGrammarLocator = MainGrammarLocator.getInstance(); - if(highlightedSource.charAt(highlightedSource.length() - 1) == '\n') { - // Removes a line break which is probably added by Prism4j but not actually present in the source. - // This line should be altered in case this gets fixed. - sourceView.setText(highlightedSource.subSequence(0, highlightedSource.length() - 1)); - } - else { - sourceView.setText(highlightedSource); + CharSequence highlightedSource = Prism4jSyntaxHighlight + .create(new Prism4j(mainGrammarLocator), prism4jTheme, MainGrammarLocator.DEFAULT_FALLBACK_LANGUAGE) + .highlight(mainGrammarLocator.fromExtension(extension), source); + + getActivity().runOnUiThread(() -> { + if(highlightedSource.charAt(highlightedSource.length() - 1) == '\n') { + // Removes a line break which is probably added by Prism4j but not actually present in the source. + // This line should be altered in case this gets fixed. + sourceView.setText(highlightedSource.subSequence(0, highlightedSource.length() - 1)); + } else { + sourceView.setText(highlightedSource); + } + }); + + } catch(Throwable ignored) { + // Fall back to plaintext if something fails + getActivity().runOnUiThread(() -> sourceView.setText(source)); } - } catch(Throwable ignored) { - // Fall back to plaintext if something fails - sourceView.setText(source); - } + }); + + Thread lineCountingThread = new Thread(() -> { + + long lineCount = AppUtil.getLineCount(source); + + try { + highlightingThread.join(); + } catch(InterruptedException ignored) {} + + getActivity().runOnUiThread(() -> linesView.setLineCount(lineCount)); + + }); + + highlightingThread.start(); + lineCountingThread.start(); + } } - public String getContent() { + private Activity getActivity() { + return (Activity) getContext(); + } + public String getContent() { return sourceView.getText().toString(); } @@ -137,27 +159,31 @@ public class SyntaxHighlightedArea extends LinearLayout { @ColorInt private int textColor; @ColorInt private int lineColor; - private int lineCount; + private long lineCount; public LinesView(Context context) { super(context); } - public void setLineCount(int lineCount) { + public void setLineCount(long lineCount) { this.lineCount = lineCount; + requestLayout(); } @Override public void setBackgroundColor(@ColorInt int backgroundColor) { this.backgroundColor = backgroundColor; + invalidate(); } public void setTextColor(@ColorInt int textColor) { this.textColor = textColor; + invalidate(); } public void setLineColor(@ColorInt int lineColor) { this.lineColor = lineColor; + invalidate(); } public Paint getPaint() { diff --git a/app/src/main/java/org/mian/gitnex/notifications/Notifications.java b/app/src/main/java/org/mian/gitnex/notifications/Notifications.java index 68cb399c..cf03e691 100644 --- a/app/src/main/java/org/mian/gitnex/notifications/Notifications.java +++ b/app/src/main/java/org/mian/gitnex/notifications/Notifications.java @@ -13,7 +13,6 @@ import androidx.work.WorkManager; import org.mian.gitnex.R; import org.mian.gitnex.helpers.Constants; import org.mian.gitnex.helpers.TinyDB; -import org.mian.gitnex.helpers.Version; import java.util.concurrent.TimeUnit; /** @@ -22,8 +21,6 @@ import java.util.concurrent.TimeUnit; public class Notifications { - private static int notificationsSupported = -1; - public static int uniqueNotificationId(Context context) { TinyDB tinyDB = TinyDB.getInstance(context); @@ -51,7 +48,7 @@ public class Notifications { mainChannel.setDescription(context.getString(R.string.mainNotificationChannelDescription)); if(tinyDB.getBoolean("notificationsEnableVibration", true)) { - mainChannel.setVibrationPattern(new long[] { 1000, 1000 }); + mainChannel.setVibrationPattern(Constants.defaultVibrationPattern); mainChannel.enableVibration(true); } else { mainChannel.enableVibration(false); @@ -75,7 +72,7 @@ public class Notifications { public static void stopWorker(Context context) { - WorkManager.getInstance(context).cancelAllWorkByTag(context.getPackageName()); + WorkManager.getInstance(context).cancelAllWorkByTag(Constants.notificationsWorkerId); } public static void startWorker(Context context) { @@ -84,42 +81,25 @@ public class Notifications { if(tinyDB.getBoolean("notificationsEnabled", true)) { - if(notificationsSupported == -1) checkVersion(tinyDB); - - if(notificationsSupported == 1) { - - Constraints.Builder constraints = new Constraints.Builder() - .setRequiredNetworkType(NetworkType.CONNECTED) - .setRequiresBatteryNotLow(false) - .setRequiresStorageNotLow(false) - .setRequiresCharging(false); - - if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - - constraints.setRequiresDeviceIdle(false); - } - - int pollingDelayMinutes = Math.max(tinyDB.getInt("pollingDelayMinutes", Constants.defaultPollingDelay), 15); - - PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(NotificationsWorker.class, pollingDelayMinutes, TimeUnit.MINUTES) - .setConstraints(constraints.build()) - .addTag(context.getPackageName()) - .build(); - - WorkManager.getInstance(context).enqueueUniquePeriodicWork(context.getPackageName(), ExistingPeriodicWorkPolicy.KEEP, periodicWorkRequest); + Constraints.Builder constraints = new Constraints.Builder() + .setRequiredNetworkType(NetworkType.CONNECTED) + .setRequiresBatteryNotLow(false) + .setRequiresStorageNotLow(false) + .setRequiresCharging(false); + if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + constraints.setRequiresDeviceIdle(false); } + + int pollingDelayMinutes = Math.max(tinyDB.getInt("pollingDelayMinutes", Constants.defaultPollingDelay), 15); + + PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(NotificationsWorker.class, pollingDelayMinutes, TimeUnit.MINUTES) + .setConstraints(constraints.build()) + .addTag(Constants.notificationsWorkerId) + .build(); + + WorkManager.getInstance(context).enqueueUniquePeriodicWork(Constants.notificationsWorkerId, ExistingPeriodicWorkPolicy.KEEP, periodicWorkRequest); + } } - - private static void checkVersion(TinyDB tinyDB) { - - String currentVersion = tinyDB.getString("giteaVersion"); - - if(tinyDB.getBoolean("loggedInMode") && !currentVersion.isEmpty()) { - - notificationsSupported = new Version(currentVersion).higherOrEqual("1.12.3") ? 1 : 0; - } - } - } diff --git a/app/src/main/java/org/mian/gitnex/notifications/NotificationsWorker.java b/app/src/main/java/org/mian/gitnex/notifications/NotificationsWorker.java index cdf40405..f80a861e 100644 --- a/app/src/main/java/org/mian/gitnex/notifications/NotificationsWorker.java +++ b/app/src/main/java/org/mian/gitnex/notifications/NotificationsWorker.java @@ -15,12 +15,18 @@ import org.gitnex.tea4j.models.NotificationThread; import org.mian.gitnex.R; import org.mian.gitnex.activities.MainActivity; 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.helpers.AppUtil; import org.mian.gitnex.helpers.Authorization; import org.mian.gitnex.helpers.Constants; import org.mian.gitnex.helpers.TinyDB; +import org.mian.gitnex.helpers.Version; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import retrofit2.Call; import retrofit2.Response; @@ -30,86 +36,101 @@ import retrofit2.Response; public class NotificationsWorker extends Worker { - private static final int MAXIMUM_NOTIFICATIONS = 100; - private final Context context; private final TinyDB tinyDB; + private final Map> userAccounts; public NotificationsWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); + UserAccountsApi userAccountsApi = BaseApi.getInstance(context, UserAccountsApi.class); + this.context = context; this.tinyDB = TinyDB.getInstance(context); + this.userAccounts = new HashMap<>(userAccountsApi.getCount()); + for(UserAccount userAccount : userAccountsApi.usersAccounts()) { + + // We do also accept empty values, since the server version was not saved properly in the beginning. + if(userAccount.getServerVersion() == null || userAccount.getServerVersion().isEmpty() || + new Version(userAccount.getServerVersion()).higherOrEqual("1.12.3")) { + + Map userAccountParameters = new HashMap<>(); + userAccountParameters.put("previousTimestamp", AppUtil.getTimestampFromDate(context, new Date())); + + userAccounts.put(userAccount, userAccountParameters); + } + } } @NonNull @Override public Result doWork() { + pollingLoops(); + return Result.success(); + } - int notificationLoops = tinyDB.getInt("pollingDelayMinutes", Constants.defaultPollingDelay) >= 15 ? 1 : Math.min(15 - tinyDB.getInt("pollingDelayMinutes"), 10); + /** + * Used to bypass the 15-minute limit of {@code WorkManager}. + */ + private void pollingLoops() { + int notificationLoops = tinyDB.getInt("pollingDelayMinutes", Constants.defaultPollingDelay) < 15 ? + Math.min(15 - tinyDB.getInt("pollingDelayMinutes"), 10) : 1; for(int i = 0; i < notificationLoops; i++) { - long startPollingTime = System.currentTimeMillis(); - try { - - String previousRefreshTimestamp = tinyDB.getString("previousRefreshTimestamp", AppUtil.getTimestampFromDate(context, new Date())); - - Call> call = RetrofitClient - .getApiInterface(context) - .getNotificationThreads(Authorization.get(context), false, new String[]{"unread"}, previousRefreshTimestamp, - null, 1, MAXIMUM_NOTIFICATIONS); - - Response> response = call.execute(); - - if(response.code() == 200) { - - assert response.body() != null; - - List notificationThreads = response.body(); - - if(!notificationThreads.isEmpty()) - sendNotification(notificationThreads); - - tinyDB.putString("previousRefreshTimestamp", AppUtil.getTimestampFromDate(context, new Date())); - } - - } catch(Exception ignored) {} + startPolling(); try { if(notificationLoops > 1 && i < (notificationLoops - 1)) { - Thread.sleep(60000 - (System.currentTimeMillis() - startPollingTime)); } - } catch (InterruptedException ignored) {} + } catch(InterruptedException ignored) {} } - - return Result.success(); - } - private void sendNotification(List notificationThreads) { + private void startPolling() { + for(UserAccount userAccount : userAccounts.keySet()) { + Map userAccountParameters = userAccounts.get(userAccount); - int summaryId = 0; - PendingIntent pendingIntent = getPendingIntent(); + try { + Call> call = RetrofitClient + .getApiInterface(context, userAccount.getInstanceUrl()) + .getNotificationThreads(Authorization.get(userAccount), false, new String[]{"unread"}, + userAccountParameters.get("previousTimestamp"), null, 1, Integer.MAX_VALUE); + + Response> response = call.execute(); + + if(response.code() == 200 && response.body() != null) { + List notificationThreads = response.body(); + if(!notificationThreads.isEmpty()) { + sendNotifications(userAccount, notificationThreads); + } + userAccountParameters.put("previousTimestamp", AppUtil.getTimestampFromDate(context, new Date())); + } + } catch(Exception ignored) {} + } + } + + private void sendNotifications(@NonNull UserAccount userAccount, @NonNull List notificationThreads) { + + PendingIntent pendingIntent = getPendingIntent(userAccount); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); - Notification summaryNotification = new NotificationCompat.Builder(context, context.getPackageName()) - .setContentTitle(context.getString(R.string.newMessages)) + Notification summaryNotification = new NotificationCompat.Builder(context, Constants.mainNotificationChannelId) + .setContentTitle(context.getString(R.string.newMessages, userAccount.getUserName())) .setContentText(String.format(context.getString(R.string.youHaveGotNewNotifications), notificationThreads.size())) .setSmallIcon(R.drawable.gitnex_transparent) - .setGroup(context.getPackageName()) + .setGroup(userAccount.getUserName()) .setGroupSummary(true) .setAutoCancel(true) .setContentIntent(pendingIntent) - .setChannelId(Constants.mainNotificationChannelId) .build(); - notificationManagerCompat.notify(summaryId, summaryNotification); + notificationManagerCompat.notify(userAccount.getAccountId(), summaryNotification); for(NotificationThread notificationThread : notificationThreads) { @@ -119,7 +140,7 @@ public class NotificationsWorker extends Worker { NotificationCompat.Builder builder1 = getBaseNotificationBuilder() .setContentTitle(notificationHeader) - .setGroup(context.getPackageName()) + .setGroup(userAccount.getUserName()) .setContentIntent(pendingIntent); notificationManagerCompat.notify(Notifications.uniqueNotificationId(context), builder1.build()); @@ -129,21 +150,19 @@ public class NotificationsWorker extends Worker { private NotificationCompat.Builder getBaseNotificationBuilder() { - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, context.getPackageName()) + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, Constants.mainNotificationChannelId) .setSmallIcon(R.drawable.gitnex_transparent) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_DEFAULT) - .setChannelId(Constants.mainNotificationChannelId) .setAutoCancel(true); if(tinyDB.getBoolean("notificationsEnableLights", true)) { - builder.setLights(tinyDB.getInt("notificationsLightColor", Color.GREEN), 1500, 1500); } if(tinyDB.getBoolean("notificationsEnableVibration", true)) { - builder.setVibrate(new long[]{ 1000, 1000 }); + builder.setVibrate(Constants.defaultVibrationPattern); } else { builder.setVibrate(null); } @@ -151,13 +170,16 @@ public class NotificationsWorker extends Worker { return builder; } - private PendingIntent getPendingIntent() { + private PendingIntent getPendingIntent(@NonNull UserAccount userAccount) { Intent intent = new Intent(context, MainActivity.class); + intent.putExtra("launchFragment", "notifications"); + intent.putExtra("switchAccountId", userAccount.getAccountId()); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - return PendingIntent.getActivity(context, 0, intent, 0); + return PendingIntent.getActivity(context, userAccount.getAccountId(), intent, PendingIntent.FLAG_UPDATE_CURRENT); } + } diff --git a/app/src/main/res/layout/activity_add_collaborator_to_repository.xml b/app/src/main/res/layout/activity_add_collaborator_to_repository.xml index ab0394e0..218adf7d 100644 --- a/app/src/main/res/layout/activity_add_collaborator_to_repository.xml +++ b/app/src/main/res/layout/activity_add_collaborator_to_repository.xml @@ -26,6 +26,9 @@ android:layout_marginLeft="15dp" android:gravity="center_vertical" android:contentDescription="@string/close" + android:background="?android:attr/selectableItemBackgroundBorderless" + android:focusable="true" + android:clickable="true" android:src="@drawable/ic_close" /> @@ -56,11 +61,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/repoSettingsEditProperties" + android:background="?android:attr/selectableItemBackground" android:drawablePadding="32dp" + android:padding="16dp" + android:focusable="true" + android:clickable="true" + android:text="@string/repoSettingsEditProperties" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="16dp" app:drawableStartCompat="@drawable/ic_edit" /> + android:focusable="true" + android:clickable="true" + android:visibility="gone" + tools:visibility="visible"> + android:textSize="12sp" /> + android:textSize="12sp" /> diff --git a/app/src/main/res/layout/activity_settings_appearance.xml b/app/src/main/res/layout/activity_settings_appearance.xml index 1b9f7c06..455379f5 100644 --- a/app/src/main/res/layout/activity_settings_appearance.xml +++ b/app/src/main/res/layout/activity_settings_appearance.xml @@ -10,6 +10,7 @@ android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="10dp" android:theme="@style/Widget.AppCompat.SearchView"> @@ -47,29 +51,32 @@ android:id="@+id/themeSelectionFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="10dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:orientation="vertical" + android:focusable="true" + android:clickable="true" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> @@ -77,29 +84,32 @@ android:id="@+id/customFontFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> @@ -107,29 +117,32 @@ android:id="@+id/timeFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> @@ -137,30 +150,31 @@ android:id="@+id/counterBadgeFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:switchMinWidth="56dp" /> diff --git a/app/src/main/res/layout/activity_settings_drafts.xml b/app/src/main/res/layout/activity_settings_drafts.xml index dcb6eb7e..25f3d41b 100644 --- a/app/src/main/res/layout/activity_settings_drafts.xml +++ b/app/src/main/res/layout/activity_settings_drafts.xml @@ -1,16 +1,15 @@ - + android:background="?attr/primaryBackgroundColor" + android:orientation="vertical"> @@ -48,42 +50,41 @@ android:id="@+id/enableDraftsCommentsDeletion" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:switchMinWidth="56dp" /> + android:textColor="?attr/hintColor" + android:textSize="12sp" /> diff --git a/app/src/main/res/layout/activity_settings_general.xml b/app/src/main/res/layout/activity_settings_general.xml index e48baa40..d7a6e2f1 100644 --- a/app/src/main/res/layout/activity_settings_general.xml +++ b/app/src/main/res/layout/activity_settings_general.xml @@ -1,16 +1,15 @@ - + android:background="?attr/primaryBackgroundColor" + android:orientation="vertical"> @@ -48,40 +50,41 @@ android:id="@+id/setDefaultLinkHandler" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/hintColor" + android:textSize="12sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> @@ -89,29 +92,32 @@ android:id="@+id/homeScreenFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> diff --git a/app/src/main/res/layout/activity_settings_notifications.xml b/app/src/main/res/layout/activity_settings_notifications.xml index 404246f3..e7216c3e 100644 --- a/app/src/main/res/layout/activity_settings_notifications.xml +++ b/app/src/main/res/layout/activity_settings_notifications.xml @@ -1,18 +1,17 @@ - + android:background="?attr/primaryBackgroundColor" + android:orientation="vertical"> @@ -51,8 +53,9 @@ android:id="@+id/enableNotificationsFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:switchMinWidth="56dp" /> @@ -82,29 +85,32 @@ android:id="@+id/pollingDelayFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="10dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> @@ -112,30 +118,31 @@ android:id="@+id/enableLightsFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:switchMinWidth="56dp" /> @@ -143,24 +150,25 @@ android:id="@+id/chooseColorFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:switchMinWidth="56dp" /> diff --git a/app/src/main/res/layout/activity_settings_reports.xml b/app/src/main/res/layout/activity_settings_reports.xml index f60fe70b..af55301b 100644 --- a/app/src/main/res/layout/activity_settings_reports.xml +++ b/app/src/main/res/layout/activity_settings_reports.xml @@ -1,16 +1,15 @@ - + android:background="?attr/primaryBackgroundColor" + android:orientation="vertical"> @@ -47,31 +49,31 @@ android:id="@+id/enableSendReports" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:switchMinWidth="56dp" /> diff --git a/app/src/main/res/layout/activity_settings_security.xml b/app/src/main/res/layout/activity_settings_security.xml index 17a76f0a..c4357b99 100644 --- a/app/src/main/res/layout/activity_settings_security.xml +++ b/app/src/main/res/layout/activity_settings_security.xml @@ -1,16 +1,15 @@ - + android:background="?attr/primaryBackgroundColor" + android:orientation="vertical"> @@ -47,30 +49,31 @@ android:id="@+id/biometricFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="horizontal"> + android:orientation="horizontal" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:switchMinWidth="56dp" /> @@ -78,19 +81,22 @@ android:id="@+id/certsFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> @@ -98,29 +104,32 @@ android:id="@+id/cacheSizeDataSelectionFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> @@ -128,29 +137,32 @@ android:id="@+id/cacheSizeImagesSelectionFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> @@ -158,29 +170,32 @@ android:id="@+id/clearCacheSelectionFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="15dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> diff --git a/app/src/main/res/layout/activity_settings_translation.xml b/app/src/main/res/layout/activity_settings_translation.xml index 8deae560..c9b1512e 100644 --- a/app/src/main/res/layout/activity_settings_translation.xml +++ b/app/src/main/res/layout/activity_settings_translation.xml @@ -10,6 +10,7 @@ android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="10dp" android:theme="@style/Widget.AppCompat.SearchView"> @@ -46,41 +50,44 @@ android:id="@+id/langFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="10dp" - android:orientation="vertical"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textColor="?attr/primaryTextColor" + android:textSize="16sp" /> + android:textColor="?attr/selectedTextColor" + android:textSize="14sp" /> + android:textColor="@color/lightBlue" + android:textSize="14sp" /> diff --git a/app/src/main/res/layout/bottom_sheet_admin_users.xml b/app/src/main/res/layout/bottom_sheet_admin_users.xml index 18d79744..acc6473c 100644 --- a/app/src/main/res/layout/bottom_sheet_admin_users.xml +++ b/app/src/main/res/layout/bottom_sheet_admin_users.xml @@ -15,19 +15,22 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> diff --git a/app/src/main/res/layout/bottom_sheet_drafts.xml b/app/src/main/res/layout/bottom_sheet_drafts.xml index 4d76f557..1ab7ece5 100644 --- a/app/src/main/res/layout/bottom_sheet_drafts.xml +++ b/app/src/main/res/layout/bottom_sheet_drafts.xml @@ -15,19 +15,22 @@ + android:layout_height="wrap_content" + android:orientation="vertical"> diff --git a/app/src/main/res/layout/bottom_sheet_file_viewer.xml b/app/src/main/res/layout/bottom_sheet_file_viewer.xml index 30cbcd48..a3390604 100644 --- a/app/src/main/res/layout/bottom_sheet_file_viewer.xml +++ b/app/src/main/res/layout/bottom_sheet_file_viewer.xml @@ -23,9 +23,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/editFile" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" android:padding="12dp" + android:text="@string/editFile" android:textColor="?attr/primaryTextColor" android:textSize="16sp" app:drawableStartCompat="@drawable/ic_edit" /> @@ -35,9 +38,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/deleteFile" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" android:padding="12dp" + android:text="@string/deleteFile" android:textColor="?attr/primaryTextColor" android:textSize="16sp" app:drawableStartCompat="@drawable/ic_delete" /> @@ -47,11 +53,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/downloadFile" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/downloadFile" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_download" /> diff --git a/app/src/main/res/layout/bottom_sheet_issue_comments.xml b/app/src/main/res/layout/bottom_sheet_issue_comments.xml index c7ad7a76..d49a94b1 100644 --- a/app/src/main/res/layout/bottom_sheet_issue_comments.xml +++ b/app/src/main/res/layout/bottom_sheet_issue_comments.xml @@ -30,11 +30,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/menuEditText" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/menuEditText" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_edit" /> diff --git a/app/src/main/res/layout/bottom_sheet_issues_filter.xml b/app/src/main/res/layout/bottom_sheet_issues_filter.xml index a89de021..81f9b081 100644 --- a/app/src/main/res/layout/bottom_sheet_issues_filter.xml +++ b/app/src/main/res/layout/bottom_sheet_issues_filter.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/isOpen" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/isOpen" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_issue" /> diff --git a/app/src/main/res/layout/bottom_sheet_labels_in_list.xml b/app/src/main/res/layout/bottom_sheet_labels_in_list.xml index e9e78677..002e586d 100644 --- a/app/src/main/res/layout/bottom_sheet_labels_in_list.xml +++ b/app/src/main/res/layout/bottom_sheet_labels_in_list.xml @@ -22,10 +22,10 @@ android:id="@+id/bottomSheetHeader" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/labelName" android:paddingStart="18dp" android:paddingEnd="18dp" android:paddingBottom="18dp" + android:text="@string/labelName" android:textColor="?attr/primaryTextColor" android:textSize="18sp" /> @@ -41,11 +41,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/labelMenuEdit" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/labelMenuEdit" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_edit" /> diff --git a/app/src/main/res/layout/bottom_sheet_milestones_filter.xml b/app/src/main/res/layout/bottom_sheet_milestones_filter.xml index d876482f..4d208a8c 100644 --- a/app/src/main/res/layout/bottom_sheet_milestones_filter.xml +++ b/app/src/main/res/layout/bottom_sheet_milestones_filter.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/isOpen" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/isOpen" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_milestone" /> diff --git a/app/src/main/res/layout/bottom_sheet_milestones_in_list.xml b/app/src/main/res/layout/bottom_sheet_milestones_in_list.xml index 8acacdfb..5f8bcc0f 100644 --- a/app/src/main/res/layout/bottom_sheet_milestones_in_list.xml +++ b/app/src/main/res/layout/bottom_sheet_milestones_in_list.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/closeMilestone" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/closeMilestone" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_close" /> diff --git a/app/src/main/res/layout/bottom_sheet_notifications.xml b/app/src/main/res/layout/bottom_sheet_notifications.xml index f22ab13f..adadfdda 100644 --- a/app/src/main/res/layout/bottom_sheet_notifications.xml +++ b/app/src/main/res/layout/bottom_sheet_notifications.xml @@ -23,11 +23,14 @@ android:background="?attr/primaryBackgroundColor"> android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/pinNotification" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/pinNotification" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_pin" /> android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/markAsRead" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/markAsRead" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_unwatch" /> android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/markAsUnread" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/markAsUnread" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_watchers" /> diff --git a/app/src/main/res/layout/bottom_sheet_notifications_filter.xml b/app/src/main/res/layout/bottom_sheet_notifications_filter.xml index 2ac0a503..42f13c43 100644 --- a/app/src/main/res/layout/bottom_sheet_notifications_filter.xml +++ b/app/src/main/res/layout/bottom_sheet_notifications_filter.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/isUnread" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/isUnread" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_watchers" /> diff --git a/app/src/main/res/layout/bottom_sheet_organization.xml b/app/src/main/res/layout/bottom_sheet_organization.xml index da44ef12..e4bbef2e 100644 --- a/app/src/main/res/layout/bottom_sheet_organization.xml +++ b/app/src/main/res/layout/bottom_sheet_organization.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/createRepository" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/createRepository" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_repo" /> diff --git a/app/src/main/res/layout/bottom_sheet_organization_teams.xml b/app/src/main/res/layout/bottom_sheet_organization_teams.xml index 003f7f2e..ea60c3ee 100644 --- a/app/src/main/res/layout/bottom_sheet_organization_teams.xml +++ b/app/src/main/res/layout/bottom_sheet_organization_teams.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/addNewMember" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/addNewMember" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_person_add" /> diff --git a/app/src/main/res/layout/bottom_sheet_profile.xml b/app/src/main/res/layout/bottom_sheet_profile.xml index 27d7ba80..0ef6cafd 100644 --- a/app/src/main/res/layout/bottom_sheet_profile.xml +++ b/app/src/main/res/layout/bottom_sheet_profile.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/profileCreateNewEmailAddress" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/profileCreateNewEmailAddress" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_email" /> diff --git a/app/src/main/res/layout/bottom_sheet_pull_request_filter.xml b/app/src/main/res/layout/bottom_sheet_pull_request_filter.xml index 10c06915..80d67320 100644 --- a/app/src/main/res/layout/bottom_sheet_pull_request_filter.xml +++ b/app/src/main/res/layout/bottom_sheet_pull_request_filter.xml @@ -23,11 +23,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/isOpen" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/isOpen" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_pull_request" /> diff --git a/app/src/main/res/layout/bottom_sheet_reply_layout.xml b/app/src/main/res/layout/bottom_sheet_reply_layout.xml index a07f4b76..47e74c5a 100644 --- a/app/src/main/res/layout/bottom_sheet_reply_layout.xml +++ b/app/src/main/res/layout/bottom_sheet_reply_layout.xml @@ -31,8 +31,10 @@ android:layout_height="26dp" android:layout_marginEnd="15dp" android:layout_weight="0" - android:background="?android:attr/selectableItemBackground" android:contentDescription="@string/close" + android:background="?android:attr/selectableItemBackgroundBorderless" + android:focusable="true" + android:clickable="true" android:src="@drawable/ic_close" /> @@ -63,6 +67,8 @@ android:layout_weight="0" android:alpha=".5" android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:contentDescription="@string/close" android:enabled="false" android:src="@drawable/ic_send" /> diff --git a/app/src/main/res/layout/bottom_sheet_repo.xml b/app/src/main/res/layout/bottom_sheet_repo.xml index 0b50ed57..e07f4494 100644 --- a/app/src/main/res/layout/bottom_sheet_repo.xml +++ b/app/src/main/res/layout/bottom_sheet_repo.xml @@ -23,6 +23,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" android:padding="12dp" android:text="@string/pageTitleNewFile" @@ -35,6 +38,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" android:padding="12dp" android:text="@string/pageTitleCreateNewIssue" @@ -47,6 +53,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" android:padding="12dp" android:text="@string/pageTitleNewPullRequest" @@ -59,11 +68,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/pageTitleCreateMilestone" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:drawablePadding="24dp" + android:padding="12dp" + android:text="@string/pageTitleCreateMilestone" android:textColor="?attr/primaryTextColor" android:textSize="16sp" - android:padding="12dp" app:drawableStartCompat="@drawable/ic_milestone" /> diff --git a/app/src/main/res/layout/bottom_sheet_single_issue.xml b/app/src/main/res/layout/bottom_sheet_single_issue.xml index be79900d..3eb32ac8 100644 --- a/app/src/main/res/layout/bottom_sheet_single_issue.xml +++ b/app/src/main/res/layout/bottom_sheet_single_issue.xml @@ -2,6 +2,7 @@ + app:drawableStartCompat="@drawable/ic_file" + tools:visibility="visible" /> + app:drawableStartCompat="@drawable/ic_watchers" + tools:visibility="visible" /> + app:drawableStartCompat="@drawable/ic_reopen" + tools:visibility="visible" /> diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 919ccfb2..26242e15 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -94,17 +94,18 @@ android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:theme="@style/AppTheme.AppBarOverlay"> + android:theme="@style/AppTheme.AppBarOverlay" + app:elevation="0dp"> + app:tabMode="scrollable" + app:tabTextAppearance="@style/customTabLayout" + app:tabTextColor="?attr/primaryTextColor"> @@ -124,6 +127,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" + android:background="?android:attr/selectableItemBackgroundBorderless" + android:focusable="true" + android:clickable="true" android:gravity="center" android:orientation="vertical"> @@ -146,6 +152,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" + android:background="?android:attr/selectableItemBackgroundBorderless" + android:focusable="true" + android:clickable="true" android:gravity="center" android:orientation="vertical"> @@ -168,6 +177,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" + android:background="?android:attr/selectableItemBackgroundBorderless" + android:focusable="true" + android:clickable="true" android:gravity="center" android:orientation="vertical"> diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index f8db344e..3bb79988 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -14,15 +14,20 @@ + android:paddingTop="10dp"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" + android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:paddingTop="10dp" + android:paddingBottom="10dp"> @@ -149,8 +166,12 @@ android:id="@+id/notificationsFrame" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="25dp" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:orientation="vertical" + android:paddingTop="10dp" + android:paddingBottom="10dp" android:visibility="gone"> + android:paddingTop="10dp" + android:paddingBottom="10dp"> @@ -214,8 +239,12 @@ android:id="@+id/reportsFrame" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:orientation="vertical" - android:layout_marginTop="25dp"> + android:paddingTop="10dp" + android:paddingBottom="10dp"> @@ -246,29 +275,33 @@ android:id="@+id/rateAppFrame" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:orientation="vertical" - android:layout_marginTop="25dp"> + android:paddingTop="10dp" + android:paddingBottom="10dp"> + android:textSize="16sp" + app:drawableStartCompat="@drawable/ic_like" /> @@ -278,9 +311,12 @@ android:id="@+id/aboutAppFrame" android:layout_width="match_parent" android:layout_height="wrap_content" + android:background="?android:attr/selectableItemBackground" + android:focusable="true" + android:clickable="true" android:orientation="vertical" - android:layout_marginTop="25dp" - android:layout_marginBottom="20dp"> + android:paddingTop="10dp" + android:paddingBottom="10dp"> diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 4028af15..2c020a03 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -560,7 +560,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index 3677477e..c638328d 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index c3e6a14b..656eaf4b 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -557,7 +557,7 @@ Aktiviere Hell Vibration aktivieren Farbe auswählen - Neue Nachrichten + Neue Nachrichten für %s Du hast %d neue Nachrichten. Benachrichtigungen Das ist der Haupt-Nachrichten-Kanal von GitNex. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index ec58669c..76baacae 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-fa/strings.xml b/app/src/main/res/values-fa/strings.xml index dc713a4b..388cd82a 100644 --- a/app/src/main/res/values-fa/strings.xml +++ b/app/src/main/res/values-fa/strings.xml @@ -560,7 +560,7 @@ Enable Light فعال‌سازی لرزش انتخاب رنگ - پیام‌های جدید + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index d048fea1..c3f7152b 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index e1c761e4..c3b65c07 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -557,7 +557,7 @@ Activer le témoin lumineux Activer le vibreur Couleur - Nouveaux messages + New messages for %s Vous avez %d nouvelles notifications. Notifications Le canal de notifications principal de GitNex. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 759066f6..d18f43f1 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -69,7 +69,7 @@ Impossibile connettersi all\'host. Controlla l\'URL o la porta per eventuali errori Non si consiglia di utilizzare il protocollo HTTP a meno che non si stia testando sulla rete locale Malformed JSON was received. Server response was not successful - Istanza + Istanza URL è richiesto Nome utente obbligatorio Password obbligatoria @@ -274,7 +274,7 @@ URL è richiesto I membri possono inviare i repository del team e aggiungere loro collaboratori Inserisci il nome del team Il nome del team deve contenere solo caratteri alfanumerici, trattino (-), trattino basso (_) e punto (.) - Seleziona + Seleziona autorizzazione La descrizione del team contiene caratteri non validi La descrizione del team ha più di 100 caratteri @@ -559,7 +559,7 @@ autorizzazione Enable Light Abilita la vibrazione Scegli il colore - Nuovi messaggi + New messages for %s You\'ve got %d new notifications. Notifiche This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-lv/strings.xml b/app/src/main/res/values-lv/strings.xml index 03dbc7b9..ce82af3d 100644 --- a/app/src/main/res/values-lv/strings.xml +++ b/app/src/main/res/values-lv/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 1cb1ba72..6386d7ec 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 0aa71eb1..5065a939 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index fc331922..d9e966a9 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-sr/strings.xml b/app/src/main/res/values-sr/strings.xml index 2bccf393..ea36fd71 100644 --- a/app/src/main/res/values-sr/strings.xml +++ b/app/src/main/res/values-sr/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 68cb0dd0..ac37f103 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 8b1c8fe7..d7ec89f8 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -557,7 +557,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 50b34cf4..172aa989 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -557,7 +557,7 @@ 启用 Light 启用振动 选择颜色 - 新消息 + New messages for %s 您有%d条新通知 通知 这是 GitNex 的主通知通道。 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 3a85e05f..7eb2c893 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -57,5 +57,6 @@ #050505 #d2d2d2 + #0E0E0E #151515 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7a5401f5..16639cc6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -673,7 +673,7 @@ Enable Light Enable Vibration Choose Color - New messages + New messages for %s You\'ve got %d new notifications. Notifications This is the main notification channel of GitNex. diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 58880a3f..d782d482 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -150,7 +150,7 @@ @style/AppThemeDarkSearchAutoCompleteTextView @color/hintColor @color/darkGreen - @color/hintColor + @color/pitchBlackThemeDividerColor @style/AppThemeDarkBottomSheetDialog @style/AppSearchViewStyle @color/darkGreen diff --git a/gradle.properties b/gradle.properties index ed7c758a..a43d4a12 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,7 @@ android.enableJetifier=true android.useAndroidX=true org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.workers.max=12 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects