mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-19 10:25:29 +00:00
Added settings tile / quick settings
This commit is contained in:
parent
548fa422b3
commit
b99cafb01c
3 changed files with 117 additions and 2 deletions
|
@ -53,9 +53,14 @@
|
|||
|
||||
<activity
|
||||
android:name=".ActivitySetup"
|
||||
android:exported="false"
|
||||
android:exported="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:parentActivityName=".ActivityMain" />
|
||||
android:parentActivityName=".ActivityMain">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ActivityView"
|
||||
|
@ -106,6 +111,16 @@
|
|||
android:exported="true"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE" />
|
||||
|
||||
<service
|
||||
android:name=".ServiceTile"
|
||||
android:icon="@drawable/baseline_mail_24"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}"
|
||||
|
|
95
app/src/main/java/eu/faircode/email/ServiceTile.java
Normal file
95
app/src/main/java/eu/faircode/email/ServiceTile.java
Normal file
|
@ -0,0 +1,95 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
/*
|
||||
This file is part of FairEmail.
|
||||
|
||||
FairEmail is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
FairEmail is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.service.quicksettings.Tile;
|
||||
import android.service.quicksettings.TileService;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.lifecycle.LifecycleService;
|
||||
import androidx.lifecycle.Observer;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
public class ServiceTile extends TileService {
|
||||
LifecycleService owner = new LifecycleService();
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
owner.onCreate();
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
owner.onBind(intent);
|
||||
return super.onBind(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
owner.onStartCommand(intent, flags, startId);
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
owner.onDestroy();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void onStartListening() {
|
||||
Log.i(Helper.TAG, "Tile start");
|
||||
|
||||
DB db = DB.getInstance(this);
|
||||
db.message().liveUnseenUnified().observe(owner, new Observer<List<TupleMessageEx>>() {
|
||||
@Override
|
||||
public void onChanged(List<TupleMessageEx> messages) {
|
||||
Tile tile = getQsTile();
|
||||
if (tile != null) {
|
||||
tile.setState(messages.size() > 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
|
||||
tile.setLabel(getResources().getQuantityString(
|
||||
R.plurals.title_tile_unseen, messages.size(), messages.size()));
|
||||
tile.updateTile();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onStopListening() {
|
||||
Log.i(Helper.TAG, "Tile stop");
|
||||
|
||||
DB db = DB.getInstance(this);
|
||||
db.message().liveUnseenUnified().removeObservers(owner);
|
||||
}
|
||||
|
||||
public void onClick() {
|
||||
Log.i(Helper.TAG, "Tile click");
|
||||
|
||||
Intent clear = new Intent(this, ServiceSynchronize.class);
|
||||
clear.setAction("clear");
|
||||
startService(clear);
|
||||
}
|
||||
}
|
|
@ -31,6 +31,11 @@
|
|||
<item quantity="other">%1$d unsent messages</item>
|
||||
</plurals>
|
||||
|
||||
<plurals name="title_tile_unseen">
|
||||
<item quantity="one">%1$d new</item>
|
||||
<item quantity="other">%1$d new</item>
|
||||
</plurals>
|
||||
|
||||
<string name="title_notification_failed">\'%1$s\' failed</string>
|
||||
|
||||
<string name="menu_setup">Setup</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue