Skip to content

Commit

Permalink
hint
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Sep 1, 2020
1 parent 80a6762 commit 0759823
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="true" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
android:name="android.permission.READ_EXTERNAL_STORAGE" tools:remove="true" />

<application
android:name=".PixEz"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CrashHandler : Thread.UncaughtExceptionHandler {
toast.show()
} else if (ex.message!!.toLowerCase(Locale.ROOT).contains("document")) {
val toast = Toast.makeText(mContext, """
SAF进行文件读写操作时出现异常,这似乎是由于未正确配置授权目录引起的,请前往应用内设置页,更改保存目录为Picture目录下的任意文件夹,或清除数据后重新选择目录
SAF进行文件读写操作时出现异常,这似乎是由于未正确配置授权目录引起的,请前往应用内设置页,更改保存目录为Picture目录下的任意文件夹,不要选择Donwload下载目录,或清除数据后重新选择目录
${ex.message}
""".trimIndent(), Toast.LENGTH_LONG)
toast.setGravity(Gravity.CENTER, 0, 0)
Expand Down
13 changes: 10 additions & 3 deletions android/app/src/main/kotlin/com/perol/pixez/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Bundle
import android.provider.DocumentsContract
import android.webkit.MimeTypeMap
import android.widget.Toast
Expand All @@ -38,6 +37,8 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.util.*
import kotlin.Comparator

class MainActivity : FlutterActivity() {
private val CHANNEL = "com.perol.dev/save"
Expand All @@ -60,11 +61,12 @@ class MainActivity : FlutterActivity() {
"$parentUri/$fileName"
}

private fun choiceFolder() {
private fun choiceFolder(needHint: Boolean = true) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
Toast.makeText(context, getString(R.string.choose_a_suitable_image_storage_directory), Toast.LENGTH_SHORT).show()
if (needHint)
Toast.makeText(context, getString(R.string.choose_a_suitable_image_storage_directory), Toast.LENGTH_SHORT).show()
startActivityForResult(intent, OPEN_DOCUMENT_TREE_CODE)
}

Expand Down Expand Up @@ -269,6 +271,11 @@ class MainActivity : FlutterActivity() {
if (resultCode == Activity.RESULT_OK) {
data?.data?.also { uri ->
Log.d("path", uri.toString())
if (uri.toString().toLowerCase(Locale.ROOT).contains("download")) {
Toast.makeText(applicationContext, getString(R.string.do_not_choice_download_folder_message), Toast.LENGTH_LONG).show()
choiceFolder(needHint = false)
return
}
val contentResolver = applicationContext.contentResolver
val takeFlags: Int = Intent.FLAG_GRANT_READ_URI_PERMISSION or
Intent.FLAG_GRANT_WRITE_URI_PERMISSION
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<string name="title_save_path">save path</string>
<string name="choose_a_suitable_image_storage_directory">选择合适的图片保存目录授权</string>
<string name="failure_to_obtain_authorization_may_cause_some_functions_to_fail_or_crash">未正确取得授权,可能会导致部分功能失效或闪退</string>
<string name="encode_success">encode success</string>
<string name="encode_success">合成成功</string>
<string name="do_not_choice_download_folder_message">授权目录包含download目录,可能会导致保存出错,请重新选择保存目录授权</string>
</resources>
1 change: 1 addition & 0 deletions android/app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
<string name="choose_a_suitable_image_storage_directory">選擇合適的資料夾並授權以儲存圖像</string>
<string name="failure_to_obtain_authorization_may_cause_some_functions_to_fail_or_crash">未正確取得授權,可能造成軟體功能異常或崩潰</string>
<string name="encode_success">合成成功</string>
<string name="do_not_choice_download_folder_message">授权目录包含download目录,可能会导致保存出错,请重新选择保存目录授权</string>
</resources>
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
<string name="choose_a_suitable_image_storage_directory">选择合适的图片保存目录授权</string>
<string name="failure_to_obtain_authorization_may_cause_some_functions_to_fail_or_crash">未正确取得授权,可能会导致部分功能失效或闪退</string>
<string name="encode_success">encode success</string>
<string name="do_not_choice_download_folder_message">The authorized directory contains the download directory, which may cause storage errors, please re-select the storage directory authorization</string>
</resources>
3 changes: 0 additions & 3 deletions lib/page/hello/android_hello_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ class _AndroidHelloPageState extends State<AndroidHelloPage> {
(route) => route == null,
);
} else {
Map<Permission, PermissionStatus> statuses = await [
Permission.storage,
].request();
if (await DocumentPlugin.needChoice()) {
await showDialog(
context: context,
Expand Down
86 changes: 28 additions & 58 deletions lib/page/hello/hello_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,7 @@ class _HelloPageState extends State<HelloPage> {
@override
void initState() {
index = userSetting.welcomePageNum;
if (index < 2) {
stackIndex = 0;
} else {
stackIndex = index - 1;
}
_pageController = index < 2
? PageController(initialPage: userSetting.welcomePageNum)
: PageController();
_pageController = PageController(initialPage: userSetting.welcomePageNum);
super.initState();
saveStore.context = this.context;
saveStore.saveStream.listen((stream) {
Expand Down Expand Up @@ -144,63 +137,40 @@ class _HelloPageState extends State<HelloPage> {
}
}

int stackIndex = 0;
var lists = <Widget>[
Observer(builder: (context) {
if (accountStore.now != null)
return RecomSpolightPage();
else
return PreviewPage();
}),
NewPage(),
SearchPage(),
SettingPage()
];

@override
Widget build(BuildContext context) {
return Scaffold(
body: Observer(builder: (_) {
return accountStore.now != null
? (IndexedStack(
index: stackIndex,
children: <Widget>[
PageView.builder(
itemCount: 2,
controller: _pageController,
onPageChanged: (index) {
setState(() {
this.index = index;
});
},
itemBuilder: (context, index) {
var lists = <Widget>[
RecomSpolightPage(),
NewPage(),
];
return lists[index];
}),
SearchPage(),
SettingPage()
],
))
: PageView.builder(
itemCount: 4,
controller: _pageController,
itemBuilder: (context, index) {
var lists = [
PreviewPage(),
NewPage(),
SearchPage(),
SettingPage()
];
return lists[index];
});
}),
body: PageView.builder(
itemCount: 4,
controller: _pageController,
onPageChanged: (index) {
setState(() {
this.index = index;
});
},
itemBuilder: (context, index) {
return lists[index];
}),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: index,
onTap: (index) {
if (index > 1) {
setState(() {
stackIndex = index - 1;
this.index = index;
});
} else {
setState(() {
stackIndex = 0;
this.index = index;
});
_pageController.jumpToPage(index);
}
setState(() {
this.index = index;
});
_pageController.jumpToPage(index);
},
items: [
BottomNavigationBarItem(
Expand Down

0 comments on commit 0759823

Please sign in to comment.