mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-31 18:11:03 +01:00
Select widget account
This commit is contained in:
@@ -20,18 +20,34 @@ package eu.faircode.email;
|
||||
*/
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ActivityWidgetUnified extends ActivityBase {
|
||||
private int appWidgetId;
|
||||
|
||||
private Spinner spAccount;
|
||||
private CheckBox cbUnseen;
|
||||
private CheckBox cbFlagged;
|
||||
private Button btnSave;
|
||||
private ContentLoadingProgressBar pbWait;
|
||||
private Group grpReady;
|
||||
|
||||
private ArrayAdapter<EntityAccount> adapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -48,9 +64,12 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
getSupportActionBar().setSubtitle(R.string.title_folder_unified);
|
||||
setContentView(R.layout.activity_widget_unified);
|
||||
|
||||
final CheckBox cbUnseen = findViewById(R.id.cbUnseen);
|
||||
final CheckBox cbFlagged = findViewById(R.id.cbFlagged);
|
||||
Button btnSave = findViewById(R.id.btnSave);
|
||||
spAccount = findViewById(R.id.spAccount);
|
||||
cbUnseen = findViewById(R.id.cbUnseen);
|
||||
cbFlagged = findViewById(R.id.cbFlagged);
|
||||
btnSave = findViewById(R.id.btnSave);
|
||||
pbWait = findViewById(R.id.pbWait);
|
||||
grpReady = findViewById(R.id.grpReady);
|
||||
|
||||
final Intent resultValue = new Intent();
|
||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
|
||||
@@ -58,8 +77,13 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
btnSave.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
EntityAccount account = (EntityAccount) spAccount.getSelectedItem();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityWidgetUnified.this);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
if (account != null && account.id > 0)
|
||||
editor.putString("widget." + appWidgetId + ".name", account.name);
|
||||
editor.putLong("widget." + appWidgetId + ".account", account == null ? -1L : account.id);
|
||||
editor.putBoolean("widget." + appWidgetId + ".unseen", cbUnseen.isChecked());
|
||||
editor.putBoolean("widget." + appWidgetId + ".flagged", cbFlagged.isChecked());
|
||||
editor.apply();
|
||||
@@ -72,6 +96,42 @@ public class ActivityWidgetUnified extends ActivityBase {
|
||||
}
|
||||
});
|
||||
|
||||
adapter = new ArrayAdapter<>(this, R.layout.spinner_item1, android.R.id.text1, new ArrayList<EntityAccount>());
|
||||
adapter.setDropDownViewResource(R.layout.spinner_item1_dropdown);
|
||||
spAccount.setAdapter(adapter);
|
||||
|
||||
grpReady.setVisibility(View.GONE);
|
||||
pbWait.setVisibility(View.VISIBLE);
|
||||
|
||||
setResult(RESULT_CANCELED, resultValue);
|
||||
|
||||
new SimpleTask<List<EntityAccount>>() {
|
||||
@Override
|
||||
protected List<EntityAccount> onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
return db.account().getSynchronizingAccounts();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, List<EntityAccount> accounts) {
|
||||
EntityAccount all = new EntityAccount();
|
||||
all.id = -1L;
|
||||
all.name = getString(R.string.title_widget_account_all);
|
||||
all.primary = false;
|
||||
accounts.add(0, all);
|
||||
|
||||
adapter.addAll(accounts);
|
||||
|
||||
grpReady.setVisibility(View.VISIBLE);
|
||||
pbWait.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.e(ex);
|
||||
Helper.unexpectedError(getSupportFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, new Bundle(), "widget:accounts");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user