Add trends in search
This commit is contained in:
parent
7098ea8850
commit
bc1237699b
|
@ -5484,6 +5484,7 @@ public class API {
|
|||
try {
|
||||
results.setAccounts(parseAccountResponse(resobj.getJSONArray("accounts")));
|
||||
results.setStatuses(parseStatuses(context, resobj.getJSONArray("statuses")));
|
||||
results.setTrends(parseTrends(resobj.getJSONArray("hashtags")));
|
||||
results.setHashtags(parseTags(resobj.getJSONArray("hashtags")));
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
|
|
|
@ -12,6 +12,7 @@ public class Results {
|
|||
private List<Account> accounts;
|
||||
private List<Status> statuses;
|
||||
private List<String> hashtags;
|
||||
private List<Trends> trends;
|
||||
|
||||
public List<Account> getAccounts() {
|
||||
return accounts;
|
||||
|
@ -36,4 +37,12 @@ public class Results {
|
|||
public void setHashtags(List<String> hashtags) {
|
||||
this.hashtags = hashtags;
|
||||
}
|
||||
|
||||
public List<Trends> getTrends() {
|
||||
return trends;
|
||||
}
|
||||
|
||||
public void setTrends(List<Trends> trends) {
|
||||
this.trends = trends;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,9 @@ package app.fedilab.android.client.Entities;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 23/04/2017.
|
||||
* Manage Tags
|
||||
|
@ -24,26 +27,18 @@ import android.os.Parcelable;
|
|||
|
||||
public class Tag implements Parcelable {
|
||||
|
||||
public static final Creator<Tag> CREATOR = new Creator<Tag>() {
|
||||
@Override
|
||||
public Tag createFromParcel(Parcel in) {
|
||||
return new Tag(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag[] newArray(int size) {
|
||||
return new Tag[size];
|
||||
}
|
||||
};
|
||||
private String name;
|
||||
private String url;
|
||||
|
||||
private List<TrendsHistory> trendsHistory;
|
||||
public Tag() {
|
||||
}
|
||||
|
||||
protected Tag(Parcel in) {
|
||||
name = in.readString();
|
||||
url = in.readString();
|
||||
public List<TrendsHistory> getTrendsHistory() {
|
||||
return trendsHistory;
|
||||
}
|
||||
|
||||
public void setTrendsHistory(List<TrendsHistory> trendsHistory) {
|
||||
this.trendsHistory = trendsHistory;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -69,7 +64,27 @@ public class Tag implements Parcelable {
|
|||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(name);
|
||||
dest.writeString(url);
|
||||
dest.writeString(this.name);
|
||||
dest.writeString(this.url);
|
||||
dest.writeList(this.trendsHistory);
|
||||
}
|
||||
|
||||
protected Tag(Parcel in) {
|
||||
this.name = in.readString();
|
||||
this.url = in.readString();
|
||||
this.trendsHistory = new ArrayList<TrendsHistory>();
|
||||
in.readList(this.trendsHistory, TrendsHistory.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static final Creator<Tag> CREATOR = new Creator<Tag>() {
|
||||
@Override
|
||||
public Tag createFromParcel(Parcel source) {
|
||||
return new Tag(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag[] newArray(int size) {
|
||||
return new Tag[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -15,12 +15,15 @@ package app.fedilab.android.client.Entities;
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 30/11/2019.
|
||||
* Manage Tag trends history
|
||||
*/
|
||||
|
||||
public class TrendsHistory {
|
||||
public class TrendsHistory implements Parcelable {
|
||||
|
||||
private long days;
|
||||
private int uses;
|
||||
|
@ -49,4 +52,37 @@ public class TrendsHistory {
|
|||
public void setAccounts(int accounts) {
|
||||
this.accounts = accounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(this.days);
|
||||
dest.writeInt(this.uses);
|
||||
dest.writeInt(this.accounts);
|
||||
}
|
||||
|
||||
public TrendsHistory() {
|
||||
}
|
||||
|
||||
protected TrendsHistory(Parcel in) {
|
||||
this.days = in.readLong();
|
||||
this.uses = in.readInt();
|
||||
this.accounts = in.readInt();
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<TrendsHistory> CREATOR = new Parcelable.Creator<TrendsHistory>() {
|
||||
@Override
|
||||
public TrendsHistory createFromParcel(Parcel source) {
|
||||
return new TrendsHistory(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrendsHistory[] newArray(int size) {
|
||||
return new TrendsHistory[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -20,15 +20,17 @@ import android.os.Bundle;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,7 +38,8 @@ import app.fedilab.android.R;
|
|||
import app.fedilab.android.asynctasks.RetrieveSearchAsyncTask;
|
||||
import app.fedilab.android.client.API;
|
||||
import app.fedilab.android.client.APIResponse;
|
||||
import app.fedilab.android.drawers.SearchTagsAdapter;
|
||||
import app.fedilab.android.client.Entities.Trends;
|
||||
import app.fedilab.android.drawers.TrendsAdapter;
|
||||
import app.fedilab.android.interfaces.OnRetrieveSearchInterface;
|
||||
import es.dmoral.toasty.Toasty;
|
||||
|
||||
|
@ -49,14 +52,13 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea
|
|||
|
||||
|
||||
private Context context;
|
||||
private SearchTagsAdapter searchTagsAdapter;
|
||||
private List<String> tags;
|
||||
private TrendsAdapter trendsAdapter;
|
||||
private List<Trends> tags;
|
||||
private String search;
|
||||
private RecyclerView lv_search_tags;
|
||||
private ListView lv_search_tags;
|
||||
private RelativeLayout loader;
|
||||
private RelativeLayout textviewNoAction;
|
||||
private RelativeLayout loading_next_tags;
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private boolean flag_loading;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
private String max_id;
|
||||
|
@ -88,8 +90,6 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea
|
|||
Toasty.error(context, getString(R.string.toast_error_search), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
mLayoutManager = new LinearLayoutManager(context);
|
||||
lv_search_tags.setLayoutManager(mLayoutManager);
|
||||
int c1 = getResources().getColor(R.color.cyanea_accent);
|
||||
int c2 = getResources().getColor(R.color.cyanea_primary_dark);
|
||||
int c3 = getResources().getColor(R.color.cyanea_primary);
|
||||
|
@ -100,36 +100,37 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea
|
|||
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
int size = tags.size();
|
||||
tags.clear();
|
||||
tags = new ArrayList<>();
|
||||
max_id = "0";
|
||||
searchTagsAdapter.notifyItemRangeRemoved(0, size);
|
||||
trendsAdapter.notifyDataSetChanged();
|
||||
if (search != null) {
|
||||
new RetrieveSearchAsyncTask(context, search, API.searchType.TAGS, null, DisplaySearchTagsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
});
|
||||
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;
|
||||
if (search != null) {
|
||||
new RetrieveSearchAsyncTask(context, search, API.searchType.TAGS, max_id, DisplaySearchTagsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
loading_next_tags.setVisibility(View.VISIBLE);
|
||||
lv_search_tags.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
if (firstVisibleItem + visibleItemCount == totalItemCount && context != null) {
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
if (search != null) {
|
||||
new RetrieveSearchAsyncTask(context, search, API.searchType.TAGS, max_id, DisplaySearchTagsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
} else {
|
||||
loading_next_tags.setVisibility(View.GONE);
|
||||
loading_next_tags.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
loading_next_tags.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (search != null) {
|
||||
new RetrieveSearchAsyncTask(context, search, API.searchType.TAGS, null, DisplaySearchTagsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
@ -138,8 +139,8 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea
|
|||
|
||||
|
||||
public void scrollToTop() {
|
||||
if (lv_search_tags != null && searchTagsAdapter != null) {
|
||||
lv_search_tags.setAdapter(searchTagsAdapter);
|
||||
if (lv_search_tags != null && trendsAdapter != null) {
|
||||
lv_search_tags.setAdapter(trendsAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +159,7 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
public void onAttach(@NotNull Context context) {
|
||||
super.onAttach(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
@ -167,7 +168,7 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea
|
|||
@Override
|
||||
public void onRetrieveSearch(APIResponse apiResponse) {
|
||||
|
||||
searchTagsAdapter = new SearchTagsAdapter(tags);
|
||||
trendsAdapter = new TrendsAdapter(context, tags);
|
||||
loader.setVisibility(View.GONE);
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
if (apiResponse.getError() != null) {
|
||||
|
@ -185,14 +186,14 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea
|
|||
max_id = "0";
|
||||
max_id = String.valueOf(Integer.valueOf(max_id) + 20);
|
||||
lv_search_tags.setVisibility(View.VISIBLE);
|
||||
List<String> newTags = new ArrayList<>();
|
||||
List<Trends> newTags = new ArrayList<>();
|
||||
if (apiResponse.getResults() != null) {
|
||||
newTags = apiResponse.getResults().getHashtags();
|
||||
newTags = apiResponse.getResults().getTrends();
|
||||
}
|
||||
tags.addAll(newTags);
|
||||
SearchTagsAdapter searchTagsAdapter = new SearchTagsAdapter(tags);
|
||||
lv_search_tags.setAdapter(searchTagsAdapter);
|
||||
searchTagsAdapter.notifyDataSetChanged();
|
||||
TrendsAdapter trendsAdapter = new TrendsAdapter(context, tags);
|
||||
lv_search_tags.setAdapter(trendsAdapter);
|
||||
trendsAdapter.notifyDataSetChanged();
|
||||
if (newTags.size() == 0 && tags.size() == 0)
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
<TextView
|
||||
android:id="@+id/count"
|
||||
android:layout_gravity="center"
|
||||
android:layout_width="50dp"
|
||||
android:layout_width="40dp"
|
||||
android:textSize="25sp"
|
||||
android:layout_height="wrap_content"/>
|
||||
<com.github.mikephil.charting.charts.LineChart
|
||||
|
|
|
@ -29,10 +29,11 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
<ListView
|
||||
android:id="@+id/lv_search_tags"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:divider="@color/transparent"
|
||||
android:scrollbars="none" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in New Issue