1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package it.niedermann.nextcloud.deck.ui.widget.stack;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.ActionBar;
import androidx.lifecycle.ViewModelProvider;
import java.util.Collections;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.R;
import it.niedermann.nextcloud.deck.api.ResponseCallback;
import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.widget.filter.EWidgetType;
import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidget;
import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetAccount;
import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetBoard;
import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetStack;
import it.niedermann.nextcloud.deck.ui.PickStackActivity;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionDialogFragment;
public class StackWidgetConfigurationActivity extends PickStackActivity {
private int appWidgetId;
private StackWidgetConfigurationViewModel stackWidgetConfigurationViewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
stackWidgetConfigurationViewModel = new ViewModelProvider(this).get(StackWidgetConfigurationViewModel.class);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(R.string.add_stack_widget);
}
setResult(RESULT_CANCELED);
final Bundle extras = getIntent().getExtras();
if (extras != null) {
appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
DeckLog.error("INVALID_APPWIDGET_ID");
finish();
}
}
@Override
protected void onSubmit(Account account, long boardId, long stackId) {
final FilterWidget config = new FilterWidget(appWidgetId, EWidgetType.STACK_WIDGET);
final FilterWidgetAccount filterWidgetAccount = new FilterWidgetAccount(account.getId(), false);
filterWidgetAccount.setIncludeNoProject(false);
FilterWidgetBoard filterWidgetBoard = new FilterWidgetBoard(boardId, Collections.singletonList(new FilterWidgetStack(stackId)));
filterWidgetBoard.setIncludeNoLabel(false);
filterWidgetAccount.setBoards(
Collections.singletonList(filterWidgetBoard));
config.setAccounts(Collections.singletonList(filterWidgetAccount));
stackWidgetConfigurationViewModel.addStackWidget(config, new ResponseCallback<Integer>(account) {
@Override
public void onResponse(Integer response) {
final Intent updateIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null,
getApplicationContext(), StackWidget.class)
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, updateIntent);
getApplicationContext().sendBroadcast(updateIntent);
finish();
}
@Override
public void onError(Throwable throwable) {
super.onError(throwable);
ExceptionDialogFragment
.newInstance(throwable, account)
.show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
});
}
@Override
protected boolean showBoardsWithoutEditPermission() {
return true;
}
}
|