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 38 of file BookmarkViewModel.java.

Constructor & Destructor Documentation

◆ BookmarkViewModel()

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

Definition at line 55 of file BookmarkViewModel.java.

56 {
57 super(application);
58 manualBookmarkGateway =
59 new ManualBookmarkGateway(AppDatabase.getInstance(application).bookmarkDao());
60 quickConnectHistoryGateway =
61 new QuickConnectHistoryGateway(HistoryDatabase.getInstance(application).historyDao());
62 }

Member Function Documentation

◆ getBookmark()

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

Definition at line 74 of file BookmarkViewModel.java.

75 {
76 return bookmarkLiveData.getValue();
77 }

◆ getBookmarkLiveData()

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

Definition at line 64 of file BookmarkViewModel.java.

65 {
66 return bookmarkLiveData;
67 }

◆ getSaveCompleteEvent()

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

Definition at line 69 of file BookmarkViewModel.java.

70 {
71 return saveCompleteEvent;
72 }

◆ isNewBookmark()

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

Definition at line 89 of file BookmarkViewModel.java.

90 {
91 return newBookmark;
92 }

◆ isSettingsChanged()

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

Definition at line 79 of file BookmarkViewModel.java.

80 {
81 return settingsChanged;
82 }

◆ loadBookmark()

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

Definition at line 103 of file BookmarkViewModel.java.

104 {
105 if (bookmarkLiveData.getValue() != null)
106 return;
107
108 executor.execute(() -> {
109 BookmarkBase bookmark = null;
110 boolean isNew = false;
111
112 if (bundle != null && bundle.containsKey(BookmarkActivity.PARAM_CONNECTION_REFERENCE))
113 {
114 String refStr = bundle.getString(BookmarkActivity.PARAM_CONNECTION_REFERENCE);
115
116 if (ConnectionReference.isBookmarkReference(refStr))
117 {
118 bookmark =
119 manualBookmarkGateway.findById(ConnectionReference.getBookmarkId(refStr));
120 isNew = false;
121 }
122 else if (ConnectionReference.isHostnameReference(refStr))
123 {
124 bookmark = new BookmarkBase();
125 bookmark.setLabel(ConnectionReference.getHostname(refStr));
126 bookmark.setHostname(ConnectionReference.getHostname(refStr));
127 isNew = true;
128 }
129 else if (ConnectionReference.isFileReference(refStr))
130 {
131 String fileRef = ConnectionReference.getFile(refStr);
132 bookmark = new BookmarkBase();
133 String name = Uri.decode(new File(fileRef).getName());
134 String lower = name.toLowerCase(java.util.Locale.ROOT);
135 if (lower.endsWith(".rdp"))
136 name = name.substring(0, name.length() - 4);
137 else if (lower.endsWith(".rdpw"))
138 name = name.substring(0, name.length() - 5);
139 bookmark.setLabel(name);
140 try
141 {
142 Uri uri = Uri.parse(fileRef);
143 RDPFileHelper.importFrom(
144 getApplication().getContentResolver().openInputStream(uri), bookmark);
145 }
146 catch (IOException e)
147 {
148 Log.e(TAG, "Failed reading RDP file", e);
149 }
150 isNew = true;
151 }
152 }
153
154 if (bookmark == null)
155 {
156 bookmark = new BookmarkBase();
157 }
158
159 this.newBookmark = isNew;
160 this.settingsChanged = false;
161
162 // Clear TEMP SharedPreferences and write fresh data BEFORE posting to UI
163 prefs.edit().clear().apply();
164 bookmark.writeToSharedPreferences(prefs);
165
166 // Notify Activity that loading is complete on the Main Thread
167 bookmarkLiveData.postValue(bookmark);
168 });
169 }

◆ onCleared()

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

Definition at line 199 of file BookmarkViewModel.java.

200 {
201 super.onCleared();
202 executor.shutdown(); // Clean up threads when ViewModel dies
203 }

◆ saveBookmark()

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

Definition at line 171 of file BookmarkViewModel.java.

172 {
173 BookmarkBase bookmark = getBookmark();
174 if (bookmark == null)
175 return;
176
177 executor.execute(() -> {
178 bookmark.readFromSharedPreferences(prefs);
179
180 if (bookmark.getType() == BookmarkBase.TYPE_MANUAL)
181 {
182 quickConnectHistoryGateway.removeHistoryItem(bookmark.getHostname());
183
184 if (bookmark.getId() > 0)
185 {
186 manualBookmarkGateway.update(bookmark);
187 }
188 else
189 {
190 manualBookmarkGateway.insert(bookmark);
191 }
192 }
193
194 // Notify Activity to close
195 saveCompleteEvent.postValue(true);
196 });
197 }

◆ setNewBookmark()

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

Definition at line 94 of file BookmarkViewModel.java.

95 {
96 newBookmark = isNew;
97 }

◆ setSettingsChanged()

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

Definition at line 84 of file BookmarkViewModel.java.

85 {
86 settingsChanged = changed;
87 }

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