Skip to content

Commit d858bf8

Browse files
committed
Add new techstackskotlin port of techstacks Android App in Kotlin with Kotlin dtos
1 parent b30170d commit d858bf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2054
-1
lines changed

src/AndroidClient/.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AndroidClient/.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AndroidClient/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include ':app', ':client', ':android', ':techstacks', ':kotlin'
1+
include ':app', ':client', ':android', ':techstacks', ':kotlin', ':techstackskotlin'
22

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
4+
android {
5+
compileSdkVersion 23
6+
buildToolsVersion "23.0.2"
7+
8+
defaultConfig {
9+
applicationId "test.servicestack.net.techstackskotlin"
10+
minSdkVersion 16
11+
targetSdkVersion 23
12+
versionCode 1
13+
versionName "1.0"
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
sourceSets {
22+
main.java.srcDirs += 'src/main/kotlin'
23+
}
24+
}
25+
26+
dependencies {
27+
compile fileTree(dir: 'libs', include: ['*.jar'])
28+
testCompile 'junit:junit:4.12'
29+
compile 'com.android.support:appcompat-v7:23.1.1'
30+
compile 'com.android.support:design:23.1.1'
31+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
32+
compile project(':android')
33+
compile 'com.squareup.picasso:picasso:2.5.2'
34+
}
35+
buildscript {
36+
ext.kotlin_version = '1.0.0-beta-3595'
37+
repositories {
38+
mavenCentral()
39+
}
40+
dependencies {
41+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
42+
}
43+
}
44+
repositories {
45+
mavenCentral()
46+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\Users\mythz\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package servicestack.net.techstackskotlin
2+
3+
import android.app.Application
4+
import android.test.ApplicationTestCase
5+
6+
/**
7+
* [Testing Fundamentals](http://d.android.com/tools/testing/testing_android.html)
8+
*/
9+
class ApplicationTest : ApplicationTestCase<Application>(Application::class.java)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="servicestack.net.techstackskotlin" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/logo_transparent"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme" >
10+
<activity
11+
android:name=".MainActivity"
12+
android:label="TechStacks (Kotlin)" >
13+
<intent-filter android:label="@string/app_name">
14+
<action android:name="android.intent.action.MAIN" />
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
<activity
19+
android:name=".TechnologyActivity"
20+
android:label="Technology" >
21+
<intent-filter>
22+
<action android:name="android.intent.action.VIEW" />
23+
<category android:name="android.intent.category.DEFAULT" />
24+
</intent-filter>
25+
</activity>
26+
<activity
27+
android:name=".TechStackActivity"
28+
android:label="TechStack" >
29+
<intent-filter>
30+
<action android:name="android.intent.action.VIEW" />
31+
<category android:name="android.intent.category.DEFAULT" />
32+
</intent-filter>
33+
</activity>
34+
</application>
35+
36+
</manifest>
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
package servicestack.net.techstackskotlin
2+
3+
import android.app.Activity
4+
import android.content.Intent
5+
import android.graphics.Bitmap
6+
import android.net.Uri
7+
import net.servicestack.android.AndroidServiceClient
8+
import net.servicestack.android.AndroidUtils
9+
import net.servicestack.client.AsyncResult
10+
import net.servicestack.client.Utils
11+
import java.util.*
12+
13+
class App {
14+
15+
internal var client: AndroidServiceClient
16+
var appData: AppData
17+
18+
init {
19+
client = AndroidServiceClient("http://techstacks.io")
20+
appData = AppData(client)
21+
}
22+
23+
class AppData(internal var client: AndroidServiceClient) {
24+
25+
internal var listeners = ArrayList<AppDataListener>()
26+
27+
fun addListener(callback: AppDataListener): AppData {
28+
if (!listeners.contains(callback)) {
29+
listeners.add(callback)
30+
}
31+
return this
32+
}
33+
34+
fun onUpdate(dataType: DataType) {
35+
for (listener in listeners) {
36+
listener.onUpdate(this, dataType)
37+
}
38+
}
39+
40+
fun loadAppOverview(): AppData {
41+
if (appOverviewResponse != null) {
42+
onUpdate(DataType.AppOverview)
43+
}
44+
client.getAsync(AppOverview(), object : AsyncResult<AppOverviewResponse>() {
45+
override fun success(response: AppOverviewResponse) {
46+
appOverviewResponse = response
47+
onUpdate(DataType.AppOverview)
48+
}
49+
})
50+
return this
51+
}
52+
53+
var appOverviewResponse: AppOverviewResponse? = null
54+
internal set
55+
56+
internal var lastTechStacksQuery: String? = null
57+
58+
fun searchTechStacks(query: String): AppData {
59+
if (searchTechStacksResponse != null && Utils.equals(query, lastTechStacksQuery)) {
60+
onUpdate(DataType.SearchTechStacks)
61+
}
62+
63+
lastTechStacksQuery = query
64+
client.getAsync(FindTechStacks(),
65+
Utils.createMap("NameContains", query, "DescriptionContains", query),
66+
object : AsyncResult<QueryResponse<TechnologyStack>>() {
67+
override fun success(response: QueryResponse<TechnologyStack>) {
68+
if (Utils.equals(query, lastTechStacksQuery)) {
69+
searchTechStacksResponse = response
70+
onUpdate(DataType.SearchTechStacks)
71+
}
72+
}
73+
})
74+
75+
return this
76+
}
77+
78+
var searchTechStacksResponse: QueryResponse<TechnologyStack>? = null
79+
internal set
80+
81+
internal var lastTechnologiesQuery: String? = null
82+
83+
fun searchTechnologies(query: String): AppData {
84+
if (searchTechnologiesResponse != null && Utils.equals(query, lastTechnologiesQuery)) {
85+
onUpdate(DataType.SearchTechnologies)
86+
}
87+
88+
lastTechnologiesQuery = query
89+
client.getAsync(FindTechnologies(),
90+
Utils.createMap("NameContains", query, "DescriptionContains", query),
91+
object : AsyncResult<QueryResponse<Technology>>() {
92+
override fun success(response: QueryResponse<Technology>) {
93+
if (Utils.equals(query, lastTechnologiesQuery)) {
94+
searchTechnologiesResponse = response
95+
onUpdate(DataType.SearchTechnologies)
96+
}
97+
}
98+
})
99+
100+
return this
101+
}
102+
103+
var searchTechnologiesResponse: QueryResponse<Technology>? = null
104+
internal set
105+
106+
var technology: GetTechnologyResponse? = null
107+
internal set
108+
109+
fun loadTechnology(slug: String) {
110+
if (technology != null) {
111+
onUpdate(DataType.Technology)
112+
}
113+
114+
val request = GetTechnology()
115+
request.Slug = slug
116+
client.getAsync(request,
117+
object : AsyncResult<GetTechnologyResponse>() {
118+
override fun success(response: GetTechnologyResponse) {
119+
technology = response
120+
onUpdate(DataType.Technology)
121+
}
122+
})
123+
}
124+
125+
var techStack: GetTechnologyStackResponse? = null
126+
internal set
127+
128+
fun loadTechStack(slug: String) {
129+
if (techStack != null) {
130+
onUpdate(DataType.TechStack)
131+
}
132+
133+
val request = GetTechnologyStack()
134+
request.Slug = slug
135+
client.getAsync(request,
136+
object : AsyncResult<GetTechnologyStackResponse>() {
137+
override fun success(response: GetTechnologyStackResponse) {
138+
techStack = response
139+
onUpdate(DataType.TechStack)
140+
}
141+
})
142+
}
143+
144+
internal var imgCache = HashMap<String, Bitmap>()
145+
fun loadImage(imgUrl: String, callback: ImageResult) {
146+
val img = imgCache[imgUrl]
147+
if (img != null) {
148+
callback.success(img)
149+
return
150+
}
151+
152+
client.getAsync(imgUrl, object : AsyncResult<ByteArray>() {
153+
override fun success(imgBytes: ByteArray) {
154+
val img = AndroidUtils.readBitmap(imgBytes)
155+
imgCache.put(imgUrl, img)
156+
callback.success(img)
157+
}
158+
})
159+
}
160+
}
161+
162+
interface AppDataListener {
163+
fun onUpdate(data: AppData, dataType: DataType)
164+
}
165+
166+
interface ImageResult {
167+
fun success(img: Bitmap)
168+
}
169+
170+
enum class DataType {
171+
AppOverview,
172+
SearchTechStacks,
173+
SearchTechnologies,
174+
Technology,
175+
TechStack
176+
}
177+
178+
companion object {
179+
180+
var Instance = App()
181+
182+
fun get(): App {
183+
return Instance
184+
}
185+
186+
val data: AppData
187+
get() = get().appData
188+
189+
fun openTechStack(activity: Activity, slug: String?) {
190+
if (slug == null) return
191+
val openTechStack = Intent(activity, TechStackActivity::class.java)
192+
openTechStack.putExtra("slug", slug)
193+
activity.startActivity(openTechStack)
194+
}
195+
196+
fun openTechnology(activity: Activity, slug: String?) {
197+
if (slug == null) return
198+
val openTechnology = Intent(activity, TechnologyActivity::class.java)
199+
openTechnology.putExtra("slug", slug)
200+
activity.startActivity(openTechnology)
201+
}
202+
203+
fun openUrl(activity: Activity, url: String?) {
204+
if (url == null) return
205+
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
206+
}
207+
}
208+
209+
}

0 commit comments

Comments
 (0)