Implement drafts, introduce Room persistence library for db #139
|
@ -5,11 +5,13 @@ import android.content.Context;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.database.models.DraftsWithRepositories;
|
||||
import org.mian.gitnex.database.repository.DraftsRepository;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -20,38 +22,45 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
|||
|
||||
private List<DraftsWithRepositories> draftsList;
|
||||
private Context mCtx;
|
||||
//private List<CommentsDraft> draftsListFull;
|
||||
|
||||
static class DraftsViewHolder extends RecyclerView.ViewHolder {
|
||||
class DraftsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView draftText;
|
||||
private TextView repoInfo;
|
||||
private TextView draftId;
|
||||
|
||||
private DraftsViewHolder(View itemView) {
|
||||
|
||||
super(itemView);
|
||||
|
||||
draftText = itemView.findViewById(R.id.draftText);
|
||||
repoInfo = itemView.findViewById(R.id.repoInfo);
|
||||
draftId = itemView.findViewById(R.id.draftId);
|
||||
ImageView deleteDraft = itemView.findViewById(R.id.deleteDraft);
|
||||
|
||||
//ImageView draftsDropdownMenu = itemView.findViewById(R.id.draftsDropdownMenu);
|
||||
deleteDraft.setOnClickListener(itemDelete -> {
|
||||
|
||||
/*draftText.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int getDraftId = Integer.parseInt(draftId.getText().toString());
|
||||
deleteDraft(getAdapterPosition());
|
||||
DraftsRepository.deleteSingleDraft(getDraftId);
|
||||
|
||||
Context context = v.getContext();
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
|
||||
}
|
||||
});*/
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public DraftsAdapter(Context mCtx, List<DraftsWithRepositories> draftsListMain) {
|
||||
this.mCtx = mCtx;
|
||||
this.draftsList = draftsListMain;
|
||||
//draftsListFull = new ArrayList<>(draftsList);
|
||||
}
|
||||
|
||||
private void deleteDraft(int position) {
|
||||
|
||||
draftsList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
notifyItemRangeChanged(position, draftsList.size());
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -67,6 +76,7 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
|||
|
||||
DraftsWithRepositories currentItem = draftsList.get(position);
|
||||
|
||||
holder.draftId.setText(String.valueOf(currentItem.getDraftId()));
|
||||
holder.draftText.setText(currentItem.getDraftText());
|
||||
holder.repoInfo.setText(String.format("%s/%s %s%d", currentItem.getRepositoryOwner(), currentItem.getRepositoryName(), mCtx.getResources().getString(R.string.hash), currentItem.getIssueId()));
|
||||
|
||||
|
|
|
@ -10,7 +10,13 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_margin="10dp"
|
||||
android:background="?attr/primaryBackgroundColor"
|
||||
tools:context=".activities.MainActivity" >
|
||||
tools:context=".activities.MainActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/draftId"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/frameDraftInfo"
|
||||
|
@ -35,7 +41,7 @@
|
|||
android:layout_height="20dp"
|
||||
android:layout_gravity="end"
|
||||
android:src="@drawable/ic_delete"
|
||||
android:contentDescription="@string/menuDeleteText"/>
|
||||
android:contentDescription="@string/menuDeleteText" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -46,7 +52,7 @@
|
|||
android:layout_marginBottom="0dp"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="12sp"
|
||||
android:text="@string/noDataFound"/>
|
||||
android:text="@string/noDataFound" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
Reference in New Issue
Block a user