From: masensio Date: Wed, 27 May 2015 12:19:30 +0000 (+0200) Subject: Merge branch 'remove_ActionBarSherlock' into navigationDrawer_update X-Git-Tag: oc-android-1.7.2~1^2~23^2~37^2~3 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/c20041d157baebede8e47a5f6837ba7dd51204f7?hp=e7493203deca0edc7edeb5fb26f2774ede84a479 Merge branch 'remove_ActionBarSherlock' into navigationDrawer_update Conflicts: res/menu/main_menu.xml src/com/owncloud/android/ui/activity/FileDisplayActivity.java src/com/owncloud/android/ui/activity/FolderPickerActivity.java src/com/owncloud/android/ui/activity/Preferences.java src/com/owncloud/android/ui/preview/PreviewImageActivity.java --- diff --git a/res/drawable-hdpi/ic_drawer.png b/res/drawable-hdpi/ic_drawer.png new file mode 100644 index 00000000..6614ea4f Binary files /dev/null and b/res/drawable-hdpi/ic_drawer.png differ diff --git a/res/drawable-mdpi/ic_drawer.png b/res/drawable-mdpi/ic_drawer.png new file mode 100644 index 00000000..fb681ba2 Binary files /dev/null and b/res/drawable-mdpi/ic_drawer.png differ diff --git a/res/drawable-xhdpi/ic_drawer.png b/res/drawable-xhdpi/ic_drawer.png new file mode 100644 index 00000000..b9bc3d70 Binary files /dev/null and b/res/drawable-xhdpi/ic_drawer.png differ diff --git a/res/layout/drawer_account_group.xml b/res/layout/drawer_account_group.xml new file mode 100644 index 00000000..85a1c753 --- /dev/null +++ b/res/layout/drawer_account_group.xml @@ -0,0 +1,22 @@ + + + \ No newline at end of file diff --git a/res/layout/drawer_list_item.xml b/res/layout/drawer_list_item.xml new file mode 100644 index 00000000..30f3843b --- /dev/null +++ b/res/layout/drawer_list_item.xml @@ -0,0 +1,42 @@ + + + + + + + + diff --git a/res/layout/drawer_radiobutton.xml b/res/layout/drawer_radiobutton.xml new file mode 100644 index 00000000..917d8944 --- /dev/null +++ b/res/layout/drawer_radiobutton.xml @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/res/layout/files.xml b/res/layout/files.xml index 5d62c131..5f11f068 100644 --- a/res/layout/files.xml +++ b/res/layout/files.xml @@ -1,5 +1,5 @@ - - + - - - - - - \ No newline at end of file + android:clickable="true" > + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/listrow_details.xml b/res/layout/listrow_details.xml new file mode 100644 index 00000000..01651bf9 --- /dev/null +++ b/res/layout/listrow_details.xml @@ -0,0 +1,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/res/layout/listrow_group.xml b/res/layout/listrow_group.xml new file mode 100644 index 00000000..735a11e4 --- /dev/null +++ b/res/layout/listrow_group.xml @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/res/layout/uploader_layout.xml b/res/layout/uploader_layout.xml index 60a21112..a5351f04 100644 --- a/res/layout/uploader_layout.xml +++ b/res/layout/uploader_layout.xml @@ -22,11 +22,11 @@ android:layout_width="wrap_content" android:background="#fefefe" android:gravity="center"> + android:layout_below="@+id/drawer_username" android:layout_above="@+id/linearLayout1"> diff --git a/res/layout/uploader_list_item_layout.xml b/res/layout/uploader_list_item_layout.xml index e0932690..d2d0005b 100644 --- a/res/layout/uploader_list_item_layout.xml +++ b/res/layout/uploader_list_item_layout.xml @@ -35,7 +35,7 @@ diff --git a/res/values/colors.xml b/res/values/colors.xml index 6aeb6acf..b42538fd 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -22,6 +22,7 @@ #DDDDDD #00ddff #989898 + #000000 #303030 #fff0f0f0 diff --git a/res/values/drawer_resources.xml b/res/values/drawer_resources.xml new file mode 100644 index 00000000..ca0143ba --- /dev/null +++ b/res/values/drawer_resources.xml @@ -0,0 +1,39 @@ + + + + + + + @string/prefs_accounts + @string/drawer_item_all_files + + @string/actionbar_settings + @string/actionbar_logger + + + + + @string/drawer_item_accounts + @string/drawer_item_all_files + + @string/drawer_item_settings + @string/drawer_item_logs + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 0e2e9458..8a7d8139 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -20,6 +20,14 @@ + Accounts + All files + + Settings + Logs + ownCloud + Close General More Accounts @@ -330,10 +338,14 @@ Upload Video Path Download of %1$s folder could not be completed - %1$s shared \"%2$s\" with you + shared + with you + + %1$s %2$s >>%3$s<< %4$s Refresh connection Server address Not enough memory + Username diff --git a/src/com/owncloud/android/MainApp.java b/src/com/owncloud/android/MainApp.java index 657469ef..c805f9f7 100644 --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@ -53,6 +53,11 @@ public class MainApp extends Application { private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client"; private static Context mContext; + + // TODO Enable when "On Device" is recovered? + // TODO better place + // private static boolean mOnlyOnDevice = false; + public void onCreate(){ super.onCreate(); @@ -171,6 +176,15 @@ public class MainApp extends Application { return getAppContext().getResources().getString(R.string.log_name); } + // TODO Enable when "On Device" is recovered ? +// public static void showOnlyFilesOnDevice(boolean state){ +// mOnlyOnDevice = state; +// } +// +// public static boolean getOnlyOnDevice(){ +// return mOnlyOnDevice; +// } + // user agent public static String getUserAgent() { String appString = getAppContext().getResources().getString(R.string.user_agent); diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index c32dbbce..7db0a637 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -28,14 +28,6 @@ import java.util.Iterator; import java.util.List; import java.util.Vector; -import com.owncloud.android.MainApp; -import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.lib.resources.files.FileUtils; -import com.owncloud.android.utils.FileStorageUtils; - import android.accounts.Account; import android.content.ContentProviderClient; import android.content.ContentProviderOperation; @@ -50,6 +42,14 @@ import android.net.Uri; import android.os.RemoteException; import android.provider.MediaStore; +import com.owncloud.android.MainApp; +import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.utils.FileStorageUtils; + public class FileDataStorageManager { public static final int ROOT_PARENT_ID = 0; @@ -142,9 +142,10 @@ public class FileDataStorageManager { } - public Vector getFolderContent(OCFile f) { + public Vector getFolderContent(OCFile f/*, boolean onlyOnDevice*/) { if (f != null && f.isFolder() && f.getFileId() != -1) { - return getFolderContent(f.getFileId()); + // TODO Enable when "On Device" is recovered ? + return getFolderContent(f.getFileId()/*, onlyOnDevice*/); } else { return new Vector(); @@ -152,11 +153,12 @@ public class FileDataStorageManager { } - public Vector getFolderImages(OCFile folder) { + public Vector getFolderImages(OCFile folder/*, boolean onlyOnDevice*/) { Vector ret = new Vector(); if (folder != null) { - // TODO better implementation, filtering in the access to database instead of here - Vector tmp = getFolderContent(folder); + // TODO better implementation, filtering in the access to database instead of here + // TODO Enable when "On Device" is recovered ? + Vector tmp = getFolderContent(folder/*, onlyOnDevice*/); OCFile current = null; for (int i=0; i files = getFolderContent(folder.getFileId()); + // TODO Enable when "On Device" is recovered ? + Vector files = getFolderContent(folder.getFileId()/*, false*/); if (files != null) { for (OCFile file : files) { if (file.isFolder()) { @@ -731,7 +734,7 @@ public class FileDataStorageManager { } - private Vector getFolderContent(long parentId) { + private Vector getFolderContent(long parentId/*, boolean onlyOnDevice*/) { Vector ret = new Vector(); @@ -758,7 +761,10 @@ public class FileDataStorageManager { if (c.moveToFirst()) { do { OCFile child = createFileInstance(c); - ret.add(child); + // TODO Enable when "On Device" is recovered ? + // if (child.isFolder() || !onlyOnDevice || onlyOnDevice && child.isDown()){ + ret.add(child); + // } } while (c.moveToNext()); } @@ -1435,14 +1441,14 @@ public class FileDataStorageManager { } private ArrayList prepareRemoveSharesInFolder( - OCFile folder, ArrayList preparedOperations - ) { + OCFile folder, ArrayList preparedOperations) { if (folder != null) { String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"; String [] whereArgs = new String[]{ "", mAccount.name }; - - Vector files = getFolderContent(folder); + + // TODO Enable when "On Device" is recovered ? + Vector files = getFolderContent(folder /*, false*/); for (OCFile file : files) { whereArgs[0] = file.getRemotePath(); diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index 50a35fdb..2e3c4692 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -201,7 +201,8 @@ public class RefreshFolderOperation extends RemoteOperation { if (mRemoteFolderChanged) { result = fetchAndSyncRemoteFolder(client); } else { - mChildren = mStorageManager.getFolderContent(mLocalFolder); + // TODO Enable when "On Device" is recovered ? + mChildren = mStorageManager.getFolderContent(mLocalFolder/*, false*/); } } @@ -341,7 +342,8 @@ public class RefreshFolderOperation extends RemoteOperation { List filesToSyncContents = new Vector(); // get current data about local contents of the folder to synchronize - List localFiles = mStorageManager.getFolderContent(mLocalFolder); + // TODO Enable when "On Device" is recovered ? + List localFiles = mStorageManager.getFolderContent(mLocalFolder/*, false*/); Map localFilesMap = new HashMap(localFiles.size()); for (OCFile file : localFiles) { localFilesMap.put(file.getRemotePath(), file); diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 286b5ea9..6bf1ef82 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -20,12 +20,19 @@ package com.owncloud.android.operations; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Vector; + import android.accounts.Account; import android.content.Context; import android.content.Intent; import android.util.Log; -import com.owncloud.android.MainApp; + import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader; @@ -41,12 +48,6 @@ import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.services.OperationsService; import com.owncloud.android.utils.FileStorageUtils; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; //import android.support.v4.content.LocalBroadcastManager; @@ -297,7 +298,8 @@ public class SynchronizeFolderOperation extends SyncOperation { } // get current data about local contents of the folder to synchronize - List localFiles = storageManager.getFolderContent(mLocalFolder); + // TODO Enable when "On Device" is recovered ? + List localFiles = storageManager.getFolderContent(mLocalFolder/*, false*/); Map localFilesMap = new HashMap(localFiles.size()); for (OCFile file : localFiles) { localFilesMap.put(file.getRemotePath(), file); @@ -392,7 +394,8 @@ public class SynchronizeFolderOperation extends SyncOperation { private void prepareOpsFromLocalKnowledge() throws OperationCancelledException { - List children = getStorageManager().getFolderContent(mLocalFolder); + // TODO Enable when "On Device" is recovered ? + List children = getStorageManager().getFolderContent(mLocalFolder/*, false*/); for (OCFile child : children) { /// classify file to sync/download contents later if (child.isFolder()) { diff --git a/src/com/owncloud/android/ui/NavigationDrawerItem.java b/src/com/owncloud/android/ui/NavigationDrawerItem.java new file mode 100644 index 00000000..44ed3ecc --- /dev/null +++ b/src/com/owncloud/android/ui/NavigationDrawerItem.java @@ -0,0 +1,56 @@ +/** + * ownCloud Android client application + * + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.ui; + +public class NavigationDrawerItem { + + private String mTitle; + private String mContentDescription; + + // Constructors + public NavigationDrawerItem(){} + + public NavigationDrawerItem(String title){ + mTitle = title; + } + + public NavigationDrawerItem(String title, String contentDescription){ + mTitle = title; + mContentDescription = contentDescription; + } + + // Getters and Setters + public String getTitle() { + return mTitle; + } + + public void setTitle(String title) { + this.mTitle = title; + } + + public String getContentDescription() { + return mContentDescription; + } + + public void setContentDescription(String contentDescription) { + this.mContentDescription = contentDescription; + } +} diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 67173d7e..0844dc26 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -23,6 +23,7 @@ package com.owncloud.android.ui.activity; import java.io.File; +import java.util.ArrayList; import android.accounts.Account; import android.accounts.AccountManager; @@ -39,6 +40,7 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.content.SharedPreferences; import android.content.SyncRequest; +import android.content.res.Configuration; import android.content.res.Resources.NotFoundException; import android.database.Cursor; import android.net.Uri; @@ -47,9 +49,13 @@ import android.os.Bundle; import android.os.IBinder; import android.preference.PreferenceManager; import android.provider.OpenableColumns; +import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; + +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; import android.view.Menu; import android.view.MenuInflater; @@ -57,13 +63,19 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; + +import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; 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.OCFile; import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; @@ -89,6 +101,8 @@ import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.syncadapter.FileSyncAdapter; +import com.owncloud.android.ui.NavigationDrawerItem; +import com.owncloud.android.ui.adapter.NavigationDrawerListAdapter; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; @@ -150,8 +164,22 @@ public class FileDisplayActivity extends HookActivity implements private static String DIALOG_UPLOAD_SOURCE = "DIALOG_UPLOAD_SOURCE"; private static String DIALOG_CERT_NOT_SAVED = "DIALOG_CERT_NOT_SAVED"; - private OCFile mWaitingToSend; + + // Navigation Drawer + private DrawerLayout mDrawerLayout; + private ActionBarDrawerToggle mDrawerToggle; + private ListView mDrawerList; + + // Slide menu items + private String[] mDrawerTitles; + private String[] mDrawerContentDescriptions; + + private ArrayList mDrawerItems; + + private NavigationDrawerListAdapter mNavigationDrawerAdapter = null; + + private boolean mShowAccounts = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -184,7 +212,11 @@ public class FileDisplayActivity extends HookActivity implements /// USER INTERFACE // Inflate and set the layout view - setContentView(R.layout.files); + setContentView(R.layout.files); + + // Navigation Drawer + initDrawer(); + mDualPane = getResources().getBoolean(R.bool.large_land_layout); mLeftFragmentContainer = findViewById(R.id.left_fragment_container); mRightFragmentContainer = findViewById(R.id.right_fragment_container); @@ -201,12 +233,101 @@ public class FileDisplayActivity extends HookActivity implements setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/); // always AFTER setContentView(...) ; to work around bug in its implementation + + // TODO Remove??, it is done in onPostCreate + mDrawerToggle.syncState(); setBackgroundText(); Log_OC.v(TAG, "onCreate() end"); } - + + private void initDrawer(){ + mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + // Notification Drawer + LinearLayout navigationDrawerLayout = (LinearLayout) findViewById(R.id.left_drawer); + mDrawerList = (ListView) navigationDrawerLayout.findViewById(R.id.drawer_list); + + // load Account in the Drawer Title + // User-Icon + ImageView userIcon = (ImageView) navigationDrawerLayout.findViewById(R.id.drawer_userIcon); + userIcon.setImageResource(DisplayUtils.getSeasonalIconId()); + + // Username + TextView username = (TextView) navigationDrawerLayout.findViewById(R.id.drawer_username); + Account account = AccountUtils.getCurrentOwnCloudAccount(getApplicationContext()); + + if (account != null) { + int lastAtPos = account.name.lastIndexOf("@"); + username.setText(account.name.substring(0, lastAtPos)); + } + + // load slide menu items + mDrawerTitles = getResources().getStringArray(R.array.drawer_items); + + // nav drawer content description from resources + mDrawerContentDescriptions = getResources(). + getStringArray(R.array.drawer_content_descriptions); + + // nav drawer items + mDrawerItems = new ArrayList(); + // adding nav drawer items to array + // Accounts + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[0], mDrawerContentDescriptions[0])); + // All Files + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[1], mDrawerContentDescriptions[1])); + + // TODO Enable when "On Device" is recovered + // On Device + //mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], + // mDrawerContentDescriptions[2])); + + // Settings + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[2], mDrawerContentDescriptions[2])); + // Logs + if (BuildConfig.DEBUG) { + mDrawerItems.add(new NavigationDrawerItem(mDrawerTitles[3], + mDrawerContentDescriptions[3])); + } + + // setting the nav drawer list adapter + mNavigationDrawerAdapter = new NavigationDrawerListAdapter(getApplicationContext(), this, + mDrawerItems); + mDrawerList.setAdapter(mNavigationDrawerAdapter); + + mDrawerToggle = new ActionBarDrawerToggle( + this, + mDrawerLayout, + R.drawable.ic_drawer, + R.string.drawer_open, + R.string.empty) { + + /** Called when a drawer has settled in a completely closed state. */ + public void onDrawerClosed(View view) { + super.onDrawerClosed(view); + getSupportActionBar().setDisplayShowTitleEnabled(true); + getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); + initFragmentsWithFile(); + invalidateOptionsMenu(); + } + + /** Called when a drawer has settled in a completely open state. */ + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + getSupportActionBar().setTitle(R.string.drawer_open); + getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + invalidateOptionsMenu(); + } + }; + + mDrawerToggle.setDrawerIndicatorEnabled(true); + // Set the list's click listener + mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); + + // Set the drawer toggle as the DrawerListener + mDrawerLayout.setDrawerListener(mDrawerToggle); + } + @Override protected void onStart() { Log_OC.v(TAG, "onStart() start"); @@ -214,6 +335,19 @@ public class FileDisplayActivity extends HookActivity implements getSupportActionBar().setIcon(DisplayUtils.getSeasonalIconId()); Log_OC.v(TAG, "onStart() end"); } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + // Sync the toggle state after onRestoreInstanceState has occurred. + mDrawerToggle.syncState(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + mDrawerToggle.onConfigurationChanged(newConfig); + } @Override protected void onDestroy() { @@ -298,7 +432,9 @@ public class FileDisplayActivity extends HookActivity implements /// First fragment OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { - listOfFiles.listDirectory(getCurrentDir()); + listOfFiles.listDirectory(getCurrentDir()); + // TODO Enable when "On Device" is recovered + // listOfFiles.listDirectory(getCurrentDir(), MainApp.getOnlyOnDevice()); } else { Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >("); } @@ -422,8 +558,10 @@ public class FileDisplayActivity extends HookActivity implements protected void refreshListOfFilesFragment() { OCFileListFragment fileListFragment = getListOfFilesFragment(); - if (fileListFragment != null) { + if (fileListFragment != null) { fileListFragment.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(MainApp.getOnlyOnDevice()); } } @@ -471,11 +609,11 @@ public class FileDisplayActivity extends HookActivity implements @Override public boolean onPrepareOptionsMenu(Menu menu) { - if (BuildConfig.DEBUG) { - menu.findItem(R.id.action_logger).setVisible(true); - } else { - menu.findItem(R.id.action_logger).setVisible(false); - } + boolean drawerOpen = mDrawerLayout.isDrawerOpen(GravityCompat.START); + menu.findItem(R.id.action_upload).setVisible(!drawerOpen); + menu.findItem(R.id.action_create_dir).setVisible(!drawerOpen); + menu.findItem(R.id.action_sort).setVisible(!drawerOpen); + return super.onPrepareOptionsMenu(menu); } @@ -485,6 +623,7 @@ public class FileDisplayActivity extends HookActivity implements inflater.inflate(R.menu.main_menu, menu); return true; } + @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -495,34 +634,19 @@ public class FileDisplayActivity extends HookActivity implements dialog.show(getSupportFragmentManager(), DIALOG_CREATE_FOLDER); break; } - case R.id.action_sync_account: { - startSynchronization(); - break; - } case R.id.action_upload: { UploadSourceDialogFragment dialog = UploadSourceDialogFragment.newInstance(getAccount()); dialog.show(getSupportFragmentManager(), DIALOG_UPLOAD_SOURCE); break; } - case R.id.action_settings: { - Intent settingsIntent = new Intent(this, Preferences.class); - startActivity(settingsIntent); - break; - } - case R.id.action_logger: { - Intent loggerIntent = new Intent(getApplicationContext(),LogHistoryActivity.class); - startActivity(loggerIntent); - break; - } case android.R.id.home: { - FileFragment second = getSecondFragment(); - OCFile currentDir = getCurrentDir(); - if((currentDir != null && currentDir.getParentId() != 0) || - (second != null && second.getFile() != null)) { - onBackPressed(); - + if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) { + mDrawerLayout.closeDrawer(GravityCompat.START); + } else { + mDrawerLayout.openDrawer(GravityCompat.START); } + // TODO add hamburger to left of android.R.id.home break; } case R.id.action_sort: { @@ -537,19 +661,16 @@ public class FileDisplayActivity extends HookActivity implements builder.setTitle(R.string.actionbar_sort_title) .setSingleChoiceItems(R.array.actionbar_sortby, sortOrder , new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { - switch (which){ - case 0: - sortByName(true); - break; - case 1: - sortByDate(false); - break; - + case 0: + sortByName(true); + break; + case 1: + sortByDate(false); + break; } - + dialog.dismiss(); - } }); builder.create().show(); @@ -687,7 +808,8 @@ public class FileDisplayActivity extends HookActivity implements } else { Log_OC.d(TAG, "User clicked on 'Update' with no selection"); - Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected), Toast.LENGTH_LONG); + Toast t = Toast.makeText(this, getString(R.string.filedisplay_no_file_selected), + Toast.LENGTH_LONG); t.show(); return; } @@ -819,6 +941,9 @@ public class FileDisplayActivity extends HookActivity implements Log_OC.v(TAG, "onResume() start"); super.onResume(); + // refresh Navigation Drawer account list + mNavigationDrawerAdapter.updateAccountList(); + // refresh list of files refreshListOfFilesFragment(); @@ -960,7 +1085,8 @@ public class FileDisplayActivity extends HookActivity implements if (currentDir == null) { // current folder was removed from the server Toast.makeText( FileDisplayActivity.this, - String.format(getString(R.string.sync_current_folder_was_removed), + String.format( + getString(R.string.sync_current_folder_was_removed), mDirectories.getItem(0)), Toast.LENGTH_LONG) .show(); @@ -968,7 +1094,8 @@ public class FileDisplayActivity extends HookActivity implements } else { if (currentFile == null && !getFile().isFolder()) { - // currently selected file was removed in the server, and now we know it + // currently selected file was removed in the server, and now we + // know it cleanSecondFragment(); currentFile = currentDir; } @@ -977,14 +1104,18 @@ public class FileDisplayActivity extends HookActivity implements currentDir.getRemotePath().equals(synchFolderRemotePath)) { OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { - fileListFragment.listDirectory(currentDir); + fileListFragment.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(currentDir, + // MainApp.getOnlyOnDevice()); } } setFile(currentFile); } mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && - !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event)); + !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED + .equals(event)); if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED. equals(event) && @@ -1215,6 +1346,8 @@ public class FileDisplayActivity extends HookActivity implements } OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); listOfFiles.listDirectory(root); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(root, MainApp.getOnlyOnDevice()); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(root, false); } @@ -1230,6 +1363,8 @@ public class FileDisplayActivity extends HookActivity implements if (listOfFiles != null) { setNavigationListWithFolder(folder); listOfFiles.listDirectory(folder); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(folder, MainApp.getOnlyOnDevice()); setFile(listOfFiles.getCurrentFile()); startSyncFolderOperation(folder, false); } else { @@ -1283,13 +1418,16 @@ public class FileDisplayActivity extends HookActivity implements // only list of files - set for browsing through folders OCFile currentDir = getCurrentDir(); boolean noRoot = (currentDir != null && currentDir.getParentId() != 0); - actionBar.setDisplayHomeAsUpEnabled(noRoot); - actionBar.setDisplayShowTitleEnabled(!noRoot); +// actionBar.setDisplayHomeAsUpEnabled(noRoot); +// actionBar.setDisplayShowTitleEnabled(!noRoot); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowTitleEnabled(true); if (!noRoot) { actionBar.setTitle(getString(R.string.default_display_name_for_root_folder)); View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId); if (actionBarTitleView != null) { // it's null in Android 2.x - actionBarTitleView.setContentDescription(getString(R.string.default_display_name_for_root_folder)); + actionBarTitleView.setContentDescription( + getString(R.string.default_display_name_for_root_folder)); } } actionBar.setNavigationMode(!noRoot ? ActionBar.NAVIGATION_MODE_STANDARD : @@ -1321,7 +1459,8 @@ public class FileDisplayActivity extends HookActivity implements @Override public void onServiceConnected(ComponentName component, IBinder service) { - if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) { + if (component.equals(new ComponentName( + FileDisplayActivity.this, FileDownloader.class))) { Log_OC.d(TAG, "Download service connected"); mDownloaderBinder = (FileDownloaderBinder) service; if (mWaitingToPreview != null) @@ -1346,6 +1485,8 @@ public class FileDisplayActivity extends HookActivity implements OCFileListFragment listOfFiles = getListOfFilesFragment(); if (listOfFiles != null) { listOfFiles.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(MainApp.getOnlyOnDevice()); } FileFragment secondFragment = getSecondFragment(); if (secondFragment != null && secondFragment instanceof FileDetailFragment) { @@ -1705,7 +1846,7 @@ public class FileDisplayActivity extends HookActivity implements public void showUntrustedCertDialog(RemoteOperationResult result) { // Show a dialog with the certificate info SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstanceForFullSslError( - (CertificateCombinedException)result.getException()); + (CertificateCombinedException) result.getException()); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); dialog.show(ft, DIALOG_UNTRUSTED_CERT); @@ -1836,5 +1977,54 @@ public class FileDisplayActivity extends HookActivity implements private void sortByName(boolean ascending){ getListOfFilesFragment().sortByName(ascending); } + + public void restart(){ + Intent i = new Intent(this, FileDisplayActivity.class); + i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(i); + } + + public void closeDrawer() { + mDrawerLayout.closeDrawers(); + } + private class DrawerItemClickListener implements ListView.OnItemClickListener { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (mShowAccounts && position > 0){ + position = position - 1; + } + switch (position){ + case 0: // Accounts + mShowAccounts = !mShowAccounts; + mNavigationDrawerAdapter.setShowAccounts(mShowAccounts); + mNavigationDrawerAdapter.notifyDataSetChanged(); + break; + + case 1: // All Files + // TODO Enable when "On Device" is recovered ? + //MainApp.showOnlyFilesOnDevice(false); + mDrawerLayout.closeDrawers(); + break; + + // TODO Enable when "On Device" is recovered ? +// case 2: +// MainApp.showOnlyFilesOnDevice(true); +// mDrawerLayout.closeDrawers(); +// break; + + case 2: // Settings + Intent settingsIntent = new Intent(getApplicationContext(), + Preferences.class); + startActivity(settingsIntent); + break; + + case 3: // Logs + Intent loggerIntent = new Intent(getApplicationContext(), + LogHistoryActivity.class); + startActivity(loggerIntent); + break; + } + } + } } diff --git a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java index 5fd2bdf5..a358f79e 100644 --- a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -19,12 +19,9 @@ package com.owncloud.android.ui.activity; -import java.io.IOException; - import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -141,7 +138,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C if (!stateWasRecovered) { OCFileListFragment listOfFolders = getListOfFilesFragment(); - listOfFolders.listDirectory(folder); + listOfFolders.listDirectory(folder/*, false*/); startSyncFolderOperation(folder, false); } @@ -264,9 +261,6 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); menu.findItem(R.id.action_upload).setVisible(false); - menu.findItem(R.id.action_settings).setVisible(false); - menu.findItem(R.id.action_sync_account).setVisible(false); - menu.findItem(R.id.action_logger).setVisible(false); menu.findItem(R.id.action_sort).setVisible(false); return true; } @@ -312,8 +306,10 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C protected void refreshListOfFilesFragment() { OCFileListFragment fileListFragment = getListOfFilesFragment(); - if (fileListFragment != null) { + if (fileListFragment != null) { fileListFragment.listDirectory(); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(false); } } @@ -322,6 +318,8 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C if (listOfFiles != null) { // should never be null, indeed OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH); listOfFiles.listDirectory(root); + // TODO Enable when "On Device" is recovered ? + // listOfFiles.listDirectory(root, false); setFile(listOfFiles.getCurrentFile()); updateNavigationElementsInActionBar(); startSyncFolderOperation(root, false); @@ -474,6 +472,8 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C OCFileListFragment fileListFragment = getListOfFilesFragment(); if (fileListFragment != null) { fileListFragment.listDirectory(currentDir); + // TODO Enable when "On Device" is recovered ? + // fileListFragment.listDirectory(currentDir, false); } } setFile(currentFile); diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index 23ab550a..ef8c2226 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -54,6 +54,7 @@ import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListAdapter; import android.widget.ListView; +import com.owncloud.android.BuildConfig; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; @@ -203,8 +204,21 @@ public class Preferences extends PreferenceActivity } } + + if (BuildConfig.DEBUG) { + Preference pLog = findPreference("log"); + if (pLog != null ){ + pLog.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent loggerIntent = new Intent(getApplicationContext(),LogHistoryActivity.class); + startActivity(loggerIntent); + return true; + } + }); + } + } - boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled); Preference pRecommend = findPreference("recommend"); if (pRecommend != null){ @@ -223,7 +237,8 @@ public class Preferences extends PreferenceActivity Account currentAccount = AccountUtils.getCurrentOwnCloudAccount(Preferences.this); String username = currentAccount.name.substring(0, currentAccount.name.lastIndexOf('@')); - String recommendSubject = String.format(getString(R.string.recommend_subject), appName); + String recommendSubject = String.format(getString(R.string.recommend_subject), + appName); String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrl, username); diff --git a/src/com/owncloud/android/ui/activity/UploadPathActivity.java b/src/com/owncloud/android/ui/activity/UploadPathActivity.java index d1509f95..db704d14 100644 --- a/src/com/owncloud/android/ui/activity/UploadPathActivity.java +++ b/src/com/owncloud/android/ui/activity/UploadPathActivity.java @@ -20,7 +20,6 @@ package com.owncloud.android.ui.activity; import android.accounts.Account; - import android.os.Bundle; import android.view.View.OnClickListener; @@ -68,7 +67,8 @@ public class UploadPathActivity extends FolderPickerActivity implements FileFrag if (!stateWasRecovered) { OCFileListFragment listOfFolders = getListOfFilesFragment(); - listOfFolders.listDirectory(folder); + // TODO Enable when "On Device" is recovered ? + listOfFolders.listDirectory(folder/*, false*/); startSyncFolderOperation(folder, false); } diff --git a/src/com/owncloud/android/ui/activity/Uploader.java b/src/com/owncloud/android/ui/activity/Uploader.java index f4bd273b..533bb991 100644 --- a/src/com/owncloud/android/ui/activity/Uploader.java +++ b/src/com/owncloud/android/ui/activity/Uploader.java @@ -72,9 +72,9 @@ import com.owncloud.android.R; import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileUploader; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.dialog.LoadingDialog; @@ -326,7 +326,8 @@ public class Uploader extends FileActivity public void onItemClick(AdapterView parent, View view, int position, long id) { // click on folder in the list Log_OC.d(TAG, "on item click"); - Vector tmpfiles = getStorageManager().getFolderContent(mFile); + // TODO Enable when "On Device" is recovered ? + Vector tmpfiles = getStorageManager().getFolderContent(mFile /*, false*/); if (tmpfiles.size() <= 0) return; // filter on dirtype Vector files = new Vector(); @@ -411,7 +412,8 @@ public class Uploader extends FileActivity mFile = getStorageManager().getFileByPath(full_path); if (mFile != null) { - Vector files = getStorageManager().getFolderContent(mFile); + // TODO Enable when "On Device" is recovered ? + Vector files = getStorageManager().getFolderContent(mFile/*, false*/); List> data = new LinkedList>(); for (OCFile f : files) { HashMap h = new HashMap(); diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 2c1aa9e9..c6ea0344 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -407,14 +407,16 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { * @param updatedStorageManager Optional updated storage manager; used to replace * mStorageManager if is different (and not NULL) */ - public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager) { + public void swapDirectory(OCFile directory, FileDataStorageManager updatedStorageManager + /*, boolean onlyOnDevice*/) { mFile = directory; if (updatedStorageManager != null && updatedStorageManager != mStorageManager) { mStorageManager = updatedStorageManager; mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); } if (mStorageManager != null) { - mFiles = mStorageManager.getFolderContent(mFile); + // TODO Enable when "On Device" is recovered ? + mFiles = mStorageManager.getFolderContent(mFile/*, onlyOnDevice*/); mFilesOrig.clear(); mFilesOrig.addAll(mFiles); diff --git a/src/com/owncloud/android/ui/adapter/Group.java b/src/com/owncloud/android/ui/adapter/Group.java new file mode 100644 index 00000000..b01d29c6 --- /dev/null +++ b/src/com/owncloud/android/ui/adapter/Group.java @@ -0,0 +1,15 @@ +package com.owncloud.android.ui.adapter; + +import java.util.ArrayList; +import java.util.List; + +public class Group { + + public String string; + public final List children = new ArrayList(); + + public Group(String string) { + this.string = string; + } + +} \ No newline at end of file diff --git a/src/com/owncloud/android/ui/adapter/MyExpandableListAdapter.java b/src/com/owncloud/android/ui/adapter/MyExpandableListAdapter.java new file mode 100644 index 00000000..20cfdff5 --- /dev/null +++ b/src/com/owncloud/android/ui/adapter/MyExpandableListAdapter.java @@ -0,0 +1,120 @@ +package com.owncloud.android.ui.adapter; + +import android.app.Activity; +import android.util.SparseArray; +import android.view.LayoutInflater; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.BaseExpandableListAdapter; +import android.widget.TextView; +import android.widget.Toast; + +import com.owncloud.android.R; + +public class MyExpandableListAdapter extends BaseExpandableListAdapter { + + private final SparseArray groups; + public LayoutInflater inflater; + public Activity activity; + + public MyExpandableListAdapter(Activity act, SparseArray groups) { + activity = act; + this.groups = groups; + inflater = act.getLayoutInflater(); + + } + + + @Override + public Object getChild(int groupPosition, int childPosition) { + return groups.get(groupPosition).children.get(childPosition); + } + + @Override + public long getChildId(int groupPosition, int childPosition) { + return 0; + } + + @Override + public View getChildView(int groupPosition, final int childPosition, + boolean isLastChild, View convertView, ViewGroup parent) { + final String children = (String) getChild(groupPosition, childPosition); + TextView text = null; + if (convertView == null) { + convertView = inflater.inflate(R.layout.listrow_details, null); + } + + + text = (TextView) convertView.findViewById(R.id.textView1); + text.setText(children); + convertView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(activity, children, Toast.LENGTH_SHORT).show(); + } + }); + return convertView; + } + + @Override + public View getGroupView(int groupPosition, boolean isExpanded, + View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = inflater.inflate(R.layout.listrow_group, null); + } + + final Group group = (Group) getGroup(groupPosition); + if (group.children.size() == 0){ + convertView.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(activity, group.string, Toast.LENGTH_SHORT).show(); + } + }); + } + ((TextView) convertView).setText(group.string); + + return convertView; + } + + @Override + public int getChildrenCount(int groupPosition) { + return groups.get(groupPosition).children.size(); + } + + @Override + public Object getGroup(int groupPosition) { + return groups.get(groupPosition); + } + + @Override + public int getGroupCount() { + return groups.size(); + } + + @Override + public void onGroupCollapsed(int groupPosition) { + super.onGroupCollapsed(groupPosition); + } + + @Override + public void onGroupExpanded(int groupPosition) { + super.onGroupExpanded(groupPosition); + } + + @Override + public long getGroupId(int groupPosition) { + return 0; + } + + @Override + public boolean hasStableIds() { + return false; + } + + @Override + public boolean isChildSelectable(int groupPosition, int childPosition) { + return false; + } +} \ No newline at end of file diff --git a/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java b/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java new file mode 100644 index 00000000..b53f66f4 --- /dev/null +++ b/src/com/owncloud/android/ui/adapter/NavigationDrawerListAdapter.java @@ -0,0 +1,200 @@ +/** + * ownCloud Android client application + * + * @author tobiasKaminsky + * @author masensio + * Copyright (C) 2015 ownCloud Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.owncloud.android.ui.adapter; + +import java.nio.ByteBuffer; +import java.security.MessageDigest; +import java.util.ArrayList; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.content.Context; +import android.graphics.Color; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.LinearLayout; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.RadioGroup.LayoutParams; +import android.widget.TextView; + +import com.owncloud.android.MainApp; +import com.owncloud.android.R; +import com.owncloud.android.authentication.AccountUtils; +import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.ui.NavigationDrawerItem; +import com.owncloud.android.ui.activity.FileDisplayActivity; +import com.owncloud.android.utils.BitmapUtils; + +public class NavigationDrawerListAdapter extends BaseAdapter { + + private final static String TAG = NavigationDrawerListAdapter.class.getSimpleName(); + + private Context mContext; + + private ArrayList mNavigationDrawerItems; + private ArrayList mAll = new ArrayList(); + private Account[] mAccounts; + private boolean mShowAccounts; + private Account mCurrentAccount; + private FileDisplayActivity mFileDisplayActivity; + + + public NavigationDrawerListAdapter(Context context, FileDisplayActivity fileDisplayActivity, + ArrayList navigationDrawerItems){ + mFileDisplayActivity = fileDisplayActivity; + mContext = context; + mNavigationDrawerItems = navigationDrawerItems; + + updateAccountList(); + + mAll.addAll(mNavigationDrawerItems); + } + + public void updateAccountList(){ + AccountManager am = (AccountManager) mContext.getSystemService(mContext.ACCOUNT_SERVICE); + mAccounts = am.getAccountsByType(MainApp.getAccountType()); + mCurrentAccount = AccountUtils.getCurrentOwnCloudAccount(mContext); + } + + @Override + public int getCount() { + if (mShowAccounts){ + return mNavigationDrawerItems.size() + 1; + } else { + return mNavigationDrawerItems.size(); + } + } + + @Override + public Object getItem(int position) { + //return all.get(position); + return null; + } + + @Override + public long getItemId(int position) { + return 0; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + + LayoutInflater inflator = (LayoutInflater) mContext + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + if (mAll.size() > position) { + // Normal entry + if (mAll.get(position) instanceof NavigationDrawerItem){ + NavigationDrawerItem navItem = (NavigationDrawerItem) mAll.get(position); + + View view = inflator.inflate(R.layout.drawer_list_item, null); + view.setMinimumHeight(40); + LinearLayout itemLayout = (LinearLayout) view.findViewById(R.id.itemLayout); + itemLayout.setContentDescription(navItem.getContentDescription()); + TextView itemText = (TextView) view.findViewById(R.id.itemTitle); + itemText.setText(navItem.getTitle()); + + return view; + } + + // Account + if (mAll.get(position) instanceof Account[]){ + final View view = inflator.inflate(R.layout.drawer_account_group, null); + + final RadioGroup group = (RadioGroup) view.findViewById(R.id.drawer_radio_group); + + for (Account account : mAccounts) { + RadioButton rb = new RadioButton(mContext); + rb.setText(account.name); + rb.setContentDescription(account.name); + + try { + byte[] bytesOfMessage = account.name.substring(0,5).getBytes("UTF-8"); + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] digest = md.digest(bytesOfMessage); + int result = Math.abs(ByteBuffer.wrap(digest).getInt()); + + Log_OC.d(TAG, "Integer: " + result % 100000); + Log_OC.d(TAG, "length: " + digest.length); + + + Double hue = (result % 100000) / 99999.0; + + Log_OC.d(TAG, "hue: " + hue); + + int[] rgb = BitmapUtils.hslToRgb(hue, 0.9, 0.65); + rb.setTextColor(Color.rgb(rgb[0], rgb[1], rgb[2])); + Log_OC.d(TAG, "Color: " + rgb[0] + " " + rgb[1] + rgb[2]); + + } catch (Exception e){ + Log_OC.d(TAG, e.toString()); + rb.setTextColor(mContext.getResources().getColor(R.color.black)); + } + RadioGroup.LayoutParams params = new RadioGroup.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); + params.weight=1.0f; + params.setMargins(15, 5, 5, 5); + + // Check the current account that is being used + if (account.name.equals(mCurrentAccount.name)) { + rb.setChecked(true); + } else { + rb.setChecked(false); + } + + group.addView(rb, params); + } + + group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ + public void onCheckedChanged(RadioGroup group, int checkedId) { + // checkedId is the RadioButton selected + RadioButton rb = (RadioButton) view.findViewById(checkedId); + + AccountUtils.setCurrentOwnCloudAccount(mContext,rb.getText().toString()); + notifyDataSetChanged(); + mFileDisplayActivity.closeDrawer(); + + // restart the main activity + mFileDisplayActivity.restart(); + } + }); + + return view; + } + } + return convertView; + } + + // TODO update Account List after creating a new account and on fresh installation + public void setShowAccounts(boolean value){ + mAll.clear(); + mAll.addAll(mNavigationDrawerItems); + + if (value){ + mAll.add(1, mAccounts); + } + mShowAccounts = value; + } +} diff --git a/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java b/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java index 782ed04d..3045b278 100644 --- a/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java +++ b/src/com/owncloud/android/ui/dialog/RemoveFileDialogFragment.java @@ -112,7 +112,8 @@ implements ConfirmationDialogFragmentListener { boolean containsKeepInSync = false; if (mTargetFile.isFolder()) { - Vector files = storageManager.getFolderContent(mTargetFile); + // TODO Enable when "On Device" is recovered ? + Vector files = storageManager.getFolderContent(mTargetFile/*, false*/); for(OCFile file: files) { containsKeepInSync = file.keepInSync() || containsKeepInSync; diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index ed97de0b..dd8ed029 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -77,7 +77,8 @@ public class OCFileListFragment extends ExtendedListFragment { private boolean mJustFolders; private OCFile mTargetFile; - + + /** * {@inheritDoc} @@ -182,8 +183,9 @@ public class OCFileListFragment extends ExtendedListFragment { moveCount++; } // exit is granted because storageManager.getFileByPath("/") never returns null mFile = parentDir; - - listDirectory(mFile); + + // TODO Enable when "On Device" is recovered ? + listDirectory(mFile /*, MainApp.getOnlyOnDevice()*/); onRefresh(false); @@ -201,7 +203,8 @@ public class OCFileListFragment extends ExtendedListFragment { if (file != null) { if (file.isFolder()) { // update state and view of this fragment - listDirectory(file); + // TODO Enable when "On Device" is recovered ? + listDirectory(file/*, MainApp.getOnlyOnDevice()*/); // then, notify parent activity to let it update its state and view mContainerActivity.onBrowsedDownTo(file); // save index and top position @@ -355,8 +358,15 @@ public class OCFileListFragment extends ExtendedListFragment { /** * Calls {@link OCFileListFragment#listDirectory(OCFile)} with a null parameter */ - public void listDirectory(){ + public void listDirectory(/*boolean onlyOnDevice*/){ listDirectory(null); + // TODO Enable when "On Device" is recovered ? + // listDirectory(null, onlyOnDevice); + } + + public void refreshDirectory(){ + // TODO Enable when "On Device" is recovered ? + listDirectory(getCurrentFile()/*, MainApp.getOnlyOnDevice()*/); } /** @@ -366,7 +376,7 @@ public class OCFileListFragment extends ExtendedListFragment { * * @param directory File to be listed */ - public void listDirectory(OCFile directory) { + public void listDirectory(OCFile directory/*, boolean onlyOnDevice*/) { FileDataStorageManager storageManager = mContainerActivity.getStorageManager(); if (storageManager != null) { @@ -387,7 +397,8 @@ public class OCFileListFragment extends ExtendedListFragment { directory = storageManager.getFileById(directory.getParentId()); } - mAdapter.swapDirectory(directory, storageManager); + // TODO Enable when "On Device" is recovered ? + mAdapter.swapDirectory(directory, storageManager/*, onlyOnDevice*/); if (mFile == null || !mFile.equals(directory)) { mCurrentListView.setSelection(0); } @@ -459,5 +470,7 @@ public class OCFileListFragment extends ExtendedListFragment { public void sortBySize(boolean descending) { mAdapter.setSortOrder(FileStorageUtils.SORT_SIZE, descending); } - + + + } diff --git a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java index 6dc87cbb..a67788a2 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java @@ -140,8 +140,11 @@ public class PreviewImageActivity extends FileActivity implements // should not be necessary parentFolder = getStorageManager().getFileByPath(OCFile.ROOT_PATH); } + + // TODO Enable when "On Device" is recovered ? mPreviewImagePagerAdapter = new PreviewImagePagerAdapter(getSupportFragmentManager(), - parentFolder, getAccount(), getStorageManager()); + parentFolder, getAccount(), getStorageManager()/*, MainApp.getOnlyOnDevice()*/); + mViewPager = (ExtendedViewPager) findViewById(R.id.fragmentPager); int position = mHasSavedPosition ? mSavedPosition : mPreviewImagePagerAdapter.getFilePosition(getFile()); diff --git a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java index 6e7f19d4..dda7dda2 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java +++ b/src/com/owncloud/android/ui/preview/PreviewImagePagerAdapter.java @@ -19,8 +19,6 @@ */ package com.owncloud.android.ui.preview; -import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -36,7 +34,6 @@ import android.view.ViewGroup; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.ui.adapter.FileListListAdapter; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.utils.FileStorageUtils; @@ -58,11 +55,14 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { /** * Constructor. * - * @param fragmentManager {@link FragmentManager} instance that will handle the {@link Fragment}s provided by the adapter. + * @param fragmentManager {@link FragmentManager} instance that will handle + * the {@link Fragment}s provided by the adapter. * @param parentFolder Folder where images will be searched for. * @param storageManager Bridge to database. */ - public PreviewImagePagerAdapter(FragmentManager fragmentManager, OCFile parentFolder, Account account, FileDataStorageManager storageManager) { + public PreviewImagePagerAdapter(FragmentManager fragmentManager, OCFile parentFolder, + Account account, FileDataStorageManager storageManager /*, + boolean onlyOnDevice*/) { super(fragmentManager); if (fragmentManager == null) { @@ -77,7 +77,8 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { mAccount = account; mStorageManager = storageManager; - mImageFiles = mStorageManager.getFolderImages(parentFolder); + // TODO Enable when "On Device" is recovered ? + mImageFiles = mStorageManager.getFolderImages(parentFolder/*, false*/); mImageFiles = FileStorageUtils.sortFolder(mImageFiles); @@ -102,7 +103,8 @@ public class PreviewImagePagerAdapter extends FragmentStatePagerAdapter { OCFile file = mImageFiles.get(i); Fragment fragment = null; if (file.isDown()) { - fragment = PreviewImageFragment.newInstance(file, mObsoletePositions.contains(Integer.valueOf(i))); + fragment = PreviewImageFragment.newInstance(file, + mObsoletePositions.contains(Integer.valueOf(i))); } else if (mDownloadErrors.contains(Integer.valueOf(i))) { fragment = FileDownloadFragment.newInstance(file, mAccount, true); diff --git a/src/com/owncloud/android/utils/BitmapUtils.java b/src/com/owncloud/android/utils/BitmapUtils.java index 7b9382e6..7af6960f 100644 --- a/src/com/owncloud/android/utils/BitmapUtils.java +++ b/src/com/owncloud/android/utils/BitmapUtils.java @@ -178,6 +178,46 @@ public class BitmapUtils { } /** + * Converts an HSL color value to RGB. Conversion formula + * adapted from http://en.wikipedia.org/wiki/HSL_color_space. + * Assumes h, s, and l are contained in the set [0, 1] and + * returns r, g, and b in the set [0, 255]. + * from: http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c + * + * @param integer h The hue + * @param Integer s The saturation + * @param Integer l The lightness + * @return Array The RGB representation + */ + public static int[] hslToRgb(Double h, Double s, Double l){ + Double r, g, b; + + if(s == 0){ + r = g = b = l; // achromatic + } else { + Double q = l < 0.5 ? l * (1 + s) : l + s - l * s; + Double p = 2 * l - q; + r = hue2rgb(p, q, h + 1/3) * 255; + g = hue2rgb(p, q, h) * 255; + b = hue2rgb(p, q, h - 1/3) * 255; + } + + + int[] array = {r.intValue(), g.intValue(), b.intValue()}; + return array; + } + + private static Double hue2rgb(Double p, Double q, Double t){ + if(t < 0) t += 1; + if(t > 1) t -= 1; + if(t < 1/6) return p + (q - p) * 6 * t; + if(t < 1/2) return q; + if(t < 2/3) return p + (q - p) * (2/3 - t) * 6; + return p; + } + + + /** * Checks if file passed is an image * @param file * @return true/false