Optimize fragments, add filters, fix search and clean up (#439)
Code Reformat hide not found message Refactor issues, remove fastadapter. fix swipe back filter icon issue, fix crash on issues with faster swiping Change filter icon based on selection, empty the list for progress bar, check for gitea version to pass limit and other improvements Separate menu and interface for pr Add filter bottom sheet to PRs, issues Fix search/filter pull requests Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: 6543 <6543@noreply.gitea.io> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/439 Reviewed-by: opyale <opyale@noreply.gitea.io>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import org.mian.gitnex.R;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class BottomSheetIssuesFilterFragment extends BottomSheetDialogFragment {
|
||||
|
||||
private BottomSheetIssuesFilterFragment.BottomSheetListener bmListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.bottom_sheet_issues_filter, container, false);
|
||||
|
||||
TextView openIssues = v.findViewById(R.id.openIssues);
|
||||
TextView closedIssues = v.findViewById(R.id.closedIssues);
|
||||
|
||||
openIssues.setOnClickListener(v1 -> {
|
||||
bmListener.onButtonClicked("openIssues");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
closedIssues.setOnClickListener(v12 -> {
|
||||
bmListener.onButtonClicked("closedIssues");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public interface BottomSheetListener {
|
||||
|
||||
void onButtonClicked(String text);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
|
||||
super.onAttach(context);
|
||||
|
||||
try {
|
||||
bmListener = (BottomSheetIssuesFilterFragment.BottomSheetListener) context;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
throw new ClassCastException(context.toString() + " must implement BottomSheetListener");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import org.mian.gitnex.R;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class BottomSheetPullRequestFilterFragment extends BottomSheetDialogFragment {
|
||||
|
||||
private BottomSheetPullRequestFilterFragment.BottomSheetListener bmListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.bottom_sheet_pull_request_filter, container, false);
|
||||
|
||||
TextView openPr = v.findViewById(R.id.openPr);
|
||||
TextView closedPr = v.findViewById(R.id.closedPr);
|
||||
|
||||
openPr.setOnClickListener(v1 -> {
|
||||
bmListener.onButtonClicked("openPr");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
closedPr.setOnClickListener(v12 -> {
|
||||
bmListener.onButtonClicked("closedPr");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public interface BottomSheetListener {
|
||||
|
||||
void onButtonClicked(String text);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
|
||||
super.onAttach(context);
|
||||
|
||||
try {
|
||||
bmListener = (BottomSheetPullRequestFilterFragment.BottomSheetListener) context;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
throw new ClassCastException(context.toString() + " must implement BottomSheetListener");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
@@ -7,6 +9,8 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.actions.IssueActions;
|
||||
@@ -17,10 +21,6 @@ import org.mian.gitnex.activities.FileDiffActivity;
|
||||
import org.mian.gitnex.activities.MergePullRequestActivity;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ClipData;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -29,213 +29,219 @@ import java.util.Objects;
|
||||
|
||||
public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.bottom_sheet_single_issue_layout, container, false);
|
||||
View v = inflater.inflate(R.layout.bottom_sheet_single_issue_layout, container, false);
|
||||
|
||||
final Context ctx = getContext();
|
||||
final TinyDB tinyDB = new TinyDB(ctx);
|
||||
final Context ctx = getContext();
|
||||
final TinyDB tinyDB = new TinyDB(ctx);
|
||||
|
||||
TextView editIssue = v.findViewById(R.id.editIssue);
|
||||
TextView editLabels = v.findViewById(R.id.editLabels);
|
||||
TextView closeIssue = v.findViewById(R.id.closeIssue);
|
||||
TextView reOpenIssue = v.findViewById(R.id.reOpenIssue);
|
||||
TextView addRemoveAssignees = v.findViewById(R.id.addRemoveAssignees);
|
||||
TextView copyIssueUrl = v.findViewById(R.id.copyIssueUrl);
|
||||
TextView openFilesDiff = v.findViewById(R.id.openFilesDiff);
|
||||
TextView mergePullRequest = v.findViewById(R.id.mergePullRequest);
|
||||
TextView shareIssue = v.findViewById(R.id.shareIssue);
|
||||
TextView subscribeIssue = v.findViewById(R.id.subscribeIssue);
|
||||
TextView unsubscribeIssue = v.findViewById(R.id.unsubscribeIssue);
|
||||
TextView editIssue = v.findViewById(R.id.editIssue);
|
||||
TextView editLabels = v.findViewById(R.id.editLabels);
|
||||
TextView closeIssue = v.findViewById(R.id.closeIssue);
|
||||
TextView reOpenIssue = v.findViewById(R.id.reOpenIssue);
|
||||
TextView addRemoveAssignees = v.findViewById(R.id.addRemoveAssignees);
|
||||
TextView copyIssueUrl = v.findViewById(R.id.copyIssueUrl);
|
||||
TextView openFilesDiff = v.findViewById(R.id.openFilesDiff);
|
||||
TextView mergePullRequest = v.findViewById(R.id.mergePullRequest);
|
||||
TextView shareIssue = v.findViewById(R.id.shareIssue);
|
||||
TextView subscribeIssue = v.findViewById(R.id.subscribeIssue);
|
||||
TextView unsubscribeIssue = v.findViewById(R.id.unsubscribeIssue);
|
||||
|
||||
if(tinyDB.getString("issueType").equals("pr")) {
|
||||
if(tinyDB.getString("issueType").equals("pr")) {
|
||||
|
||||
editIssue.setText(R.string.editPrText);
|
||||
copyIssueUrl.setText(R.string.copyPrUrlText);
|
||||
shareIssue.setText(R.string.sharePr);
|
||||
editIssue.setText(R.string.editPrText);
|
||||
copyIssueUrl.setText(R.string.copyPrUrlText);
|
||||
shareIssue.setText(R.string.sharePr);
|
||||
|
||||
if(tinyDB.getBoolean("prMerged")) {
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
mergePullRequest.setVisibility(View.VISIBLE);
|
||||
}
|
||||
if(tinyDB.getBoolean("prMerged") || tinyDB.getString("repoPrState").equals("closed")) {
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
mergePullRequest.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if(tinyDB.getString("repoType").equals("public")) {
|
||||
openFilesDiff.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
openFilesDiff.setVisibility(View.GONE);
|
||||
}
|
||||
if(tinyDB.getString("repoType").equals("public")) {
|
||||
openFilesDiff.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
openFilesDiff.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mergePullRequest.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mergePullRequest.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
startActivity(new Intent(ctx, MergePullRequestActivity.class));
|
||||
dismiss();
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
startActivity(new Intent(ctx, MergePullRequestActivity.class));
|
||||
dismiss();
|
||||
|
||||
openFilesDiff.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
}
|
||||
});
|
||||
|
||||
startActivity(new Intent(ctx, FileDiffActivity.class));
|
||||
dismiss();
|
||||
openFilesDiff.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
editIssue.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(ctx, FileDiffActivity.class));
|
||||
dismiss();
|
||||
|
||||
startActivity(new Intent(ctx, EditIssueActivity.class));
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
editIssue.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
editLabels.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
startActivity(new Intent(ctx, AddRemoveLabelsActivity.class));
|
||||
dismiss();
|
||||
startActivity(new Intent(ctx, EditIssueActivity.class));
|
||||
dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
addRemoveAssignees.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
editLabels.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
startActivity(new Intent(ctx, AddRemoveAssigneesActivity.class));
|
||||
dismiss();
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
startActivity(new Intent(ctx, AddRemoveLabelsActivity.class));
|
||||
dismiss();
|
||||
|
||||
shareIssue.setOnClickListener(v1 -> {
|
||||
}
|
||||
});
|
||||
|
||||
// get url of repo
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String instanceUrlWithProtocol = "https://" + tinyDB.getString("instanceUrlRaw");
|
||||
if (!tinyDB.getString("instanceUrlWithProtocol").isEmpty()) {
|
||||
instanceUrlWithProtocol = tinyDB.getString("instanceUrlWithProtocol");
|
||||
}
|
||||
addRemoveAssignees.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
// get issue Url
|
||||
String issueUrl = instanceUrlWithProtocol + "/" + repoFullName + "/issues/" + tinyDB.getString("issueNumber");
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
// share issue
|
||||
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||
sharingIntent.setType("text/plain");
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle"));
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, issueUrl);
|
||||
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle")));
|
||||
startActivity(new Intent(ctx, AddRemoveAssigneesActivity.class));
|
||||
dismiss();
|
||||
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
shareIssue.setOnClickListener(v1 -> {
|
||||
|
||||
copyIssueUrl.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// get url of repo
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String instanceUrlWithProtocol = "https://" + tinyDB.getString("instanceUrlRaw");
|
||||
if(!tinyDB.getString("instanceUrlWithProtocol").isEmpty()) {
|
||||
instanceUrlWithProtocol = tinyDB.getString("instanceUrlWithProtocol");
|
||||
}
|
||||
|
||||
// get url of repo
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String instanceUrlWithProtocol = "https://" + tinyDB.getString("instanceUrlRaw");
|
||||
if (!tinyDB.getString("instanceUrlWithProtocol").isEmpty()) {
|
||||
instanceUrlWithProtocol = tinyDB.getString("instanceUrlWithProtocol");
|
||||
}
|
||||
// get issue Url
|
||||
String issueUrl = instanceUrlWithProtocol + "/" + repoFullName + "/issues/" + tinyDB.getString("issueNumber");
|
||||
|
||||
// get issue Url
|
||||
String issueUrl = instanceUrlWithProtocol + "/" + repoFullName + "/issues/" + tinyDB.getString("issueNumber");
|
||||
// share issue
|
||||
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||
sharingIntent.setType("text/plain");
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle"));
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, issueUrl);
|
||||
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle")));
|
||||
|
||||
// copy to clipboard
|
||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(android.content.Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("issueUrl", issueUrl);
|
||||
assert clipboard != null;
|
||||
clipboard.setPrimaryClip(clip);
|
||||
dismiss();
|
||||
|
||||
dismiss();
|
||||
});
|
||||
|
||||
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
||||
copyIssueUrl.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if(tinyDB.getString("issueType").equals("issue")) {
|
||||
// get url of repo
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String instanceUrlWithProtocol = "https://" + tinyDB.getString("instanceUrlRaw");
|
||||
if(!tinyDB.getString("instanceUrlWithProtocol").isEmpty()) {
|
||||
instanceUrlWithProtocol = tinyDB.getString("instanceUrlWithProtocol");
|
||||
}
|
||||
|
||||
if (tinyDB.getString("issueState").equals("open")) { // close issue
|
||||
// get issue Url
|
||||
String issueUrl = instanceUrlWithProtocol + "/" + repoFullName + "/issues/" + tinyDB.getString("issueNumber");
|
||||
|
||||
reOpenIssue.setVisibility(View.GONE);
|
||||
closeIssue.setVisibility(View.VISIBLE);
|
||||
// copy to clipboard
|
||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(android.content.Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("issueUrl", issueUrl);
|
||||
assert clipboard != null;
|
||||
clipboard.setPrimaryClip(clip);
|
||||
|
||||
closeIssue.setOnClickListener(closeSingleIssue -> {
|
||||
dismiss();
|
||||
|
||||
IssueActions.closeReopenIssue(ctx, Integer.parseInt(tinyDB.getString("issueNumber")), "closed");
|
||||
dismiss();
|
||||
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else if (tinyDB.getString("issueState").equals("closed")) {
|
||||
if(tinyDB.getString("issueType").equals("issue")) {
|
||||
|
||||
closeIssue.setVisibility(View.GONE);
|
||||
reOpenIssue.setVisibility(View.VISIBLE);
|
||||
if(tinyDB.getString("issueState").equals("open")) { // close issue
|
||||
|
||||
reOpenIssue.setOnClickListener(reOpenSingleIssue -> {
|
||||
reOpenIssue.setVisibility(View.GONE);
|
||||
closeIssue.setVisibility(View.VISIBLE);
|
||||
|
||||
IssueActions.closeReopenIssue(ctx, Integer.parseInt(tinyDB.getString("issueNumber")), "open");
|
||||
dismiss();
|
||||
closeIssue.setOnClickListener(closeSingleIssue -> {
|
||||
|
||||
});
|
||||
IssueActions.closeReopenIssue(ctx, Integer.parseInt(tinyDB.getString("issueNumber")), "closed");
|
||||
dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
}
|
||||
else if(tinyDB.getString("issueState").equals("closed")) {
|
||||
|
||||
reOpenIssue.setVisibility(View.GONE);
|
||||
closeIssue.setVisibility(View.GONE);
|
||||
closeIssue.setVisibility(View.GONE);
|
||||
reOpenIssue.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
reOpenIssue.setOnClickListener(reOpenSingleIssue -> {
|
||||
|
||||
subscribeIssue.setOnClickListener(subscribeToIssue -> {
|
||||
IssueActions.closeReopenIssue(ctx, Integer.parseInt(tinyDB.getString("issueNumber")), "open");
|
||||
dismiss();
|
||||
|
||||
IssueActions.subscribe(ctx, subscribeIssue, unsubscribeIssue);
|
||||
//dismiss();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
unsubscribeIssue.setOnClickListener(unsubscribeToIssue -> {
|
||||
}
|
||||
else {
|
||||
|
||||
IssueActions.unsubscribe(ctx, subscribeIssue, unsubscribeIssue);
|
||||
//dismiss();
|
||||
reOpenIssue.setVisibility(View.GONE);
|
||||
closeIssue.setVisibility(View.GONE);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//if RepoWatch True Provide Unsubscribe first
|
||||
// ToDo: API to check if user is subscribed to an issue (do not exist can be guessed by many api endpoints :/)
|
||||
if (tinyDB.getBoolean("repoWatch")) {
|
||||
subscribeIssue.setVisibility(View.GONE);
|
||||
unsubscribeIssue.setVisibility(View.VISIBLE);
|
||||
}
|
||||
subscribeIssue.setOnClickListener(subscribeToIssue -> {
|
||||
|
||||
return v;
|
||||
}
|
||||
IssueActions.subscribe(ctx, subscribeIssue, unsubscribeIssue);
|
||||
//dismiss();
|
||||
|
||||
});
|
||||
|
||||
unsubscribeIssue.setOnClickListener(unsubscribeToIssue -> {
|
||||
|
||||
IssueActions.unsubscribe(ctx, subscribeIssue, unsubscribeIssue);
|
||||
//dismiss();
|
||||
|
||||
});
|
||||
|
||||
//if RepoWatch True Provide Unsubscribe first
|
||||
// ToDo: API to check if user is subscribed to an issue (do not exist can be guessed by many api endpoints :/)
|
||||
if(tinyDB.getBoolean("repoWatch")) {
|
||||
subscribeIssue.setVisibility(View.GONE);
|
||||
unsubscribeIssue.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,14 +4,6 @@ import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -22,12 +14,19 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.FileViewActivity;
|
||||
import org.mian.gitnex.adapters.FilesAdapter;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.models.Files;
|
||||
import org.mian.gitnex.util.AppUtil;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import org.mian.gitnex.viewmodels.FilesViewModel;
|
||||
import java.util.ArrayList;
|
||||
@@ -44,268 +43,275 @@ import moe.feng.common.view.breadcrumbs.model.BreadcrumbItem;
|
||||
|
||||
public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapterListener {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private FilesAdapter adapter;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TextView noDataFiles;
|
||||
private LinearLayout filesFrame;
|
||||
private TextView fileStructure;
|
||||
private static String repoNameF = "param2";
|
||||
private static String repoOwnerF = "param1";
|
||||
private BreadcrumbsView mBreadcrumbsView;
|
||||
private ProgressBar mProgressBar;
|
||||
private FilesAdapter adapter;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TextView noDataFiles;
|
||||
private LinearLayout filesFrame;
|
||||
private TextView fileStructure;
|
||||
private static String repoNameF = "param2";
|
||||
private static String repoOwnerF = "param1";
|
||||
private BreadcrumbsView mBreadcrumbsView;
|
||||
|
||||
private String repoName;
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
private String repoOwner;
|
||||
|
||||
private OnFragmentInteractionListener mListener;
|
||||
private OnFragmentInteractionListener mListener;
|
||||
|
||||
public FilesFragment() {
|
||||
}
|
||||
public FilesFragment() {
|
||||
|
||||
public static FilesFragment newInstance(String param1, String param2) {
|
||||
FilesFragment fragment = new FilesFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
args.putString(repoNameF, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
repoName = getArguments().getString(repoNameF);
|
||||
repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
}
|
||||
public static FilesFragment newInstance(String param1, String param2) {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
FilesFragment fragment = new FilesFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(repoOwnerF, param1);
|
||||
args.putString(repoNameF, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_files, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
super.onCreate(savedInstanceState);
|
||||
if(getArguments() != null) {
|
||||
repoName = getArguments().getString(repoNameF);
|
||||
repoOwner = getArguments().getString(repoOwnerF);
|
||||
}
|
||||
}
|
||||
|
||||
noDataFiles = v.findViewById(R.id.noDataFiles);
|
||||
filesFrame = v.findViewById(R.id.filesFrame);
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
fileStructure = v.findViewById(R.id.fileStructure);
|
||||
mRecyclerView = v.findViewById(R.id.recyclerView);
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
View v = inflater.inflate(R.layout.fragment_files, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
noDataFiles = v.findViewById(R.id.noDataFiles);
|
||||
filesFrame = v.findViewById(R.id.filesFrame);
|
||||
|
||||
mBreadcrumbsView = v.findViewById(R.id.breadcrumbs_view);
|
||||
mBreadcrumbsView.setItems(new ArrayList<>(Arrays.asList(
|
||||
BreadcrumbItem.createSimpleItem(getResources().getString(R.string.filesBreadcrumbRoot))
|
||||
)));
|
||||
fileStructure = v.findViewById(R.id.fileStructure);
|
||||
mRecyclerView = v.findViewById(R.id.recyclerView);
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
return v;
|
||||
}
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
mBreadcrumbsView = v.findViewById(R.id.breadcrumbs_view);
|
||||
mBreadcrumbsView.setItems(new ArrayList<>(Arrays.asList(BreadcrumbItem.createSimpleItem(getResources().getString(R.string.filesBreadcrumbRoot)))));
|
||||
|
||||
private static BreadcrumbItem createItem(String title) {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(title);
|
||||
return new BreadcrumbItem(list);
|
||||
}
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
|
||||
|
||||
@Override
|
||||
public void onClickDir(String dirName) {
|
||||
return v;
|
||||
}
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
StringBuilder breadcrumbBuilder = new StringBuilder();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
breadcrumbBuilder.append(fileStructure.getText().toString()).append("/").append(dirName);
|
||||
private static BreadcrumbItem createItem(String title) {
|
||||
|
||||
fileStructure.setText(breadcrumbBuilder);
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(title);
|
||||
return new BreadcrumbItem(list);
|
||||
}
|
||||
|
||||
String dirName_ = fileStructure.getText().toString();
|
||||
dirName_ = dirName_.startsWith("/") ? dirName_.substring(1) : dirName_;
|
||||
final String finalDirName_ = dirName_;
|
||||
@Override
|
||||
public void onClickDir(String dirName) {
|
||||
|
||||
mBreadcrumbsView.addItem(createItem(dirName));
|
||||
//noinspection unchecked
|
||||
mBreadcrumbsView.setCallback(new DefaultBreadcrumbsCallback<BreadcrumbItem>() {
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onNavigateBack(BreadcrumbItem item, int position) {
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
if(position == 0) {
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
|
||||
fileStructure.setText("");
|
||||
return;
|
||||
}
|
||||
StringBuilder breadcrumbBuilder = new StringBuilder();
|
||||
|
||||
String filterDir = fileStructure.getText().toString();
|
||||
String result = filterDir.substring(0, filterDir.indexOf(item.getSelectedItem()));
|
||||
fileStructure.setText(result + item.getSelectedItem());
|
||||
breadcrumbBuilder.append(fileStructure.getText().toString()).append("/").append(dirName);
|
||||
|
||||
String currentIndex = (result + item.getSelectedItem()).substring(1);
|
||||
fileStructure.setText(breadcrumbBuilder);
|
||||
|
||||
fetchDataAsyncSub(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, currentIndex);
|
||||
String dirName_ = fileStructure.getText().toString();
|
||||
dirName_ = dirName_.startsWith("/") ? dirName_.substring(1) : dirName_;
|
||||
final String finalDirName_ = dirName_;
|
||||
|
||||
}
|
||||
mBreadcrumbsView.addItem(createItem(dirName));
|
||||
//noinspection unchecked
|
||||
mBreadcrumbsView.setCallback(new DefaultBreadcrumbsCallback<BreadcrumbItem>() {
|
||||
|
||||
@Override
|
||||
public void onNavigateNewLocation(BreadcrumbItem newItem, int changedPosition) {
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onNavigateBack(BreadcrumbItem item, int position) {
|
||||
|
||||
}
|
||||
});
|
||||
if(position == 0) {
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
|
||||
fileStructure.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
fetchDataAsyncSub(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, finalDirName_);
|
||||
String filterDir = fileStructure.getText().toString();
|
||||
String result = filterDir.substring(0, filterDir.indexOf(item.getSelectedItem()));
|
||||
fileStructure.setText(result + item.getSelectedItem());
|
||||
|
||||
}
|
||||
String currentIndex = (result + item.getSelectedItem()).substring(1);
|
||||
|
||||
@Override
|
||||
public void onClickFile(String fileName) {
|
||||
fetchDataAsyncSub(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, currentIndex);
|
||||
|
||||
Intent intent = new Intent(getContext(), FileViewActivity.class);
|
||||
}
|
||||
|
||||
if(!fileStructure.getText().toString().equals("Root")) {
|
||||
@Override
|
||||
public void onNavigateNewLocation(BreadcrumbItem newItem, int changedPosition) {
|
||||
|
||||
intent.putExtra("singleFileName", fileStructure.getText().toString()+"/"+fileName);
|
||||
}
|
||||
else {
|
||||
}
|
||||
});
|
||||
|
||||
intent.putExtra("singleFileName", fileName);
|
||||
}
|
||||
fetchDataAsyncSub(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, finalDirName_);
|
||||
|
||||
Objects.requireNonNull(getContext()).startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo) {
|
||||
@Override
|
||||
public void onClickFile(String fileName) {
|
||||
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
Intent intent = new Intent(getContext(), FileViewActivity.class);
|
||||
|
||||
FilesViewModel filesModel = new ViewModelProvider(this).get(FilesViewModel.class);
|
||||
if(!fileStructure.getText().toString().equals("Root")) {
|
||||
|
||||
filesModel.getFilesList(instanceUrl, instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), new Observer<List<Files>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<Files> filesListMain) {
|
||||
adapter = new FilesAdapter(getContext(), filesListMain, FilesFragment.this);
|
||||
intent.putExtra("singleFileName", fileStructure.getText().toString() + "/" + fileName);
|
||||
}
|
||||
else {
|
||||
|
||||
mBreadcrumbsView.removeItemAfter(1);
|
||||
if(adapter.getItemCount() > 0) {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.VISIBLE);
|
||||
}
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
intent.putExtra("singleFileName", fileName);
|
||||
}
|
||||
|
||||
}
|
||||
Objects.requireNonNull(getContext()).startActivity(intent);
|
||||
}
|
||||
|
||||
private void fetchDataAsyncSub(String instanceUrl, String instanceToken, String owner, String repo, String filesDir) {
|
||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo) {
|
||||
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
FilesViewModel filesModel2 = new ViewModelProvider(this).get(FilesViewModel.class);
|
||||
FilesViewModel filesModel = new ViewModelProvider(this).get(FilesViewModel.class);
|
||||
|
||||
filesModel2.getFilesList2(instanceUrl, instanceToken, owner, repo, filesDir, getContext()).observe(this, new Observer<List<Files>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<Files> filesListMain2) {
|
||||
adapter = new FilesAdapter(getContext(), filesListMain2, FilesFragment.this);
|
||||
if(adapter.getItemCount() > 0) {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.VISIBLE);
|
||||
}
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
filesModel.getFilesList(instanceUrl, instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), new Observer<List<Files>>() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onChanged(@Nullable List<Files> filesListMain) {
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
adapter = new FilesAdapter(getContext(), filesListMain, FilesFragment.this);
|
||||
|
||||
boolean connToInternet = AppUtil.haveNetworkConnection(Objects.requireNonNull(getContext()));
|
||||
mBreadcrumbsView.removeItemAfter(1);
|
||||
if(adapter.getItemCount() > 0) {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.VISIBLE);
|
||||
}
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
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.setQueryHint(getContext().getString(R.string.search));
|
||||
private void fetchDataAsyncSub(String instanceUrl, String instanceToken, String owner, String repo, String filesDir) {
|
||||
|
||||
/*if(!connToInternet) {
|
||||
return;
|
||||
}*/
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
FilesViewModel filesModel2 = new ViewModelProvider(this).get(FilesViewModel.class);
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
if(mRecyclerView.getAdapter() != null) {
|
||||
adapter.getFilter().filter(newText);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
filesModel2.getFilesList2(instanceUrl, instanceToken, owner, repo, filesDir, getContext()).observe(this, new Observer<List<Files>>() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onChanged(@Nullable List<Files> filesListMain2) {
|
||||
|
||||
public void onButtonPressed(Uri uri) {
|
||||
if (mListener != null) {
|
||||
mListener.onFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
adapter = new FilesAdapter(getContext(), filesListMain2, FilesFragment.this);
|
||||
if(adapter.getItemCount() > 0) {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
noDataFiles.setVisibility(View.VISIBLE);
|
||||
}
|
||||
filesFrame.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@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(mRecyclerView.getAdapter() != null) {
|
||||
adapter.getFilter().filter(newText);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void onButtonPressed(Uri uri) {
|
||||
|
||||
if(mListener != null) {
|
||||
mListener.onFragmentInteraction(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
public interface OnFragmentInteractionListener {
|
||||
|
||||
void onFragmentInteraction(Uri uri);
|
||||
|
||||
}
|
||||
|
||||
public interface OnFragmentInteractionListener {
|
||||
void onFragmentInteraction(Uri uri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
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 android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||
import org.mian.gitnex.helpers.VersionCheck;
|
||||
import org.mian.gitnex.adapters.IssuesAdapter;
|
||||
import org.mian.gitnex.models.Issues;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import com.mikepenz.fastadapter.IItemAdapter;
|
||||
import com.mikepenz.fastadapter.adapters.ItemAdapter;
|
||||
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter;
|
||||
import com.mikepenz.fastadapter.listeners.ItemFilterListener;
|
||||
import com.mikepenz.fastadapter_extensions.items.ProgressItem;
|
||||
import com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import static com.mikepenz.fastadapter.adapters.ItemAdapter.items;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class IssuesClosedFragment extends Fragment implements ItemFilterListener<IssuesAdapter> {
|
||||
|
||||
private Context ctx;
|
||||
private ProgressBar mProgressBarClosed;
|
||||
private boolean loadNextFlag = false;
|
||||
private String TAG = StaticGlobalVariables.tagIssuesListClosed;
|
||||
private TextView noDataIssuesClosed;
|
||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
||||
private String requestType = StaticGlobalVariables.issuesRequestType;
|
||||
private String issueState = StaticGlobalVariables.issueStateClosed;
|
||||
|
||||
private List<IssuesAdapter> items = new ArrayList<>();
|
||||
private FastItemAdapter<IssuesAdapter> fastItemAdapter;
|
||||
private ItemAdapter footerAdapter;
|
||||
private EndlessRecyclerOnScrollListener endlessRecyclerOnScrollListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_issues_closed, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
if (VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) < 1) {
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
noDataIssuesClosed = v.findViewById(R.id.noDataIssuesClosed);
|
||||
mProgressBarClosed = v.findViewById(R.id.progress_barClosed);
|
||||
final SwipeRefreshLayout swipeRefreshLayout = v.findViewById(R.id.pullToRefreshClosed);
|
||||
|
||||
RecyclerView recyclerView = v.findViewById(R.id.recyclerViewClosed);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
fastItemAdapter = new FastItemAdapter<>();
|
||||
fastItemAdapter.withSelectable(true);
|
||||
|
||||
footerAdapter = items();
|
||||
//noinspection unchecked
|
||||
fastItemAdapter.addAdapter(StaticGlobalVariables.issuesPageInit, footerAdapter);
|
||||
|
||||
fastItemAdapter.getItemFilter().withFilterPredicate((IItemAdapter.Predicate<IssuesAdapter>) (item, constraint) -> item.getIssueTitle().toLowerCase().contains(constraint.toString().toLowerCase()));
|
||||
|
||||
fastItemAdapter.getItemFilter().withItemFilterListener(this);
|
||||
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.setAdapter(fastItemAdapter);
|
||||
|
||||
endlessRecyclerOnScrollListener = new EndlessRecyclerOnScrollListener(footerAdapter) {
|
||||
|
||||
@Override
|
||||
public void onLoadMore(final int currentPage) {
|
||||
|
||||
loadNext(instanceUrl, instanceToken, repoOwner, repoName, resultLimit, issueState, requestType, currentPage);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
|
||||
mProgressBarClosed.setVisibility(View.VISIBLE);
|
||||
fastItemAdapter.clear();
|
||||
endlessRecyclerOnScrollListener.resetPageCount();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
});
|
||||
|
||||
recyclerView.addOnScrollListener(endlessRecyclerOnScrollListener);
|
||||
|
||||
loadInitial(instanceUrl, instanceToken, repoOwner, repoName, issueState, resultLimit, requestType);
|
||||
|
||||
fastItemAdapter.withEventHook(new IssuesAdapter.IssueTitleClickEvent());
|
||||
|
||||
assert savedInstanceState != null;
|
||||
fastItemAdapter.withSavedInstanceState(savedInstanceState);
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
|
||||
if(tinyDb.getBoolean("resumeClosedIssues")) {
|
||||
|
||||
mProgressBarClosed.setVisibility(View.VISIBLE);
|
||||
fastItemAdapter.clear();
|
||||
endlessRecyclerOnScrollListener.resetPageCount();
|
||||
tinyDb.putBoolean("resumeClosedIssues", false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadInitial(String instanceUrl, String token, String repoOwner, String repoName, String issueState, int resultLimit, String requestType) {
|
||||
|
||||
Call<List<Issues>> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().getClosedIssues(token, repoOwner, repoName, 1, issueState, resultLimit, requestType);
|
||||
|
||||
call.enqueue(new Callback<List<Issues>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Issues>> call, @NonNull Response<List<Issues>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
assert response.body() != null;
|
||||
if(response.body().size() > 0) {
|
||||
|
||||
if(response.body().size() == resultLimit) {
|
||||
loadNextFlag = true;
|
||||
}
|
||||
|
||||
for(int i = 0; i < response.body().size(); i++) {
|
||||
items.add(new IssuesAdapter(getContext()).withNewItems(response.body().get(i).getTitle(), response.body().get(i).getNumber(), response.body().get(i).getUser().getAvatar_url(), response.body().get(i).getCreated_at(), response.body().get(i).getComments(), response.body().get(i).getUser().getFull_name(), response.body().get(i).getUser().getLogin()));
|
||||
}
|
||||
|
||||
fastItemAdapter.add(items);
|
||||
noDataIssuesClosed.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
noDataIssuesClosed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mProgressBarClosed.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loadNext(String instanceUrl, String token, String repoOwner, String repoName, int resultLimit, String issueState, String requestType, final int currentPage) {
|
||||
|
||||
footerAdapter.clear();
|
||||
//noinspection unchecked
|
||||
footerAdapter.add(new ProgressItem().withEnabled(false));
|
||||
Handler handler = new Handler();
|
||||
|
||||
handler.postDelayed(() -> {
|
||||
|
||||
Call<List<Issues>> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().getClosedIssues(token, repoOwner, repoName, currentPage + 1, issueState, resultLimit, requestType);
|
||||
|
||||
call.enqueue(new Callback<List<Issues>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Issues>> call, @NonNull Response<List<Issues>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
assert response.body() != null;
|
||||
|
||||
if(response.body().size() > 0) {
|
||||
|
||||
loadNextFlag = response.body().size() == resultLimit;
|
||||
|
||||
for(int i = 0; i < response.body().size(); i++) {
|
||||
|
||||
fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new IssuesAdapter(getContext()).withNewItems(response.body().get(i).getTitle(), response.body().get(i).getNumber(), response.body().get(i).getUser().getAvatar_url(), response.body().get(i).getCreated_at(), response.body().get(i).getComments(), response.body().get(i).getUser().getFull_name(), response.body().get(i).getUser().getLogin()));
|
||||
|
||||
}
|
||||
|
||||
footerAdapter.clear();
|
||||
mProgressBarClosed.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
footerAdapter.clear();
|
||||
}
|
||||
|
||||
mProgressBarClosed.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.i(TAG, t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}, 1000);
|
||||
|
||||
if(!loadNextFlag) {
|
||||
footerAdapter.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
fastItemAdapter.filter(newText);
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
endlessRecyclerOnScrollListener.enable();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemsFiltered(@Nullable CharSequence constraint, @Nullable List<IssuesAdapter> results) {
|
||||
|
||||
endlessRecyclerOnScrollListener.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReset() {
|
||||
|
||||
endlessRecyclerOnScrollListener.enable();
|
||||
}
|
||||
|
||||
}
|
||||
312
app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java
Normal file
312
app/src/main/java/org/mian/gitnex/fragments/IssuesFragment.java
Normal file
@@ -0,0 +1,312 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
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 android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.adapters.IssuesAdapter;
|
||||
import org.mian.gitnex.clients.IssuesService;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.VersionCheck;
|
||||
import org.mian.gitnex.interfaces.ApiInterface;
|
||||
import org.mian.gitnex.models.Issues;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class IssuesFragment extends Fragment {
|
||||
|
||||
private Menu menu;
|
||||
private RecyclerView recyclerView;
|
||||
private List<Issues> issuesList;
|
||||
private IssuesAdapter adapter;
|
||||
private ApiInterface api;
|
||||
private Context context;
|
||||
private int pageSize = StaticGlobalVariables.issuesPageInit;
|
||||
private ProgressBar mProgressBar;
|
||||
private String TAG = StaticGlobalVariables.tagIssuesList;
|
||||
private TextView noDataIssues;
|
||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
||||
private String requestType = StaticGlobalVariables.issuesRequestType;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_issues, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
context = getContext();
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||
|
||||
// if gitea is 1.12 or higher use the new limit
|
||||
if(VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) < 1) {
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
recyclerView = v.findViewById(R.id.recyclerView);
|
||||
issuesList = new ArrayList<>();
|
||||
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
noDataIssues = v.findViewById(R.id.noDataIssues);
|
||||
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
loadInitial(instanceToken, repoOwner, repoName, resultLimit, requestType, tinyDb.getString("repoIssuesState"));
|
||||
adapter.notifyDataChanged();
|
||||
|
||||
}, 200));
|
||||
|
||||
adapter = new IssuesAdapter(getContext(), issuesList);
|
||||
adapter.setLoadMoreListener(() -> recyclerView.post(() -> {
|
||||
|
||||
if(issuesList.size() == resultLimit || pageSize == resultLimit) {
|
||||
|
||||
int page = (issuesList.size() + resultLimit) / resultLimit;
|
||||
loadMore(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, page, resultLimit, requestType, tinyDb.getString("repoIssuesState"));
|
||||
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
((RepoDetailActivity) Objects.requireNonNull(getActivity())).setFragmentRefreshListener(issueState -> {
|
||||
|
||||
if(issueState.equals("closed")) {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter_closed);
|
||||
}
|
||||
else {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter);
|
||||
}
|
||||
|
||||
issuesList.clear();
|
||||
adapter = new IssuesAdapter(getContext(), issuesList);
|
||||
tinyDb.putString("repoIssuesState", issueState);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
noDataIssues.setVisibility(View.GONE);
|
||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, resultLimit, requestType, issueState);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
});
|
||||
|
||||
api = IssuesService.createService(ApiInterface.class, instanceUrl, getContext());
|
||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, resultLimit, requestType, tinyDb.getString("repoIssuesState"));
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
if(tinyDb.getBoolean("resumeIssues")) {
|
||||
|
||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, resultLimit, requestType, tinyDb.getString("repoIssuesState"));
|
||||
tinyDb.putBoolean("resumeIssues", false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadInitial(String token, String repoOwner, String repoName, int resultLimit, String requestType, String issueState) {
|
||||
|
||||
Call<List<Issues>> call = api.getIssues(token, repoOwner, repoName, 1, resultLimit, requestType, issueState);
|
||||
|
||||
call.enqueue(new Callback<List<Issues>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Issues>> call, @NonNull Response<List<Issues>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
assert response.body() != null;
|
||||
if(response.body().size() > 0) {
|
||||
|
||||
issuesList.clear();
|
||||
issuesList.addAll(response.body());
|
||||
adapter.notifyDataChanged();
|
||||
noDataIssues.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
issuesList.clear();
|
||||
adapter.notifyDataChanged();
|
||||
noDataIssues.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loadMore(String token, String repoOwner, String repoName, int page, int resultLimit, String requestType, String issueState) {
|
||||
|
||||
//add loading progress view
|
||||
issuesList.add(new Issues("load"));
|
||||
adapter.notifyItemInserted((issuesList.size() - 1));
|
||||
|
||||
Call<List<Issues>> call = api.getIssues(token, repoOwner, repoName, page, resultLimit, requestType, issueState);
|
||||
|
||||
call.enqueue(new Callback<List<Issues>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Issues>> call, @NonNull Response<List<Issues>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
//remove loading view
|
||||
issuesList.remove(issuesList.size() - 1);
|
||||
|
||||
List<Issues> result = response.body();
|
||||
|
||||
assert result != null;
|
||||
if(result.size() > 0) {
|
||||
|
||||
pageSize = result.size();
|
||||
issuesList.addAll(result);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.info(context, getString(R.string.noMoreData));
|
||||
adapter.setMoreDataAvailable(false);
|
||||
|
||||
}
|
||||
|
||||
adapter.notifyDataChanged();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
this.menu = menu;
|
||||
inflater.inflate(R.menu.search_menu, menu);
|
||||
inflater.inflate(R.menu.filter_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
|
||||
if(tinyDb.getString("repoIssuesState").equals("closed")) {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter_closed);
|
||||
}
|
||||
else {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
filter(newText);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void filter(String text) {
|
||||
|
||||
List<Issues> arr = new ArrayList<>();
|
||||
|
||||
for(Issues d : issuesList) {
|
||||
if(d.getTitle().toLowerCase().contains(text) || d.getBody().toLowerCase().contains(text)) {
|
||||
arr.add(d);
|
||||
}
|
||||
}
|
||||
|
||||
adapter.updateList(arr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
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;
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class IssuesMainFragment extends Fragment {
|
||||
|
||||
private Context ctx;
|
||||
|
||||
public IssuesMainFragment() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_issues_main, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
|
||||
SectionsPagerAdapter mSectionsPagerAdapter = new IssuesMainFragment.SectionsPagerAdapter(getChildFragmentManager());
|
||||
|
||||
ViewPager mViewPager = v.findViewById(R.id.issuesContainer);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
|
||||
Typeface myTypeface;
|
||||
if(tinyDb.getInt("customFontId") == 0) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 1) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/manroperegular.ttf");
|
||||
|
||||
}
|
||||
else if (tinyDb.getInt("customFontId") == 2) {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), "fonts/roboto.ttf");
|
||||
|
||||
}
|
||||
|
||||
TabLayout tabLayout = v.findViewById(R.id.tabs);
|
||||
|
||||
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
|
||||
int tabsCount = vg.getChildCount();
|
||||
|
||||
for (int j = 0; j < tabsCount; j++) {
|
||||
|
||||
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
|
||||
int tabChildCount = vgTab.getChildCount();
|
||||
|
||||
for (int i = 0; i < tabChildCount; i++) {
|
||||
|
||||
View tabViewChild = vgTab.getChildAt(i);
|
||||
if (tabViewChild instanceof TextView) {
|
||||
((TextView) tabViewChild).setTypeface(myTypeface);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
||||
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
public static class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
|
||||
Fragment fragment = null;
|
||||
switch (position) {
|
||||
case 0: // open issues
|
||||
fragment = new IssuesOpenFragment();
|
||||
break;
|
||||
case 1: // closed issues
|
||||
fragment = new IssuesClosedFragment();
|
||||
break;
|
||||
}
|
||||
assert fragment != null;
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
menu.clear();
|
||||
Objects.requireNonNull(getActivity()).getMenuInflater().inflate(R.menu.repo_dotted_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
int id = item.getItemId();
|
||||
|
||||
switch (id) {
|
||||
case android.R.id.home:
|
||||
return true;
|
||||
case R.id.repoMenu:
|
||||
BottomSheetRepoFragment bottomSheet = new BottomSheetRepoFragment();
|
||||
bottomSheet.show(getChildFragmentManager(), "repoBottomSheet");
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,308 +0,0 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
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 android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import com.mikepenz.fastadapter.IItemAdapter;
|
||||
import com.mikepenz.fastadapter.adapters.ItemAdapter;
|
||||
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter;
|
||||
import com.mikepenz.fastadapter.listeners.ItemFilterListener;
|
||||
import com.mikepenz.fastadapter_extensions.items.ProgressItem;
|
||||
import com.mikepenz.fastadapter_extensions.scroll.EndlessRecyclerOnScrollListener;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||
import org.mian.gitnex.helpers.VersionCheck;
|
||||
import org.mian.gitnex.adapters.IssuesAdapter;
|
||||
import org.mian.gitnex.models.Issues;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static com.mikepenz.fastadapter.adapters.ItemAdapter.items;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class IssuesOpenFragment extends Fragment implements ItemFilterListener<IssuesAdapter> {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private boolean loadNextFlag = false;
|
||||
private String TAG = StaticGlobalVariables.tagIssuesListOpen;
|
||||
private TextView noDataIssues;
|
||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
||||
private String requestType = StaticGlobalVariables.issuesRequestType;
|
||||
|
||||
private List<IssuesAdapter> items = new ArrayList<>();
|
||||
private FastItemAdapter<IssuesAdapter> fastItemAdapter;
|
||||
private ItemAdapter footerAdapter;
|
||||
private EndlessRecyclerOnScrollListener endlessRecyclerOnScrollListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_issues, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
if (VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) < 1) {
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
noDataIssues = v.findViewById(R.id.noDataIssues);
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
final SwipeRefreshLayout swipeRefreshLayout = v.findViewById(R.id.pullToRefresh);
|
||||
|
||||
RecyclerView recyclerView = v.findViewById(R.id.recyclerView);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
fastItemAdapter = new FastItemAdapter<>();
|
||||
fastItemAdapter.withSelectable(true);
|
||||
|
||||
footerAdapter = items();
|
||||
//noinspection unchecked
|
||||
fastItemAdapter.addAdapter(StaticGlobalVariables.issuesPageInit, footerAdapter);
|
||||
|
||||
fastItemAdapter.getItemFilter().withFilterPredicate((IItemAdapter.Predicate<IssuesAdapter>) (item, constraint) -> item.getIssueTitle().toLowerCase().contains(constraint.toString().toLowerCase()));
|
||||
|
||||
fastItemAdapter.getItemFilter().withItemFilterListener(this);
|
||||
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.setAdapter(fastItemAdapter);
|
||||
|
||||
endlessRecyclerOnScrollListener = new EndlessRecyclerOnScrollListener(footerAdapter) {
|
||||
|
||||
@Override
|
||||
public void onLoadMore(final int currentPage) {
|
||||
|
||||
loadNext(instanceUrl, instanceToken, repoOwner, repoName, resultLimit, requestType, currentPage);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
swipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
fastItemAdapter.clear();
|
||||
endlessRecyclerOnScrollListener.resetPageCount();
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
|
||||
});
|
||||
|
||||
recyclerView.addOnScrollListener(endlessRecyclerOnScrollListener);
|
||||
|
||||
loadInitial(instanceUrl, instanceToken, repoOwner, repoName, resultLimit, requestType);
|
||||
|
||||
fastItemAdapter.withEventHook(new IssuesAdapter.IssueTitleClickEvent());
|
||||
|
||||
assert savedInstanceState != null;
|
||||
fastItemAdapter.withSavedInstanceState(savedInstanceState);
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
|
||||
if(tinyDb.getBoolean("resumeIssues")) {
|
||||
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
fastItemAdapter.clear();
|
||||
endlessRecyclerOnScrollListener.resetPageCount();
|
||||
tinyDb.putBoolean("resumeIssues", false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void loadInitial(String instanceUrl, String token, String repoOwner, String repoName, int resultLimit, String requestType) {
|
||||
|
||||
Call<List<Issues>> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().getIssues(token, repoOwner, repoName, 1, resultLimit, requestType);
|
||||
|
||||
call.enqueue(new Callback<List<Issues>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Issues>> call, @NonNull Response<List<Issues>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
assert response.body() != null;
|
||||
if(response.body().size() > 0) {
|
||||
|
||||
if(response.body().size() == resultLimit) {
|
||||
loadNextFlag = true;
|
||||
}
|
||||
|
||||
for(int i = 0; i < response.body().size(); i++) {
|
||||
items.add(new IssuesAdapter(getContext()).withNewItems(response.body().get(i).getTitle(), response.body().get(i).getNumber(), response.body().get(i).getUser().getAvatar_url(), response.body().get(i).getCreated_at(), response.body().get(i).getComments(), response.body().get(i).getUser().getFull_name(), response.body().get(i).getUser().getLogin()));
|
||||
}
|
||||
|
||||
fastItemAdapter.add(items);
|
||||
noDataIssues.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
noDataIssues.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loadNext(String instanceUrl, String token, String repoOwner, String repoName, int resultLimit, String requestType, final int currentPage) {
|
||||
|
||||
footerAdapter.clear();
|
||||
//noinspection unchecked
|
||||
footerAdapter.add(new ProgressItem().withEnabled(false));
|
||||
Handler handler = new Handler();
|
||||
|
||||
handler.postDelayed(() -> {
|
||||
|
||||
Call<List<Issues>> call = RetrofitClient.getInstance(instanceUrl, getContext()).getApiInterface().getIssues(token, repoOwner, repoName, currentPage + 1, resultLimit, requestType);
|
||||
|
||||
call.enqueue(new Callback<List<Issues>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Issues>> call, @NonNull Response<List<Issues>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
assert response.body() != null;
|
||||
|
||||
if(response.body().size() > 0) {
|
||||
|
||||
loadNextFlag = response.body().size() == resultLimit;
|
||||
|
||||
for(int i = 0; i < response.body().size(); i++) {
|
||||
|
||||
fastItemAdapter.add(fastItemAdapter.getAdapterItemCount(), new IssuesAdapter(getContext()).withNewItems(response.body().get(i).getTitle(), response.body().get(i).getNumber(), response.body().get(i).getUser().getAvatar_url(), response.body().get(i).getCreated_at(), response.body().get(i).getComments(), response.body().get(i).getUser().getFull_name(), response.body().get(i).getUser().getLogin()));
|
||||
|
||||
}
|
||||
|
||||
footerAdapter.clear();
|
||||
noDataIssues.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
footerAdapter.clear();
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Issues>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.i(TAG, t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}, 1000);
|
||||
|
||||
if(!loadNextFlag) {
|
||||
footerAdapter.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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) {
|
||||
|
||||
fastItemAdapter.filter(newText);
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
endlessRecyclerOnScrollListener.enable();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemsFiltered(@Nullable CharSequence constraint, @Nullable List<IssuesAdapter> results) {
|
||||
|
||||
endlessRecyclerOnScrollListener.disable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReset() {
|
||||
|
||||
endlessRecyclerOnScrollListener.enable();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,13 +2,6 @@ package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -20,14 +13,23 @@ import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.adapters.PullRequestsAdapter;
|
||||
import org.mian.gitnex.clients.PullRequestsService;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.VersionCheck;
|
||||
import org.mian.gitnex.interfaces.ApiInterface;
|
||||
import org.mian.gitnex.models.PullRequests;
|
||||
import org.mian.gitnex.util.AppUtil;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -42,254 +44,274 @@ import retrofit2.Response;
|
||||
|
||||
public class PullRequestsFragment extends Fragment {
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView recyclerView;
|
||||
private List<PullRequests> prList;
|
||||
private PullRequestsAdapter adapter;
|
||||
private ApiInterface apiPR;
|
||||
private String TAG = "PullRequestsListFragment - ";
|
||||
private Context context;
|
||||
private int pageSize = 1;
|
||||
private TextView noData;
|
||||
private String prState = "open";
|
||||
private int resultLimit = 50;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
final View v = inflater.inflate(R.layout.fragment_pull_requests, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
private Menu menu;
|
||||
private ProgressBar mProgressBar;
|
||||
private RecyclerView recyclerView;
|
||||
private List<PullRequests> prList;
|
||||
private PullRequestsAdapter adapter;
|
||||
private ApiInterface apiPR;
|
||||
private String TAG = StaticGlobalVariables.tagPullRequestsList;
|
||||
private Context context;
|
||||
private int pageSize = StaticGlobalVariables.prPageInit;
|
||||
private TextView noData;
|
||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
//Log.i("repoFullName", tinyDb.getString("repoFullName"));
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||
final View v = inflater.inflate(R.layout.fragment_pull_requests, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
context = getContext();
|
||||
|
||||
context = getContext();
|
||||
recyclerView = v.findViewById(R.id.recyclerView);
|
||||
prList = new ArrayList<>();
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
noData = v.findViewById(R.id.noData);
|
||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||
|
||||
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
loadInitial(instanceToken, repoOwner, repoName, pageSize, prState, resultLimit);
|
||||
adapter.notifyDataChanged();
|
||||
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
|
||||
adapter = new PullRequestsAdapter(getContext(), prList);
|
||||
adapter.setLoadMoreListener(new PullRequestsAdapter.OnLoadMoreListener() {
|
||||
@Override
|
||||
public void onLoadMore() {
|
||||
// if gitea is 1.12 or higher use the new limit
|
||||
if(VersionCheck.compareVersion("1.12.0", tinyDb.getString("giteaVersion")) < 1) {
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
recyclerView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(prList.size() == 10 || pageSize == 10) {
|
||||
recyclerView = v.findViewById(R.id.recyclerView);
|
||||
prList = new ArrayList<>();
|
||||
|
||||
int page = (prList.size() + 10) / 10;
|
||||
loadMore(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, page, prState, resultLimit);
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
noData = v.findViewById(R.id.noData);
|
||||
|
||||
}
|
||||
/*else {
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
|
||||
|
||||
Toasty.info(context, getString(R.string.noMoreData));
|
||||
swipeRefresh.setRefreshing(false);
|
||||
loadInitial(instanceToken, repoOwner, repoName, pageSize, tinyDb.getString("repoPrState"), resultLimit);
|
||||
adapter.notifyDataChanged();
|
||||
|
||||
}*/
|
||||
}
|
||||
});
|
||||
}, 200));
|
||||
|
||||
}
|
||||
});
|
||||
adapter = new PullRequestsAdapter(getContext(), prList);
|
||||
adapter.setLoadMoreListener(() -> recyclerView.post(() -> {
|
||||
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
recyclerView.setAdapter(adapter);
|
||||
if(prList.size() == 10 || pageSize == resultLimit) {
|
||||
|
||||
apiPR = PullRequestsService.createService(ApiInterface.class, instanceUrl, getContext());
|
||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, pageSize, prState, resultLimit);
|
||||
int page = (prList.size() + resultLimit) / resultLimit;
|
||||
loadMore(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, page, tinyDb.getString("repoPrState"), resultLimit);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
}));
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
super.onResume();
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
((RepoDetailActivity) Objects.requireNonNull(getActivity())).setFragmentRefreshListenerPr(prState -> {
|
||||
|
||||
if(tinyDb.getBoolean("resumePullRequests")) {
|
||||
if(prState.equals("closed")) {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter_closed);
|
||||
}
|
||||
else {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter);
|
||||
}
|
||||
|
||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, pageSize, prState, resultLimit);
|
||||
tinyDb.putBoolean("resumePullRequests", false);
|
||||
tinyDb.putBoolean("prMerged", false);
|
||||
prList.clear();
|
||||
adapter = new PullRequestsAdapter(context, prList);
|
||||
tinyDb.putString("repoPrState", prState);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
noData.setVisibility(View.GONE);
|
||||
loadInitial(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName, pageSize, prState, resultLimit);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
apiPR = PullRequestsService.createService(ApiInterface.class, instanceUrl, context);
|
||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, pageSize, tinyDb.getString("repoPrState"), resultLimit);
|
||||
|
||||
private void loadInitial(String token, String repoOwner, String repoName, int page, String prState, int resultLimit) {
|
||||
return v;
|
||||
|
||||
Call<List<PullRequests>> call = apiPR.getPullRequests(token, repoOwner, repoName, page, prState, resultLimit);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<List<PullRequests>>() {
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<PullRequests>> call, @NonNull Response<List<PullRequests>> response) {
|
||||
super.onResume();
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
if(tinyDb.getBoolean("resumePullRequests")) {
|
||||
|
||||
assert response.body() != null;
|
||||
if(response.body().size() > 0) {
|
||||
loadInitial(Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, pageSize, tinyDb.getString("repoPrState"), resultLimit);
|
||||
tinyDb.putBoolean("resumePullRequests", false);
|
||||
tinyDb.putBoolean("prMerged", false);
|
||||
|
||||
prList.clear();
|
||||
prList.addAll(response.body());
|
||||
adapter.notifyDataChanged();
|
||||
noData.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
prList.clear();
|
||||
adapter.notifyDataChanged();
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("http", String.valueOf(response.code()));
|
||||
private void loadInitial(String token, String repoOwner, String repoName, int page, String prState, int resultLimit) {
|
||||
|
||||
}
|
||||
Call<List<PullRequests>> call = apiPR.getPullRequests(token, repoOwner, repoName, page, prState, resultLimit);
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<PullRequests>> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, t.toString());
|
||||
}
|
||||
call.enqueue(new Callback<List<PullRequests>>() {
|
||||
|
||||
});
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<PullRequests>> call, @NonNull Response<List<PullRequests>> response) {
|
||||
|
||||
}
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
private void loadMore(String token, String repoOwner, String repoName, int page, String prState, int resultLimit){
|
||||
assert response.body() != null;
|
||||
if(response.body().size() > 0) {
|
||||
|
||||
//add loading progress view
|
||||
prList.add(new PullRequests("load"));
|
||||
adapter.notifyItemInserted((prList.size() - 1));
|
||||
prList.clear();
|
||||
prList.addAll(response.body());
|
||||
adapter.notifyDataChanged();
|
||||
noData.setVisibility(View.GONE);
|
||||
|
||||
Call<List<PullRequests>> call = apiPR.getPullRequests(token, repoOwner, repoName, page, prState, resultLimit);
|
||||
}
|
||||
else {
|
||||
prList.clear();
|
||||
adapter.notifyDataChanged();
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
Log.i(TAG, String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<List<PullRequests>>() {
|
||||
Log.i(TAG, String.valueOf(response.code()));
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<PullRequests>> call, @NonNull Response<List<PullRequests>> response) {
|
||||
}
|
||||
|
||||
if(response.isSuccessful()){
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<PullRequests>> call, @NonNull Throwable t) {
|
||||
|
||||
//remove loading view
|
||||
prList.remove(prList.size()-1);
|
||||
Log.e(TAG, t.toString());
|
||||
}
|
||||
|
||||
List<PullRequests> result = response.body();
|
||||
});
|
||||
|
||||
assert result != null;
|
||||
if(result.size() > 0) {
|
||||
}
|
||||
|
||||
pageSize = result.size();
|
||||
prList.addAll(result);
|
||||
private void loadMore(String token, String repoOwner, String repoName, int page, String prState, int resultLimit) {
|
||||
|
||||
}
|
||||
else {
|
||||
//add loading progress view
|
||||
prList.add(new PullRequests("load"));
|
||||
adapter.notifyItemInserted((prList.size() - 1));
|
||||
|
||||
Toasty.info(context, getString(R.string.noMoreData));
|
||||
adapter.setMoreDataAvailable(false);
|
||||
Call<List<PullRequests>> call = apiPR.getPullRequests(token, repoOwner, repoName, page, prState, resultLimit);
|
||||
|
||||
}
|
||||
call.enqueue(new Callback<List<PullRequests>>() {
|
||||
|
||||
adapter.notifyDataChanged();
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<PullRequests>> call, @NonNull Response<List<PullRequests>> response) {
|
||||
|
||||
}
|
||||
else {
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
//remove loading view
|
||||
prList.remove(prList.size() - 1);
|
||||
|
||||
}
|
||||
List<PullRequests> result = response.body();
|
||||
|
||||
}
|
||||
assert result != null;
|
||||
if(result.size() > 0) {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<PullRequests>> call, @NonNull Throwable t) {
|
||||
pageSize = result.size();
|
||||
prList.addAll(result);
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
Toasty.info(context, getString(R.string.noMoreData));
|
||||
adapter.setMoreDataAvailable(false);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
adapter.notifyDataChanged();
|
||||
|
||||
boolean connToInternet = AppUtil.haveNetworkConnection(Objects.requireNonNull(getContext()));
|
||||
}
|
||||
else {
|
||||
|
||||
inflater.inflate(R.menu.search_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
|
||||
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.setQueryHint(getContext().getString(R.string.strFilter));
|
||||
}
|
||||
|
||||
/*if(!connToInternet) {
|
||||
return;
|
||||
}*/
|
||||
}
|
||||
|
||||
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<PullRequests>> call, @NonNull Throwable t) {
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
}
|
||||
|
||||
adapter.getFilter().filter(newText);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
});
|
||||
this.menu = menu;
|
||||
inflater.inflate(R.menu.search_menu, menu);
|
||||
inflater.inflate(R.menu.filter_menu_pr, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
}
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
|
||||
if(tinyDb.getString("repoPrState").equals("closed")) {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter_closed);
|
||||
}
|
||||
else {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
filter(newText);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void filter(String text) {
|
||||
|
||||
List<PullRequests> arr = new ArrayList<>();
|
||||
|
||||
for(PullRequests d : prList) {
|
||||
if(d.getTitle().toLowerCase().contains(text) || d.getBody().toLowerCase().contains(text)) {
|
||||
arr.add(d);
|
||||
}
|
||||
}
|
||||
|
||||
adapter.updateList(arr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user