Skip to content

Commit

Permalink
fix corner crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Nov 1, 2020
1 parent 0293112 commit 9db26ef
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 76 deletions.
3 changes: 3 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ flutter {
}

dependencies {
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
implementation('com.waynejo:androidndkgif:0.3.3')
Expand Down
64 changes: 41 additions & 23 deletions android/app/src/main/kotlin/com/perol/pixez/CardAppWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.content.Intent
import android.graphics.*
import android.graphics.Bitmap
import android.util.Log
import android.widget.RemoteViews
import com.bumptech.glide.Glide
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.load.model.LazyHeaders
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.dart.DartExecutor
import io.flutter.plugin.common.MethodChannel
import io.flutter.view.FlutterCallbackInformation
import io.flutter.view.FlutterMain


/**
* Implementation of App Widget functionality.
*/
Expand Down Expand Up @@ -66,7 +74,6 @@ class CardAppWidget : AppWidgetProvider(), MethodChannel.Result {
this.context = context
init()
for (appWidgetId in appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId)
channel?.invokeMethod("update", appWidgetId, this)
}
}
Expand Down Expand Up @@ -100,9 +107,15 @@ class CardAppWidget : AppWidgetProvider(), MethodChannel.Result {
override fun success(result: Any?) {
result ?: return
val args = result as HashMap<*, *>
val code = args["code"] as Int
if (code == 400) {
val message = args["message"] as String?
Log.d("update error", "message=$message")
return
}
val id = args["id"] as Int
val iId = args["iid"] as Int
val value = args["value"] as ByteArray
val value = args["value"] as String
Log.d("w", "success${iId}")
updateWidget(context, value, id, iId)
}
Expand All @@ -114,29 +127,34 @@ class CardAppWidget : AppWidgetProvider(), MethodChannel.Result {
}
}

internal fun updateWidget(context: Context, byteArray: ByteArray, appWidgetId: Int, iId: Int?) {
internal fun updateWidget(context: Context, url: String, appWidgetId: Int, iId: Int?) {
val views = RemoteViews(context.packageName, R.layout.card_app_widget)
val bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.lastIndex)
val manager = AppWidgetManager.getInstance(context)
val output = Bitmap.createBitmap(bitmap.width, bitmap
.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(output)
val paint = Paint().apply {
isAntiAlias = true
color = -0xbdbdbe
isAntiAlias = true
xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)
try {
val glideUrl = GlideUrl(url, LazyHeaders.Builder()
.addHeader("referer", "https://app-api.pixiv.net/")
.addHeader("User-Agent", "PixivIOSApp/5.8.0")
.build())
Glide.with(context)
.asBitmap()
.load(glideUrl)
.apply(RequestOptions.bitmapTransform(RoundedCorners(20)))
.into(object :SimpleTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
views.setImageViewBitmap(R.id.appwidget_image, resource)
val intent = Intent(context, IntentActivity::class.java).apply {
putExtra("iid", iId)
setPackage("com.perol.pixez")
}
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
views.setOnClickPendingIntent(R.id.appwidget_image, pendingIntent)
manager.updateAppWidget(appWidgetId, views)
}
});
} catch (throwable: Throwable) {
Log.d("throw", "Throwable=" + throwable.message)
}
val rect = Rect(0, 0, bitmap.width, bitmap.height)
canvas.drawARGB(0, 0, 0, 0)
val roundPx = 16f
canvas.drawRoundRect(RectF(rect), roundPx, roundPx, paint)
canvas.drawBitmap(bitmap, rect, rect, paint)
views.setImageViewBitmap(R.id.appwidget_image, output)
val intent = Intent(context, IntentActivity::class.java).apply { putExtra("iid", iId) }
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
views.setOnClickPendingIntent(R.id.appwidget_image, pendingIntent)
manager.updateAppWidget(appWidgetId, views)

}

internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) {
Expand Down
6 changes: 3 additions & 3 deletions lib/generated/intl/messages_zh-TW.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MessageLookup extends MessageLookupByLibrary {
"enqueued" : MessageLookupByLibrary.simpleMessage("在佇列中"),
"exact_match_for_tag" : MessageLookupByLibrary.simpleMessage("與標簽完全一致"),
"failed" : MessageLookupByLibrary.simpleMessage("失敗"),
"favorited_tag" : MessageLookupByLibrary.simpleMessage("已收藏標籤"),
"favorited_tag" : MessageLookupByLibrary.simpleMessage("標籤收藏"),
"feedback" : MessageLookupByLibrary.simpleMessage("問題回報"),
"filter" : MessageLookupByLibrary.simpleMessage("篩選"),
"follow" : MessageLookupByLibrary.simpleMessage("關註"),
Expand Down Expand Up @@ -155,7 +155,7 @@ class MessageLookup extends MessageLookupByLibrary {
"private" : MessageLookupByLibrary.simpleMessage("非公開"),
"public" : MessageLookupByLibrary.simpleMessage("公開"),
"pull_up_to_load_more" : MessageLookupByLibrary.simpleMessage("上拉以載入更多內容"),
"quality_setting" : MessageLookupByLibrary.simpleMessage("偏好選項"),
"quality_setting" : MessageLookupByLibrary.simpleMessage("偏好設定"),
"quick_view" : MessageLookupByLibrary.simpleMessage("速覽"),
"quietly_follow" : MessageLookupByLibrary.simpleMessage("私密關註"),
"rank" : MessageLookupByLibrary.simpleMessage("排行"),
Expand Down Expand Up @@ -189,7 +189,7 @@ class MessageLookup extends MessageLookupByLibrary {
"share" : MessageLookupByLibrary.simpleMessage("分享"),
"share_this_app_link" : MessageLookupByLibrary.simpleMessage("推薦這個APP"),
"shield_message" : m2,
"shielding_settings" : MessageLookupByLibrary.simpleMessage("屏蔽設定"),
"shielding_settings" : MessageLookupByLibrary.simpleMessage("屏蔽內容"),
"skimige_message" : MessageLookupByLibrary.simpleMessage("完成 MarkDown 整理"),
"skin" : MessageLookupByLibrary.simpleMessage("主題"),
"skip" : MessageLookupByLibrary.simpleMessage("跳過"),
Expand Down
17 changes: 9 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ initAppWidget() {
void onWidgetUpdate() {
WidgetsFlutterBinding.ensureInitialized();
const MethodChannel channel = MethodChannel('com.example.app/widget');
ApiClient apiClient = ApiClient();
channel.setMethodCallHandler(
(call) async {
if (call.method == 'update') {
Expand All @@ -81,10 +82,10 @@ void onWidgetUpdate() {
final id = call.arguments;
SharedPreferences pref = await SharedPreferences.getInstance();
int position = pref.getInt(NOW_POSITION) ?? 0; //Position Zero!
ApiClient apiClient = ApiClient();
AccountProvider accountProvider = AccountProvider();
await accountProvider.open();
List<AccountPersist> accounts = await accountProvider.getAllAccount();
List<AccountPersist> accounts =
await accountProvider.getAllAccount(); //bug token refresh
Response response;
if (accounts.isNotEmpty)
response = await apiClient.getIllustRanking("day", null);
Expand All @@ -97,22 +98,23 @@ void onWidgetUpdate() {
"User-Agent": "PixivIOSApp/5.8.0",
"Host": 'i.pximg.net'
}, responseType: ResponseType.bytes));
Response<List<int>> rs =
await dio.get(recommend.illusts[position].imageUrls.medium);
Uint8List uint8list = Uint8List.fromList(rs.data);
String url = recommend.illusts[position].imageUrls.squareMedium;
int fPosition = position + 1;
if (fPosition >= recommend.illusts.length) {
fPosition = 0;
}
await pref.setInt(NOW_POSITION, fPosition);
LPrinter.d("setMethodCallHandler:Success");
return {
'code': 200,
'message': 'success',
'id': id,
'iid': recommend.illusts.first.id,
'value': uint8list,
'iid': recommend.illusts[position].id,
'value': url,
};
} catch (e) {
LPrinter.d("setMethodCallHandler:Fail=$e");
return {'code': 400, 'message': e.toString()};
}
}
},
Expand All @@ -125,7 +127,6 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {

@override
void dispose() {
saveStore?.dispose();
Expand Down
109 changes: 105 additions & 4 deletions lib/page/about/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'dart:async';
import 'dart:io';

import 'package:bot_toast/bot_toast.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -30,6 +31,15 @@ import 'package:pixez/page/about/update_page.dart';
import 'package:share/share.dart';
import 'package:url_launcher/url_launcher.dart';

class Contributor {
final String name;
final String avatar;
final String url;
final String content;

Contributor(this.name, this.avatar, this.url, this.content);
}

class AboutPage extends StatefulWidget {
final bool newVersion;

Expand All @@ -40,6 +50,41 @@ class AboutPage extends StatefulWidget {
}

class _AboutPageState extends State<AboutPage> {
List<Contributor> contributors = [
Contributor(
'Tragic Life',
'https://avatars3.githubusercontent.com/u/16817202?v=4',
'https://github.com/TragicLifeHu',
'🌍'),
Contributor(
'Skimige',
'https://avatars3.githubusercontent.com/u/9017470?v=4',
'https://xyx.moe/',
'📖'),
Contributor('Xian', 'https://avatars1.githubusercontent.com/u/34748039?v=4',
'https://github.com/itzXian', '🌍'),
Contributor(
'karin722',
'https://avatars0.githubusercontent.com/u/54385201?v=4',
'http://ivtune.net/',
'🌍'),
Contributor(
'Romani-Archman',
'https://avatars0.githubusercontent.com/u/68731023?v=4',
'http://archman.fun/',
'📖'),
Contributor(
'Henry-ZHR',
'https://avatars1.githubusercontent.com/u/51886614?s=64&v=4',
'https://github.com/Henry-ZHR',
'💻'),
Contributor(
'Takase',
'https://avatars0.githubusercontent.com/u/20792268?s=64&v=4',
'https://github.com/takase1121',
'🌍'),
];

StreamSubscription _purchaseUpdatedSubscription;
StreamSubscription _purchaseErrorSubscription;
final List<String> _productLists = ['support', 'support1'];
Expand Down Expand Up @@ -209,6 +254,64 @@ class _AboutPageState extends State<AboutPage> {
);
},
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Text('Contributors'),
),
Container(
height: 142,
padding: EdgeInsets.only(left: 8.0),
child: ListView.builder(
shrinkWrap: true,
itemCount: contributors.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
final data = contributors[index];
return Card(
child: InkWell(
onTap: () {
if (Constants.isGooglePlay || Platform.isIOS) return;
launch(data.url);
},
child: Container(
width: 80,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Container(
height: 8,
),
CircleAvatar(
backgroundImage: NetworkImage(
data.avatar,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
data.name,
textAlign: TextAlign.center,
),
),
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
data.content,
textAlign: TextAlign.center,
),
)
],
),
),
),
);
}),
),
ListTile(
leading: Icon(Icons.rate_review),
title: Text(I18n.of(context).rate_title),
Expand All @@ -225,9 +328,7 @@ class _AboutPageState extends State<AboutPage> {
if (Platform.isAndroid) ...[
ListTile(
leading: Icon(Icons.device_hub),
title: Text(I18n
.of(context)
.repo_address),
title: Text(I18n.of(context).repo_address),
subtitle: SelectableText('github.com/Notsfsssf/pixez-flutter'),
trailing: Visibility(
child: NewVersionChip(),
Expand All @@ -239,7 +340,7 @@ class _AboutPageState extends State<AboutPage> {
context: context,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.vertical(top: Radius.circular(16.0))),
BorderRadius.vertical(top: Radius.circular(16.0))),
builder: (_) {
return Container(
child: Column(
Expand Down
Loading

0 comments on commit 9db26ef

Please sign in to comment.