Changes the way it works...
This commit is contained in:
parent
03c119e367
commit
3ea3c9d9eb
|
@ -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{
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||
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<Void, Void, Void> {
|
||||
|
||||
private String query;
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveSearchStatusInterface listener;
|
||||
private API api;
|
||||
private WeakReference<Context> 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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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<String, String> 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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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">
|
||||
<TextView
|
||||
android:drawableRight="@drawable/ic_keyboard_arrow_right"
|
||||
android:drawableEnd="@drawable/ic_keyboard_arrow_right"
|
||||
android:id="@+id/search_keyword"
|
||||
android:textSize="18sp"
|
||||
android:background="?attr/colorAccent"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
|
|
Loading…
Reference in New Issue