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();
}
}
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;
}
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);
}
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);
}
}
});
}
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;
}
Aggregations