FreeRDP
Loading...
Searching...
No Matches
com.freerdp.freerdpcore.presentation.BookmarkViewModel Class Reference
Inheritance diagram for com.freerdp.freerdpcore.presentation.BookmarkViewModel:
Collaboration diagram for com.freerdp.freerdpcore.presentation.BookmarkViewModel:

Public Member Functions

 BookmarkViewModel (@NonNull Application application)
 
LiveData< BookmarkBase > getBookmarkLiveData ()
 
LiveData< Boolean > getSaveCompleteEvent ()
 
BookmarkBase getBookmark ()
 
boolean isSettingsChanged ()
 
void setSettingsChanged (boolean changed)
 
boolean isNewBookmark ()
 
void setNewBookmark (boolean isNew)
 
void loadBookmark (Bundle bundle, SharedPreferences prefs)
 
void saveBookmark (SharedPreferences prefs)
 

Protected Member Functions

void onCleared ()
 

Detailed Description

Definition at line 31 of file BookmarkViewModel.java.

Constructor & Destructor Documentation

◆ BookmarkViewModel()

com.freerdp.freerdpcore.presentation.BookmarkViewModel.BookmarkViewModel ( @NonNull Application  application)
inline

Definition at line 48 of file BookmarkViewModel.java.

49 {
50 super(application);
51 manualBookmarkGateway =
52 new ManualBookmarkGateway(AppDatabase.getInstance(application).bookmarkDao());
53 quickConnectHistoryGateway =
54 new QuickConnectHistoryGateway(HistoryDatabase.getInstance(application).historyDao());
55 }

Member Function Documentation

◆ getBookmark()

BookmarkBase com.freerdp.freerdpcore.presentation.BookmarkViewModel.getBookmark ( )
inline

Definition at line 67 of file BookmarkViewModel.java.

68 {
69 return bookmarkLiveData.getValue();
70 }

◆ getBookmarkLiveData()

LiveData< BookmarkBase > com.freerdp.freerdpcore.presentation.BookmarkViewModel.getBookmarkLiveData ( )
inline

Definition at line 57 of file BookmarkViewModel.java.

58 {
59 return bookmarkLiveData;
60 }

◆ getSaveCompleteEvent()

LiveData< Boolean > com.freerdp.freerdpcore.presentation.BookmarkViewModel.getSaveCompleteEvent ( )
inline

Definition at line 62 of file BookmarkViewModel.java.

63 {
64 return saveCompleteEvent;
65 }

◆ isNewBookmark()

boolean com.freerdp.freerdpcore.presentation.BookmarkViewModel.isNewBookmark ( )
inline

Definition at line 82 of file BookmarkViewModel.java.

83 {
84 return newBookmark;
85 }

◆ isSettingsChanged()

boolean com.freerdp.freerdpcore.presentation.BookmarkViewModel.isSettingsChanged ( )
inline

Definition at line 72 of file BookmarkViewModel.java.

73 {
74 return settingsChanged;
75 }

◆ loadBookmark()

void com.freerdp.freerdpcore.presentation.BookmarkViewModel.loadBookmark ( Bundle  bundle,
SharedPreferences  prefs 
)
inline

Definition at line 96 of file BookmarkViewModel.java.

97 {
98 if (bookmarkLiveData.getValue() != null)
99 return;
100
101 executor.execute(() -> {
102 BookmarkBase bookmark = null;
103 boolean isNew = false;
104
105 if (bundle != null && bundle.containsKey(BookmarkActivity.PARAM_CONNECTION_REFERENCE))
106 {
107 String refStr = bundle.getString(BookmarkActivity.PARAM_CONNECTION_REFERENCE);
108
109 if (ConnectionReference.isBookmarkReference(refStr))
110 {
111 bookmark =
112 manualBookmarkGateway.findById(ConnectionReference.getBookmarkId(refStr));
113 isNew = false;
114 }
115 else if (ConnectionReference.isHostnameReference(refStr))
116 {
117 bookmark = new BookmarkBase();
118 bookmark.setLabel(ConnectionReference.getHostname(refStr));
119 bookmark.setHostname(ConnectionReference.getHostname(refStr));
120 isNew = true;
121 }
122 else if (ConnectionReference.isFileReference(refStr))
123 {
124 String file = ConnectionReference.getFile(refStr);
125 bookmark = new BookmarkBase();
126 bookmark.setLabel(file);
127 try
128 {
129 RDPFileParser rdpFile = new RDPFileParser(file);
130 updateBookmarkFromFile(bookmark, rdpFile);
131 bookmark.setLabel(new File(file).getName());
132 isNew = true;
133 }
134 catch (IOException e)
135 {
136 Log.e(TAG, "Failed reading RDP file", e);
137 }
138 }
139 }
140
141 if (bookmark == null)
142 {
143 bookmark = new BookmarkBase();
144 }
145
146 this.newBookmark = isNew;
147 this.settingsChanged = false;
148
149 // Clear TEMP SharedPreferences and write fresh data BEFORE posting to UI
150 prefs.edit().clear().apply();
151 bookmark.writeToSharedPreferences(prefs);
152
153 // Notify Activity that loading is complete on the Main Thread
154 bookmarkLiveData.postValue(bookmark);
155 });
156 }

◆ onCleared()

void com.freerdp.freerdpcore.presentation.BookmarkViewModel.onCleared ( )
inlineprotected

Definition at line 228 of file BookmarkViewModel.java.

229 {
230 super.onCleared();
231 executor.shutdown(); // Clean up threads when ViewModel dies
232 }

◆ saveBookmark()

void com.freerdp.freerdpcore.presentation.BookmarkViewModel.saveBookmark ( SharedPreferences  prefs)
inline

Definition at line 158 of file BookmarkViewModel.java.

159 {
160 BookmarkBase bookmark = getBookmark();
161 if (bookmark == null)
162 return;
163
164 executor.execute(() -> {
165 bookmark.readFromSharedPreferences(prefs);
166
167 if (bookmark.getType() == BookmarkBase.TYPE_MANUAL)
168 {
169 quickConnectHistoryGateway.removeHistoryItem(bookmark.getHostname());
170
171 if (bookmark.getId() > 0)
172 {
173 manualBookmarkGateway.update(bookmark);
174 }
175 else
176 {
177 manualBookmarkGateway.insert(bookmark);
178 }
179 }
180
181 // Notify Activity to close
182 saveCompleteEvent.postValue(true);
183 });
184 }

◆ setNewBookmark()

void com.freerdp.freerdpcore.presentation.BookmarkViewModel.setNewBookmark ( boolean  isNew)
inline

Definition at line 87 of file BookmarkViewModel.java.

88 {
89 newBookmark = isNew;
90 }

◆ setSettingsChanged()

void com.freerdp.freerdpcore.presentation.BookmarkViewModel.setSettingsChanged ( boolean  changed)
inline

Definition at line 77 of file BookmarkViewModel.java.

78 {
79 settingsChanged = changed;
80 }

The documentation for this class was generated from the following file: