mirror of
https://github.com/gitnex-org/gitnex.git
synced 2026-07-15 12:37:07 -05:00
implement delete a release
This commit is contained in:
@@ -91,7 +91,7 @@ public class CreateFileActivity extends BaseActivity {
|
||||
filePath = getIntent().getStringExtra("filePath");
|
||||
fileSha = getIntent().getStringExtra("fileSha");
|
||||
|
||||
toolbarTitle.setText(getString(R.string.deleteFileText, filePath));
|
||||
toolbarTitle.setText(getString(R.string.deleteGenericTitle, filePath));
|
||||
|
||||
binding.newFileCreate.setText(R.string.deleteFile);
|
||||
|
||||
|
||||
@@ -10,21 +10,30 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import org.gitnex.tea4j.v2.models.Release;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.activities.ProfileActivity;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.Markdown;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.structs.FragmentRefreshListener;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
@@ -34,12 +43,14 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
|
||||
private List<Release> releasesList;
|
||||
private final Context context;
|
||||
private final String repoOwner;
|
||||
private final String repoName;
|
||||
|
||||
private OnLoadMoreListener loadMoreListener;
|
||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||
private final FragmentRefreshListener startDownload;
|
||||
|
||||
static class ReleasesViewHolder extends RecyclerView.ViewHolder {
|
||||
class ReleasesViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private Release releases;
|
||||
|
||||
@@ -56,6 +67,7 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
private final LinearLayout releaseTarDownloadFrame;
|
||||
private final ImageView downloadDropdownIcon;
|
||||
private final RecyclerView downloadList;
|
||||
private final ImageView optionsMenu;
|
||||
|
||||
private ReleasesViewHolder(View itemView) {
|
||||
|
||||
@@ -75,6 +87,7 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
releaseTarDownloadFrame = itemView.findViewById(R.id.releaseTarDownloadFrame);
|
||||
downloadDropdownIcon = itemView.findViewById(R.id.downloadDropdownIcon);
|
||||
downloadList = itemView.findViewById(R.id.downloadList);
|
||||
optionsMenu = itemView.findViewById(R.id.releasesOptionsMenu);
|
||||
|
||||
downloadList.setHasFixedSize(true);
|
||||
downloadList.setLayoutManager(new LinearLayoutManager(itemView.getContext()));
|
||||
@@ -86,13 +99,33 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
intent.putExtra("username", releases.getAuthor().getLogin());
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
||||
optionsMenu.setOnClickListener(v -> {
|
||||
final Context context = v.getContext();
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_release_in_list, null);
|
||||
|
||||
TextView deleteRelease = view.findViewById(R.id.deleteRelease);
|
||||
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
deleteRelease.setOnClickListener(v1 -> {
|
||||
deleteRelease(context, releases.getName(), releases.getId(), repoOwner, repoName, getBindingAdapterPosition());
|
||||
dialog.dismiss();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ReleasesAdapter(Context ctx, List<Release> releasesMain, FragmentRefreshListener startDownload) {
|
||||
public ReleasesAdapter(Context ctx, List<Release> releasesMain, FragmentRefreshListener startDownload, String repoOwner, String repoName) {
|
||||
this.context = ctx;
|
||||
this.releasesList = releasesMain;
|
||||
this.startDownload = startDownload;
|
||||
this.repoOwner = repoOwner;
|
||||
this.repoName = repoName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -178,6 +211,10 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
isLoading = true;
|
||||
loadMoreListener.onLoadMore();
|
||||
}
|
||||
|
||||
if(!((RepoDetailActivity) context).repository.getPermissions().isPush()) {
|
||||
holder.optionsMenu.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -213,4 +250,44 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
releasesList = list;
|
||||
notifyDataChanged();
|
||||
}
|
||||
|
||||
private void updateAdapter(int position) {
|
||||
releasesList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
notifyItemRangeChanged(position, releasesList.size());
|
||||
}
|
||||
|
||||
private void deleteRelease(final Context context, final String releaseName, final Long releaseId, final String owner, final String repo, int position) {
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(String.format(context.getString(R.string.deleteGenericTitle), releaseName))
|
||||
.setMessage(R.string.deleteReleaseConfirmation)
|
||||
.setIcon(R.drawable.ic_delete)
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, whichButton) -> RetrofitClient
|
||||
.getApiInterface(context).repoDeleteRelease(owner, repo, releaseId).enqueue(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
updateAdapter(position);
|
||||
Toasty.success(context, context.getString(R.string.releaseDeleted));
|
||||
MainActivity.repoCreated = true;
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
Toasty.error(context, context.getString(R.string.authorizeError));
|
||||
}
|
||||
else {
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
}))
|
||||
.setNeutralButton(R.string.cancelButton, null).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class TagsAdapter extends RecyclerView.Adapter<TagsAdapter.TagsViewHolder
|
||||
public void tagDeleteDialog(final Context context, final String tagName, final String owner, final String repo, int position) {
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(String.format(context.getString(R.string.deleteTagTitle), tagName))
|
||||
.setTitle(String.format(context.getString(R.string.deleteGenericTitle), tagName))
|
||||
.setMessage(R.string.deleteTagConfirmation)
|
||||
.setIcon(R.drawable.ic_delete)
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, whichButton) -> RetrofitClient
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
@@ -128,7 +129,7 @@ public class ReleasesFragment extends Fragment {
|
||||
|
||||
releasesModel.getReleasesList(owner, repo, getContext()).observe(getViewLifecycleOwner(), releasesListMain -> {
|
||||
if(!repository.isReleasesViewTypeIsTag()) {
|
||||
adapter = new ReleasesAdapter(getContext(), releasesListMain, this::requestFileDownload);
|
||||
adapter = new ReleasesAdapter(getContext(), releasesListMain, this::requestFileDownload, repository.getOwner(), repository.getName());
|
||||
adapter.setLoadMoreListener(new ReleasesAdapter.OnLoadMoreListener() {
|
||||
|
||||
@Override
|
||||
@@ -270,7 +271,7 @@ public class ReleasesFragment extends Fragment {
|
||||
|
||||
OutputStream outputStream = requireContext().getContentResolver().openOutputStream(result.getData().getData());
|
||||
|
||||
AppUtil.copyProgress(response.body().byteStream(), outputStream, 0, p -> {});
|
||||
AppUtil.copyProgress(Objects.requireNonNull(response.body()).byteStream(), outputStream, 0, p -> {});
|
||||
builder.setContentTitle(getString(R.string.fileViewerNotificationTitleFinished))
|
||||
.setContentText(getString(R.string.fileViewerNotificationDescriptionFinished,
|
||||
Uri.parse(currentDownloadUrl).getLastPathSegment())).setOngoing(false);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class AlertDialogs {
|
||||
RepositoryContext repository) {
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(context.getString(R.string.deleteLabelTitle, labelTitle))
|
||||
.setTitle(context.getString(R.string.deleteGenericTitle, labelTitle))
|
||||
.setMessage(R.string.labelDeleteMessage)
|
||||
.setIcon(R.drawable.ic_delete)
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, whichButton) -> {
|
||||
|
||||
67
app/src/main/res/layout/bottom_sheet_release_in_list.xml
Normal file
67
app/src/main/res/layout/bottom_sheet_release_in_list.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:background="?attr/primaryBackgroundColor">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/releasesListHeadFrame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bottomSheetHeader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/release"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
android:id="@+id/releasesListSection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:flexWrap="wrap"
|
||||
app:alignItems="stretch"
|
||||
android:padding="8dp"
|
||||
app:alignContent="stretch" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deleteRelease"
|
||||
android:layout_width="98dp"
|
||||
android:layout_height="100dp"
|
||||
android:padding="8dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:gravity="center"
|
||||
app:layout_alignSelf="flex_start"
|
||||
app:drawableTopCompat="@drawable/ic_delete"
|
||||
android:text="@string/menuDeleteText"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.flexbox.FlexboxLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -29,16 +29,15 @@
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/releaseType"
|
||||
<ImageView
|
||||
android:id="@+id/releasesOptionsMenu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:background="@drawable/shape_stable_release"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:textColor="@color/colorWhite"
|
||||
android:textSize="14sp" />
|
||||
android:layout_gravity="center_vertical|end"
|
||||
android:contentDescription="@string/labelMenuContentDesc"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_dotted_menu_horizontal" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -77,6 +76,25 @@
|
||||
android:gravity="end"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end|center_vertical"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/releaseType"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/shape_stable_release"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp"
|
||||
android:textColor="@color/colorWhite"
|
||||
android:textSize="14sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
@@ -270,7 +270,6 @@
|
||||
|
||||
<string name="alertDialogTokenRevokedTitle">Authorization Error</string>
|
||||
<string name="alertDialogTokenRevokedMessage">It seems that the Access Token is revoked OR your are not allowed to see these contents.\n\nIn case of revoked Token, please logout and login again</string>
|
||||
<string name="deleteLabelTitle">Delete %s</string>
|
||||
<string name="labelDeleteMessage">Do you really want to delete this label?</string>
|
||||
|
||||
<!-- org tabbed layout str -->
|
||||
@@ -404,6 +403,8 @@
|
||||
<string name="tagNameErrorEmpty">Tag name is empty</string>
|
||||
<string name="titleErrorEmpty">Title is empty</string>
|
||||
<string name="releaseCreatedText">New release created</string>
|
||||
<string name="deleteReleaseConfirmation">Do you really want to delete this release?</string>
|
||||
<string name="releaseDeleted">Release deleted</string>
|
||||
<!-- release -->
|
||||
|
||||
<string name="loginOTPTypeError">OTP code should be numbers</string>
|
||||
@@ -506,6 +507,7 @@
|
||||
<string name="download">Download</string>
|
||||
<string name="reopen">Reopen</string>
|
||||
<string name="openInBrowser">Open in Browser</string>
|
||||
<string name="deleteGenericTitle">Delete %s</string>
|
||||
<!-- generic copy -->
|
||||
|
||||
<string name="exploreUsers">Explore users</string>
|
||||
@@ -561,7 +563,6 @@
|
||||
<string name="excludeFilesInFileViewer">This file type/size is not supported in file viewer. You can download it from the menu.</string>
|
||||
<string name="deleteFile">Delete This File</string>
|
||||
<string name="editFile">Edit This File</string>
|
||||
<string name="deleteFileText">Delete %1$s</string>
|
||||
<string name="deleteFileMessage">File is set for deletion by branch %1$s</string>
|
||||
<string name="editFileText">Edit %1$s</string>
|
||||
<string name="editFileMessage">File is modified by branch %1$s</string>
|
||||
@@ -750,7 +751,7 @@
|
||||
<string name="tagCreated">Tag created</string>
|
||||
<string name="asRef">Use as reference</string>
|
||||
<string name="deleteTagConfirmation">Do you really want to delete this tag?</string>
|
||||
<string name="deleteTagTitle">Delete tag %s</string>
|
||||
|
||||
<string name="tagDeleted">Tag deleted</string>
|
||||
<string name="tagDeleteError">A tag attached to a release cannot be deleted directly</string>
|
||||
<string name="useCustomTabs">Use Custom Tabs</string>
|
||||
|
||||
Reference in New Issue
Block a user