FreeRDP
Loading...
Searching...
No Matches
ShortcutsViewModel.java
1/*
2 ViewModel for ShortcutsActivity
3
4 Copyright 2026 Ibrahim Sevinc <ibrahim.sevinc.mail@gmail.com>
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.presentation;
12
13import android.app.Application;
14
15import androidx.annotation.NonNull;
16import androidx.lifecycle.AndroidViewModel;
17import androidx.lifecycle.LiveData;
18import androidx.lifecycle.MutableLiveData;
19
20import com.freerdp.freerdpcore.data.AppDatabase;
21import com.freerdp.freerdpcore.domain.BookmarkBase;
22import com.freerdp.freerdpcore.services.ManualBookmarkGateway;
23
24import java.util.Collections;
25import java.util.List;
26import java.util.concurrent.ExecutorService;
27import java.util.concurrent.Executors;
28
29public class ShortcutsViewModel extends AndroidViewModel
30{
31 private final MutableLiveData<List<BookmarkBase>> bookmarks =
32 new MutableLiveData<>(Collections.emptyList());
33 private final ExecutorService executor = Executors.newSingleThreadExecutor();
34 private final ManualBookmarkGateway manualBookmarkGateway;
35
36 public ShortcutsViewModel(@NonNull Application application)
37 {
38 super(application);
39 manualBookmarkGateway =
40 new ManualBookmarkGateway(AppDatabase.getInstance(application).bookmarkDao());
41 }
42
43 public LiveData<List<BookmarkBase>> getBookmarks()
44 {
45 return bookmarks;
46 }
47
48 public void loadBookmarks()
49 {
50 executor.execute(() -> bookmarks.postValue(manualBookmarkGateway.findAll()));
51 }
52
53 @Override protected void onCleared()
54 {
55 super.onCleared();
56 executor.shutdown();
57 }
58}