This repository has been archived by the owner on Jun 12, 2018. It is now read-only.
/
Model.java
64 lines (54 loc) · 1.96 KB
/
Model.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.parse.anydevice.models;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import com.parse.ParseClassName;
import com.parse.ParseFile;
import com.parse.ParseImageView;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.concurrent.TimeUnit;
/**
* Model represents the device and the application it's running
*/
@ParseClassName(Model.PARSE_CLASS_NAME)
public class Model extends ParseObject {
public static final String PARSE_CLASS_NAME = "Model";
public static final String DEFAULT = "default";
public static final String BOARD_TYPE = "boardType";
public static final String APP_NAME = "appName";
public static final String ICON = "icon";
public Model() {}
public boolean isDefault() {
return getBoolean(DEFAULT);
}
public String getBoardType() {
return getString(BOARD_TYPE);
}
public String getAppName() {
return getString(APP_NAME);
}
/**
* Helper to put image from URL in ImageView
*
* @param model {@link Model}
* @param imageView ParseImageView to have application logo
* @param drawableRes Drawable for the placeholder icon
*/
public static void putLogoIntoImageView(final Model model, @NonNull final ParseImageView imageView, @DrawableRes final int drawableRes) {
final ParseFile imagePtr = (ParseFile) model.get(Model.ICON);
imageView.setPlaceholder(imageView.getResources().getDrawable(drawableRes));
imageView.setParseFile(imagePtr);
imageView.loadInBackground();
}
/**
* Helper to create a query with a cache
*
* @return Model query
*/
public static ParseQuery<Model> getQuery() {
final ParseQuery<Model> query = ParseQuery.getQuery(Model.class);
query.setMaxCacheAge(TimeUnit.DAYS.toMillis(30));
query.setCachePolicy(ParseQuery.CachePolicy.CACHE_THEN_NETWORK);
return query;
}
}