[Libreoffice-commits] online.git: 13 commits - android/app android/lib
Jan Holesovsky (via logerrit)
logerrit at kemper.freedesktop.org
Thu Feb 20 13:53:41 UTC 2020
android/app/build.gradle | 9
android/app/src/main/AndroidManifest.xml | 4
android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderFactory.java | 118 -
android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderSettingsActivity.java | 107 -
android/app/src/main/java/org/libreoffice/androidapp/storage/IDocumentProvider.java | 72
android/app/src/main/java/org/libreoffice/androidapp/storage/IFile.java | 118 -
android/app/src/main/java/org/libreoffice/androidapp/storage/IOUtils.java | 56
android/app/src/main/java/org/libreoffice/androidapp/storage/external/BrowserSelectorActivity.java | 173 --
android/app/src/main/java/org/libreoffice/androidapp/storage/external/DirectoryBrowserActivity.java | 43
android/app/src/main/java/org/libreoffice/androidapp/storage/external/DirectoryBrowserFragment.java | 200 --
android/app/src/main/java/org/libreoffice/androidapp/storage/external/ExternalFile.java | 176 --
android/app/src/main/java/org/libreoffice/androidapp/storage/external/ExtsdDocumentsProvider.java | 184 --
android/app/src/main/java/org/libreoffice/androidapp/storage/external/IExternalDocumentProvider.java | 22
android/app/src/main/java/org/libreoffice/androidapp/storage/external/OTGDocumentsProvider.java | 93 -
android/app/src/main/java/org/libreoffice/androidapp/storage/local/LocalDocumentsDirectoryProvider.java | 74
android/app/src/main/java/org/libreoffice/androidapp/storage/local/LocalDocumentsProvider.java | 60
android/app/src/main/java/org/libreoffice/androidapp/storage/local/LocalFile.java | 103 -
android/app/src/main/java/org/libreoffice/androidapp/storage/owncloud/OwnCloudFile.java | 196 --
android/app/src/main/java/org/libreoffice/androidapp/storage/owncloud/OwnCloudProvider.java | 192 --
android/app/src/main/java/org/libreoffice/androidapp/ui/FileUtilities.java | 4
android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java | 811 ++--------
android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java | 87 -
android/app/src/main/res/drawable/ic_list_black_24dp.xml | 9
android/app/src/main/res/drawable/ic_view_module_black_24dp.xml | 9
android/app/src/main/res/layout/activity_document_browser.xml | 74
android/app/src/main/res/layout/file_explorer_grid_item.xml | 28
android/app/src/main/res/menu/view_menu.xml | 11
android/app/src/main/res/values/arrays.xml | 9
android/app/src/main/res/values/integers.xml | 4
android/app/src/main/res/xml/libreoffice_preferences.xml | 8
android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java | 66
31 files changed, 409 insertions(+), 2711 deletions(-)
New commits:
commit bd3aba415db6feac272134be2c822b05efadd045
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Thu Feb 20 12:41:14 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Avoid deadlock when saving to Nextcloud.
The actual saving to Nextcloud takes time, so what happened was that the
LOOLWSD instance managed to tear down itself, new one was created, and
only after that the onPause() was called - which then tried to send the
"save ...", but there was nothing that could actually receive that.
Change-Id: I3c503461dc7d7e9c2e784911931ddc36b382cc5e
diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
index 23758b23e..9b6c5d168 100644
--- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
@@ -532,6 +532,7 @@ public class LOActivity extends AppCompatActivity {
// Most probably the native part has already got a 'BYE' from
// finishWithProgress(), but it is actually better to send it twice
// than never, so let's call it from here too anyway
+ documentLoaded = false;
postMobileMessageNative("BYE");
}
@@ -620,6 +621,7 @@ public class LOActivity extends AppCompatActivity {
mainHandler.post(new Runnable() {
@Override
public void run() {
+ documentLoaded = false;
postMobileMessageNative("BYE");
copyTempBackToIntent();
commit 49272da0a64262d29931d45aaf64fcdeb21efb58
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Thu Feb 20 12:31:11 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Simplify the loading & saving of the document.
Change-Id: Ib759adfbddec9f254bf9c9e2ba8a6bba08033cce
diff --git a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
index 9af5eb267..23758b23e 100644
--- a/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
+++ b/android/lib/src/main/java/org/libreoffice/androidlib/LOActivity.java
@@ -425,8 +425,9 @@ public class LOActivity extends AppCompatActivity {
/** When we get the file via a content: URI, we need to put it to a temp file. */
private boolean copyFileToTemp() {
ContentResolver contentResolver = getContentResolver();
- FileChannel inputChannel = null;
- FileChannel outputChannel = null;
+ InputStream inputStream = null;
+ OutputStream outputStream = null;
+
// CSV files need a .csv suffix to be opened in Calc.
String suffix = null;
String intentType = getIntent().getType();
@@ -436,25 +437,24 @@ public class LOActivity extends AppCompatActivity {
try {
try {
- AssetFileDescriptor assetFD = contentResolver.openAssetFileDescriptor(getIntent().getData(), "r");
- if (assetFD == null) {
- Log.e(TAG, "couldn't create assetfiledescriptor from " + getIntent().getDataString());
- return false;
- }
- inputChannel = assetFD.createInputStream().getChannel();
+ Uri uri = getIntent().getData();
+ inputStream = contentResolver.openInputStream(uri);
+
mTempFile = File.createTempFile("LibreOffice", suffix, this.getCacheDir());
+ outputStream = new FileOutputStream(mTempFile);
- outputChannel = new FileOutputStream(mTempFile).getChannel();
- long bytesTransferred = 0;
- // might not copy all at once, so make sure everything gets copied....
- while (bytesTransferred < inputChannel.size()) {
- bytesTransferred += outputChannel.transferFrom(inputChannel, bytesTransferred, inputChannel.size());
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = inputStream.read(buffer)) > 0) {
+ outputStream.write(buffer, 0, length);
}
- Log.e(TAG, "Success copying " + bytesTransferred + " bytes");
+ Log.e(TAG, "Success copying from " + uri + " to " + mTempFile);
return true;
} finally {
- if (inputChannel != null) inputChannel.close();
- if (outputChannel != null) outputChannel.close();
+ if (inputStream != null)
+ inputStream.close();
+ if (outputStream != null)
+ outputStream.close();
}
} catch (FileNotFoundException e) {
return false;
@@ -469,28 +469,26 @@ public class LOActivity extends AppCompatActivity {
return;
ContentResolver contentResolver = getContentResolver();
- FileChannel inputChannel = null;
- FileChannel outputChannel = null;
+ InputStream inputStream = null;
+ OutputStream outputStream = null;
try {
try {
- AssetFileDescriptor assetFD = contentResolver.openAssetFileDescriptor(getIntent().getData(), "w");
- if (assetFD == null) {
- Log.e(TAG, "couldn't create assetfiledescriptor from " + getIntent().getDataString());
- return;
- }
- outputChannel = assetFD.createOutputStream().getChannel();
- inputChannel = new FileInputStream(mTempFile).getChannel();
-
- long bytesTransferred = 0;
- // might not copy all at once, so make sure everything gets copied....
- while (bytesTransferred < inputChannel.size()) {
- bytesTransferred += outputChannel.transferFrom(inputChannel, bytesTransferred, inputChannel.size());
+ Uri uri = getIntent().getData();
+ outputStream = contentResolver.openOutputStream(uri);
+ inputStream = new FileInputStream(mTempFile);
+
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = inputStream.read(buffer)) > 0) {
+ outputStream.write(buffer, 0, length);
}
- Log.e(TAG, "Success copying " + bytesTransferred + " bytes");
+ Log.e(TAG, "Success copying from " + mTempFile + " to " + uri);
} finally {
- if (inputChannel != null) inputChannel.close();
- if (outputChannel != null) outputChannel.close();
+ if (inputStream != null)
+ inputStream.close();
+ if (outputStream != null)
+ outputStream.close();
}
} catch (FileNotFoundException e) {
Log.e(TAG, "file not found: " + e.getMessage());
commit b2faff47f1e44a085ec76ed24d785e94fa57bfe7
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Thu Feb 20 11:45:49 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Create new file using the appropriate Intent too.
Instead of a home-grown input dialog.
Change-Id: I04e9f2fe2a093301d7702faf9a454d05494a3ee4
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index a1ed3de3e..91c71116f 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -114,10 +114,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
public static final String NEW_FILE_PATH_KEY = "NEW_FILE_PATH_KEY";
public static final String NEW_DOC_TYPE_KEY = "NEW_DOC_TYPE_KEY";
- public static final String NEW_WRITER_STRING_KEY = "private:factory/swriter";
- public static final String NEW_IMPRESS_STRING_KEY = "private:factory/simpress";
- public static final String NEW_CALC_STRING_KEY = "private:factory/scalc";
- public static final String NEW_DRAW_STRING_KEY = "private:factory/sdraw";
public static final String GRID_VIEW = "0";
public static final String LIST_VIEW = "1";
@@ -148,6 +144,9 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
/** Request code to evaluate that we are returning from the LOActivity. */
private static final int LO_ACTIVITY_REQUEST_CODE = 42;
private static final int OPEN_FILE_REQUEST_CODE = 43;
+ private static final int CREATE_DOCUMENT_REQUEST_CODE = 44;
+ private static final int CREATE_SPREADSHEET_REQUEST_CODE = 45;
+ private static final int CREATE_PRESENTATION_REQUEST_CODE = 46;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -429,121 +428,36 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
startActivityForResult(i, LO_ACTIVITY_REQUEST_CODE);
}
- // Opens an Input dialog to get the name of new file
- private void createNewFileInputDialog(final String defaultFileName, final String newDocumentType, final String extension) {
- LayoutInflater inflater = getLayoutInflater();
- View view = inflater.inflate(R.layout.dialog_create_file, null);
-
- // file name input
- final EditText input = (EditText)view.findViewById(R.id.fileName);
- input.setText(defaultFileName);
- input.setSelection(0, input.getText().toString().lastIndexOf('.'));
- input.requestFocus();
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-
- // We should just focus on the input EditText so the keyboard would hide automatically.
- // imm.showSoftInput(input,0); Should be enough, alas this is the wrong place, so doesn't work.
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
-
- // warning text to notify the user that such a file already exists
- final TextView warningText = (TextView)view.findViewById(R.id.overwriteWarning);
-
- // check if the file exists when showing the create dialog
- //File tempFile = new File(currentDirectory.getUri().getPath() + input.getText().toString());
- //warningText.setVisibility(tempFile.exists() ? View.VISIBLE : View.GONE);
-
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.create_new_document_title)
- .setView(view)
- .setPositiveButton(/*tempFile.exists() ? R.string.action_overwrite :*/ R.string.action_create, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // Hide the keyboard, which we show forcefully.
- imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
-
- /*
- final String path = currentDirectory.getUri().getPath() + input.getText().toString();
- Uri newDocUri = createNewFile(path, extension);
- if (newDocUri != null) {
- Intent i = new Intent(Intent.ACTION_VIEW, newDocUri);
-
- String packageName = getApplicationContext().getPackageName();
- ComponentName componentName = new ComponentName(packageName, LOActivity.class.getName());
- i.setComponent(componentName);
-
- //i.putExtra("org.libreoffice.document_provider_id", documentProvider.getId());
- i.putExtra("org.libreoffice.document_uri", newDocUri);
-
- startActivityForResult(i, LO_ACTIVITY_REQUEST_CODE);
- } else {
- Toast.makeText(LibreOfficeUIActivity.this, getString(R.string.file_creation_failed), Toast.LENGTH_SHORT).show();
- }
- */
- }
- })
- .setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
+ /** Opens an Input dialog to get the name of new file. */
+ private void createNewFileInputDialog(final String defaultFileName, final String mimeType, final int requestCode) {
+ Intent i = new Intent(Intent.ACTION_CREATE_DOCUMENT);
- // Hide the keyboard, which we show forcefully.
- imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
+ // The mime type and category must be set
+ i.setType(mimeType);
+ i.addCategory(Intent.CATEGORY_OPENABLE);
- dialog.cancel();
- }
- });
+ i.putExtra(Intent.EXTRA_TITLE, defaultFileName);
- final AlertDialog alertDialog = builder.show();
-
- // check if a file with this name already exists and notify the user
- input.addTextChangedListener(new TextWatcher() {
- @Override
- public void onTextChanged(CharSequence c, int start, int before, int count) {
- Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- boolean emptyInput = input.getText().toString().isEmpty();
-
- /*File tempFile = new File(currentDirectory.getUri().getPath() + input.getText().toString());
- if (!emptyInput && tempFile.exists()) {
- warningText.setVisibility(View.VISIBLE);
- positiveButton.setText(R.string.action_overwrite);
- }
- else {
- warningText.setVisibility(View.GONE);
- positiveButton.setText(R.string.action_create);
- }*/
-
- // hide the button completely if empty
- if (emptyInput)
- positiveButton.setVisibility(View.GONE);
- else
- positiveButton.setVisibility(View.VISIBLE);
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- }
+ // TODO remember where the user picked the file the last time
+ // TODO and that should default to Context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)
+ //i.putExtra(DocumentsContract.EXTRA_INITIAL_URI, previousDirectoryPath);
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- });
+ startActivityForResult(i, requestCode);
}
/**
* Creates a new file at the specified path, by copying an empty template to that location.
*
- * @param path the complete path (including the file name) where the file will be created
+ * @param uri uri that we should overwrite with the new file content
* @param extension is required to know what template should be used when creating the document
- * @return Uri of newFile if newFile is successfully created else null
*/
- private Uri createNewFile(final String path, final String extension) {
+ private void createNewFile(final Uri uri, final String extension) {
InputStream templateFileStream = null;
- //create a new file where the template will be written
- File newFile = new File(path);
OutputStream newFileStream = null;
try {
//read the template and copy it to the new file
- templateFileStream = getAssets().open("templates/untitled" + extension);
- newFileStream = new FileOutputStream(newFile);
+ templateFileStream = getAssets().open("templates/untitled." + extension);
+ newFileStream = getContentResolver().openOutputStream(uri);
byte[] buffer = new byte[1024];
int length;
while ((length = templateFileStream.read(buffer)) > 0) {
@@ -551,7 +465,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
} catch (IOException e) {
e.printStackTrace();
- return null;
} finally {
try {
//close the streams
@@ -561,7 +474,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
e.printStackTrace();
}
}
- return Uri.fromFile(newFile);
}
/** Context menu item handling. */
@@ -679,6 +591,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private void openDocument() {
Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
+ i.addCategory(Intent.CATEGORY_OPENABLE);
+
// set only the allowed mime types
// NOTE: If updating the list here, also check the AndroidManifest.xml,
// I didn't find a way how to do it from one central place :-(
@@ -932,13 +846,17 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
/** Uploading back when we return from the LOActivity. */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == LO_ACTIVITY_REQUEST_CODE) {
- // TODO probably kill this, we don't need to do anything here any more
- Log.d(LOGTAG, "LOActivity has finished.");
- }
- else if (requestCode == OPEN_FILE_REQUEST_CODE) {
- Log.d(LOGTAG, "File open chooser has finished, starting the LOActivity.");
- if (resultCode == RESULT_OK && data != null) {
+ switch (requestCode) {
+ case LO_ACTIVITY_REQUEST_CODE: {
+ // TODO probably kill this, we don't need to do anything here any more
+ Log.d(LOGTAG, "LOActivity has finished.");
+ break;
+ }
+ case OPEN_FILE_REQUEST_CODE: {
+ Log.d(LOGTAG, "File open chooser has finished, starting the LOActivity.");
+ if (resultCode != RESULT_OK || data == null)
+ return;
+
Uri uri = data.getData();
if (uri == null)
return;
@@ -946,6 +864,22 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
open(uri);
+ break;
+ }
+ case CREATE_DOCUMENT_REQUEST_CODE:
+ case CREATE_SPREADSHEET_REQUEST_CODE:
+ case CREATE_PRESENTATION_REQUEST_CODE: {
+ if (resultCode != RESULT_OK || data == null)
+ return;
+
+ Uri uri = data.getData();
+ getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+
+ String extension = (requestCode == CREATE_DOCUMENT_REQUEST_CODE)? "odt": ((requestCode == CREATE_SPREADSHEET_REQUEST_CODE)? "ods": "odp");
+ createNewFile(uri, extension);
+
+ open(uri);
+ break;
}
}
}
@@ -1084,13 +1018,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
break;
case R.id.newWriterFAB:
- createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_WRITER_EXTENSION, NEW_WRITER_STRING_KEY, FileUtilities.DEFAULT_WRITER_EXTENSION);
+ createNewFileInputDialog(getString(R.string.new_textdocument) + FileUtilities.DEFAULT_WRITER_EXTENSION, "application/vnd.oasis.opendocument.text", CREATE_DOCUMENT_REQUEST_CODE);
break;
case R.id.newImpressFAB:
- createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_IMPRESS_EXTENSION, NEW_IMPRESS_STRING_KEY, FileUtilities.DEFAULT_IMPRESS_EXTENSION);
+ createNewFileInputDialog(getString(R.string.new_presentation) + FileUtilities.DEFAULT_IMPRESS_EXTENSION, "application/vnd.oasis.opendocument.presentation", CREATE_PRESENTATION_REQUEST_CODE);
break;
case R.id.newCalcFAB:
- createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_SPREADSHEET_EXTENSION, NEW_CALC_STRING_KEY, FileUtilities.DEFAULT_SPREADSHEET_EXTENSION);
+ createNewFileInputDialog(getString(R.string.new_spreadsheet) + FileUtilities.DEFAULT_SPREADSHEET_EXTENSION, "application/vnd.oasis.opendocument.spreadsheet", CREATE_SPREADSHEET_REQUEST_CODE);
break;
}
}
commit cd75360469c3538b4d7dd4d777020b4f55d09b99
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Thu Feb 20 00:22:49 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Keep the order of the recent files.
Change-Id: I1b8a60126228cc59cd3d308f44244b3ee3db7413
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index 80aba41d5..a1ed3de3e 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -29,6 +29,7 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.Editable;
+import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.ContextMenu;
@@ -68,8 +69,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.Arrays;
+import java.util.List;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
@@ -108,7 +109,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
public static final String EXPLORER_VIEW_TYPE_KEY = "EXPLORER_VIEW_TYPE";
public static final String EXPLORER_PREFS_KEY = "EXPLORER_PREFS";
public static final String SORT_MODE_KEY = "SORT_MODE";
- private static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENTS";
+ private static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENTS_LIST";
private static final String ENABLE_SHOW_HIDDEN_FILES_KEY = "ENABLE_SHOW_HIDDEN_FILES";
public static final String NEW_FILE_PATH_KEY = "NEW_FILE_PATH_KEY";
@@ -177,6 +178,15 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
fabCloseAnimation = AnimationUtils.loadAnimation(this, R.anim.fab_close);
}
+ private String[] getRecentDocuments() {
+ String joinedStrings = prefs.getString(RECENT_DOCUMENTS_KEY, "");
+ if (joinedStrings.isEmpty())
+ return new String[]{};
+
+ // we are using \n as delimiter
+ return joinedStrings.split("\n", 0);
+ }
+
/** Update the recent files list. */
public void updateRecentFiles() {
// update also the icon switching between list and grid
@@ -185,7 +195,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
else
mRecentFilesListOrGrid.setImageResource(R.drawable.ic_list_black_24dp);
- Set<String> recentFileStrings = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>());
+ String[] recentFileStrings = getRecentDocuments();
final ArrayList<Uri> recentUris = new ArrayList<Uri>();
for (String recentFileString : recentFileStrings) {
@@ -989,13 +999,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private void addDocumentToRecents(Uri uri) {
String newRecent = uri.toString();
- Set<String> recentsSet = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>());
- //create array to work with
- ArrayList<String> recentsArrayList = new ArrayList<String>(recentsSet);
+ // Create array to work with (have to copy the content)
+ ArrayList<String> recentsArrayList = new ArrayList<String>(Arrays.asList(getRecentDocuments()));
//remove string if present, so that it doesn't appear multiple times
- recentsSet.remove(newRecent);
+ recentsArrayList.remove(newRecent);
//put the new value in the first place
recentsArrayList.add(0, newRecent);
@@ -1003,14 +1012,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
final int RECENTS_SIZE = 30;
while (recentsArrayList.size() > RECENTS_SIZE) {
- recentsArrayList.remove(RECENTS_SIZE);
+ recentsArrayList.remove(recentsArrayList.size() - 1);
}
- //switch to Set, so that it could be inserted into prefs
- recentsSet = new HashSet<String>(recentsArrayList);
-
- prefs.edit().putStringSet(RECENT_DOCUMENTS_KEY, recentsSet).apply();
-
+ // Join the array, use \n's as delimiters
+ String joined = TextUtils.join("\n", recentsArrayList);
+ prefs.edit().putString(RECENT_DOCUMENTS_KEY, joined).apply();
//update app shortcuts (7.0 and above)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
@@ -1021,6 +1028,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
ArrayList<ShortcutInfo> shortcuts = new ArrayList<ShortcutInfo>();
for (String pathString : recentsArrayList) {
+ if (pathString.isEmpty())
+ continue;
//find the appropriate drawable
int drawable = 0;
@@ -1039,6 +1048,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
break;
}
+ // TODO better way to get the filename for content: uris
File file = new File(pathString);
//for some reason, getName uses %20 instead of space
commit d87caa292023f866eb079a569285eb2d3889be6f
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 19 23:10:44 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Center text under the icons for better look.
Change-Id: Ib9a466290558577105f87ba0eab038931b093789
diff --git a/android/app/src/main/res/layout/file_explorer_grid_item.xml b/android/app/src/main/res/layout/file_explorer_grid_item.xml
index e64fdc23a..d36de5d8a 100644
--- a/android/app/src/main/res/layout/file_explorer_grid_item.xml
+++ b/android/app/src/main/res/layout/file_explorer_grid_item.xml
@@ -15,28 +15,28 @@
<ImageView
android:id="@+id/file_item_icon"
- tools:src="@drawable/ic_folder_black_24dp"
- tools:tint="@color/text_color_secondary"
- android:layout_width="100dp"
+ android:layout_width="match_parent"
android:layout_height="100dp"
- android:scaleType="fitStart"
android:layout_gravity="center"
- android:contentDescription="@string/file_icon_desc" >
- </ImageView>
+ android:contentDescription="@string/file_icon_desc"
+ android:scaleType="fitCenter"
+ tools:src="@drawable/ic_folder_black_24dp"
+ tools:tint="@color/text_color_secondary"/>
<TextView
android:id="@+id/file_item_name"
- tools:text="file or dirname"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:layout_height="40dp"
+ android:layout_gravity="center"
+ android:layout_marginTop="4dp"
+ android:gravity="center_vertical"
+ android:maxLines="2"
android:paddingLeft="10dp"
android:paddingRight="10dp"
- android:paddingTop="10dp"
- android:layout_gravity="center"
+ android:textAlignment="center"
+ android:textColor="@android:color/secondary_text_light"
android:textSize="15sp"
android:textStyle="bold"
- android:textColor="@android:color/secondary_text_light"
- android:maxLines="2">
- </TextView>
+ tools:text="file or dirname"/>
</LinearLayout>
commit b00c6b105b1f7a24774e09a9e4d42143a81c31fc
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 19 22:22:24 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Switch between grid and list directly on the main screen.
Change-Id: I668bacc0206af7f72a434296806c9149a6edda9e
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index 6d78fe857..80aba41d5 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -10,7 +10,6 @@
package org.libreoffice.androidapp.ui;
import android.Manifest;
-import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -19,14 +18,12 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
-import android.content.UriPermission;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.hardware.usb.UsbManager;
import android.net.Uri;
-import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
@@ -42,8 +39,6 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
-import android.view.View.OnLongClickListener;
-import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.OvershootInterpolator;
@@ -72,14 +67,8 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import androidx.annotation.NonNull;
@@ -89,7 +78,6 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
-import androidx.core.content.FileProvider;
import androidx.core.view.ViewCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@@ -101,7 +89,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private String LOGTAG = LibreOfficeUIActivity.class.getSimpleName();
private SharedPreferences prefs;
private int filterMode = FileUtilities.ALL;
- private int viewMode;
private int sortMode;
private boolean showHiddenFiles;
@@ -131,8 +118,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
public static final String NEW_CALC_STRING_KEY = "private:factory/scalc";
public static final String NEW_DRAW_STRING_KEY = "private:factory/sdraw";
- public static final int GRID_VIEW = 0;
- public static final int LIST_VIEW = 1;
+ public static final String GRID_VIEW = "0";
+ public static final String LIST_VIEW = "1";
private DrawerLayout drawerLayout;
private NavigationView navigationDrawer;
@@ -154,6 +141,9 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private LinearLayout impressLayout;
private LinearLayout calcLayout;
+ /** Recent files list vs. grid switch. */
+ private ImageView mRecentFilesListOrGrid;
+
/** Request code to evaluate that we are returning from the LOActivity. */
private static final int LO_ACTIVITY_REQUEST_CODE = 42;
private static final int OPEN_FILE_REQUEST_CODE = 43;
@@ -188,7 +178,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
/** Update the recent files list. */
- public void updateRecentFilesAdapter() {
+ public void updateRecentFiles() {
+ // update also the icon switching between list and grid
+ if (isViewModeList())
+ mRecentFilesListOrGrid.setImageResource(R.drawable.ic_view_module_black_24dp);
+ else
+ mRecentFilesListOrGrid.setImageResource(R.drawable.ic_list_black_24dp);
+
Set<String> recentFileStrings = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>());
final ArrayList<Uri> recentUris = new ArrayList<Uri>();
@@ -232,7 +228,17 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
recentRecyclerView = findViewById(R.id.list_recent);
noRecentItemsTextView = findViewById(R.id.no_recent_items_msg);
- updateRecentFilesAdapter();
+ // Icon to switch showing the recent files as list vs. as grid
+ mRecentFilesListOrGrid = (ImageView) findViewById(R.id.recent_list_or_grid);
+ mRecentFilesListOrGrid.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ toggleViewMode();
+ updateRecentFiles();
+ }
+ });
+
+ updateRecentFiles();
//registerForContextMenu(fileRecyclerView);
@@ -337,7 +343,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private void refreshView() {
// refresh view
- updateRecentFilesAdapter();
+ updateRecentFiles();
// close drawer if it was open
drawerLayout.closeDrawer(navigationDrawer);
@@ -384,7 +390,15 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
public boolean isViewModeList() {
- return viewMode == LIST_VIEW;
+ return prefs.getString(EXPLORER_VIEW_TYPE_KEY, GRID_VIEW).equals(LIST_VIEW);
+ }
+
+ /** Change the view state (without updating the UI). */
+ private void toggleViewMode() {
+ if (isViewModeList())
+ prefs.edit().putString(EXPLORER_VIEW_TYPE_KEY, GRID_VIEW).apply();
+ else
+ prefs.edit().putString(EXPLORER_VIEW_TYPE_KEY, LIST_VIEW).apply();
}
/** Start editing of the given Uri. */
@@ -813,7 +827,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
prefs = getSharedPreferences(EXPLORER_PREFS_KEY, MODE_PRIVATE);
sortMode = prefs.getInt(SORT_MODE_KEY, FileUtilities.SORT_AZ);
SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
- viewMode = Integer.valueOf(defaultPrefs.getString(EXPLORER_VIEW_TYPE_KEY, "" + GRID_VIEW));
filterMode = Integer.valueOf(defaultPrefs.getString(FILTER_MODE_KEY, "-1"));
showHiddenFiles = defaultPrefs.getBoolean(ENABLE_SHOW_HIDDEN_FILES_KEY, false);
@@ -832,11 +845,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
filterMode = i.getIntExtra(FILTER_MODE_KEY, FileUtilities.ALL);
Log.d(LOGTAG, FILTER_MODE_KEY);
}
-
- if (i.hasExtra(EXPLORER_VIEW_TYPE_KEY)) {
- viewMode = i.getIntExtra(EXPLORER_VIEW_TYPE_KEY, GRID_VIEW);
- Log.d(LOGTAG, EXPLORER_VIEW_TYPE_KEY);
- }
}
@@ -851,15 +859,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
- /*if (currentDirectory != null) {
- outState.putString(CURRENT_DIRECTORY_KEY, currentDirectory.getUri().toString());
- Log.d(LOGTAG, currentDirectory.toString() + Integer.toString(filterMode) + Integer.toString(viewMode));
- }
outState.putInt(FILTER_MODE_KEY, filterMode);
- outState.putInt(EXPLORER_VIEW_TYPE_KEY, viewMode);
- if (documentProvider != null)
- outState.putInt(DOC_PROVIDER_KEY, documentProvider.getId());
- */
outState.putBoolean(ENABLE_SHOW_HIDDEN_FILES_KEY, showHiddenFiles);
@@ -886,11 +886,10 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
currentDirectory = documentProvider.getRootDirectory(this);
}*/
filterMode = savedInstanceState.getInt(FILTER_MODE_KEY, FileUtilities.ALL);
- viewMode = savedInstanceState.getInt(EXPLORER_VIEW_TYPE_KEY, GRID_VIEW);
showHiddenFiles = savedInstanceState.getBoolean(ENABLE_SHOW_HIDDEN_FILES_KEY, false);
//openDirectory(currentDirectory);
Log.d(LOGTAG, "onRestoreInstanceState");
- //Log.d(LOGTAG, currentDirectory.toString() + Integer.toString(filterMode) + Integer.toString(viewMode));
+ //Log.d(LOGTAG, currentDirectory.toString() + Integer.toString(filterMode));
}
private final BroadcastReceiver mUSBReceiver = new BroadcastReceiver() {
diff --git a/android/app/src/main/res/drawable/ic_list_black_24dp.xml b/android/app/src/main/res/drawable/ic_list_black_24dp.xml
new file mode 100644
index 000000000..4c2fb8834
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_list_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/>
+</vector>
diff --git a/android/app/src/main/res/drawable/ic_view_module_black_24dp.xml b/android/app/src/main/res/drawable/ic_view_module_black_24dp.xml
new file mode 100644
index 000000000..ab36b0766
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_view_module_black_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M4,11h5L9,5L4,5v6zM4,18h5v-6L4,12v6zM10,18h5v-6h-5v6zM16,18h5v-6h-5v6zM10,11h5L15,5h-5v6zM16,5v6h5L21,5h-5z"/>
+</vector>
diff --git a/android/app/src/main/res/layout/activity_document_browser.xml b/android/app/src/main/res/layout/activity_document_browser.xml
index d95ff6436..0611557fe 100644
--- a/android/app/src/main/res/layout/activity_document_browser.xml
+++ b/android/app/src/main/res/layout/activity_document_browser.xml
@@ -60,15 +60,30 @@
android:divider="@color/doorhanger_divider_light"
android:showDividers="middle">
- <TextView
+ <LinearLayout
android:layout_width="match_parent"
- android:layout_height="48dp"
- android:id="@+id/header_recents"
- android:text="@string/title_recents"
- android:gravity="center_vertical"
- android:textSize="14sp"
- android:padding="16dp"
- android:textStyle="bold" />
+ android:layout_height="match_parent"
+ android:orientation="horizontal">
+
+ <TextView
+ android:id="@+id/header_recents"
+ android:layout_width="match_parent"
+ android:layout_height="48dp"
+ android:layout_weight="1"
+ android:gravity="center_vertical"
+ android:padding="16dp"
+ android:text="@string/title_recents"
+ android:textSize="14sp"
+ android:textStyle="bold" />
+
+ <ImageView
+ android:id="@+id/recent_list_or_grid"
+ android:layout_width="96dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1"
+ android:scaleType="centerInside"
+ app:srcCompat="@drawable/ic_list_black_24dp" />
+ </LinearLayout>
<!--Recent files-->
<FrameLayout
diff --git a/android/app/src/main/res/values/arrays.xml b/android/app/src/main/res/values/arrays.xml
index 6a0c1e7cd..f5a3706b4 100644
--- a/android/app/src/main/res/values/arrays.xml
+++ b/android/app/src/main/res/values/arrays.xml
@@ -16,15 +16,6 @@
<item >4</item>
<item >5</item>
</string-array>
- <!-- View Mode names,values -->
- <string-array name="ViewModeNames">
- <item >@string/grid_view</item>
- <item >@string/list_view</item>
- </string-array>
- <string-array name="ViewModeStringValues">
- <item >0</item>
- <item >1</item>
- </string-array>
<string-array name="FilterTypeNames">
<item>@string/filter_everything</item>
<item>@string/filter_documents</item>
diff --git a/android/app/src/main/res/values/integers.xml b/android/app/src/main/res/values/integers.xml
deleted file mode 100644
index 5f7fc625e..000000000
--- a/android/app/src/main/res/values/integers.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <integer name="grid_view_integer">0</integer>
-</resources>
diff --git a/android/app/src/main/res/xml/libreoffice_preferences.xml b/android/app/src/main/res/xml/libreoffice_preferences.xml
index a6da9e4ef..7ffdbd8dd 100644
--- a/android/app/src/main/res/xml/libreoffice_preferences.xml
+++ b/android/app/src/main/res/xml/libreoffice_preferences.xml
@@ -21,14 +21,6 @@
android:defaultValue="0"
android:entryValues="@array/SortModeStringValues"
app:iconSpaceReserved="false" />
- <ListPreference
- android:entries="@array/ViewModeNames"
- android:entryValues="@array/ViewModeStringValues"
- android:defaultValue="@integer/grid_view_integer"
- android:title="@string/pref_file_explorer_title"
- android:key="EXPLORER_VIEW_TYPE"
- android:summary="@string/pref_viewmode_summary"
- app:iconSpaceReserved="false" />
<CheckBoxPreference
android:title="@string/pref_show_hidden_files"
commit d6e37728d5997f96be69a23da7a1ffc2c89e94d6
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 19 18:40:36 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Kill the document browsing functionality.
Change-Id: I9dd0e448818bfebf6efd7b544487f881ae2de8ab
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index bc34085b4..6d78fe857 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -110,11 +110,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
FileFilter fileFilter;
FilenameFilter filenameFilter;
- //private List<IFile> filePaths = new ArrayList<IFile>();
- //private DocumentProviderFactory documentProviderFactory;
- //private IDocumentProvider documentProvider = null;
- //private IFile homeDirectory;
- //private IFile currentDirectory;
private int currentlySelectedFile;
/** The document that is being edited - to know what to save back to cloud. */
@@ -143,12 +138,10 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private NavigationView navigationDrawer;
private ActionBar actionBar;
private ActionBarDrawerToggle drawerToggle;
- private RecyclerView fileRecyclerView;
private RecyclerView recentRecyclerView;
//kept package-private to use these in recyclerView's adapter
TextView noRecentItemsTextView;
- TextView noItemsTextView;
private Animation fabOpenAnimation;
private Animation fabCloseAnimation;
@@ -163,8 +156,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
/** Request code to evaluate that we are returning from the LOActivity. */
private static final int LO_ACTIVITY_REQUEST_CODE = 42;
- private static final int SD_CARD_REQUEST_CODE = 43;
- private static final int OPEN_FILE_REQUEST_CODE = 44;
+ private static final int OPEN_FILE_REQUEST_CODE = 43;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -242,27 +234,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
updateRecentFilesAdapter();
- fileRecyclerView = findViewById(R.id.file_recycler_view);
- noItemsTextView = findViewById(R.id.no_items_msg);
- //This should be tested because it possibly disables view recycling
- fileRecyclerView.setNestedScrollingEnabled(false);
- //openDirectory(currentDirectory);
- registerForContextMenu(fileRecyclerView);
+ //registerForContextMenu(fileRecyclerView);
//Setting up navigation drawer
drawerLayout = findViewById(R.id.drawer_layout);
navigationDrawer = findViewById(R.id.navigation_drawer);
- /*final ArrayList<CharSequence> providerNames = new ArrayList<CharSequence>(
- Arrays.asList(documentProviderFactory.getNames())
- );
-
- // Loop through the document providers menu items and check if they are available or not
- for (int index = 0; index < providerNames.size(); ++index) {
- MenuItem item = navigationDrawer.getMenu().getItem(index);
- item.setVisible(documentProviderFactory.getProvider(index).checkProviderAvailability(this));
- }*/
-
navigationDrawer.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
@@ -274,12 +251,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
case R.id.menu_provider_documents: {
- switchToDocumentProvider(0);
+ //switchToDocumentProvider(0);
return true;
}
case R.id.menu_provider_filesystem: {
- switchToDocumentProvider(1);
+ //switchToDocumentProvider(1);
return true;
}
@@ -289,12 +266,12 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
case R.id.menu_provider_otg: {
- switchToDocumentProvider(3);
+ //switchToDocumentProvider(3);
return true;
}
case R.id.menu_provider_owncloud: {
- switchToDocumentProvider(4);
+ //switchToDocumentProvider(4);
return true;
}
@@ -359,13 +336,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
private void refreshView() {
- // enable home icon as "up" if required
- /*if (currentDirectory != null && homeDirectory != null && !currentDirectory.equals(homeDirectory)) {
- drawerToggle.setDrawerIndicatorEnabled(false);
- } else {
- drawerToggle.setDrawerIndicatorEnabled(true);
- }
- */
// refresh view
updateRecentFilesAdapter();
@@ -383,10 +353,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
if (isFabMenuOpen) {
collapseFabMenu();
}
- } /*else if (currentDirectory != null && homeDirectory != null && !currentDirectory.equals(homeDirectory)) {
- // navigate upwards in directory hierarchy
- openParentDirectory();
- }*/ else if (isFabMenuOpen) {
+ } else if (isFabMenuOpen) {
collapseFabMenu();
} else {
// exit the app
@@ -420,137 +387,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
return viewMode == LIST_VIEW;
}
- private void switchToDocumentProvider(int providerId) {
- /*
- IDocumentProvider provider = documentProviderFactory.getProvider(providerId);
-
- new AsyncTask<IDocumentProvider, Void, Void>() {
- @Override
- protected Void doInBackground(IDocumentProvider... provider) {
- Log.d(LOGTAG, "switching to document provider " + provider[0].getId());
-
- // switch document provider:
- // these operations may imply network access and must be run in
- // a different thread
- try {
- homeDirectory = provider[0].getRootDirectory(LibreOfficeUIActivity.this);
- List<IFile> paths = homeDirectory.listFiles(FileUtilities
- .getFileFilter(filterMode));
- filePaths = new ArrayList<IFile>();
- for (IFile file : paths) {
- if (showHiddenFiles) {
- filePaths.add(file);
- } else {
- if (!file.getName().startsWith(".")) {
- filePaths.add(file);
- }
- }
- }
- } catch (final RuntimeException e) {
- SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(LibreOfficeUIActivity.this);
- String sdPath = preferences.getString(DocumentProviderSettingsActivity.KEY_PREF_EXTERNAL_SD_PATH_URI, "");
-
- if (provider[0].getId() != DocumentProviderFactory.EXTSD_PROVIDER_INDEX || !sdPath.isEmpty()) {
- LibreOfficeUIActivity.this.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(LibreOfficeUIActivity.this, e.getMessage(),
- Toast.LENGTH_SHORT).show();
- }
- });
- }
-
- if (provider[0].getId() == DocumentProviderFactory.EXTSD_PROVIDER_INDEX) {
- Intent i = new Intent(LibreOfficeUIActivity.this, BrowserSelectorActivity.class);
- i.putExtra(BrowserSelectorActivity.PREFERENCE_KEY_EXTRA, DocumentProviderSettingsActivity.KEY_PREF_EXTERNAL_SD_PATH_URI);
- i.putExtra(BrowserSelectorActivity.MODE_EXTRA, BrowserSelectorActivity.MODE_EXT_SD);
- startActivityForResult(i, SD_CARD_REQUEST_CODE);
- }
- else
- startActivity(new Intent(LibreOfficeUIActivity.this, DocumentProviderSettingsActivity.class));
-
- Log.e(LOGTAG, "failed to switch document provider " + e.getMessage(), e.getCause());
- return null;
- }
- //no exception
- documentProvider = provider[0];
- currentDirectory = homeDirectory;
- return null;
- }
-
- @Override
- protected void onPostExecute(Void result) {
- refreshView();
- }
- }.execute(provider);
- */
- }
-
- /*
- public void openDirectory(IFile dir) {
- if (dir == null)
- return;
-
- //show recent files if in home directory
- if (dir.equals(homeDirectory)) {
- recentRecyclerView.setVisibility(View.VISIBLE);
- findViewById(R.id.header_browser).setVisibility((View.VISIBLE));
- findViewById(R.id.header_recents).setVisibility((View.VISIBLE));
- actionBar.setTitle(R.string.app_name);
- findViewById(R.id.text_directory_path).setVisibility(View.GONE);
- } else {
- recentRecyclerView.setVisibility(View.GONE);
- noRecentItemsTextView.setVisibility(View.GONE);
- findViewById(R.id.header_browser).setVisibility((View.GONE));
- findViewById(R.id.header_recents).setVisibility((View.GONE));
- actionBar.setTitle(dir.getName());
- findViewById(R.id.text_directory_path).setVisibility(View.VISIBLE);
- ((TextView) findViewById(R.id.text_directory_path)).setText(getString(R.string.current_dir,
- dir.getUri().getPath()));
- }
-
- new AsyncTask<IFile, Void, Void>() {
- @Override
- protected Void doInBackground(IFile... dir) {
- // get list of files:
- // this operation may imply network access and must be run in
- // a different thread
- currentDirectory = dir[0];
- try {
- List<IFile> paths = currentDirectory.listFiles(FileUtilities
- .getFileFilter(filterMode));
- filePaths = new ArrayList<IFile>();
- for (IFile file : paths) {
- if (showHiddenFiles) {
- filePaths.add(file);
- } else {
- if (!file.getName().startsWith(".")) {
- filePaths.add(file);
- }
- }
- }
- } catch (final RuntimeException e) {
- final Activity activity = LibreOfficeUIActivity.this;
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(activity, e.getMessage(),
- Toast.LENGTH_SHORT).show();
- }
- });
- Log.e(LOGTAG, e.getMessage(), e.getCause());
- }
- return null;
- }
-
- @Override
- protected void onPostExecute(Void result) {
- refreshView();
- }
- }.execute(dir);
- }
- */
-
/** Start editing of the given Uri. */
public void open(final Uri uri) {
if (uri == null)
@@ -704,7 +540,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
return Uri.fromFile(newFile);
}
-
+ /** Context menu item handling. */
private void open(int position) {
/*
IFile file = filePaths.get(position);
@@ -716,24 +552,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
*/
}
- private void openParentDirectory() {
- /*
- new AsyncTask<Void, Void, IFile>() {
- @Override
- protected IFile doInBackground(Void... dir) {
- // this operation may imply network access and must be run in
- // a different thread
- return currentDirectory.getParent(LibreOfficeUIActivity.this);
- }
-
- @Override
- protected void onPostExecute(IFile result) {
- openDirectory(result);
- }
- }.execute();
- */
- }
-
+ /** Context menu item handling. */
private void share(int position) {
/*
new AsyncTask<IFile, Void, File>() {
@@ -912,11 +731,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
break;
case android.R.id.home:
- /*
- if (!currentDirectory.equals(homeDirectory)) {
- openParentDirectory();
- }
- */
+ // TODO probably kill
break;
case R.id.menu_filter_everything:
@@ -1100,7 +915,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
// Handle various events from LOActivity
if (event.equals("SAVE")) {
- LibreOfficeUIActivity.this.saveFileToCloud();
+ // TODO probably kill this, we don't need to do anything here any more
}
}
};
@@ -1109,14 +924,9 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == LO_ACTIVITY_REQUEST_CODE) {
+ // TODO probably kill this, we don't need to do anything here any more
Log.d(LOGTAG, "LOActivity has finished.");
- saveFileToCloud();
}
- /*else if (requestCode == SD_CARD_REQUEST_CODE) {
- Log.d(LOGTAG, "SD card chooser has finished.");
- if (resultCode == RESULT_OK)
- switchToDocumentProvider(DocumentProviderFactory.EXTSD_PROVIDER_INDEX);
- }*/
else if (requestCode == OPEN_FILE_REQUEST_CODE) {
Log.d(LOGTAG, "File open chooser has finished, starting the LOActivity.");
if (resultCode == RESULT_OK && data != null) {
@@ -1131,46 +941,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
}
- /** Actually copy the file to the remote storage (if applicable). */
- public void saveFileToCloud() {
- /*
- if (mCurrentDocument == null)
- {
- Log.e(LOGTAG, "No idea what should be uploaded.");
- return;
- }
-
- final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- try {
- // call document provider save operation
- mCurrentDocument.saveDocument();
- }
- catch (final RuntimeException e) {
- LibreOfficeUIActivity.this.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(LibreOfficeUIActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
- }
- });
- Log.e(LOGTAG, e.getMessage(), e.getCause());
- }
- return null;
- }
-
- @Override
- protected void onPostExecute(Void param) {
- // FIXME Should we present a toast that the file was saved, or
- // is it annoying?
- //Toast.makeText(LibreOfficeUIActivity.this, R.string.message_saved, Toast.LENGTH_SHORT).show();
- }
- };
-
- task.execute();
- */
- }
-
@Override
protected void onPause() {
super.onPause();
@@ -1194,8 +964,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
PERMISSION_WRITE_EXTERNAL_STORAGE);
} else {
- /*if (documentProvider == null)
- switchToDocumentProvider(0);*/
setEditFABVisibility(View.VISIBLE);
}
Log.d(LOGTAG, "onStart");
@@ -1233,11 +1001,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
//put the new value in the first place
recentsArrayList.add(0, newRecent);
- /*
- * 4 because the number of recommended items in App Shortcuts is 4, and also
- * because it's a good number of recent items in general
- */
- final int RECENTS_SIZE = 4;
+ final int RECENTS_SIZE = 30;
while (recentsArrayList.size() > RECENTS_SIZE) {
recentsArrayList.remove(RECENTS_SIZE);
@@ -1322,122 +1086,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
}
- /*
- class ExplorerItemAdapter extends RecyclerView.Adapter<ExplorerItemAdapter.ViewHolder> {
-
- private LibreOfficeUIActivity mActivity;
- private List<IFile> filePaths;
- private final long KB = 1024;
- private final long MB = 1048576;
-
- ExplorerItemAdapter(LibreOfficeUIActivity activity, List<IFile> filePaths) {
- this.mActivity = activity;
- this.filePaths = filePaths;
- }
-
- @Override
- public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- View item = LayoutInflater.from(parent.getContext())
- .inflate(isViewModeList() ? R.layout.file_list_item : R.layout.file_explorer_grid_item, parent, false);
- return new ViewHolder(item);
- }
-
- @Override
- public void onBindViewHolder(final ViewHolder holder, final int position) {
- final IFile file = filePaths.get(position);
-
- holder.itemView.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- open(holder.getAdapterPosition());
- }
- });
- holder.itemView.setOnLongClickListener(new OnLongClickListener() {
-
- @Override
- public boolean onLongClick(View view) {
- //to be picked out by floating context menu (workaround-ish)
- currentlySelectedFile = holder.getAdapterPosition();
- //must return false so the click is not consumed
- return false;
- }
- });
-
- holder.filenameView.setText(file.getName());
- switch (FileUtilities.getType(file.getName())) {
- case FileUtilities.DOC:
- holder.iconView.setImageResource(R.drawable.writer);
- break;
- case FileUtilities.CALC:
- holder.iconView.setImageResource(R.drawable.calc);
- break;
- case FileUtilities.DRAWING:
- holder.iconView.setImageResource(R.drawable.draw);
- break;
- case FileUtilities.IMPRESS:
- holder.iconView.setImageResource(R.drawable.impress);
- break;
- }
-
- if (file.isDirectory()) {
- //Eventually have thumbnails of each sub file on a black circle
- //For now just a folder icon
- holder.iconView.setImageResource(R.drawable.ic_folder_black_24dp);
- holder.iconView.setColorFilter(ContextCompat.getColor(mActivity, R.color.text_color_secondary));
- }
-
- // Date and Size field only exist when we are displaying items in a list.
- if (isViewModeList()) {
- if (!file.isDirectory()) {
- String size;
- long length = filePaths.get(position).getSize();
- if (length < KB) {
- size = Long.toString(length) + "B";
- } else if (length < MB) {
- size = Long.toString(length / KB) + "KB";
- } else {
- size = Long.toString(length / MB) + "MB";
- }
- holder.fileSizeView.setText(size);
- }
- SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy hh:ss");
- Date date = file.getLastModified();
- //TODO format date
- holder.fileDateView.setText(df.format(date));
- }
- }
-
- @Override
- public int getItemCount() {
- if (filePaths.size() == 0) {
- mActivity.noItemsTextView.setVisibility(View.VISIBLE);
- } else {
- mActivity.noItemsTextView.setVisibility(View.GONE);
- }
- return filePaths.size();
- }
-
- class ViewHolder extends RecyclerView.ViewHolder {
-
- View itemView;
- TextView filenameView, fileSizeView, fileDateView;
- ImageView iconView;
-
- ViewHolder(View itemView) {
- super(itemView);
- this.itemView = itemView;
- filenameView = itemView.findViewById(R.id.file_item_name);
- iconView = itemView.findViewById(R.id.file_item_icon);
- // Check if view mode is List, only then initialise Size and Date field
- if (isViewModeList()) {
- fileSizeView = itemView.findViewById(R.id.file_item_size);
- fileDateView = itemView.findViewById(R.id.file_item_date);
- }
- }
- }
- }
- */
-
private void setEditFABVisibility(final int visibility) {
LibreOfficeApplication.getMainHandler().post(new Runnable() {
@Override
@@ -1452,8 +1100,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
switch (requestCode) {
case PERMISSION_WRITE_EXTERNAL_STORAGE:
if (permissions.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
- /*if (documentProvider == null)
- switchToDocumentProvider(0);*/
setEditFABVisibility(View.VISIBLE);
} else {
setEditFABVisibility(View.INVISIBLE);
diff --git a/android/app/src/main/res/layout/activity_document_browser.xml b/android/app/src/main/res/layout/activity_document_browser.xml
index 7964689ef..d95ff6436 100644
--- a/android/app/src/main/res/layout/activity_document_browser.xml
+++ b/android/app/src/main/res/layout/activity_document_browser.xml
@@ -93,49 +93,6 @@
</FrameLayout>
- <TextView
- android:layout_width="match_parent"
- android:layout_height="48dp"
- android:id="@+id/header_browser"
- android:text="@string/title_browser"
- android:gravity="center_vertical"
- android:textSize="14sp"
- android:padding="16dp"
- android:textStyle="bold" />
-
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textSize="14sp"
- android:padding="7dp"
- android:id="@+id/text_directory_path"
- android:background="@color/background_normal"
- />
-
-
- <!--Document browser-->
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/file_recycler_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@color/background_normal"
- android:orientation="vertical" />
-
- <TextView
- android:id="@+id/no_items_msg"
- android:layout_width="wrap_content"
- android:layout_height="48dp"
- android:layout_gravity="center"
- android:gravity="center"
- android:textSize="14sp"
- android:text="@string/no_items" />
-
- </FrameLayout>
-
</LinearLayout>
</androidx.core.widget.NestedScrollView>
commit cdea4cdd0831849c4031ef60c26eae13c07ca22b
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 19 18:14:33 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Move some functionality to the Recent files.
* Bigger icons for the recent files.
* Possibility to switch to list view (which displays file sizes).
Change-Id: I5c0f3b4670d7e3f2acb2935adb6be1b78553c5ea
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index 536709d48..bc34085b4 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -195,6 +195,24 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
fabCloseAnimation = AnimationUtils.loadAnimation(this, R.anim.fab_close);
}
+ /** Update the recent files list. */
+ public void updateRecentFilesAdapter() {
+ Set<String> recentFileStrings = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>());
+
+ final ArrayList<Uri> recentUris = new ArrayList<Uri>();
+ for (String recentFileString : recentFileStrings) {
+ try {
+ recentUris.add(Uri.parse(recentFileString));
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ }
+ }
+ // TODO FileUtilities.sortFiles(filePaths, sortMode);
+
+ recentRecyclerView.setLayoutManager(isViewModeList() ? new LinearLayoutManager(this) : new GridLayoutManager(this, 2));
+ recentRecyclerView.setAdapter(new RecentFilesAdapter(this, recentUris));
+ }
+
public void createUI() {
setContentView(R.layout.activity_document_browser);
@@ -222,19 +240,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
recentRecyclerView = findViewById(R.id.list_recent);
noRecentItemsTextView = findViewById(R.id.no_recent_items_msg);
- Set<String> recentFileStrings = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>());
-
- final ArrayList<Uri> recentUris = new ArrayList<Uri>();
- for (String recentFileString : recentFileStrings) {
- try {
- recentUris.add(Uri.parse(recentFileString));
- } catch (RuntimeException e) {
- e.printStackTrace();
- }
- }
-
- recentRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
- recentRecyclerView.setAdapter(new RecentFilesAdapter(this, recentUris));
+ updateRecentFilesAdapter();
fileRecyclerView = findViewById(R.id.file_recycler_view);
noItemsTextView = findViewById(R.id.no_items_msg);
@@ -359,12 +365,10 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
} else {
drawerToggle.setDrawerIndicatorEnabled(true);
}
-
- FileUtilities.sortFiles(filePaths, sortMode);
- // refresh view
- fileRecyclerView.setLayoutManager(isViewModeList() ? new LinearLayoutManager(this) : new GridLayoutManager(this, 3));
- fileRecyclerView.setAdapter(new ExplorerItemAdapter(this, filePaths));
*/
+ // refresh view
+ updateRecentFilesAdapter();
+
// close drawer if it was open
drawerLayout.closeDrawer(navigationDrawer);
if (isFabMenuOpen) {
@@ -412,7 +416,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
}
- private boolean isViewModeList() {
+ public boolean isViewModeList() {
return viewMode == LIST_VIEW;
}
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java
index e5a551c65..fc05d38b3 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java
@@ -20,6 +20,8 @@ import android.widget.TextView;
import org.libreoffice.androidapp.R;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
import androidx.core.content.ContextCompat;
@@ -27,6 +29,9 @@ import androidx.recyclerview.widget.RecyclerView;
class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHolder> {
+ private final long KB = 1024;
+ private final long MB = 1048576;
+
private LibreOfficeUIActivity mActivity;
private List<Uri> recentUris;
@@ -37,8 +42,7 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- View item = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.item_recent_files, parent, false);
+ View item = LayoutInflater.from(parent.getContext()).inflate(mActivity.isViewModeList() ? R.layout.file_list_item : R.layout.file_explorer_grid_item, parent, false);
return new ViewHolder(item);
}
@@ -54,12 +58,15 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
});
String filename = "";
+ long length = 0;
+ Date date = null; // TODO get it at least for files
// Try to get it from the content resolver first, fallback to path
Cursor cursor = mActivity.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
+ length = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
}
} finally {
if (cursor != null)
@@ -72,7 +79,11 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
filename = segments.get(segments.size() - 1);
}
- holder.textView.setText(filename);
+ if (length == 0) {
+ // TODO maybe try to get File & return File.length()?
+ }
+
+ holder.filenameView.setText(filename);
int compoundDrawableInt = 0;
@@ -93,6 +104,25 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
if (compoundDrawableInt != 0)
holder.imageView.setImageDrawable(ContextCompat.getDrawable(mActivity, compoundDrawableInt));
+
+ // Date and Size field only exist when we are displaying items in a list.
+ if (mActivity.isViewModeList()) {
+ String size;
+ if (length < KB) {
+ size = Long.toString(length) + "B";
+ } else if (length < MB) {
+ size = Long.toString(length / KB) + "KB";
+ } else {
+ size = Long.toString(length / MB) + "MB";
+ }
+ holder.fileSizeView.setText(size);
+
+ if (date != null) {
+ SimpleDateFormat df = new SimpleDateFormat("dd MMM yyyy hh:ss");
+ //TODO format date
+ holder.fileDateView.setText(df.format(date));
+ }
+ }
}
@Override
@@ -107,13 +137,18 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
class ViewHolder extends RecyclerView.ViewHolder {
- TextView textView;
+ TextView filenameView, fileSizeView, fileDateView;
ImageView imageView;
ViewHolder(View itemView) {
super(itemView);
- this.textView = itemView.findViewById(R.id.textView);
- this.imageView = itemView.findViewById(R.id.imageView);
+ this.filenameView = itemView.findViewById(R.id.file_item_name);
+ this.imageView = itemView.findViewById(R.id.file_item_icon);
+ // Check if view mode is List, only then initialise Size and Date field
+ if (mActivity.isViewModeList()) {
+ fileSizeView = itemView.findViewById(R.id.file_item_size);
+ fileDateView = itemView.findViewById(R.id.file_item_date);
+ }
}
}
}
commit dca9151fe3439f404c30cef57e685b036269812f
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 19 12:35:18 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Make the recent documents work again.
Change-Id: Iae7523184ec7aa9c85c5cf833f63b5423774e5d1
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index 31d2a722c..536709d48 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -19,6 +19,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.content.UriPermission;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
@@ -78,6 +79,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import androidx.annotation.NonNull;
@@ -222,20 +224,17 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
Set<String> recentFileStrings = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>());
- /*final ArrayList<IFile> recentFiles = new ArrayList<IFile>();
+ final ArrayList<Uri> recentUris = new ArrayList<Uri>();
for (String recentFileString : recentFileStrings) {
try {
- if (documentProvider != null)
- recentFiles.add(documentProvider.createFromUri(this, new URI(recentFileString)));
- } catch (URISyntaxException e) {
- e.printStackTrace();
+ recentUris.add(Uri.parse(recentFileString));
} catch (RuntimeException e) {
e.printStackTrace();
}
- }*/
+ }
recentRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
- //recentRecyclerView.setAdapter(new RecentFilesAdapter(this, recentFiles));
+ recentRecyclerView.setAdapter(new RecentFilesAdapter(this, recentUris));
fileRecyclerView = findViewById(R.id.file_recycler_view);
noItemsTextView = findViewById(R.id.no_items_msg);
@@ -548,51 +547,23 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
*/
- /*
- public void open(final IFile document) {
- addDocumentToRecents(document);
- mCurrentDocument = document;
- new AsyncTask<IFile, Void, File>() {
- @Override
- protected File doInBackground(IFile... document) {
- // this operation may imply network access and must be run in
- // a different thread
- try {
- return document[0].getDocument();
- } catch (final RuntimeException e) {
- final Activity activity = LibreOfficeUIActivity.this;
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Toast.makeText(activity, e.getMessage(),
- Toast.LENGTH_SHORT).show();
- }
- });
- Log.e(LOGTAG, e.getMessage(), e.getCause());
- return null;
- }
- }
+ /** Start editing of the given Uri. */
+ public void open(final Uri uri) {
+ if (uri == null)
+ return;
- @Override
- protected void onPostExecute(File file) {
- if (file != null) {
- Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
- String packageName = getApplicationContext().getPackageName();
- ComponentName componentName = new ComponentName(packageName, LOActivity.class.getName());
- i.setComponent(componentName);
-
- // these extras allow to rebuild the IFile object in LOActivity
- i.putExtra("org.libreoffice.document_provider_id",
- documentProvider.getId());
- i.putExtra("org.libreoffice.document_uri",
- document.getUri());
-
- startActivityForResult(i, LO_ACTIVITY_REQUEST_CODE);
- }
- }
- }.execute(document);
+ addDocumentToRecents(uri);
+
+ Intent i = new Intent(Intent.ACTION_EDIT, uri);
+ i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+
+ String packageName = getApplicationContext().getPackageName();
+ ComponentName componentName = new ComponentName(packageName, LOActivity.class.getName());
+ i.setComponent(componentName);
+
+ startActivityForResult(i, LO_ACTIVITY_REQUEST_CODE);
}
- */
// Opens an Input dialog to get the name of new file
private void createNewFileInputDialog(final String defaultFileName, final String newDocumentType, final String extension) {
@@ -1144,19 +1115,14 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}*/
else if (requestCode == OPEN_FILE_REQUEST_CODE) {
Log.d(LOGTAG, "File open chooser has finished, starting the LOActivity.");
- if (resultCode == RESULT_OK) {
+ if (resultCode == RESULT_OK && data != null) {
Uri uri = data.getData();
- getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ if (uri == null)
+ return;
- Intent i = new Intent(Intent.ACTION_EDIT, uri);
- i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
-
- String packageName = getApplicationContext().getPackageName();
- ComponentName componentName = new ComponentName(packageName, LOActivity.class.getName());
- i.setComponent(componentName);
+ getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
- startActivityForResult(i, LO_ACTIVITY_REQUEST_CODE);
+ open(uri);
}
}
}
@@ -1250,9 +1216,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
return (int) (dp * scale + 0.5f);
}
- /*
- private void addDocumentToRecents(IFile iFile) {
- String newRecent = iFile.getUri().toString();
+ private void addDocumentToRecents(Uri uri) {
+ String newRecent = uri.toString();
Set<String> recentsSet = prefs.getStringSet(RECENT_DOCUMENTS_KEY, new HashSet<String>());
//create array to work with
@@ -1267,7 +1232,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
/*
* 4 because the number of recommended items in App Shortcuts is 4, and also
* because it's a good number of recent items in general
- * /
+ */
final int RECENTS_SIZE = 4;
while (recentsArrayList.size() > RECENTS_SIZE) {
@@ -1329,7 +1294,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
shortcutManager.setDynamicShortcuts(shortcuts);
}
}
- */
@Override
public void onClick(View v) {
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java
index 42ef666ab..e5a551c65 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/RecentFilesAdapter.java
@@ -9,7 +9,9 @@
package org.libreoffice.androidapp.ui;
-
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.OpenableColumns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -26,11 +28,11 @@ import androidx.recyclerview.widget.RecyclerView;
class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHolder> {
private LibreOfficeUIActivity mActivity;
- //private List<IFile> recentFiles;
+ private List<Uri> recentUris;
- RecentFilesAdapter(LibreOfficeUIActivity activity/*, List<IFile> recentFiles*/) {
+ RecentFilesAdapter(LibreOfficeUIActivity activity, List<Uri> recentUris) {
this.mActivity = activity;
- //this.recentFiles = recentFiles;
+ this.recentUris = recentUris;
}
@Override
@@ -42,17 +44,33 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
- /*
- final IFile iFile = recentFiles.get(position);
+ final Uri uri = recentUris.get(position);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- mActivity.open(iFile);
+ mActivity.open(uri);
}
});
- String filename = iFile.getName();
+ String filename = "";
+
+ // Try to get it from the content resolver first, fallback to path
+ Cursor cursor = mActivity.getContentResolver().query(uri, null, null, null, null);
+ try {
+ if (cursor != null && cursor.moveToFirst()) {
+ filename = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
+ }
+ } finally {
+ if (cursor != null)
+ cursor.close();
+ }
+
+ if (filename.isEmpty()) {
+ List<String> segments = uri.getPathSegments();
+ if (segments.size() > 0)
+ filename = segments.get(segments.size() - 1);
+ }
holder.textView.setText(filename);
@@ -75,20 +93,16 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
if (compoundDrawableInt != 0)
holder.imageView.setImageDrawable(ContextCompat.getDrawable(mActivity, compoundDrawableInt));
- */
}
@Override
public int getItemCount() {
- /*
- if (recentFiles.size() == 0) {
+ if (recentUris.size() == 0) {
mActivity.noRecentItemsTextView.setVisibility(View.VISIBLE);
} else {
mActivity.noRecentItemsTextView.setVisibility(View.GONE);
}
- return recentFiles.size();
- */
- return 0;
+ return recentUris.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
@@ -103,3 +117,5 @@ class RecentFilesAdapter extends RecyclerView.Adapter<RecentFilesAdapter.ViewHol
}
}
}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit bdcf644fbd14cc5958a7c753fedaa5e106a192d0
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 19 09:09:33 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: No need for the Nextcloud lib any more.
Change-Id: Ifdf8ae09d2350aa56d7f139bfbdf3db88eedba67
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 307837015..6ca998f58 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -54,12 +54,6 @@ android {
}
}
-repositories {
- maven {
- url "https://jitpack.io"
- }
-}
-
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
@@ -68,9 +62,6 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha04'
- implementation 'com.github.nextcloud:android-library:-SNAPSHOT'
- implementation "commons-httpclient:commons-httpclient:3.1 at jar" // remove after entire switch to lib v2
-
//before changing the version please see https://issuetracker.google.com/issues/111662669
implementation 'androidx.preference:preference:1.1.0-alpha01'
implementation project(path: ':lib')
commit 2a52d768dd61f2ef8fedccb32f015c9095915935
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Feb 19 09:05:56 2020 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Feb 20 14:53:06 2020 +0100
android shell: Remove the 'storage framework', we have content providers.
Needs further work to make the recend documents + list of local files
work again.
Change-Id: I2562ef2b35e5c8ed9ab71149b6b7180b40e61de9
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderFactory.java b/android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderFactory.java
deleted file mode 100644
index 9590ebe35..000000000
--- a/android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderFactory.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package org.libreoffice.androidapp.storage;
-
-import android.content.Context;
-import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
-
-import org.libreoffice.androidapp.storage.external.ExtsdDocumentsProvider;
-import org.libreoffice.androidapp.storage.external.OTGDocumentsProvider;
-import org.libreoffice.androidapp.storage.local.LocalDocumentsDirectoryProvider;
-import org.libreoffice.androidapp.storage.local.LocalDocumentsProvider;
-import org.libreoffice.androidapp.storage.owncloud.OwnCloudProvider;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * Keeps the instances of the available IDocumentProviders in the system.
- * Instances are maintained in a sorted list and providers have to be
- * accessed from their position.
- * <p>
- * The factory follows the Singleton pattern, there is only one instance of it
- * in the application and it must be retrieved with
- * DocumentProviderFactory.getInstance().
- */
-public final class DocumentProviderFactory {
- public static int EXTSD_PROVIDER_INDEX = 2;
- public static int OTG_PROVIDER_INDEX = 3;
-
- /**
- * Private factory instance for the Singleton pattern.
- */
- private static DocumentProviderFactory instance = null;
-
- private IDocumentProvider[] providers;
-
- private String[] providerNames;
-
- private DocumentProviderFactory() {
- // private to prevent external instances of the factory
- }
-
- /**
- * Initializes the factory with some context. If this method is called for
- * twice or more times those calls will have no effect.
- *
- * @param context Application context for the factory.
- */
- public static void initialize(Context context) {
- if (instance == null) {
- // initialize instance
- instance = new DocumentProviderFactory();
-
- // initialize document providers list
- instance.providers = new IDocumentProvider[5];
- instance.providers[0] = new LocalDocumentsDirectoryProvider(0);
- instance.providers[1] = new LocalDocumentsProvider(1);
- instance.providers[EXTSD_PROVIDER_INDEX] = new ExtsdDocumentsProvider(EXTSD_PROVIDER_INDEX, context);
- instance.providers[OTG_PROVIDER_INDEX] = new OTGDocumentsProvider(OTG_PROVIDER_INDEX, context);
- instance.providers[4] = new OwnCloudProvider(4, context);
-
- // initialize document provider names list
- instance.providerNames = new String[instance.providers.length];
- for (int i = 0; i < instance.providers.length; i++) {
- if (instance.providerNames[i] != null)//own cloud is not declared yet
- instance.providerNames[i] = context.getString(instance
- .getProvider(i).getNameResource());
- }
- }
- }
-
- /**
- * Retrieve the unique instance of the factory.
- *
- * @return the unique factory object or null if it is not yet initialized.
- */
- public static DocumentProviderFactory getInstance() {
- return instance;
- }
-
- /**
- * Retrieve the provider associated to a certain id.
- *
- * @param id
- * @return document provider with that id.
- */
- public IDocumentProvider getProvider(int id) {
- // as for now, id == position in providers array
- return providers[id];
- }
-
- /**
- * Returns a sorted list of the names of the providers. Order is meaningful
- * to retrieve the actual provider object with getProvider().
- *
- * @return Array with the names of the available providers.
- */
- public String[] getNames() {
- return providerNames;
- }
-
- public Set<OnSharedPreferenceChangeListener> getChangeListeners() {
- Set<OnSharedPreferenceChangeListener> listeners =
- new HashSet<OnSharedPreferenceChangeListener>();
- for (IDocumentProvider provider : providers) {
- if (provider instanceof OnSharedPreferenceChangeListener)
- listeners.add((OnSharedPreferenceChangeListener) provider);
- }
- return listeners;
- }
-}
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderSettingsActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderSettingsActivity.java
deleted file mode 100644
index c7c1532b1..000000000
--- a/android/app/src/main/java/org/libreoffice/androidapp/storage/DocumentProviderSettingsActivity.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-package org.libreoffice.androidapp.storage;
-
-import android.content.Intent;
-import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-
-import org.libreoffice.androidapp.R;
-import org.libreoffice.androidapp.storage.external.BrowserSelectorActivity;
-
-import java.util.Set;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceFragmentCompat;
-
-public class DocumentProviderSettingsActivity extends AppCompatActivity {
-
- public static final String KEY_PREF_OWNCLOUD_SERVER = "pref_server_url";
- public static final String KEY_PREF_OWNCLOUD_USER_NAME = "pref_user_name";
- public static final String KEY_PREF_OWNCLOUD_PASSWORD = "pref_password";
- public static final String KEY_PREF_EXTERNAL_SD_PATH_URI = "pref_extsd_path_uri";
- public static final String KEY_PREF_OTG_PATH_URI = "pref_otg_path_uri";
-
- private Set<OnSharedPreferenceChangeListener> listeners;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Display the fragment as the main content.
- getSupportFragmentManager().beginTransaction()
- .replace(android.R.id.content, new SettingsFragment()).commit();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- listeners = DocumentProviderFactory.getInstance().getChangeListeners();
- for (OnSharedPreferenceChangeListener listener : listeners) {
- PreferenceManager.getDefaultSharedPreferences(this)
- .registerOnSharedPreferenceChangeListener(listener);
- }
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- for (OnSharedPreferenceChangeListener listener : listeners) {
- PreferenceManager.getDefaultSharedPreferences(this)
- .unregisterOnSharedPreferenceChangeListener(listener);
- }
- }
-
- public static class SettingsFragment extends PreferenceFragmentCompat {
-
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- // Load the preferences from an XML resource
- addPreferencesFromResource(R.xml.documentprovider_preferences);
-
- Preference extSDPreference = findPreference(KEY_PREF_EXTERNAL_SD_PATH_URI);
-
- /* FIXME fix or remove
- Preference otgPreference = findPreference(KEY_PREF_OTG_PATH_URI);
- */
-
- extSDPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list