Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SingleNoteWidgetConfigurationActivity.java « singlenote « widget « notes « owncloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 72febe4f69614a3220f79a9078d67e9aaee569ee (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
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.WidgetSingleNoteEntity;
import it.niedermann.owncloud.notes.shared.model.DBNote;

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 DBNote note = (DBNote) 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);

        try {
            roomDatabase.getWidgetSingleNoteDao().createOrUpdateSingleNoteWidgetData(
                    new WidgetSingleNoteEntity(
                            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);
        } catch (SQLException e) {
            Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
        }

        finish();
    }
}