package com.michaldabski.filemanager.favourites;

import java.io.File;

import android.content.Context;

import com.michaldabski.filemanager.nav_drawer.NavDrawerShortcut;
import com.michaldabski.msqlite.Annotations.PrimaryKey;

public class FavouriteFolder extends NavDrawerShortcut
{
	private String label;
	@PrimaryKey
	private String path;
	Integer order = null;
	
	public FavouriteFolder()
	{
		
	}
	
	public FavouriteFolder(File folder, String label)
	{
		this();
		if (folder.isDirectory() == false)
			throw new RuntimeException(folder.getName()+" is not a directory");
		this.path = folder.getAbsolutePath();
		this.label = label;
	}
	
	public FavouriteFolder(File folder)
	{
		this(folder, folder.getName());
	}
	
	public FavouriteFolder(String path, String label) 
	{
		this(new File(path), label);
	}

	public File getFile()
	{
		return new File(path);
	}
	
	@Override
	public boolean equals(Object o)
	{
		if (o instanceof FavouriteFolder)
			return ((FavouriteFolder) o).path.equals(path);
		else if (o instanceof File)
			return o.equals(getFile());
		return super.equals(o);
	}
	
	@Override
	public String toString()
	{
		return label;
	}
	
	@Override
	public int hashCode()
	{
		return getFile().hashCode();
	}
	
	public void setOrder(int order)
	{
		this.order = order;
	}
	
	public int getOrder()
	{
		return order;
	}
	
	public boolean exists()
	{
		return getFile().exists();
	}

	@Override
	public CharSequence getTitle(Context context)
	{
		return label;
	}

}

@@ -275,16 +275,55 @@
 Shortcut
+ implements Comparable%3CFavouriteFolder%3E
 %0A%7B%0A%09priv
@@ -393,15 +393,8 @@
 rder
- = null
 ;%0A%09%0A
@@ -1506,10 +1506,193 @@
 el;%0A%09%7D%0A%0A
+%09@Override%0A%09public int compareTo(FavouriteFolder another)%0A%09%7B%0A%09%09if (order == null)%0A%09%09%09return -1;%0A%09%09if (another.order == null)%0A%09%09%09return 1;%0A%09%09return order.compareTo(another.order);%0A%09%7D%0A%0A
 %7D%0A

Implement comparable