Skip to content

Commit

Permalink
Upgrade project
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Sep 10, 2023
1 parent 62f22d8 commit 010f69f
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 71 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ jobs:

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.0.5'
- run: flutter pub get
- run: flutter build apk
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.0
with:
# A file, directory or wildcard pattern that describes what to upload
path: build/app/outputs/flutter-apk
# The desired behavior if no files are found using the provided path.
- uses: actions/checkout@v3.5.3
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.10.6'
- run: flutter pub get
- run: flutter build apk
- name: Upload a Build Artifact
uses: actions/upload-artifact@v3.1.0
with:
# A file, directory or wildcard pattern that describes what to upload
path: build/app/outputs/flutter-apk
# The desired behavior if no files are found using the provided path.

4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
69 changes: 46 additions & 23 deletions lib/my_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
Future<void> saveRepos() async {
Directory saveDir = await getApplicationDocumentsDirectory();
File saveFile = File("${saveDir.path}/repos.json");
List<String> repoStrings = repos.map((repo) => repo.repoSlug.toString()).toList();
await saveFile.writeAsString(json.encode(repoStrings), mode: FileMode.write, flush: true);

List<String> repoStrings =
repos.map((repo) => repo.repoSlug.toString()).toList();

await saveFile.writeAsString(
json.encode(repoStrings),
mode: FileMode.write,
flush: true,
);
}

Future<void> loadRepos() async {
Expand Down Expand Up @@ -102,14 +109,19 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {

void _addListItem() {
TextEditingController textEditingController = TextEditingController();
// ignore: avoid_init_to_null
String? errorMessage = null; //starts off being valid, to not immediately show the red warning
Key key = UniqueKey(); //create a unique key for the text field (used by the shaker)
bool justShook = false; //used to prevent the shaker from clearing the error message if the repo didn't exist
//starts off being valid, to not immediately show the red warning
String? errorMessage;
//create a unique key for the text field (used by the shaker)
Key key = UniqueKey();
//used to prevent the shaker from clearing the error message if the repo didn't exist
bool justShook = false;

void validate(List<String> parts) {
errorMessage = parts.length != 2 ? invalidGitHubURL : null;
if (textEditingController.text == "") errorMessage = cannotBeEmpty; //when the user presses Enter with no text, the dialog is not valid
if (textEditingController.text == "") {
//when the user presses Enter with no text, the dialog is not valid
errorMessage = cannotBeEmpty;
}
}

Future<void> attemptAdd(StateSetter setDialogState) async {
Expand All @@ -136,9 +148,11 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
if (e is RepositoryNotFound) {
errorMessage = repoDoesNotExist;
} else if (e.toString().contains(errorAPILimit)) {
errorMessage = "$errorAPILimit, but added the repo anyway.\nYou can close this dialog if you'd like.";
errorMessage = "$errorAPILimit, but added the repo anyway.\n"
"You can close this dialog if you'd like.";
} else {
errorMessage = "Error: ${e.toString()}"; //hopefully this will never happen
//hopefully this will never happen
errorMessage = "Error: ${e.toString()}";
}
});
}
Expand All @@ -162,7 +176,9 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
width: 600,
child: ShakeWidget(
key: key,
duration: Duration(milliseconds: errorMessage == null ? 0 : 500),
duration: Duration(
milliseconds: errorMessage == null ? 0 : 500,
),
child: TextField(
controller: textEditingController,
style: const TextStyle(fontSize: 18),
Expand Down Expand Up @@ -226,12 +242,21 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
text: TextSpan(
style: TextStyle(
fontSize: 18,
color: Theme.of(context).textTheme.bodyText1?.color, //TODO (low-prio): Find a better solution for this (it fixes the dark/light theme)
color: Theme.of(context)
.textTheme
.bodyLarge
?.color, //TODO (low-prio): Find a better solution for this (it fixes the dark/light theme)
),
children: <TextSpan>[
const TextSpan(text: areYouSureDelete),
TextSpan(text: "${repos[index].prettyName}?", style: const TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: "\n\n${repos[index].url.toString()}", style: const TextStyle(fontStyle: FontStyle.italic)),
TextSpan(
text: "${repos[index].prettyName}?",
style: const TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(
text: "\n\n${repos[index].url.toString()}",
style: const TextStyle(fontStyle: FontStyle.italic),
),
],
),
),
Expand Down Expand Up @@ -277,23 +302,18 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called

// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: const Text("Git-Droid"),
actions: [
IconButton(
onPressed: () {
updateApiCalls(setState);
apiDialog();
},
icon: Text(remainingApiCalls == null ? "" : remainingApiCalls.toString()),
icon: Text(
remainingApiCalls == null ? "" : remainingApiCalls.toString(),
),
tooltip: apiCallsRemainingDesc,
)
],
Expand All @@ -302,7 +322,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
onPressed: _addListItem,
tooltip: addFabTooltip,
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
),
body: RefreshIndicator(
onRefresh: refreshList,
child: ListView.separated(
Expand All @@ -314,7 +334,10 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
repos[index].expand();
}),
onLongPress: () => _onLongPress(index),
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
contentPadding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
),
),
),
Expand Down
64 changes: 49 additions & 15 deletions lib/release_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import 'globals.dart';
import 'repo_item.dart';

void showRelease(BuildContext context, RepoItem widget) {
ScrollController scrollController = ScrollController(); //needed for the scrollbar in the assets list
//needed for the scrollbar in the assets list
ScrollController scrollController = ScrollController();

void downloadAPK(String url, String name) async {
//Get download location in file system
Expand All @@ -25,7 +26,8 @@ void showRelease(BuildContext context, RepoItem widget) {
if (!apkFileInCacheDir.existsSync()) {
try {
Flushbar flushbar = Flushbar(
title: "Downloading", //TODO (low-prio): Global string
//TODO (low-prio): Global string:
title: "Downloading",
message: name,
icon: const Icon(Icons.file_download, color: Colors.blue),
flushbarPosition: FlushbarPosition.TOP,
Expand All @@ -41,7 +43,8 @@ void showRelease(BuildContext context, RepoItem widget) {
flushbar.dismiss();
} catch (e) {
Flushbar(
title: "Download failed", //TODO (low-prio): Global string
title: "Download failed",
//TODO (low-prio): Global string
message: e.toString(),
duration: const Duration(seconds: 10),
flushbarPosition: FlushbarPosition.BOTTOM,
Expand All @@ -53,7 +56,8 @@ void showRelease(BuildContext context, RepoItem widget) {
//And install the file

// === OPTION ONE ===
OpenFile.open(apkFileInCacheDir.path); //TODO (low-prio): Replace this with a custom Intent thing, using android_intent_plus
//TODO (low-prio): Replace this with a custom Intent thing, using android_intent_plus
OpenFile.open(apkFileInCacheDir.path);

// === OPTION TWO ===
// try {
Expand Down Expand Up @@ -93,7 +97,13 @@ void showRelease(BuildContext context, RepoItem widget) {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(widget.data.releaseTitle, style: const TextStyle(fontSize: 26, fontWeight: FontWeight.bold)),
Text(
widget.data.releaseTitle,
style: const TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Flexible(
child: SingleChildScrollView(
Expand All @@ -109,18 +119,23 @@ void showRelease(BuildContext context, RepoItem widget) {
margin: const EdgeInsets.all(8),
child: Stack(
children: [
const Divider(height: 0, color: Colors.transparent), //just there to make the MarkdownBody the full width of the dialog
//just there to make the MarkdownBody the full width of the dialog:
const Divider(height: 0, color: Colors.transparent),
MarkdownBody(
data: widget.data.releaseMarkdown,
selectable: true,
extensionSet: md.ExtensionSet(md.ExtensionSet.gitHubWeb.blockSyntaxes, md.ExtensionSet.gitHubWeb.inlineSyntaxes),
extensionSet: md.ExtensionSet(
md.ExtensionSet.gitHubWeb.blockSyntaxes,
md.ExtensionSet.gitHubWeb.inlineSyntaxes,
),
softLineBreak: true,
imageBuilder: (uri, title, alt) {
return Image.network(
uri.toString(),
//I tried making it load the image as an SVG, but it didn't work,
// so I guess some images just won't be able to load.
errorBuilder: (context, error, stackTrace) => const Icon(Icons.broken_image_rounded),
errorBuilder: (context, error, stackTrace) =>
const Icon(Icons.broken_image_rounded),
);
},
onTapLink: launchURL,
Expand All @@ -135,21 +150,27 @@ void showRelease(BuildContext context, RepoItem widget) {
DefaultTextStyle(
style: TextStyle(
fontSize: 20,
color: Theme.of(context).textTheme.bodyText1?.color, //TODO (low-prio): Find a better solution for this (it fixes the dark/light theme)
color: Theme.of(context)
.textTheme
.bodyLarge
?.color, //TODO (low-prio): Find a better solution for this (it fixes the dark/light theme)
),
child: widget.data.releaseApkAssets.isEmpty //if there are no apk assets, don't show the download button
//if there are no apk assets, don't show the download button
child: widget.data.releaseApkAssets.isEmpty
? const Text(noDownloads)
: const Text(downloads),
),
Flexible(
child: Scrollbar(
controller: scrollController,
thumbVisibility: true, //always show the scrollbar, to hint that there are more items in the list than currently in view
//always show the scrollbar, to hint that there are more items in the list than currently in view
thumbVisibility: true,
child: ListView.separated(
controller: scrollController,
shrinkWrap: true,
itemCount: widget.data.releaseApkAssets.length,
separatorBuilder: (context, index) => const Divider(height: 0),
separatorBuilder: (context, index) =>
const Divider(height: 0),
itemBuilder: (context, index) {
return ListTile(
title: Text(widget.data.releaseApkAssets[index].name),
Expand All @@ -158,11 +179,20 @@ void showRelease(BuildContext context, RepoItem widget) {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(filesize(widget.data.releaseApkAssets[index].size)),
Text(
filesize(
widget.data.releaseApkAssets[index].size,
),
),
Text.rich(
TextSpan(
children: <InlineSpan>[
TextSpan(text: NumberFormat.compact().format(widget.data.releaseApkAssets[index].downloadCount)),
TextSpan(
text: NumberFormat.compact().format(
widget.data.releaseApkAssets[index]
.downloadCount,
),
),
const WidgetSpan(
child: Icon(Icons.download),
alignment: PlaceholderAlignment.middle,
Expand All @@ -174,7 +204,11 @@ void showRelease(BuildContext context, RepoItem widget) {
),
),
onTap: () {
downloadAPK(widget.data.releaseApkAssets[index].browserDownloadUrl, widget.data.releaseApkAssets[index].name);
downloadAPK(
widget.data.releaseApkAssets[index]
.browserDownloadUrl,
widget.data.releaseApkAssets[index].name,
);
Navigator.pop(context);
},
);
Expand Down
Loading

0 comments on commit 010f69f

Please sign in to comment.