Working solution reached for scrolling to and expanding alarm when PendingIntent fired from status bar
This commit is contained in:
parent
5bf0ccc3f4
commit
862521ff54
@ -161,6 +161,29 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
Log.d(TAG, "Got new intent " + intent);
|
||||
// TODO: Make actual action const
|
||||
// if ("RecyclerViewFragment.ACTION_SCROLL_TO_STABLE_ID".equals(intent.getAction())) {
|
||||
// TODO: Get int extra for the page of the exact RVFrag this scrolling should be applied to.
|
||||
// Requires making RVFrag.EXTRA_SCROLL_TARGET_PAGE.
|
||||
final int targetPage = PAGE_ALARMS;
|
||||
if (targetPage >= 0 && targetPage <= mSectionsPagerAdapter.getCount() - 1) {
|
||||
mViewPager.setCurrentItem(targetPage, true/*smoothScroll*/);
|
||||
// TODO: Make generic extra RVFrag.EXTRA_SCROLL_TO_STABLE_ID
|
||||
final long scrollToStableId = intent.getLongExtra(AlarmsFragment.EXTRA_SCROLL_TO_ALARM_ID, -1);
|
||||
if (scrollToStableId != -1) {
|
||||
RecyclerViewFragment rvFrag = (RecyclerViewFragment)
|
||||
mSectionsPagerAdapter.getFragment(targetPage);
|
||||
Log.d(TAG, "Scrolling to stable id");
|
||||
rvFrag.performScrollToStableId(scrollToStableId);
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode != RESULT_OK)
|
||||
|
||||
@ -79,6 +79,9 @@ public final class AlarmController {
|
||||
final PendingIntent alarmIntent = alarmIntent(alarm, false);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
Intent viewAlarm = new Intent(mAppContext, MainActivity.class);
|
||||
// TODO: Use RVFrag.ACTION_......
|
||||
viewAlarm.setAction("viewAlarm");
|
||||
// TODO: Pass int extra for the alarms page to RVFrag.EXTRA_SCROLL_TARGET_PAGE.
|
||||
viewAlarm.putExtra(AlarmsFragment.EXTRA_SCROLL_TO_ALARM_ID, alarm.getId());
|
||||
PendingIntent showIntent = PendingIntent.getActivity(mAppContext,
|
||||
alarm.getIntId(), viewAlarm, FLAG_CANCEL_CURRENT);
|
||||
|
||||
@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -47,10 +48,10 @@ public class AlarmsFragment extends RecyclerViewFragment<Alarm, BaseAlarmViewHol
|
||||
getFragmentManager(), getActivity(), this);
|
||||
mTimePickerDialogController.tryRestoreCallback(makeTimePickerDialogTag());
|
||||
|
||||
long scrollToStableId = getActivity().getIntent().getLongExtra(EXTRA_SCROLL_TO_ALARM_ID, -1);
|
||||
if (scrollToStableId != -1) {
|
||||
setScrollToStableId(scrollToStableId);
|
||||
}
|
||||
// long scrollToStableId = getActivity().getIntent().getLongExtra(EXTRA_SCROLL_TO_ALARM_ID, -1);
|
||||
// if (scrollToStableId != -1) {
|
||||
// setScrollToStableId(scrollToStableId);
|
||||
// }
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -63,9 +64,28 @@ public class AlarmsFragment extends RecyclerViewFragment<Alarm, BaseAlarmViewHol
|
||||
return super.onCreateView(inflater, container, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Log.d(TAG, "onPause()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Log.d(TAG, "onStop()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Log.d(TAG, "onStart()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Log.d(TAG, "onResume()");
|
||||
// Show the pending Snackbar, if any, that was prepared for us
|
||||
// by another app component.
|
||||
DelayedSnackbarHandler.makeAndShow(mSnackbarAnchor);
|
||||
@ -79,6 +99,7 @@ public class AlarmsFragment extends RecyclerViewFragment<Alarm, BaseAlarmViewHol
|
||||
@Override
|
||||
public void onLoadFinished(Loader<AlarmCursor> loader, AlarmCursor data) {
|
||||
super.onLoadFinished(loader, data);
|
||||
Log.d(TAG, "onLoadFinished()");
|
||||
// TODO: If this was a content change due to an update, verify that
|
||||
// we scroll to the updated alarm if its sort order changes.
|
||||
|
||||
|
||||
@ -168,7 +168,7 @@ public abstract class RecyclerViewFragment<
|
||||
mList.smoothScrollToPosition(position);
|
||||
}
|
||||
|
||||
protected final void performScrollToStableId(long stableId) {
|
||||
public final void performScrollToStableId(long stableId) {
|
||||
if (stableId != RecyclerView.NO_ID) {
|
||||
int position = -1;
|
||||
for (int i = 0; i < mAdapter.getItemCount(); i++) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user