blob: eb06201a8d79b719d1529010c6d06327c3f6d0ad (
plain)
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
|
package it.niedermann.owncloud.notes.widget.singlenote;
import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.database.SQLException;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import it.niedermann.owncloud.notes.NotesApplication;
import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.exception.ExceptionHandler;
import it.niedermann.owncloud.notes.main.MainActivity;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.persistence.entity.SingleNoteWidgetData;
public class SingleNoteWidgetConfigurationActivity extends MainActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
setResult(Activity.RESULT_CANCELED);
fabCreate.setVisibility(View.GONE);
Toolbar toolbar = binding.activityNotesListView.toolbar;
SwipeRefreshLayout swipeRefreshLayout = binding.activityNotesListView.swiperefreshlayout;
toolbar.setTitle(R.string.activity_select_single_note);
swipeRefreshLayout.setEnabled(false);
swipeRefreshLayout.setRefreshing(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public void onNoteClick(int position, View v) {
final Note note = (Note) adapter.getItem(position);
final Bundle extras = getIntent().getExtras();
if (extras == null) {
finish();
return;
}
int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
new Thread(() -> {
try {
mainViewModel.createOrUpdateSingleNoteWidgetData(
new SingleNoteWidgetData(
appWidgetId,
note.getAccountId(),
note.getId(),
NotesApplication.getAppTheme(this).getModeId()
)
);
final Intent updateIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null,
getApplicationContext(), SingleNoteWidget.class)
.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, updateIntent);
getApplicationContext().sendBroadcast(updateIntent);
finish();
} catch (SQLException e) {
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
}).start();
}
}
|