-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabor Keszthelyi
committed
Dec 20, 2017
1 parent
62e6af8
commit e9f8cc6
Showing
33 changed files
with
1,179 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
opentasks/src/main/java/org/dmfs/tasks/data/ContentProviderClientDisposable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.data; | ||
|
||
import android.content.ContentProviderClient; | ||
import android.os.Build; | ||
|
||
import org.dmfs.tasks.utils.rxjava.disposable.DelegatingDisposable; | ||
|
||
import io.reactivex.disposables.Disposable; | ||
import io.reactivex.disposables.Disposables; | ||
|
||
|
||
/** | ||
* {@link Disposable} for {@link ContentProviderClient}. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public final class ContentProviderClientDisposable extends DelegatingDisposable | ||
{ | ||
public ContentProviderClientDisposable(final ContentProviderClient client) | ||
{ | ||
super(Disposables.fromRunnable(new Runnable() | ||
{ | ||
@Override | ||
public void run() | ||
{ | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) | ||
{ | ||
client.close(); | ||
} | ||
else | ||
{ | ||
client.release(); | ||
} | ||
} | ||
})); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
opentasks/src/main/java/org/dmfs/tasks/data/ContentProviderClientSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.data; | ||
|
||
import android.content.ContentProviderClient; | ||
import android.content.Context; | ||
import android.net.Uri; | ||
|
||
import org.dmfs.provider.tasks.AuthorityUtil; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
import org.dmfs.tasks.utils.rxjava.singlesource.DelegatingSingleSource; | ||
|
||
import io.reactivex.Single; | ||
import io.reactivex.SingleEmitter; | ||
import io.reactivex.SingleOnSubscribe; | ||
import io.reactivex.SingleSource; | ||
import io.reactivex.annotations.NonNull; | ||
|
||
|
||
/** | ||
* {@link SingleSource} for accessing a {@link ContentProviderClient} for the given {@link Uri}. | ||
* Takes care of closing the client upon disposal. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public class ContentProviderClientSource extends DelegatingSingleSource<ContentProviderClient> | ||
{ | ||
|
||
public ContentProviderClientSource(final Context context, final Uri uri) | ||
{ | ||
super(Single.create(new SingleOnSubscribe<ContentProviderClient>() | ||
{ | ||
@Override | ||
public void subscribe(@NonNull SingleEmitter<ContentProviderClient> emitter) throws Exception | ||
{ | ||
ContentProviderClient client = context.getContentResolver().acquireContentProviderClient(uri); | ||
emitter.setDisposable(new ContentProviderClientDisposable(client)); | ||
emitter.onSuccess(client); | ||
} | ||
})); | ||
} | ||
|
||
|
||
public ContentProviderClientSource(Context context) | ||
{ | ||
this(context, TaskContract.getContentUri(AuthorityUtil.taskAuthority(context))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2017 dmfs GmbH | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.dmfs.tasks.data; | ||
|
||
import android.content.ContentProviderClient; | ||
import android.content.Context; | ||
|
||
import org.dmfs.android.contentpal.RowSet; | ||
|
||
|
||
/** | ||
* Represents a ContentProvider query resulting in ContentPal's {@link RowSet}. | ||
* | ||
* @author Gabor Keszthelyi | ||
*/ | ||
public interface CpQuery<T> | ||
{ | ||
|
||
/** | ||
* Returns the {@link RowSet} that represent the result of this query. | ||
*/ | ||
RowSet<T> rowSet(ContentProviderClient client, Context appContext); | ||
|
||
} |
Oops, something went wrong.