Android Open Source - syncarnet Synced Device






From Project

Back to project page syncarnet.

License

The source code is released under:

GNU General Public License

If you think the Android project syncarnet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 Nicolas Miller, Florian Paindorge
 *//w  w w.  j  a  va 2 s.co m
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package fr.syncarnet.sync;

import fr.syncarnet.tasks.*;
import fr.syncarnet.*;
import java.io.Serializable;
import java.util.Date; // rightNow = new Date().getTime(); (In Unix Time)
import java.util.UUID;
import java.text.DateFormat;

public class SyncedDevice implements Serializable {
  private String name;
  private String id;
  private long lastSynchronized; // unix timestamp

  public SyncedDevice(String name, String id) {
    this.name = name;
    this.id = id;
    this.lastSynchronized = new Date().getTime();
  }

  public void updated() {
    this.lastSynchronized = new Date().getTime();
  }

  public long lastSynchronized() {
    return this.lastSynchronized;
  }

  public String getId() {
    return this.id;
  }

  public TaskList buildDifferentialTaskList(TaskList tl) {
    TaskList diffTaskList = new TaskList();
    for (Task t : tl) {
      if (t.getEntry() >= lastSynchronized || t.getModified() >= lastSynchronized) {
        diffTaskList.add(t);
      }
    }

    // Retrieve deleted tasks that needs to be synchronized
    DeletedTasks deletedTasks = tl.getDeletedTasks();
    DeletedTasks diffDeletedTasks = new DeletedTasks();
    for (UUID uuid : deletedTasks) {
      if (deletedTasks.getTimestamp(uuid) < lastSynchronized) {
        diffDeletedTasks.add(uuid, deletedTasks.getTimestamp(uuid));
      }
    }
    diffTaskList.setDeletedTasks(diffDeletedTasks);

    return diffTaskList;
  }

  public String toString() {
    // The toString is used in the ArrayAdapter
    String lastSyncDate = DateFormat.getDateInstance().format(new Date(lastSynchronized));
    return name + " (" + lastSyncDate + ")";
  }
}




Java Source Code List

fr.syncarnet.ProjectsAdapter.java
fr.syncarnet.SynCarnet.java
fr.syncarnet.TaskAddFragment.java
fr.syncarnet.TaskEditFragment.java
fr.syncarnet.TaskListAdapter.java
fr.syncarnet.TaskListFragment.java
fr.syncarnet.helpers.PrioritySpinnerHelper.java
fr.syncarnet.sync.DeviceListActivity.java
fr.syncarnet.sync.PeerListAdapter.java
fr.syncarnet.sync.PeerListDialog.java
fr.syncarnet.sync.PeerList.java
fr.syncarnet.sync.PeerSelection.java
fr.syncarnet.sync.SynCarnetBroadcastReceiver.java
fr.syncarnet.sync.SyncBTService.java
fr.syncarnet.sync.SyncService.java
fr.syncarnet.sync.SyncedDevice.java
fr.syncarnet.sync.SyncedDevicesFragment.java
fr.syncarnet.sync.TaskListTransferService.java
fr.syncarnet.tasks.DeletedTasks.java
fr.syncarnet.tasks.Priority.java
fr.syncarnet.tasks.TaskList.java
fr.syncarnet.tasks.Task.java