|
@@ -38,6 +38,7 @@ import android.content.IntentFilter;
|
|
import android.content.ServiceConnection;
|
|
import android.content.ServiceConnection;
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.PackageManager;
|
|
import android.content.res.Resources.NotFoundException;
|
|
import android.content.res.Resources.NotFoundException;
|
|
|
|
+import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
import android.os.Parcelable;
|
|
import android.os.Parcelable;
|
|
@@ -52,6 +53,7 @@ import com.google.android.material.snackbar.Snackbar;
|
|
import com.nextcloud.client.account.User;
|
|
import com.nextcloud.client.account.User;
|
|
import com.nextcloud.client.appinfo.AppInfo;
|
|
import com.nextcloud.client.appinfo.AppInfo;
|
|
import com.nextcloud.client.di.Injectable;
|
|
import com.nextcloud.client.di.Injectable;
|
|
|
|
+import com.nextcloud.client.files.DeepLinkHandler;
|
|
import com.nextcloud.client.media.PlayerServiceConnection;
|
|
import com.nextcloud.client.media.PlayerServiceConnection;
|
|
import com.nextcloud.client.network.ConnectivityService;
|
|
import com.nextcloud.client.network.ConnectivityService;
|
|
import com.nextcloud.client.preferences.AppPreferences;
|
|
import com.nextcloud.client.preferences.AppPreferences;
|
|
@@ -123,8 +125,6 @@ import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.regex.Matcher;
|
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
import javax.annotation.Nullable;
|
|
import javax.inject.Inject;
|
|
import javax.inject.Inject;
|
|
@@ -2291,12 +2291,6 @@ public class FileDisplayActivity extends FileActivity
|
|
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
|
|
transaction.replace(R.id.left_fragment_container, fragment, TAG_LIST_OF_FILES);
|
|
transaction.commit();
|
|
transaction.commit();
|
|
}
|
|
}
|
|
-// else {
|
|
|
|
-// Log_OC.d(this, "Switch to OCFileListFragment");
|
|
|
|
-//
|
|
|
|
-// fragment = new OCFileListFragment();
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
@@ -2408,44 +2402,54 @@ public class FileDisplayActivity extends FileActivity
|
|
String fileId = intent.getStringExtra(KEY_FILE_ID);
|
|
String fileId = intent.getStringExtra(KEY_FILE_ID);
|
|
|
|
|
|
if (userName == null && fileId == null && intent.getData() != null) {
|
|
if (userName == null && fileId == null && intent.getData() != null) {
|
|
- // Handle intent coming from URI
|
|
|
|
-
|
|
|
|
- Pattern pattern = Pattern.compile("(.*)/index\\.php/([f])/([0-9]+)$");
|
|
|
|
- Matcher matcher = pattern.matcher(intent.getData().toString());
|
|
|
|
- if (matcher.matches()) {
|
|
|
|
- String uri = matcher.group(1);
|
|
|
|
- if ("f".equals(matcher.group(2))) {
|
|
|
|
- fileId = matcher.group(3);
|
|
|
|
- findAccountAndOpenFile(uri, fileId);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ openDeepLink(intent.getData());
|
|
|
|
+ } else {
|
|
|
|
+ Optional<User> optionalUser = userName == null ? getUser() : getUserAccountManager().getUser(userName);
|
|
|
|
+ if (optionalUser.isPresent()) {
|
|
|
|
+ openFile(optionalUser.get(), fileId);
|
|
} else {
|
|
} else {
|
|
dismissLoadingDialog();
|
|
dismissLoadingDialog();
|
|
- DisplayUtils.showSnackMessage(this, getString(R.string.invalid_url));
|
|
|
|
- return;
|
|
|
|
|
|
+ DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- openFile(userName, fileId);
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
- private void openFile(String userName, String fileId) {
|
|
|
|
- Optional<User> optionalNewUser;
|
|
|
|
- User user;
|
|
|
|
|
|
|
|
- if (userName == null) {
|
|
|
|
- optionalNewUser = getUser();
|
|
|
|
|
|
+ private void openDeepLink(Uri uri) {
|
|
|
|
+ DeepLinkHandler linkHandler = new DeepLinkHandler(getUserAccountManager());
|
|
|
|
+ DeepLinkHandler.Match match = linkHandler.parseDeepLink(uri);
|
|
|
|
+ if (match == null) {
|
|
|
|
+ dismissLoadingDialog();
|
|
|
|
+ DisplayUtils.showSnackMessage(this, getString(R.string.invalid_url));
|
|
|
|
+ } else if (match.getUsers().isEmpty()) {
|
|
|
|
+ dismissLoadingDialog();
|
|
|
|
+ DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found));
|
|
|
|
+ } else if (match.getUsers().size() == 1) {
|
|
|
|
+ openFile(match.getUsers().get(0), match.getFileId());
|
|
} else {
|
|
} else {
|
|
- optionalNewUser = getUserAccountManager().getUser(userName);
|
|
|
|
|
|
+ selectUserAndOpenFile(match.getUsers(), match.getFileId());
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- if (optionalNewUser.isPresent()) {
|
|
|
|
- user = optionalNewUser.get();
|
|
|
|
- setUser(user);
|
|
|
|
- } else {
|
|
|
|
- dismissLoadingDialog();
|
|
|
|
- DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found));
|
|
|
|
- return;
|
|
|
|
|
|
+ private void selectUserAndOpenFile(List<User> users, String fileId) {
|
|
|
|
+ final CharSequence[] userNames = new CharSequence[users.size()];
|
|
|
|
+ for (int i = 0; i < userNames.length; i++) {
|
|
|
|
+ userNames[i] = users.get(i).getAccountName();
|
|
}
|
|
}
|
|
|
|
+ final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
+ builder
|
|
|
|
+ .setTitle(R.string.common_choose_account)
|
|
|
|
+ .setItems(userNames, (dialog, which) -> {
|
|
|
|
+ User user = users.get(which);
|
|
|
|
+ openFile(user, fileId);
|
|
|
|
+ showLoadingDialog(getString(R.string.retrieving_file));
|
|
|
|
+ });
|
|
|
|
+ final AlertDialog dialog = builder.create();
|
|
|
|
+ dismissLoadingDialog();
|
|
|
|
+ dialog.show();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void openFile(User user, String fileId) {
|
|
|
|
+ setUser(user);
|
|
|
|
|
|
if (fileId == null) {
|
|
if (fileId == null) {
|
|
dismissLoadingDialog();
|
|
dismissLoadingDialog();
|
|
@@ -2466,46 +2470,4 @@ public class FileDisplayActivity extends FileActivity
|
|
fetchRemoteFileTask.execute();
|
|
fetchRemoteFileTask.execute();
|
|
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- private void findAccountAndOpenFile(String uri, String fileId) {
|
|
|
|
-
|
|
|
|
- ArrayList<User> validUsers = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- for (User user : getUserAccountManager().getAllUsers()) {
|
|
|
|
- if (user.getServer().getUri().toString().equals(uri)) {
|
|
|
|
- validUsers.add(user);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (validUsers.size() == 0) {
|
|
|
|
- dismissLoadingDialog();
|
|
|
|
- DisplayUtils.showSnackMessage(this, getString(R.string.associated_account_not_found));
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (validUsers.size() == 1) {
|
|
|
|
- openFile(validUsers.get(0).getAccountName(), fileId);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- ArrayList<String> validUserNames = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- for (User user : validUsers) {
|
|
|
|
- validUserNames.add(user.getAccountName());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
|
|
- builder
|
|
|
|
- .setTitle(R.string.common_choose_account)
|
|
|
|
- .setItems(validUserNames.toArray(new CharSequence[validUserNames.size()]),
|
|
|
|
- new DialogInterface.OnClickListener() {
|
|
|
|
- public void onClick(DialogInterface dialog, int which) {
|
|
|
|
- openFile(validUsers.get(which).getAccountName(), fileId);
|
|
|
|
- showLoadingDialog(getString(R.string.retrieving_file));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- AlertDialog dialog = builder.create();
|
|
|
|
- dismissLoadingDialog();
|
|
|
|
- dialog.show();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|