mirror of
https://github.com/gitnex-org/gitnex.git
synced 2026-07-17 02:13:37 -05:00
Move input to titlebar
This commit is contained in:
@@ -7,7 +7,6 @@ import android.graphics.drawable.ColorDrawable;
|
||||
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;
|
||||
@@ -15,7 +14,6 @@ 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;
|
||||
@@ -30,17 +28,15 @@ import org.mian.gitnex.databinding.CustomExploreRepositoriesDialogBinding;
|
||||
import org.mian.gitnex.databinding.FragmentExploreRepoBinding;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Template Author M M Arif
|
||||
* Author 6543
|
||||
* Modified M M Arif
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class ExploreRepositoriesFragment extends Fragment {
|
||||
@@ -77,26 +73,6 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
|
||||
resultLimit = Constants.getCurrentResultLimit(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(String.valueOf(viewBinding.searchKeyword.getText()), resultLimit);
|
||||
|
||||
adapter.setLoadMoreListener(() -> viewBinding.recyclerViewReposSearch.post(() -> {
|
||||
if(dataList.size() == resultLimit || pageSize == resultLimit) {
|
||||
int page = (dataList.size() + resultLimit) / resultLimit;
|
||||
loadMore(String.valueOf(viewBinding.searchKeyword.getText()), resultLimit, page);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
viewBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
viewBinding.pullToRefresh.setRefreshing(false);
|
||||
loadInitial("", resultLimit);
|
||||
@@ -106,7 +82,7 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
adapter.setLoadMoreListener(() -> viewBinding.recyclerViewReposSearch.post(() -> {
|
||||
if(dataList.size() == resultLimit || pageSize == resultLimit) {
|
||||
int page = (dataList.size() + resultLimit) / resultLimit;
|
||||
loadMore(String.valueOf(viewBinding.searchKeyword.getText()), resultLimit, page);
|
||||
loadMore("", resultLimit, page);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -125,9 +101,12 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
|
||||
Call<ExploreRepositories> call = RetrofitClient
|
||||
.getApiInterface(context).queryRepos(((BaseActivity) requireActivity()).getAccount().getAuthorization(), searchKeyword, repoTypeInclude, sort, order, includeTopic, includeDescription, includeTemplate, onlyArchived, resultLimit, 1);
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
if(response.body() != null && response.body().getSearchedData().size() > 0) {
|
||||
dataList.clear();
|
||||
@@ -147,13 +126,14 @@ public class ExploreRepositoriesFragment 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<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
Toasty.error(requireActivity(), requireActivity().getResources().getString(R.string.genericServerResponseError));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -163,9 +143,12 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
viewBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
Call<ExploreRepositories> call = RetrofitClient.getApiInterface(context)
|
||||
.queryRepos(((BaseActivity) requireActivity()).getAccount().getAuthorization(), searchKeyword, repoTypeInclude, sort, order, includeTopic, includeDescription, includeTemplate, onlyArchived, resultLimit, page);
|
||||
call.enqueue(new Callback<ExploreRepositories>() {
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ExploreRepositories> call, @NonNull Response<ExploreRepositories> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
assert response.body() != null;
|
||||
List<UserRepositories> result = response.body().getSearchedData();
|
||||
@@ -181,13 +164,14 @@ public class ExploreRepositoriesFragment 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<ExploreRepositories> call, @NonNull Throwable t) {
|
||||
Log.e(TAG, t.toString());
|
||||
|
||||
Toasty.error(requireActivity(), requireActivity().getResources().getString(R.string.genericServerResponseError));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -196,6 +180,7 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
menu.clear();
|
||||
inflater.inflate(R.menu.search_menu, menu);
|
||||
inflater.inflate(R.menu.filter_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
MenuItem filter = menu.findItem(R.id.filter);
|
||||
@@ -205,6 +190,33 @@ public class ExploreRepositoriesFragment extends Fragment {
|
||||
showFilterOptions();
|
||||
return false;
|
||||
});
|
||||
|
||||
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(query, resultLimit);
|
||||
adapter.setLoadMoreListener(() -> viewBinding.recyclerViewReposSearch.post(() -> {
|
||||
if(dataList.size() == resultLimit || pageSize == resultLimit) {
|
||||
int page = (dataList.size() + resultLimit) / resultLimit;
|
||||
loadMore(query, resultLimit, page);
|
||||
}
|
||||
}));
|
||||
searchView.setQuery(null, false);
|
||||
searchItem.collapseActionView();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showFilterOptions() {
|
||||
|
||||
@@ -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/exploreTextBoxHint">
|
||||
|
||||
<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"
|
||||
|
||||
Reference in New Issue
Block a user