Skip to content

Commit

Permalink
Merge branch 'release/2.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	example/build.gradle
#	gradle.properties
#	library/build.gradle
  • Loading branch information
rpano committed Nov 13, 2018
2 parents 66e1c24 + abd2d33 commit db3313d
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 403 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -13,6 +16,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
}
}
15 changes: 7 additions & 8 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "23.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
applicationId "world.rafoufoun.providerdelegate.example"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
targetSdkVersion 28
versionCode 2
versionName "2.0"
}
buildTypes {
release {
Expand All @@ -20,7 +20,6 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.0.0'
compile project(':library')
implementation project(':library')
implementation 'com.android.support:appcompat-v7:28.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@


public class ExampleDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "example";
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "example";
private static final int DATABASE_VERSION = 1;

public ExampleDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public ExampleDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable._ID + "' INTEGER PRIMARY KEY AUTOINCREMENT, '" + ExampleTable.TITLE + "' TEXT NOT NULL );");
db.execSQL("INSERT INTO " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable.TITLE + "' ) VALUES ('Hello World');");
db.execSQL("INSERT INTO " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable.TITLE + "' ) VALUES ('Bonjour');");
db.execSQL("INSERT INTO " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable.TITLE + "' ) VALUES ('Hallo');");
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable._ID + "' INTEGER PRIMARY KEY AUTOINCREMENT, '" + ExampleTable.TITLE + "' TEXT NOT NULL );");
db.execSQL("INSERT INTO " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable.TITLE + "' ) VALUES ('Hello World');");
db.execSQL("INSERT INTO " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable.TITLE + "' ) VALUES ('Bonjour');");
db.execSQL("INSERT INTO " + ExampleTable.TABLE_NAME + " ( '" + ExampleTable.TITLE + "' ) VALUES ('Hallo');");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.provider.BaseColumns;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import world.rafoufoun.providerdelegate.ProviderDelegate;
Expand All @@ -17,24 +18,26 @@ public class ExampleDelegate extends ProviderDelegate {

private static final String TAG = "ExampleDelegate";

public ExampleDelegate(String authority) {
super(authority);
public ExampleDelegate() {
super();
}

@Override
protected void initUriMatcher(String authority) {
uriMatcher.addURI(authority, ExampleTable.TABLE_NAME, ConstantProviderDelegate.EXAMPLE);
uriMatcher.addURI(authority, ExampleTable.TABLE_NAME + ConstantProviderDelegate.SLASH + ConstantProviderDelegate.STAR, ConstantProviderDelegate.EXAMPLE_ITEM);
public void initUriMatcher(@NonNull String authority) {
getUriMatcher().addURI(authority, ExampleTable.TABLE_NAME, ConstantProviderDelegate.EXAMPLE);
getUriMatcher().addURI(authority, ExampleTable.TABLE_NAME + ConstantProviderDelegate.SLASH + ConstantProviderDelegate.STAR, ConstantProviderDelegate.EXAMPLE_ITEM);
}

@NonNull
@Override
public String getTable() {
return ExampleTable.TABLE_NAME;
}

@NonNull
@Override
public String getType(Uri uri) {
final int match = uriMatcher.match(uri);
public String getType(@NonNull Uri uri) {
final int match = getUriMatcher().match(uri);
switch (match) {
case ConstantProviderDelegate.EXAMPLE:
return ExampleTable.CONTENT_TYPE;
Expand All @@ -45,13 +48,14 @@ public String getType(Uri uri) {
}
}

public Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
@NonNull
public Uri insert(@NonNull SQLiteDatabase db, @NonNull Uri uri, ContentValues values) {
long itemId = db.insert(ExampleTable.TABLE_NAME, null, values);
return ExampleTable.buildItemUri((int) itemId);
}

public int delete(SQLiteDatabase db, Uri uri, String selection, String[] selectionArgs) {
final int match = uriMatcher.match(uri);
public int delete(@NonNull SQLiteDatabase db, @NonNull Uri uri, String selection, String[] selectionArgs) {
final int match = getUriMatcher().match(uri);
if (TextUtils.isEmpty(selection)) {
selection = "";
}
Expand All @@ -65,8 +69,8 @@ public int delete(SQLiteDatabase db, Uri uri, String selection, String[] selecti
}
}

public int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
final int match = uriMatcher.match(uri);
public int update(@NonNull SQLiteDatabase db, @NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
final int match = getUriMatcher().match(uri);
if (TextUtils.isEmpty(selection)) {
selection = "";
}
Expand All @@ -80,8 +84,9 @@ public int update(SQLiteDatabase db, Uri uri, ContentValues values, String selec
}
}

public Cursor query(SQLiteDatabase db, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
final int match = uriMatcher.match(uri);
@NonNull
public Cursor query(@NonNull SQLiteDatabase db, @NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
final int match = getUriMatcher().match(uri);
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
switch (match) {
case ConstantProviderDelegate.EXAMPLE_ITEM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;

import world.rafoufoun.providerdelegate.DelegationProvider;
import world.rafoufoun.providerdelegate.ProviderDelegateManager;
Expand All @@ -19,20 +20,23 @@ public void initializeProvider() {
}

@Override
protected void addProviderDelegate(ProviderDelegateManager delegateManager) {
delegateManager.addDelegate(new ExampleDelegate(getAuthority()));
protected void addProviderDelegate(@NonNull ProviderDelegateManager delegateManager) {
delegateManager.addDelegate(new ExampleDelegate());
}

@NonNull
@Override
protected String getAuthority() {
return Contract.AUTHORITY;
}

@NonNull
@Override
protected SQLiteDatabase getWritableDatabase() {
return database.getWritableDatabase();
}

@NonNull
@Override
protected SQLiteDatabase getReadableDatabase() {
return database.getReadableDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,38 @@
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;


import world.rafoufoun.providerdelegate.example.R;
import world.rafoufoun.providerdelegate.example.database.table.ExampleTable;

public class ExampleActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
TextView titleItem =(TextView) findViewById(R.id.textView);
TextView countItem =(TextView) findViewById(R.id.textView2);

Cursor cursorTitle = this.getContentResolver().query(ExampleTable.buildItemUri(1),new String[]{ExampleTable.TITLE},null,null,null);

if(cursorTitle!=null) {
if (cursorTitle.moveToFirst()){
titleItem.setText(String.format(getString(R.string.title_item), cursorTitle.getString(0)));
}else{
titleItem.setText(getString(R.string.error));
}
cursorTitle.close();
}

Cursor cursorCount = this.getContentResolver().query(ExampleTable.buildUri(),new String[]{"count('"+ExampleTable.TABLE_NAME+"') AS count"},null,null,null);

if(cursorCount!=null) {
if (cursorCount.moveToFirst()) {
countItem.setText(String.format(getString(R.string.num_item), cursorCount.getInt(0)));
} else {
countItem.setText(getString(R.string.error));
}
cursorCount.close();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
TextView titleItem = findViewById(R.id.textView);
TextView countItem = findViewById(R.id.textView2);

Cursor cursorTitle = this.getContentResolver().query(ExampleTable.buildItemUri(1), new String[]{ExampleTable.TITLE}, null, null, null);

if (cursorTitle != null) {
if (cursorTitle.moveToFirst()) {
titleItem.setText(String.format(getString(R.string.title_item), cursorTitle.getString(0)));
} else {
titleItem.setText(getString(R.string.error));
}
cursorTitle.close();
}

Cursor cursorCount = this.getContentResolver().query(ExampleTable.buildUri(), new String[]{"count('" + ExampleTable.TABLE_NAME + "') AS count"}, null, null, null);

if (cursorCount != null) {
if (cursorCount.moveToFirst()) {
countItem.setText(String.format(getString(R.string.num_item), cursorCount.getInt(0)));
} else {
countItem.setText(getString(R.string.error));
}
cursorCount.close();
}
}
}
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
VERSION_NAME=1.0.1
VERSION_CODE=5
VERSION_NAME=2.0.0
VERSION_CODE=6
GROUP=com.gitlab.rafoufoun

POM_DESCRIPTION=Delegate pattern applied to ContentProvider for Android applications.
POM_URL=https://gitlab.com/rafoufoun/ProviderDelegate
POM_SCM_URL=https://gitlab.com/rafoufoun/ProviderDelegate
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
21 changes: 13 additions & 8 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
apply plugin: 'com.android.library'

apply plugin: 'kotlin-android'

android {
compileSdkVersion 24
buildToolsVersion "23.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 9
targetSdkVersion 24
targetSdkVersion 28
versionCode 5
versionName "1.0.1"
versionName "1.0.0"
}
buildTypes {
release {
Expand All @@ -19,10 +21,13 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:appcompat-v7:24.0.0'
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}

apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
repositories {
mavenCentral()
}
Loading

0 comments on commit db3313d

Please sign in to comment.