mirror of https://github.com/tasks/tasks
Add NotificationActivity
Replaces NotificationFragment when opening notificationpull/281/head
parent
5958663658
commit
9211b049e0
@ -1,89 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.reminders;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.todoroo.astrid.activity.AstridActivity;
|
||||
import com.todoroo.astrid.activity.TaskListFragment;
|
||||
|
||||
import org.tasks.Broadcaster;
|
||||
import org.tasks.R;
|
||||
import org.tasks.reminders.SnoozeActivity;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* This activity is launched when a user opens up a notification from the
|
||||
* tray. It launches the appropriate activity based on the passed in parameters.
|
||||
*
|
||||
* @author timsu
|
||||
*
|
||||
*/
|
||||
public class NotificationFragment extends TaskListFragment {
|
||||
|
||||
public static final String TOKEN_ID = "id"; //$NON-NLS-1$
|
||||
|
||||
@Inject Broadcaster broadcaster;
|
||||
|
||||
@Override
|
||||
protected void initializeData() {
|
||||
displayNotificationPopup();
|
||||
super.initializeData();
|
||||
}
|
||||
|
||||
private void displayNotificationPopup() {
|
||||
final String title = extras.getString(Notifications.EXTRAS_TITLE);
|
||||
final long taskId = extras.getLong(TOKEN_ID);
|
||||
final AstridActivity activity = (AstridActivity) getActivity();
|
||||
|
||||
new Dialog(activity, R.style.ReminderDialog) {{
|
||||
setContentView(R.layout.astrid_reminder_view_portrait);
|
||||
findViewById(R.id.speech_bubble_container).setVisibility(View.GONE);
|
||||
|
||||
// set up listeners
|
||||
findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.reminder_snooze).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
dismiss();
|
||||
activity.startActivity(new Intent(activity, SnoozeActivity.class) {{
|
||||
putExtra(SnoozeActivity.EXTRA_TASK_ID, taskId);
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.reminder_complete).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
broadcaster.completeTask(taskId);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.reminder_edit).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
activity.onTaskListItemClicked(taskId);
|
||||
}
|
||||
});
|
||||
|
||||
((TextView) findViewById(R.id.reminder_title)).setText(activity.getString(R.string.rmd_NoA_dlg_title) + " " + title);
|
||||
|
||||
setOwnerActivity(activity);
|
||||
}}.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.tasks.reminders;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import org.tasks.injection.InjectingFragmentActivity;
|
||||
|
||||
public class NotificationActivity extends InjectingFragmentActivity implements DialogInterface.OnDismissListener {
|
||||
|
||||
private static final String FRAG_TAG_NOTIFICATION_FRAGMENT = "frag_tag_notification_fragment";
|
||||
|
||||
public static final String EXTRA_TITLE = "extra_title";
|
||||
public static final String EXTRA_TASK_ID = "extra_task_id";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
FragmentManager supportFragmentManager = getSupportFragmentManager();
|
||||
NotificationDialog fragment = (NotificationDialog) supportFragmentManager.findFragmentByTag(FRAG_TAG_NOTIFICATION_FRAGMENT);
|
||||
if (fragment == null) {
|
||||
Intent intent = getIntent();
|
||||
fragment = new NotificationDialog();
|
||||
fragment.setTitle(intent.getStringExtra(EXTRA_TITLE));
|
||||
fragment.setTaskId(intent.getLongExtra(EXTRA_TASK_ID, 0L));
|
||||
fragment.show(supportFragmentManager, FRAG_TAG_NOTIFICATION_FRAGMENT);
|
||||
}
|
||||
fragment.setOnDismissListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package org.tasks.reminders;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import org.tasks.Broadcaster;
|
||||
import org.tasks.R;
|
||||
import org.tasks.injection.InjectingDialogFragment;
|
||||
import org.tasks.intents.TaskIntents;
|
||||
import org.tasks.notifications.NotificationManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class NotificationDialog extends InjectingDialogFragment {
|
||||
|
||||
@Inject NotificationManager notificationManager;
|
||||
@Inject Broadcaster broadcaster;
|
||||
|
||||
private long taskId;
|
||||
private String title;
|
||||
private DialogInterface.OnDismissListener onDismissListener;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, asList(
|
||||
getString(R.string.TAd_actionEditTask),
|
||||
getString(R.string.rmd_NoA_snooze),
|
||||
getString(R.string.rmd_NoA_done)
|
||||
));
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Tasks_Dialog);
|
||||
builder.setTitle(title);
|
||||
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
TaskIntents
|
||||
.getEditTaskStack(getActivity(), null, taskId)
|
||||
.startActivities();
|
||||
notificationManager.cancel(taskId);
|
||||
dismiss();
|
||||
break;
|
||||
case 1:
|
||||
dismiss();
|
||||
startActivity(new Intent(getActivity(), SnoozeActivity.class) {{
|
||||
setFlags(FLAG_ACTIVITY_NEW_TASK);
|
||||
putExtra(SnoozeActivity.EXTRA_TASK_ID, taskId);
|
||||
}});
|
||||
break;
|
||||
case 2:
|
||||
broadcaster.completeTask(taskId);
|
||||
dismiss();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (onDismissListener != null) {
|
||||
onDismissListener.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
});
|
||||
return builder.show();
|
||||
}
|
||||
|
||||
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
|
||||
this.onDismissListener = onDismissListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (onDismissListener != null) {
|
||||
onDismissListener.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setTaskId(long taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/reminder_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dip"
|
||||
android:paddingRight="10dip"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="20dip"
|
||||
android:layout_marginLeft="5dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@android:color/white"
|
||||
android:layout_weight="1"/>
|
||||
<ImageView
|
||||
android:id="@+id/dismiss"
|
||||
android:layout_width="25dip"
|
||||
android:layout_height="25dip"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_menu_close"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/astrid_speech_bubble"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/reminders_should_show"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:text="@string/TLA_quickadd_confirm_hide_helpers"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/reminder_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/TAd_actionEditTask"
|
||||
android:background="#707070"/>
|
||||
<Button
|
||||
android:id="@+id/reminder_snooze"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/rmd_NoA_snooze"
|
||||
android:background="#707070"/>
|
||||
<Button
|
||||
android:id="@+id/reminder_complete"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/rmd_NoA_done"
|
||||
android:background="?attr/asThemeTextColor"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue