Search with keywords
This commit is contained in:
parent
038fe79718
commit
e74a273f97
|
@ -90,6 +90,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplayDraftsFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
||||||
import fr.gouv.etalab.mastodon.fragments.DisplayScheduledTootsFragment;
|
import fr.gouv.etalab.mastodon.fragments.DisplayScheduledTootsFragment;
|
||||||
|
import fr.gouv.etalab.mastodon.fragments.DisplaySearchFragment;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveInstanceInterface;
|
||||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface;
|
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMetaDataInterface;
|
||||||
|
@ -120,7 +121,7 @@ import android.support.v4.app.FragmentStatePagerAdapter;
|
||||||
public abstract class BaseMainActivity extends AppCompatActivity
|
public abstract class BaseMainActivity extends AppCompatActivity
|
||||||
implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface {
|
implements NavigationView.OnNavigationItemSelectedListener, OnUpdateAccountInfoInterface, OnRetrieveMetaDataInterface, OnRetrieveInstanceInterface {
|
||||||
|
|
||||||
private FloatingActionButton toot, delete_all;
|
private FloatingActionButton toot, delete_all, add_new;
|
||||||
private HashMap<String, String> tagTile = new HashMap<>();
|
private HashMap<String, String> tagTile = new HashMap<>();
|
||||||
private HashMap<String, Integer> tagItem = new HashMap<>();
|
private HashMap<String, Integer> tagItem = new HashMap<>();
|
||||||
private TextView toolbarTitle;
|
private TextView toolbarTitle;
|
||||||
|
@ -568,6 +569,7 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
||||||
|
|
||||||
toot = findViewById(R.id.toot);
|
toot = findViewById(R.id.toot);
|
||||||
delete_all = findViewById(R.id.delete_all);
|
delete_all = findViewById(R.id.delete_all);
|
||||||
|
add_new = findViewById(R.id.add_new);
|
||||||
toot.setOnClickListener(new View.OnClickListener() {
|
toot.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -1086,6 +1088,7 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
||||||
tabLayout.setVisibility(View.VISIBLE);
|
tabLayout.setVisibility(View.VISIBLE);
|
||||||
toolbarTitle.setVisibility(View.GONE);
|
toolbarTitle.setVisibility(View.GONE);
|
||||||
delete_all.setVisibility(View.GONE);
|
delete_all.setVisibility(View.GONE);
|
||||||
|
add_new.setVisibility(View.GONE);
|
||||||
final NavigationView navigationView = findViewById(R.id.nav_view);
|
final NavigationView navigationView = findViewById(R.id.nav_view);
|
||||||
unCheckAllMenuItems(navigationView);
|
unCheckAllMenuItems(navigationView);
|
||||||
toot.setVisibility(View.VISIBLE);
|
toot.setVisibility(View.VISIBLE);
|
||||||
|
@ -1258,6 +1261,11 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
||||||
}else{
|
}else{
|
||||||
delete_all.setVisibility(View.VISIBLE);
|
delete_all.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
if( id != R.id.nav_search){
|
||||||
|
add_new.setVisibility(View.GONE);
|
||||||
|
}else{
|
||||||
|
add_new.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
if (id == R.id.nav_settings) {
|
if (id == R.id.nav_settings) {
|
||||||
toot.setVisibility(View.GONE);
|
toot.setVisibility(View.GONE);
|
||||||
TabLayoutSettingsFragment tabLayoutSettingsFragment= new TabLayoutSettingsFragment();
|
TabLayoutSettingsFragment tabLayoutSettingsFragment= new TabLayoutSettingsFragment();
|
||||||
|
@ -1296,12 +1304,17 @@ public abstract class BaseMainActivity extends AppCompatActivity
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
.replace(R.id.main_app_container, displayScheduledTootsFragment, fragmentTag).commit();
|
.replace(R.id.main_app_container, displayScheduledTootsFragment, fragmentTag).commit();
|
||||||
}else if (id == R.id.nav_drafts) {
|
}else if (id == R.id.nav_drafts) {
|
||||||
toot.setVisibility(View.VISIBLE);
|
|
||||||
DisplayDraftsFragment displayDraftsFragment = new DisplayDraftsFragment();
|
DisplayDraftsFragment displayDraftsFragment = new DisplayDraftsFragment();
|
||||||
fragmentTag = "DRAFTS";
|
fragmentTag = "DRAFTS";
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
.replace(R.id.main_app_container, displayDraftsFragment, fragmentTag).commit();
|
.replace(R.id.main_app_container, displayDraftsFragment, fragmentTag).commit();
|
||||||
toot.setVisibility(View.GONE);
|
toot.setVisibility(View.GONE);
|
||||||
|
}else if (id == R.id.nav_search) {
|
||||||
|
DisplaySearchFragment displaySearchFragment = new DisplaySearchFragment();
|
||||||
|
fragmentTag = "SEARCH";
|
||||||
|
fragmentManager.beginTransaction()
|
||||||
|
.replace(R.id.main_app_container, displaySearchFragment, fragmentTag).commit();
|
||||||
|
toot.setVisibility(View.GONE);
|
||||||
}else if( id == R.id.nav_follow_request){
|
}else if( id == R.id.nav_follow_request){
|
||||||
toot.setVisibility(View.GONE);
|
toot.setVisibility(View.GONE);
|
||||||
DisplayFollowRequestSentFragment followRequestSentFragment = new DisplayFollowRequestSentFragment();
|
DisplayFollowRequestSentFragment followRequestSentFragment = new DisplayFollowRequestSentFragment();
|
||||||
|
|
|
@ -27,27 +27,27 @@ import fr.gouv.etalab.mastodon.R;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 26/05/2017.
|
* Created by Thomas on 22/11/2017.
|
||||||
* Adapter for tags when searching
|
* Adapter for search
|
||||||
*/
|
*/
|
||||||
public class TagsListAdapter extends BaseAdapter {
|
public class SearchTootsListAdapter extends BaseAdapter {
|
||||||
|
|
||||||
private List<String> tags;
|
private List<String> searches;
|
||||||
private LayoutInflater layoutInflater;
|
private LayoutInflater layoutInflater;
|
||||||
|
|
||||||
public TagsListAdapter(Context context, List<String> tags){
|
public SearchTootsListAdapter(Context context, List<String> searches){
|
||||||
this.tags = tags;
|
this.searches = searches;
|
||||||
layoutInflater = LayoutInflater.from(context);
|
layoutInflater = LayoutInflater.from(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return tags.size();
|
return searches.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getItem(int position) {
|
public Object getItem(int position) {
|
||||||
return tags.get(position);
|
return searches.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,18 +59,18 @@ public class TagsListAdapter extends BaseAdapter {
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
|
|
||||||
final String tag = tags.get(position);
|
final String tag = searches.get(position);
|
||||||
final ViewHolder holder;
|
final ViewHolder holder;
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = layoutInflater.inflate(R.layout.drawer_tag, parent, false);
|
convertView = layoutInflater.inflate(R.layout.drawer_search, parent, false);
|
||||||
holder = new ViewHolder();
|
holder = new ViewHolder();
|
||||||
holder.tag_name = (TextView) convertView.findViewById(R.id.tag_name);
|
holder.search_title = convertView.findViewById(R.id.search_keyword);
|
||||||
convertView.setTag(holder);
|
convertView.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
holder = (ViewHolder) convertView.getTag();
|
holder = (ViewHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
holder.tag_name.setText(tag);
|
holder.search_title.setText(tag);
|
||||||
holder.tag_name.setOnClickListener(new View.OnClickListener() {
|
holder.search_title.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class TagsListAdapter extends BaseAdapter {
|
||||||
|
|
||||||
|
|
||||||
private class ViewHolder {
|
private class ViewHolder {
|
||||||
TextView tag_name;
|
TextView search_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.drawers;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -63,6 +64,7 @@ public class TagsSearchAdapter extends ArrayAdapter<String> implements Filterabl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ public class TagsSearchAdapter extends ArrayAdapter<String> implements Filterabl
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
convertView = layoutInflater.inflate(R.layout.drawer_tag_search, parent, false);
|
convertView = layoutInflater.inflate(R.layout.drawer_tag_search, parent, false);
|
||||||
holder = new ViewHolder();
|
holder = new ViewHolder();
|
||||||
holder.tag_name = (TextView) convertView.findViewById(R.id.tag_name);
|
holder.tag_name = convertView.findViewById(R.id.tag_name);
|
||||||
convertView.setTag(holder);
|
convertView.setTag(holder);
|
||||||
} else {
|
} else {
|
||||||
holder = (ViewHolder) convertView.getTag();
|
holder = (ViewHolder) convertView.getTag();
|
||||||
|
@ -81,6 +83,7 @@ public class TagsSearchAdapter extends ArrayAdapter<String> implements Filterabl
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Filter getFilter() {
|
public Filter getFilter() {
|
||||||
return searchFilter;
|
return searchFilter;
|
||||||
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
package fr.gouv.etalab.mastodon.fragments;
|
||||||
|
/* 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>. */
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.design.widget.FloatingActionButton;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
|
import fr.gouv.etalab.mastodon.drawers.SearchTootsListAdapter;
|
||||||
|
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
|
||||||
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||||
|
import fr.gouv.etalab.mastodon.R;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 22/11/2017.
|
||||||
|
* Fragment to display search with keywords
|
||||||
|
*/
|
||||||
|
public class DisplaySearchFragment extends Fragment {
|
||||||
|
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
private SearchTootsListAdapter searchTootsListAdapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
View rootView = inflater.inflate(R.layout.fragment_drafts, container, false);
|
||||||
|
context = getContext();
|
||||||
|
|
||||||
|
final ListView lv_search_toots = rootView.findViewById(R.id.lv_search_toots);
|
||||||
|
|
||||||
|
RelativeLayout mainLoader = rootView.findViewById(R.id.loader);
|
||||||
|
RelativeLayout textviewNoAction = rootView.findViewById(R.id.no_action);
|
||||||
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
|
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||||
|
List<String> searches = new SearchDAO(context, db).getAllSearch();
|
||||||
|
if( searches != null && searches.size() > 0) {
|
||||||
|
searchTootsListAdapter = new SearchTootsListAdapter(context, searches);
|
||||||
|
lv_search_toots.setAdapter(searchTootsListAdapter);
|
||||||
|
searchTootsListAdapter.notifyDataSetChanged();
|
||||||
|
}else {
|
||||||
|
textviewNoAction.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
mainLoader.setVisibility(View.GONE);
|
||||||
|
FloatingActionButton add_new = null;
|
||||||
|
try {
|
||||||
|
add_new = ((MainActivity) context).findViewById(R.id.add_new);
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
if( add_new != null)
|
||||||
|
add_new.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle(R.string.search);
|
||||||
|
builder.setIcon(android.R.drawable.ic_menu_search)
|
||||||
|
.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogConfirm, int which) {
|
||||||
|
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
|
||||||
|
LayoutInflater inflater = getLayoutInflater();
|
||||||
|
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.search_toot, null);
|
||||||
|
dialogBuilder.setView(dialogView);
|
||||||
|
final EditText editText = dialogView.findViewById(R.id.search_toot);
|
||||||
|
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
|
String keyword = editText.getText().toString().trim();
|
||||||
|
//Already in db
|
||||||
|
List<String> searches = new SearchDAO(context, db).getSearchByKeyword(keyword);
|
||||||
|
if( searches.size() > 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
new SearchDAO(context, db).insertSearch(keyword);
|
||||||
|
searches.add(keyword);
|
||||||
|
searchTootsListAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
|
alertDialog.show();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogConfirm, int which) {
|
||||||
|
dialogConfirm.dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return rootView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle saveInstance)
|
||||||
|
{
|
||||||
|
super.onCreate(saveInstance);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,139 @@
|
||||||
|
package fr.gouv.etalab.mastodon.sqlite;
|
||||||
|
/* 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>. */
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 22/11/2017.
|
||||||
|
* Manage search in DB
|
||||||
|
*/
|
||||||
|
public class SearchDAO {
|
||||||
|
|
||||||
|
private SQLiteDatabase db;
|
||||||
|
public Context context;
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
public SearchDAO(Context context, SQLiteDatabase db) {
|
||||||
|
//Creation of the DB with tables
|
||||||
|
this.context = context;
|
||||||
|
this.db = db;
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//------- INSERTIONS -------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a keyword in database
|
||||||
|
* @param keyword String
|
||||||
|
*/
|
||||||
|
public void insertSearch(String keyword) {
|
||||||
|
ContentValues values = new ContentValues();
|
||||||
|
values.put(Sqlite.COL_KEYWORDS, keyword);
|
||||||
|
values.put(Sqlite.COL_USER_ID, userId);
|
||||||
|
values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(context, new Date()));
|
||||||
|
//Inserts search
|
||||||
|
try{
|
||||||
|
db.insert(Sqlite.TABLE_SEARCH, null, values);
|
||||||
|
}catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//------- REMOVE -------
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Remove search by keyword
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public int remove(String keyword){
|
||||||
|
return db.delete(Sqlite.TABLE_SEARCH, Sqlite.COL_KEYWORDS + " = \"" + keyword + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId+ "\"", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//------- GETTERS -------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all search in db for a user
|
||||||
|
* @return search List<String>
|
||||||
|
*/
|
||||||
|
public List<String> getAllSearch(){
|
||||||
|
try {
|
||||||
|
Cursor c = db.query(Sqlite.TABLE_SEARCH, null, Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_KEYWORDS + " ASC", null);
|
||||||
|
return cursorToListSearch(c);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns search by its keyword in db
|
||||||
|
* @return keywords List<String>
|
||||||
|
*/
|
||||||
|
public List<String> getSearchStartingBy(String keyword){
|
||||||
|
try {
|
||||||
|
Cursor c = db.query(Sqlite.TABLE_SEARCH, null, Sqlite.COL_KEYWORDS + " LIKE \"%" + keyword + "%\" AND " + Sqlite.COL_USER_ID + " = \"" + userId+ "\"", null, null, null, null, null);
|
||||||
|
return cursorToListSearch(c);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns search by its keyword in db
|
||||||
|
* @return keywords List<String>
|
||||||
|
*/
|
||||||
|
public List<String> getSearchByKeyword(String keyword){
|
||||||
|
try {
|
||||||
|
Cursor c = db.query(Sqlite.TABLE_SEARCH, null, Sqlite.COL_KEYWORDS + " = \"" + keyword + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId+ "\"", null, null, null, null, null);
|
||||||
|
return cursorToListSearch(c);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Method to hydrate stored search from database
|
||||||
|
* @param c Cursor
|
||||||
|
* @return List<String>
|
||||||
|
*/
|
||||||
|
private List<String> cursorToListSearch(Cursor c){
|
||||||
|
//No element found
|
||||||
|
if (c.getCount() == 0)
|
||||||
|
return null;
|
||||||
|
List<String> searches = new ArrayList<>();
|
||||||
|
while (c.moveToNext() ) {
|
||||||
|
searches.add(c.getString(c.getColumnIndex(Sqlite.COL_KEYWORDS)));
|
||||||
|
}
|
||||||
|
//Close the cursor
|
||||||
|
c.close();
|
||||||
|
//Search list is returned
|
||||||
|
return searches;
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public class Sqlite extends SQLiteOpenHelper {
|
public class Sqlite extends SQLiteOpenHelper {
|
||||||
|
|
||||||
public static final int DB_VERSION = 6;
|
public static final int DB_VERSION = 7;
|
||||||
public static final String DB_NAME = "mastodon_etalab_db";
|
public static final String DB_NAME = "mastodon_etalab_db";
|
||||||
public static SQLiteDatabase db;
|
public static SQLiteDatabase db;
|
||||||
private static Sqlite sInstance;
|
private static Sqlite sInstance;
|
||||||
|
@ -40,6 +40,8 @@ public class Sqlite extends SQLiteOpenHelper {
|
||||||
static final String TABLE_STATUSES_STORED = "STATUSES_STORED";
|
static final String TABLE_STATUSES_STORED = "STATUSES_STORED";
|
||||||
//Table for custom emoji
|
//Table for custom emoji
|
||||||
static final String TABLE_CUSTOM_EMOJI = "CUSTOM_EMOJI";
|
static final String TABLE_CUSTOM_EMOJI = "CUSTOM_EMOJI";
|
||||||
|
//Table for search
|
||||||
|
static final String TABLE_SEARCH = "SEARCH";
|
||||||
|
|
||||||
public static final String COL_USER_ID = "USER_ID";
|
public static final String COL_USER_ID = "USER_ID";
|
||||||
public static final String COL_USERNAME = "USERNAME";
|
public static final String COL_USERNAME = "USERNAME";
|
||||||
|
@ -95,6 +97,12 @@ public class Sqlite extends SQLiteOpenHelper {
|
||||||
+ COL_SHORTCODE + " TEXT NOT NULL, " + COL_INSTANCE + " TEXT NOT NULL, "
|
+ COL_SHORTCODE + " TEXT NOT NULL, " + COL_INSTANCE + " TEXT NOT NULL, "
|
||||||
+ COL_URL + " TEXT NOT NULL, " + COL_URL_STATIC + " TEXT NOT NULL, " + COL_DATE_CREATION + " TEXT NOT NULL)";
|
+ COL_URL + " TEXT NOT NULL, " + COL_URL_STATIC + " TEXT NOT NULL, " + COL_DATE_CREATION + " TEXT NOT NULL)";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String COL_KEYWORDS = "KEYWORDS";
|
||||||
|
private final String CREATE_TABLE_SEARCH = "CREATE TABLE " + TABLE_SEARCH + " ("
|
||||||
|
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||||
|
+ COL_KEYWORDS + " TEXT NOT NULL, " + COL_USER_ID + " TEXT NOT NULL, " + COL_DATE_CREATION + " TEXT NOT NULL)";
|
||||||
|
|
||||||
public Sqlite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
|
public Sqlite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
|
||||||
super(context, name, factory, version);
|
super(context, name, factory, version);
|
||||||
}
|
}
|
||||||
|
@ -113,6 +121,7 @@ public class Sqlite extends SQLiteOpenHelper {
|
||||||
db.execSQL(CREATE_TABLE_USER_ACCOUNT);
|
db.execSQL(CREATE_TABLE_USER_ACCOUNT);
|
||||||
db.execSQL(CREATE_TABLE_STATUSES_STORED);
|
db.execSQL(CREATE_TABLE_STATUSES_STORED);
|
||||||
db.execSQL(CREATE_TABLE_CUSTOM_EMOJI);
|
db.execSQL(CREATE_TABLE_CUSTOM_EMOJI);
|
||||||
|
db.execSQL(CREATE_TABLE_SEARCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -132,6 +141,8 @@ public class Sqlite extends SQLiteOpenHelper {
|
||||||
+ COL_URL + " TEXT NOT NULL, " + COL_URL_STATIC + " TEXT NOT NULL, " + COL_DATE_CREATION + " TEXT NOT NULL)");
|
+ COL_URL + " TEXT NOT NULL, " + COL_URL_STATIC + " TEXT NOT NULL, " + COL_DATE_CREATION + " TEXT NOT NULL)");
|
||||||
case 5:
|
case 5:
|
||||||
db.execSQL("delete from "+ TABLE_CUSTOM_EMOJI); //Reset table due to bugs
|
db.execSQL("delete from "+ TABLE_CUSTOM_EMOJI); //Reset table due to bugs
|
||||||
|
case 6:
|
||||||
|
db.execSQL(CREATE_TABLE_SEARCH);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M8.59,16.34l4.58,-4.59 -4.58,-4.59L10,5.75l6,6 -6,6z"/>
|
||||||
|
</vector>
|
Binary file not shown.
After Width: | Height: | Size: 134 B |
Binary file not shown.
After Width: | Height: | Size: 119 B |
Binary file not shown.
After Width: | Height: | Size: 116 B |
Binary file not shown.
After Width: | Height: | Size: 168 B |
Binary file not shown.
After Width: | Height: | Size: 242 B |
Binary file not shown.
After Width: | Height: | Size: 500 B |
|
@ -127,6 +127,15 @@
|
||||||
android:layout_margin="@dimen/fab_margin"
|
android:layout_margin="@dimen/fab_margin"
|
||||||
app:srcCompat="@drawable/ic_delete_floating"
|
app:srcCompat="@drawable/ic_delete_floating"
|
||||||
tools:ignore="VectorDrawableCompat" />
|
tools:ignore="VectorDrawableCompat" />
|
||||||
|
<android.support.design.widget.FloatingActionButton
|
||||||
|
android:id="@+id/add_new"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="@dimen/fab_margin"
|
||||||
|
app:srcCompat="@drawable/ic_action_add_new"
|
||||||
|
tools:ignore="VectorDrawableCompat" />
|
||||||
</android.support.design.widget.CoordinatorLayout>
|
</android.support.design.widget.CoordinatorLayout>
|
||||||
|
|
||||||
<android.support.design.widget.NavigationView
|
<android.support.design.widget.NavigationView
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
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>.
|
||||||
|
-->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/account_container"
|
||||||
|
android:orientation="vertical">
|
||||||
|
<TextView
|
||||||
|
android:drawableRight="@drawable/ic_keyboard_arrow_right"
|
||||||
|
android:drawableEnd="@drawable/ic_keyboard_arrow_right"
|
||||||
|
android:id="@+id/search_keyword"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:textSize="18sp"
|
||||||
|
android:background="?attr/colorAccent"
|
||||||
|
android:paddingBottom="10dp"
|
||||||
|
android:paddingTop="10dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
</LinearLayout>
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
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>.
|
||||||
|
-->
|
||||||
|
<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 -->
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/lv_search_toots"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none"
|
||||||
|
android:divider="@null"
|
||||||
|
>
|
||||||
|
</ListView>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/no_action"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<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>
|
||||||
|
</RelativeLayout>
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/search_toot"
|
||||||
|
android:inputType="text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/action_search"
|
||||||
|
android:maxLines="1"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
|
@ -19,6 +19,10 @@
|
||||||
android:id="@+id/nav_drafts"
|
android:id="@+id/nav_drafts"
|
||||||
android:icon="@drawable/ic_save_white"
|
android:icon="@drawable/ic_save_white"
|
||||||
android:title="@string/drafts" />
|
android:title="@string/drafts" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_search"
|
||||||
|
android:icon="@drawable/ic_search"
|
||||||
|
android:title="@string/search" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_remote_follow"
|
android:id="@+id/nav_remote_follow"
|
||||||
android:icon="@drawable/ic_person_add"
|
android:icon="@drawable/ic_person_add"
|
||||||
|
|
|
@ -432,4 +432,5 @@
|
||||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||||
<string name="live_notif">Live notifications</string>
|
<string name="live_notif">Live notifications</string>
|
||||||
<string name="filter_regex">Mit regulären Ausdrücken filtern</string>
|
<string name="filter_regex">Mit regulären Ausdrücken filtern</string>
|
||||||
|
<string name="search">Suche</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -439,4 +439,6 @@
|
||||||
<string name="no_emoji">L\'application n\'a pas encore collecté d\'emojis personnalisés</string>
|
<string name="no_emoji">L\'application n\'a pas encore collecté d\'emojis personnalisés</string>
|
||||||
<string name="live_notif">Notifications en direct</string>
|
<string name="live_notif">Notifications en direct</string>
|
||||||
<string name="filter_regex">Filtrer avec une expression rationnelle</string>
|
<string name="filter_regex">Filtrer avec une expression rationnelle</string>
|
||||||
|
|
||||||
|
<string name="search">Rechercher</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -436,4 +436,5 @@
|
||||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||||
<string name="live_notif">Live notifications</string>
|
<string name="live_notif">Live notifications</string>
|
||||||
<string name="filter_regex">Wegfilteren met reguliere expressies</string>
|
<string name="filter_regex">Wegfilteren met reguliere expressies</string>
|
||||||
|
<string name="search">Zoeken</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -438,4 +438,5 @@
|
||||||
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
<string name="no_emoji">The app did not collect custom emojis for the moment.</string>
|
||||||
<string name="live_notif">Live notifications</string>
|
<string name="live_notif">Live notifications</string>
|
||||||
<string name="filter_regex">Filtrar com uma expressão regular</string>
|
<string name="filter_regex">Filtrar com uma expressão regular</string>
|
||||||
|
<string name="search">Pesquisar</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -445,4 +445,5 @@
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<string name="filter_regex">Filter out by regular expressions</string>
|
<string name="filter_regex">Filter out by regular expressions</string>
|
||||||
|
<string name="search">Search</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue