Skip to content

Commit 58af1a5

Browse files
authored
Merge pull request #1 from tmaxxdd/feature/create-code-item-widget
Create code item widget
2 parents a5b939a + 452055f commit 58af1a5

23 files changed

+591
-239
lines changed

app/src/main/java/pl/tkadziolka/snipmeandroid/Messages.java

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Autogenerated from Pigeon (v4.2.2), do not edit directly.
1+
// Autogenerated from Pigeon (v4.2.3), do not edit directly.
22
// See also: https://pub.dev/packages/pigeon
33

44
package pl.tkadziolka.snipmeandroid;
@@ -14,6 +14,7 @@
1414
import java.nio.ByteBuffer;
1515
import java.util.Arrays;
1616
import java.util.ArrayList;
17+
import java.util.Collections;
1718
import java.util.List;
1819
import java.util.Map;
1920
import java.util.HashMap;
@@ -134,6 +135,24 @@ public void setLanguage(@Nullable SnippetLanguage setterArg) {
134135
this.language = setterArg;
135136
}
136137

138+
private @Nullable Owner owner;
139+
public @Nullable Owner getOwner() { return owner; }
140+
public void setOwner(@Nullable Owner setterArg) {
141+
this.owner = setterArg;
142+
}
143+
144+
private @Nullable String timeAgo;
145+
public @Nullable String getTimeAgo() { return timeAgo; }
146+
public void setTimeAgo(@Nullable String setterArg) {
147+
this.timeAgo = setterArg;
148+
}
149+
150+
private @Nullable Long voteResult;
151+
public @Nullable Long getVoteResult() { return voteResult; }
152+
public void setVoteResult(@Nullable Long setterArg) {
153+
this.voteResult = setterArg;
154+
}
155+
137156
public static final class Builder {
138157
private @Nullable String uuid;
139158
public @NonNull Builder setUuid(@Nullable String setterArg) {
@@ -155,12 +174,30 @@ public static final class Builder {
155174
this.language = setterArg;
156175
return this;
157176
}
177+
private @Nullable Owner owner;
178+
public @NonNull Builder setOwner(@Nullable Owner setterArg) {
179+
this.owner = setterArg;
180+
return this;
181+
}
182+
private @Nullable String timeAgo;
183+
public @NonNull Builder setTimeAgo(@Nullable String setterArg) {
184+
this.timeAgo = setterArg;
185+
return this;
186+
}
187+
private @Nullable Long voteResult;
188+
public @NonNull Builder setVoteResult(@Nullable Long setterArg) {
189+
this.voteResult = setterArg;
190+
return this;
191+
}
158192
public @NonNull Snippet build() {
159193
Snippet pigeonReturn = new Snippet();
160194
pigeonReturn.setUuid(uuid);
161195
pigeonReturn.setTitle(title);
162196
pigeonReturn.setCode(code);
163197
pigeonReturn.setLanguage(language);
198+
pigeonReturn.setOwner(owner);
199+
pigeonReturn.setTimeAgo(timeAgo);
200+
pigeonReturn.setVoteResult(voteResult);
164201
return pigeonReturn;
165202
}
166203
}
@@ -170,6 +207,9 @@ public static final class Builder {
170207
toMapResult.put("title", title);
171208
toMapResult.put("code", (code == null) ? null : code.toMap());
172209
toMapResult.put("language", (language == null) ? null : language.toMap());
210+
toMapResult.put("owner", (owner == null) ? null : owner.toMap());
211+
toMapResult.put("timeAgo", timeAgo);
212+
toMapResult.put("voteResult", voteResult);
173213
return toMapResult;
174214
}
175215
static @NonNull Snippet fromMap(@NonNull Map<String, Object> map) {
@@ -182,6 +222,12 @@ public static final class Builder {
182222
pigeonResult.setCode((code == null) ? null : SnippetCode.fromMap((Map)code));
183223
Object language = map.get("language");
184224
pigeonResult.setLanguage((language == null) ? null : SnippetLanguage.fromMap((Map)language));
225+
Object owner = map.get("owner");
226+
pigeonResult.setOwner((owner == null) ? null : Owner.fromMap((Map)owner));
227+
Object timeAgo = map.get("timeAgo");
228+
pigeonResult.setTimeAgo((String)timeAgo);
229+
Object voteResult = map.get("voteResult");
230+
pigeonResult.setVoteResult((voteResult == null) ? null : ((voteResult instanceof Integer) ? (Integer)voteResult : (Long)voteResult));
185231
return pigeonResult;
186232
}
187233
}
@@ -345,6 +391,54 @@ public static final class Builder {
345391
}
346392
}
347393

