display external links, disabled by default

stored in database
This commit is contained in:
tobiasKaminsky 2017-04-06 08:48:12 +02:00
parent 843b76333e
commit a5c2cc0fb6
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
13 changed files with 475 additions and 30 deletions

View file

@ -0,0 +1,169 @@
/**
* Nextcloud Android client application
*
* Copyright (C) 2017 Tobias Kaminsky
* Copyright (C) 2017 Nextcloud.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This program 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.datamodel;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.support.annotation.NonNull;
import com.owncloud.android.db.ProviderMeta;
import com.owncloud.android.lib.common.ExternalLink;
import com.owncloud.android.lib.common.ExternalLinkType;
import com.owncloud.android.lib.common.utils.Log_OC;
import java.util.ArrayList;
/**
* Database provider for handling the persistence aspects of {@link com.owncloud.android.lib.common.ExternalLink}s.
*/
public class ExternalLinksProvider {
static private final String TAG = ExternalLinksProvider.class.getSimpleName();
private ContentResolver mContentResolver;
public ExternalLinksProvider(ContentResolver contentResolver) {
if (contentResolver == null) {
throw new IllegalArgumentException("Cannot create an instance with a NULL contentResolver");
}
mContentResolver = contentResolver;
}
/**
* Stores an external link in database.
*
* @param externalLink object to store
* @return external link id, -1 if the insert process fails.
*/
public long storeExternalLink(ExternalLink externalLink) {
Log_OC.v(TAG, "Adding " + externalLink.name);
ContentValues cv = createContentValuesFromExternalLink(externalLink);
Uri result = mContentResolver.insert(ProviderMeta.ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS, cv);
if (result != null) {
return Long.parseLong(result.getPathSegments().get(1));
} else {
Log_OC.e(TAG, "Failed to insert item " + externalLink.name + " into external link db.");
return -1;
}
}
/**
* Delete all external links from the db
* @return numbers of rows deleted
*/
public int deleteAllExternalLinks() {
return mContentResolver.delete(ProviderMeta.ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS, " 1 = 1 ", null);
}
/**
* get by type external links.
*
* @return external links, empty if none exists
*/
public ArrayList<ExternalLink> getExternalLink(ExternalLinkType type) {
Cursor cursor = mContentResolver.query(
ProviderMeta.ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS,
null,
"type = ?",
new String[]{type.toString()},
null
);
if (cursor != null) {
ArrayList<ExternalLink> list = new ArrayList<>();
if (cursor.moveToFirst()) {
do {
ExternalLink externalLink = createExternalLinkFromCursor(cursor);
if (externalLink == null) {
Log_OC.e(TAG, "ExternalLink could not be created from cursor");
} else {
list.add(externalLink);
}
} while (cursor.moveToNext());
}
cursor.close();
return list;
} else {
Log_OC.e(TAG, "DB error restoring externalLinks.");
}
return new ArrayList<>();
}
/**
* create ContentValues object based on given externalLink.
*
* @param externalLink the external Link
* @return the corresponding ContentValues object
*/
@NonNull
private ContentValues createContentValuesFromExternalLink(ExternalLink externalLink) {
ContentValues cv = new ContentValues();
cv.put(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_ICON_URL, externalLink.iconUrl);
cv.put(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE, externalLink.language);
cv.put(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TYPE, externalLink.type.toString());
cv.put(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_NAME, externalLink.name);
cv.put(ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_URL, externalLink.url);
return cv;
}
/**
* cursor to externalLink
*
* @param cursor db cursor
* @return externalLink, null if cursor is null
*/
private ExternalLink createExternalLinkFromCursor(Cursor cursor) {
ExternalLink externalLink = null;
if (cursor != null) {
int id = cursor.getInt(cursor.getColumnIndex(ProviderMeta.ProviderTableMeta._ID));
String iconUrl = cursor.getString(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_ICON_URL));
String language = cursor.getString(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE));
ExternalLinkType type = ExternalLinkType.LINK;
switch (cursor.getString(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_TYPE))) {
case "link":
type = ExternalLinkType.LINK;
break;
case "settings":
type = ExternalLinkType.SETTINGS;
break;
case "quota":
type = ExternalLinkType.QUOTA;
break;
}
String name = cursor.getString(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_NAME));
String url = cursor.getString(cursor.getColumnIndex(
ProviderMeta.ProviderTableMeta.EXTERNAL_LINKS_URL));
externalLink = new ExternalLink(id, iconUrl, language, type, name, url);
}
return externalLink;
}
}

