Search improvements

pull/168/head
M66B 5 years ago
parent a7b30f28e8
commit d63b703674

@ -820,7 +820,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
searching = true;
FragmentMessages.search(
ActivityView.this, ActivityView.this, getSupportFragmentManager(),
-1, false, search);
-1, -1, false, search);
}
intent.removeExtra(Intent.EXTRA_PROCESS_TEXT);
@ -1040,11 +1040,12 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
}
private void onSearchMessages(Intent intent) {
long account = intent.getLongExtra("account", -1);
long folder = intent.getLongExtra("folder", -1);
String query = intent.getStringExtra("query");
FragmentMessages.search(
this, this, getSupportFragmentManager(),
folder, false, query);
account, folder, false, query);
}
private void onViewThread(Intent intent) {

@ -2304,6 +2304,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_SEARCH)
.putExtra("account", -1L)
.putExtra("folder", -1L)
.putExtra("query", query));
}

@ -284,7 +284,7 @@ public class FragmentAccounts extends FragmentBase {
public void onSearch(String query) {
FragmentMessages.search(
getContext(), getViewLifecycleOwner(), getParentFragmentManager(),
-1, false, query);
-1, -1, false, query);
}
});

@ -396,7 +396,7 @@ public class FragmentFolders extends FragmentBase {
public void onSearch(String query) {
FragmentMessages.search(
getContext(), getViewLifecycleOwner(), getParentFragmentManager(),
-1, false, query);
account, -1, false, query);
}
});

@ -134,7 +134,6 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -817,62 +816,77 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fabSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (folder < 0) {
Bundle args = new Bundle();
Bundle args = new Bundle();
args.putLong("account", account);
new SimpleTask<List<EntityAccount>>() {
@Override
protected List<EntityAccount> onExecute(Context context, Bundle args) {
Map<EntityAccount, List<EntityFolder>> result = new LinkedHashMap<>();
new SimpleTask<List<EntityAccount>>() {
@Override
protected List<EntityAccount> onExecute(Context context, Bundle args) {
long aid = args.getLong("account");
DB db = DB.getInstance(context);
return db.account().getSynchronizingAccounts();
List<EntityAccount> result = new ArrayList<>();
DB db = DB.getInstance(context);
if (aid < 0) {
List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
for (EntityAccount account : accounts)
if (!account.pop)
result.add(account);
} else {
EntityAccount account = db.account().getAccount(aid);
if (account != null && !account.pop)
result.add(account);
}
@Override
protected void onExecuted(Bundle args, List<EntityAccount> accounts) {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabSearch);
if (result.size() == 0)
throw new IllegalArgumentException(context.getString(R.string.title_no_search));
else
return result;
}
popupMenu.getMenu().add(Menu.NONE, 0, 0, R.string.title_search_server).setEnabled(false);
@Override
protected void onExecuted(Bundle args, List<EntityAccount> accounts) {
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabSearch);
int order = 1;
for (EntityAccount account : accounts)
if (!account.pop)
popupMenu.getMenu().add(Menu.NONE, 0, order++, account.name)
.setIntent(new Intent().putExtra("account", account.id));
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
Intent intent = target.getIntent();
if (intent == null)
return false;
Bundle args = new Bundle();
args.putString("title", getString(R.string.title_search_in));
args.putLong("account", intent.getLongExtra("account", -1));
args.putLongArray("disabled", new long[]{});
args.putString("query", query);
FragmentDialogFolder fragment = new FragmentDialogFolder();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentMessages.this, FragmentMessages.REQUEST_SEARCH);
fragment.show(getParentFragmentManager(), "messages:search");
return true;
}
});
popupMenu.getMenu().add(Menu.NONE, 0, 0, R.string.title_search_server).setEnabled(false);
popupMenu.show();
}
int order = 1;
for (EntityAccount account : accounts)
popupMenu.getMenu().add(Menu.NONE, 0, order++, account.name)
.setIntent(new Intent().putExtra("account", account.id));
@Override
protected void onException(Bundle args, Throwable ex) {
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
Intent intent = target.getIntent();
if (intent == null)
return false;
Bundle args = new Bundle();
args.putString("title", getString(R.string.title_search_in));
args.putLong("account", intent.getLongExtra("account", -1));
args.putLongArray("disabled", new long[]{});
args.putString("query", query);
FragmentDialogFolder fragment = new FragmentDialogFolder();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentMessages.this, FragmentMessages.REQUEST_SEARCH);
fragment.show(getParentFragmentManager(), "messages:search");
return true;
}
});
popupMenu.show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException)
ToastEx.makeText(getContext(), ex.getMessage(), Toast.LENGTH_LONG).show();
else
Helper.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "messages:search");
} else
search(getContext(), getViewLifecycleOwner(), getParentFragmentManager(), folder, true, query);
}
}.execute(FragmentMessages.this, args, "messages:search");
}
});
@ -2682,7 +2696,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
public void onSearch(String query) {
FragmentMessages.search(
getContext(), getViewLifecycleOwner(), getParentFragmentManager(),
folder, false, query);
account, folder, false, query);
}
});
@ -3920,7 +3934,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
Bundle args = data.getBundleExtra("args");
search(
getContext(), getViewLifecycleOwner(), getParentFragmentManager(),
args.getLong("folder"), true, args.getString("query"));
args.getLong("account"),
args.getLong("folder"),
true,
args.getString("query"));
}
break;
case REQUEST_ACCOUNT:
@ -4725,7 +4742,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
static void search(
final Context context, final LifecycleOwner owner, final FragmentManager manager,
long folder, boolean server, String query) {
long account, long folder, boolean server, String query) {
if (server && !ActivityBilling.isPro(context)) {
context.startActivity(new Intent(context, ActivityBilling.class));
return;
@ -4735,6 +4752,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
manager.popBackStack("search", FragmentManager.POP_BACK_STACK_INCLUSIVE);
Bundle args = new Bundle();
args.putLong("account", account);
args.putLong("folder", folder);
args.putBoolean("server", server);
args.putString("query", query);

@ -604,6 +604,7 @@
<string name="title_no_folder">Folder does not exist</string>
<string name="title_no_format">The originally received message will be included</string>
<string name="title_no_image">Image could not be decoded</string>
<string name="title_no_search">Search on server is not available for this account</string>
<string name="title_unused_inline">Unused inline images will be removed on save/send</string>
<string name="title_accross_remark">Messages moved across accounts will be downloaded again resulting in extra data usage</string>
<string name="title_raw_saved">Raw message saved</string>
@ -1071,6 +1072,7 @@
<item>Extra large</item>
</string-array>
<!-- https://en.wikipedia.org/wiki/Display_resolution -->
<integer-array name="resizeValues" translatable="false">
<item>1080</item>
<item>1440</item>

Loading…
Cancel
Save