use of com.khmelenko.lab.varis.network.response.Job in project Varis-Android by dkhmelenko.
the class TestBuildDetailsPresenter method testStartLoadingDataManyJobs.
@Test
public void testStartLoadingDataManyJobs() {
final long buildId = 1L;
final String slug = "test";
final Build build = new Build();
final Commit commit = new Commit();
final List<Job> jobs = new ArrayList<>();
final Job job1 = new Job();
jobs.add(job1);
final Job job2 = new Job();
jobs.add(job2);
BuildDetails buildDetails = new BuildDetails();
buildDetails.setBuild(build);
buildDetails.setCommit(commit);
buildDetails.setJobs(jobs);
when(mTravisRestClient.getApiService().getBuild(slug, buildId)).thenReturn(buildDetails);
mBuildsDetailsPresenter.startLoadingData(null, slug, buildId);
verify(mTaskManager).getBuildDetails(slug, buildId);
verify(mBuildDetailsView).showProgress();
verify(mBuildDetailsView).hideProgress();
verify(mBuildDetailsView).updateBuildDetails(buildDetails);
verify(mBuildDetailsView).showBuildJobs(jobs);
}
use of com.khmelenko.lab.varis.network.response.Job in project Varis-Android by dkhmelenko.
the class TestBuildDetailsPresenter method testStartLoadingDataSingleJob.
@Test
public void testStartLoadingDataSingleJob() {
final long buildId = 1L;
final String slug = "test";
final Build build = new Build();
final Commit commit = new Commit();
final List<Job> jobs = new ArrayList<>();
final Job job = new Job();
jobs.add(job);
BuildDetails buildDetails = new BuildDetails();
buildDetails.setBuild(build);
buildDetails.setCommit(commit);
buildDetails.setJobs(jobs);
final String expectedUrl = "https://sample.org";
Response response = new Response(expectedUrl, 200, "", Collections.<Header>emptyList(), null);
final String accessToken = "test";
final String authToken = "token " + accessToken;
AppSettings.putAccessToken("test");
when(mRawClient.getApiService().getLog(authToken, String.valueOf(job.getId()))).thenReturn(response);
when(mTravisRestClient.getApiService().getBuild(slug, buildId)).thenReturn(buildDetails);
mBuildsDetailsPresenter.startLoadingData(null, slug, buildId);
verify(mTaskManager).getBuildDetails(slug, buildId);
verify(mBuildDetailsView).showProgress();
verify(mBuildDetailsView).hideProgress();
verify(mBuildDetailsView).updateBuildDetails(buildDetails);
verify(mBuildDetailsView).showBuildLogs();
verify(mBuildDetailsView).showAdditionalActionsForBuild(buildDetails);
}
use of com.khmelenko.lab.varis.network.response.Job in project Varis-Android by dkhmelenko.
the class JobsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_jobs, container, false);
ButterKnife.bind(this, view);
mJobsRecyclerView.setNestedScrollingEnabled(false);
mJobsRecyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
mJobsRecyclerView.setLayoutManager(layoutManager);
mJobsListAdapter = new JobsListAdapter(getContext(), mJobs, new OnListItemListener() {
@Override
public void onItemSelected(int position) {
if (mJobs != null && !mJobs.isEmpty()) {
Job job = mJobs.get(position);
mListener.onJobSelected(job);
}
}
});
mJobsRecyclerView.setAdapter(mJobsListAdapter);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int itemHeight = (int) ((mJobsListAdapter.getItemHeight() * metrics.density) + 0.5);
mJobsRecyclerView.getLayoutParams().height = itemHeight * mJobsListAdapter.getItemCount();
return view;
}
use of com.khmelenko.lab.varis.network.response.Job in project Varis-Android by dkhmelenko.
the class JobsListAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(JobViewHolder holder, int position) {
if (mJobs != null) {
Job job = mJobs.get(position);
// job data
holder.mNumber.setText(mContext.getString(R.string.build_details_job_number, job.getNumber()));
String state = job.getState();
if (!TextUtils.isEmpty(state)) {
int buildColor = BuildStateHelper.getBuildColor(state);
holder.mState.setText(state);
holder.mState.setTextColor(buildColor);
holder.mNumber.setTextColor(buildColor);
Drawable drawable = BuildStateHelper.getBuildImage(state);
if (drawable != null) {
holder.mNumber.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
}
}
// duration
if (BuildStateHelper.isPassed(job.getState())) {
Date started = DateTimeUtils.parseXmlDateTime(job.getStartedAt());
Date finished = DateTimeUtils.parseXmlDateTime(job.getFinishedAt());
long durationInSeconds = (finished.getTime() - started.getTime()) / 1000L;
String duration = TimeConverter.durationToString(durationInSeconds);
duration = mContext.getString(R.string.build_details_job_duration, duration);
holder.mDuration.setText(duration);
} else {
String stateInProgress = mContext.getString(R.string.build_details_job_in_progress);
String duration = mContext.getString(R.string.build_details_job_duration, stateInProgress);
holder.mDuration.setText(duration);
}
}
}
Aggregations