mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2023-12-13 20:50:18 +01:00
Reset all or one record for most visited repos
This commit is contained in:
parent
e541f0b0b1
commit
a2ecb3e527
|
@ -13,10 +13,14 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.database.api.BaseApi;
|
||||
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||
import org.mian.gitnex.database.models.Repository;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -27,8 +31,9 @@ import java.util.List;
|
|||
public class MostVisitedReposAdapter extends RecyclerView.Adapter<MostVisitedReposAdapter.MostVisitedViewHolder> {
|
||||
|
||||
private List<Repository> mostVisitedReposList;
|
||||
private final Context ctx;
|
||||
|
||||
static class MostVisitedViewHolder extends RecyclerView.ViewHolder {
|
||||
class MostVisitedViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private Repository repository;
|
||||
|
||||
|
@ -36,6 +41,7 @@ public class MostVisitedReposAdapter extends RecyclerView.Adapter<MostVisitedRep
|
|||
private final TextView repoName;
|
||||
private final TextView orgName;
|
||||
private final TextView mostVisited;
|
||||
private final ImageView resetCounter;
|
||||
|
||||
private MostVisitedViewHolder(View itemView) {
|
||||
|
||||
|
@ -45,6 +51,7 @@ public class MostVisitedReposAdapter extends RecyclerView.Adapter<MostVisitedRep
|
|||
repoName = itemView.findViewById(R.id.repo_name);
|
||||
orgName = itemView.findViewById(R.id.org_name);
|
||||
mostVisited = itemView.findViewById(R.id.most_visited);
|
||||
resetCounter = itemView.findViewById(R.id.reset_counter);
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
|
||||
|
@ -53,10 +60,37 @@ public class MostVisitedReposAdapter extends RecyclerView.Adapter<MostVisitedRep
|
|||
Intent intent = repositoryContext.getIntent(context, RepoDetailActivity.class);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
||||
resetCounter.setOnClickListener(itemDelete -> {
|
||||
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
||||
|
||||
materialAlertDialogBuilder.setTitle(ctx.getString(R.string.reset))
|
||||
.setMessage(ctx.getString(R.string.resetCounterDialogMessage, repository.getRepositoryName()))
|
||||
.setPositiveButton(R.string.reset, (dialog, whichButton) -> {
|
||||
|
||||
int getRepositoryId = repository.getRepositoryId();
|
||||
resetRepositoryCounter(getBindingAdapterPosition());
|
||||
|
||||
RepositoriesApi repositoriesApi = BaseApi.getInstance(ctx, RepositoriesApi.class);
|
||||
assert repositoriesApi != null;
|
||||
repositoriesApi.updateRepositoryMostVisited(0, getRepositoryId);
|
||||
})
|
||||
.setNeutralButton(R.string.cancelButton, null).show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public MostVisitedReposAdapter(List<Repository> reposListMain) {
|
||||
private void resetRepositoryCounter(int position) {
|
||||
|
||||
mostVisitedReposList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
notifyItemRangeChanged(position, mostVisitedReposList.size());
|
||||
Toasty.success(ctx, ctx.getResources().getString(R.string.resetMostReposCounter));
|
||||
}
|
||||
|
||||
public MostVisitedReposAdapter(Context ctx, List<Repository> reposListMain) {
|
||||
this.ctx = ctx;
|
||||
this.mostVisitedReposList = reposListMain;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,10 @@ public class RepositoriesApi extends BaseApi {
|
|||
executorService.execute(() -> repositoriesDao.updateRepositoryMostVisited(mostVisited, repositoryId));
|
||||
}
|
||||
|
||||
public void resetAllRepositoryMostVisited(int repoAccountId) {
|
||||
executorService.execute(() -> repositoriesDao.resetAllRepositoryMostVisited(repoAccountId));
|
||||
}
|
||||
|
||||
public LiveData<List<Repository>> fetchAllMostVisited(int repoAccountId) {
|
||||
return repositoriesDao.fetchAllMostVisited(repoAccountId);
|
||||
}
|
||||
|
|
|
@ -49,4 +49,7 @@ public interface RepositoriesDao {
|
|||
|
||||
@Query("SELECT * FROM Repositories WHERE mostVisited > 0 AND repoAccountId = :repoAccountId ORDER BY mostVisited DESC LIMIT 50")
|
||||
LiveData<List<Repository>> fetchAllMostVisited(int repoAccountId);
|
||||
|
||||
@Query("UPDATE Repositories SET mostVisited = 0 WHERE repoAccountId = :repoAccountId")
|
||||
void resetAllRepositoryMostVisited(int repoAccountId);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ 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.widget.TextView;
|
||||
|
@ -13,6 +16,7 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.adapters.MostVisitedReposAdapter;
|
||||
|
@ -21,8 +25,10 @@ import org.mian.gitnex.database.api.RepositoriesApi;
|
|||
import org.mian.gitnex.database.models.Repository;
|
||||
import org.mian.gitnex.databinding.FragmentDraftsBinding;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
|
@ -62,7 +68,7 @@ public class MostVisitedReposFragment extends Fragment {
|
|||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||
|
||||
adapter = new MostVisitedReposAdapter(mostVisitedReposList);
|
||||
adapter = new MostVisitedReposAdapter(ctx, mostVisitedReposList);
|
||||
currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
|
@ -95,4 +101,48 @@ public class MostVisitedReposFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void resetAllRepositoryCounter(int accountId) {
|
||||
|
||||
if(mostVisitedReposList.size() > 0) {
|
||||
|
||||
Objects.requireNonNull(BaseApi.getInstance(ctx, RepositoriesApi.class)).resetAllRepositoryMostVisited(accountId);
|
||||
mostVisitedReposList.clear();
|
||||
adapter.notifyDataChanged();
|
||||
Toasty.success(ctx, getResources().getString(R.string.resetMostReposCounter));
|
||||
}
|
||||
else {
|
||||
Toasty.warning(ctx, getResources().getString(R.string.noDataFound));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
inflater.inflate(R.menu.reset_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
if(item.getItemId() == R.id.reset_menu_item) {
|
||||
|
||||
if (mostVisitedReposList.size() == 0) {
|
||||
Toasty.warning(ctx, getResources().getString(R.string.noDataFound));
|
||||
}
|
||||
else {
|
||||
new MaterialAlertDialogBuilder(ctx)
|
||||
.setTitle(R.string.reset)
|
||||
.setMessage(R.string.resetCounterAllDialogMessage)
|
||||
.setPositiveButton(R.string.reset, (dialog, which) -> {
|
||||
|
||||
resetAllRepositoryCounter(currentActiveAccountId);
|
||||
dialog.dismiss();
|
||||
}).setNeutralButton(R.string.cancelButton, null).show();
|
||||
}
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
13
app/src/main/res/drawable/ic_reset.xml
Normal file
13
app/src/main/res/drawable/ic_reset.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<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="M4,4v5h0.582m15.356,2A8.001,8.001 0,0 0,4.582 9m0,0H9m11,11v-5h-0.581m0,0a8.003,8.003 0,0 1,-15.357 -2m15.357,2H15"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -66,12 +66,10 @@
|
|||
android:layout_marginBottom="@dimen/dimen8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/repo_info_stars_frame"
|
||||
android:id="@+id/repo_info_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|start"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="@dimen/dimen18dp"
|
||||
|
@ -91,6 +89,28 @@
|
|||
android:textSize="@dimen/dimen14sp"
|
||||
tools:text="@string/repoStars" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/repo_info_end_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/dimen10dp"
|
||||
android:gravity="center_vertical|end"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="@dimen/dimen6dp"
|
||||
android:paddingEnd="@dimen/dimen6dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/reset_counter"
|
||||
android:layout_width="@dimen/dimen18dp"
|
||||
android:layout_height="@dimen/dimen18dp"
|
||||
android:layout_marginStart="@dimen/dimen16dp"
|
||||
android:layout_marginEnd="@dimen/dimen2dp"
|
||||
android:contentDescription="@string/generalImgContentText"
|
||||
app:srcCompat="@drawable/ic_reset"
|
||||
app:tint="?attr/iconsColor" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
android:id="@+id/orgInfoFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginBottom="@dimen/dimen8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="UseCompoundDrawables">
|
||||
|
@ -43,8 +43,8 @@
|
|||
android:id="@+id/imageAvatar"
|
||||
android:layout_width="@dimen/dimen24dp"
|
||||
android:layout_height="@dimen/dimen24dp"
|
||||
android:layout_marginStart="0dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginStart="@dimen/dimen0dp"
|
||||
android:layout_marginEnd="@dimen/dimen10dp"
|
||||
android:contentDescription="@string/repoContentAvatar"
|
||||
android:src="@drawable/ic_android" />
|
||||
|
||||
|
@ -53,7 +53,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="14sp"
|
||||
android:textSize="@dimen/dimen14sp"
|
||||
tools:text="@string/orgName" />
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -64,16 +64,16 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/repoName"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="18sp"
|
||||
android:textSize="@dimen/dimen18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/repoDescription"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginBottom="@dimen/dimen8dp"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="15sp"
|
||||
android:textSize="@dimen/dimen16sp"
|
||||
android:visibility="gone"
|
||||
android:text="@string/noDataDescription" />
|
||||
|
||||
|
@ -81,7 +81,7 @@
|
|||
android:id="@+id/spacerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="8dp" />
|
||||
android:layout_marginBottom="@dimen/dimen8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/repoInfoFrame"
|
||||
|
@ -94,7 +94,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/hintColor"
|
||||
android:textSize="13sp"
|
||||
android:textSize="@dimen/dimen12sp"
|
||||
tools:text="@string/lastUpdatedAt" />
|
||||
|
||||
<LinearLayout
|
||||
|
@ -104,14 +104,14 @@
|
|||
android:layout_marginStart="10dp"
|
||||
android:gravity="center_vertical|end"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp">
|
||||
android:paddingStart="@dimen/dimen6dp"
|
||||
android:paddingEnd="@dimen/dimen6dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_marginStart="3dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_width="@dimen/dimen18dp"
|
||||
android:layout_height="@dimen/dimen18dp"
|
||||
android:layout_marginStart="@dimen/dimen4dp"
|
||||
android:layout_marginEnd="@dimen/dimen6dp"
|
||||
android:contentDescription="@string/generalImgContentText"
|
||||
app:srcCompat="@drawable/ic_star"
|
||||
app:tint="?attr/iconsColor" />
|
||||
|
@ -122,14 +122,14 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="14sp"
|
||||
android:textSize="@dimen/dimen14sp"
|
||||
tools:text="@string/repoStars" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="18dp"
|
||||
android:layout_height="18dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_width="@dimen/dimen18dp"
|
||||
android:layout_height="@dimen/dimen18dp"
|
||||
android:layout_marginStart="@dimen/dimen16dp"
|
||||
android:layout_marginEnd="@dimen/dimen2dp"
|
||||
android:contentDescription="@string/generalImgContentText"
|
||||
android:visibility="gone"
|
||||
app:srcCompat="@drawable/ic_star"
|
||||
|
@ -141,7 +141,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="14sp"
|
||||
android:textSize="@dimen/dimen14sp"
|
||||
android:visibility="gone"
|
||||
tools:text="Java" />
|
||||
|
||||
|
|
12
app/src/main/res/menu/reset_menu.xml
Normal file
12
app/src/main/res/menu/reset_menu.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/reset_menu_item"
|
||||
android:icon="@drawable/ic_reset"
|
||||
android:title="@string/menuContentDesc"
|
||||
android:orderInCategory="1"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
|
@ -508,6 +508,7 @@
|
|||
<string name="reopen">Reopen</string>
|
||||
<string name="openInBrowser">Open in Browser</string>
|
||||
<string name="deleteGenericTitle">Delete %s</string>
|
||||
<string name="reset">Reset</string>
|
||||
<!-- generic copy -->
|
||||
|
||||
<string name="exploreUsers">Explore users</string>
|
||||
|
@ -616,6 +617,10 @@
|
|||
<string name="deleteAllDraftsDialogMessage">This will delete all the drafts for this account. \n\nProceed with deletion?</string>
|
||||
<string name="draftSaved">Draft was saved automatically.</string>
|
||||
|
||||
<string name="resetMostReposCounter">Counter is reset successfully</string>
|
||||
<string name="resetCounterDialogMessage">Do you want to reset counter for repository %s?</string>
|
||||
<string name="resetCounterAllDialogMessage">This will reset all the counters for this account repositories.</string>
|
||||
|
||||
<string name="appearanceHintText">Themes, fonts, badges</string>
|
||||
<string name="securityHintText">Biometric authentication, SSL certificates, cache</string>
|
||||
<string name="languagesHintText">Languages</string>
|
||||
|
|
Loading…
Reference in a new issue