Insert note(s) to an issue description

This commit is contained in:
M M Arif 2024-05-10 22:49:51 +05:00
parent 601bc80bc5
commit ab0f5b0a47
6 changed files with 138 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -14,6 +15,7 @@ import android.widget.TextView;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.datepicker.MaterialDatePicker;
@ -43,10 +45,15 @@ import org.mian.gitnex.actions.LabelsActions;
import org.mian.gitnex.adapters.AssigneesListAdapter;
import org.mian.gitnex.adapters.AttachmentsAdapter;
import org.mian.gitnex.adapters.LabelsListAdapter;
import org.mian.gitnex.adapters.NotesAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.NotesApi;
import org.mian.gitnex.database.models.Notes;
import org.mian.gitnex.databinding.ActivityCreateIssueBinding;
import org.mian.gitnex.databinding.BottomSheetAttachmentsBinding;
import org.mian.gitnex.databinding.CustomAssigneesSelectionDialogBinding;
import org.mian.gitnex.databinding.CustomInsertNoteBinding;
import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
import org.mian.gitnex.fragments.IssuesFragment;
import org.mian.gitnex.helpers.AlertDialogs;
@ -84,6 +91,11 @@ public class CreateIssueActivity extends BaseActivity
private static List<AttachmentsModel> attachmentsList;
private AttachmentsAdapter attachmentsAdapter;
private static final List<Uri> contentUri = new ArrayList<>();
private CustomInsertNoteBinding customInsertNoteBinding;
private NotesAdapter adapter;
private NotesApi notesApi;
private List<Notes> notesList;
public AlertDialog dialogNotes;
@SuppressLint("ClickableViewAccessibility")
@Override
@ -174,6 +186,8 @@ public class CreateIssueActivity extends BaseActivity
}
});
viewBinding.insertNote.setOnClickListener(insertNote -> showAllNotes());
getMilestones(repository.getOwner(), repository.getName(), resultLimit);
viewBinding.newIssueLabels.setOnClickListener(newIssueLabels -> showLabels());
@ -189,6 +203,58 @@ public class CreateIssueActivity extends BaseActivity
}
}
private void showAllNotes() {
notesList = new ArrayList<>();
notesApi = BaseApi.getInstance(ctx, NotesApi.class);
customInsertNoteBinding = CustomInsertNoteBinding.inflate(LayoutInflater.from(ctx));
View view = customInsertNoteBinding.getRoot();
materialAlertDialogBuilder.setView(view);
customInsertNoteBinding.recyclerView.setHasFixedSize(true);
customInsertNoteBinding.recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
adapter = new NotesAdapter(ctx, notesList, "insert");
customInsertNoteBinding.pullToRefresh.setOnRefreshListener(
() ->
new Handler(Looper.getMainLooper())
.postDelayed(
() -> {
notesList.clear();
customInsertNoteBinding.pullToRefresh.setRefreshing(
false);
customInsertNoteBinding.progressBar.setVisibility(
View.VISIBLE);
fetchNotes();
},
250));
fetchNotes();
dialogNotes = materialAlertDialogBuilder.show();
}
private void fetchNotes() {
notesApi.fetchAllNotes()
.observe(
this,
allNotes -> {
assert allNotes != null;
if (!allNotes.isEmpty()) {
notesList.clear();
notesList.addAll(allNotes);
adapter.notifyDataChanged();
customInsertNoteBinding.recyclerView.setAdapter(adapter);
}
customInsertNoteBinding.progressBar.setVisibility(View.GONE);
});
}
ActivityResultLauncher<Intent> startActivityForResult =
registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),

View File

@ -6,6 +6,7 @@ import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -19,6 +20,7 @@ import java.util.Locale;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CreateIssueActivity;
import org.mian.gitnex.activities.CreateNoteActivity;
import org.mian.gitnex.database.api.BaseApi;
import org.mian.gitnex.database.api.NotesApi;
@ -35,11 +37,13 @@ public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NotesViewHol
private List<Notes> notesList;
private final Context ctx;
private final Intent noteIntent;
private final String insert;
public NotesAdapter(Context ctx, List<Notes> notesListMain) {
public NotesAdapter(Context ctx, List<Notes> notesListMain, String insert) {
this.ctx = ctx;
this.notesList = notesListMain;
noteIntent = new Intent(ctx, CreateNoteActivity.class);
this.insert = insert;
}
public class NotesViewHolder extends RecyclerView.ViewHolder {
@ -82,6 +86,20 @@ public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NotesViewHol
.setNeutralButton(R.string.cancelButton, null)
.show();
});
if (insert.equalsIgnoreCase("insert")) {
deleteNote.setVisibility(View.GONE);
itemView.setOnClickListener(
view -> {
CreateIssueActivity parentActivity = (CreateIssueActivity) ctx;
EditText text = parentActivity.findViewById(R.id.newIssueDescription);
text.append(notes.getContent());
parentActivity.dialogNotes.dismiss();
});
}
}
}

View File

@ -70,7 +70,7 @@ public class NotesFragment extends Fragment {
binding.recyclerView.setPadding(0, 0, 0, 220);
binding.recyclerView.setClipToPadding(false);
adapter = new NotesAdapter(ctx, notesList);
adapter = new NotesAdapter(ctx, notesList, "");
binding.pullToRefresh.setOnRefreshListener(
() ->
@ -103,7 +103,7 @@ public class NotesFragment extends Fragment {
allNotes -> {
binding.pullToRefresh.setRefreshing(false);
assert allNotes != null;
if (allNotes.size() > 0) {
if (!allNotes.isEmpty()) {
notesList.clear();
binding.noData.setVisibility(View.GONE);
@ -138,7 +138,7 @@ public class NotesFragment extends Fragment {
public void deleteAllNotes() {
if (notesList.size() > 0) {
if (!notesList.isEmpty()) {
notesApi.deleteAllNotes();
notesList.clear();
@ -159,6 +159,7 @@ public class NotesFragment extends Fragment {
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView();
assert searchView != null;
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
searchView.setOnQueryTextListener(
@ -184,7 +185,7 @@ public class NotesFragment extends Fragment {
if (item.getItemId() == R.id.reset_menu_item) {
if (notesList.size() == 0) {
if (notesList.isEmpty()) {
Toasty.warning(ctx, getResources().getString(R.string.noDataFound));
} else {
new MaterialAlertDialogBuilder(ctx)

View File

@ -84,6 +84,17 @@
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/insertNote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="@dimen/dimen8dp"
android:layout_marginBottom="@dimen/dimen0dp"
android:text="@string/insertNote"
android:textColor="?attr/primaryTextColor"
android:textSize="@dimen/dimen14sp"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/newIssueDescriptionLayout"
android:layout_width="match_parent"

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/primaryBackgroundColor"
android:padding="@dimen/dimen16dp">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/pullToRefresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</FrameLayout>
<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
style="@style/Widget.Material3.LinearProgressIndicator"
app:indicatorColor="?attr/progressIndicatorColor" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -853,6 +853,7 @@
<item quantity="other">Notes deleted successfully</item>
</plurals>
<string name="notesAllDeletionMessage">This will delete all of your notes. This action cannot be undone.</string>
<string name="insertNote">Insert a Note</string>
<!-- timeline -->
<string name="commitsText">commit</string>