Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SearchRecents.java « search « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 197006f79f94f0c7edd4833453aad8c0e22e540d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.mapswithme.maps.search;

import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Pair;
import com.mapswithme.util.Language;

import java.util.ArrayList;
import java.util.List;

public final class SearchRecents
{
  private static final List<String> sRecents = new ArrayList<>();

  private SearchRecents() {}

  public static void refresh()
  {
    final List<Pair<String, String>> pairs = new ArrayList<>();
    nativeGetList(pairs);
    sRecents.clear();

    for (Pair<String, String> pair : pairs)
      sRecents.add(pair.second);
  }

  public static int getSize()
  {
    return sRecents.size();
  }

  public static String get(int position)
  {
    return sRecents.get(position);
  }

  public static boolean add(@NonNull String query)
  {
    if (TextUtils.isEmpty(query) || sRecents.contains(query))
      return false;

    nativeAdd(Language.getKeyboardLocale(), query);
    refresh();
    return true;
  }

  public static void clear()
  {
    nativeClear();
    sRecents.clear();
  }

  private static native void nativeGetList(List<Pair<String, String>> result);
  private static native void nativeAdd(String locale, String query);
  private static native void nativeClear();
}