Skip to content

Commit

Permalink
Time left/past badge added
Browse files Browse the repository at this point in the history
  • Loading branch information
Motoaleks committed Jan 6, 2018
1 parent 620200e commit d1137ac
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
/*
* Copyright 2017 Aleksandr Smilyanskiy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mobile.ui.milestone;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.github.mobile.R;
import com.github.mobile.ui.DialogFragment;

import org.eclipse.egit.github.core.Milestone;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import static com.github.mobile.Intents.EXTRA_MILESTONE;


/**
* Created by Александр on 20.12.2017.
* Fragment to display a milestone.
*
*/

public class MilestoneFragment extends DialogFragment {
private Milestone milestone;

Expand All @@ -32,6 +48,7 @@ public class MilestoneFragment extends DialogFragment {
private TextView milestoneDescription;
private ProgressBar milestoneProgress;
private TextView milestoneProgressPercentage;
private TextView milestoneTime;

@Override
public void onAttach(Context context) {
Expand All @@ -55,6 +72,7 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
milestoneDescription = (TextView) finder.find(R.id.tv_milestone_description);
milestoneProgress = (ProgressBar) finder.find(R.id.pB_milestone_completion_progress);
milestoneProgressPercentage = (TextView) finder.find(R.id.tv_milestone_progress_percentage);
milestoneTime = (TextView) finder.find(R.id.tv_milestone_time);
}

@Override
Expand Down Expand Up @@ -92,5 +110,24 @@ private void updateMilestone(final Milestone milestone){
int progress = totalIssues == 0 ? 0 : milestone.getClosedIssues() * 100 / totalIssues;
milestoneProgress.setProgress(progress);
milestoneProgressPercentage.setText(String.valueOf(progress));

Date dueOn = milestone.getDueOn();
Date current = Calendar.getInstance().getTime();

long diff = dueOn.getTime() - current.getTime();
long days = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
GradientDrawable back = (GradientDrawable) milestoneTime.getBackground();
if (-100 <= days && days < 0){
milestoneTime.setText("past due by " + (-days) + " days");
back.setColor(getResources().getColor(R.color.badge_red));
}
else if (0 <= days && days <= 100){
milestoneTime.setText(days + " days");
back.setColor(getResources().getColor(R.color.badge_default));
}
else {
milestoneTime.setText("");
back.setColor(getResources().getColor(R.color.background));
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/res/drawable/rounded_corners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="@color/background" />

<solid android:color="#ffffff" />

<padding
android:left="3dp"
android:right="3dp"
android:top="3dp"
android:bottom="3dp"/>

<corners android:radius="5dp" />
</shape>
25 changes: 22 additions & 3 deletions app/src/main/res/layout/repo_milestone_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,28 @@
android:paddingStart="?android:attr/listPreferredItemPaddingEnd"
android:paddingTop="10dp">

<TextView
android:id="@+id/tv_milestone_name"
style="@style/TitleText" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
android:id="@+id/tv_milestone_name"
style="@style/TitleText"
android:layout_weight="1" />

<TextView
android:background="@drawable/rounded_corners"
android:id="@+id/tv_milestone_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="end"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:textAlignment="viewEnd"
android:textColor="@android:color/white" />
</LinearLayout>

<TextView
android:id="@+id/tv_milestone_due_to"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
<color name="issue_event_red">#BD2C00</color>
<color name="issue_event_green">#6CC644</color>
<color name="notification_unread">#4078C0</color>
<color name="badge_default">#616161</color>
<color name="badge_red">#bf360c</color>

<color name="color_primary">#3F51B5</color>
<color name="color_primary_dark">#1A237E</color>
Expand Down

0 comments on commit d1137ac

Please sign in to comment.