Bug
This commit is contained in:
parent
1c6156c638
commit
c6dd0c08e6
4 changed files with 10 additions and 10 deletions
|
@ -34,7 +34,7 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="io.heckel.ntfy.add.AddTopicActivity" />
|
<activity android:name="io.heckel.ntfy.add.AddTopicActivity" />
|
||||||
<activity android:name="io.heckel.ntfy.detail.TopicDetailActivity" />
|
<activity android:name="io.heckel.ntfy.detail.DetailActivity" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -34,12 +34,11 @@ import com.google.gson.GsonBuilder
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonSyntaxException
|
import com.google.gson.JsonSyntaxException
|
||||||
import io.heckel.ntfy.add.AddTopicActivity
|
import io.heckel.ntfy.add.AddTopicActivity
|
||||||
import io.heckel.ntfy.add.TOPIC_URL
|
|
||||||
import io.heckel.ntfy.data.Topic
|
import io.heckel.ntfy.data.Topic
|
||||||
import io.heckel.ntfy.detail.TopicDetailActivity
|
import io.heckel.ntfy.detail.DetailActivity
|
||||||
import io.heckel.ntfy.list.TopicsAdapter
|
import io.heckel.ntfy.list.TopicsAdapter
|
||||||
import io.heckel.ntfy.list.TopicsViewModelFactory
|
|
||||||
import io.heckel.ntfy.list.TopicsViewModel
|
import io.heckel.ntfy.list.TopicsViewModel
|
||||||
|
import io.heckel.ntfy.list.TopicsViewModelFactory
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
|
@ -47,6 +46,7 @@ import java.net.URL
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
const val TOPIC_ID = "topic id"
|
const val TOPIC_ID = "topic id"
|
||||||
|
const val TOPIC_URL = "url"
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
private val gson = GsonBuilder().create()
|
private val gson = GsonBuilder().create()
|
||||||
|
@ -80,7 +80,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
/* Opens TopicDetailActivity when RecyclerView item is clicked. */
|
/* Opens TopicDetailActivity when RecyclerView item is clicked. */
|
||||||
private fun adapterOnClick(topic: Topic) {
|
private fun adapterOnClick(topic: Topic) {
|
||||||
val intent = Intent(this, TopicDetailActivity()::class.java)
|
val intent = Intent(this, DetailActivity()::class.java)
|
||||||
intent.putExtra(TOPIC_ID, topic.id)
|
intent.putExtra(TOPIC_ID, topic.id)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
@ -124,9 +124,10 @@ class MainActivity : AppCompatActivity() {
|
||||||
try {
|
try {
|
||||||
val input = conn.inputStream.bufferedReader()
|
val input = conn.inputStream.bufferedReader()
|
||||||
while (scope.isActive) {
|
while (scope.isActive) {
|
||||||
val line = input.readLine() ?: break // Break if null!
|
val line = input.readLine() ?: break // Exit if null
|
||||||
try {
|
try {
|
||||||
displayNotification(gson.fromJson(line, JsonObject::class.java))
|
val json = gson.fromJson(line, JsonObject::class.java) ?: break // Exit if null
|
||||||
|
displayNotification(json)
|
||||||
} catch (e: JsonSyntaxException) {
|
} catch (e: JsonSyntaxException) {
|
||||||
// Ignore invalid JSON
|
// Ignore invalid JSON
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,7 @@ import android.widget.Button
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
import io.heckel.ntfy.R
|
import io.heckel.ntfy.R
|
||||||
|
import io.heckel.ntfy.TOPIC_URL
|
||||||
const val TOPIC_URL = "url"
|
|
||||||
|
|
||||||
class AddTopicActivity : AppCompatActivity() {
|
class AddTopicActivity : AppCompatActivity() {
|
||||||
private lateinit var addTopicUrl: TextInputEditText
|
private lateinit var addTopicUrl: TextInputEditText
|
|
@ -26,7 +26,7 @@ import io.heckel.ntfy.TOPIC_ID
|
||||||
import io.heckel.ntfy.list.TopicsViewModel
|
import io.heckel.ntfy.list.TopicsViewModel
|
||||||
import io.heckel.ntfy.list.TopicsViewModelFactory
|
import io.heckel.ntfy.list.TopicsViewModelFactory
|
||||||
|
|
||||||
class TopicDetailActivity : AppCompatActivity() {
|
class DetailActivity : AppCompatActivity() {
|
||||||
private val topicDetailViewModel by viewModels<TopicsViewModel> {
|
private val topicDetailViewModel by viewModels<TopicsViewModel> {
|
||||||
TopicsViewModelFactory(this)
|
TopicsViewModelFactory(this)
|
||||||
}
|
}
|
Loading…
Reference in a new issue