mirror of
https://github.com/gitnex-org/gitnex.git
synced 2026-07-16 01:50:11 -05:00
Move inputs to title bar for explore fragments
This commit is contained in:
@@ -1,28 +1,28 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
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 android.view.inputmethod.InputMethodManager;
|
||||
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.adapters.ExploreIssuesAdapter;
|
||||
import org.mian.gitnex.databinding.FragmentSearchIssuesBinding;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.viewmodels.IssuesViewModel;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class ExploreIssuesFragment extends Fragment {
|
||||
@@ -30,37 +30,18 @@ public class ExploreIssuesFragment extends Fragment {
|
||||
private FragmentSearchIssuesBinding viewBinding;
|
||||
private ExploreIssuesAdapter adapter;
|
||||
private int page = 1;
|
||||
private final String TAG = Constants.exploreIssues;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
viewBinding = FragmentSearchIssuesBinding.inflate(inflater, container, false);
|
||||
|
||||
viewBinding.searchKeyword.setOnEditorActionListener((v1, actionId, event) -> {
|
||||
if(actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
if(!Objects.requireNonNull(viewBinding.searchKeyword.getText()).toString().equals("")) {
|
||||
InputMethodManager imm = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(viewBinding.searchKeyword.getWindowToken(), 0);
|
||||
|
||||
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), String.valueOf(viewBinding.searchKeyword.getText()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
viewBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
viewBinding.pullToRefresh.setRefreshing(false);
|
||||
if(!Objects.requireNonNull(viewBinding.searchKeyword.getText()).toString().equals("")) {
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), String.valueOf(viewBinding.searchKeyword.getText()));
|
||||
}
|
||||
else {
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), "");
|
||||
}
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), "");
|
||||
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
}, 50));
|
||||
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(requireActivity(), DividerItemDecoration.VERTICAL);
|
||||
@@ -110,4 +91,33 @@ public class ExploreIssuesFragment extends Fragment {
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
menu.clear();
|
||||
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) {
|
||||
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
fetchDataAsync(((BaseActivity) requireActivity()).getAccount().getAuthorization(), query);
|
||||
searchView.setQuery(null, false);
|
||||
searchItem.collapseActionView();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
private final boolean repoTypeInclude = true;
|
||||
private final String sort = "updated";
|
||||
private final String order = "desc";
|
||||
private final String TAG = Constants.exploreRepositories;
|
||||
private int resultLimit;
|
||||
private List<UserRepositories> dataList;
|
||||
private ExploreRepositoriesAdapter adapter;
|
||||
@@ -181,9 +180,9 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
|
||||
menu.clear();
|
||||
inflater.inflate(R.menu.search_menu, menu);
|
||||
inflater.inflate(R.menu.filter_menu, menu);
|
||||
inflater.inflate(R.menu.filter_menu_explore, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
MenuItem filter = menu.findItem(R.id.filter);
|
||||
MenuItem filter = menu.findItem(R.id.filter_explore);
|
||||
|
||||
filter.setOnMenuItemClickListener(filter_ -> {
|
||||
|
||||
|
||||
@@ -4,12 +4,13 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
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.view.inputmethod.InputMethodManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
@@ -23,15 +24,15 @@ import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.databinding.FragmentExploreUsersBinding;
|
||||
import org.mian.gitnex.helpers.Constants;
|
||||
import org.mian.gitnex.helpers.SnackBar;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
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
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class ExploreUsersFragment extends Fragment {
|
||||
@@ -42,7 +43,6 @@ public class ExploreUsersFragment extends Fragment {
|
||||
private List<UserInfo> usersList;
|
||||
private UsersAdapter adapter;
|
||||
private int pageSize;
|
||||
private final String TAG = Constants.exploreUsers;
|
||||
private int resultLimit;
|
||||
|
||||
@Override
|
||||
@@ -50,32 +50,13 @@ public class ExploreUsersFragment extends Fragment {
|
||||
|
||||
viewBinding = FragmentExploreUsersBinding.inflate(inflater, container, false);
|
||||
context = getContext();
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
resultLimit = Constants.getCurrentResultLimit(context);
|
||||
|
||||
usersList = new ArrayList<>();
|
||||
adapter = new UsersAdapter(usersList, context);
|
||||
|
||||
viewBinding.searchKeyword.setOnEditorActionListener((v1, actionId, event) -> {
|
||||
if(actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
if(!Objects.requireNonNull(viewBinding.searchKeyword.getText()).toString().equals("")) {
|
||||
InputMethodManager imm = (InputMethodManager) requireActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(viewBinding.searchKeyword.getWindowToken(), 0);
|
||||
|
||||
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
loadInitial(((BaseActivity) requireActivity()).getAccount().getAuthorization(), String.valueOf(viewBinding.searchKeyword.getText()), resultLimit);
|
||||
|
||||
adapter.setLoadMoreListener(() -> viewBinding.recyclerViewExploreUsers.post(() -> {
|
||||
if(usersList.size() == resultLimit || pageSize == resultLimit) {
|
||||
int page = (usersList.size() + resultLimit) / resultLimit;
|
||||
loadMore(((BaseActivity) requireActivity()).getAccount().getAuthorization(), String.valueOf(viewBinding.searchKeyword.getText()), resultLimit, page);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
viewBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
viewBinding.pullToRefresh.setRefreshing(false);
|
||||
loadInitial(((BaseActivity) requireActivity()).getAccount().getAuthorization(), "", resultLimit);
|
||||
@@ -104,9 +85,12 @@ public class ExploreUsersFragment extends Fragment {
|
||||
|
||||
Call<UserSearch> call = RetrofitClient
|
||||
.getApiInterface(context).getUserBySearch(token, searchKeyword, resultLimit, 1);
|
||||
call.enqueue(new Callback<UserSearch>() {
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
if(response.body() != null && response.body().getData().size() > 0) {
|
||||
usersList.clear();
|
||||
@@ -126,13 +110,14 @@ public class ExploreUsersFragment extends Fragment {
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
Toasty.error(requireActivity(), requireActivity().getResources().getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<UserSearch> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
Toasty.error(requireActivity(), requireActivity().getResources().getString(R.string.genericServerResponseError));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -141,9 +126,12 @@ public class ExploreUsersFragment extends Fragment {
|
||||
|
||||
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
Call<UserSearch> call = RetrofitClient.getApiInterface(context).getUserBySearch(token, searchKeyword, resultLimit, page);
|
||||
call.enqueue(new Callback<UserSearch>() {
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
List<UserInfo> result = response.body().getData();
|
||||
@@ -161,13 +149,49 @@ public class ExploreUsersFragment extends Fragment {
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
Toasty.error(requireActivity(), requireActivity().getResources().getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<UserSearch> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
Toasty.error(requireActivity(), requireActivity().getResources().getString(R.string.genericServerResponseError));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
menu.clear();
|
||||
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) {
|
||||
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
loadInitial(((BaseActivity) requireActivity()).getAccount().getAuthorization(), query, resultLimit);
|
||||
adapter.setLoadMoreListener(() -> viewBinding.recyclerViewExploreUsers.post(() -> {
|
||||
if(usersList.size() == resultLimit || pageSize == resultLimit) {
|
||||
int page = (usersList.size() + resultLimit) / resultLimit;
|
||||
loadMore(((BaseActivity) requireActivity()).getAccount().getAuthorization(), query, resultLimit, page);
|
||||
}
|
||||
}));
|
||||
searchView.setQuery(null, false);
|
||||
searchItem.collapseActionView();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,45 +14,6 @@
|
||||
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
|
||||
app:indicatorColor="?attr/progressIndicatorColor" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/searchKeywordLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:boxBackgroundColor="?attr/inputBackgroundColor"
|
||||
android:textColorHint="?attr/hintColor"
|
||||
app:hintTextColor="?attr/hintColor"
|
||||
app:boxStrokeErrorColor="@color/darkRed"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:startIconDrawable="@drawable/ic_search"
|
||||
app:startIconTint="?attr/iconsColor"
|
||||
app:endIconMode="clear_text"
|
||||
app:endIconTint="?attr/iconsColor"
|
||||
android:hint="@string/exploreUsers">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/searchKeyword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/inputTextColor"
|
||||
android:textColorHighlight="?attr/hintColor"
|
||||
android:textColorHint="?attr/hintColor"
|
||||
android:imeOptions="actionSend"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/noData"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -14,45 +14,6 @@
|
||||
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
|
||||
app:indicatorColor="?attr/progressIndicatorColor" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/searchKeywordLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:boxBackgroundColor="?attr/inputBackgroundColor"
|
||||
android:textColorHint="?attr/hintColor"
|
||||
app:hintTextColor="?attr/hintColor"
|
||||
app:boxStrokeErrorColor="@color/darkRed"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:startIconDrawable="@drawable/ic_search"
|
||||
app:startIconTint="?attr/iconsColor"
|
||||
app:endIconMode="clear_text"
|
||||
app:endIconTint="?attr/iconsColor"
|
||||
android:hint="@string/exploreIssues">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/searchKeyword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?attr/inputTextColor"
|
||||
android:textColorHighlight="?attr/hintColor"
|
||||
android:textColorHint="?attr/hintColor"
|
||||
android:imeOptions="actionSend"
|
||||
android:inputType="text"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/noData"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
12
app/src/main/res/menu/filter_menu_explore.xml
Normal file
12
app/src/main/res/menu/filter_menu_explore.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/filter_explore"
|
||||
android:icon="@drawable/ic_filter"
|
||||
android:title="@string/strFilter"
|
||||
android:orderInCategory="0"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
</menu>
|
||||
Reference in New Issue
Block a user