Skip to content

Commit

Permalink
Merge pull request #704 from haiwen/share_for_wechat
Browse files Browse the repository at this point in the history
Share for wechat
  • Loading branch information
freeplant authored Nov 5, 2017
2 parents 26b56e4 + b421cb8 commit ce92ef1
Show file tree
Hide file tree
Showing 27 changed files with 177 additions and 62 deletions.
6 changes: 2 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId 'com.seafile.seadroid2'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 72
versionName "2.1.18"
versionCode 73
versionName "2.1.19"
multiDexEnabled true
resValue "string", "authorities", applicationId + '.cameraupload.provider'
resValue "string", "account_type", "com.seafile.seadroid2.account.api2"
Expand Down Expand Up @@ -119,5 +119,3 @@ android {

}

dependencies {
}
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.seafile.seadroid2"
android:versionCode="72"
android:versionName="2.1.18">
package="com.seafile.seadroid2">

<uses-sdk
tools:overrideLibrary="us.feras.mdv" />
Expand Down
72 changes: 72 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/ui/WidgetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,79 @@ public void onTaskSuccess() {

}

/**
* if dir will share dir link .
* if local file ,will share file to wachat app.
* if server file , it will download file and share file.
*
* @param activity
* @param account
* @param repoID
* @param path
* @param fileName
* @param fileSize
* @param isdir
*/
public static void ShareWeChat(final BaseActivity activity, Account account, String repoID, String path,
String fileName,
long fileSize,
boolean isdir) {

if (isdir) {//share link
final Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
ResolveInfo weChatInfo = Utils.getWeChatIntent(shareIntent);
if (weChatInfo == null) {
activity.showShortToast(activity, R.string.no_app_available);
return;
}
String className = weChatInfo.activityInfo.name;
String packageName = weChatInfo.activityInfo.packageName;
shareIntent.setClassName(packageName, className);
final GetShareLinkDialog gdialog = new GetShareLinkDialog();
gdialog.init(repoID, path, isdir, account, null, null);
gdialog.setTaskDialogLisenter(new TaskDialog.TaskDialogListener() {
@Override
public void onTaskSuccess() {
shareIntent.putExtra(Intent.EXTRA_TEXT, gdialog.getLink());
activity.startActivity(shareIntent);
}
});
gdialog.show(activity.getSupportFragmentManager(), "DialogFragment");
} else {//share files
BrowserActivity browserActivity = ((BrowserActivity) activity);
String repoName = ((BrowserActivity) activity).getNavContext().getRepoName();
String dirPath = ((BrowserActivity) activity).getNavContext().getDirPath();

String fullPath = Utils.pathJoin(dirPath, fileName);
final File file = browserActivity.getDataManager().getLocalRepoFile(repoName, repoID, fullPath);
Uri uri = null;
if (android.os.Build.VERSION.SDK_INT > 23) {
uri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", file);
} else {
uri = Uri.fromFile(file);
}
final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType(Utils.getFileMimeType(file));
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
ResolveInfo weChatInfo = Utils.getWeChatIntent(sendIntent);
if (weChatInfo == null) {
activity.showShortToast(activity, R.string.no_app_available);
return;
}
String className = weChatInfo.activityInfo.name;
String packageName = weChatInfo.activityInfo.packageName;
sendIntent.setClassName(packageName, className);
if (!Utils.isNetworkOn() && file.exists()) {
activity.startActivity(sendIntent);
return;
}
browserActivity.fetchFileAndExport(weChatInfo, sendIntent, repoName, repoID, path, fileSize);

}
}
/**
* display the file according to its file type
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ public void onAppSelected(ResolveInfo appInfo) {
dialog.show(getSupportFragmentManager(), CHOOSE_APP_DIALOG_FRAGMENT_TAG);
}

private void fetchFileAndExport(final ResolveInfo appInfo, final Intent intent,
public void fetchFileAndExport(final ResolveInfo appInfo, final Intent intent,
final String repoName, final String repoID, final String path, final long fileSize) {

fetchFileDialog = new FetchFileDialog();
Expand Down Expand Up @@ -1902,25 +1902,41 @@ public void onTaskSuccess() {
}

/**
* Share a file. Generating a file share link and send the link to someone
* Share a file. Generating a file share link and send the link or file to someone
* through some app.
* @param repoID
* @param path
*/
public void shareFile(final String repoID, final String path, boolean isEncrypt) {
if (isEncrypt) {
WidgetUtils.inputSharePassword(this, repoID, path, false, account);
} else {
WidgetUtils.chooseShareApp(this, repoID, path, false, account, null, null);
}
}

