Search in sources :

Example 1 with Library

use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.

the class LibraryListActivity method showListStates.

public void showListStates(String country) {
    LibraryListFragment fragment = new LibraryListFragment();
    Bundle args = new Bundle();
    args.putInt("level", LEVEL_STATE);
    args.putString("country", country);
    fragment.setArguments(args);
    Set<String> data = new HashSet<>();
    for (Library lib : libraries) {
        if (country.equals(lib.getCountry()) && !data.contains(lib.getState())) {
            data.add(lib.getState());
        }
    }
    List<String> list = new ArrayList<>(data);
    if (data.size() == 1) {
        showListCities(country, list.get(0));
    }
    Collator deCollator = Collator.getInstance(Locale.GERMAN);
    deCollator.setStrength(Collator.TERTIARY);
    Collections.sort(list, deCollator);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.listitem_simple, R.id.txtText, list);
    fragment.setListAdapter(adapter);
    if (findViewById(R.id.llFragments) != null) {
        fragment2 = fragment;
        getSupportFragmentManager().beginTransaction().replace(R.id.container2, fragment2).commit();
        if (fragment3 != null) {
            getSupportFragmentManager().beginTransaction().detach(fragment3).commit();
        }
        if (fragment4 != null) {
            getSupportFragmentManager().beginTransaction().detach(fragment4).commit();
        }
    } else if (data.size() > 1) {
        this.fragment = fragment;
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit();
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Library(de.geeksfactory.opacclient.objects.Library) ArrayAdapter(android.widget.ArrayAdapter) HashSet(java.util.HashSet) Collator(java.text.Collator)

Example 2 with Library

use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.

the class LibraryListActivity method showListCountries.

public void showListCountries(boolean fade) {
    fragment = new LibraryListFragment();
    Bundle args = new Bundle();
    args.putInt("level", LEVEL_COUNTRY);
    fragment.setArguments(args);
    Set<String> data = new HashSet<>();
    for (Library lib : libraries) {
        if (!data.contains(lib.getCountry())) {
            data.add(lib.getCountry());
        }
    }
    List<String> list = new ArrayList<>(data);
    Collator deCollator = Collator.getInstance(Locale.GERMAN);
    deCollator.setStrength(Collator.TERTIARY);
    Collections.sort(list, deCollator);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.listitem_simple, R.id.txtText, list.toArray(new String[list.size()]));
    fragment.setListAdapter(adapter);
    if (findViewById(R.id.llFragments) != null) {
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
        if (fragment2 != null) {
            getSupportFragmentManager().beginTransaction().detach(fragment2).commit();
        }
        if (fragment3 != null) {
            getSupportFragmentManager().beginTransaction().detach(fragment3).commit();
        }
        if (fragment4 != null) {
            getSupportFragmentManager().beginTransaction().detach(fragment4).commit();
        }
    } else {
        if (fade) {
            getSupportFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).replace(R.id.container, fragment).commit();
        } else {
            getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
        }
    }
    list_rendered = true;
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Library(de.geeksfactory.opacclient.objects.Library) ArrayAdapter(android.widget.ArrayAdapter) HashSet(java.util.HashSet) Collator(java.text.Collator)

Example 3 with Library

use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.

the class LibraryListActivity method search.

public void search(String query) {
    if (libraries == null)
        return;
    fragment = new LocatedLibraryListFragment();
    Bundle args = new Bundle();
    args.putInt("level", LEVEL_LIBRARY);
    fragment.setArguments(args);
    Set<LibrarySearchResult> data = new HashSet<>();
    query = query.toLowerCase(Locale.GERMAN);
    for (Library lib : libraries) {
        int rank = 0;
        if (lib.getCity().toLowerCase(Locale.GERMAN).contains(query)) {
            rank += 3;
        }
        if (lib.getTitle().toLowerCase(Locale.GERMAN).contains(query)) {
            rank += 3;
        }
        if (lib.getState().toLowerCase(Locale.GERMAN).contains(query)) {
            rank += 2;
        }
        if (lib.getCountry().toLowerCase(Locale.GERMAN).contains(query)) {
            rank += 1;
        }
        if (rank > 0) {
            data.add(new LibrarySearchResult(lib, rank));
        }
    }
    List<LibrarySearchResult> list = new ArrayList<>(data);
    Collections.sort(list);
    List<Library> libraries = new ArrayList<>();
    for (LibrarySearchResult sr : list) {
        libraries.add(sr.getLibrary());
    }
    LibraryAdapter adapter = new LibraryAdapter(this, R.layout.listitem_library, R.id.tvTitle, libraries);
    fragment.setListAdapter(adapter);
    getSupportFragmentManager().beginTransaction().addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).replace(R.id.container, fragment).commit();
    if (fragment2 != null) {
        getSupportFragmentManager().beginTransaction().detach(fragment2).commit();
    }
    if (fragment3 != null) {
        getSupportFragmentManager().beginTransaction().detach(fragment3).commit();
    }
    if (fragment4 != null) {
        getSupportFragmentManager().beginTransaction().detach(fragment4).commit();
    }
    tvLocateString.setText(R.string.alphabetic_list);
    ivLocationIcon.setImageResource(R.drawable.ic_list_24dp);
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Library(de.geeksfactory.opacclient.objects.Library) HashSet(java.util.HashSet)

Example 4 with Library

use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.

the class LibraryListActivity method showListGeo.

