From b44a422954aae3a70ea44a8709dc81ac1ca33105 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Sat, 16 Sep 2023 19:37:12 +0500 Subject: [PATCH] Open individual commit(s) and branch from dashboard --- .../gitnex/adapters/DashboardAdapter.java | 144 +++++++++++++++--- 1 file changed, 126 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/adapters/DashboardAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/DashboardAdapter.java index e5621aa2..1f33a799 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/DashboardAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/DashboardAdapter.java @@ -17,7 +17,12 @@ import androidx.recyclerview.widget.RecyclerView; import com.vdurmont.emoji.EmojiParser; import java.util.List; import java.util.Locale; +import java.util.Objects; +import org.apache.commons.lang3.StringUtils; import org.gitnex.tea4j.v2.models.Activity; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import org.mian.gitnex.R; import org.mian.gitnex.activities.IssueDetailActivity; import org.mian.gitnex.activities.ProfileActivity; @@ -206,17 +211,9 @@ public class DashboardAdapter extends RecyclerView.Adapter 1) { - id = contentParts[0]; - content = contentParts[1]; - dashTextFrame.setVisibility(View.VISIBLE); - dashText.setText(EmojiParser.parseToUnicode(content)); - } else { - id = contentParts[0]; - } + id = contentParts[0]; Intent intentIssueDetail = new IssueContext(repo, Integer.parseInt(id), "open") @@ -264,17 +261,9 @@ public class DashboardAdapter extends RecyclerView.Adapter 1) { - id = contentParts[0]; - content = contentParts[1]; - dashTextFrame.setVisibility(View.VISIBLE); - dashText.setText(EmojiParser.parseToUnicode(content)); - } else { - id = contentParts[0]; - } + id = contentParts[0]; Intent intentIssueDetail = new IssueContext(repo, Integer.parseInt(id), "open") @@ -287,6 +276,45 @@ public class DashboardAdapter extends RecyclerView.Adapter { + RepositoryContext repo = + new RepositoryContext( + activityObject.getRepo(), + context); + + Intent repoIntent = + new Intent( + context, + RepoDetailActivity.class); + repoIntent.putExtra("goToSection", "yes"); + repoIntent.putExtra( + "goToSectionType", "commitsList"); + repoIntent.putExtra( + "branchName", + activityObject + .getRefName() + .substring( + activityObject + .getRefName() + .lastIndexOf( + "/") + + 1) + .trim()); + + repo.saveToDB(context); + repoIntent.putExtra( + RepositoryContext.INTENT_EXTRA, repo); + + context.startActivity(repoIntent); + }); + } + } }, 200); } @@ -373,6 +401,7 @@ public class DashboardAdapter extends RecyclerView.Adapter" + activity.getRepo().getFullName() + ""; + if (activity.getContent().isEmpty()) { String branch = "" + + StringUtils.substring( + String.valueOf(commitsShaArray.get(i)), + 9, + 19) + + ""; + + TextView dynamicCommitTv = new TextView(context); + dynamicCommitTv.setId(View.generateViewId()); + + dynamicCommitTv.setText( + HtmlCompat.fromHtml( + timelineCommits, HtmlCompat.FROM_HTML_MODE_LEGACY)); + + JSONObject sha1Obj = null; + try { + sha1Obj = (JSONObject) commitsShaArray.get(i); + } catch (JSONException ignored) { + } + + JSONObject finalSha1Obj = sha1Obj; + dynamicCommitTv.setOnClickListener( + v14 -> { + RepositoryContext repo = + new RepositoryContext( + activity.getRepo(), context); + + Intent repoIntent = + new Intent(context, RepoDetailActivity.class); + repoIntent.putExtra("goToSection", "yes"); + repoIntent.putExtra("goToSectionType", "commit"); + try { + assert finalSha1Obj != null; + repoIntent.putExtra( + "sha", (String) finalSha1Obj.get("Sha1")); + } catch (JSONException ignored) { + } + + repo.saveToDB(context); + repoIntent.putExtra( + RepositoryContext.INTENT_EXTRA, repo); + + context.startActivity(repoIntent); + }); + + dashTextFrame.setOrientation(LinearLayout.VERTICAL); + dashTextFrame.addView(dynamicCommitTv); + } catch (JSONException ignored) { + } + } } typeIcon.setImageResource(R.drawable.ic_commit); }