Show analytic snackbar from task list activity

pull/384/head
Alex Baker 9 years ago
parent 7de4e98746
commit 452fd35d2e

@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.graphics.drawable.DrawableCompat; import android.support.v4.graphics.drawable.DrawableCompat;
@ -31,6 +32,7 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.actfm.FilterSettingsActivity; import com.todoroo.astrid.actfm.FilterSettingsActivity;
import com.todoroo.astrid.actfm.TagSettingsActivity; import com.todoroo.astrid.actfm.TagSettingsActivity;
import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.CustomFilter; import com.todoroo.astrid.api.CustomFilter;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
@ -52,7 +54,9 @@ import com.todoroo.astrid.widget.TasksWidget;
import org.tasks.R; import org.tasks.R;
import org.tasks.activities.SortActivity; import org.tasks.activities.SortActivity;
import org.tasks.analytics.Tracker;
import org.tasks.preferences.ActivityPreferences; import org.tasks.preferences.ActivityPreferences;
import org.tasks.preferences.BasicPreferences;
import org.tasks.receivers.RepeatConfirmationReceiver; import org.tasks.receivers.RepeatConfirmationReceiver;
import org.tasks.ui.MenuColorizer; import org.tasks.ui.MenuColorizer;
import org.tasks.ui.NavigationDrawerFragment; import org.tasks.ui.NavigationDrawerFragment;
@ -71,6 +75,7 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
@Inject GtasksPreferenceService gtasksPreferenceService; @Inject GtasksPreferenceService gtasksPreferenceService;
@Inject VoiceInputAssistant voiceInputAssistant; @Inject VoiceInputAssistant voiceInputAssistant;
@Inject BuiltInFilters builtInFilters; @Inject BuiltInFilters builtInFilters;
@Inject Tracker tracker;
private static final int REQUEST_EDIT_TAG = 11543; private static final int REQUEST_EDIT_TAG = 11543;
private static final int REQUEST_EDIT_FILTER = 11544; private static final int REQUEST_EDIT_FILTER = 11544;
@ -149,17 +154,13 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER); Filter savedFilter = getIntent().getParcelableExtra(TaskListFragment.TOKEN_FILTER);
if (savedFilter == null) { if (savedFilter == null) {
savedFilter = getDefaultFilter(); savedFilter = builtInFilters.getMyTasks();
extras.putAll(configureIntentAndExtrasWithFilter(getIntent(), savedFilter)); extras.putAll(configureIntentAndExtrasWithFilter(getIntent(), savedFilter));
} }
extras.putParcelable(TaskListFragment.TOKEN_FILTER, savedFilter); extras.putParcelable(TaskListFragment.TOKEN_FILTER, savedFilter);
setupTasklistFragmentWithFilter(savedFilter, extras); setupTasklistFragmentWithFilter(savedFilter, extras);
setListsTitle(savedFilter.listingTitle);
if (savedFilter != null) {
setListsTitle(savedFilter.listingTitle);
}
} }
public NavigationDrawerFragment getNavigationDrawerFragment() { public NavigationDrawerFragment getNavigationDrawerFragment() {
@ -204,8 +205,11 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
completed.setEnabled(false); completed.setEnabled(false);
} else if(tlf instanceof TagViewFragment) { } else if(tlf instanceof TagViewFragment) {
menu.findItem(R.id.menu_tag_settings).setVisible(true); menu.findItem(R.id.menu_tag_settings).setVisible(true);
} else if(tlf.getFilter() instanceof CustomFilter && ((CustomFilter) tlf.getFilter()).getId() > 0) { } else {
menu.findItem(R.id.menu_filter_settings).setVisible(true); Filter filter = tlf.getFilter();
if(filter != null && filter instanceof CustomFilter && ((CustomFilter) filter).getId() > 0) {
menu.findItem(R.id.menu_filter_settings).setVisible(true);
}
} }
if (tlf instanceof SubtasksTagListFragment || tlf instanceof SubtasksListFragment) { if (tlf instanceof SubtasksTagListFragment || tlf instanceof SubtasksListFragment) {
@ -249,10 +253,6 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
return true; return true;
} }
protected Filter getDefaultFilter() {
return builtInFilters.getMyTasks();
}
@Override @Override
public boolean onFilterItemClicked(FilterListItem item) { public boolean onFilterItemClicked(FilterListItem item) {
TaskEditFragment.removeExtrasFromIntent(getIntent()); TaskEditFragment.removeExtrasFromIntent(getIntent());
@ -295,8 +295,7 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
try { try {
FragmentManager manager = getSupportFragmentManager(); FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction(); FragmentTransaction transaction = manager.beginTransaction();
transaction.replace(R.id.tasklist_fragment_container, newFragment, transaction.replace(R.id.tasklist_fragment_container, newFragment, TaskListFragment.TAG_TASKLIST_FRAGMENT);
TaskListFragment.TAG_TASKLIST_FRAGMENT);
transaction.commit(); transaction.commit();
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
@ -359,6 +358,33 @@ public class TaskListActivity extends AstridActivity implements OnPageChangeList
if (getIntent().getBooleanExtra(TOKEN_CREATE_NEW_LIST, false)) { if (getIntent().getBooleanExtra(TOKEN_CREATE_NEW_LIST, false)) {
newListFromLaunch(); newListFromLaunch();
} }
if (getResources().getBoolean(R.bool.google_play_store_available) &&
!preferences.getBoolean(R.string.p_collect_statistics_notification, false)) {
try {
View taskList = findViewById(R.id.task_list_coordinator);
String text = getString(R.string.anonymous_usage_blurb);
//noinspection ResourceType
Snackbar.make(taskList, text, 10000)
.setActionTextColor(getResources().getColor(R.color.snackbar_undo))
.setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
preferences.setBoolean(R.string.p_collect_statistics_notification, true);
}
})
.setAction(R.string.opt_out, new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(TaskListActivity.this, BasicPreferences.class), FilterAdapter.REQUEST_SETTINGS);
}
})
.show();
} catch (Exception e) {
Timber.e(e, e.getMessage());
tracker.reportException(e);
}
}
} }
private void newListFromLaunch() { private void newListFromLaunch() {

@ -206,6 +206,10 @@ public class Filter extends FilterListItem {
@Override @Override
public String toString() { public String toString() {
return listingTitle; return "Filter{" +
"sqlQuery='" + sqlQuery + '\'' +
", filterOverride='" + filterOverride + '\'' +
", valuesForNewTasks=" + valuesForNewTasks +
'}';
} }
} }

@ -10,15 +10,10 @@ import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.preference.PreferenceManager;
import android.support.design.widget.Snackbar;
import android.view.View;
import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener; import com.todoroo.andlib.data.DatabaseDao.ModelUpdateListener;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.activity.TaskListActivity;
import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.activity.AstridActivity; import com.todoroo.astrid.activity.AstridActivity;
import com.todoroo.astrid.backup.TasksXmlImporter; import com.todoroo.astrid.backup.TasksXmlImporter;
import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.Database;
@ -37,9 +32,7 @@ import com.todoroo.astrid.tags.TaskToTagMetadata;
import org.tasks.Broadcaster; import org.tasks.Broadcaster;
import org.tasks.BuildConfig; import org.tasks.BuildConfig;
import org.tasks.R; import org.tasks.R;
import org.tasks.analytics.Tracker;
import org.tasks.dialogs.DialogBuilder; import org.tasks.dialogs.DialogBuilder;
import org.tasks.preferences.BasicPreferences;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
import java.io.File; import java.io.File;
@ -68,16 +61,14 @@ public class StartupService {
private final Preferences preferences; private final Preferences preferences;
private final TasksXmlImporter xmlImporter; private final TasksXmlImporter xmlImporter;
private final TaskDeleter taskDeleter; private final TaskDeleter taskDeleter;
private Broadcaster broadcaster; private final Broadcaster broadcaster;
private DialogBuilder dialogBuilder; private final DialogBuilder dialogBuilder;
private Tracker tracker;
@Inject @Inject
public StartupService(TagDataDao tagDataDao, Database database, GtasksPreferenceService gtasksPreferenceService, public StartupService(TagDataDao tagDataDao, Database database, GtasksPreferenceService gtasksPreferenceService,
GtasksSyncService gtasksSyncService, MetadataDao metadataDao, GtasksSyncService gtasksSyncService, MetadataDao metadataDao,
Preferences preferences, TasksXmlImporter xmlImporter, Preferences preferences, TasksXmlImporter xmlImporter,
TaskDeleter taskDeleter, Broadcaster broadcaster, DialogBuilder dialogBuilder, TaskDeleter taskDeleter, Broadcaster broadcaster, DialogBuilder dialogBuilder) {
Tracker tracker) {
this.tagDataDao = tagDataDao; this.tagDataDao = tagDataDao;
this.database = database; this.database = database;
this.gtasksPreferenceService = gtasksPreferenceService; this.gtasksPreferenceService = gtasksPreferenceService;
@ -88,7 +79,6 @@ public class StartupService {
this.taskDeleter = taskDeleter; this.taskDeleter = taskDeleter;
this.broadcaster = broadcaster; this.broadcaster = broadcaster;
this.dialogBuilder = dialogBuilder; this.dialogBuilder = dialogBuilder;
this.tracker = tracker;
} }
/** /**
@ -151,34 +141,6 @@ public class StartupService {
gtasksPreferenceService.stopOngoing(); gtasksPreferenceService.stopOngoing();
gtasksSyncService.initialize(); gtasksSyncService.initialize();
if (activity.getResources().getBoolean(R.bool.google_play_store_available) &&
!preferences.getBoolean(R.string.p_collect_statistics_notification, false) &&
activity instanceof TaskListActivity) {
preferences.setBoolean(R.string.p_collect_statistics_notification, true);
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
View taskList = activity.findViewById(R.id.task_list_body);
String text = activity.getString(R.string.anonymous_usage_blurb);
//noinspection ResourceType
Snackbar.make(taskList, text, 10000)
.setActionTextColor(activity.getResources().getColor(R.color.snackbar_undo))
.setAction(R.string.opt_out, new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.startActivityForResult(new Intent(activity, BasicPreferences.class), FilterAdapter.REQUEST_SETTINGS);
}
})
.show();
} catch (Exception e) {
Timber.e(e, e.getMessage());
tracker.reportException(e);
}
}
});
}
} }
}).start(); }).start();

@ -52,7 +52,7 @@ public class RepeatConfirmationReceiver extends InjectingBroadcastReceiver {
Task task = taskService.fetchById(taskId, REPEAT_RESCHEDULED_PROPERTIES); Task task = taskService.fetchById(taskId, REPEAT_RESCHEDULED_PROPERTIES);
try { try {
showSnackbar(activity.findViewById(R.id.task_list_body), task, oldDueDate, newDueDate); showSnackbar(activity.findViewById(R.id.task_list_coordinator), task, oldDueDate, newDueDate);
} catch (WindowManager.BadTokenException e) { // Activity not running when tried to show dialog--rebroadcast } catch (WindowManager.BadTokenException e) { // Activity not running when tried to show dialog--rebroadcast
Timber.e(e, e.getMessage()); Timber.e(e, e.getMessage());
new Thread() { new Thread() {

@ -5,6 +5,7 @@
--> -->
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/task_list_coordinator"
android:background="?attr/asContentBackground" android:background="?attr/asContentBackground"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"

Loading…
Cancel
Save