Skip to content

Commit

Permalink
Merge pull request #768 from haiwen/add_editor_select
Browse files Browse the repository at this point in the history
Add editor select
  • Loading branch information
freeplant authored Nov 19, 2018
2 parents 0587eeb + d6854df commit 7a55af0
Show file tree
Hide file tree
Showing 30 changed files with 93 additions and 49 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 83
versionName "2.2.8"
versionCode 84
versionName "2.2.9"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,27 @@ public void onTaskSuccess() {

}
}

public static void showFile(final BaseActivity activity, File file) {
showFile(activity, file, false);
}

/**
* display the file according to its file type
*
* @param file
*/
public static void showFile(final BaseActivity activity, File file) {
public static void showFile(final BaseActivity activity, File file, boolean isOpenWith) {

String name = file.getName();
String suffix = name.substring(name.lastIndexOf('.') + 1).toLowerCase();

// Open markdown and txt files in MarkdownActivity
if ("md".equals(suffix) || "markdown".equals(suffix) || "txt".equals(suffix)) {
startMarkdownActivity(activity, file.getPath());
activity.overridePendingTransition(0, 0);
return;
if (!isOpenWith) {
//Open markdown and txt files in MarkdownActivity
if ("md".equals(suffix) || "markdown".equals(suffix) || "txt".equals(suffix)) {
startMarkdownActivity(activity, file.getPath());
activity.overridePendingTransition(0, 0);
return;
}
}

String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v4.app.NavUtils;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,8 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
case DOWNLOAD_FILE_REQUEST:
if (resultCode == RESULT_OK) {
File file = new File(data.getStringExtra("path"));
WidgetUtils.showFile(BrowserActivity.this, file);
boolean isOpenWith = data.getBooleanExtra("is_open_with", false);
WidgetUtils.showFile(BrowserActivity.this, file, isOpenWith);
}
default:
break;
Expand Down Expand Up @@ -1507,8 +1508,7 @@ public void onItemSelected() {

/*************** Navigation *************/

@Override
public void onFileSelected(SeafDirent dirent) {
public void onFileSelected(SeafDirent dirent,boolean isOpenWith) {
final String fileName= dirent.name;
final long fileSize = dirent.size;
final String repoName = navContext.getRepoName();
Expand All @@ -1527,7 +1527,7 @@ public void onFileSelected(SeafDirent dirent) {

final File localFile = dataManager.getLocalCachedFile(repoName, repoID, filePath, dirent.id);
if (localFile != null) {
WidgetUtils.showFile(this, localFile);
WidgetUtils.showFile(this, localFile, isOpenWith);
return;
}
boolean videoFile = Utils.isVideoFile(fileName);
Expand All @@ -1539,12 +1539,17 @@ public void onClick(DialogInterface dialog, int which) {
if (which == 0) // create file
startPlayActivity(fileName, repoID, filePath);
else if (which == 1) // create folder
startFileActivity(repoName, repoID, filePath, fileSize);
startFileActivity(repoName, repoID, filePath, fileSize, isOpenWith);
}
}).show();
return;
}
startFileActivity(repoName, repoID, filePath, fileSize);
startFileActivity(repoName, repoID, filePath, fileSize, isOpenWith);
}

@Override
public void onFileSelected(SeafDirent dirent) {
onFileSelected(dirent, false);
}

/**
Expand Down Expand Up @@ -1701,6 +1706,10 @@ protected void onPostExecute(List<SeafDirent> dirents) {
}

private void startFileActivity(String repoName, String repoID, String filePath, long fileSize) {
startFileActivity(repoName, repoID, filePath, fileSize);
}

private void startFileActivity(String repoName, String repoID, String filePath, long fileSize, boolean isOpenWith) {
// txService maybe null if layout orientation has changed
if (txService == null) {
return;
Expand All @@ -1712,6 +1721,7 @@ private void startFileActivity(String repoName, String repoID, String filePath,
intent.putExtra("filePath", filePath);
intent.putExtra("account", account);
intent.putExtra("taskID", taskID);
intent.putExtra("is_open_with", isOpenWith);
startActivityForResult(intent, DOWNLOAD_FILE_REQUEST);
}

Expand All @@ -1721,12 +1731,12 @@ private void startPlayActivity(String fileName, String repoID, String filePath)
intent.putExtra("repoID", repoID);
intent.putExtra("filePath", filePath);
intent.putExtra("account", account);
// DOWNLOAD_PLAY_REQUEST
//DOWNLOAD_PLAY_REQUEST
startActivity(intent );
}

@Override
public void onStarredFileSelected(final SeafStarredFile starredFile) {

public void onStarredFileSelected(final SeafStarredFile starredFile, boolean isOpenWith) {
final long fileSize = starredFile.getSize();
final String repoID = starredFile.getRepoID();
final SeafRepo repo = dataManager.getCachedRepoByID(repoID);
Expand Down Expand Up @@ -1763,7 +1773,12 @@ public void onTaskSuccess() {
return;
}

startFileActivity(repoName, repoID, filePath, fileSize);
startFileActivity(repoName, repoID, filePath, fileSize, isOpenWith);
}

@Override
public void onStarredFileSelected(SeafStarredFile starredFile) {
onStarredFileSelected(starredFile, false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.seafile.seadroid2.SeafException;
import com.seafile.seadroid2.account.Account;
import com.seafile.seadroid2.data.DataManager;
import com.seafile.seadroid2.data.SeafRepo;
import com.seafile.seadroid2.notification.DownloadNotificationProvider;
import com.seafile.seadroid2.transfer.DownloadTaskInfo;
import com.seafile.seadroid2.transfer.TaskState;
Expand Down Expand Up @@ -71,6 +70,7 @@ public void onServiceDisconnected(ComponentName arg0) {
};

private final Handler mTimer = new Handler();
private boolean isOpenWith;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -81,7 +81,7 @@ protected void onCreate(Bundle savedInstanceState) {
mRepoID = intent.getStringExtra("repoID");
mFilePath = intent.getStringExtra("filePath");
mTaskID = intent.getIntExtra("taskID", 0);

isOpenWith = intent.getBooleanExtra("is_open_with", false);
mDataManager = new DataManager(mAccount);

setContentView(R.layout.file_activity);
Expand Down Expand Up @@ -209,6 +209,7 @@ private void onFileDownloaded() {
if (file != null && timerStarted) {
Intent result = new Intent();
result.putExtra("path", file.getAbsolutePath());
result.putExtra("is_open_with", isOpenWith);
setResult(RESULT_OK, result);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;

import br.tiagohm.markdownview.MarkdownView;
import br.tiagohm.markdownview.Utils;
import br.tiagohm.markdownview.css.InternalStyleSheet;
import br.tiagohm.markdownview.css.styles.Github;

Expand Down Expand Up @@ -60,7 +61,12 @@ public void onResume() {
css.addRule("body", new String[]{"line-height: 1.6", "padding: 0px"});
css.addRule("a", "color: orange");
markdownView.addStyleSheet(css);
markdownView.loadMarkdownFromFile(file);
try {
markdownView.loadMarkdownFromFile(file);
} catch (Exception e) {
markdownView.loadData(Utils.getStringFromFile(file), "text/plain", "UTF-8");
e.printStackTrace();
}

getSupportActionBar().setTitle(file.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ public void showFileBottomSheet(String title, final SeafDirent dirent) {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case R.id.share:
mActivity.showShareDialog(repoID, path, false, dirent.size,dirent.name);
mActivity.showShareDialog(repoID, path, false, dirent.size, dirent.name);
break;
case R.id.open:
mActivity.onFileSelected(dirent, true);
break;
case R.id.delete:
mActivity.deleteFile(repoID, repoName, path);
Expand Down
Binary file modified app/src/main/res/drawable-xhdpi/action_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/action_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/src/main/res/drawable-xxhdpi/action_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/action_open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/action_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/group_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/action_move"/>
android:src="@drawable/action_open"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/bottom_sheet_op_dir.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:title="@string/file_action_copy" />
<item
android:id="@+id/move"
android:icon="@drawable/action_move"
android:icon="@drawable/action_open"
android:title="@string/file_action_move" />
<group android:id="@+id/group_update">
<item
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/bottom_sheet_op_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
android:id="@+id/export"
android:icon="@drawable/action_export"
android:title="@string/file_action_export" />

<item
android:id="@+id/open"
android:icon="@drawable/action_open"
android:title="@string/file_action_open"/>


<group android:id="@+id/group_manage">
<item
android:id="@+id/star"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ E-Mail: [email protected]<br>
<string name="editor_file_save_failed">Zwischenspeicher konnte nicht gelöscht werden</string>
<string name="editor_file_save_title">Datei speichern</string>
<string name="description">Beschreibung</string>
<string name="link">Link</string>
<string name="undo">Rückgängig</string>
<string name="redo">Wiederholen</string>
<string name="link">Link</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-es-rAR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
<string name="editor_file_save_failed">Falló borrar el caché</string>
<string name="editor_file_save_title">Guardar archivo</string>
<string name="description">Descripción</string>
<string name="link">Enlace</string>
<string name="undo">deshacer</string>
<string name="redo">rehacer</string>
<string name="link">Enlace</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
<string name="editor_file_save_failed">Falló borrar el caché</string>
<string name="editor_file_save_title">Guardar archivo</string>
<string name="description">Descripción</string>
<string name="link">Enlace</string>
<string name="undo">deshacer</string>
<string name="redo">rehacer</string>
<string name="link">Enlace</string>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -527,4 +527,12 @@ Sähköposti: [email protected]<br>
<string name="add_auto_expiration">Lisää automaattinen päättymisaika</string>
<string name="input_auto_expiration">Ole hyvä ja syötä vanhentumispäivämäärä</string>
<!--editor-->
<string name="editor_file_save">Haluatko tallentaa ja lopettaa?</string>
<string name="editor_file_save_success">Tiedoston tallennus onnistui</string>
<string name="editor_file_save_failed">Välimuistin tyhjennys epäonnistui</string>
<string name="editor_file_save_title">Tallenna tiedosto</string>
<string name="description">Kuvaus</string>
<string name="undo">kumoa</string>
<string name="redo">tee uudelleen</string>
<string name="link">Linkki</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
<string name="editor_file_save_failed">キャッシュのクリアに失敗しました</string>
<string name="editor_file_save_title">ファイルの保存</string>
<string name="description">説明</string>
<string name="link">リンク</string>
<string name="undo">元に戻す</string>
<string name="redo">繰り返し</string>
<string name="link">リンク</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
<string name="editor_file_save_failed">Не удалось очистить кэш</string>
<string name="editor_file_save_title">Сохранение файла</string>
<string name="description">Описание</string>
<string name="link">Ссылка</string>
<string name="undo">отмена</string>
<string name="redo">повтор</string>
<string name="link">Ссылка</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<string name="file_action_share_link">分享链接</string>
<string name="file_action_share_encrypt">分享高级链接</string>
<string name="file_action_export">导出</string>
<string name="file_action_open">打开方式</string>
<string name="file_action_delete">删除</string>
<string name="file_action_rename">重命名</string>
<string name="file_action_copy">复制</string>
Expand Down Expand Up @@ -525,7 +526,7 @@
<string name="editor_file_save_failed">缓存清理失败</string>
<string name="editor_file_save_title">保存文件</string>
<string name="description">描述</string>
<string name="link">链接</string>
<string name="undo">撤销</string>
<string name="redo">还原</string>
<string name="link">链接</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@
<string name="editor_file_save_failed">清理緩存失敗</string>
<string name="editor_file_save_title">保存文件</string>
<string name="description">描述</string>
<string name="link">鏈接</string>
<string name="undo">撤銷</string>
<string name="redo">還原</string>
<string name="link">鏈接</string>
</resources>
21 changes: 11 additions & 10 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<string name="file_action_share_link">Share link</string>
<string name="file_action_share_encrypt">Share link with password</string>
<string name="file_action_export">Export</string>
<string name="file_action_open">Open with</string>
<string name="file_action_delete">Delete</string>
<string name="file_action_rename">Rename</string>
<string name="file_action_copy">Copy</string>
Expand Down Expand Up @@ -543,14 +544,14 @@
<string name="expiration_dates">expiration dates</string>
<string name="add_auto_expiration">Add auto expiration</string>
<string name="input_auto_expiration">Please enter the expiration dates</string>
<!--editor-->
<string name="editor_lines_error">Unable to operate multiple lines</string>
<string name="editor_file_save">Do you want to save and quit?</string>
<string name="editor_file_save_success">File save successfully</string>
<string name="editor_file_save_failed">Cache cleared failed</string>
<string name="editor_file_save_title">File save</string>
<string name="description">Description</string>
<string name="undo">undo</string>
<string name="redo">redo</string>
<string name="link">Link</string>
<!--editor-->
<string name="editor_lines_error">Unable to operate multiple lines</string>
<string name="editor_file_save">Do you want to save and quit?</string>
<string name="editor_file_save_success">File save successfully</string>
<string name="editor_file_save_failed">Cache cleared failed</string>
<string name="editor_file_save_title">File save</string>
<string name="description">Description</string>
<string name="undo">undo</string>
<string name="redo">redo</string>
<string name="link">Link</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 04 14:05:15 CST 2018
#Sat Oct 13 10:58:35 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 comments on commit 7a55af0

Please sign in to comment.