Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Icon and Sorting logic #12

Merged
merged 6 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified android/app/src/main/res/mipmap-hdpi/launcher_icon.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 android/app/src/main/res/mipmap-mdpi/launcher_icon.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 android/app/src/main/res/mipmap-xhdpi/launcher_icon.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 android/app/src/main/res/mipmap-xxhdpi/launcher_icon.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 android/app/src/main/res/mipmap-xxxhdpi/launcher_icon.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 assets/icon/dndr.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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
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 ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
Binary file modified ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]
152 changes: 113 additions & 39 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:permission_handler/permission_handler.dart';
import "dart:io";
import "package:path/path.dart";
import "pdfviewer.dart";
import 'package:path_provider/path_provider.dart';

void main() => runApp(MyApp());

Expand All @@ -16,53 +17,77 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
ListStorage _listStorage = new ListStorage();
List<String> listFromFile = new List<String>();
final ScrollController _scrollController = ScrollController();
List<FileSystemEntity> _pdfs = [];
List<FileSystemEntity> _dup = [];
List<String> _pdfs = [];
Permission storagePerm = Permission.storage;
PermissionStatus status = PermissionStatus.undetermined;
TextEditingController editingController = TextEditingController();
FocusNode myFocusNode;

@override
void initState() {
super.initState();
checkStatus(storagePerm);
myFocusNode = new FocusNode();
}

void getlists() {
_pdfs.clear();
_dup.clear();
Directory dir = Directory('/storage/emulated/0/');
// String pdfdir = dir.toString();
List<FileSystemEntity> _files;

_files = dir.listSync(recursive: true, followLinks: false);
for (FileSystemEntity entity in _files) {
String path = entity.path;
if (path.endsWith('.pdf')) {
_dup.add(entity);
}
}
_dup.sort((a, b) {
return basename(a.path)
.replaceAll(".pdf", "")
.compareTo(basename(b.path).replaceAll(".pdf", ""));
});
List<String> getpdfs(){
Directory dir = Directory('/storage/emulated/0/');
List<FileSystemEntity> _files;
List<String> _dup = new List<String>();
_files = dir.listSync(recursive: true, followLinks: false);
for (FileSystemEntity entity in _files) {
String path = entity.path;
if (path.endsWith('.pdf')) {
_dup.add(entity.path);
}
}
_dup.sort((a, b) {
return basename(a)
.replaceAll(".pdf", "")
.compareTo(basename(b).replaceAll(".pdf", ""));
});

return _dup;

}

setState(() {
_pdfs.addAll(_dup);
});
void getlists() {
List<String> temp = getpdfs();
_listStorage.read().then<void>((val){
String listString = val;
if(listString.isEmpty){
listFromFile.addAll(temp);
_listStorage.write(listFromFile);
setState((){
_pdfs.addAll(temp);
});
} else {
listFromFile = listString.split("%*%*%");
if(temp.length > listFromFile.length){
for(String p in temp){
if(!listFromFile.contains(p)){
listFromFile.insert(0, p);
}
}
}
_listStorage.write(listFromFile);
setState((){
_pdfs.clear();
_pdfs.addAll(listFromFile);
});

}});
}

void filterSearchResults(String query) {
List<FileSystemEntity> dummySearchList = List<FileSystemEntity>();
dummySearchList.addAll(_dup);
List<String> dummySearchList = List<String>();
dummySearchList.addAll(listFromFile);
if (query.isNotEmpty) {
List<FileSystemEntity> dummyListData = List<FileSystemEntity>();
List<String> dummyListData = List<String>();
dummySearchList.forEach((item) {
if (basename(item.path)
if (basename(item)
.replaceAll(".pdf", "")
.toLowerCase()
.contains(query.toLowerCase())) {
Expand All @@ -77,7 +102,7 @@ class _MyAppState extends State<MyApp> {
} else {
setState(() {
_pdfs.clear();
_pdfs.addAll(_dup);
_pdfs.addAll(listFromFile);
});
}
}
Expand Down Expand Up @@ -117,10 +142,12 @@ class _MyAppState extends State<MyApp> {
])),
)
]).then<void>((String sel) {
File tochange = new File(_pdfs[_index].path);
File tochange = new File(_pdfs[_index]);
if (sel == "del") {
try {
tochange.delete();
listFromFile.removeAt(_index);
_listStorage.write(listFromFile);
getlists();
} catch (e) {
print(e);
Expand Down Expand Up @@ -158,14 +185,14 @@ class _MyAppState extends State<MyApp> {
_newName +
".pdf";
List<String> _temp = new List<String>();
for (FileSystemEntity i in _pdfs) {
_temp.add(i.path);
for (String i in _pdfs) {
_temp.add(i);
}
if (_temp.contains(_newName)) {
print("already there");
} else {
print("in here");
tochange.rename(_newName);
listFromFile[_index] = _newName;
_listStorage.write(listFromFile);
getlists();
}
} else {
Expand Down Expand Up @@ -281,12 +308,26 @@ class _MyAppState extends State<MyApp> {
borderRadius: BorderRadius.all(
Radius.circular(10)),
child: ListTile(
title: Text(
basename(_pdfs[index].path)
.replaceAll(".pdf", "")),
title: Text(basename(_pdfs[index])
.replaceAll(".pdf", "")),
onTap: () {
int lind = listFromFile.indexOf(_pdfs[index]);
if (lind != 0) {
String temp = listFromFile[lind];
for(int i=lind;i>0;i--){
listFromFile[i] = listFromFile[i-1];
}
listFromFile[0] = temp;
_listStorage.write(listFromFile);
setState((){
_pdfs.clear();
_pdfs.addAll(listFromFile);
});
}
navigateToSubPage(context,
_pdfs[index].path.toString());
_pdfs[0].toString());
FocusScope.of(context).requestFocus(new FocusNode());
editingController.clear();
},
),
),
Expand All @@ -301,3 +342,36 @@ class _MyAppState extends State<MyApp> {
)));
}
}

class ListStorage {
Future<File> get _localFile async {
final path = await _localPath;
return File('$path/list').create(recursive: true);
}

Future<String> read() async {
try {
final file = await _localFile;
String list = await file.readAsString();
return list;
} catch (e) {
return e.toString();
}
}

Future<void> write(List<String> x) async {
String p = x.join("%*%*%");
try {
final file = await _localFile;

await file.writeAsString('$p');
} catch (e) {
return e.toString();
}
}

Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
}
65 changes: 64 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "5.2.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -116,6 +123,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.14"
intl:
dependency: transitive
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
matcher:
dependency: transitive
description:
Expand All @@ -137,6 +151,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.11"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+2"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+3"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
permission_handler:
dependency: "direct main"
description:
Expand All @@ -158,13 +200,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.4"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.13"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -226,6 +282,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
xml:
dependency: transitive
description:
Expand All @@ -242,4 +305,4 @@ packages:
version: "2.2.1"
sdks:
dart: ">=2.7.0 <3.0.0"
flutter: ">=1.12.8 <2.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
version: 1.1.0

environment:
sdk: ">=2.7.0 <3.0.0"
Expand All @@ -27,8 +27,8 @@ dependencies:
flutter_full_pdf_viewer: ^1.0.6
path: ^1.7.0
draggable_scrollbar: ^0.0.4
flutter_launcher_icons: "^0.7.3"

flutter_launcher_icons: ^0.7.3
path_provider: ^1.6.11
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
Expand Down