Search in sources :

Example 1 with Job

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);
}
Also used : Commit(com.khmelenko.lab.varis.network.response.Commit) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) Build(com.khmelenko.lab.varis.network.response.Build) ArrayList(java.util.ArrayList) Job(com.khmelenko.lab.varis.network.response.Job) Test(org.junit.Test)

Example 2 with Job

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);
}
Also used : Response(retrofit.client.Response) Commit(com.khmelenko.lab.varis.network.response.Commit) BuildDetails(com.khmelenko.lab.varis.network.response.BuildDetails) Build(com.khmelenko.lab.varis.network.response.Build) ArrayList(java.util.ArrayList) Job(com.khmelenko.lab.varis.network.response.Job) Test(org.junit.Test)

Example 3 with Job

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;
}
Also used : JobsListAdapter(com.khmelenko.lab.varis.adapter.JobsListAdapter) OnListItemListener(com.khmelenko.lab.varis.adapter.OnListItemListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Job(com.khmelenko.lab.varis.network.response.Job) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DisplayMetrics(android.util.DisplayMetrics)

Example 4 with Job

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);
        }
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) Job(com.khmelenko.lab.varis.network.response.Job) Date(java.util.Date)

Aggregations

Job (com.khmelenko.lab.varis.network.response.Job)4 Build (com.khmelenko.lab.varis.network.response.Build)2 BuildDetails (com.khmelenko.lab.varis.network.response.BuildDetails)2 Commit (com.khmelenko.lab.varis.network.response.Commit)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Drawable (android.graphics.drawable.Drawable)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1 JobsListAdapter (com.khmelenko.lab.varis.adapter.JobsListAdapter)1 OnListItemListener (com.khmelenko.lab.varis.adapter.OnListItemListener)1 Date (java.util.Date)1 Response (retrofit.client.Response)1