View file

@ -897,21 +897,21 @@ public class FileDataStorageManager {
c.getColumnIndex(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA)));
file.setLastSyncDateForProperties(c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE)));
file.setLastSyncDateForData(c.getLong(c.getColumnIndex(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA)));
file.setAvailableOffline(c.getInt(c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1 ? true : false);
file.setAvailableOffline(c.getInt(c.getColumnIndex(ProviderTableMeta.FILE_KEEP_IN_SYNC)) == 1);
file.setEtag(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG)));
file.setShareViaLink(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1 ? true : false);
c.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1);
file.setShareWithSharee(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1 ? true : false);
c.getColumnIndex(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1);
file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK)));
file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
file.setNeedsUpdateThumbnail(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1 ? true : false);
c.getColumnIndex(ProviderTableMeta.FILE_UPDATE_THUMBNAIL)) == 1);
file.setDownloading(c.getInt(
c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1 ? true : false);
c.getColumnIndex(ProviderTableMeta.FILE_IS_DOWNLOADING)) == 1);
file.setEtagInConflict(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG_IN_CONFLICT)));
file.setFavorite(c.getInt(c.getColumnIndex(ProviderTableMeta.FILE_FAVORITE)) == 1 ? true : false);
file.setFavorite(c.getInt(c.getColumnIndex(ProviderTableMeta.FILE_FAVORITE)) == 1);
}
return file;
@ -1862,6 +1862,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.CAPABILITIES_FILES_UNDELETE, capability.getFilesUndelete().getValue());
cv.put(ProviderTableMeta.CAPABILITIES_FILES_VERSIONING, capability.getFilesVersioning().getValue());
cv.put(ProviderTableMeta.CAPABILITIES_FILES_DROP, capability.getFilesFileDrop().getValue());
cv.put(ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS, capability.getExternalLinks().getValue());
if (capabilityExists(mAccount.name)) {
if (getContentResolver() != null) {
@ -1998,7 +1999,8 @@ public class FileDataStorageManager {
.getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_VERSIONING))));
capability.setFilesFileDrop(CapabilityBooleanType.fromValue(c.getInt(c
.getColumnIndex(ProviderTableMeta.CAPABILITIES_FILES_DROP))));
capability.setExternalLinks(CapabilityBooleanType.fromValue(c.getInt(c
.getColumnIndex(ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS))));
}
return capability;
}

View file

