// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public class SensorData extends RealmObject {
//     public static final String ID = "id";
//     public static final String START_DATE = "startDate";
// 
//     public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct
//     public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
// 
//     @PrimaryKey
//     private String id;
//     private long startDate = -1;
// 
//     public SensorData() {}
// 
//     public SensorData(RawTagData rawTagData) {
//         id = String.format(Locale.US, "sensor_%s", rawTagData.getTagId());
//         startDate = rawTagData.getDate() - (rawTagData.getDate() % TimeUnit.MINUTES.toMillis(1))
//                 - TimeUnit.MINUTES.toMillis(rawTagData.getSensorAgeInMinutes());
//     }
// 
//     public SensorData(SensorData sensor) {
//         this.id = sensor.id;
//         this.startDate = sensor.getStartDate();
//     }
// 
//     public String getTagId() {
//         return id.substring(7);
//     }
// 
//     public long getTimeLeft() {
//         return max(0, startDate + TimeUnit.MINUTES.toMillis(maxSensorAgeInMinutes) - System.currentTimeMillis());
//     }
// 
//     public long getStartDate() {
//         return startDate;
//     }
// 
//     public String getId() {
//         return id;
//     }
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static String getDurationBreakdown(Resources resources, long duration)
// {
//     duration = max(0, duration);
// 
//     long days = TimeUnit.MILLISECONDS.toDays(duration);
//     duration -= TimeUnit.DAYS.toMillis(days);
//     long hours = TimeUnit.MILLISECONDS.toHours(duration);
//     duration -= TimeUnit.HOURS.toMillis(hours);
//     long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
// 
//     if (days > 1) {
//         return days + " " + resources.getString(R.string.days);
//     }
//     if (days == 1) {
//         return "1 " + resources.getString(R.string.day);
//     }
//     if (hours > 1) {
//         return hours + " " + resources.getString(R.string.hours);
//     }
//     if (hours == 1) {
//         return "1 " + resources.getString(R.string.hour);
//     }
//     if (minutes > 1) {
//         return minutes + " " + resources.getString(R.string.minutes);
//     }
//     if (minutes == 1) {
//         return "1 " + resources.getString(R.string.minute);
//     }
// 
//     return "0 " + resources.getString(R.string.minutes);
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final String START_DATE = "startDate";


import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import de.dorianscholz.openlibre.R;
import de.dorianscholz.openlibre.model.SensorData;
import io.realm.Realm;
import io.realm.RealmResults;
import io.realm.Sort;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.getDurationBreakdown;
import static de.dorianscholz.openlibre.model.SensorData.START_DATE;
package de.dorianscholz.openlibre.ui;






public class SensorStatusFragment extends DialogFragment {
    public SensorStatusFragment() {
        // Required empty public constructor
    }

    public static SensorStatusFragment newInstance() {
        SensorStatusFragment fragment = new SensorStatusFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    public void setupUi(View view) {
        Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public class SensorData extends RealmObject {
//     public static final String ID = "id";
//     public static final String START_DATE = "startDate";
// 
//     public static final long minSensorAgeInMinutes = 60; // data generated by the sensor in the first 60 minutes is not correct
//     public static final long maxSensorAgeInMinutes = TimeUnit.DAYS.toMinutes(14); // data generated by the sensor after 14 days also has faults
// 
//     @PrimaryKey
//     private String id;
//     private long startDate = -1;
// 
//     public SensorData() {}
// 
//     public SensorData(RawTagData rawTagData) {
//         id = String.format(Locale.US, "sensor_%s", rawTagData.getTagId());
//         startDate = rawTagData.getDate() - (rawTagData.getDate() % TimeUnit.MINUTES.toMillis(1))
//                 - TimeUnit.MINUTES.toMillis(rawTagData.getSensorAgeInMinutes());
//     }
// 
//     public SensorData(SensorData sensor) {
//         this.id = sensor.id;
//         this.startDate = sensor.getStartDate();
//     }
// 
//     public String getTagId() {
//         return id.substring(7);
//     }
// 
//     public long getTimeLeft() {
//         return max(0, startDate + TimeUnit.MINUTES.toMillis(maxSensorAgeInMinutes) - System.currentTimeMillis());
//     }
// 
//     public long getStartDate() {
//         return startDate;
//     }
// 
//     public String getId() {
//         return id;
//     }
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/OpenLibre.java
// public static RealmConfiguration realmConfigProcessedData;
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/AlgorithmUtil.java
// public static String getDurationBreakdown(Resources resources, long duration)
// {
//     duration = max(0, duration);
// 
//     long days = TimeUnit.MILLISECONDS.toDays(duration);
//     duration -= TimeUnit.DAYS.toMillis(days);
//     long hours = TimeUnit.MILLISECONDS.toHours(duration);
//     duration -= TimeUnit.HOURS.toMillis(hours);
//     long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
// 
//     if (days > 1) {
//         return days + " " + resources.getString(R.string.days);
//     }
//     if (days == 1) {
//         return "1 " + resources.getString(R.string.day);
//     }
//     if (hours > 1) {
//         return hours + " " + resources.getString(R.string.hours);
//     }
//     if (hours == 1) {
//         return "1 " + resources.getString(R.string.hour);
//     }
//     if (minutes > 1) {
//         return minutes + " " + resources.getString(R.string.minutes);
//     }
//     if (minutes == 1) {
//         return "1 " + resources.getString(R.string.minute);
//     }
// 
//     return "0 " + resources.getString(R.string.minutes);
// }
// 
// Path: app/src/main/java/de/dorianscholz/openlibre/model/SensorData.java
// public static final String START_DATE = "startDate";


// Path: app/src/main/java/de/dorianscholz/openlibre/ui/SensorStatusFragment.java
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import de.dorianscholz.openlibre.R;
import de.dorianscholz.openlibre.model.SensorData;
import io.realm.Realm;
import io.realm.RealmResults;
import io.realm.Sort;
import static de.dorianscholz.openlibre.OpenLibre.realmConfigProcessedData;
import static de.dorianscholz.openlibre.model.AlgorithmUtil.getDurationBreakdown;
import static de.dorianscholz.openlibre.model.SensorData.START_DATE;

package de.dorianscholz.openlibre.ui;






public class SensorStatusFragment extends DialogFragment {
    public SensorStatusFragment() {
        // Required empty public constructor
    }

    public static SensorStatusFragment newInstance() {
        SensorStatusFragment fragment = new SensorStatusFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    public void setupUi(View view) {
        Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData);
        RealmResults<SensorData> sensorDataResults = realmProcessedData.where(SensorData.class).