Some fixes
This commit is contained in:
parent
a1b816030a
commit
4027a8b725
|
@ -202,6 +202,8 @@ public class DisplayStatusFragment extends Fragment implements AccountsHorizonta
|
|||
}
|
||||
}
|
||||
}
|
||||
FeedsVM viewModelFeeds = new ViewModelProvider(DisplayStatusFragment.this).get(FeedsVM.class);
|
||||
SearchVM viewModelSearch = new ViewModelProvider(DisplayStatusFragment.this).get(SearchVM.class);
|
||||
if (mLayoutManager != null) {
|
||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||
if (dy > 0) {
|
||||
|
@ -211,11 +213,9 @@ public class DisplayStatusFragment extends Fragment implements AccountsHorizonta
|
|||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
if (search_peertube == null) { //Not a Peertube search
|
||||
FeedsVM viewModel = new ViewModelProvider(DisplayStatusFragment.this).get(FeedsVM.class);
|
||||
viewModel.getVideos(type, max_id, null, null).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
viewModelFeeds.getVideos(type, max_id, null, null).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
} else {
|
||||
SearchVM viewModel = new ViewModelProvider(DisplayStatusFragment.this).get(SearchVM.class);
|
||||
viewModel.getVideos(max_id, search_peertube).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
viewModelSearch.getVideos(max_id, search_peertube).observe(DisplayStatusFragment.this.requireActivity(), apiResponse -> manageVIewVideos(apiResponse));
|
||||
}
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
|
|
@ -30,23 +30,19 @@ import app.fedilab.fedilabtube.client.PeertubeAPI;
|
|||
|
||||
public class AccountsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public AccountsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getAccounts(String max_id, String name, accountFetch type) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadAccounts(max_id, name, type);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void loadAccounts(String max_id, String name, accountFetch type) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
|
|
|
@ -36,23 +36,19 @@ import app.fedilab.fedilabtube.sqlite.Sqlite;
|
|||
|
||||
public class ChannelsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public ChannelsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> get() {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getChannels();
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void getChannels() {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
|
|
|
@ -30,24 +30,20 @@ import app.fedilab.fedilabtube.client.PeertubeAPI;
|
|||
|
||||
public class CommentVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public CommentVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getComment(String instanceName, String videoId) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getSingle(instanceName, videoId);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
||||
private void getSingle(String instanceName, String videoId) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api = new PeertubeAPI(_mContext);
|
||||
|
|
|
@ -38,18 +38,14 @@ import app.fedilab.fedilabtube.sqlite.Sqlite;
|
|||
|
||||
public class FeedsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public FeedsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getVideos(Type action, String max_id, String target, String forAccount) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadVideos(action, max_id, target, forAccount);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
|
@ -67,7 +63,7 @@ public class FeedsVM extends AndroidViewModel {
|
|||
}
|
||||
|
||||
private void update(Peertube peertube) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
|
@ -85,7 +81,7 @@ public class FeedsVM extends AndroidViewModel {
|
|||
|
||||
|
||||
private void getSingle(String instanceName, String videoId) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
|
@ -107,7 +103,7 @@ public class FeedsVM extends AndroidViewModel {
|
|||
}
|
||||
|
||||
private void loadVideos(Type action, String max_id, String target, String forAccount) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
|
|
|
@ -32,23 +32,19 @@ import app.fedilab.fedilabtube.client.entities.Error;
|
|||
|
||||
public class NotificationsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public NotificationsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getNotifications(Account account, String max_id) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadNotifications(account, max_id);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void loadNotifications(Account account, String max_id) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api;
|
||||
|
|
|
@ -39,23 +39,19 @@ import app.fedilab.fedilabtube.sqlite.Sqlite;
|
|||
|
||||
public class PlaylistsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public PlaylistsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> manage(action apiAction, Playlist playlist, String videoId, String max_id) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
managePlaylists(apiAction, playlist, videoId, max_id);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void managePlaylists(action apiAction, Playlist playlist, String videoId, String max_id) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
SharedPreferences sharedpreferences = _mContext.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
|
|
@ -30,23 +30,19 @@ import app.fedilab.fedilabtube.client.PeertubeAPI;
|
|||
|
||||
public class PostActionsVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public PostActionsVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> post(PeertubeAPI.StatusAction apiAction, String targetedId, String comment, String targetedComment) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
makeAction(apiAction, targetedId, comment, targetedComment);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void makeAction(PeertubeAPI.StatusAction apiAction, String targetedId, String comment, String targetedComment) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI peertubeAPI = new PeertubeAPI(_mContext);
|
||||
|
|
|
@ -34,23 +34,19 @@ import app.fedilab.fedilabtube.client.entities.Relationship;
|
|||
|
||||
public class RelationshipVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public RelationshipVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> get(String targetedId) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
getRelationShip(targetedId);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void getRelationShip(String targetedId) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api = new PeertubeAPI(_mContext);
|
||||
|
|
|
@ -30,23 +30,19 @@ import app.fedilab.fedilabtube.client.PeertubeAPI;
|
|||
|
||||
public class SearchVM extends AndroidViewModel {
|
||||
private MutableLiveData<APIResponse> apiResponseMutableLiveData;
|
||||
private Application application;
|
||||
|
||||
public SearchVM(@NonNull Application application) {
|
||||
super(application);
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<APIResponse> getVideos(String max_id, String query) {
|
||||
if (apiResponseMutableLiveData == null) {
|
||||
apiResponseMutableLiveData = new MutableLiveData<>();
|
||||
loadVideos(max_id, query);
|
||||
}
|
||||
return apiResponseMutableLiveData;
|
||||
}
|
||||
|
||||
private void loadVideos(String max_id, String query) {
|
||||
Context _mContext = this.application.getApplicationContext();
|
||||
Context _mContext = getApplication().getApplicationContext();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
PeertubeAPI api = new PeertubeAPI(_mContext);
|
||||
|
|
Loading…
Reference in New Issue