From 1e30c37d7c4f2af361efc89de9849dd05d35a0c6 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Thu, 8 Oct 2020 20:44:38 +0200 Subject: [PATCH] Improve repo files (#719) Merge branch 'master' into improve-files Improve repo files Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/719 --- .../gitnex/activities/CommitsActivity.java | 23 ++++--- .../mian/gitnex/fragments/FilesFragment.java | 7 ++- .../gitnex/viewmodels/FilesViewModel.java | 63 ++++++++++++------- app/src/main/res/layout/fragment_files.xml | 22 +++---- 4 files changed, 68 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java b/app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java index 14c567f8..75b31fae 100644 --- a/app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java @@ -24,6 +24,7 @@ import org.mian.gitnex.clients.AppApiService; import org.mian.gitnex.helpers.Authorization; import org.mian.gitnex.helpers.StaticGlobalVariables; import org.mian.gitnex.helpers.TinyDB; +import org.mian.gitnex.helpers.Toasty; import org.mian.gitnex.helpers.Version; import org.mian.gitnex.interfaces.ApiInterface; import org.mian.gitnex.models.Commits; @@ -115,7 +116,6 @@ public class CommitsActivity extends BaseActivity { int page = (commitsList.size() + resultLimit) / resultLimit; loadMore(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, branchName, resultLimit); - } })); @@ -138,7 +138,7 @@ public class CommitsActivity extends BaseActivity { @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { - if(response.isSuccessful()) { + if(response.code() == 200) { assert response.body() != null; if(response.body().size() > 0) { @@ -150,13 +150,15 @@ public class CommitsActivity extends BaseActivity { } else { + commitsList.clear(); adapter.notifyDataChanged(); noData.setVisibility(View.VISIBLE); } + } + if(response.code() == 409) { - progressBar.setVisibility(View.GONE); - + noData.setVisibility(View.VISIBLE); } else { @@ -164,12 +166,13 @@ public class CommitsActivity extends BaseActivity { } + progressBar.setVisibility(View.GONE); } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - Log.e(TAG, t.toString()); + Toasty.error(ctx, getResources().getString(R.string.errorOnLogin)); } }); @@ -190,23 +193,19 @@ public class CommitsActivity extends BaseActivity { if(response.isSuccessful()) { List result = response.body(); - assert result != null; + if(result.size() > 0) { pageSize = result.size(); commitsList.addAll(result); - } else { adapter.setMoreDataAvailable(false); - } adapter.notifyDataChanged(); - progressLoadMore.setVisibility(View.GONE); - } else { @@ -214,13 +213,13 @@ public class CommitsActivity extends BaseActivity { } + progressLoadMore.setVisibility(View.GONE); } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - Log.e(TAG, t.toString()); - + Toasty.error(ctx, getResources().getString(R.string.errorOnLogin)); } }); diff --git a/app/src/main/java/org/mian/gitnex/fragments/FilesFragment.java b/app/src/main/java/org/mian/gitnex/fragments/FilesFragment.java index 986187e3..c9e061e0 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/FilesFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/FilesFragment.java @@ -207,17 +207,19 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter FilesViewModel filesModel = new ViewModelProvider(this).get(FilesViewModel.class); - filesModel.getFilesList(instanceUrl, instanceToken, owner, repo, ref, getContext()).observe(getViewLifecycleOwner(), filesListMain -> { + filesModel.getFilesList(instanceUrl, instanceToken, owner, repo, ref, getContext(), mProgressBar, noDataFiles).observe(getViewLifecycleOwner(), filesListMain -> { adapter = new FilesAdapter(getContext(), filesListMain, FilesFragment.this); mBreadcrumbsView.removeItemAfter(1); if(adapter.getItemCount() > 0) { + mRecyclerView.setAdapter(adapter); AppUtil.setMultiVisibility(View.VISIBLE, mRecyclerView, filesFrame); noDataFiles.setVisibility(View.GONE); } else { + adapter.notifyDataSetChanged(); mRecyclerView.setAdapter(adapter); AppUtil.setMultiVisibility(View.VISIBLE, mRecyclerView, filesFrame, noDataFiles); @@ -225,7 +227,6 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter filesFrame.setVisibility(View.VISIBLE); mProgressBar.setVisibility(View.GONE); - }); } @@ -237,7 +238,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter FilesViewModel filesModel2 = new ViewModelProvider(this).get(FilesViewModel.class); - filesModel2.getFilesList2(instanceUrl, instanceToken, owner, repo, filesDir, ref, getContext()).observe(this, filesListMain2 -> { + filesModel2.getFilesList2(instanceUrl, instanceToken, owner, repo, filesDir, ref, getContext(), mProgressBar, noDataFiles).observe(this, filesListMain2 -> { adapter = new FilesAdapter(getContext(), filesListMain2, FilesFragment.this); diff --git a/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java b/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java index 538757bf..70db17bb 100644 --- a/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java +++ b/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java @@ -1,7 +1,9 @@ package org.mian.gitnex.viewmodels; import android.content.Context; -import android.util.Log; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; @@ -25,15 +27,15 @@ public class FilesViewModel extends ViewModel { private static MutableLiveData> filesList; private static MutableLiveData> filesList2; - public LiveData> getFilesList(String instanceUrl, String token, String owner, String repo, String ref, Context ctx) { + public LiveData> getFilesList(String instanceUrl, String token, String owner, String repo, String ref, Context ctx, ProgressBar progressBar, TextView noDataFiles) { filesList = new MutableLiveData<>(); - loadFilesList(instanceUrl, token, owner, repo, ref, ctx); + loadFilesList(instanceUrl, token, owner, repo, ref, ctx, progressBar, noDataFiles); return filesList; } - private static void loadFilesList(String instanceUrl, String token, String owner, String repo, String ref, final Context ctx) { + private static void loadFilesList(String instanceUrl, String token, String owner, String repo, String ref, final Context ctx, ProgressBar progressBar, TextView noDataFiles) { Call> call = RetrofitClient .getInstance(instanceUrl, ctx) @@ -45,37 +47,47 @@ public class FilesViewModel extends ViewModel { @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { - if (response.isSuccessful()) { + if (response.code() == 200) { assert response.body() != null; - Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); - filesList.postValue(response.body()); - } else { + if(response.body().size() > 0) { - Toasty.warning(ctx, ctx.getString(R.string.noDataFilesTab)); - Log.i("onResponse", String.valueOf(response.code())); + Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); + filesList.postValue(response.body()); + } + else { + + progressBar.setVisibility(View.GONE); + noDataFiles.setVisibility(View.VISIBLE); + } + } + else { + + progressBar.setVisibility(View.GONE); + noDataFiles.setVisibility(View.VISIBLE); } } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - Log.i("onFailure", t.toString()); + + Toasty.error(ctx, ctx.getString(R.string.errorOnLogin)); } }); } - public LiveData> getFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir, String ref, Context ctx) { + public LiveData> getFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir, String ref, Context ctx, ProgressBar progressBar, TextView noDataFiles) { filesList2 = new MutableLiveData<>(); - loadFilesList2(instanceUrl, token, owner, repo, filesDir, ref, ctx); + loadFilesList2(instanceUrl, token, owner, repo, filesDir, ref, ctx, progressBar, noDataFiles); return filesList2; } - private static void loadFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir, String ref, final Context ctx) { + private static void loadFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir, String ref, final Context ctx, ProgressBar progressBar, TextView noDataFiles) { Call> call = RetrofitClient .getInstance(instanceUrl, ctx) @@ -87,23 +99,32 @@ public class FilesViewModel extends ViewModel { @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { - if (response.isSuccessful()) { + if (response.code() == 200) { assert response.body() != null; - Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); - filesList2.postValue(response.body()); - } else { + if(response.body().size() > 0) { - Toasty.warning(ctx, ctx.getString(R.string.noDataFilesTab)); - Log.i("onResponse", String.valueOf(response.code())); + Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); + filesList2.postValue(response.body()); + } + else { + + progressBar.setVisibility(View.GONE); + noDataFiles.setVisibility(View.VISIBLE); + } } + else { + progressBar.setVisibility(View.GONE); + noDataFiles.setVisibility(View.VISIBLE); + } } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - Log.i("onFailure", t.toString()); + + Toasty.error(ctx, ctx.getString(R.string.errorOnLogin)); } }); diff --git a/app/src/main/res/layout/fragment_files.xml b/app/src/main/res/layout/fragment_files.xml index c9fb628f..7e8a65aa 100644 --- a/app/src/main/res/layout/fragment_files.xml +++ b/app/src/main/res/layout/fragment_files.xml @@ -36,19 +36,19 @@ android:background="?attr/primaryBackgroundColor" android:scrollbars="vertical" /> - - + +