Fix #154
This commit is contained in:
		@@ -192,7 +192,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
 | 
			
		||||
 | 
			
		||||
        FilesViewModel filesModel = new ViewModelProvider(this).get(FilesViewModel.class);
 | 
			
		||||
 | 
			
		||||
        filesModel.getFilesList(instanceUrl, instanceToken, owner, repo).observe(this, new Observer<List<Files>>() {
 | 
			
		||||
        filesModel.getFilesList(instanceUrl, instanceToken, owner, repo, getContext()).observe(this, new Observer<List<Files>>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onChanged(@Nullable List<Files> filesListMain) {
 | 
			
		||||
                adapter = new FilesAdapter(getContext(), filesListMain, FilesFragment.this);
 | 
			
		||||
@@ -225,7 +225,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
 | 
			
		||||
 | 
			
		||||
        FilesViewModel filesModel2 = new ViewModelProvider(this).get(FilesViewModel.class);
 | 
			
		||||
 | 
			
		||||
        filesModel2.getFilesList2(instanceUrl, instanceToken, owner, repo, filesDir).observe(this, new Observer<List<Files>>() {
 | 
			
		||||
        filesModel2.getFilesList2(instanceUrl, instanceToken, owner, repo, filesDir, getContext()).observe(this, new Observer<List<Files>>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onChanged(@Nullable List<Files> filesListMain2) {
 | 
			
		||||
                adapter = new FilesAdapter(getContext(), filesListMain2, FilesFragment.this);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,14 @@
 | 
			
		||||
package org.mian.gitnex.viewmodels;
 | 
			
		||||
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import androidx.annotation.NonNull;
 | 
			
		||||
import androidx.lifecycle.LiveData;
 | 
			
		||||
import androidx.lifecycle.MutableLiveData;
 | 
			
		||||
import androidx.lifecycle.ViewModel;
 | 
			
		||||
import org.mian.gitnex.R;
 | 
			
		||||
import org.mian.gitnex.clients.RetrofitClient;
 | 
			
		||||
import org.mian.gitnex.helpers.Toasty;
 | 
			
		||||
import org.mian.gitnex.models.Files;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.Comparator;
 | 
			
		||||
@@ -23,15 +26,15 @@ public class FilesViewModel extends ViewModel {
 | 
			
		||||
    private static MutableLiveData<List<Files>> filesList;
 | 
			
		||||
    private static MutableLiveData<List<Files>> filesList2;
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Files>> getFilesList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
    public LiveData<List<Files>> getFilesList(String instanceUrl, String token, String owner, String repo, Context ctx) {
 | 
			
		||||
 | 
			
		||||
        filesList = new MutableLiveData<>();
 | 
			
		||||
        loadFilesList(instanceUrl, token, owner, repo);
 | 
			
		||||
        loadFilesList(instanceUrl, token, owner, repo, ctx);
 | 
			
		||||
 | 
			
		||||
        return filesList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadFilesList(String instanceUrl, String token, String owner, String repo) {
 | 
			
		||||
    private static void loadFilesList(String instanceUrl, String token, String owner, String repo, final Context ctx) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Files>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
@@ -43,16 +46,17 @@ public class FilesViewModel extends ViewModel {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> response) {
 | 
			
		||||
 | 
			
		||||
                Collections.sort(response.body(), new Comparator<Files>() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public int compare(Files byType1, Files byType2) {
 | 
			
		||||
                        return byType1.getType().compareTo(byType2.getType());
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    Collections.sort(response.body(), new Comparator<Files>() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public int compare(Files byType1, Files byType2) {
 | 
			
		||||
                            return byType1.getType().compareTo(byType2.getType());
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
 | 
			
		||||
                    filesList.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Toasty.info(ctx, ctx.getString(R.string.noDataFilesTab));
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@@ -66,15 +70,15 @@ public class FilesViewModel extends ViewModel {
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public LiveData<List<Files>> getFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir) {
 | 
			
		||||
    public LiveData<List<Files>> getFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir, Context ctx) {
 | 
			
		||||
 | 
			
		||||
        filesList = new MutableLiveData<>();
 | 
			
		||||
        loadFilesList2(instanceUrl, token, owner, repo, filesDir);
 | 
			
		||||
        filesList2 = new MutableLiveData<>();
 | 
			
		||||
        loadFilesList2(instanceUrl, token, owner, repo, filesDir, ctx);
 | 
			
		||||
 | 
			
		||||
        return filesList;
 | 
			
		||||
        return filesList2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void loadFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir) {
 | 
			
		||||
    private static void loadFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir, final Context ctx) {
 | 
			
		||||
 | 
			
		||||
        Call<List<Files>> call = RetrofitClient
 | 
			
		||||
                .getInstance(instanceUrl)
 | 
			
		||||
@@ -86,19 +90,17 @@ public class FilesViewModel extends ViewModel {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> response) {
 | 
			
		||||
 | 
			
		||||
                assert response.body() != null;
 | 
			
		||||
                if(response.body().size() > 0) {
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    Collections.sort(response.body(), new Comparator<Files>() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public int compare(Files byType1, Files byType2) {
 | 
			
		||||
                            return byType1.getType().compareTo(byType2.getType());
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (response.isSuccessful()) {
 | 
			
		||||
                    filesList.postValue(response.body());
 | 
			
		||||
                    filesList2.postValue(response.body());
 | 
			
		||||
                } else {
 | 
			
		||||
                    Toasty.info(ctx, ctx.getString(R.string.noDataFilesTab));
 | 
			
		||||
                    Log.i("onResponse", String.valueOf(response.code()));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user