From ea954503bf9e56043b9fd82570c1c61971fe6911 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Tue, 18 Jul 2023 18:32:32 +0000 Subject: [PATCH] Update build process, fix crash on repo name saving (#1276) Closes #1227 Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1276 --- .woodpecker/build.yml | 4 +- .woodpecker/check.yml | 4 +- app/build.gradle | 30 +-- .../gitnex/activities/CommitsActivity.java | 23 ++- .../mian/gitnex/activities/LoginActivity.java | 4 + .../gitnex/activities/RepoForksActivity.java | 182 +++++------------- .../RepositorySettingsActivity.java | 25 ++- .../gitnex/adapters/RepoForksAdapter.java | 74 ++++++- .../gitnex/database/api/RepositoriesApi.java | 8 + .../gitnex/database/dao/RepositoriesDao.java | 4 + .../fragments/CommitDetailFragment.java | 2 +- .../viewmodels/AdminGetUsersViewModel.java | 4 +- .../gitnex/viewmodels/IssuesViewModel.java | 2 + .../viewmodels/RepositoryForksViewModel.java | 104 ++++++++++ build.gradle | 2 +- gradle.properties | 5 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 17 files changed, 306 insertions(+), 175 deletions(-) create mode 100644 app/src/main/java/org/mian/gitnex/viewmodels/RepositoryForksViewModel.java diff --git a/.woodpecker/build.yml b/.woodpecker/build.yml index d685226c..8c59fa31 100644 --- a/.woodpecker/build.yml +++ b/.woodpecker/build.yml @@ -1,13 +1,13 @@ pipeline: build: - image: alvrme/alpine-android:android-31-jdk11 + image: alvrme/alpine-android:android-32-jdk17 commands: - ./gradlew assembleFreeRelease when: path: [ app/**, build.gradle ] sign: - image: alvrme/alpine-android:android-31-jdk11 + image: alvrme/alpine-android:android-32-jdk17 environment: OUTPUT: "signed.apk" INSTANCE: "https://codeberg.org" diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml index 97d2ee11..4d3da82a 100644 --- a/.woodpecker/check.yml +++ b/.woodpecker/check.yml @@ -8,12 +8,12 @@ pipeline: must_contain: true style: - image: alvrme/alpine-android:android-31-jdk11 + image: alvrme/alpine-android:android-32-jdk17 group: check commands: - ./gradlew :app:spotlessCheck test: - image: alvrme/alpine-android:android-31-jdk11 + image: alvrme/alpine-android:android-32-jdk17 commands: - ./gradlew test diff --git a/app/build.gradle b/app/build.gradle index f3dbde41..aa97c4a8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,13 +4,13 @@ plugins { apply plugin: 'com.android.application' android { - compileSdkVersion 33 + compileSdkVersion 34 defaultConfig { applicationId "org.mian.gitnex" minSdkVersion 23 - targetSdkVersion 33 - versionCode 510 - versionName "5.1.0" + targetSdkVersion 34 + versionCode 515 + versionName "5.2.0-dev" multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -37,7 +37,7 @@ android { coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_17 } lint { abortOnError false @@ -54,17 +54,17 @@ configurations { } dependencies { - def lifecycle_version = '2.6.0' + def lifecycle_version = '2.6.1' def markwon_version = '4.6.2' def work_version = '2.8.1' def acra = '5.9.7' implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'com.google.android.material:material:1.9.0-beta01' - implementation 'androidx.compose.material3:material3:1.1.0-beta01' - implementation 'androidx.compose.material3:material3-window-size-class:1.1.0-beta01' - implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01' + implementation 'com.google.android.material:material:1.11.0-alpha01' + implementation 'androidx.compose.material3:material3:1.2.0-alpha03' + implementation 'androidx.compose.material3:material3-window-size-class:1.2.0-alpha03' + implementation 'androidx.viewpager2:viewpager2:1.1.0-beta02' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "androidx.legacy:legacy-support-v4:1.0.0" implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version" @@ -79,7 +79,7 @@ dependencies { implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:converter-scalars:2.9.0' implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2' - implementation 'org.ocpsoft.prettytime:prettytime:5.0.6.Final' + implementation 'org.ocpsoft.prettytime:prettytime:5.0.7.Final' implementation 'com.github.Pes8:android-material-color-picker-dialog:master' implementation "io.noties.markwon:core:$markwon_version" implementation "io.noties.markwon:ext-latex:$markwon_version" @@ -103,8 +103,8 @@ dependencies { implementation "ch.acra:acra-mail:$acra" implementation "ch.acra:acra-limiter:$acra" implementation "ch.acra:acra-notification:$acra" - implementation 'androidx.room:room-runtime:2.5.1' - annotationProcessor 'androidx.room:room-compiler:2.5.1' + implementation 'androidx.room:room-runtime:2.5.2' + annotationProcessor 'androidx.room:room-compiler:2.5.2' implementation "androidx.work:work-runtime:$work_version" implementation "io.mikael:urlbuilder:2.0.9" implementation "org.codeberg.gitnex-garage:emoji-java:v5.1.2" @@ -113,10 +113,10 @@ dependencies { implementation 'com.github.chrisvest:stormpot:2.4.2' implementation 'androidx.browser:browser:1.5.0' implementation 'com.google.android.flexbox:flexbox:3.0.0' - implementation('org.codeberg.gitnex:tea4j-autodeploy:3111bc1b18') { + implementation('org.codeberg.gitnex:tea4j-autodeploy:65f700d036') { exclude module: 'org.apache.oltu.oauth2.common' } - implementation 'io.github.amrdeveloper:codeview:1.3.7' + implementation 'io.github.amrdeveloper:codeview:1.3.8' constraints { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") 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 bc303b41..cfaf05dd 100644 --- a/app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/CommitsActivity.java @@ -126,7 +126,17 @@ public class CommitsActivity extends BaseActivity { Call> call = RetrofitClient.getApiInterface(ctx) - .repoGetAllCommits(repoOwner, repoName, branchName, null, 1, resultLimit); + .repoGetAllCommits( + repoOwner, + repoName, + branchName, + null, + true, + false, + true, + 1, + resultLimit, + ""); call.enqueue( new Callback<>() { @@ -180,7 +190,16 @@ public class CommitsActivity extends BaseActivity { Call> call = RetrofitClient.getApiInterface(ctx) .repoGetAllCommits( - repoOwner, repoName, branchName, null, page, resultLimit); + repoOwner, + repoName, + branchName, + null, + true, + false, + true, + page, + resultLimit, + ""); call.enqueue( new Callback<>() { diff --git a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java b/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java index df10a9f0..db8e04db 100644 --- a/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/LoginActivity.java @@ -639,6 +639,10 @@ public class LoginActivity extends BaseActivity { final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8); CreateAccessTokenOption createUserToken = new CreateAccessTokenOption().name(tokenName); + if (giteaVersion.higherOrEqual("1.19.0")) { + createUserToken.addScopesItem("all"); + createUserToken.addScopesItem("sudo"); + } Call callCreateToken; if (loginOTP != 0) { diff --git a/app/src/main/java/org/mian/gitnex/activities/RepoForksActivity.java b/app/src/main/java/org/mian/gitnex/activities/RepoForksActivity.java index cdd13510..fab994d6 100644 --- a/app/src/main/java/org/mian/gitnex/activities/RepoForksActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/RepoForksActivity.java @@ -4,28 +4,20 @@ import android.annotation.SuppressLint; import android.os.Bundle; import android.os.Handler; import android.os.Looper; -import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.EditorInfo; import androidx.annotation.NonNull; -import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.Toolbar; +import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; -import java.util.ArrayList; -import java.util.List; -import org.gitnex.tea4j.v2.models.Repository; import org.mian.gitnex.R; import org.mian.gitnex.adapters.RepoForksAdapter; -import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.databinding.ActivityRepoForksBinding; -import org.mian.gitnex.helpers.Constants; import org.mian.gitnex.helpers.contexts.RepositoryContext; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; +import org.mian.gitnex.viewmodels.RepositoryForksViewModel; /** * @author M M Arif @@ -33,13 +25,8 @@ import retrofit2.Response; public class RepoForksActivity extends BaseActivity { private ActivityRepoForksBinding activityRepoForksBinding; - private final String TAG = "RepositoryForks"; - - private int resultLimit; private int pageSize = 1; - private List forksList; private RepoForksAdapter adapter; - private RepositoryContext repository; @SuppressLint("DefaultLocale") @@ -55,15 +42,11 @@ public class RepoForksActivity extends BaseActivity { setSupportActionBar(toolbar); repository = RepositoryContext.fromIntent(getIntent()); - final String repoOwner = repository.getOwner(); - final String repoName = repository.getName(); activityRepoForksBinding.toolbarTitle.setText( ctx.getResources().getString(R.string.infoTabRepoForksCount)); activityRepoForksBinding.close.setOnClickListener(v -> finish()); - resultLimit = Constants.getCurrentResultLimit(ctx); - forksList = new ArrayList<>(); activityRepoForksBinding.pullToRefresh.setOnRefreshListener( () -> @@ -73,128 +56,77 @@ public class RepoForksActivity extends BaseActivity { pageSize = 1; activityRepoForksBinding.pullToRefresh.setRefreshing( false); - loadInitial(repoOwner, repoName, pageSize, resultLimit); - adapter.notifyDataChanged(); + fetchData(); + activityRepoForksBinding.progressBar.setVisibility( + View.VISIBLE); }, - 200)); - - adapter = new RepoForksAdapter(ctx, forksList); - adapter.setLoadMoreListener( - () -> - activityRepoForksBinding.recyclerView.post( - () -> { - if (forksList.size() == resultLimit - || pageSize == resultLimit) { - - int page = (forksList.size() + resultLimit) / resultLimit; - loadMore(repoOwner, repoName, page, resultLimit); - } - })); + 150)); activityRepoForksBinding.recyclerView.setHasFixedSize(true); activityRepoForksBinding.recyclerView.setLayoutManager(new LinearLayoutManager(ctx)); - activityRepoForksBinding.recyclerView.setAdapter(adapter); - loadInitial(repoOwner, repoName, pageSize, resultLimit); + fetchData(); } - private void loadInitial(String repoOwner, String repoName, int pageSize, int resultLimit) { + private void fetchData() { - Call> call = - RetrofitClient.getApiInterface(ctx) - .listForks(repoOwner, repoName, pageSize, resultLimit); + RepositoryForksViewModel repositoryForksViewModel = + new ViewModelProvider(this).get(RepositoryForksViewModel.class); - call.enqueue( - new Callback<>() { + repositoryForksViewModel + .getForksList(repository.getOwner(), repository.getName(), ctx) + .observe( + this, + forksListMain -> { + adapter = new RepoForksAdapter(ctx, forksListMain); + adapter.setLoadMoreListener( + new RepoForksAdapter.OnLoadMoreListener() { - @Override - public void onResponse( - @NonNull Call> call, - @NonNull Response> response) { + @Override + public void onLoadMore() { - if (response.isSuccessful()) { + pageSize += 1; + repositoryForksViewModel.loadMore( + repository.getOwner(), + repository.getName(), + pageSize, + ctx, + adapter); + activityRepoForksBinding.progressBar.setVisibility( + View.VISIBLE); + } - assert response.body() != null; + @Override + public void onLoadFinished() { - if (response.body().size() > 0) { - forksList.clear(); - forksList.addAll(response.body()); - adapter.notifyDataChanged(); + activityRepoForksBinding.progressBar.setVisibility( + View.GONE); + } + }); + + if (adapter.getItemCount() > 0) { + activityRepoForksBinding.recyclerView.setAdapter(adapter); activityRepoForksBinding.noData.setVisibility(View.GONE); } else { - forksList.clear(); adapter.notifyDataChanged(); + activityRepoForksBinding.recyclerView.setAdapter(adapter); activityRepoForksBinding.noData.setVisibility(View.VISIBLE); } activityRepoForksBinding.progressBar.setVisibility(View.GONE); - } else { - Log.e(TAG, String.valueOf(response.code())); - } - } - - @Override - public void onFailure( - @NonNull Call> call, @NonNull Throwable t) { - Log.e(TAG, t.toString()); - } - }); - } - - private void loadMore(String repoOwner, String repoName, int page, int resultLimit) { - - activityRepoForksBinding.progressLoadMore.setVisibility(View.VISIBLE); - - Call> call = - RetrofitClient.getApiInterface(ctx) - .listForks(repoOwner, repoName, page, resultLimit); - - call.enqueue( - new Callback<>() { - - @Override - public void onResponse( - @NonNull Call> call, - @NonNull Response> response) { - - if (response.isSuccessful()) { - - // remove loading view - forksList.remove(forksList.size() - 1); - - List result = response.body(); - assert result != null; - - if (result.size() > 0) { - pageSize = result.size(); - forksList.addAll(result); - } else { - adapter.setMoreDataAvailable(false); - } - - adapter.notifyDataChanged(); - activityRepoForksBinding.progressLoadMore.setVisibility(View.GONE); - } else { - Log.e(TAG, String.valueOf(response.code())); - } - } - - @Override - public void onFailure( - @NonNull Call> call, @NonNull Throwable t) { - Log.e(TAG, t.toString()); - } - }); + }); } @Override - public boolean onCreateOptionsMenu(Menu menu) { + public boolean onCreateOptionsMenu(@NonNull Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.search_menu, menu); + super.onCreateOptionsMenu(menu); MenuItem searchItem = menu.findItem(R.id.action_search); - SearchView searchView = (SearchView) searchItem.getActionView(); + androidx.appcompat.widget.SearchView searchView = + (androidx.appcompat.widget.SearchView) searchItem.getActionView(); searchView.setImeOptions(EditorInfo.IME_ACTION_DONE); searchView.setOnQueryTextListener( @@ -207,27 +139,13 @@ public class RepoForksActivity extends BaseActivity { @Override public boolean onQueryTextChange(String newText) { - filter(newText); - return true; + if (activityRepoForksBinding.recyclerView.getAdapter() != null) { + adapter.getFilter().filter(newText); + } + return false; } }); - - return super.onCreateOptionsMenu(menu); - } - - private void filter(String text) { - List userRepositories = new ArrayList<>(); - - for (Repository d : forksList) { - if (d.getOwner().getLogin().contains(text) - || d.getName().toLowerCase().contains(text) - || d.getDescription().toLowerCase().contains(text)) { - - userRepositories.add(d); - } - } - - adapter.updateList(userRepositories); + return false; } @Override diff --git a/app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java b/app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java index 8a871d12..e258739a 100644 --- a/app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/RepositorySettingsActivity.java @@ -42,6 +42,7 @@ public class RepositorySettingsActivity extends BaseActivity { private View.OnClickListener onClickListener; private RepositoryContext repository; + private String repositoryName; @Override public void onCreate(Bundle savedInstanceState) { @@ -52,6 +53,7 @@ public class RepositorySettingsActivity extends BaseActivity { setContentView(viewBinding.getRoot()); repository = RepositoryContext.fromIntent(getIntent()); + ; ImageView closeActivity = findViewById(R.id.close); @@ -246,6 +248,8 @@ public class RepositorySettingsActivity extends BaseActivity { propBinding.repoEnableIssues.setChecked(repoInfo.isHasIssues()); + repositoryName = repoInfo.getName(); + propBinding.repoEnableIssues.setOnCheckedChangeListener( (buttonView, isChecked) -> { if (isChecked) { @@ -340,19 +344,22 @@ public class RepositorySettingsActivity extends BaseActivity { dialogRepo.dismiss(); Toasty.success(ctx, getString(R.string.repoPropertiesSaveSuccess)); - assert response.body() != null; - repository.setRepository(response.body()); if (!repository.getName().equals(repoName)) { + + int currentActiveAccountId = + tinyDB.getInt("currentActiveAccountId"); + Objects.requireNonNull( BaseApi.getInstance(ctx, RepositoriesApi.class)) - .updateRepositoryOwnerAndName( - repository.getOwner(), - repoName, - repository.getRepositoryId()); - Intent result = new Intent(); - result.putExtra("nameChanged", true); - setResult(200, result); + .deleteRepositoryByName( + currentActiveAccountId, repositoryName); + + Intent intent = + new Intent( + RepositorySettingsActivity.this, + MainActivity.class); + RepositorySettingsActivity.this.startActivity(intent); finish(); } } else { diff --git a/app/src/main/java/org/mian/gitnex/adapters/RepoForksAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/RepoForksAdapter.java index 264ae6b6..05c7e908 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/RepoForksAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/RepoForksAdapter.java @@ -8,12 +8,15 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; +import android.widget.Filter; +import android.widget.Filterable; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; +import java.util.ArrayList; import java.util.List; import java.util.Locale; import org.mian.gitnex.R; @@ -29,19 +32,62 @@ import org.mian.gitnex.helpers.contexts.RepositoryContext; /** * @author M M Arif */ -public class RepoForksAdapter extends RecyclerView.Adapter { +public class RepoForksAdapter extends RecyclerView.Adapter + implements Filterable { + private final List forksListFull; private final Context context; private List forksList; - private Runnable loadMoreListener; - private boolean isLoading = false; - private boolean isMoreDataAvailable = true; + private OnLoadMoreListener loadMoreListener; + private boolean isLoading = false, isMoreDataAvailable = true; + + private final Filter forksFilter = + new Filter() { + @Override + protected FilterResults performFiltering(CharSequence constraint) { + List filteredList = new ArrayList<>(); + + if (constraint == null || constraint.length() == 0) { + filteredList.addAll(forksListFull); + } else { + String filterPattern = constraint.toString().toLowerCase().trim(); + + for (org.gitnex.tea4j.v2.models.Repository item : forksListFull) { + if (item.getFullName().toLowerCase().contains(filterPattern) + || item.getOwner() + .getLogin() + .toLowerCase() + .contains(filterPattern) + || item.getOwner() + .getEmail() + .toLowerCase() + .contains(filterPattern)) { + filteredList.add(item); + } + } + } + + FilterResults results = new FilterResults(); + results.values = filteredList; + + return results; + } + + @Override + protected void publishResults(CharSequence constraint, FilterResults results) { + + forksList.clear(); + forksList.addAll((List) results.values); + notifyDataChanged(); + } + }; public RepoForksAdapter( Context ctx, List forksListMain) { this.context = ctx; this.forksList = forksListMain; + forksListFull = new ArrayList<>(forksList); } @NonNull @Override @@ -59,7 +105,7 @@ public class RepoForksAdapter extends RecyclerView.Adapter repositoriesDao.deleteRepository(repositoryId)); } + public void deleteRepositoryByName( + final int currentActiveAccountId, final String repositoryName) { + executorService.execute( + () -> + repositoriesDao.deleteRepositoryByName( + currentActiveAccountId, repositoryName)); + } + public void updateRepositoryMostVisited(int mostVisited, int repositoryId) { executorService.execute( () -> repositoriesDao.updateRepositoryMostVisited(mostVisited, repositoryId)); diff --git a/app/src/main/java/org/mian/gitnex/database/dao/RepositoriesDao.java b/app/src/main/java/org/mian/gitnex/database/dao/RepositoriesDao.java index ca819393..bfc316ac 100644 --- a/app/src/main/java/org/mian/gitnex/database/dao/RepositoriesDao.java +++ b/app/src/main/java/org/mian/gitnex/database/dao/RepositoriesDao.java @@ -46,6 +46,10 @@ public interface RepositoriesDao { @Query("DELETE FROM Repositories WHERE repositoryId = :repositoryId") void deleteRepository(int repositoryId); + @Query( + "DELETE FROM Repositories WHERE repositoryName = :repositoryName AND repoAccountId = :currentActiveAccountId") + void deleteRepositoryByName(int currentActiveAccountId, String repositoryName); + @Query("DELETE FROM Repositories WHERE repoAccountId = :repoAccountId") void deleteRepositoriesByAccount(int repoAccountId); diff --git a/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java b/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java index 6006e509..0b64ae4f 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java @@ -185,7 +185,7 @@ public class CommitDetailFragment extends Fragment { private void getCommit() { RetrofitClient.getApiInterface(requireContext()) - .repoGetSingleCommit(repoOwner, repoName, sha) + .repoGetSingleCommit(repoOwner, repoName, sha, true, false, true) .enqueue( new Callback<>() { diff --git a/app/src/main/java/org/mian/gitnex/viewmodels/AdminGetUsersViewModel.java b/app/src/main/java/org/mian/gitnex/viewmodels/AdminGetUsersViewModel.java index 3e7728f6..a81db168 100644 --- a/app/src/main/java/org/mian/gitnex/viewmodels/AdminGetUsersViewModel.java +++ b/app/src/main/java/org/mian/gitnex/viewmodels/AdminGetUsersViewModel.java @@ -33,7 +33,7 @@ public class AdminGetUsersViewModel extends ViewModel { public void loadUsersList(int page, int resultLimit, Context ctx) { Call> call = - RetrofitClient.getApiInterface(ctx).adminGetAllUsers(page, resultLimit); + RetrofitClient.getApiInterface(ctx).adminSearchUsers(null, null, page, resultLimit); call.enqueue( new Callback<>() { @@ -61,7 +61,7 @@ public class AdminGetUsersViewModel extends ViewModel { int page, int resultLimit, Context ctx, AdminGetUsersAdapter adapter) { Call> call = - RetrofitClient.getApiInterface(ctx).adminGetAllUsers(page, resultLimit); + RetrofitClient.getApiInterface(ctx).adminSearchUsers(null, null, page, resultLimit); call.enqueue( new Callback<>() { diff --git a/app/src/main/java/org/mian/gitnex/viewmodels/IssuesViewModel.java b/app/src/main/java/org/mian/gitnex/viewmodels/IssuesViewModel.java index 89919793..9e33928d 100644 --- a/app/src/main/java/org/mian/gitnex/viewmodels/IssuesViewModel.java +++ b/app/src/main/java/org/mian/gitnex/viewmodels/IssuesViewModel.java @@ -63,6 +63,7 @@ public class IssuesViewModel extends ViewModel { null, null, null, + null, 1, resultLimit); @@ -116,6 +117,7 @@ public class IssuesViewModel extends ViewModel { null, null, null, + null, page, resultLimit); diff --git a/app/src/main/java/org/mian/gitnex/viewmodels/RepositoryForksViewModel.java b/app/src/main/java/org/mian/gitnex/viewmodels/RepositoryForksViewModel.java new file mode 100644 index 00000000..c1d6a617 --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/viewmodels/RepositoryForksViewModel.java @@ -0,0 +1,104 @@ +package org.mian.gitnex.viewmodels; + +import android.content.Context; +import androidx.annotation.NonNull; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; +import java.util.List; +import org.gitnex.tea4j.v2.models.Repository; +import org.mian.gitnex.R; +import org.mian.gitnex.adapters.RepoForksAdapter; +import org.mian.gitnex.clients.RetrofitClient; +import org.mian.gitnex.helpers.Constants; +import org.mian.gitnex.helpers.Toasty; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +/** + * @author M M Arif + */ +public class RepositoryForksViewModel extends ViewModel { + + private MutableLiveData> forksList; + private int resultLimit; + + public LiveData> getForksList(String repoOwner, String repoName, Context ctx) { + + forksList = new MutableLiveData<>(); + resultLimit = Constants.getCurrentResultLimit(ctx); + loadInitialList(repoOwner, repoName, ctx); + return forksList; + } + + public void loadInitialList(String repoOwner, String repoName, Context ctx) { + + Call> call = + RetrofitClient.getApiInterface(ctx).listForks(repoOwner, repoName, 1, resultLimit); + + call.enqueue( + new Callback<>() { + + @Override + public void onResponse( + @NonNull Call> call, + @NonNull Response> response) { + + if (response.isSuccessful()) { + forksList.postValue(response.body()); + } else { + Toasty.error(ctx, ctx.getString(R.string.genericError)); + } + } + + @Override + public void onFailure( + @NonNull Call> call, @NonNull Throwable t) { + + Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError)); + } + }); + } + + public void loadMore( + String repoOwner, String repoName, int page, Context ctx, RepoForksAdapter adapter) { + + Call> call = + RetrofitClient.getApiInterface(ctx) + .listForks(repoOwner, repoName, page, resultLimit); + + call.enqueue( + new Callback<>() { + + @Override + public void onResponse( + @NonNull Call> call, + @NonNull Response> response) { + + if (response.isSuccessful()) { + + List list = forksList.getValue(); + assert list != null; + assert response.body() != null; + + if (response.body().size() != 0) { + list.addAll(response.body()); + adapter.updateList(list); + } else { + adapter.setMoreDataAvailable(false); + } + } else { + Toasty.error(ctx, ctx.getString(R.string.genericError)); + } + } + + @Override + public void onFailure( + @NonNull Call> call, @NonNull Throwable t) { + + Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError)); + } + }); + } +} diff --git a/build.gradle b/build.gradle index 9c232347..a92da85f 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' + classpath 'com.android.tools.build:gradle:8.0.2' } } diff --git a/gradle.properties b/gradle.properties index a43d4a12..1547a776 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,9 +6,12 @@ # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. +android.defaults.buildfeatures.buildconfig=true android.enableJetifier=true +android.nonFinalResIds=false +android.nonTransitiveRClass=false android.useAndroidX=true -org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.workers.max=12 # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a3aaf6e2..8ba31e99 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Feb 10 19:24:36 CET 2021 +#Tue Jul 11 23:34:25 PKT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip