Search in sources :

Example 1 with TodoListRepositoryImpl

use of de.djuelg.neuronizer.storage.TodoListRepositoryImpl in project Neuronizer by djuelg.

the class TodoListAppWidgetProvider method createRemoteViews.

private static RemoteViews createRemoteViews(Context context, int appWidgetId, String repositoryName, String uuid) {
    Optional<TodoList> todoList = new TodoListRepositoryImpl(repositoryName).getTodoListById(uuid);
    String title = todoList.isPresent() ? todoList.get().getTitle() : context.getResources().getString(R.string.widget_empty);
    // Pending intent, used to start correct fragment from widget button
    Intent intent = new Intent(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(KEY_SWITCH_FRAGMENT, KEY_TODO_LIST);
    intent.putExtra(KEY_WIDGET_REPOSITORY, repositoryName);
    intent.putExtra(KEY_UUID, uuid);
    intent.putExtra(KEY_TITLE, title);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    // RemoteView setup fro WidgetListFactory
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_todo_list);
    remoteViews.setOnClickPendingIntent(R.id.widget_todo_list_bar_container, pendingIntent);
    remoteViews.setOnClickPendingIntent(R.id.widget_todo_list_bar_button, pendingIntent);
    remoteViews.setTextViewText(R.id.widget_todo_list_bar_title, title);
    return remoteViews;
}
Also used : RemoteViews(android.widget.RemoteViews) TodoListRepositoryImpl(de.djuelg.neuronizer.storage.TodoListRepositoryImpl) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 2 with TodoListRepositoryImpl

use of de.djuelg.neuronizer.storage.TodoListRepositoryImpl in project Neuronizer by djuelg.

the class TodoListAppWidgetConfigure method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setResult(RESULT_CANCELED);
    setContentView(R.layout.activity_widget_configure);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    repositoryName = sharedPreferences.getString(KEY_PREF_ACTIVE_REPO, FALLBACK_REALM);
    List<TodoList> list = new TodoListRepositoryImpl(repositoryName).getAll();
    radioGroup = findViewById(R.id.widget_config_radio_group);
    todoLists = list.toArray(new TodoList[list.size()]);
    radioButtons = new RadioButton[todoLists.length];
    createRadioButtons();
}
Also used : SharedPreferences(android.content.SharedPreferences) TodoListRepositoryImpl(de.djuelg.neuronizer.storage.TodoListRepositoryImpl) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Aggregations

TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)2 TodoListRepositoryImpl (de.djuelg.neuronizer.storage.TodoListRepositoryImpl)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 RemoteViews (android.widget.RemoteViews)1