12
12
import android .support .annotation .NonNull ;
13
13
import android .support .annotation .Nullable ;
14
14
import android .support .v4 .app .NotificationCompat ;
15
+
16
+ import java .util .Collections ;
17
+
15
18
import de .jonasrottmann .realmbrowser .files .view .FilesActivity ;
16
- import de .jonasrottmann .realmbrowser .helper .RealmHolder ;
19
+ import de .jonasrottmann .realmbrowser .helper .DataHolder ;
17
20
import de .jonasrottmann .realmbrowser .models .view .ModelsActivity ;
18
21
import io .realm .RealmConfiguration ;
19
- import java .util .Collections ;
20
22
23
+ @ SuppressWarnings ({"unused" , "WeakerAccess" })
21
24
public final class RealmBrowser {
22
25
23
26
private static final int NOTIFICATION_ID = 1000 ;
24
27
25
28
/**
26
29
* @param context A valid {@link Context}
27
30
*/
28
- @ SuppressWarnings ("WeakerAccess" )
29
31
public static void startRealmFilesActivity (@ NonNull Context context ) {
30
32
context .startActivity (FilesActivity .getIntent (context ));
31
33
}
32
34
33
35
/**
34
- * @param context A valid {@link Context}
36
+ * @param context A valid {@link Context}
35
37
* @param realmFileName The name of the realm file to open.
36
38
*/
37
- @ SuppressWarnings ("WeakerAccess" )
38
39
public static void startRealmModelsActivity (@ NonNull Context context , @ NonNull String realmFileName ) {
39
40
RealmConfiguration config = new RealmConfiguration .Builder ().name (realmFileName ).build ();
40
41
startRealmModelsActivity (context , config );
41
42
}
42
43
43
44
/**
44
- * @param context A valid {@link Context}
45
+ * @param context A valid {@link Context}
45
46
* @param realmConfiguration The config of the realm to open.
46
47
*/
47
- @ SuppressWarnings ("WeakerAccess" )
48
48
public static void startRealmModelsActivity (@ NonNull Context context , @ NonNull RealmConfiguration realmConfiguration ) {
49
- RealmHolder .getInstance ().setRealmConfiguration ( realmConfiguration );
49
+ DataHolder .getInstance ().save ( DataHolder . DATA_HOLDER_KEY_CONFIG , realmConfiguration );
50
50
context .startActivity (ModelsActivity .getIntent (context ));
51
51
}
52
52
53
53
/**
54
54
* @param context A valid {@link Context}
55
55
*/
56
- @ SuppressWarnings ("WeakerAccess" )
57
56
public static void showRealmFilesNotification (@ NonNull Context context ) {
58
57
Intent notifyIntent = new Intent (context , FilesActivity .class );
59
58
notifyIntent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
@@ -62,22 +61,21 @@ public static void showRealmFilesNotification(@NonNull Context context) {
62
61
}
63
62
64
63
/**
65
- * @param context A valid {@link Context}
64
+ * @param context A valid {@link Context}
66
65
* @param realmConfiguration The config of the realm to open.
67
66
*/
68
- @ SuppressWarnings ("WeakerAccess" )
69
67
public static void showRealmModelsNotification (@ NonNull Context context , @ NonNull RealmConfiguration realmConfiguration ) {
70
- RealmHolder .getInstance ().setRealmConfiguration ( realmConfiguration );
68
+ DataHolder .getInstance ().save ( DataHolder . DATA_HOLDER_KEY_CONFIG , realmConfiguration );
71
69
Intent notifyIntent = ModelsActivity .getIntent (context );
72
70
PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 , notifyIntent , PendingIntent .FLAG_UPDATE_CURRENT );
73
71
showNotification (context , pendingIntent );
74
72
}
75
73
76
74
private static void showNotification (@ NonNull Context context , @ NonNull PendingIntent pendingIntent ) {
77
75
NotificationCompat .Builder builder = new NotificationCompat .Builder (context ).setSmallIcon (R .drawable .realm_browser_ic_rb )
78
- .setContentTitle (context .getString (R .string .realm_browser_title ))
79
- .setContentText (context .getApplicationContext ().getPackageName ())
80
- .setAutoCancel (false );
76
+ .setContentTitle (context .getString (R .string .realm_browser_title ))
77
+ .setContentText (context .getApplicationContext ().getPackageName ())
78
+ .setAutoCancel (false );
81
79
82
80
builder .setContentIntent (pendingIntent );
83
81
NotificationManager mNotificationManager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
@@ -89,17 +87,16 @@ private static void showNotification(@NonNull Context context, @NonNull PendingI
89
87
* @return The id of the added shortcut (<code>null</code> if this feature is not supported on the device). Is used if you want to remove this shortcut later on.
90
88
*/
91
89
@ TargetApi (Build .VERSION_CODES .N_MR1 )
92
- @ SuppressWarnings ("WeakerAccess" )
93
90
@ Nullable
94
91
public static String addFilesShortcut (@ NonNull Context context ) {
95
92
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N_MR1 ) {
96
93
final String id = "realm_browser_ac_files" ;
97
94
final ShortcutManager shortcutManager = context .getSystemService (ShortcutManager .class );
98
95
final ShortcutInfo shortcut = new ShortcutInfo .Builder (context , id ).setShortLabel ("Files" )
99
- .setLongLabel ("Open realm-browser files activity" )
100
- .setIcon (Icon .createWithResource (context , R .drawable .realm_browser_shortcut_rb ))
101
- .setIntent (FilesActivity .getIntent (context ).setAction (Intent .ACTION_VIEW ))
102
- .build ();
96
+ .setLongLabel ("Open realm-browser files activity" )
97
+ .setIcon (Icon .createWithResource (context , R .drawable .realm_browser_shortcut_rb ))
98
+ .setIntent (FilesActivity .getIntent (context ).setAction (Intent .ACTION_VIEW ))
99
+ .build ();
103
100
shortcutManager .addDynamicShortcuts (Collections .singletonList (shortcut ));
104
101
return id ;
105
102
} else {
@@ -108,25 +105,24 @@ public static String addFilesShortcut(@NonNull Context context) {
108
105
}
109
106
110
107
/**
111
- * @param context A valid {@link Context}
108
+ * @param context A valid {@link Context}
112
109
* @param realmConfiguration The config of the realm to open.
113
110
* @return The id of the added shortcut (<code>null</code> if this feature is not supported on the device). Is used if you want to remove this shortcut later on.
114
111
*/
115
112
@ TargetApi (Build .VERSION_CODES .N_MR1 )
116
- @ SuppressWarnings ("WeakerAccess" )
117
113
@ Nullable
118
114
public static String addModelsShortcut (@ NonNull Context context , @ NonNull RealmConfiguration realmConfiguration ) {
119
115
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N_MR1 ) {
120
- RealmHolder .getInstance ().setRealmConfiguration ( realmConfiguration );
116
+ DataHolder .getInstance ().save ( DataHolder . DATA_HOLDER_KEY_CONFIG , realmConfiguration );
121
117
final String id = "realm_browser_ac_models" ;
122
118
final ShortcutManager shortcutManager = context .getSystemService (ShortcutManager .class );
123
119
final ShortcutInfo shortcut = new ShortcutInfo .Builder (context , id ).setShortLabel ("Models" )
124
- .setLongLabel ("Open realm-browser models activity" )
125
- .setIcon (Icon .createWithResource (context , R .drawable .realm_browser_shortcut_rb ))
126
- .setIntents (new Intent [] {
127
- FilesActivity .getIntent (context ).setAction (Intent .ACTION_VIEW ), ModelsActivity .getIntent (context ).setAction (Intent .ACTION_VIEW )
128
- })
129
- .build ();
120
+ .setLongLabel ("Open realm-browser models activity" )
121
+ .setIcon (Icon .createWithResource (context , R .drawable .realm_browser_shortcut_rb ))
122
+ .setIntents (new Intent []{
123
+ FilesActivity .getIntent (context ).setAction (Intent .ACTION_VIEW ), ModelsActivity .getIntent (context ).setAction (Intent .ACTION_VIEW )
124
+ })
125
+ .build ();
130
126
shortcutManager .addDynamicShortcuts (Collections .singletonList (shortcut ));
131
127
return id ;
132
128
} else {
0 commit comments