package eu.nerro.wolappla.provider;

import android.app.Activity;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;

import static eu.nerro.wolappla.util.LogUtils.makeLogTag;

/**
 * Provider that stores {@link DeviceContract} data. Data is inserted
 * and queried by various {@link Activity} instances.
 */
public class DeviceProvider extends ContentProvider {
  private static final String TAG = makeLogTag(DeviceProvider.class);

  private static final UriMatcher sUriMatcher = buildUriMatcher();

  private static final int DEVICES = 100;
  private static final int DEVICES_ID = 101;

  private DeviceDatabase mOpenHelper;

  /**
   * Build and return a {@link UriMatcher} that catches all {@link Uri}
   * variations supported by this {@link ContentProvider}.
   */
  private static UriMatcher buildUriMatcher() {
    final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
    final String authority = DeviceContract.CONTENT_AUTHORITY;

    matcher.addURI(authority, "devices", DEVICES);
    matcher.addURI(authority, "devices/*", DEVICES_ID);

    return matcher;
  }

  @Override
  public boolean onCreate() {
    mOpenHelper = new DeviceDatabase(getContext());
    return true;
  }

  @Override
  public Cursor query(Uri uri, String[] strings, String s, String[] strings2, String s2) {
    return null;
  }

  @Override
  public String getType(Uri uri) {
    return null;
  }

  @Override
  public Uri insert(Uri uri, ContentValues contentValues) {
    return null;
  }

  @Override
  public int delete(Uri uri, String s, String[] strings) {
    return 0;
  }

  @Override
  public int update(Uri uri, ContentValues contentValues, String s, String[] strings) {
    return 0;
  }
}

@@ -229,16 +229,81 @@
 t.Uri;%0A%0A
+import static eu.nerro.wolappla.provider.DeviceContract.Devices;%0A
 import s
@@ -1402,155 +1402,443 @@
 lic 
-Cursor query(Uri uri, String%5B%5D strings, String s, String%5B%5D strings2, String s2) %7B%0A    return null;%0A  %7D%0A%0A  @Override%0A  public String getType(Uri uri
+String getType(Uri uri) %7B%0A    final int match = sUriMatcher.match(uri);%0A    switch (match) %7B%0A      case DEVICES:%0A        return Devices.CONTENT_TYPE;%0A      case DEVICES_ID:%0A        return Devices.CONTENT_ITEM_TYPE;%0A      default:%0A        throw new UnsupportedOperationException(%22Unknown uri: %22 + uri);%0A    %7D%0A  %7D%0A%0A  @Override%0A  public Cursor query(Uri uri, String%5B%5D projection, String selection, String%5B%5D selectionArgs, String sortOrder
 ) %7B%0A

Implement method getType() for device content provider