mirror of
https://github.com/gitnex-org/gitnex.git
synced 2026-07-16 09:52:49 -05:00
Filter my issues and use remote search
This commit is contained in:
@@ -36,6 +36,7 @@ import org.mian.gitnex.database.models.UserAccount;
|
||||
import org.mian.gitnex.databinding.ActivityMainBinding;
|
||||
import org.mian.gitnex.fragments.AdministrationFragment;
|
||||
import org.mian.gitnex.fragments.BottomSheetDraftsFragment;
|
||||
import org.mian.gitnex.fragments.BottomSheetMyIssuesFilterFragment;
|
||||
import org.mian.gitnex.fragments.DraftsFragment;
|
||||
import org.mian.gitnex.fragments.ExploreFragment;
|
||||
import org.mian.gitnex.fragments.MyIssuesFragment;
|
||||
@@ -53,6 +54,7 @@ import org.mian.gitnex.helpers.ColorInverter;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.structs.BottomSheetListener;
|
||||
import org.mian.gitnex.structs.FragmentRefreshListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jp.wasabeef.picasso.transformations.BlurTransformation;
|
||||
@@ -81,6 +83,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
private TextView notificationCounter;
|
||||
|
||||
private BottomSheetListener profileInitListener;
|
||||
private FragmentRefreshListener fragmentRefreshListenerMyIssues;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -461,39 +464,51 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
public void onButtonClicked(String text) {
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
|
||||
if("deleteDrafts".equals(text)) {
|
||||
switch(text) {
|
||||
|
||||
if(currentActiveAccountId > 0) {
|
||||
case "deleteDrafts":
|
||||
if(currentActiveAccountId > 0) {
|
||||
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
DraftsFragment frag = (DraftsFragment) fm.findFragmentById(R.id.fragment_container);
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
DraftsFragment frag = (DraftsFragment) fm.findFragmentById(R.id.fragment_container);
|
||||
|
||||
if(frag != null) {
|
||||
if(frag != null) {
|
||||
|
||||
new AlertDialog.Builder(ctx)
|
||||
.setTitle(R.string.deleteAllDrafts)
|
||||
.setIcon(R.drawable.ic_delete)
|
||||
.setCancelable(false)
|
||||
.setMessage(R.string.deleteAllDraftsDialogMessage)
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> {
|
||||
new AlertDialog.Builder(ctx)
|
||||
.setTitle(R.string.deleteAllDrafts)
|
||||
.setIcon(R.drawable.ic_delete)
|
||||
.setCancelable(false)
|
||||
.setMessage(R.string.deleteAllDraftsDialogMessage)
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> {
|
||||
|
||||
frag.deleteAllDrafts(currentActiveAccountId);
|
||||
dialog.dismiss();
|
||||
frag.deleteAllDrafts(currentActiveAccountId);
|
||||
dialog.dismiss();
|
||||
|
||||
})
|
||||
.setNeutralButton(R.string.cancelButton, null).show();
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||
}
|
||||
|
||||
})
|
||||
.setNeutralButton(R.string.cancelButton, null).show();
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||
}
|
||||
|
||||
case "openMyIssues":
|
||||
if(getFragmentRefreshListener() != null) {
|
||||
getFragmentRefreshListener().onRefresh("open");
|
||||
}
|
||||
break;
|
||||
case "closedMyIssues":
|
||||
if(getFragmentRefreshListener() != null) {
|
||||
getFragmentRefreshListener().onRefresh("closed");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -591,6 +606,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
bottomSheet.show(getSupportFragmentManager(), "draftsBottomSheet");
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.filter) {
|
||||
|
||||
BottomSheetMyIssuesFilterFragment filterBottomSheet = new BottomSheetMyIssuesFilterFragment();
|
||||
filterBottomSheet.show(getSupportFragmentManager(), "myIssuesFilterMenuBottomSheet");
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -698,4 +719,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
this.profileInitListener = profileInitListener;
|
||||
}
|
||||
|
||||
// My issues-open-close interface
|
||||
public FragmentRefreshListener getFragmentRefreshListener() { return fragmentRefreshListenerMyIssues; }
|
||||
public void setFragmentRefreshListenerMyIssues(FragmentRefreshListener fragmentRefreshListener) { this.fragmentRefreshListenerMyIssues = fragmentRefreshListener; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
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 androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import org.mian.gitnex.databinding.BottomSheetMyIssuesFilterBinding;
|
||||
import org.mian.gitnex.structs.BottomSheetListener;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class BottomSheetMyIssuesFilterFragment extends BottomSheetDialogFragment {
|
||||
|
||||
private BottomSheetListener bmListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
BottomSheetMyIssuesFilterBinding bottomSheetIssuesFilterBinding = BottomSheetMyIssuesFilterBinding.inflate(inflater, container, false);
|
||||
|
||||
bottomSheetIssuesFilterBinding.openMyIssues.setOnClickListener(v1 -> {
|
||||
bmListener.onButtonClicked("openMyIssues");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
bottomSheetIssuesFilterBinding.closedMyIssues.setOnClickListener(v12 -> {
|
||||
bmListener.onButtonClicked("closedMyIssues");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
return bottomSheetIssuesFilterBinding.getRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
|
||||
super.onAttach(context);
|
||||
|
||||
try {
|
||||
bmListener = (BottomSheetListener) context;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
throw new ClassCastException(context + " must implement BottomSheetListener");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,20 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.BaseActivity;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.adapters.ExploreIssuesAdapter;
|
||||
import org.mian.gitnex.databinding.FragmentIssuesBinding;
|
||||
import org.mian.gitnex.viewmodels.IssuesViewModel;
|
||||
@@ -25,11 +31,14 @@ public class MyIssuesFragment extends Fragment {
|
||||
private FragmentIssuesBinding fragmentIssuesBinding;
|
||||
private ExploreIssuesAdapter adapter;
|
||||
private int page = 1;
|
||||
private Menu menu;
|
||||
public String state = "open";
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
fragmentIssuesBinding = FragmentIssuesBinding.inflate(inflater, container, false);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
fragmentIssuesBinding.recyclerView.setHasFixedSize(true);
|
||||
fragmentIssuesBinding.recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
@@ -37,23 +46,40 @@ public class MyIssuesFragment extends Fragment {
|
||||
DividerItemDecoration.VERTICAL);
|
||||
fragmentIssuesBinding.recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
((MainActivity) requireActivity()).setFragmentRefreshListenerMyIssues(myIssuesState -> {
|
||||
|
||||
state = myIssuesState;
|
||||
if(myIssuesState.equals("open")) {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter);
|
||||
}
|
||||
else {
|
||||
menu.getItem(1).setIcon(R.drawable.ic_filter_closed);
|
||||
}
|
||||
|
||||
fragmentIssuesBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
fragmentIssuesBinding.noDataIssues.setVisibility(View.GONE);
|
||||
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), null, myIssuesState);
|
||||
});
|
||||
|
||||
fragmentIssuesBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
page = 1;
|
||||
fragmentIssuesBinding.pullToRefresh.setRefreshing(false);
|
||||
IssuesViewModel.loadIssuesList(((BaseActivity) requireActivity()).getAccount().getAuthorization(), null, "issues", true, "open", getContext());
|
||||
IssuesViewModel.loadIssuesList(((BaseActivity) requireActivity()).getAccount().getAuthorization(), null, "issues", true, state, getContext());
|
||||
fragmentIssuesBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
}, 50));
|
||||
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization());
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), null, state);
|
||||
|
||||
return fragmentIssuesBinding.getRoot();
|
||||
};
|
||||
|
||||
private void fetchDataAsync(String instanceToken) {
|
||||
private void fetchDataAsync(String instanceToken, String query, String state) {
|
||||
|
||||
IssuesViewModel issuesModel = new ViewModelProvider(this).get(IssuesViewModel.class);
|
||||
|
||||
issuesModel.getIssuesList(instanceToken, "", "issues", true, "open", getContext()).observe(getViewLifecycleOwner(), issuesListMain -> {
|
||||
issuesModel.getIssuesList(instanceToken, query, "issues", true, state, getContext()).observe(getViewLifecycleOwner(), issuesListMain -> {
|
||||
|
||||
adapter = new ExploreIssuesAdapter(issuesListMain, getContext());
|
||||
adapter.setLoadMoreListener(new ExploreIssuesAdapter.OnLoadMoreListener() {
|
||||
@@ -62,7 +88,7 @@ public class MyIssuesFragment extends Fragment {
|
||||
public void onLoadMore() {
|
||||
|
||||
page += 1;
|
||||
IssuesViewModel.loadMoreIssues(instanceToken, "", "issues", true, "open", page, getContext(), adapter);
|
||||
IssuesViewModel.loadMoreIssues(instanceToken, query, "issues", true, state, page, getContext(), adapter);
|
||||
fragmentIssuesBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -86,4 +112,33 @@ public class MyIssuesFragment extends Fragment {
|
||||
fragmentIssuesBinding.progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
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) {
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), query, state);
|
||||
searchView.setQuery(null, false);
|
||||
searchItem.collapseActionView();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
80
app/src/main/res/layout/bottom_sheet_my_issues_filter.xml
Normal file
80
app/src/main/res/layout/bottom_sheet_my_issues_filter.xml
Normal file
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="12dp"
|
||||
android:background="?attr/primaryBackgroundColor">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/repoCreate"
|
||||
android:padding="8dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bottomSheetHeader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="@string/strFilter"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/repoCreateSection"
|
||||
app:flexWrap="wrap"
|
||||
app:alignItems="stretch"
|
||||
android:padding="8dp"
|
||||
app:alignContent="stretch" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openMyIssues"
|
||||
android:layout_width="98dp"
|
||||
android:layout_height="100dp"
|
||||
android:padding="8dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:gravity="center"
|
||||
app:layout_alignSelf="flex_start"
|
||||
app:drawableTopCompat="@drawable/ic_issue"
|
||||
android:text="@string/isOpen"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/closedMyIssues"
|
||||
android:layout_width="98dp"
|
||||
android:layout_height="100dp"
|
||||
android:padding="8dp"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
app:layout_alignSelf="flex_start"
|
||||
android:gravity="center"
|
||||
app:drawableTopCompat="@drawable/ic_issue_closed"
|
||||
android:text="@string/isClosed"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.flexbox.FlexboxLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user