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.Authorization;
import org.mian.gitnex.helpers.StaticGlobalVariables; import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version; import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.interfaces.ApiInterface; import org.mian.gitnex.interfaces.ApiInterface;
import org.mian.gitnex.models.Commits; import org.mian.gitnex.models.Commits;
@ -115,7 +116,6 @@ public class CommitsActivity extends BaseActivity {
int page = (commitsList.size() + resultLimit) / resultLimit; int page = (commitsList.size() + resultLimit) / resultLimit;
loadMore(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, branchName, resultLimit); loadMore(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, branchName, resultLimit);
} }
})); }));
@ -138,7 +138,7 @@ public class CommitsActivity extends BaseActivity {
@Override @Override
public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) { public void onResponse(@NonNull Call<List<Commits>> call, @NonNull Response<List<Commits>> response) {
if(response.isSuccessful()) { if(response.code() == 200) {
assert response.body() != null; assert response.body() != null;
if(response.body().size() > 0) { if(response.body().size() > 0) {
@ -150,13 +150,15 @@ public class CommitsActivity extends BaseActivity {
} }
else { else {
commitsList.clear(); commitsList.clear();
adapter.notifyDataChanged(); adapter.notifyDataChanged();
noData.setVisibility(View.VISIBLE); noData.setVisibility(View.VISIBLE);
} }
}
if(response.code() == 409) {
progressBar.setVisibility(View.GONE); noData.setVisibility(View.VISIBLE);
} }
else { else {
@ -164,12 +166,13 @@ public class CommitsActivity extends BaseActivity {
} }
progressBar.setVisibility(View.GONE);
} }
@Override @Override
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) { 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()) { if(response.isSuccessful()) {
List<Commits> result = response.body(); List<Commits> result = response.body();
assert result != null; assert result != null;
if(result.size() > 0) { if(result.size() > 0) {
pageSize = result.size(); pageSize = result.size();
commitsList.addAll(result); commitsList.addAll(result);
} }
else { else {
adapter.setMoreDataAvailable(false); adapter.setMoreDataAvailable(false);
} }
adapter.notifyDataChanged(); adapter.notifyDataChanged();
progressLoadMore.setVisibility(View.GONE);
} }
else { else {
@ -214,13 +213,13 @@ public class CommitsActivity extends BaseActivity {
} }
progressLoadMore.setVisibility(View.GONE);
} }
@Override @Override
public void onFailure(@NonNull Call<List<Commits>> call, @NonNull Throwable t) { 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); 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); adapter = new FilesAdapter(getContext(), filesListMain, FilesFragment.this);
mBreadcrumbsView.removeItemAfter(1); mBreadcrumbsView.removeItemAfter(1);
if(adapter.getItemCount() > 0) { if(adapter.getItemCount() > 0) {
mRecyclerView.setAdapter(adapter); mRecyclerView.setAdapter(adapter);
AppUtil.setMultiVisibility(View.VISIBLE, mRecyclerView, filesFrame); AppUtil.setMultiVisibility(View.VISIBLE, mRecyclerView, filesFrame);
noDataFiles.setVisibility(View.GONE); noDataFiles.setVisibility(View.GONE);
} }
else { else {
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
mRecyclerView.setAdapter(adapter); mRecyclerView.setAdapter(adapter);
AppUtil.setMultiVisibility(View.VISIBLE, mRecyclerView, filesFrame, noDataFiles); AppUtil.setMultiVisibility(View.VISIBLE, mRecyclerView, filesFrame, noDataFiles);
@ -225,7 +227,6 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
filesFrame.setVisibility(View.VISIBLE); filesFrame.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
}); });
} }
@ -237,7 +238,7 @@ public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapter
FilesViewModel filesModel2 = new ViewModelProvider(this).get(FilesViewModel.class); 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); adapter = new FilesAdapter(getContext(), filesListMain2, FilesFragment.this);

View File

@ -1,7 +1,9 @@
package org.mian.gitnex.viewmodels; package org.mian.gitnex.viewmodels;
import android.content.Context; 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.annotation.NonNull;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
@ -25,15 +27,15 @@ public class FilesViewModel extends ViewModel {
private static MutableLiveData<List<Files>> filesList; private static MutableLiveData<List<Files>> filesList;
private static MutableLiveData<List<Files>> filesList2; 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<>(); filesList = new MutableLiveData<>();
loadFilesList(instanceUrl, token, owner, repo, ref, ctx); loadFilesList(instanceUrl, token, owner, repo, ref, ctx, progressBar, noDataFiles);
return filesList; 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 Call<List<Files>> call = RetrofitClient
.getInstance(instanceUrl, ctx) .getInstance(instanceUrl, ctx)
@ -45,37 +47,47 @@ public class FilesViewModel extends ViewModel {
@Override @Override
public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> response) { public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> response) {
if (response.isSuccessful()) { if (response.code() == 200) {
assert response.body() != null; assert response.body() != null;
if(response.body().size() > 0) {
Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType()));
filesList.postValue(response.body()); filesList.postValue(response.body());
}
else {
} else { progressBar.setVisibility(View.GONE);
noDataFiles.setVisibility(View.VISIBLE);
}
}
else {
Toasty.warning(ctx, ctx.getString(R.string.noDataFilesTab)); progressBar.setVisibility(View.GONE);
Log.i("onResponse", String.valueOf(response.code())); noDataFiles.setVisibility(View.VISIBLE);
} }
} }
@Override @Override
public void onFailure(@NonNull Call<List<Files>> call, @NonNull Throwable t) { 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<>(); filesList2 = new MutableLiveData<>();
loadFilesList2(instanceUrl, token, owner, repo, filesDir, ref, ctx); loadFilesList2(instanceUrl, token, owner, repo, filesDir, ref, ctx, progressBar, noDataFiles);
return filesList2; 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 Call<List<Files>> call = RetrofitClient
.getInstance(instanceUrl, ctx) .getInstance(instanceUrl, ctx)
@ -87,23 +99,32 @@ public class FilesViewModel extends ViewModel {
@Override @Override
public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> response) { public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> response) {
if (response.isSuccessful()) { if (response.code() == 200) {
assert response.body() != null; assert response.body() != null;
if(response.body().size() > 0) {
Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType()));
filesList2.postValue(response.body()); filesList2.postValue(response.body());
} else {
Toasty.warning(ctx, ctx.getString(R.string.noDataFilesTab));
Log.i("onResponse", String.valueOf(response.code()));
} }
else {
progressBar.setVisibility(View.GONE);
noDataFiles.setVisibility(View.VISIBLE);
}
}
else {
progressBar.setVisibility(View.GONE);
noDataFiles.setVisibility(View.VISIBLE);
}
} }
@Override @Override
public void onFailure(@NonNull Call<List<Files>> call, @NonNull Throwable t) { 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,6 +36,8 @@
android:background="?attr/primaryBackgroundColor" android:background="?attr/primaryBackgroundColor"
android:scrollbars="vertical" /> android:scrollbars="vertical" />
</LinearLayout>
<TextView <TextView
android:id="@+id/noDataFiles" android:id="@+id/noDataFiles"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -47,8 +49,6 @@
android:textSize="20sp" android:textSize="20sp"
android:visibility="gone" /> android:visibility="gone" />
</LinearLayout>
<com.google.android.material.progressindicator.ProgressIndicator <com.google.android.material.progressindicator.ProgressIndicator
android:id="@+id/progress_bar" android:id="@+id/progress_bar"
android:layout_width="match_parent" android:layout_width="match_parent"