@ -33,7 +33,7 @@ import com.owncloud.android.MainApp;
public class ProviderMeta {
public static final String DB_NAME = "filelist";
public static final int DB_VERSION = 17;
public static final int DB_VERSION = 19;
private ProviderMeta() {
}
@ -44,6 +44,7 @@ public class ProviderMeta {
public static final String CAPABILITIES_TABLE_NAME = "capabilities";
public static final String UPLOADS_TABLE_NAME = "list_of_uploads";
public static final String SYNCED_FOLDERS_TABLE_NAME = "synced_folders";
public static final String EXTERNAL_LINKS_TABLE_NAME = "external_links";
private static final String CONTENT_PREFIX = "content://";
@ -61,6 +62,8 @@ public class ProviderMeta {
+ MainApp.getAuthority() + "/uploads");
public static final Uri CONTENT_URI_SYNCED_FOLDERS = Uri.parse(CONTENT_PREFIX
+ MainApp.getAuthority() + "/synced_folders");
public static final Uri CONTENT_URI_EXTERNAL_LINKS = Uri.parse(CONTENT_PREFIX
+ MainApp.getAuthority() + "/external_links");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file";
public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file";
@ -139,6 +142,7 @@ public class ProviderMeta {
public static final String CAPABILITIES_FILES_UNDELETE = "files_undelete";
public static final String CAPABILITIES_FILES_VERSIONING = "files_versioning";
public static final String CAPABILITIES_FILES_DROP = "files_drop";
public static final String CAPABILITIES_EXTERNAL_LINKS = "external_links";
public static final String CAPABILITIES_DEFAULT_SORT_ORDER = CAPABILITIES_ACCOUNT_NAME
+ " collate nocase asc";
@ -167,5 +171,12 @@ public class ProviderMeta {
public static final String SYNCED_FOLDER_SUBFOLDER_BY_DATE = "subfolder_by_date";
public static final String SYNCED_FOLDER_ACCOUNT = "account";
public static final String SYNCED_FOLDER_UPLOAD_ACTION = "upload_option";
// Columns of external links table
public static final String EXTERNAL_LINKS_ICON_URL = "icon_url";
public static final String EXTERNAL_LINKS_LANGUAGE = "language";
public static final String EXTERNAL_LINKS_TYPE = "type";
public static final String EXTERNAL_LINKS_NAME = "name";
public static final String EXTERNAL_LINKS_URL = "url";
}
}

View file

@ -71,6 +71,7 @@ public class FileContentProvider extends ContentProvider {
private static final int CAPABILITIES = 5;
private static final int UPLOADS = 6;
private static final int SYNCED_FOLDERS = 7;
private static final int EXTERNAL_LINKS = 8;
private static final String TAG = FileContentProvider.class.getSimpleName();
@ -197,6 +198,9 @@ public class FileContentProvider extends ContentProvider {
case SYNCED_FOLDERS:
count = db.delete(ProviderTableMeta.SYNCED_FOLDERS_TABLE_NAME, where, whereArgs);
break;
case EXTERNAL_LINKS:
count = db.delete(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, where, whereArgs);
break;
default:
//Log_OC.e(TAG, "Unknown uri " + uri);
throw new IllegalArgumentException("Unknown uri: " + uri.toString());
@ -319,6 +323,18 @@ public class FileContentProvider extends ContentProvider {
}
return insertedSyncedFolderUri;
case EXTERNAL_LINKS:
Uri insertedExternalLinkUri = null;
long externalLinkId = db.insert(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME, null, values);
if (externalLinkId > 0) {
insertedExternalLinkUri =
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_EXTERNAL_LINKS, externalLinkId);
} else {
throw new SQLException("ERROR " + uri);
}
return insertedExternalLinkUri;
default:
throw new IllegalArgumentException("Unknown uri id: " + uri);
}
@ -368,6 +384,7 @@ public class FileContentProvider extends ContentProvider {
mUriMatcher.addURI(authority, "uploads/", UPLOADS);
mUriMatcher.addURI(authority, "uploads/#", UPLOADS);
mUriMatcher.addURI(authority, "synced_folders", SYNCED_FOLDERS);
mUriMatcher.addURI(authority, "external_links", EXTERNAL_LINKS);
return true;
}
@ -449,6 +466,13 @@ public class FileContentProvider extends ContentProvider {
+ uri.getPathSegments().get(1));
}
break;
case EXTERNAL_LINKS:
sqlQuery.setTables(ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME);
if (uri.getPathSegments().size() > 1) {
sqlQuery.appendWhere(ProviderTableMeta._ID + "="
+ uri.getPathSegments().get(1));
}
break;
default:
throw new IllegalArgumentException("Unknown uri id: " + uri);
}
@ -468,6 +492,9 @@ public class FileContentProvider extends ContentProvider {
case SYNCED_FOLDERS:
order = ProviderTableMeta.SYNCED_FOLDER_LOCAL_PATH;
break;
case EXTERNAL_LINKS:
order = ProviderTableMeta.EXTERNAL_LINKS_NAME;
break;
default: // Files
order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
break;
@ -581,6 +608,9 @@ public class FileContentProvider extends ContentProvider {
// Create synced folders table
createSyncedFoldersTable(db);
// Create external links table
createExternalLinksTable(db);
}
@Override
@ -862,6 +892,41 @@ public class FileContentProvider extends ContentProvider {
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
if (oldVersion < 18 && newVersion >= 18) {
Log_OC.i(SQL, "Adding external link column to capabilities");
db.beginTransaction();
try {
db.execSQL(ALTER_TABLE + ProviderTableMeta.CAPABILITIES_TABLE_NAME +
ADD_COLUMN + ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS +
" INTEGER " + " DEFAULT -1");
upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
if (oldVersion < 19 && newVersion >= 19) {
Log_OC.i(SQL, "Adding external link column to capabilities");
db.beginTransaction();
try {
createExternalLinksTable(db);
upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (!upgraded) {
Log_OC.i(SQL, String.format(Locale.ENGLISH, UPGRADE_VERSION_MSG, oldVersion, newVersion));
}
}
}
@ -941,7 +1006,8 @@ public class FileContentProvider extends ContentProvider {
+ ProviderTableMeta.CAPABILITIES_FILES_BIGFILECHUNKING + INTEGER // boolean
+ ProviderTableMeta.CAPABILITIES_FILES_UNDELETE + INTEGER // boolean
+ ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + INTEGER // boolean
+ ProviderTableMeta.CAPABILITIES_FILES_DROP + " INTEGER );"); // boolean
+ ProviderTableMeta.CAPABILITIES_FILES_DROP + INTEGER // boolean
+ ProviderTableMeta.CAPABILITIES_EXTERNAL_LINKS + " INTEGER );" ); // boolean
}
private void createUploadsTable(SQLiteDatabase db) {
@ -987,6 +1053,17 @@ public class FileContentProvider extends ContentProvider {
);
}
private void createExternalLinksTable(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + ProviderTableMeta.EXTERNAL_LINKS_TABLE_NAME + "("
+ ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " // id
+ ProviderTableMeta.EXTERNAL_LINKS_ICON_URL + " TEXT, " // icon url
+ ProviderTableMeta.EXTERNAL_LINKS_LANGUAGE + " TEXT, " // language
+ ProviderTableMeta.EXTERNAL_LINKS_TYPE + " INTEGER, " // type
+ ProviderTableMeta.EXTERNAL_LINKS_NAME + " TEXT, " // name
+ ProviderTableMeta.EXTERNAL_LINKS_URL + " TEXT )" // url
);
}
/**
* Version 10 of database does not modify its scheme. It coincides with the upgrade of the ownCloud account names
* structure to include in it the path to the server instance. Updating the account names and path to local files

View file

@ -46,7 +46,10 @@ import android.widget.TextView;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.ExternalLinksProvider;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.ExternalLink;
import com.owncloud.android.lib.common.ExternalLinkType;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.Quota;
import com.owncloud.android.lib.common.UserInfo;
@ -66,6 +69,8 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
/**
* Base class to handle setup of the drawer implementation including user switching and avatar fetching and fallback
* generation.
@ -77,7 +82,8 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
private static final int ACTION_MANAGE_ACCOUNTS = 101;
private static final int MENU_ORDER_ACCOUNT = 1;
private static final int MENU_ORDER_ACCOUNT_FUNCTION = 2;
private static final int MENU_ORDER_EXTERNAL_LINKS = 3;
private static final int MENU_ITEM_EXTERNAL_LINK = 111;
/**
* menu account avatar radius.
*/
@ -96,7 +102,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
/**
* Reference to the drawer layout.
*/
private DrawerLayout mDrawerLayout;
protected DrawerLayout mDrawerLayout;
/**
* Reference to the drawer toggle.
@ -158,6 +164,8 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
*/
private Runnable pendingRunnable;
private ExternalLinksProvider externalLinksProvider;
/**
* Initializes the drawer, its content and highlights the menu item with the given id.
* This method needs to be called after the content view has been set.
@ -450,6 +458,10 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
EventBus.getDefault().post(new SearchEvent("video/%", SearchOperation.SearchType.CONTENT_TYPE_SEARCH,
SearchEvent.UnsetType.UNSET_BOTTOM_NAV_BAR));
break;
case MENU_ITEM_EXTERNAL_LINK:
// external link clicked
externalLinkClicked(menuItem);
break;
case Menu.NONE:
// account clicked
accountClicked(menuItem.getTitle().toString());
@ -479,6 +491,20 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
}
}
private void externalLinkClicked(MenuItem menuItem){
for (ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
if (menuItem.getTitle().toString().equalsIgnoreCase(link.name)) {
Intent externalWebViewIntent = new Intent(getApplicationContext(),
ExternalSiteWebView.class);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.name);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.url);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, true);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, menuItem.getItemId());
startActivity(externalWebViewIntent);
}
}
}
/**
* click method for mini avatars in drawer header.
*
@ -690,11 +716,13 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
}
mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_standard, false);
mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_external_links, false);
mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_bottom, false);
} else {
mAccountChooserToggle.setImageResource(R.drawable.ic_down);
mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, false);
mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_standard, true);
mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_external_links, true);
mNavigationView.getMenu().setGroupVisible(R.id.drawer_menu_bottom, true);
}
}
@ -724,10 +752,37 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
mQuotaProgressBar.setProgress(relative);
DisplayUtils.colorHorizontalProgressBar(mQuotaProgressBar, DisplayUtils.getRelativeInfoColor(this, relative));
mQuotaTextView.setText(String.format(
getString(R.string.drawer_quota),
DisplayUtils.bytesToHumanReadable(usedSpace),
DisplayUtils.bytesToHumanReadable(totalSpace)));
if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
ArrayList<ExternalLink> quotas = externalLinksProvider.getExternalLink(ExternalLinkType.QUOTA);
if (quotas.size() > 0) {
final ExternalLink firstQuota = quotas.get(0);
mQuotaTextView.setText(firstQuota.name);
mQuotaTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.arrow_down, 0, 0, 0);
mQuotaTextView.setClickable(true);
mQuotaTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, firstQuota.name);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, firstQuota.url);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, true);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, -1);
startActivity(externalWebViewIntent);
}
});
} else {
mQuotaTextView.setText(String.format(
getString(R.string.drawer_quota),
DisplayUtils.bytesToHumanReadable(usedSpace),
DisplayUtils.bytesToHumanReadable(totalSpace)));
}
} else {
mQuotaTextView.setText(String.format(
getString(R.string.drawer_quota),
DisplayUtils.bytesToHumanReadable(usedSpace),
DisplayUtils.bytesToHumanReadable(totalSpace)));
}
showQuota(true);
}
@ -811,6 +866,17 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
t.start();
}
private void updateExternalLinks() {
if (mNavigationView != null && getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
mNavigationView.getMenu().removeGroup(R.id.drawer_menu_external_links);
for (ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
mNavigationView.getMenu().add(R.id.drawer_menu_external_links, MENU_ITEM_EXTERNAL_LINK,
MENU_ORDER_EXTERNAL_LINKS, link.name)
.setIcon(R.drawable.ic_activity_light_grey);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -826,6 +892,9 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
.getDimension(R.dimen.nav_drawer_header_avatar_other_accounts_radius);
mMenuAccountAvatarRadiusDimension = getResources()
.getDimension(R.dimen.nav_drawer_menu_avatar_radius);
externalLinksProvider =
new ExternalLinksProvider(MainApp.getAppContext().getContentResolver());
}
@Override
@ -863,6 +932,7 @@ public abstract class DrawerActivity extends ToolbarActivity implements DisplayU
}
}
updateAccountList();
updateExternalLinks();
}
@Override

View file

@ -24,12 +24,14 @@ package com.owncloud.android.ui.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.owncloud.android.MainApp;
@ -41,13 +43,24 @@ import com.owncloud.android.lib.common.utils.Log_OC;
*/
public class ExternalSiteWebView extends FileActivity {
public static final String EXTRA_TITLE = "TITLE";
public static final String EXTRA_URL = "URL";
public static final String EXTRA_SHOW_SIDEBAR = "SHOW_SIDEBAR";
public static final String EXTRA_MENU_ITEM_ID = "MENU_ITEM_ID";
private static final String TAG = ExternalSiteWebView.class.getSimpleName();
private boolean showSidebar = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log_OC.v(TAG, "onCreate() start");
// TODO get name, url, boolean showSidebar
Bundle extras = getIntent().getExtras();
String title = extras.getString(EXTRA_TITLE);
String url = extras.getString(EXTRA_URL);
int menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID);
showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR);
// show progress
getWindow().requestFeature(Window.FEATURE_PROGRESS);
@ -66,18 +79,25 @@ public class ExternalSiteWebView extends FileActivity {
setupToolbar();
// setup drawer
setupDrawer(R.id.nav_external);
getSupportActionBar().setTitle("About us");
if (showSidebar) {
setupDrawer(menuItemId);
} else {
setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
}
getSupportActionBar().setTitle(title);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// enable zoom
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);
// next two settings grant that non-responsive webs are zoomed out when loaded
// Non-responsive webs are zoomed out when loaded
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
// user agent
webSettings.setUserAgentString(MainApp.getUserAgent());
// no private data storing
@ -91,9 +111,11 @@ public class ExternalSiteWebView extends FileActivity {
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 1000);
progressBar.setProgress(progress * 1000);
}
});
@ -103,7 +125,7 @@ public class ExternalSiteWebView extends FileActivity {
}
});
webview.loadUrl("http://nextcloud.com");
webview.loadUrl(url);
}
@Override
@ -111,10 +133,15 @@ public class ExternalSiteWebView extends FileActivity {
boolean retval;
switch (item.getItemId()) {
case android.R.id.home: {
if (isDrawerOpen()) {
closeDrawer();
if (showSidebar) {
if (isDrawerOpen()) {
closeDrawer();
} else {
openDrawer();
}
} else {
openDrawer();
Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class);
startActivity(settingsIntent);
}
}
@ -127,8 +154,7 @@ public class ExternalSiteWebView extends FileActivity {
@Override
public void showFiles(boolean onDeviceOnly) {
super.showFiles(onDeviceOnly);
Intent fileDisplayActivity = new Intent(getApplicationContext(),
FileDisplayActivity.class);
Intent fileDisplayActivity = new Intent(getApplicationContext(), FileDisplayActivity.class);
fileDisplayActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(fileDisplayActivity);
}

View file

@ -40,16 +40,18 @@ import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.authentication.AuthenticatorActivity;
import com.owncloud.android.datamodel.ExternalLinksProvider;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import com.owncloud.android.files.services.FileDownloader;
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.common.ExternalLink;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.OwnCloudCredentials;
import com.owncloud.android.lib.common.accounts.ExternalLinksOperation;
import com.owncloud.android.lib.common.network.CertificateCombinedException;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@ -68,8 +70,11 @@ import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.LoadingDialog;
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
import com.owncloud.android.ui.helpers.FileOperationsHelper;
import com.owncloud.android.utils.ErrorMessageAdapter;
import java.util.ArrayList;
/**
* Activity with common behaviour for activities handling {@link OCFile}s in ownCloud {@link Account}s .
@ -179,6 +184,41 @@ public abstract class FileActivity extends DrawerActivity
@Override
protected void onStart() {
super.onStart();
getAndDisplayExternalLinks();
}
/**
* Retrieves external links via api from 'external' app
*/
public void getAndDisplayExternalLinks() {
Thread t = new Thread(new Runnable() {
public void run() {
if (getCapabilities().getExternalLinks().isTrue()) {
Log_OC.d("ExternalLinks", "update via api");
ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver());
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(
AccountUtils.getCurrentOwnCloudAccount(FileActivity.this), FileActivity.this);
if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();
ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();
for (ExternalLink link : externalLinks) {
externalLinksProvider.storeExternalLink(link);
}
}
} else {
Log_OC.d("ExternalLinks", "links disabled");
}
}
});
t.start();
}
@Override

View file

@ -58,9 +58,12 @@ import com.owncloud.android.BuildConfig;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.ExternalLinksProvider;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datastorage.DataStorageProvider;
import com.owncloud.android.datastorage.StoragePoint;
import com.owncloud.android.lib.common.ExternalLink;
import com.owncloud.android.lib.common.ExternalLinkType;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.utils.Log_OC;
@ -463,6 +466,8 @@ public class Preferences extends PreferenceActivity
pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
}
loadExternalSettingLinks(preferenceCategory);
loadStoragePath();
}
@ -727,6 +732,38 @@ public class Preferences extends PreferenceActivity
return mDelegate;
}
private void loadExternalSettingLinks(PreferenceCategory preferenceCategory) {
if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
ExternalLinksProvider externalLinksProvider = new ExternalLinksProvider(getContentResolver());
for (final ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.SETTINGS)) {
// only add if it does not exist, in case activity is re-used
if (findPreference(link.id.toString()) == null) {
Preference p = new Preference(this);
p.setTitle(link.name);
p.setKey(link.id.toString());
p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.name);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, link.url);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_MENU_ITEM_ID, link.id);
startActivity(externalWebViewIntent);
return true;
}
});
preferenceCategory.addPreference(p);
}
}
}
}
/**
* Load upload path set on preferences
*/

