2019-06-03 23:25:05 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
import com.google.android.material.tabs.TabLayout;
|
2019-10-11 22:03:01 +02:00
|
|
|
import com.google.gson.JsonElement;
|
2019-06-03 23:25:05 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
|
|
|
import androidx.viewpager.widget.ViewPager;
|
|
|
|
import retrofit2.Call;
|
|
|
|
import retrofit2.Callback;
|
2019-09-19 08:21:15 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.content.Intent;
|
2019-09-19 08:21:15 +02:00
|
|
|
import android.content.res.ColorStateList;
|
2020-01-01 21:03:53 +01:00
|
|
|
import android.graphics.Typeface;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
2020-01-02 08:51:10 +01:00
|
|
|
import android.view.ViewGroup;
|
2019-06-03 23:25:05 +02:00
|
|
|
import android.widget.TextView;
|
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.clients.RetrofitClient;
|
2020-03-16 20:28:03 +01:00
|
|
|
import org.mian.gitnex.fragments.BottomSheetRepoFragment;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.fragments.BranchesFragment;
|
|
|
|
import org.mian.gitnex.fragments.CollaboratorsFragment;
|
2019-10-02 10:30:07 +02:00
|
|
|
import org.mian.gitnex.fragments.FilesFragment;
|
2020-04-14 22:55:04 +02:00
|
|
|
import org.mian.gitnex.fragments.IssuesMainFragment;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.fragments.LabelsFragment;
|
|
|
|
import org.mian.gitnex.fragments.MilestonesFragment;
|
2019-11-24 13:42:57 +01:00
|
|
|
import org.mian.gitnex.fragments.PullRequestsFragment;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.fragments.ReleasesFragment;
|
|
|
|
import org.mian.gitnex.fragments.RepoInfoFragment;
|
|
|
|
import org.mian.gitnex.helpers.Authorization;
|
2020-04-07 06:15:56 +02:00
|
|
|
import org.mian.gitnex.helpers.VersionCheck;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.models.UserRepositories;
|
2019-10-12 11:00:36 +02:00
|
|
|
import org.mian.gitnex.models.WatchRepository;
|
2019-06-03 23:25:05 +02:00
|
|
|
import org.mian.gitnex.util.AppUtil;
|
|
|
|
import org.mian.gitnex.util.TinyDB;
|
|
|
|
import java.util.Objects;
|
2019-09-10 19:48:44 +02:00
|
|
|
import android.net.Uri;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-16 20:28:03 +01:00
|
|
|
public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoFragment.BottomSheetListener {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-04 21:20:25 +02:00
|
|
|
private TextView textViewBadgeIssue;
|
|
|
|
private TextView textViewBadgePull;
|
|
|
|
private TextView textViewBadgeRelease;
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
@Override
|
2020-01-01 21:03:53 +01:00
|
|
|
protected int getLayoutResourceId(){
|
|
|
|
return R.layout.activity_repo_detail;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2019-06-03 23:25:05 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
|
|
|
String repoName1 = parts[1];
|
|
|
|
|
|
|
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
final String repoOwner = parts[0];
|
|
|
|
final String loginUid = tinyDb.getString("loginUid");
|
|
|
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
|
|
|
|
|
|
String appLocale = tinyDb.getString("locale");
|
|
|
|
AppUtil.setAppLocale(getResources(), appLocale);
|
|
|
|
|
|
|
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
2020-01-02 08:51:10 +01:00
|
|
|
TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
Objects.requireNonNull(getSupportActionBar()).setTitle(repoName1);
|
|
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
|
|
|
|
|
|
|
ViewPager mViewPager = findViewById(R.id.container);
|
|
|
|
mViewPager.setAdapter(mSectionsPagerAdapter);
|
|
|
|
|
|
|
|
TabLayout tabLayout = findViewById(R.id.tabs);
|
|
|
|
|
2020-01-02 08:51:10 +01:00
|
|
|
Typeface myTypeface;
|
|
|
|
|
2020-04-12 17:19:33 +02:00
|
|
|
switch(tinyDb.getInt("customFontId", -1)) {
|
2020-01-02 08:51:10 +01:00
|
|
|
|
2020-04-12 17:19:33 +02:00
|
|
|
case 0:
|
|
|
|
myTypeface = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/roboto.ttf");
|
|
|
|
break;
|
2020-01-02 08:51:10 +01:00
|
|
|
|
2020-04-12 17:19:33 +02:00
|
|
|
case 2:
|
|
|
|
myTypeface = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/sourcecodeproregular.ttf");
|
|
|
|
break;
|
2020-01-02 08:51:10 +01:00
|
|
|
|
2020-04-12 17:19:33 +02:00
|
|
|
default:
|
|
|
|
myTypeface = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/manroperegular.ttf");
|
|
|
|
break;
|
2020-01-02 08:51:10 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
toolbarTitle.setTypeface(myTypeface);
|
|
|
|
toolbarTitle.setText(repoName1);
|
|
|
|
|
|
|
|
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
|
|
|
|
int tabsCount = vg.getChildCount();
|
|
|
|
for (int j = 0; j < tabsCount; j++) {
|
|
|
|
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
|
|
|
|
int tabChildCount = vgTab.getChildCount();
|
|
|
|
for (int i = 0; i < tabChildCount; i++) {
|
|
|
|
View tabViewChild = vgTab.getChildAt(i);
|
|
|
|
if (tabViewChild instanceof TextView) {
|
|
|
|
((TextView) tabViewChild).setTypeface(myTypeface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 21:25:36 +02:00
|
|
|
// only show Collaborators if you have permission to
|
2020-04-14 22:55:04 +02:00
|
|
|
final View collaboratorTab = vg.getChildAt(8);
|
2020-04-14 21:25:36 +02:00
|
|
|
if (tinyDb.getBoolean("isRepoAdmin")) {
|
|
|
|
collaboratorTab.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
collaboratorTab.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
|
|
|
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
|
|
|
|
2020-04-04 21:20:25 +02:00
|
|
|
if(tinyDb.getBoolean("enableCounterBadges")) {
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-04 21:20:25 +02:00
|
|
|
@SuppressLint("InflateParams") View tabHeader2 = LayoutInflater.from(this).inflate(R.layout.badge_issue, null);
|
|
|
|
textViewBadgeIssue = tabHeader2.findViewById(R.id.counterBadgeIssue);
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams") View tabHeader4 = LayoutInflater.from(this).inflate(R.layout.badge_pull, null);
|
|
|
|
textViewBadgePull = tabHeader4.findViewById(R.id.counterBadgePull);
|
|
|
|
|
|
|
|
@SuppressLint("InflateParams") View tabHeader6 = LayoutInflater.from(this).inflate(R.layout.badge_release, null);
|
|
|
|
textViewBadgeRelease = tabHeader6.findViewById(R.id.counterBadgeRelease);
|
|
|
|
|
|
|
|
textViewBadgeIssue.setVisibility(View.GONE);
|
|
|
|
textViewBadgePull.setVisibility(View.GONE);
|
|
|
|
textViewBadgeRelease.setVisibility(View.GONE);
|
2019-06-03 23:25:05 +02:00
|
|
|
|
2020-04-04 21:20:25 +02:00
|
|
|
getRepoInfo(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName1);
|
2019-09-19 08:21:15 +02:00
|
|
|
ColorStateList textColor = tabLayout.getTabTextColors();
|
|
|
|
|
2020-04-04 21:20:25 +02:00
|
|
|
// issue count
|
|
|
|
if (textViewBadgeIssue.getText() != "") {
|
|
|
|
TabLayout.Tab tabOpenIssues = tabLayout.getTabAt(2);
|
|
|
|
Objects.requireNonNull(tabLayout.getTabAt(2)).setCustomView(tabHeader2);
|
|
|
|
assert tabOpenIssues != null;
|
|
|
|
TextView openIssueTabView = Objects.requireNonNull(tabOpenIssues.getCustomView()).findViewById(R.id.counterBadgeIssueText);
|
|
|
|
openIssueTabView.setTextColor(textColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// pull count
|
|
|
|
if (textViewBadgePull.getText() != "") { // only show if API returned a number
|
2020-04-14 22:55:04 +02:00
|
|
|
Objects.requireNonNull(tabLayout.getTabAt(3)).setCustomView(tabHeader4);
|
|
|
|
TabLayout.Tab tabOpenPulls = tabLayout.getTabAt(3);
|
2020-04-04 21:20:25 +02:00
|
|
|
assert tabOpenPulls != null;
|
|
|
|
TextView openPullTabView = Objects.requireNonNull(tabOpenPulls.getCustomView()).findViewById(R.id.counterBadgePullText);
|
|
|
|
openPullTabView.setTextColor(textColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// release count
|
2020-04-07 06:15:56 +02:00
|
|
|
if (VersionCheck.compareVersion("1.11.5", tinyDb.getString("giteaVersion")) < 1) {
|
|
|
|
if(textViewBadgeRelease.getText() != "") { // only show if API returned a number
|
2020-04-14 22:55:04 +02:00
|
|
|
Objects.requireNonNull(tabLayout.getTabAt(5)).setCustomView(tabHeader6);
|
|
|
|
TabLayout.Tab tabOpenRelease = tabLayout.getTabAt(5);
|
2020-04-07 06:15:56 +02:00
|
|
|
assert tabOpenRelease != null;
|
|
|
|
TextView openReleaseTabView = Objects.requireNonNull(tabOpenRelease.getCustomView()).findViewById(R.id.counterBadgeReleaseText);
|
|
|
|
openReleaseTabView.setTextColor(textColor);
|
|
|
|
}
|
2020-04-04 21:20:25 +02:00
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
2019-10-11 22:03:01 +02:00
|
|
|
|
|
|
|
checkRepositoryStarStatus(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName1);
|
2019-10-12 11:00:36 +02:00
|
|
|
checkRepositoryWatchStatus(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName1);
|
2020-04-04 21:20:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
|
|
|
|
super.onResume();
|
|
|
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
|
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
|
|
|
final String loginUid = tinyDb.getString("loginUid");
|
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
|
|
|
final String repoOwner = parts[0];
|
|
|
|
final String repoName = parts[1];
|
|
|
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
|
|
|
|
|
|
|
if(tinyDb.getBoolean("enableCounterIssueBadge")) {
|
|
|
|
getRepoInfo(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName);
|
|
|
|
}
|
2020-04-04 21:20:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2020-04-04 21:20:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.repo_dotted_menu, menu);
|
|
|
|
return true;
|
2020-04-04 21:20:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
case android.R.id.home:
|
|
|
|
finish();
|
|
|
|
return true;
|
|
|
|
case R.id.repoMenu:
|
2020-03-16 20:28:03 +01:00
|
|
|
BottomSheetRepoFragment bottomSheet = new BottomSheetRepoFragment();
|
2019-06-03 23:25:05 +02:00
|
|
|
bottomSheet.show(getSupportFragmentManager(), "repoBottomSheet");
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onButtonClicked(String text) {
|
|
|
|
|
2020-03-16 20:28:03 +01:00
|
|
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String instanceUrlWithProtocol = "https://" + tinyDb.getString("instanceUrlRaw");
|
|
|
|
if(!tinyDb.getString("instanceUrlWithProtocol").isEmpty()) {
|
|
|
|
instanceUrlWithProtocol = tinyDb.getString("instanceUrlWithProtocol");
|
|
|
|
}
|
|
|
|
Uri url = Uri.parse(instanceUrlWithProtocol + "/" + repoFullName);
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
switch (text) {
|
|
|
|
case "label":
|
|
|
|
startActivity(new Intent(RepoDetailActivity.this, CreateLabelActivity.class));
|
|
|
|
break;
|
|
|
|
case "newIssue":
|
|
|
|
startActivity(new Intent(RepoDetailActivity.this, CreateIssueActivity.class));
|
|
|
|
break;
|
|
|
|
case "newMilestone":
|
2020-03-17 11:32:03 +01:00
|
|
|
startActivity(new Intent(RepoDetailActivity.this, CreateMilestoneActivity.class));
|
2019-06-03 23:25:05 +02:00
|
|
|
break;
|
|
|
|
case "addCollaborator":
|
|
|
|
startActivity(new Intent(RepoDetailActivity.this, AddCollaboratorToRepositoryActivity.class));
|
|
|
|
break;
|
|
|
|
case "createRelease":
|
|
|
|
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
|
|
|
|
break;
|
2019-09-10 19:48:44 +02:00
|
|
|
case "openWebRepo":
|
|
|
|
Intent i = new Intent(Intent.ACTION_VIEW, url);
|
|
|
|
startActivity(i);
|
|
|
|
break;
|
2020-03-16 20:28:03 +01:00
|
|
|
case "shareRepo":
|
|
|
|
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
|
|
|
sharingIntent.setType("text/plain");
|
|
|
|
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, url);
|
|
|
|
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, url);
|
|
|
|
startActivity(Intent.createChooser(sharingIntent, url.toString()));
|
|
|
|
break;
|
2019-09-17 08:17:05 +02:00
|
|
|
case "newFile":
|
2020-03-17 11:32:03 +01:00
|
|
|
startActivity(new Intent(RepoDetailActivity.this, CreateFileActivity.class));
|
2019-09-17 08:17:05 +02:00
|
|
|
break;
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
|
|
|
|
|
|
|
SectionsPagerAdapter(FragmentManager fm) {
|
2019-09-14 10:20:00 +02:00
|
|
|
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Fragment getItem(int position) {
|
|
|
|
|
|
|
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
|
|
String repoFullName = tinyDb.getString("repoFullName");
|
|
|
|
String[] parts = repoFullName.split("/");
|
|
|
|
String repoOwner = parts[0];
|
|
|
|
String repoName = parts[1];
|
|
|
|
|
|
|
|
Fragment fragment = null;
|
|
|
|
switch (position) {
|
|
|
|
case 0: // information
|
|
|
|
return RepoInfoFragment.newInstance(repoOwner, repoName);
|
2019-10-01 16:48:20 +02:00
|
|
|
case 1: // files
|
2019-10-02 10:30:07 +02:00
|
|
|
return FilesFragment.newInstance(repoOwner, repoName);
|
2019-10-01 16:48:20 +02:00
|
|
|
case 2: // issues
|
2020-04-14 22:55:04 +02:00
|
|
|
fragment = new IssuesMainFragment();
|
2019-06-03 23:25:05 +02:00
|
|
|
break;
|
2020-04-14 22:55:04 +02:00
|
|
|
case 3: // pull requests
|
2019-11-24 13:42:57 +01:00
|
|
|
fragment = new PullRequestsFragment();
|
|
|
|
break;
|
2020-04-14 22:55:04 +02:00
|
|
|
case 4: // branches
|
2019-06-03 23:25:05 +02:00
|
|
|
return BranchesFragment.newInstance(repoOwner, repoName);
|
2020-04-14 22:55:04 +02:00
|
|
|
case 5: // releases
|
2019-06-03 23:25:05 +02:00
|
|
|
return ReleasesFragment.newInstance(repoOwner, repoName);
|
2020-04-14 22:55:04 +02:00
|
|
|
case 6: // milestones
|
2020-03-28 11:52:09 +01:00
|
|
|
return MilestonesFragment.newInstance(repoOwner, repoName);
|
2020-04-14 22:55:04 +02:00
|
|
|
case 7: // labels
|
2020-03-28 11:52:09 +01:00
|
|
|
return LabelsFragment.newInstance(repoOwner, repoName);
|
2020-04-14 22:55:04 +02:00
|
|
|
case 8: // collaborators
|
2019-06-03 23:25:05 +02:00
|
|
|
return CollaboratorsFragment.newInstance(repoOwner, repoName);
|
|
|
|
}
|
2020-03-28 11:52:09 +01:00
|
|
|
assert fragment != null;
|
2019-06-03 23:25:05 +02:00
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2020-04-14 22:55:04 +02:00
|
|
|
return 9;
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getRepoInfo(String instanceUrl, String token, final String owner, String repo) {
|
|
|
|
|
2020-04-04 21:20:25 +02:00
|
|
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
Call<UserRepositories> call = RetrofitClient
|
2019-11-13 16:52:49 +01:00
|
|
|
.getInstance(instanceUrl, getApplicationContext())
|
2019-06-03 23:25:05 +02:00
|
|
|
.getApiInterface()
|
|
|
|
.getUserRepository(token, owner, repo);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<UserRepositories>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<UserRepositories> call, @NonNull retrofit2.Response<UserRepositories> response) {
|
|
|
|
|
|
|
|
UserRepositories repoInfo = response.body();
|
|
|
|
|
|
|
|
if (response.isSuccessful()) {
|
|
|
|
|
|
|
|
if (response.code() == 200) {
|
|
|
|
|
2020-04-04 21:20:25 +02:00
|
|
|
if(tinyDb.getBoolean("enableCounterBadges")) {
|
|
|
|
assert repoInfo != null;
|
|
|
|
|
|
|
|
if(repoInfo.getOpen_issues_count() != null) {
|
|
|
|
textViewBadgeIssue.setVisibility(View.VISIBLE);
|
|
|
|
textViewBadgeIssue.setText(repoInfo.getOpen_issues_count());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(repoInfo.getOpen_pull_count() != null) {
|
|
|
|
textViewBadgePull.setVisibility(View.VISIBLE);
|
|
|
|
textViewBadgePull.setText(repoInfo.getOpen_pull_count());
|
|
|
|
}
|
|
|
|
|
|
|
|
if(repoInfo.getRelease_count() != null) {
|
|
|
|
textViewBadgeRelease.setVisibility(View.VISIBLE);
|
|
|
|
textViewBadgeRelease.setText(repoInfo.getRelease_count());
|
|
|
|
}
|
|
|
|
}
|
2019-06-03 23:25:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Log.e("onFailure", String.valueOf(response.code()));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<UserRepositories> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
2020-04-04 21:20:25 +02:00
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-11 22:03:01 +02:00
|
|
|
private void checkRepositoryStarStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
|
|
|
|
|
|
|
Call<JsonElement> call;
|
|
|
|
|
|
|
|
call = RetrofitClient
|
2019-11-13 16:52:49 +01:00
|
|
|
.getInstance(instanceUrl, getApplicationContext())
|
2019-10-11 22:03:01 +02:00
|
|
|
.getApiInterface()
|
|
|
|
.checkRepoStarStatus(instanceToken, owner, repo);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<JsonElement>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
|
|
|
|
|
|
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
|
|
tinyDb.putInt("repositoryStarStatus", response.code());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-10-12 11:00:36 +02:00
|
|
|
private void checkRepositoryWatchStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
|
|
|
|
|
|
|
Call<WatchRepository> call;
|
|
|
|
|
|
|
|
call = RetrofitClient
|
2019-11-13 16:52:49 +01:00
|
|
|
.getInstance(instanceUrl, getApplicationContext())
|
2019-10-12 11:00:36 +02:00
|
|
|
.getApiInterface()
|
|
|
|
.checkRepoWatchStatus(instanceToken, owner, repo);
|
|
|
|
|
|
|
|
call.enqueue(new Callback<WatchRepository>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResponse(@NonNull Call<WatchRepository> call, @NonNull retrofit2.Response<WatchRepository> response) {
|
|
|
|
|
|
|
|
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
|
|
|
|
|
|
|
if(response.code() == 200) {
|
|
|
|
assert response.body() != null;
|
|
|
|
if(response.body().getSubscribed()) {
|
|
|
|
tinyDb.putBoolean("repositoryWatchStatus", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tinyDb.putBoolean("repositoryWatchStatus", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(@NonNull Call<WatchRepository> call, @NonNull Throwable t) {
|
|
|
|
Log.e("onFailure", t.toString());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-06-03 23:25:05 +02:00
|
|
|
}
|