62 lines
1.5 KiB
Dart
62 lines
1.5 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:get/get_rx/get_rx.dart';
|
|
import 'package:wallpaper/models/imgnetodel.dart';
|
|
import 'package:wallpaper/utils/downloadmanager.dart';
|
|
import 'dart:async';
|
|
|
|
class ImgScanPageController extends GetxController {
|
|
late NetImgCategory dataModel;
|
|
RxInt currentIndex = RxInt(0);
|
|
RxInt showAppbar = RxInt(0);//控制appbar显示....
|
|
Timer? _timer;
|
|
var albumPermisonisDenied = false.obs;
|
|
@override
|
|
void onInit(){
|
|
super.onInit();
|
|
currentIndex.value = Get.arguments["index"];
|
|
dataModel = Get.arguments["dataModel"];
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
cancelTimer();
|
|
super.onClose();
|
|
|
|
}
|
|
|
|
void cancelTimer() {
|
|
if (_timer != null) {
|
|
_timer!.cancel();
|
|
_timer = null;
|
|
}
|
|
}
|
|
|
|
Future < void> downloadImg() async {
|
|
String urlStr = dataModel.data![currentIndex.value].original!;
|
|
if ((await DownloadManager.downloadImgWithUrl(urlStr)) == false){
|
|
albumPermisonisDenied.value = true;
|
|
}
|
|
//提示框
|
|
//....已下载
|
|
}
|
|
|
|
Future < void> saveImgToAlbum() async {
|
|
String imgUrl = dataModel.data![currentIndex.value].original!;
|
|
await DownloadManager.saveNetworkImage(imgUrl);
|
|
//如果是android,还应该调用设置壁纸的功能
|
|
//....
|
|
//给结果提示框
|
|
}
|
|
|
|
void showAppbarAction(){
|
|
showAppbar.value = 1;
|
|
cancelTimer();
|
|
|
|
const oneSec = Duration(seconds: 3);
|
|
_timer = Timer.periodic(oneSec, (Timer timer) {
|
|
timer.cancel();
|
|
_timer = null;
|
|
showAppbar.value = 0;
|
|
});
|
|
}
|
|
} |