Improve repo files (#719)

Merge branch 'master' into improve-files

Improve repo files

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/719
This commit is contained in:
M M Arif 2020-10-08 20:44:38 +02:00
parent 1bf023357b
commit 1e30c37d7c
4 changed files with 68 additions and 47 deletions

View File

@ -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<List<Commits>> call, @NonNull Response<List<Commits>> 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<List<Commits>> 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<Commits> 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<List<Commits>> call, @NonNull Throwable t) {
Log.e(TAG, t.toString());
Toasty.error(ctx, getResources().getString(R.string.errorOnLogin));
}
});

View File

@ -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);

View File

@ -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<List<Files>> filesList;
private static MutableLiveData<List<Files>> filesList2;
public LiveData<List<Files>> getFilesList(String instanceUrl, String token, String owner, String repo, String ref, Context ctx) {
public LiveData<List<Files>> 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<List<Files>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
@ -45,37 +47,47 @@ public class FilesViewModel extends ViewModel {
@Override
public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> 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<List<Files>> call, @NonNull Throwable t) {
Log.i("onFailure", t.toString());
Toasty.error(ctx, ctx.getString(R.string.errorOnLogin));
}
});
}
public LiveData<List<Files>> getFilesList2(String instanceUrl, String token, String owner, String repo, String filesDir, String ref, Context ctx) {
public LiveData<List<Files>> 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<List<Files>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
@ -87,23 +99,32 @@ public class FilesViewModel extends ViewModel {
@Override
public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> 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<List<Files>> call, @NonNull Throwable t) {
Log.i("onFailure", t.toString());
Toasty.error(ctx, ctx.getString(R.string.errorOnLogin));
}
});

View File

@ -36,19 +36,19 @@
android:background="?attr/primaryBackgroundColor"
android:scrollbars="vertical" />
<TextView
android:id="@+id/noDataFiles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:gravity="center"
android:text="@string/noDataFilesTab"
android:textColor="?attr/primaryTextColor"
android:textSize="20sp"
android:visibility="gone" />
</LinearLayout>
<TextView
android:id="@+id/noDataFiles"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:gravity="center"
android:text="@string/noDataFilesTab"
android:textColor="?attr/primaryTextColor"
android:textSize="20sp"
android:visibility="gone" />
<com.google.android.material.progressindicator.ProgressIndicator
android:id="@+id/progress_bar"
android:layout_width="match_parent"