mirror of https://codeberg.org/gitnex/GitNex.git
Add watched repositories, fix unwatch repository
This commit is contained in:
parent
5c0f494b2c
commit
5898965840
|
@ -123,6 +123,7 @@ public class RepositoryActions {
|
|||
if (response.isSuccessful()) {
|
||||
if (response.code() == 200) {
|
||||
|
||||
MainActivity.reloadRepos = true;
|
||||
Toasty.success(
|
||||
context,
|
||||
context.getString(R.string.watchRepositorySuccess));
|
||||
|
@ -155,7 +156,7 @@ public class RepositoryActions {
|
|||
|
||||
Call<Void> call =
|
||||
RetrofitClient.getApiInterface(context)
|
||||
.userCurrentDeleteStar(repository.getOwner(), repository.getName());
|
||||
.userCurrentDeleteSubscription(repository.getOwner(), repository.getName());
|
||||
|
||||
call.enqueue(
|
||||
new Callback<>() {
|
||||
|
@ -166,6 +167,7 @@ public class RepositoryActions {
|
|||
|
||||
if (response.code() == 204) {
|
||||
|
||||
MainActivity.reloadRepos = true;
|
||||
Toasty.success(
|
||||
context, context.getString(R.string.unWatchRepositorySuccess));
|
||||
} else if (response.code() == 401) {
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.mian.gitnex.fragments.OrganizationsFragment;
|
|||
import org.mian.gitnex.fragments.RepositoriesFragment;
|
||||
import org.mian.gitnex.fragments.SettingsFragment;
|
||||
import org.mian.gitnex.fragments.StarredRepositoriesFragment;
|
||||
import org.mian.gitnex.fragments.WatchedRepositoriesFragment;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.ChangeLog;
|
||||
|
@ -71,18 +72,14 @@ public class MainActivity extends BaseActivity
|
|||
|
||||
public static boolean refActivity = false;
|
||||
public static boolean reloadRepos = false;
|
||||
|
||||
private DrawerLayout drawer;
|
||||
private TextView toolbarTitle;
|
||||
private Typeface myTypeface;
|
||||
|
||||
private boolean noConnection = false;
|
||||
|
||||
private View hView;
|
||||
private NavigationView navigationView;
|
||||
private MenuItem navNotifications;
|
||||
private TextView notificationCounter;
|
||||
|
||||
private BottomSheetListener profileInitListener;
|
||||
private FragmentRefreshListener fragmentRefreshListenerMyIssues;
|
||||
private String username;
|
||||
|
@ -154,6 +151,8 @@ public class MainActivity extends BaseActivity
|
|||
toolbarTitle.setText(getResources().getString(R.string.navMyIssues));
|
||||
} else if (fragmentById instanceof DashboardFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.dashboard));
|
||||
} else if (fragmentById instanceof WatchedRepositoriesFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.navWatchedRepositories));
|
||||
}
|
||||
|
||||
getNotificationsCount();
|
||||
|
@ -503,6 +502,14 @@ public class MainActivity extends BaseActivity
|
|||
.commit();
|
||||
navigationView.setCheckedItem(R.id.nav_dashboard);
|
||||
break;
|
||||
case 12:
|
||||
toolbarTitle.setText(getResources().getString(R.string.navWatchedRepositories));
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, new WatchedRepositoriesFragment())
|
||||
.commit();
|
||||
navigationView.setCheckedItem(R.id.nav_watched_repositories);
|
||||
break;
|
||||
default:
|
||||
toolbarTitle.setText(getResources().getString(R.string.navMyRepos));
|
||||
getSupportFragmentManager()
|
||||
|
@ -737,6 +744,13 @@ public class MainActivity extends BaseActivity
|
|||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, new AccountSettingsFragment())
|
||||
.commit();
|
||||
} else if (id == R.id.nav_watched_repositories) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.navWatchedRepositories));
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, new WatchedRepositoriesFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
|
|
|
@ -71,7 +71,7 @@ public class SettingsGeneralActivity extends BaseActivity {
|
|||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navRepos));
|
||||
} else if (homeScreenSelectedChoice == 4) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navProfile));
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navAccount));
|
||||
} else if (homeScreenSelectedChoice == 5) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(
|
||||
|
@ -96,6 +96,10 @@ public class SettingsGeneralActivity extends BaseActivity {
|
|||
} else if (homeScreenSelectedChoice == 11) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.dashboard));
|
||||
} else if (homeScreenSelectedChoice == 12) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(
|
||||
getResources().getString(R.string.navWatchedRepositories));
|
||||
}
|
||||
|
||||
viewBinding.homeScreenFrame.setOnClickListener(
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.CreateRepoActivity;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.adapters.ReposListAdapter;
|
||||
import org.mian.gitnex.databinding.FragmentRepositoriesBinding;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.viewmodels.RepositoriesViewModel;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
public class WatchedRepositoriesFragment extends Fragment {
|
||||
|
||||
private RepositoriesViewModel repositoriesViewModel;
|
||||
private FragmentRepositoriesBinding fragmentRepositoriesBinding;
|
||||
private ReposListAdapter adapter;
|
||||
private int page = 1;
|
||||
private int resultLimit;
|
||||
|
||||
@Override
|
||||
public View onCreateView(
|
||||
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
fragmentRepositoriesBinding =
|
||||
FragmentRepositoriesBinding.inflate(inflater, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
((MainActivity) requireActivity())
|
||||
.setActionBarTitle(getResources().getString(R.string.navWatchedRepositories));
|
||||
repositoriesViewModel = new ViewModelProvider(this).get(RepositoriesViewModel.class);
|
||||
|
||||
resultLimit = Constants.getCurrentResultLimit(getContext());
|
||||
|
||||
fragmentRepositoriesBinding.addNewRepo.setOnClickListener(
|
||||
view -> {
|
||||
Intent intent = new Intent(view.getContext(), CreateRepoActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
fragmentRepositoriesBinding.recyclerView.setHasFixedSize(true);
|
||||
fragmentRepositoriesBinding.recyclerView.setLayoutManager(
|
||||
new LinearLayoutManager(getContext()));
|
||||
|
||||
fragmentRepositoriesBinding.recyclerView.setPadding(0, 0, 0, 220);
|
||||
fragmentRepositoriesBinding.recyclerView.setClipToPadding(false);
|
||||
|
||||
fragmentRepositoriesBinding.pullToRefresh.setOnRefreshListener(
|
||||
() ->
|
||||
new Handler(Looper.getMainLooper())
|
||||
.postDelayed(
|
||||
() -> {
|
||||
page = 1;
|
||||
fragmentRepositoriesBinding.pullToRefresh.setRefreshing(
|
||||
false);
|
||||
fetchDataAsync();
|
||||
fragmentRepositoriesBinding.progressBar.setVisibility(
|
||||
View.VISIBLE);
|
||||
},
|
||||
50));
|
||||
|
||||
fetchDataAsync();
|
||||
|
||||
return fragmentRepositoriesBinding.getRoot();
|
||||
}
|
||||
|
||||
private void fetchDataAsync() {
|
||||
|
||||
repositoriesViewModel
|
||||
.getRepositories(
|
||||
page,
|
||||
resultLimit,
|
||||
"",
|
||||
"watched",
|
||||
null,
|
||||
getContext(),
|
||||
fragmentRepositoriesBinding)
|
||||
.observe(
|
||||
getViewLifecycleOwner(),
|
||||
reposListMain -> {
|
||||
adapter = new ReposListAdapter(reposListMain, getContext());
|
||||
adapter.setLoadMoreListener(
|
||||
new ReposListAdapter.OnLoadMoreListener() {
|
||||
|
||||
@Override
|
||||
public void onLoadMore() {
|
||||
|
||||
page += 1;
|
||||
repositoriesViewModel.loadMoreRepos(
|
||||
page,
|
||||
resultLimit,
|
||||
"",
|
||||
"watched",
|
||||
null,
|
||||
getContext(),
|
||||
adapter);
|
||||
fragmentRepositoriesBinding.progressBar.setVisibility(
|
||||
View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished() {
|
||||
|
||||
fragmentRepositoriesBinding.progressBar.setVisibility(
|
||||
View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
if (adapter.getItemCount() > 0) {
|
||||
fragmentRepositoriesBinding.recyclerView.setAdapter(adapter);
|
||||
fragmentRepositoriesBinding.noData.setVisibility(View.GONE);
|
||||
} else {
|
||||
adapter.notifyDataChanged();
|
||||
fragmentRepositoriesBinding.recyclerView.setAdapter(adapter);
|
||||
fragmentRepositoriesBinding.noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
fragmentRepositoriesBinding.progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
inflater.inflate(R.menu.search_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
MenuItem searchItem = menu.findItem(R.id.action_search);
|
||||
androidx.appcompat.widget.SearchView searchView =
|
||||
(androidx.appcompat.widget.SearchView) searchItem.getActionView();
|
||||
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
|
||||
searchView.setOnQueryTextListener(
|
||||
new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if (fragmentRepositoriesBinding.recyclerView.getAdapter() != null) {
|
||||
adapter.getFilter().filter(newText);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (MainActivity.reloadRepos) {
|
||||
page = 1;
|
||||
fetchDataAsync();
|
||||
MainActivity.reloadRepos = false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,6 +70,11 @@ public class RepositoriesViewModel extends ViewModel {
|
|||
RetrofitClient.getApiInterface(ctx)
|
||||
.orgListTeamRepos(Long.valueOf(userLogin), page, resultLimit);
|
||||
break;
|
||||
case "watched":
|
||||
call =
|
||||
RetrofitClient.getApiInterface(ctx)
|
||||
.userCurrentListSubscriptions(page, resultLimit);
|
||||
break;
|
||||
default:
|
||||
call = RetrofitClient.getApiInterface(ctx).userCurrentListRepos(page, resultLimit);
|
||||
break;
|
||||
|
|
|
@ -1,20 +1,34 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M1,12s4,-8 11,-8 11,8 11,8 -4,8 -11,8 -11,-8 -11,-8z"
|
||||
android:strokeWidth="2"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M12,12m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0"
|
||||
android:strokeWidth="2"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeLineJoin="round"/>
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M9.88,9.88a3,3 0,1 0,4.24 4.24"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M10.73,5.08A10.43,10.43 0,0 1,12 5c7,0 10,7 10,7a13.16,13.16 0,0 1,-1.67 2.68"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M6.61,6.61A13.526,13.526 0,0 0,2 12s3,7 10,7a9.74,9.74 0,0 0,5.39 -1.61"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M2,2L22,22"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp"
|
||||
android:height="24dp" android:tint="?attr/iconsColor"
|
||||
android:viewportWidth="24.0" android:viewportHeight="24.0">
|
||||
<path android:fillColor="#FF000000"
|
||||
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M2,12s3,-7 10,-7 10,7 10,7 -3,7 -10,7 -10,-7 -10,-7Z"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M12,12m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
||||
|
|
|
@ -254,7 +254,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/repoWatchersInMenu"
|
||||
app:srcCompat="@drawable/ic_unwatch"/>
|
||||
app:srcCompat="@drawable/ic_watchers"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/repoMetaWatchers"
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
android:icon="@drawable/ic_repo"
|
||||
android:title="@string/navRepos"/>
|
||||
|
||||
<item android:id="@+id/nav_watched_repositories"
|
||||
android:icon="@drawable/ic_watchers"
|
||||
android:title="@string/navWatchedRepositories"/>
|
||||
|
||||
<item android:id="@+id/nav_my_issues"
|
||||
android:icon="@drawable/ic_issue"
|
||||
android:title="@string/navMyIssues"
|
||||
|
|
|
@ -77,6 +77,7 @@
|
|||
<item>@string/navMostVisited</item>
|
||||
<item>@string/navNotes</item>
|
||||
<item>@string/dashboard</item>
|
||||
<item>@string/navWatchedRepositories</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="linkHandlerDefaultScreen">
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
<string name="navMostVisited">Most Visited Repos</string>
|
||||
<string name="navNotes">Notes</string>
|
||||
<string name="navAccount">Account Settings</string>
|
||||
<string name="navWatchedRepositories">Watched Repositories</string>
|
||||
<!-- menu items -->
|
||||
|
||||
<!-- page titles -->
|
||||
|
|
Loading…
Reference in New Issue