394+
/** Generated class from Pigeon that represents data sent in messages. */
395+
public static class Owner {
396+
private @Nullable Long id;
397+
public @Nullable Long getId() { return id; }
398+
public void setId(@Nullable Long setterArg) {
399+
this.id = setterArg;
400+
}
401+
402+
private @Nullable String login;
403+
public @Nullable String getLogin() { return login; }
404+
public void setLogin(@Nullable String setterArg) {
405+
this.login = setterArg;
406+
}
407+
408+
public static final class Builder {
409+
private @Nullable Long id;
410+
public @NonNull Builder setId(@Nullable Long setterArg) {
411+
this.id = setterArg;
412+
return this;
413+
}
414+
private @Nullable String login;
415+
public @NonNull Builder setLogin(@Nullable String setterArg) {
416+
this.login = setterArg;
417+
return this;
418+
}
419+
public @NonNull Owner build() {
420+
Owner pigeonReturn = new Owner();
421+
pigeonReturn.setId(id);
422+
pigeonReturn.setLogin(login);
423+
return pigeonReturn;
424+
}
425+
}
426+
@NonNull Map<String, Object> toMap() {
427+
Map<String, Object> toMapResult = new HashMap<>();
428+
toMapResult.put("id", id);
429+
toMapResult.put("login", login);
430+
return toMapResult;
431+
}
432+
static @NonNull Owner fromMap(@NonNull Map<String, Object> map) {
433+
Owner pigeonResult = new Owner();
434+
Object id = map.get("id");
435+
pigeonResult.setId((id == null) ? null : ((id instanceof Integer) ? (Integer)id : (Long)id));
436+
Object login = map.get("login");
437+
pigeonResult.setLogin((String)login);
438+
return pigeonResult;
439+
}
440+
}
441+
348442
/** Generated class from Pigeon that represents data sent in messages. */
349443
public static class SnippetFilter {
350444
private @Nullable SnippetFilterType type;
@@ -516,18 +610,21 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
516610
return MainModelStateData.fromMap((Map<String, Object>) readValue(buffer));
517611

518612
case (byte)130:
519-
return Snippet.fromMap((Map<String, Object>) readValue(buffer));
613+
return Owner.fromMap((Map<String, Object>) readValue(buffer));
520614

521615
case (byte)131:
522-
return SnippetCode.fromMap((Map<String, Object>) readValue(buffer));
616+
return Snippet.fromMap((Map<String, Object>) readValue(buffer));
523617

524618
case (byte)132:
525-
return SnippetFilter.fromMap((Map<String, Object>) readValue(buffer));
619+
return SnippetCode.fromMap((Map<String, Object>) readValue(buffer));
526620

527621
case (byte)133:
528-
return SnippetLanguage.fromMap((Map<String, Object>) readValue(buffer));
622+
return SnippetFilter.fromMap((Map<String, Object>) readValue(buffer));
529623

530624
case (byte)134:
625+
return SnippetLanguage.fromMap((Map<String, Object>) readValue(buffer));
626+
627+
case (byte)135:
531628
return SyntaxToken.fromMap((Map<String, Object>) readValue(buffer));
532629

533630
default:
@@ -545,24 +642,28 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value)
545642
stream.write(129);
546643
writeValue(stream, ((MainModelStateData) value).toMap());
547644
} else
548-
if (value instanceof Snippet) {
645+
if (value instanceof Owner) {
549646
stream.write(130);
647+
writeValue(stream, ((Owner) value).toMap());
648+
} else
649+
if (value instanceof Snippet) {
650+
stream.write(131);
550651
writeValue(stream, ((Snippet) value).toMap());
551652
} else
552653
if (value instanceof SnippetCode) {
553-
stream.write(131);
654+
stream.write(132);
554655
writeValue(stream, ((SnippetCode) value).toMap());
555656
} else
556657
if (value instanceof SnippetFilter) {
557-
stream.write(132);
658+
stream.write(133);
558659
writeValue(stream, ((SnippetFilter) value).toMap());
559660
} else
560661
if (value instanceof SnippetLanguage) {
561-
stream.write(133);
662+
stream.write(134);
562663
writeValue(stream, ((SnippetLanguage) value).toMap());
563664
} else
564665
if (value instanceof SyntaxToken) {
565-
stream.write(134);
666+
stream.write(135);
566667
writeValue(stream, ((SyntaxToken) value).toMap());
567668
} else
568669
{
@@ -673,6 +774,7 @@ static void setup(BinaryMessenger binaryMessenger, MainModelApi api) {
673774
Map<String, Object> wrapped = new HashMap<>();
674775
try {
675776
ArrayList<Object> args = (ArrayList<Object>)message;
777+
assert args != null;
676778
SnippetFilter filterArg = (SnippetFilter)args.get(0);
677779
if (filterArg == null) {
678780
throw new NullPointerException("filterArg unexpectedly null.");

app/src/main/java/pl/tkadziolka/snipmeandroid/PigeonPlugin.kt

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
package pl.tkadziolka.snipmeandroid
22

3-
import android.text.SpannableString
43
import android.text.Spanned
4+
import android.text.format.DateUtils
55
import android.text.style.ForegroundColorSpan
66
import androidx.core.text.getSpans
77
import io.flutter.embedding.engine.plugins.FlutterPlugin
88
import kotlinx.coroutines.ExperimentalCoroutinesApi
9-
import kotlinx.coroutines.flow.map
109
import org.koin.core.component.KoinComponent
1110
import org.koin.core.component.inject
1211
import pl.tkadziolka.snipmeandroid.bridge.MainModel
12+
import pl.tkadziolka.snipmeandroid.domain.snippets.Owner
1313
import pl.tkadziolka.snipmeandroid.domain.snippets.Snippet
1414
import pl.tkadziolka.snipmeandroid.domain.snippets.SnippetCode
1515
import pl.tkadziolka.snipmeandroid.domain.snippets.SnippetLanguage
1616
import pl.tkadziolka.snipmeandroid.ui.main.*
1717
import pl.tkadziolka.snipmeandroid.util.view.SnippetFilter
18-
import timber.log.Timber
18+
import java.util.*
1919

20-
// flutter pub run pigeon \
21-
// --input pigeons/messages.dart \
22-
// --dart_out lib/messages.dart \
23-
// --java_out ../app/src/main/java/pl/tkadziolka/snipmeandroid/Messages.java \
24-
// --java_package "pl.tkadziolka.snipmeandroid"
20+
/*
21+
flutter pub run pigeon \
22+
--input pigeons/messages.dart \
23+
--dart_out lib/messages.dart \
24+
--java_out ../app/src/main/java/pl/tkadziolka/snipmeandroid/Messages.java \
25+
--java_package "pl.tkadziolka.snipmeandroid"
26+
*/
2527

2628
@ExperimentalCoroutinesApi
2729
class PigeonPlugin : FlutterPlugin, Messages.MainModelApi, KoinComponent {
28-
2930
private val mainModel: MainModel by inject()
3031

3132
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
@@ -93,13 +94,26 @@ class PigeonPlugin : FlutterPlugin, Messages.MainModelApi, KoinComponent {
9394
title = it.title
9495
code = it.code.toModelSnippetCode()
9596
language = it.language.toModelSnippetLanguage()
97+
owner = it.owner.toModelOwner()
98+
voteResult = (it.numberOfLikes - it.numberOfDislikes).toLong()
99+
timeAgo = DateUtils.getRelativeTimeSpanString(
100+
it.modifiedAt.time,
101+
Date().time,
102+
DateUtils.SECOND_IN_MILLIS
103+
).toString()
96104
}
97105
}
98106

107+
private fun Owner.toModelOwner() =
108+
Messages.Owner().let {
109+
it.id = id.toLong()
110+
it.login = login
111+
it
112+
}
113+
99114
private fun SnippetCode.toModelSnippetCode() =
100115
Messages.SnippetCode().let {
101116
it.raw = raw
102-
// TODO Debug resolving spans (lines = 5)???
103117
it.tokens = highlighted.getSpans<ForegroundColorSpan>().map { span ->
104118
span.toSyntaxToken(highlighted)
105119
}
@@ -121,7 +135,3 @@ class PigeonPlugin : FlutterPlugin, Messages.MainModelApi, KoinComponent {
121135
it
122136
}
123137
}
124-
125-
126-
127-

flutter_module/lib/main.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_module/messages.dart';
33
import 'package:flutter_module/presentation/pages/main_page.dart';
4+
import 'package:flutter_module/presentation/widgets/snippet_list_item.dart';
5+
import 'package:flutter_module/utils/mock/mock_page.dart';
6+
import 'package:flutter_module/utils/mock/mocks.dart';
47

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

@@ -15,7 +18,9 @@ class MyApp extends StatelessWidget {
1518
return MaterialApp(
1619
title: 'SnipMe',
1720
theme: ThemeData(primarySwatch: Colors.blue),
18-
home: MainPage(model: mainModel),
21+
home: MockPage(children: [
22+
SnippetListTile(snippet: Mocks.snippet),
23+
]),
1924
);
2025
}
2126
}

0 commit comments

Comments
 (0)