Skip to content

Commit

Permalink
Sync edited files (#3)
Browse files Browse the repository at this point in the history
* enable client side encryption for camera upload

* Add CHACHA20_POLY1305 to the ssl cipher list (haiwen#904)

* FileMonitorService is not running, start it in EditorActivity (haiwen#908)

* UpdateEditFile (haiwen#905)

* Upload the edited and saved file

* update edit save file

* update to upload the edited file

* Update the logic for uploading edited files

* Update upload retrieval FileMonitorService

* Restart the upload service after editing the file

* modify the upload service logic after editing the file

* FileMonitorService is not running, start it in EditorActivity

* SaveEditFile (haiwen#910)

* Save the edit file

* 1,Modify movement and copy of encrypted files
2,Fixed the problem of slow loading of list data in database

* Modify mobile repo encryption file list display

* delete FileSaveTaskDialog.java

* delete showSaveDialog method

* ModifySharingLinkErr (haiwen#916)

* Modify the failed message for generating share links

* 1,Update sharing and generating link prompt information
2,Update translation

* 1,Modify the title of the share Generate link dialog
2,Update the translation

* Update the translation

* Fix travis pipeline (haiwen#912)

* fix 2fa login for 2nd server

* add luckycloud christmas logos

* increase versionCode and versionName + set compileSdkVersion and targetSdkVersion to 30

* replace seafile privacy policy link with luckycloud link

* set default value for client_encrypt_switch_key to true -> enable local encryption and decryption by default

* Revert "add luckycloud christmas logos"

This reverts commit e2d3ad8

* increate versionName

* increase versionCode to 115 / 2.6.0 -> new playstore release

* change logo in unlock view + hide password and username field in demo login

* update versionCode and versionName -> playstore relase 2.6.1

* Edit file synchronization, for example onlyOffice (haiwen#928)

Co-authored-by: Viktor Rieger <[email protected]>
Co-authored-by: fakuivan <[email protected]>
Co-authored-by: maxiaoping <[email protected]>
Co-authored-by: Louis Royer <[email protected]>
  • Loading branch information
5 people authored May 11, 2022
1 parent b4d37c4 commit be99fc5
Show file tree
Hide file tree
Showing 28 changed files with 236 additions and 149 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ android:
components:
- tools
- platform-tools
- build-tools-28.0.3
- android-27
- build-tools-29.0.2
- android-29
- extra-android-support
- extra-android-m2repository

# License agreement workaround
# From similar issue: https://travis-ci.community/t/accept-license-for-android-build-tools-27-0-3-bug/549
before_install:
- yes | sdkmanager "build-tools;28.0.3"
- yes | sdkmanager "build-tools;29.0.2"

# https://docs.travis-ci.com/user/languages/android/#Caching
before_cache:
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'de.luckycloud.luckycloud'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 112
versionName "2.4.0"
versionCode 117
versionName "2.6.2"
multiDexEnabled true
setProperty("archivesBaseName", "luckycloud-v" + versionName)
resValue "string", "authorities", applicationId + '.cameraupload.provider'
Expand Down Expand Up @@ -101,7 +101,7 @@ android {
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
implementation 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
implementation 'com.github.kevinsawicki:http-request:6.0'
implementation 'commons-io:commons-io:2.4'
implementation 'commons-io:commons-io:2.11.0'
implementation 'com.google.guava:guava:18.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
implementation 'com.cocosw:bottomsheet:1.3.1'
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/seafile/seadroid2/SeafConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,19 @@ private void checkRequestResponseStatus(HttpRequest req, int expectedStatusCode)
throw new SeafException(req.code(), req.message());
}
} else {
throw new SeafException(req.code(), req.message());
try {
String result = new String(req.bytes(), "UTF-8");
if (result != null && Utils.parseJsonObject(result) != null) {
JSONObject json = Utils.parseJsonObject(result);
throw new SeafException(req.code(), json.optString("error_msg"));
} else {
throw new SeafException(req.code(), req.message());
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new SeafException(req.code(), req.message());
}

}
} else {
// Log.v(DEBUG_TAG, "HTTP request ok : " + req.url());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void setupEncrypt(boolean enable) {
* Whether the user has enabled client side encryption
*/
public boolean isEncryptEnabled() {
return settingsSharedPref.getBoolean(CLIENT_ENC_SWITCH_KEY, false);
return settingsSharedPref.getBoolean(CLIENT_ENC_SWITCH_KEY, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ public class AccountDetailActivity extends BaseActivity implements Toolbar.OnMen
private TextView statusView;
private TextView demoWarningText;

private TextInputLayout emailHint;
private TextInputLayout password_hint;
private EditText serverText;
private EditText passwdText;
private EditText authTokenText;
private ImageView passwordEyeClick;

private Button loginButton;
private ProgressDialog progressDialog;
Expand Down Expand Up @@ -91,8 +94,11 @@ public void onCreate(Bundle savedInstanceState) {
httpsCheckBox = (CheckBox) findViewById(R.id.https_checkbox);

serverText = (EditText) findViewById(R.id.server_url);
emailHint = (TextInputLayout) findViewById(R.id.email_hint);
password_hint = (TextInputLayout) findViewById(R.id.password_hint);
emailText = (EmailAutoCompleteTextView) findViewById(R.id.email_address);
passwdText = (EditText) findViewById(R.id.password);
passwordEyeClick = (ImageView) findViewById(R.id.iv_eye_click);
demoWarningText = findViewById(R.id.demo_warning);
// seahubUrlHintText = (TextView) findViewById(R.id.seahub_url_hint);

Expand Down Expand Up @@ -138,13 +144,23 @@ else if (defaultServerUri != null) {
if (defaultServerUri.startsWith(HTTPS_PREFIX))
httpsCheckBox.setChecked(true);
serverText.setText(defaultServerUri);
if(demoAccount) {
if (demoAccount) {
emailText.setText(intent.getStringExtra(SeafileAuthenticatorActivity.ARG_DEMO_ACCOUNT_NAME));
passwdText.setText(intent.getStringExtra(SeafileAuthenticatorActivity.ARG_DEMO_ACCOUNT_PASSWORD));
emailHint.setVisibility(View.GONE);
password_hint.setVisibility(View.GONE);
emailText.setVisibility(View.GONE);
passwdText.setVisibility(View.GONE);
passwordEyeClick.setVisibility(View.GONE);
demoWarningText.setVisibility(View.VISIBLE);
}
else {
emailText.requestFocus();
emailHint.setVisibility(View.VISIBLE);
password_hint.setVisibility(View.VISIBLE);
emailText.setVisibility(View.VISIBLE);
passwdText.setVisibility(View.VISIBLE);
passwordEyeClick.setVisibility(View.VISIBLE);
demoWarningText.setVisibility(View.GONE);
}
}
Expand Down Expand Up @@ -239,8 +255,6 @@ public void onClick(View v) {
}
});



rlEye.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -542,12 +556,25 @@ public void onRejected() {

private String checkLogin() {
try {
return doLogin(getResources().getString(R.string.server_url_storage));
String url = serverText.getText().toString();
if(!url.endsWith("/")){
url += "/";
}
return doLogin(url);
}
catch (SeafException e) {
// try again with 2nd server url
e.printStackTrace();
Log.e(DEBUG_TAG, getResources().getString(R.string.auto_server_url_error));
err = e;
if (e == SeafException.sslException) {
return getString(R.string.ssl_error);
} else if (e == SeafException.twoFactorAuthTokenMissing) {
return getString(R.string.two_factor_auth_error);
} else if (e == SeafException.twoFactorAuthTokenInvalid) {
return getString(R.string.two_factor_auth_invalid);
} else {
// try again with 2nd server url
e.printStackTrace();
Log.e(DEBUG_TAG, getResources().getString(R.string.auto_server_url_error));
}
}
try {
return doLogin(getResources().getString(R.string.server_url_sync));
Expand Down Expand Up @@ -601,5 +628,4 @@ private String doLogin(String serverURL) throws SeafException{
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,19 @@ private void uploadFile(DataManager dataManager, File file, String bucketName) t
}

// Log.d(DEBUG_TAG, "uploading file " + file.getName() + " to " + serverPath);

Utils.utilsLogInfo(true,"====uploading file " + file.getName() + " to " + serverPath);
int taskID = txService.addUploadTask(dataManager.getAccount(), targetRepoId, targetRepoName,
serverPath, file.getAbsolutePath(), false, false);
final SeafRepo repo = dataManager.getCachedRepoByID(targetRepoId);
int taskID = 0;
if (repo != null && repo.canLocalDecrypt()) {
taskID = txService.addTaskToUploadQueBlock(dataManager.getAccount(), targetRepoId, targetRepoName,
serverPath, file.getAbsolutePath(), false, false);
}
else {
taskID = txService.addUploadTask(dataManager.getAccount(), targetRepoId, targetRepoName,
serverPath, file.getAbsolutePath(), false, false);
}

tasksInProgress.add(taskID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ protected SeafRepo getChildSeafRepo(int position) {
public boolean isEnabled(int position) {
// if repo is encrypted, disable it
// because camera upload service doesn`t support it
return !(repos.get(position).encrypted);
return true;
// return !(repos.get(position).encrypted);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,9 @@ private void updateAdapterWithRepos(List<SeafRepo> repos) {
// remove encrypted repos in order to "hide" them in selection list
List<SeafRepo> filteredRepos = Lists.newArrayList();
for (SeafRepo repo : repos) {
if (!repo.encrypted)
filteredRepos.add(repo);
filteredRepos.add(repo);
// if (!repo.encrypted)
// filteredRepos.add(repo);
}
getReposAdapter().setRepos(filteredRepos);
showListOrEmptyText(filteredRepos.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public List<SeafRepo> getReposFromServer() throws SeafException {
return reposCache;
}

private void getEncryptRepo(String repoID) throws SeafException {
public void getEncryptRepo(String repoID) throws SeafException {
String json = sc.getEncryptRepo(repoID);
//Save to Cache
if (!TextUtils.isEmpty(json)) {
Expand Down
64 changes: 46 additions & 18 deletions app/src/main/java/com/seafile/seadroid2/editor/EditorActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.seafile.seadroid2.editor;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
Expand All @@ -13,9 +14,10 @@
import com.seafile.seadroid2.R;
import com.seafile.seadroid2.SeafException;
import com.seafile.seadroid2.editor.widget.HorizontalEditScrollView;
import com.seafile.seadroid2.monitor.FileMonitorService;
import com.seafile.seadroid2.ui.activity.BaseActivity;
import com.seafile.seadroid2.ui.dialog.FileSaveTaskDialog;
import com.seafile.seadroid2.ui.dialog.TaskDialog;
import com.seafile.seadroid2.util.ConcurrentAsyncTask;
import com.seafile.seadroid2.util.Utils;
import com.yydcdut.markdown.MarkdownConfiguration;
import com.yydcdut.markdown.MarkdownEditText;
import com.yydcdut.markdown.MarkdownProcessor;
Expand Down Expand Up @@ -146,7 +148,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
mPerformEdit.redo();
break;
case R.id.edit_save:
showSaveDialog();
// showSaveDialog();
saveFile();
break;
}
return super.onOptionsItemSelected(item);
Expand All @@ -162,28 +165,53 @@ public void onBackPressed() {
if (isSave) {
super.onBackPressed();
} else {
showSaveDialog();
// showSaveDialog();
saveFile();
}
}

@Override
protected void onResume() {
super.onResume();
if (!com.seafile.seadroid2.util.Utils.isServiceRunning(EditorActivity.this, "com.seafile.seadroid2.monitor.FileMonitorService")) {
Intent monitorIntent = new Intent(EditorActivity.this, FileMonitorService.class);
EditorActivity.this.startService(monitorIntent);
Utils.utilsLogInfo(true, "---------FileMonitorService is not running, start it in EditorActivity");
}
}

private void showSaveDialog() {
FileSaveTaskDialog dialog = new FileSaveTaskDialog();
dialog.init(path, mMarkdownEditText);
dialog.setTaskDialogLisenter(new TaskDialog.TaskDialogListener() {
@Override
public void onTaskSuccess() {
// save file success
isSave = true;
Toast.makeText(EditorActivity.this, getString(R.string.editor_file_save_success), Toast.LENGTH_SHORT).show();
finish();
private void saveFile() {
Task task = new Task();
ConcurrentAsyncTask.execute(task);
}


public class Task extends AsyncTask<Void, Long, Void> {
private SeafException err;

protected void setTaskException(SeafException e) {
err = e;
}

@Override
public Void doInBackground(Void... params) {
try {
Utils.writeFile(new File(path), mMarkdownEditText.getText().toString());
} catch (IOException e) {
setTaskException(new SeafException(SeafException.OTHER_EXCEPTION, "File save failed"));
}
return null;
}

@Override
public void onTaskFailed(SeafException e) {
@Override
public void onPostExecute(Void result) {
if (err != null) {
Toast.makeText(EditorActivity.this, getString(R.string.editor_file_save_failed), Toast.LENGTH_SHORT).show();
} else {
isSave = true;
Toast.makeText(EditorActivity.this, getString(R.string.editor_file_save_success), Toast.LENGTH_SHORT).show();
finish();
}
});
dialog.show(getSupportFragmentManager(), "FileSaveTaskDialog");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public SeafileObserver(Account account, CachedFileChangedListener listener) {
this.listener = listener;
alterationObserver = new FileAlterationObserver(getAccountDir());
alterationObserver.addListener(this);
startWatching();
watchAllCachedFiles();
}

Expand Down Expand Up @@ -82,6 +83,9 @@ public Account getAccount() {
public void startWatching() {
try {
alterationObserver.initialize();
FileAlterationObserverRunner fileAlterationObserverRunner = new FileAlterationObserverRunner(alterationObserver);
Thread observer = new Thread(fileAlterationObserverRunner);
observer.start();
} catch (Exception e) {

}
Expand All @@ -96,6 +100,26 @@ public void stopWatching() {
}
}

public class FileAlterationObserverRunner implements Runnable {
private final FileAlterationObserver fileAlterationObserver;

public FileAlterationObserverRunner(FileAlterationObserver fileAlterationObserver) {
this.fileAlterationObserver = fileAlterationObserver;
}

@Override
public void run() {
while (true) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
fileAlterationObserver.checkAndNotify();
}
}
}

@Override
public void onDirectoryChange(File directory) {
Log.v(DEBUG_TAG, directory.getPath() + " was modified!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ protected String[] getCipherList() {
"DHE-RSA-AES128-SHA",
"DHE-RSA-AES256-SHA",
"DHE-DSS-AES128-SHA",
"DHE-RSA-CHACHA20-POLY1305",
"AES128-SHA",
"AES256-SHA"
};
Expand All @@ -138,6 +139,11 @@ protected String[] getCipherList() {
"TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",

// ChaCha20 support for servers without AES hardware
// acceleration (eg. Raspberry Pi 4)
"TLS_CHACHA20_POLY1305_SHA256",
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",

// backward compatibility. offers no forward security.
"TLS_RSA_WITH_AES_128_CBC_SHA",
"TLS_RSA_WITH_AES_256_CBC_SHA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2270,10 +2270,11 @@ private void chooseCopyMoveDestForMultiFiles(String repoID, String repoName, Str
Intent intent = new Intent(this, SeafilePathChooserActivity.class);
intent.putExtra(SeafilePathChooserActivity.DATA_ACCOUNT, account);
SeafRepo repo = getDataManager().getCachedRepoByID(repoID);
boolean isShowEncryptDir = false;
boolean isShowEncryptDir = true;
if (repo.encrypted) {
intent.putExtra(SeafilePathChooserActivity.ENCRYPTED_REPO_ID, repoID);
}
intent.putExtra(SeafilePathChooserActivity.REPO_ENCRYPTED, repo.encrypted);
intent.putExtra(SeafilePathChooserActivity.SHOW_ENCRYPTED_REPOS, isShowEncryptDir);
startActivityForResult(intent, BrowserActivity.CHOOSE_COPY_MOVE_DEST_REQUEST);
}
Expand Down
Loading

0 comments on commit be99fc5

Please sign in to comment.