Prepares the new search feature
This commit is contained in:
parent
1cfa584f38
commit
805aa74229
|
@ -172,6 +172,11 @@
|
|||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
/>
|
||||
<activity android:name=".activities.SearchResultTabActivity"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"
|
||||
android:configChanges="orientation|screenSize"
|
||||
android:label="@string/app_name"
|
||||
/>
|
||||
<activity android:name=".activities.ListActivity"
|
||||
android:windowSoftInputMode="stateAlwaysHidden"
|
||||
android:configChanges="orientation|screenSize"
|
||||
|
|
|
@ -1128,9 +1128,16 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
//It's not a peertube search
|
||||
if(displayPeertube == null){
|
||||
if( social != UpdateAccountInfoAsyncTask.SOCIAL.GNU) {
|
||||
Intent intent = new Intent(BaseMainActivity.this, SearchResultActivity.class);
|
||||
intent.putExtra("search", query);
|
||||
startActivity(intent);
|
||||
if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
|
||||
Intent intent = new Intent(BaseMainActivity.this, SearchResultTabActivity.class);
|
||||
intent.putExtra("search", query);
|
||||
startActivity(intent);
|
||||
}else{
|
||||
Intent intent = new Intent(BaseMainActivity.this, SearchResultActivity.class);
|
||||
intent.putExtra("search", query);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}else{
|
||||
Intent intent = new Intent(BaseMainActivity.this, HashTagActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
|
|
|
@ -0,0 +1,292 @@
|
|||
/* Copyright 2019 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.SearchListAdapter;
|
||||
import fr.gouv.etalab.mastodon.drawers.SearchTagsAdapter;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplaySearchTagsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.TabLayoutTootsFragment;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchStatusInterface;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.THEME_LIGHT;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 31/03/2019.
|
||||
* Show search results within tabs
|
||||
*/
|
||||
|
||||
public class SearchResultTabActivity extends BaseActivity implements OnRetrieveSearchInterface, OnRetrieveSearchStatusInterface {
|
||||
|
||||
|
||||
private String search;
|
||||
private ListView lv_search;
|
||||
private RelativeLayout loader;
|
||||
private TabLayout tabLayout;
|
||||
private ViewPager search_viewpager;
|
||||
private DisplayStatusFragment displayStatusFragment;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
switch (theme){
|
||||
case Helper.THEME_LIGHT:
|
||||
setTheme(R.style.AppTheme);
|
||||
break;
|
||||
case Helper.THEME_DARK:
|
||||
setTheme(R.style.AppThemeDark);
|
||||
break;
|
||||
case Helper.THEME_BLACK:
|
||||
setTheme(R.style.AppThemeBlack);
|
||||
break;
|
||||
default:
|
||||
setTheme(R.style.AppThemeDark);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_search_result_tabs);
|
||||
|
||||
loader = findViewById(R.id.loader);
|
||||
lv_search = findViewById(R.id.lv_search);
|
||||
tabLayout = findViewById(R.id.search_tabLayout);
|
||||
search_viewpager = findViewById(R.id.search_viewpager);
|
||||
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null){
|
||||
search = b.getString("search");
|
||||
if( search != null)
|
||||
new RetrieveSearchAsyncTask(getApplicationContext(), search.trim(), SearchResultTabActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
Toasty.error(this,getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
|
||||
}else{
|
||||
Toasty.error(this,getString(R.string.toast_error_search),Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if( getSupportActionBar() != null)
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if( actionBar != null ) {
|
||||
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
assert inflater != null;
|
||||
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.simple_bar, null);
|
||||
actionBar.setCustomView(view, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||
ImageView toolbar_close = actionBar.getCustomView().findViewById(R.id.toolbar_close);
|
||||
TextView toolbar_title = actionBar.getCustomView().findViewById(R.id.toolbar_title);
|
||||
toolbar_close.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
toolbar_title.setText(search);
|
||||
if (theme == THEME_LIGHT){
|
||||
Toolbar toolbar = actionBar.getCustomView().findViewById(R.id.toolbar);
|
||||
Helper.colorizeToolbar(toolbar, R.color.black, SearchResultTabActivity.this);
|
||||
}
|
||||
}
|
||||
setTitle(search);
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
lv_search.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveSearch(Results results, Error error) {
|
||||
loader.setVisibility(View.GONE);
|
||||
|
||||
if( error != null){
|
||||
Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if( results == null || (results.getAccounts().size() == 0 && results.getStatuses().size() == 0 && results.getHashtags().size() == 0)){
|
||||
RelativeLayout no_result = findViewById(R.id.no_result);
|
||||
no_result.setVisibility(View.VISIBLE);
|
||||
return;
|
||||
}
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.tags)));
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.accounts)));
|
||||
tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots)));
|
||||
|
||||
PagerAdapter mPagerAdapter = new SearchResultTabActivity.ScreenSlidePagerAdapter(getSupportFragmentManager());
|
||||
|
||||
search_viewpager.setAdapter(mPagerAdapter);
|
||||
|
||||
search_viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
TabLayout.Tab tab = tabLayout.getTabAt(position);
|
||||
if( tab != null)
|
||||
tab.select();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||
@Override
|
||||
public void onTabSelected(TabLayout.Tab tab) {
|
||||
search_viewpager.setCurrentItem(tab.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(TabLayout.Tab tab) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(TabLayout.Tab tab) {
|
||||
Fragment fragment = null;
|
||||
if( search_viewpager.getAdapter() != null)
|
||||
fragment = (Fragment) search_viewpager.getAdapter().instantiateItem(search_viewpager, tab.getPosition());
|
||||
if( fragment != null) {
|
||||
if( fragment instanceof DisplayAccountsFragment) {
|
||||
DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment);
|
||||
displayAccountsFragment.scrollToTop();
|
||||
}else if (fragment instanceof DisplayStatusFragment){
|
||||
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||
displayStatusFragment.scrollToTop();
|
||||
}else if (fragment instanceof DisplaySearchTagsFragment){
|
||||
DisplaySearchTagsFragment displaySearchTagsFragment = ((DisplaySearchTagsFragment) fragment);
|
||||
displaySearchTagsFragment.scrollToTop();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pager adapter for the 4 fragments
|
||||
*/
|
||||
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
ScreenSlidePagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
Bundle bundle = new Bundle();
|
||||
switch (position){
|
||||
case 0:
|
||||
DisplaySearchTagsFragment displaySearchTagsFragment = new DisplaySearchTagsFragment();
|
||||
bundle.putSerializable("tagsOnly", true);
|
||||
displaySearchTagsFragment.setArguments(bundle);
|
||||
return displaySearchTagsFragment;
|
||||
case 1:
|
||||
DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment();
|
||||
bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.SEARCH);
|
||||
displayAccountsFragment.setArguments(bundle);
|
||||
return displayAccountsFragment;
|
||||
case 2:
|
||||
DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment();
|
||||
bundle = new Bundle();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.SEARCH);
|
||||
displayStatusFragment.setArguments(bundle);
|
||||
return displayStatusFragment;
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveSearchStatus(APIResponse apiResponse, Error error) {
|
||||
loader.setVisibility(View.GONE);
|
||||
if( apiResponse.getError() != null){
|
||||
Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
lv_search.setVisibility(View.VISIBLE);
|
||||
List<String> tags = new ArrayList<>();
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
|
||||
SearchListAdapter searchListAdapter = new SearchListAdapter(SearchResultTabActivity.this, statuses, accounts, tags);
|
||||
lv_search.setAdapter(searchListAdapter);
|
||||
searchListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
|
@ -48,7 +48,8 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
FOLLOWERS,
|
||||
CHANNELS,
|
||||
REBLOGGED,
|
||||
FAVOURITED
|
||||
FAVOURITED,
|
||||
SEARCH
|
||||
}
|
||||
|
||||
public RetrieveAccountsAsyncTask(Context context, String instance, String name, OnRetrieveAccountsInterface onRetrieveAccountsInterface){
|
||||
|
|
|
@ -76,6 +76,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
REMOTE_INSTANCE,
|
||||
ART,
|
||||
NOTIFICATION,
|
||||
SEARCH,
|
||||
|
||||
PSUBSCRIPTIONS,
|
||||
POVERVIEW,
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
package fr.gouv.etalab.mastodon.drawers;
|
||||
/* Copyright 2019 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.HashTagActivity;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 31/03/2019.
|
||||
* Adapter for tags results
|
||||
*/
|
||||
public class SearchTagsAdapter extends RecyclerView.Adapter {
|
||||
|
||||
private Context context;
|
||||
private List<String> tags;
|
||||
|
||||
private LayoutInflater layoutInflater;
|
||||
|
||||
public SearchTagsAdapter(Context context, List<String> tags){
|
||||
this.context = context;
|
||||
this.tags = ( tags != null)?tags:new ArrayList<String>();
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
}
|
||||
|
||||
|
||||
public String getItem(int position) {
|
||||
return tags.get(position);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
|
||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_tag_search, parent, false));
|
||||
}
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder{
|
||||
private TextView tag_name;
|
||||
public ViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
tag_name = itemView.findViewById(R.id.tag_name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
|
||||
final ViewHolder holder = (ViewHolder) viewHolder;
|
||||
final String tag = (String) getItem(i);
|
||||
|
||||
holder.tag_name.setText(String.format("#%s",tag));
|
||||
holder.tag_name.setPaintFlags(holder.tag_name.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
holder.tag_name.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, HashTagActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("tag", tag.trim());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return tags.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
package fr.gouv.etalab.mastodon.fragments;
|
||||
/* Copyright 2019 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import es.dmoral.toasty.Toasty;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.SearchResultActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Results;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.SearchListAdapter;
|
||||
import fr.gouv.etalab.mastodon.drawers.SearchTagsAdapter;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 31/03/2019.
|
||||
* Fragment to display tags
|
||||
*/
|
||||
public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSearchInterface {
|
||||
|
||||
|
||||
private Context context;
|
||||
private SearchTagsAdapter searchTagsAdapter;
|
||||
private List<String> tags;
|
||||
private String search;
|
||||
private RecyclerView lv_search_tags;
|
||||
private RelativeLayout loader;
|
||||
private RelativeLayout textviewNoAction;
|
||||
private RelativeLayout loading_next_tags;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private boolean flag_loading;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_search, container, false);
|
||||
context = getContext();
|
||||
|
||||
lv_search_tags = rootView.findViewById(R.id.lv_search_toots);
|
||||
loader = rootView.findViewById(R.id.loader);
|
||||
textviewNoAction = rootView.findViewById(R.id.no_action);
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
loading_next_tags = rootView.findViewById(R.id.loading_next_tags);
|
||||
flag_loading = true;
|
||||
if (tags == null)
|
||||
tags = new ArrayList<>();
|
||||
|
||||
Bundle bundle = this.getArguments();
|
||||
if (bundle != null) {
|
||||
search = bundle.getString("search");
|
||||
if (search != null)
|
||||
new RetrieveSearchAsyncTask(context, search.trim(), DisplaySearchTagsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
Toasty.error(context, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toasty.error(context, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_search_tags.setLayoutManager(mLayoutManager);
|
||||
|
||||
lv_search_tags.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
|
||||
{
|
||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||
if(dy > 0){
|
||||
int visibleItemCount = mLayoutManager.getChildCount();
|
||||
int totalItemCount = mLayoutManager.getItemCount();
|
||||
if(firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
|
||||
if(!flag_loading ) {
|
||||
flag_loading = true;
|
||||
|
||||
loading_next_tags.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
loading_next_tags.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
||||
public void scrollToTop(){
|
||||
if( lv_search_tags != null) {
|
||||
lv_search_tags.setAdapter(searchTagsAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle saveInstance) {
|
||||
super.onCreate(saveInstance);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveSearch(Results results, Error error) {
|
||||
|
||||
searchTagsAdapter = new SearchTagsAdapter(context, tags);
|
||||
|
||||
loader.setVisibility(View.GONE);
|
||||
if (error!= null) {
|
||||
Toasty.error(context, error.getError(), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
lv_search_tags.setVisibility(View.VISIBLE);
|
||||
List<String> newTags = results.getHashtags();
|
||||
tags.addAll(newTags);
|
||||
SearchTagsAdapter searchTagsAdapter = new SearchTagsAdapter(context, tags);
|
||||
lv_search_tags.setAdapter(searchTagsAdapter);
|
||||
searchTagsAdapter.notifyDataSetChanged();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 Thomas Schneider
|
||||
|
||||
This file is a part of Mastalab
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingLeft="@dimen/fab_margin"
|
||||
android:paddingRight="@dimen/fab_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:orientation="vertical">
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/search_tabLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:tabSelectedTextColor="?attr/colorAccent"
|
||||
app:tabTextColor="?attr/textColor"
|
||||
app:tabMode="fixed"
|
||||
app:tabGravity="fill"
|
||||
/>
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/search_viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
/>
|
||||
<RelativeLayout
|
||||
android:id="@+id/no_result"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:padding="10dp"
|
||||
android:gravity="center"
|
||||
android:textSize="25sp"
|
||||
android:layout_gravity="center"
|
||||
android:textStyle="italic|bold"
|
||||
android:typeface="serif"
|
||||
android:text="@string/no_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</RelativeLayout>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loader"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2019 Thomas Schneider
|
||||
|
||||
This file is a part of Mastalab
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
see <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:paddingLeft="@dimen/fab_margin"
|
||||
android:paddingRight="@dimen/fab_margin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<!-- Listview drafts toots -->
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/swipeContainer"
|
||||
android:layout_height="match_parent">
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/lv_search_tags"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
/>
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
<RelativeLayout
|
||||
android:id="@+id/no_action"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/no_action_text"
|
||||
android:padding="10dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:gravity="center"
|
||||
android:textSize="25sp"
|
||||
android:layout_gravity="center"
|
||||
android:textStyle="italic|bold"
|
||||
android:typeface="serif"
|
||||
android:text="@string/no_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</RelativeLayout>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loader"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
<!-- Loader for next tags -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/loading_next_tags"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:gravity="bottom|center_horizontal"
|
||||
android:layout_height="20dp">
|
||||
<ProgressBar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
Loading…
Reference in New Issue