public void showListGeo() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, REQUEST_LOCATION_PERMISSION);
        return;
    }
    final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    // no GPS
    criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    final String provider = locationManager.getBestProvider(criteria, true);
    if (provider == null) {
        Toast.makeText(this, R.string.geolocate_not_available, Toast.LENGTH_LONG).show();
        tvLocateString.setText(R.string.geolocate);
        ivLocationIcon.setImageResource(R.drawable.ic_locate_24dp);
        return;
    }
    if (libraries == null) {
        return;
    }
    locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onLocationChanged(Location location) {
            if (!visible) {
                return;
            }
            fragment = new LocatedLibraryListFragment();
            Bundle args = new Bundle();
            args.putInt("level", LEVEL_LIBRARY);
            fragment.setArguments(args);
            if (location != null && libraries != null) {
                double lat = location.getLatitude();
                double lon = location.getLongitude();
                // Calculate distances
                List<Library> distancedlibs = new ArrayList<>();
                for (Library lib : libraries) {
                    float[] result = new float[1];
                    double[] geo = lib.getGeo();
                    if (geo == null) {
                        continue;
                    }
                    Location.distanceBetween(lat, lon, geo[0], geo[1], result);
                    lib.setGeo_distance(result[0]);
                    distancedlibs.add(lib);
                }
                Collections.sort(distancedlibs, new DistanceComparator());
                if (distancedlibs.size() > 20) {
                    distancedlibs = distancedlibs.subList(0, 20);
                }
                LibraryAdapter adapter = new LibraryAdapter(LibraryListActivity.this, R.layout.listitem_library, R.id.tvTitle, distancedlibs);
                fragment.setListAdapter(adapter);
                getSupportFragmentManager().beginTransaction().addToBackStack(null).setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).replace(R.id.container, fragment).commit();
                if (fragment2 != null) {
                    getSupportFragmentManager().beginTransaction().detach(fragment2).commit();
                }
                if (fragment3 != null) {
                    getSupportFragmentManager().beginTransaction().detach(fragment3).commit();
                }
                if (fragment4 != null) {
                    getSupportFragmentManager().beginTransaction().detach(fragment4).commit();
                }
                tvLocateString.setText(R.string.alphabetic_list);
                ivLocationIcon.setImageResource(R.drawable.ic_list_24dp);
            }
        }
    });
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) Criteria(android.location.Criteria) LocationListener(android.location.LocationListener) List(java.util.List) ArrayList(java.util.ArrayList) Library(de.geeksfactory.opacclient.objects.Library) Location(android.location.Location)

Example 5 with Library

use of de.geeksfactory.opacclient.objects.Library in project opacclient by opacapp.

the class AccountListAdapter method getView.

@SuppressWarnings("deprecation")
@Override
public View getView(int position, View contentView, ViewGroup viewGroup) {
    View view;
    // position always 0-7
    if (objects.get(position) == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_account, viewGroup, false);
        return view;
    }
    Account item = objects.get(position);
    if (contentView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_account, viewGroup, false);
    } else {
        view = contentView;
    }
    if (((OpacClient) ((Activity) context).getApplication()).getAccount().getId() == item.getId() && highlight) {
        view.findViewById(R.id.rlItem).setBackgroundColor(context.getResources().getColor(R.color.accent_red));
    } else {
        // should be replaced by setBackground which is not available before API level 16
        view.findViewById(R.id.rlItem).setBackgroundDrawable(null);
    }
    Library lib;
    try {
        lib = ((OpacClient) ((Activity) context).getApplication()).getLibrary(item.getLibrary());
        TextView tvCity = (TextView) view.findViewById(R.id.tvCity);
        if (lib.getTitle() != null && !lib.getTitle().equals("null")) {
            tvCity.setText(lib.getCity() + "\n" + lib.getTitle());
        } else {
            tvCity.setText(lib.getCity());
        }
    } catch (IOException | JSONException e) {
        e.printStackTrace();
    }
    TextView tvName = (TextView) view.findViewById(R.id.tvName);
    if (item.getName() != null) {
        tvName.setText(item.getName());
    }
    TextView tvLabel = (TextView) view.findViewById(R.id.tvLabel);
    if (item.getLabel() != null) {
        tvLabel.setText(item.getLabel());
    }
    return view;
}
Also used : Account(de.geeksfactory.opacclient.objects.Account) LayoutInflater(android.view.LayoutInflater) Activity(android.app.Activity) JSONException(org.json.JSONException) TextView(android.widget.TextView) Library(de.geeksfactory.opacclient.objects.Library) IOException(java.io.IOException) TextView(android.widget.TextView) View(android.view.View)

Aggregations

Library (de.geeksfactory.opacclient.objects.Library)15 ArrayList (java.util.ArrayList)8 Bundle (android.os.Bundle)6 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 JSONException (org.json.JSONException)6 OpacClient (de.geeksfactory.opacclient.OpacClient)3 Account (de.geeksfactory.opacclient.objects.Account)3 Collator (java.text.Collator)3 List (java.util.List)3 ArrayAdapter (android.widget.ArrayAdapter)2 OpacApi (de.geeksfactory.opacclient.apis.OpacApi)2 JSONObject (org.json.JSONObject)2 Before (org.junit.Before)2 Activity (android.app.Activity)1 SharedPreferences (android.content.SharedPreferences)1 AssetManager (android.content.res.AssetManager)1 Criteria (android.location.Criteria)1 Location (android.location.Location)1 LocationListener (android.location.LocationListener)1