list now scrollable, reformats list handling
- urls are now auto-generated from android and no longer self-handled - long-clicking a message starts decryption process, short clicking does nothing right now - only first three messages are decrypted on app load, to improve performance - fragment structure now inside a list view which makes the listview inside scrollable automatically
This commit is contained in:
@ -8,9 +8,12 @@ import android.graphics.Bitmap
|
|||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.*
|
import android.view.*
|
||||||
|
import android.widget.AdapterView.OnItemLongClickListener
|
||||||
import androidmads.library.qrgenearator.QRGContents
|
import androidmads.library.qrgenearator.QRGContents
|
||||||
import androidmads.library.qrgenearator.QRGEncoder
|
import androidmads.library.qrgenearator.QRGEncoder
|
||||||
|
import androidx.core.view.get
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
import com.google.firebase.messaging.FirebaseMessaging
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
@ -145,46 +148,47 @@ class FirstFragment : Fragment() {
|
|||||||
|
|
||||||
private fun updateLogCallback(log: JSONArray) {
|
private fun updateLogCallback(log: JSONArray) {
|
||||||
val messages: MutableList<MessageItem> = mutableListOf()
|
val messages: MutableList<MessageItem> = mutableListOf()
|
||||||
val texts: MutableList<String> = mutableListOf()
|
|
||||||
binding.nrMessages.text = log.length().toString()
|
binding.nrMessages.text = log.length().toString()
|
||||||
for(l in 0 until log.length()) {
|
var breaker = 3
|
||||||
|
if (log.length() < breaker) {
|
||||||
|
breaker = log.length()
|
||||||
|
}
|
||||||
|
for (l in log.length() - 1 downTo log.length() - breaker) {
|
||||||
val m = log[l] as JSONObject
|
val m = log[l] as JSONObject
|
||||||
messages.add(MessageItem(m.get("title") as String,
|
messages.add(
|
||||||
m.get("data") as String))
|
MessageItem(
|
||||||
texts.add(m.get("title") as String)
|
m.get("title") as String,
|
||||||
|
message = bump.decryptMessage(m.get("data") as String)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (l in log.length() - breaker downTo 0) {
|
||||||
|
val m = log[l] as JSONObject
|
||||||
|
messages.add(MessageItem(m.get("title") as String, encrypted = m.get("data") as String))
|
||||||
}
|
}
|
||||||
val adapter = NotificationAdapter(requireContext(), messages)
|
val adapter = NotificationAdapter(requireContext(), messages)
|
||||||
binding.notificationList.adapter = adapter
|
binding.notificationList.adapter = adapter
|
||||||
|
adapter.notifyDataSetChanged()
|
||||||
binding.notificationList.setOnItemClickListener { adapterView, view, i, l ->
|
binding.notificationList.setOnItemClickListener { adapterView, view, i, l ->
|
||||||
run {
|
run {
|
||||||
if(messages[i].header.startsWith("http")) {
|
if (messages[i].header.startsWith("http")) {
|
||||||
val browserIntent =
|
val browserIntent =
|
||||||
Intent(Intent.ACTION_VIEW, Uri.parse(messages[i].header))
|
Intent(Intent.ACTION_VIEW, Uri.parse(messages[i].header))
|
||||||
startActivity(browserIntent)
|
startActivity(browserIntent)
|
||||||
}
|
}
|
||||||
if(messages[i].message == null) {
|
|
||||||
messages[i].message = bump.decryptMessage(messages[i].encode)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val body:String
|
|
||||||
if(messages[i].showTitle) {
|
|
||||||
body = messages[i].message!!
|
|
||||||
messages[i].showTitle = false
|
|
||||||
} else {
|
|
||||||
body = messages[i].title
|
|
||||||
messages[i].showTitle = true
|
|
||||||
}
|
}
|
||||||
if(body == "") {
|
binding.notificationList.setOnItemLongClickListener { adapterView, view, i, l ->
|
||||||
messages[i].header = "-"
|
messages[i].encrypted?.let {
|
||||||
} else {
|
messages[i].message = bump.decryptMessage(messages[i].encrypted!!)
|
||||||
messages[i].header = body
|
|
||||||
}
|
}
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
// Log.d(TAG, bump.decryptMessage(messages[i].body))
|
true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun subscribeTopic() {
|
private fun subscribeTopic() {
|
||||||
FirebaseMessaging.getInstance().subscribeToTopic(TOPIC)
|
FirebaseMessaging.getInstance().subscribeToTopic(TOPIC)
|
||||||
.addOnCompleteListener { task ->
|
.addOnCompleteListener { task ->
|
||||||
@ -210,8 +214,6 @@ class FirstFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageItem(public val title: String, var encode: String) {
|
class MessageItem(public val title: String, var message: String = "...", var encrypted: String? = null) {
|
||||||
public var showTitle = true
|
|
||||||
public var header: String = title
|
public var header: String = title
|
||||||
public var message:String? = null
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.maenle.bump.util
|
package com.maenle.bump.util
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -31,8 +32,11 @@ class NotificationAdapter(context: Context, messages: MutableList<MessageItem>)
|
|||||||
|
|
||||||
// Populate the data into the template view using the data object
|
// Populate the data into the template view using the data object
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
title.text = message.header
|
title.text = message.title
|
||||||
data.text = "data"
|
data.text = message.message
|
||||||
|
if(data.text == "") {
|
||||||
|
data.text = "-"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the completed view to render on screen
|
// Return the completed view to render on screen
|
||||||
|
7
app/src/main/res/drawable/rounded_card.xml
Normal file
7
app/src/main/res/drawable/rounded_card.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@color/cardview_shadow_start_color"/>
|
||||||
|
<stroke android:width="3dp" android:color="@color/cardview_dark_background" />
|
||||||
|
<corners android:radius="10dp"/>
|
||||||
|
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
|
||||||
|
</shape>
|
@ -6,6 +6,12 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="com.maenle.bump.ui.FirstFragment">
|
tools:context="com.maenle.bump.ui.FirstFragment">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_marginTop="20dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textview_scan"
|
android:id="@+id/textview_scan"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -13,6 +19,7 @@
|
|||||||
android:text="@string/current_sender"
|
android:text="@string/current_sender"
|
||||||
android:layout_marginTop="40dp"
|
android:layout_marginTop="40dp"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
|
android:layout_gravity="center"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
@ -36,7 +43,8 @@
|
|||||||
android:id="@+id/idIVQrcode"
|
android:id="@+id/idIVQrcode"
|
||||||
android:layout_width="300dp"
|
android:layout_width="300dp"
|
||||||
android:layout_height="300dp"
|
android:layout_height="300dp"
|
||||||
android:layout_centerHorizontal="true"
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:contentDescription="@string/qr_code"
|
android:contentDescription="@string/qr_code"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
@ -50,6 +58,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/idIVQrcode"
|
app:layout_constraintTop_toBottomOf="@id/idIVQrcode"
|
||||||
app:layout_constraintStart_toStartOf="parent">
|
app:layout_constraintStart_toStartOf="parent">
|
||||||
@ -76,6 +85,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/buttons"
|
app:layout_constraintTop_toBottomOf="@id/buttons"
|
||||||
app:layout_constraintStart_toStartOf="parent">
|
app:layout_constraintStart_toStartOf="parent">
|
||||||
@ -96,8 +106,11 @@
|
|||||||
<ListView
|
<ListView
|
||||||
android:id="@+id/notification_list"
|
android:id="@+id/notification_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
android:layout_margin="20sp"
|
android:layout_margin="20sp"
|
||||||
android:layout_height="wrap_content"
|
android:scrollbars="vertical"
|
||||||
app:layout_constraintTop_toBottomOf="@id/header">
|
app:layout_constraintTop_toBottomOf="@id/header">
|
||||||
</ListView>
|
</ListView>
|
||||||
|
</LinearLayout>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -3,24 +3,30 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/rounded_card"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:layout_margin="2dp"
|
||||||
|
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
|
android:autoLink="web"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="marquee"
|
android:ellipsize="marquee"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:text="title"
|
android:text="title"
|
||||||
android:textSize="30sp" />
|
android:textSize="20sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/data"
|
android:id="@+id/data"
|
||||||
|
android:autoLink="web"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/dropdownListPreferredItemHeight"
|
android:layout_height="wrap_content"
|
||||||
android:text="no data"
|
android:text="no data"
|
||||||
android:textSize="30sp"
|
android:textSize="12sp"
|
||||||
android:visibility="gone"
|
|
||||||
android:ellipsize="marquee"/>
|
android:ellipsize="marquee"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -5,7 +5,7 @@ buildscript {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "com.android.tools.build:gradle:7.0.4"
|
classpath 'com.android.tools.build:gradle:7.1.0'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
|
||||||
classpath 'com.google.gms:google-services:4.3.2' // Google Services plugin
|
classpath 'com.google.gms:google-services:4.3.2' // Google Services plugin
|
||||||
|
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
#Sat Dec 11 13:26:50 CET 2021
|
#Sat Dec 11 13:26:50 CET 2021
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
Reference in New Issue
Block a user