Moved category color generation into geofavorite model
This commit is contained in:
parent
4592bb3382
commit
b9dbde7f7c
@ -62,7 +62,6 @@ import retrofit2.Response;
|
|||||||
public class GeofavoriteDetailActivity extends AppCompatActivity implements LocationListener, ActivityCompat.OnRequestPermissionsResultCallback {
|
public class GeofavoriteDetailActivity extends AppCompatActivity implements LocationListener, ActivityCompat.OnRequestPermissionsResultCallback {
|
||||||
|
|
||||||
public static final String TAG = "GeofavDetail";
|
public static final String TAG = "GeofavDetail";
|
||||||
public static final String DEFAULT_CATEGORY = "Personal";
|
|
||||||
public static final int MINIMUM_ACCEPTABLE_ACCURACY = 50; // In meters
|
public static final int MINIMUM_ACCEPTABLE_ACCURACY = 50; // In meters
|
||||||
public static final String ARG_GEOFAVORITE = "geofav";
|
public static final String ARG_GEOFAVORITE = "geofav";
|
||||||
private static final int PERMISSION_REQUEST_CODE = 9999;
|
private static final int PERMISSION_REQUEST_CODE = 9999;
|
||||||
@ -120,7 +119,7 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
|
|||||||
} else {
|
} else {
|
||||||
// New geofavorite
|
// New geofavorite
|
||||||
mGeofavorite = new Geofavorite();
|
mGeofavorite = new Geofavorite();
|
||||||
mGeofavorite.setCategory(DEFAULT_CATEGORY);
|
mGeofavorite.setCategory(Geofavorite.DEFAULT_CATEGORY);
|
||||||
mGeofavorite.setDateCreated(System.currentTimeMillis() / 1000);
|
mGeofavorite.setDateCreated(System.currentTimeMillis() / 1000);
|
||||||
mGeofavorite.setDateModified(System.currentTimeMillis() / 1000);
|
mGeofavorite.setDateModified(System.currentTimeMillis() / 1000);
|
||||||
mViewHolder.hideActions();
|
mViewHolder.hideActions();
|
||||||
|
@ -20,14 +20,11 @@
|
|||||||
|
|
||||||
package it.danieleverducci.nextcloudmaps.model;
|
package it.danieleverducci.nextcloudmaps.model;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.databinding.BaseObservable;
|
|
||||||
import androidx.databinding.Bindable;
|
|
||||||
import androidx.databinding.BindingAdapter;
|
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
@ -38,9 +35,10 @@ import org.threeten.bp.ZoneId;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class Geofavorite implements Serializable {
|
public class Geofavorite implements Serializable {
|
||||||
|
public static final String DEFAULT_CATEGORY = "Personal";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON Definition:
|
* JSON Definition:
|
||||||
* {
|
* {
|
||||||
@ -164,6 +162,27 @@ public class Geofavorite implements Serializable {
|
|||||||
return getLat() != 0 && getLng() != 0 && getName() != null && getName().length() > 0;
|
return getLat() != 0 && getLng() != 0 && getName() != null && getName().length() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Based on Nextcloud Maps's getLetterColor util.
|
||||||
|
* Assigns a color to a category based on its two first letters.
|
||||||
|
*
|
||||||
|
* @see "https://github.com/nextcloud/maps/blob/master/src/utils.js"
|
||||||
|
* @return the generated color or null for the default category
|
||||||
|
*/
|
||||||
|
public int categoryColor() {
|
||||||
|
// If category is default, return null: will be used Nextcloud's accent
|
||||||
|
if (this.category.equals(DEFAULT_CATEGORY))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
float letter1Index = this.category.toLowerCase().charAt(0);
|
||||||
|
float letter2Index = this.category.toLowerCase().charAt(1);
|
||||||
|
float letterCoef = ((letter1Index * letter2Index) % 100) / 100;
|
||||||
|
float h = letterCoef * 360;
|
||||||
|
float s = 75 + letterCoef * 10;
|
||||||
|
float l = 50 + letterCoef * 10;
|
||||||
|
return Color.HSVToColor( new float[]{ Math.round(h), Math.round(s), Math.round(l) });
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package it.danieleverducci.nextcloudmaps.utils;
|
|
||||||
|
|
||||||
public class Color {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Based on Nextcloud Maps's getLetterColor util
|
|
||||||
* @see "https://github.com/nextcloud/maps/blob/master/src/utils.js"
|
|
||||||
* @param catName category name
|
|
||||||
*/
|
|
||||||
public static generareCategoryColor(String catName) {
|
|
||||||
// If category is default, return default color
|
|
||||||
|
|
||||||
// Else
|
|
||||||
int letter1Index = letter1.toLowerCase().charCodeAt(0);
|
|
||||||
int letter2Index = letter2.toLowerCase().charCodeAt(0);
|
|
||||||
var letterCoef = ((letter1Index * letter2Index) % 100) / 100;
|
|
||||||
var h = letterCoef * 360;
|
|
||||||
var s = 75 + letterCoef * 10;
|
|
||||||
var l = 50 + letterCoef * 10;
|
|
||||||
return {h: Math.round(h), s: Math.round(s), l: Math.round(l)};
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user