Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ android {

dependencies {
implementation("androidx.appcompat:appcompat:1.7.1")
implementation("androidx.preference:preference:1.2.1")
implementation("androidx.palette:palette:1.0.0")
implementation("androidx.recyclerview:recyclerview:1.4.0")
implementation("com.github.bumptech.glide:glide:4.16.0")
Expand Down
150 changes: 147 additions & 3 deletions gradle/verification-metadata.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/com/android/messaging/datamodel/BoundCursorLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package com.android.messaging.datamodel;

import android.content.Context;
import android.content.CursorLoader;
import android.net.Uri;

import androidx.loader.content.CursorLoader;

/**
* Extension to basic cursor loader that has an attached binding id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package com.android.messaging.datamodel.data;

import android.app.LoaderManager;
import android.content.Context;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;

import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;

import com.android.messaging.datamodel.BoundCursorLoader;
import com.android.messaging.datamodel.DatabaseHelper.ParticipantColumns;
import com.android.messaging.datamodel.MessagingContentProvider;
Expand All @@ -33,8 +34,7 @@
/**
* Services data needs for BlockedParticipantsFragment
*/
public class BlockedParticipantsData extends BindableData implements
LoaderManager.LoaderCallbacks<Cursor> {
public class BlockedParticipantsData extends BindableData {
public interface BlockedParticipantsDataListener {
public void onBlockedParticipantsCursorUpdated(final Cursor cursor);
}
Expand All @@ -50,42 +50,44 @@ public BlockedParticipantsData(final Context context,
mListener = listener;
}

@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
Assert.isTrue(id == BLOCKED_PARTICIPANTS_LOADER);
final String bindingId = args.getString(BINDING_ID);
// Check if data still bound to the requesting ui element
if (isBound(bindingId)) {
final Uri uri = MessagingContentProvider.PARTICIPANTS_URI;
return new BoundCursorLoader(bindingId, mContext, uri,
ParticipantData.ParticipantsQuery.PROJECTION,
ParticipantColumns.BLOCKED + "=1", null, null);
private class BlockedParticipantsLoaderCallbacks extends CursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
Assert.isTrue(id == BLOCKED_PARTICIPANTS_LOADER);
final String bindingId = args.getString(BINDING_ID);
// Check if data still bound to the requesting ui element
if (isBound(bindingId)) {
final Uri uri = MessagingContentProvider.PARTICIPANTS_URI;
return new BoundCursorLoader(bindingId, mContext, uri,
ParticipantData.ParticipantsQuery.PROJECTION,
ParticipantColumns.BLOCKED + "=1", null, null);
}
return null;
}
return null;
}

@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) {
Assert.isTrue(loader.getId() == BLOCKED_PARTICIPANTS_LOADER);
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
Assert.isTrue(isBound(cursorLoader.getBindingId()));
mListener.onBlockedParticipantsCursorUpdated(cursor);
}
@Override
public void onLoadFinish(final Loader<Cursor> loader, final Cursor cursor) {
Assert.isTrue(loader.getId() == BLOCKED_PARTICIPANTS_LOADER);
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
Assert.isTrue(isBound(cursorLoader.getBindingId()));
mListener.onBlockedParticipantsCursorUpdated(cursor);
}

@Override
public void onLoaderReset(final Loader<Cursor> loader) {
Assert.isTrue(loader.getId() == BLOCKED_PARTICIPANTS_LOADER);
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
Assert.isTrue(isBound(cursorLoader.getBindingId()));
mListener.onBlockedParticipantsCursorUpdated(null);
@Override
public void onLoaderReset(final Loader<Cursor> loader) {
Assert.isTrue(loader.getId() == BLOCKED_PARTICIPANTS_LOADER);
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
Assert.isTrue(isBound(cursorLoader.getBindingId()));
mListener.onBlockedParticipantsCursorUpdated(null);
}
}

public void init(final LoaderManager loaderManager,
final BindingBase<BlockedParticipantsData> binding) {
final Bundle args = new Bundle();
args.putString(BINDING_ID, binding.getBindingId());
mLoaderManager = loaderManager;
mLoaderManager.initLoader(BLOCKED_PARTICIPANTS_LOADER, args, this);
mLoaderManager.initLoader(BLOCKED_PARTICIPANTS_LOADER, args, new BlockedParticipantsLoaderCallbacks());
}

@Override
Expand Down
177 changes: 90 additions & 87 deletions src/com/android/messaging/datamodel/data/ContactPickerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

package com.android.messaging.datamodel.data;

import android.app.LoaderManager;
import android.content.Context;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;

import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;

import com.android.messaging.datamodel.BoundCursorLoader;
import com.android.messaging.datamodel.FrequentContactsCursorBuilder;
import com.android.messaging.datamodel.MessagingContentProvider;
Expand All @@ -37,8 +38,7 @@
* The caller is responsible for ensuring that the app has READ_CONTACTS permission (see
* {@link ContactUtil#hasReadContactsPermission()}) before instantiating this class.
*/
public class ContactPickerData extends BindableData implements
LoaderManager.LoaderCallbacks<Cursor> {
public class ContactPickerData extends BindableData {
public interface ContactPickerDataListener {
void onAllContactsCursorUpdated(Cursor data);
void onFrequentContactsCursorUpdated(Cursor data);
Expand All @@ -61,95 +61,97 @@ public ContactPickerData(final Context context, final ContactPickerDataListener
private static final int FREQUENT_CONTACTS_LOADER = 2;
private static final int PARTICIPANT_LOADER = 3;

@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
final String bindingId = args.getString(BINDING_ID);
// Check if data still bound to the requesting ui element
if (isBound(bindingId)) {
switch (id) {
case ALL_CONTACTS_LOADER:
return ContactUtil.getPhones(mContext)
.createBoundCursorLoader(bindingId);
case FREQUENT_CONTACTS_LOADER:
return ContactUtil.getFrequentContacts(mContext)
.createBoundCursorLoader(bindingId);
case PARTICIPANT_LOADER:
return new BoundCursorLoader(bindingId, mContext,
MessagingContentProvider.PARTICIPANTS_URI,
ParticipantData.ParticipantsQuery.PROJECTION, null, null, null);
default:
Assert.fail("Unknown loader id for contact picker!");
break;
private class ContactPickerLoaderCallbacks extends CursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
final String bindingId = args.getString(BINDING_ID);
// Check if data still bound to the requesting ui element
if (isBound(bindingId)) {
switch (id) {
case ALL_CONTACTS_LOADER:
return ContactUtil.getPhones(mContext)
.createBoundCursorLoader(bindingId);
case FREQUENT_CONTACTS_LOADER:
return ContactUtil.getFrequentContacts(mContext)
.createBoundCursorLoader(bindingId);
case PARTICIPANT_LOADER:
return new BoundCursorLoader(bindingId, mContext,
MessagingContentProvider.PARTICIPANTS_URI,
ParticipantData.ParticipantsQuery.PROJECTION, null, null, null);
default:
Assert.fail("Unknown loader id for contact picker!");
break;
}
} else {
LogUtil.w(LogUtil.BUGLE_TAG, "Loader created after unbinding the contacts list");
}
} else {
LogUtil.w(LogUtil.BUGLE_TAG, "Loader created after unbinding the contacts list");
return null;
}
return null;
}

/**
* {@inheritDoc}
*/
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
if (isBound(cursorLoader.getBindingId())) {
switch (loader.getId()) {
case ALL_CONTACTS_LOADER:
mListener.onAllContactsCursorUpdated(data);
mFrequentContactsCursorBuilder.setAllContacts(data);
break;
case FREQUENT_CONTACTS_LOADER:
mFrequentContactsCursorBuilder.setFrequents(data);
break;
case PARTICIPANT_LOADER:
mListener.onContactCustomColorLoaded(this);
break;
default:
Assert.fail("Unknown loader id for contact picker!");
break;
}
/**
* {@inheritDoc}
*/
@Override
public void onLoadFinish(final Loader<Cursor> loader, final Cursor data) {
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
if (isBound(cursorLoader.getBindingId())) {
switch (loader.getId()) {
case ALL_CONTACTS_LOADER:
mListener.onAllContactsCursorUpdated(data);
mFrequentContactsCursorBuilder.setAllContacts(data);
break;
case FREQUENT_CONTACTS_LOADER:
mFrequentContactsCursorBuilder.setFrequents(data);
break;
case PARTICIPANT_LOADER:
mListener.onContactCustomColorLoaded(ContactPickerData.this);
break;
default:
Assert.fail("Unknown loader id for contact picker!");
break;
}

if (loader.getId() != PARTICIPANT_LOADER) {
// The frequent contacts cursor to be used in the UI depends on results from both
// all contacts and frequent contacts loader, and we don't know which will finish
// first. Therefore, try to build the cursor and notify the listener if it's
// successfully built.
final Cursor frequentContactsCursor = mFrequentContactsCursorBuilder.build();
if (frequentContactsCursor != null) {
mListener.onFrequentContactsCursorUpdated(frequentContactsCursor);
if (loader.getId() != PARTICIPANT_LOADER) {
// The frequent contacts cursor to be used in the UI depends on results from both
// all contacts and frequent contacts loader, and we don't know which will finish
// first. Therefore, try to build the cursor and notify the listener if it's
// successfully built.
final Cursor frequentContactsCursor = mFrequentContactsCursorBuilder.build();
if (frequentContactsCursor != null) {
mListener.onFrequentContactsCursorUpdated(frequentContactsCursor);
}
}
} else {
LogUtil.w(LogUtil.BUGLE_TAG, "Loader finished after unbinding the contacts list");
}
} else {
LogUtil.w(LogUtil.BUGLE_TAG, "Loader finished after unbinding the contacts list");
}
}

/**
* {@inheritDoc}
*/
@Override
public void onLoaderReset(final Loader<Cursor> loader) {
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
if (isBound(cursorLoader.getBindingId())) {
switch (loader.getId()) {
case ALL_CONTACTS_LOADER:
mListener.onAllContactsCursorUpdated(null);
mFrequentContactsCursorBuilder.setAllContacts(null);
break;
case FREQUENT_CONTACTS_LOADER:
mListener.onFrequentContactsCursorUpdated(null);
mFrequentContactsCursorBuilder.setFrequents(null);
break;
case PARTICIPANT_LOADER:
mListener.onContactCustomColorLoaded(this);
break;
default:
Assert.fail("Unknown loader id for contact picker!");
break;
/**
* {@inheritDoc}
*/
@Override
public void onLoaderReset(final Loader<Cursor> loader) {
final BoundCursorLoader cursorLoader = (BoundCursorLoader) loader;
if (isBound(cursorLoader.getBindingId())) {
switch (loader.getId()) {
case ALL_CONTACTS_LOADER:
mListener.onAllContactsCursorUpdated(null);
mFrequentContactsCursorBuilder.setAllContacts(null);
break;
case FREQUENT_CONTACTS_LOADER:
mListener.onFrequentContactsCursorUpdated(null);
mFrequentContactsCursorBuilder.setFrequents(null);
break;
case PARTICIPANT_LOADER:
mListener.onContactCustomColorLoaded(ContactPickerData.this);
break;
default:
Assert.fail("Unknown loader id for contact picker!");
break;
}
} else {
LogUtil.w(LogUtil.BUGLE_TAG, "Loader reset after unbinding the contacts list");
}
} else {
LogUtil.w(LogUtil.BUGLE_TAG, "Loader reset after unbinding the contacts list");
}
}

Expand All @@ -158,9 +160,10 @@ public void init(final LoaderManager loaderManager,
final Bundle args = new Bundle();
args.putString(BINDING_ID, binding.getBindingId());
mLoaderManager = loaderManager;
mLoaderManager.initLoader(ALL_CONTACTS_LOADER, args, this);
mLoaderManager.initLoader(FREQUENT_CONTACTS_LOADER, args, this);
mLoaderManager.initLoader(PARTICIPANT_LOADER, args, this);
var loaderCallbacks = new ContactPickerLoaderCallbacks();
mLoaderManager.initLoader(ALL_CONTACTS_LOADER, args, loaderCallbacks);
mLoaderManager.initLoader(FREQUENT_CONTACTS_LOADER, args, loaderCallbacks);
mLoaderManager.initLoader(PARTICIPANT_LOADER, args, loaderCallbacks);
}

@Override
Expand Down
Loading