mirror of
https://github.com/etesync/android
synced 2025-01-22 13:40:55 +00:00
Show notifications on refresh errors
* show notifications on DAV service refresh errors * add Twitter to navigation drawer
This commit is contained in:
parent
96881bd986
commit
3a49815220
@ -18,6 +18,7 @@ public class Constants {
|
||||
public final static int
|
||||
NOTIFICATION_ACCOUNT_SETTINGS_UPDATED = 0,
|
||||
NOTIFICATION_EXTERNAL_FILE_LOGGING = 1,
|
||||
NOTIFICATION_REFRESH_COLLECTIONS = 2,
|
||||
NOTIFICATION_CONTACTS_SYNC = 10,
|
||||
NOTIFICATION_CALENDAR_SYNC = 11,
|
||||
NOTIFICATION_TASK_SYNC = 12;
|
||||
|
@ -10,14 +10,19 @@ package at.bitfire.davdroid;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.NotificationCompat;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -45,6 +50,7 @@ import at.bitfire.davdroid.model.ServiceDB.Collections;
|
||||
import at.bitfire.davdroid.model.ServiceDB.HomeSets;
|
||||
import at.bitfire.davdroid.model.ServiceDB.OpenHelper;
|
||||
import at.bitfire.davdroid.model.ServiceDB.Services;
|
||||
import at.bitfire.davdroid.ui.DebugInfoActivity;
|
||||
import lombok.Cleanup;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
@ -152,14 +158,19 @@ public class DavService extends Service {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Account account = null;
|
||||
|
||||
try {
|
||||
db = dbHelper.getWritableDatabase();
|
||||
|
||||
String serviceType = serviceType();
|
||||
App.log.info("Refreshing " + serviceType + " collections of service #" + service);
|
||||
|
||||
// get account
|
||||
account = account();
|
||||
|
||||
// create authenticating OkHttpClient (credentials taken from account settings)
|
||||
OkHttpClient httpClient = httpClient();
|
||||
OkHttpClient httpClient = HttpClient.create(DavService.this, account);
|
||||
|
||||
// refresh home sets: principal
|
||||
Set<HttpUrl> homeSets = readHomeSets();
|
||||
@ -180,7 +191,7 @@ public class DavService extends Service {
|
||||
if (proxyWrite != null)
|
||||
for (String href : proxyWrite.principals) {
|
||||
App.log.fine("Principal is a read-write proxy for " + href + ", checking for home sets");
|
||||
queryHomeSets(serviceType, new DavResource(httpClient, dav.location.resolve(href)), homeSets);
|
||||
queryHomeSets(serviceType, new DavResource(httpClient, dav.location.resolve(href)), homeSets);
|
||||
}
|
||||
|
||||
// refresh home sets: direct group memberships
|
||||
@ -273,6 +284,21 @@ public class DavService extends Service {
|
||||
|
||||
} catch (IOException|HttpException|DavException e) {
|
||||
App.log.log(Level.SEVERE, "Couldn't refresh collection list", e);
|
||||
|
||||
Intent debugIntent = new Intent(DavService.this, DebugInfoActivity.class);
|
||||
debugIntent.putExtra(DebugInfoActivity.KEY_EXCEPTION, e);
|
||||
if (account != null)
|
||||
debugIntent.putExtra(DebugInfoActivity.KEY_ACCOUNT, account);
|
||||
|
||||
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
Notification notify = new NotificationCompat.Builder(DavService.this)
|
||||
.setSmallIcon(R.drawable.ic_error_light)
|
||||
.setLargeIcon(((BitmapDrawable)getResources().getDrawable(R.drawable.ic_launcher)).getBitmap())
|
||||
.setContentTitle(getString(R.string.dav_service_refresh_failed))
|
||||
.setContentText(getString(R.string.dav_service_refresh_couldnt_refresh))
|
||||
.setContentIntent(PendingIntent.getActivity(DavService.this, 0, debugIntent, 0))
|
||||
.build();
|
||||
nm.notify(Constants.NOTIFICATION_REFRESH_COLLECTIONS, notify);
|
||||
} finally {
|
||||
dbHelper.close();
|
||||
|
||||
@ -305,17 +331,16 @@ public class DavService extends Service {
|
||||
}
|
||||
|
||||
|
||||
private OkHttpClient httpClient() {
|
||||
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[]{Services.ACCOUNT_NAME}, Services.ID + "=?", new String[] { String.valueOf(service) }, null, null, null);
|
||||
private Account account() {
|
||||
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[] { Services.ACCOUNT_NAME }, Services.ID + "=?", new String[] { String.valueOf(service) }, null, null, null);
|
||||
if (cursor.moveToNext()) {
|
||||
Account account = new Account(cursor.getString(0), Constants.ACCOUNT_TYPE);
|
||||
return HttpClient.create(DavService.this, account);
|
||||
return new Account(cursor.getString(0), Constants.ACCOUNT_TYPE);
|
||||
} else
|
||||
throw new IllegalArgumentException("Service not found");
|
||||
}
|
||||
|
||||
private String serviceType() {
|
||||
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[]{Services.SERVICE}, Services.ID + "=?", new String[] { String.valueOf(service) }, null, null, null);
|
||||
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[] { Services.SERVICE }, Services.ID + "=?", new String[] { String.valueOf(service) }, null, null, null);
|
||||
if (cursor.moveToNext())
|
||||
return cursor.getString(0);
|
||||
else
|
||||
@ -323,7 +348,7 @@ public class DavService extends Service {
|
||||
}
|
||||
|
||||
private HttpUrl readPrincipal() {
|
||||
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[]{Services.PRINCIPAL}, Services.ID + "=?", new String[]{String.valueOf(service)}, null, null, null);
|
||||
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[] { Services.PRINCIPAL }, Services.ID + "=?", new String[] { String.valueOf(service) }, null, null, null);
|
||||
if (cursor.moveToNext()) {
|
||||
String principal = cursor.getString(0);
|
||||
if (principal != null)
|
||||
@ -334,14 +359,14 @@ public class DavService extends Service {
|
||||
|
||||
private Set<HttpUrl> readHomeSets() {
|
||||
Set<HttpUrl> homeSets = new LinkedHashSet<>();
|
||||
@Cleanup Cursor cursor = db.query(HomeSets._TABLE, new String[]{HomeSets.URL}, HomeSets.SERVICE_ID + "=?", new String[]{String.valueOf(service)}, null, null, null);
|
||||
@Cleanup Cursor cursor = db.query(HomeSets._TABLE, new String[] { HomeSets.URL }, HomeSets.SERVICE_ID + "=?", new String[] { String.valueOf(service) }, null, null, null);
|
||||
while (cursor.moveToNext())
|
||||
homeSets.add(HttpUrl.parse(cursor.getString(0)));
|
||||
return homeSets;
|
||||
}
|
||||
|
||||
private void saveHomeSets(Set<HttpUrl> homeSets) {
|
||||
db.delete(HomeSets._TABLE, HomeSets.SERVICE_ID + "=?", new String[]{String.valueOf(service)});
|
||||
db.delete(HomeSets._TABLE, HomeSets.SERVICE_ID + "=?", new String[] { String.valueOf(service) });
|
||||
for (HttpUrl homeSet : homeSets) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(HomeSets.SERVICE_ID, service);
|
||||
|
@ -9,6 +9,7 @@
|
||||
package at.bitfire.davdroid.ui;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
@ -51,6 +52,7 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
||||
|
||||
NavigationView navigationView = (NavigationView)findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
navigationView.setItemIconTintList(null);
|
||||
|
||||
if (savedInstanceState == null && !getPackageName().equals(getCallingPackage())) {
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
@ -72,6 +74,12 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.nav_app_settings:
|
||||
startActivity(new Intent(this, AppSettingsActivity.class));
|
||||
break;
|
||||
case R.id.nav_twitter:
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/davdroidapp")));
|
||||
break;
|
||||
case R.id.nav_about:
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("source/").build()));
|
||||
break;
|
||||
@ -87,9 +95,6 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
||||
case R.id.nav_donate:
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("donate/").build()));
|
||||
break;
|
||||
case R.id.nav_app_settings:
|
||||
startActivity(new Intent(this, AppSettingsActivity.class));
|
||||
break;
|
||||
}
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
|
||||
|
17
app/src/main/res/drawable/ic_error_light.xml
Normal file
17
app/src/main/res/drawable/ic_error_light.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<!--
|
||||
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
||||
~ All rights reserved. This program and the accompanying materials
|
||||
~ are made available under the terms of the GNU Public License v3.0
|
||||
~ which accompanies this distribution, and is available at
|
||||
~ http://www.gnu.org/licenses/gpl.html
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zm1,15h-2v-2h2v2zm0,-4h-2V7h2v6z"/>
|
||||
</vector>
|
33
app/src/main/res/drawable/twitter.xml
Normal file
33
app/src/main/res/drawable/twitter.xml
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="277"
|
||||
android:viewportHeight="277">
|
||||
|
||||
<group
|
||||
android:translateY="-0.7250061">
|
||||
<group
|
||||
android:scaleX="0.12466422"
|
||||
android:scaleY="0.12466422">
|
||||
<path
|
||||
android:fillColor="#6aa9e0"
|
||||
android:pathData="M 2198.4655,429.89797 c -80.4733,35.82942 -166.9548,60.04502 -257.7242,70.936
|
||||
92.6495,-55.75608 163.7947,-144.04056 197.2992,-249.2398 -86.6974,51.62778
|
||||
-182.7311,89.11977 -284.9407,109.32754 -81.8574,-87.5536 -198.4753,-142.26556
|
||||
-327.5334,-142.26556 -247.8202,0 -448.7354,201.70015 -448.7354,450.48215
|
||||
0,35.30737 3.976,69.69109 11.6242,102.66123 C 715.52416,753.01338
|
||||
384.88755,573.66545 163.56787,301.11765 c -38.62542,66.53463 -60.74738,143.91205
|
||||
-60.74738,226.47796 0,156.2889 79.21645,294.17718 199.61849,374.96004
|
||||
-73.55401,-2.33722 -142.74319,-22.60121 -203.244156,-56.34239 -0.0337,1.87942
|
||||
-0.0401,3.75884 -0.0401,5.66235 0,218.26959 154.674526,400.34659
|
||||
359.949116,441.72919 -37.65343,10.2934 -77.29807,15.7967 -118.21711,15.7967
|
||||
-28.91654,0 -57.02573,-2.8175 -84.423,-8.079 57.10091,178.9785
|
||||
222.81246,309.2205 419.16928,312.8565 -153.5713,120.8209 -347.05293,192.8427
|
||||
-557.28115,192.8427 -36.219604,0 -71.938914,-2.1275 -107.042597,-6.2871
|
||||
198.581677,127.8136 434.444767,202.3893 687.848917,202.3893 825.36002,0
|
||||
1276.69552,-686.4473 1276.69552,-1281.7474 0,-19.5331 -0.432,-38.96179
|
||||
-1.2961,-58.27803 87.6657,-63.51471 163.7469,-142.85991 223.9079,-233.2005" />
|
||||
</group>
|
||||
</group>
|
||||
</vector>
|
@ -7,13 +7,24 @@
|
||||
~ http://www.gnu.org/licenses/gpl.html
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<menu xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_app_settings"
|
||||
android:icon="@drawable/ic_settings_dark"
|
||||
android:title="@string/navigation_drawer_settings"/>
|
||||
|
||||
<item android:title="@string/navigation_drawer_news_updates">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/nav_twitter"
|
||||
android:icon="@drawable/twitter"
|
||||
android:title="\@davdroidapp"
|
||||
tools:ignore="HardcodedText"/>
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item android:title="@string/navigation_drawer_external_links">
|
||||
<menu>
|
||||
<item
|
||||
|
@ -46,6 +46,7 @@
|
||||
<string name="navigation_drawer_subtitle">CalDAV/CardDAV Sync Adapter</string>
|
||||
<string name="navigation_drawer_about">About / License</string>
|
||||
<string name="navigation_drawer_settings">Settings</string>
|
||||
<string name="navigation_drawer_news_updates">News & updates</string>
|
||||
<string name="navigation_drawer_external_links">External links</string>
|
||||
<string name="navigation_drawer_website">Web site</string>
|
||||
<string name="navigation_drawer_faq">FAQ</string>
|
||||
@ -54,6 +55,10 @@
|
||||
|
||||
<string name="account_list_empty">Welcome to DAVdroid!\n\nYou can add a CalDAV/CardDAV account now.</string>
|
||||
|
||||
<!-- DavService -->
|
||||
<string name="dav_service_refresh_failed">Service detection failed</string>
|
||||
<string name="dav_service_refresh_couldnt_refresh">Couldn\'t refresh collection list</string>
|
||||
|
||||
<!-- AppSettingsActivity -->
|
||||
<string name="app_settings">Settings</string>
|
||||
<string name="app_settings_user_interface">User interface</string>
|
||||
|
Loading…
Reference in New Issue
Block a user