public void shareDir(String repoID, String path, boolean isEncrypt) {
if (isEncrypt) {
WidgetUtils.inputSharePassword(this, repoID, path, true, account);
public void showShareDialog(String repoID, String path, boolean isDir, long fileSize, String fileName) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
boolean inChina = Utils.isInChina();
String[] strings;
//if user in China ,system add WeChat share
if (inChina) {
strings = getResources().getStringArray(R.array.file_action_share_array_zh);
} else {
WidgetUtils.chooseShareApp(this, repoID, path, true, account, null, null);
strings = getResources().getStringArray(R.array.file_action_share_array);
}
builder.setItems(strings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!inChina) {
which++;
}
switch (which) {
case 0:
WidgetUtils.ShareWeChat(BrowserActivity.this, account, repoID, path, fileName, fileSize, isDir);
break;
case 1:
// need input password
WidgetUtils.chooseShareApp(BrowserActivity.this, repoID, path, isDir, account, null, null);
break;
case 2:
WidgetUtils.inputSharePassword(BrowserActivity.this, repoID, path, isDir, account);
break;
}
}
}).show();
}

public void renameFile(String repoID, String repoName, String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,7 @@ public void showFileBottomSheet(String title, final SeafDirent dirent) {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case R.id.share:
mActivity.shareFile(repoID, path, false);
break;
case R.id.share_encrypt:
mActivity.shareFile(repoID, path, true);
mActivity.showShareDialog(repoID, path, false, dirent.size,dirent.name);
break;
case R.id.delete:
mActivity.deleteFile(repoID, repoName, path);
Expand Down Expand Up @@ -279,10 +276,7 @@ public void showDirBottomSheet(String title, final SeafDirent dirent) {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case R.id.share:
mActivity.shareDir(repoID, path, false);
break;
case R.id.share_encrypt:
mActivity.shareDir(repoID, path, true);
mActivity.showShareDialog(repoID, path, true, dirent.size, dirent.name);
break;
case R.id.delete:
mActivity.deleteDir(repoID, repoName, path);
Expand Down
31 changes: 31 additions & 0 deletions app/src/main/java/com/seafile/seadroid2/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.net.http.SslCertificate;
import android.os.Build;
import android.os.Bundle;
import android.os.LocaleList;
import android.provider.OpenableColumns;
import android.support.annotation.NonNull;
import android.text.TextUtils;
Expand Down Expand Up @@ -68,6 +69,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TreeMap;

public class Utils {
Expand Down Expand Up @@ -651,6 +653,35 @@ public static String cleanServerURL(String serverURL) throws MalformedURLExcepti
return serverURL;
}

public static ResolveInfo getWeChatIntent(Intent intent) {
PackageManager pm = SeadroidApplication.getAppContext().getPackageManager();
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);

ResolveInfo info = null;
Iterator<ResolveInfo> iter = infos.iterator();
while (iter.hasNext()) {
info = iter.next();
if (info.activityInfo.packageName.equals("com.tencent.mm")) {
break;
}
}
return info;
}


/**
* use compare user system is chinese
*/
public static boolean isInChina() {
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = LocaleList.getDefault().get(0);
} else {
locale = Locale.getDefault();
}
String language = locale.getCountry();
return TextUtils.equals("CN",language)||TextUtils.equals("TW",language);
}
public static List<ResolveInfo> getAppsByIntent(Intent intent) {
PackageManager pm = SeadroidApplication.getAppContext().getPackageManager();
List<ResolveInfo> infos = pm.queryIntentActivities(intent, 0);
Expand Down
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 @@ -68,7 +68,7 @@
android:layout_gravity="center_horizontal"
android:textColor="@color/white"
android:textSize="@dimen/lv_expandable_txt_size"
android:text="@string/file_action_share"/>
android:text="@string/file_action_share_link"/>
</LinearLayout>

<LinearLayout android:layout_width="wrap_content"
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/res/menu/bottom_sheet_op_dir.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
<item
android:id="@+id/share"
android:icon="@drawable/action_share"
android:title="@string/file_action_share" />

<item
android:id="@+id/share_encrypt"
android:icon="@drawable/action_share_password"
android:title="@string/file_action_share_encrypt" />
android:title="@string/file_share"/>

<item
android:id="@+id/rename"
Expand Down
6 changes: 1 addition & 5 deletions app/src/main/res/menu/bottom_sheet_op_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
<item
android:id="@+id/share"
android:icon="@drawable/action_share"
android:title="@string/file_action_share" />
<item
android:id="@+id/share_encrypt"
android:icon="@drawable/action_share_password"
android:title="@string/file_action_share_encrypt"/>
android:title="@string/file_share"/>

<item
android:id="@+id/export"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-cs-rCZ/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<string name="file_action_star">Oblíbené</string>
<string name="file_action_download">Stáhnout</string>
<string name="file_action_update">Nahrát</string>
<string name="file_action_share">Sdílet odkaz</string>
<string name="file_action_share_link">Sdílet odkaz</string>
<string name="file_action_export">Exportovat</string>
<string name="file_action_delete">Smazat</string>
<string name="file_action_rename">Přejmenovat</string>
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 @@ -74,7 +74,7 @@
<string name="file_action_star">Markieren</string>
<string name="file_action_download">Herunterladen</string>
<string name="file_action_update">Hochladen</string>
<string name="file_action_share">Link freigeben</string>
<string name="file_action_share_link">Link freigeben</string>
<string name="file_action_share_encrypt">Freigabe-Link mit Passwort</string>
<string name="file_action_export">Exportieren</string>
<string name="file_action_delete">Löschen</string>
Expand Down
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 @@ -74,7 +74,7 @@
<string name="file_action_star">Favorito</string>
<string name="file_action_download">Descargar</string>
<string name="file_action_update">Subir</string>
<string name="file_action_share">Compartir enlace</string>
<string name="file_action_share_link">Compartir enlace</string>
<string name="file_action_share_encrypt">Compartir enlace utilizando contraseña</string>
<string name="file_action_export">Exportar</string>
<string name="file_action_delete">Eliminar</string>
Expand Down
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 @@ -74,7 +74,7 @@
<string name="file_action_star">Favorito</string>
<string name="file_action_download">Descargar</string>
<string name="file_action_update">Subir</string>
<string name="file_action_share">Compartir enlace</string>
<string name="file_action_share_link">Compartir enlace</string>
<string name="file_action_share_encrypt">Compartir enlace utilizando contraseña</string>
<string name="file_action_export">Exportar</string>
<string name="file_action_delete">Eliminar</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<string name="file_action_star">Favori</string>
<string name="file_action_download">Télécharger</string>
<string name="file_action_update">Envoi</string>
<string name="file_action_share">Partager le lien</string>
<string name="file_action_share_link">Partager le lien</string>
<string name="file_action_share_encrypt">Lien partagé avec mot de passe</string>
<string name="file_action_export">Exporter</string>
<string name="file_action_delete">Effacer</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<string name="file_action_star">Kedvenc</string>
<string name="file_action_download">Letöltés</string>
<string name="file_action_update">Feltölt</string>
<string name="file_action_share">Megosztási link</string>
<string name="file_action_share_link">Megosztási link</string>
<string name="file_action_share_encrypt">Megosztás link jelszóval</string>
<string name="file_action_export">Exportálás</string>
<string name="file_action_delete">Törlés</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-is-rIS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<string name="file_action_star">Stjarna</string>
<string name="file_action_download">Hala niður</string>
<string name="file_action_update">Hlaða upp</string>
<string name="file_action_share">Deilihlekkur</string>
<string name="file_action_share_link">Deilihlekkur</string>
<string name="file_action_export">Flytja út</string>
<string name="file_action_delete">Eyða</string>
<string name="file_action_rename">Endurnefna</string>
Expand Down
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 @@ -74,7 +74,7 @@
<string name="file_action_star">スター</string>
<string name="file_action_download">ダウンロード</string>
<string name="file_action_update">アップロード</string>
<string name="file_action_share">リンクを共有</string>
<string name="file_action_share_link">リンクを共有</string>
<string name="file_action_share_encrypt">リンクをパスワードで共有</string>
<string name="file_action_export">エクスポート</string>
<string name="file_action_delete">削除</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<string name="file_action_star">별 표시</string>
<string name="file_action_download">다운로드</string>
<string name="file_action_update">업로드</string>
<string name="file_action_share">공유 링크</string>
<string name="file_action_share_link">공유 링크</string>
<string name="file_action_share_encrypt">암호로 보호한 링크 공유</string>
<string name="file_action_export">내보내기</string>
<string name="file_action_delete">삭제</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nb-rNO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<string name="file_action_star">Favoritt</string>
<string name="file_action_download">Last ned</string>
<string name="file_action_update">Laste opp</string>
<string name="file_action_share">Del lenke</string>
<string name="file_action_share_link">Del lenke</string>
<string name="file_action_export">Eksportere</string>
<string name="file_action_delete">Slette</string>
<string name="file_action_rename">Omdøpe</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nl-rNL/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<string name="file_action_star">Ster</string>
<string name="file_action_download">Downloaden</string>
<string name="file_action_update">Uploaden</string>
<string name="file_action_share">Link om te delen</string>
<string name="file_action_share_link">Link om te delen</string>
<string name="file_action_export">Exporteren</string>
<string name="file_action_delete">Verwijderen</string>
<string name="file_action_rename">Hernoemen</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pl-rPL/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<string name="file_action_star">Ulubione</string>
<string name="file_action_download">Pobierz</string>
<string name="file_action_update">Prześlij</string>
<string name="file_action_share">Łącze udostępniania</string>
<string name="file_action_share_link">Łącze udostępniania</string>
<string name="file_action_share_encrypt">Udostępnij łącze z hasłem</string>
<string name="file_action_export">Wyeksportuj</string>
<string name="file_action_delete">Usuń</string>
Expand Down
Loading

0 comments on commit ce92ef1

Please sign in to comment.