Improves search
This commit is contained in:
parent
6c48fd6c3a
commit
83bcc752a9
|
@ -20,17 +20,13 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
import fr.gouv.etalab.mastodon.client.API;
|
import fr.gouv.etalab.mastodon.client.API;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.CustomEmojiDAO;
|
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -54,6 +55,7 @@ public class DraftsListAdapter extends BaseAdapter {
|
||||||
private Context context;
|
private Context context;
|
||||||
private DraftsListAdapter draftsListAdapter;
|
private DraftsListAdapter draftsListAdapter;
|
||||||
private boolean clickable;
|
private boolean clickable;
|
||||||
|
private RelativeLayout textviewNoAction;
|
||||||
|
|
||||||
public DraftsListAdapter(Context context, List<StoredStatus> storedStatuses){
|
public DraftsListAdapter(Context context, List<StoredStatus> storedStatuses){
|
||||||
this.storedStatuses = storedStatuses;
|
this.storedStatuses = storedStatuses;
|
||||||
|
@ -63,12 +65,13 @@ public class DraftsListAdapter extends BaseAdapter {
|
||||||
this.clickable = false;
|
this.clickable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DraftsListAdapter(Context context, List<StoredStatus> storedStatuses, boolean clickable){
|
public DraftsListAdapter(Context context, List<StoredStatus> storedStatuses, boolean clickable, RelativeLayout textviewNoAction){
|
||||||
this.storedStatuses = storedStatuses;
|
this.storedStatuses = storedStatuses;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
layoutInflater = LayoutInflater.from(context);
|
layoutInflater = LayoutInflater.from(context);
|
||||||
draftsListAdapter = this;
|
draftsListAdapter = this;
|
||||||
this.clickable = clickable;
|
this.clickable = clickable;
|
||||||
|
this.textviewNoAction = textviewNoAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,6 +148,8 @@ public class DraftsListAdapter extends BaseAdapter {
|
||||||
new StatusStoredDAO(context, db).remove(draft.getId());
|
new StatusStoredDAO(context, db).remove(draft.getId());
|
||||||
storedStatuses.remove(draft);
|
storedStatuses.remove(draft);
|
||||||
draftsListAdapter.notifyDataSetChanged();
|
draftsListAdapter.notifyDataSetChanged();
|
||||||
|
if( storedStatuses.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,16 +27,18 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.R;
|
import fr.gouv.etalab.mastodon.R;
|
||||||
import fr.gouv.etalab.mastodon.activities.HashTagActivity;
|
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.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
|
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||||
|
|
||||||
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 22/11/2017.
|
* Created by Thomas on 22/11/2017.
|
||||||
|
@ -48,12 +50,14 @@ public class SearchTootsListAdapter extends BaseAdapter {
|
||||||
private LayoutInflater layoutInflater;
|
private LayoutInflater layoutInflater;
|
||||||
private Context context;
|
private Context context;
|
||||||
private SearchTootsListAdapter searchTootsListAdapter;
|
private SearchTootsListAdapter searchTootsListAdapter;
|
||||||
|
private RelativeLayout textviewNoAction;
|
||||||
|
|
||||||
public SearchTootsListAdapter(Context context, List<String> searches){
|
public SearchTootsListAdapter(Context context, List<String> searches, RelativeLayout textviewNoAction){
|
||||||
this.searches = searches;
|
this.searches = searches;
|
||||||
layoutInflater = LayoutInflater.from(context);
|
layoutInflater = LayoutInflater.from(context);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.searchTootsListAdapter = this;
|
this.searchTootsListAdapter = this;
|
||||||
|
this.textviewNoAction = textviewNoAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -90,11 +94,13 @@ public class SearchTootsListAdapter extends BaseAdapter {
|
||||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
if( theme == Helper.THEME_LIGHT){
|
if( theme == Helper.THEME_LIGHT){
|
||||||
holder.search_container.setBackgroundResource(R.color.mastodonC3__);
|
holder.search_container.setBackgroundResource(R.color.mastodonC3__);
|
||||||
|
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.black);
|
||||||
}else {
|
}else {
|
||||||
holder.search_container.setBackgroundResource(R.color.mastodonC1_);
|
holder.search_container.setBackgroundResource(R.color.mastodonC1_);
|
||||||
|
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
|
||||||
}
|
}
|
||||||
holder.search_title.setText(search);
|
holder.search_title.setText(search);
|
||||||
holder.search_title.setOnClickListener(new View.OnClickListener() {
|
holder.search_container.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(context, HashTagActivity.class);
|
Intent intent = new Intent(context, HashTagActivity.class);
|
||||||
|
@ -106,12 +112,11 @@ public class SearchTootsListAdapter extends BaseAdapter {
|
||||||
});
|
});
|
||||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
|
||||||
holder.search_container.setOnClickListener(new View.OnClickListener() {
|
holder.search_container.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public boolean onLongClick(View view) {
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setMessage(R.string.delete + ": " + search);
|
builder.setMessage(context.getString(R.string.delete) + ": " + search);
|
||||||
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -119,6 +124,8 @@ public class SearchTootsListAdapter extends BaseAdapter {
|
||||||
new SearchDAO(context, db).remove(search.trim());
|
new SearchDAO(context, db).remove(search.trim());
|
||||||
searches.remove(search);
|
searches.remove(search);
|
||||||
searchTootsListAdapter.notifyDataSetChanged();
|
searchTootsListAdapter.notifyDataSetChanged();
|
||||||
|
if( searches.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -129,6 +136,7 @@ public class SearchTootsListAdapter extends BaseAdapter {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return convertView;
|
return convertView;
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class DisplayDraftsFragment extends Fragment {
|
||||||
new StatusStoredDAO(context, db).removeAllSent();
|
new StatusStoredDAO(context, db).removeAllSent();
|
||||||
drafts = new StatusStoredDAO(context, db).getAllDrafts();
|
drafts = new StatusStoredDAO(context, db).getAllDrafts();
|
||||||
if( drafts != null && drafts.size() > 0) {
|
if( drafts != null && drafts.size() > 0) {
|
||||||
draftsListAdapter = new DraftsListAdapter(context, drafts, true);
|
draftsListAdapter = new DraftsListAdapter(context, drafts, true, textviewNoAction);
|
||||||
lv_draft_toots.setAdapter(draftsListAdapter);
|
lv_draft_toots.setAdapter(draftsListAdapter);
|
||||||
draftsListAdapter.notifyDataSetChanged();
|
draftsListAdapter.notifyDataSetChanged();
|
||||||
}else {
|
}else {
|
||||||
|
@ -100,7 +100,7 @@ public class DisplayDraftsFragment extends Fragment {
|
||||||
new StatusStoredDAO(context, db).removeAllDrafts();
|
new StatusStoredDAO(context, db).removeAllDrafts();
|
||||||
drafts = new ArrayList<>();
|
drafts = new ArrayList<>();
|
||||||
drafts.clear();
|
drafts.clear();
|
||||||
draftsListAdapter = new DraftsListAdapter(context, drafts, true);
|
draftsListAdapter = new DraftsListAdapter(context, drafts, true, textviewNoAction);
|
||||||
lv_draft_toots.setAdapter(draftsListAdapter);
|
lv_draft_toots.setAdapter(draftsListAdapter);
|
||||||
draftsListAdapter.notifyDataSetChanged();
|
draftsListAdapter.notifyDataSetChanged();
|
||||||
textviewNoAction.setVisibility(View.VISIBLE);
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -23,7 +23,6 @@ import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -67,8 +66,7 @@ public class DisplaySearchFragment extends Fragment {
|
||||||
List<String> searches = new SearchDAO(context, db).getAllSearch();
|
List<String> searches = new SearchDAO(context, db).getAllSearch();
|
||||||
if( searches == null)
|
if( searches == null)
|
||||||
searches = new ArrayList<>();
|
searches = new ArrayList<>();
|
||||||
Log.v(Helper.TAG,"searches: " + searches);
|
searchTootsListAdapter = new SearchTootsListAdapter(context, searches, textviewNoAction);
|
||||||
searchTootsListAdapter = new SearchTootsListAdapter(context, searches);
|
|
||||||
lv_search_toots.setAdapter(searchTootsListAdapter);
|
lv_search_toots.setAdapter(searchTootsListAdapter);
|
||||||
searchTootsListAdapter.notifyDataSetChanged();
|
searchTootsListAdapter.notifyDataSetChanged();
|
||||||
if( searches.size() == 0) {
|
if( searches.size() == 0) {
|
||||||
|
|
Loading…
Reference in New Issue