View file

@ -60,6 +60,7 @@
android:id="@+id/drawer_quota_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:text="@string/drawer_quota"/>
</LinearLayout>

View file

@ -104,7 +104,15 @@
</group>
<!--
all items in this group MUST have orderInCategory="3" set
all items in this group MUST have orderInCategory="3" set
-->
<group
android:id="@+id/drawer_menu_external_links"
android:checkableBehavior="single">
</group>
<!--
all items in this group MUST have orderInCategory="4" set
-->
<group
android:id="@+id/drawer_menu_bottom"
@ -112,12 +120,12 @@
<item
android:id="@+id/nav_settings"
android:icon="@drawable/ic_settings"
android:orderInCategory="3"
android:orderInCategory="4"
android:title="@string/actionbar_settings"/>
<item
android:id="@+id/nav_participate"
android:icon="@drawable/ic_participate"
android:orderInCategory="3"
android:orderInCategory="4"
android:title="@string/drawer_participate"/>
</group>

View file

@ -37,6 +37,7 @@
<bool name = "share_via_link_feature">true</bool>
<bool name = "share_with_users_feature">true</bool>
<bool name="show_whats_new">true</bool>
<bool name="show_external_links">false</bool>
<!-- Colors -->
<color name="login_text_color">@color/white</color>

View file

@ -620,6 +620,7 @@
<string name="activities_no_results_headline">No activity yet</string>
<string name="activities_no_results_message">This stream will show events like\nadditions, changes &amp; shares</string>
<string name="webview_error">Error occurred</string>
<string name="prefs_category_about">About</string>
</resources>

View file

@ -92,6 +92,8 @@
<Preference android:title="@string/prefs_feedback" android:key="feedback" />
<Preference android:title="@string/actionbar_logger" android:key="logger" />
<Preference android:title="@string/prefs_imprint" android:key="imprint" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefs_category_about" android:key="about">
<Preference android:title="@string/about_title" android:id="@+id/about_app" android:key="about_app" />
</PreferenceCategory>