Skip to content

Commit 6899b44

Browse files
authored
Merge pull request #8 from Flowdawan/1.2.0/new_architecture
1.2.0/new architecture
2 parents ef8823c + b1970a5 commit 6899b44

28 files changed

Lines changed: 235 additions & 374 deletions

.idea/deploymentTargetDropDown.xml

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

.idea/misc.xml

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

app/build.gradle

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ android {
1313
minSdk 27
1414
targetSdk 32
1515
versionCode 5
16-
versionName "1.1.0"
16+
versionName "1.2.1"
1717

1818
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1919
vectorDrawables {
@@ -22,12 +22,10 @@ android {
2222
signingConfig signingConfigs.debug
2323
}
2424

25-
compileOptions.encoding 'UTF-8'
26-
2725
buildTypes {
2826
release {
29-
minifyEnabled false
30-
shrinkResources false
27+
minifyEnabled true
28+
shrinkResources true
3129
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
3230
}
3331
}
@@ -59,7 +57,7 @@ dependencies {
5957
implementation "androidx.compose.material:material:$compose_version"
6058
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
6159
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
62-
implementation 'androidx.activity:activity-compose:1.6.0'
60+
implementation 'androidx.activity:activity-compose:1.6.1'
6361
implementation 'androidx.constraintlayout:constraintlayout-compose:1.0.1'
6462
testImplementation 'junit:junit:4.13.2'
6563
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
@@ -79,17 +77,13 @@ dependencies {
7977

8078
// Retrofit
8179
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
82-
implementation "com.squareup.retrofit2:converter-simplexml:$retrofit_version"
83-
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.9.0'
80+
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
8481

8582
// Room Database
8683
implementation "androidx.room:room-runtime:$room_version"
8784
annotationProcessor "androidx.room:room-compiler:$room_version"
8885
kapt "androidx.room:room-compiler:$room_version"
8986
implementation "androidx.room:room-ktx:$room_version"
9087

91-
// Jsoup for extracting html from String
92-
implementation("org.jsoup:jsoup:$jsoup_version")
93-
9488
implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"
9589
}

app/proguard-rules.pro

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,13 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile
22+
23+
24+
-dontwarn retrofit.**
25+
-keep class retrofit.** { *; }
26+
-keepattributes Signature
27+
-keepattributes Exceptions
28+
-keepclassmembers,allowobfuscation class * {
29+
@com.google.gson.annotations.SerializedName <fields>;
30+
}

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<activity
1414
android:name=".MainActivity"
1515
android:exported="true"
16-
android:label="@string/app_name"
1716
android:theme="@style/Theme.ViennaCalling">
1817
<intent-filter>
1918
<action android:name="android.intent.action.MAIN" />

app/src/main/java/at/deflow/viennacalling/dao/EventsDao.kt

Lines changed: 68 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package at.deflow.viennacalling.dao
33
import android.util.Log
44
import androidx.room.*
55
import at.deflow.viennacalling.models.Event
6-
import at.deflow.viennacalling.models.xml.RssFeed
76
import at.deflow.viennacalling.retrofit.RetrofitInstance
87
import kotlinx.coroutines.flow.Flow
9-
import org.jsoup.Jsoup
108
import retrofit2.Call
119
import retrofit2.Callback
1210
import retrofit2.Response
11+
import java.net.URLDecoder
1312
import java.time.LocalDateTime
1413
import java.time.format.DateTimeFormatter
1514

@@ -39,12 +38,11 @@ interface EventsDao {
3938

4039
fun fetchEventRssFeed(
4140
eventList: MutableList<Event>,
42-
categoryId: String = "6",
43-
subCategory: String = ""
41+
eventListInitial: ArrayList<Event>,
4442
) {
4543

4644
// If there are no images we select random one of these stock photos)
47-
val eventImagesList = listOf(
45+
val eventImagesListDefault = listOf(
4846
"https://cdn.pixabay.com/photo/2016/11/29/06/17/audience-1867754_1280.jpg",
4947
"https://cdn.pixabay.com/photo/2015/11/22/19/04/crowd-1056764_1280.jpg",
5048
"https://cdn.pixabay.com/photo/2019/10/15/03/16/black-and-white-4550471_1280.jpg",
@@ -59,99 +57,82 @@ interface EventsDao {
5957
"https://cdn.pixabay.com/photo/2019/06/11/16/14/vienna-4267377_960_720.jpg",
6058
"https://cdn.pixabay.com/photo/2019/08/13/17/17/vienna-state-opera-4403839_960_720.jpg",
6159
"https://cdn.pixabay.com/photo/2018/12/17/14/20/vienna-3880488_960_720.jpg",
62-
6360
)
6461

65-
// here we need to create the date param for the get request with the range current to next year
66-
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy")
67-
val current = LocalDateTime.now()
68-
val nextYear =
69-
current.plusYears(1).format(formatter) // To get all events from today + 1 year
70-
val currentFormatted = current.format(formatter)
71-
72-
val retrofitInstance = RetrofitInstance.api.getEventList(
73-
layout = "rss-vadb_neu",
74-
type = "R",
75-
hmwd = "d",
76-
category = categoryId,
77-
subCategory = subCategory,
78-
startDate = currentFormatted.toString(),
79-
endDate = nextYear.toString()
80-
)
62+
val retrofitInstance = RetrofitInstance.api.getEventListAll()
8163

8264
// Here we make the actual request to our api and if we get correct data back (which is basically models.xml.* data classes)
8365
// we use it to create a new event for each item from the rss feed and then store it in our event view model
84-
retrofitInstance.enqueue(object : Callback<RssFeed?> {
85-
override fun onResponse(call: Call<RssFeed?>, response: Response<RssFeed?>) {
86-
if (response.isSuccessful) {
87-
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy")
88-
89-
// API response
90-
response.body()!!.channel?.eventList?.forEach { event ->
91-
var startDate = ""
92-
var endDate = ""
93-
94-
// because we want to use the point for our unique id for every object we manipulate it a little
95-
val pointId = event.point?.replace("[.+\\s]".toRegex(), "")
96-
97-
if (event.dtstart != null && event.dtstart!!.first() != 'T') {
98-
startDate =
99-
LocalDateTime.parse(event.dtstart?.take(19) ?: "").format(formatter)
100-
.toString()
101-
}
102-
103-
if (event.dtend != null && event.dtend!!.first() != 'T') {
104-
endDate =
105-
LocalDateTime.parse(event.dtend?.take(19) ?: "").format(formatter)
106-
.toString()
107-
}
108-
109-
// New event is created and then saved in our list which is then displayed in the home screen
110-
val newEvent = Event(
111-
id = "${
112-
event.dtstart?.replace(
113-
"+",
114-
""
115-
)
116-
}-$pointId".replace("-$".toRegex(), ""),
117-
title = event.titleList?.get(0)?.replaceFirstChar { it.uppercase() }
118-
?: "Es ist leider kein Titel vorhanden",
119-
category = event.category ?: "Es ist leider keine Kategorie vorhanden",
120-
description = event.descriptionList?.get(0)
121-
?.let { Jsoup.parse(it).text() }
122-
?: "Es ist leider keine Beschreibung vorhanden",
123-
link = event.link ?: "Es ist leider kein Link vorhanden",
124-
url = event.organizer?.url ?: "",
125-
subject = event.subject ?: "Es ist leider kein Subject vorhanden",
126-
startTime = startDate,
127-
endTime = endDate,
128-
startHour = event.startHour ?: "",
129-
startMin = event.startMin ?: "",
130-
point = event.point ?: "",
131-
streetAddress = event.location?.street_address?.replace(
132-
"/$".toRegex(),
133-
""
134-
)
135-
?.trim()
136-
?: "",
137-
plz = event.location?.postal_code ?: "",
138-
images = event.content?.url ?: eventImagesList.random()
139-
)
66+
retrofitInstance.enqueue(object : Callback<ArrayList<Event>?> {
67+
override fun onResponse(
68+
call: Call<ArrayList<Event>?>,
69+
response: Response<ArrayList<Event>?>
70+
) {
71+
72+
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy")
73+
Log.d(TAG, "HI")
74+
75+
// API response
76+
response.body()!!.forEach { event ->
77+
if(event.title == "" || (event.startTime == "" && event.description == "")) {
78+
return@forEach
79+
}
80+
var startDate = ""
81+
var endDate = ""
82+
83+
// because we want to use the point for our unique id for every object we manipulate it a little
84+
val pointId = event.point.replace("[.+\\s]".toRegex(), "")
14085

141-
eventList.add(newEvent)
86+
if (event.startTime != "" && event.startTime.first() != 'T') {
87+
startDate =
88+
LocalDateTime.parse(event.startTime.take(19)).format(formatter)
89+
.toString()
14290
}
143-
} else {
144-
Log.d(TAG, "We got no response")
91+
92+
if (event.endTime != "" && event.endTime.first() != 'T') {
93+
endDate =
94+
LocalDateTime.parse(event.endTime.take(19)).format(formatter)
95+
.toString()
96+
}
97+
98+
// New event is created and then saved in our list which is then displayed in the home screen
99+
val newEvent = Event(
100+
id = "${
101+
event.startTime.replace(
102+
"+",
103+
""
104+
)
105+
}-$pointId".replace("-$".toRegex(), ""),
106+
title = if (event.title != "") event.title else "Es ist leider kein Titel vorhanden",
107+
description = if (event.description != "") event.description else "Es ist leider keine Beschreibung vorhanden",
108+
category = event.category,
109+
link = if (event.link != "") event.link else "Es ist leider kein Link vorhanden",
110+
url = event.url,
111+
subject = event.subject,
112+
startTime = startDate,
113+
endTime = endDate,
114+
startHour = event.startHour,
115+
startMin = event.startMin,
116+
point = event.point,
117+
streetAddress = event.streetAddress,
118+
plz = event.plz,
119+
images = if (event.images != "") event.images
120+
else
121+
when (event.category) {
122+
"party" -> eventImagesListDefault.random()
123+
"sightseeing" -> eventImagesListDefault.random()
124+
"culture" -> eventImagesListDefault.random()
125+
else -> eventImagesListDefault.random()
126+
}
127+
)
128+
eventList.add(newEvent)
129+
eventListInitial.add(newEvent)
145130
}
146131
}
147132

148-
override fun onFailure(call: Call<RssFeed?>, t: Throwable) {
149-
Log.d(
150-
TAG,
151-
"We got a exception while trying to fetch the xml feed: ${t.stackTrace}"
152-
)
133+
override fun onFailure(call: Call<ArrayList<Event>?>, t: Throwable) {
134+
Log.d(TAG, "Failed to fetch data")
153135
}
154136
})
155137
}
156-
157138
}
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,46 @@
11
package at.deflow.viennacalling.models
22

3+
import androidx.compose.ui.graphics.Color
34
import androidx.room.Entity
5+
import androidx.room.Ignore
46
import androidx.room.PrimaryKey
7+
import com.google.gson.annotations.SerializedName
58

69
@Entity(tableName = "events")
710
data class Event(
11+
@SerializedName("id")
812
@PrimaryKey
913
val id: String = "",
14+
@SerializedName("title")
1015
var title: String = "",
16+
@SerializedName("description")
1117
val description: String = "",
18+
@SerializedName("category")
1219
val category: String = "",
20+
@SerializedName("link")
1321
val link: String = "",
22+
@SerializedName("url")
1423
val url: String = "",
24+
@SerializedName("days")
25+
val days: String = "",
26+
@SerializedName("subject")
1527
val subject: String = "",
28+
@SerializedName("startTime")
1629
val startTime: String = "",
30+
@SerializedName("endTime")
1731
val endTime: String = "",
32+
@SerializedName("startHour")
1833
val startHour: String = "",
34+
@SerializedName("startMin")
1935
val startMin: String = "",
36+
@SerializedName("point")
2037
val point: String = "",
38+
@SerializedName("streetAddress")
2139
val streetAddress: String = "",
40+
@SerializedName("plz")
2241
val plz: String = "",
23-
val images: String = "",
42+
@SerializedName("images")
43+
val images: String? = "",
44+
@SerializedName("uuid")
2445
var uuid: String? = "0",
2546
)

app/src/main/java/at/deflow/viennacalling/models/xml/Channel.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)