From 3ea3c9d9ebf24e0320bbf8cd536a2b78f6bdac61 Mon Sep 17 00:00:00 2001 From: stom79 Date: Fri, 24 Nov 2017 14:46:22 +0100 Subject: [PATCH] Changes the way it works... --- .../activities/SearchResultActivity.java | 6 +- .../asynctasks/RetrieveTootsAsyncTask.java | 59 ------------------- .../fr/gouv/etalab/mastodon/client/API.java | 33 ----------- .../drawers/SearchTootsListAdapter.java | 18 +++++- app/src/main/res/layout/drawer_search.xml | 4 +- 5 files changed, 19 insertions(+), 101 deletions(-) delete mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveTootsAsyncTask.java diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java index 2cab4fc4d..3ed8c6c95 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java @@ -30,7 +30,6 @@ import java.util.List; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask; -import fr.gouv.etalab.mastodon.asynctasks.RetrieveTootsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Error; @@ -72,11 +71,8 @@ public class SearchResultActivity extends AppCompatActivity implements OnRetriev Bundle b = getIntent().getExtras(); if(b != null){ search = b.getString("search"); - boolean tootOnly = b.getBoolean("tootOnly", false); - if( !tootOnly && search != null) + if( search != null) new RetrieveSearchAsyncTask(getApplicationContext(), search.trim(), SearchResultActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else if(tootOnly) - new RetrieveTootsAsyncTask(getApplicationContext(), search.trim(), SearchResultActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else Toast.makeText(this,R.string.toast_error_search,Toast.LENGTH_LONG).show(); }else{ diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveTootsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveTootsAsyncTask.java deleted file mode 100644 index 011445717..000000000 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveTootsAsyncTask.java +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright 2017 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 . */ -package fr.gouv.etalab.mastodon.asynctasks; - -import android.content.Context; -import android.os.AsyncTask; - -import java.lang.ref.WeakReference; - -import fr.gouv.etalab.mastodon.client.API; -import fr.gouv.etalab.mastodon.client.APIResponse; -import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchStatusInterface; - - -/** - * Created by Thomas on 22/11/2017. - * Retrieves toots from search - */ - -public class RetrieveTootsAsyncTask extends AsyncTask { - - private String query; - private APIResponse apiResponse; - private OnRetrieveSearchStatusInterface listener; - private API api; - private WeakReference contextReference; - - public RetrieveTootsAsyncTask(Context context, String query, OnRetrieveSearchStatusInterface onRetrieveSearchStatusInterface){ - this.contextReference = new WeakReference<>(context); - this.query = query; - this.listener = onRetrieveSearchStatusInterface; - } - - - @Override - protected Void doInBackground(Void... params) { - api = new API(this.contextReference.get()); - apiResponse = api.searchStatus(query, 40); - return null; - } - - @Override - protected void onPostExecute(Void result) { - listener.onRetrieveSearchStatus(apiResponse, api.getError()); - } - -} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index b7a52e612..64b17941c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -1133,39 +1133,6 @@ public class API { return apiResponse; } - - /** - * Retrieves Accounts when searching (ie: via @...) *synchronously* - * - * @param query String search - * @return APIResponse - */ - public APIResponse searchStatus(String query, int count) { - - HashMap params = new HashMap<>(); - params.put("q", query); - if( count < 5) - count = 5; - if( count > 40 ) - count = 40; - params.put("limit", String.valueOf(count)); - - try { - HttpsConnection httpsConnection = new HttpsConnection(); - String response = httpsConnection.get(getAbsoluteUrl("/statuses/search"), 60, params, null); - statuses = parseStatuses(new JSONArray(response)); - apiResponse.setSince_id(httpsConnection.getSince_id()); - apiResponse.setMax_id(httpsConnection.getMax_id()); - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); - }catch (Exception e) { - setDefaultError(); - e.printStackTrace(); - } - apiResponse.setStatuses(statuses); - return apiResponse; - } - /** * Parse json response an unique account * @param resobj JSONObject diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchTootsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchTootsListAdapter.java index 515d95ea8..828b0a784 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchTootsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/SearchTootsListAdapter.java @@ -18,7 +18,9 @@ package fr.gouv.etalab.mastodon.drawers; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; @@ -29,7 +31,9 @@ import android.widget.TextView; import java.util.List; import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.activities.HashTagActivity; import fr.gouv.etalab.mastodon.activities.SearchResultActivity; +import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.SearchDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; @@ -82,13 +86,21 @@ public class SearchTootsListAdapter extends BaseAdapter { } else { holder = (ViewHolder) convertView.getTag(); } + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + if( theme == Helper.THEME_LIGHT){ + holder.search_container.setBackgroundResource(R.color.mastodonC3__); + }else { + holder.search_container.setBackgroundResource(R.color.mastodonC1_); + } holder.search_title.setText(search); holder.search_title.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(context, SearchResultActivity.class); - intent.putExtra("search", search); - intent.putExtra("tootOnly", true); + Intent intent = new Intent(context, HashTagActivity.class); + Bundle b = new Bundle(); + b.putString("tag", search.trim()); + intent.putExtras(b); context.startActivity(intent); } }); diff --git a/app/src/main/res/layout/drawer_search.xml b/app/src/main/res/layout/drawer_search.xml index 33f22f6b7..5d6bb6abf 100644 --- a/app/src/main/res/layout/drawer_search.xml +++ b/app/src/main/res/layout/drawer_search.xml @@ -19,13 +19,15 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/search_container" + android:divider="?android:dividerHorizontal" + android:showDividers="end" + android:paddingTop="5dp" android:orientation="vertical">