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:
parent
22b2ac96b9
commit
67fe7381aa
@ -8,9 +8,12 @@ import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.widget.AdapterView.OnItemLongClickListener
|
||||
import androidmads.library.qrgenearator.QRGContents
|
||||
import androidmads.library.qrgenearator.QRGEncoder
|
||||
import androidx.core.view.get
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
@ -145,46 +148,47 @@ class FirstFragment : Fragment() {
|
||||
|
||||
private fun updateLogCallback(log: JSONArray) {
|
||||
val messages: MutableList<MessageItem> = mutableListOf()
|
||||
val texts: MutableList<String> = mutableListOf()
|
||||
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
|
||||
messages.add(MessageItem(m.get("title") as String,
|
||||
m.get("data") as String))
|
||||
texts.add(m.get("title") as String)
|
||||
messages.add(
|
||||
MessageItem(
|
||||
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)
|
||||
binding.notificationList.adapter = adapter
|
||||
adapter.notifyDataSetChanged()
|
||||
binding.notificationList.setOnItemClickListener { adapterView, view, i, l ->
|
||||
run {
|
||||
if(messages[i].header.startsWith("http")) {
|
||||
if (messages[i].header.startsWith("http")) {
|
||||
val browserIntent =
|
||||
Intent(Intent.ACTION_VIEW, Uri.parse(messages[i].header))
|
||||
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 == "") {
|
||||
messages[i].header = "-"
|
||||
} else {
|
||||
messages[i].header = body
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
// Log.d(TAG, bump.decryptMessage(messages[i].body))
|
||||
}
|
||||
}
|
||||
binding.notificationList.setOnItemLongClickListener { adapterView, view, i, l ->
|
||||
messages[i].encrypted?.let {
|
||||
messages[i].message = bump.decryptMessage(messages[i].encrypted!!)
|
||||
}
|
||||
adapter.notifyDataSetChanged()
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun subscribeTopic() {
|
||||
FirebaseMessaging.getInstance().subscribeToTopic(TOPIC)
|
||||
.addOnCompleteListener { task ->
|
||||
@ -210,8 +214,6 @@ class FirstFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
class MessageItem(public val title: String, var encode: String) {
|
||||
public var showTitle = true
|
||||
class MessageItem(public val title: String, var message: String = "...", var encrypted: String? = null) {
|
||||
public var header: String = title
|
||||
public var message:String? = null
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.maenle.bump.util
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
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
|
||||
if (message != null) {
|
||||
title.text = message.header
|
||||
data.text = "data"
|
||||
title.text = message.title
|
||||
data.text = message.message
|
||||
if(data.text == "") {
|
||||
data.text = "-"
|
||||
}
|
||||
}
|
||||
|
||||
// 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"
|
||||
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
|
||||
android:id="@+id/textview_scan"
|
||||
android:layout_width="wrap_content"
|
||||
@ -13,6 +19,7 @@
|
||||
android:text="@string/current_sender"
|
||||
android:layout_marginTop="40dp"
|
||||
android:textSize="20sp"
|
||||
android:layout_gravity="center"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
@ -36,7 +43,8 @@
|
||||
android:id="@+id/idIVQrcode"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="300dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center"
|
||||
android:layout_gravity="center"
|
||||
android:contentDescription="@string/qr_code"
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone"
|
||||
@ -50,6 +58,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_gravity="center"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/idIVQrcode"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
@ -76,6 +85,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_gravity="center"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/buttons"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
@ -96,8 +106,11 @@
|
||||
<ListView
|
||||
android:id="@+id/notification_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="20sp"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="vertical"
|
||||
app:layout_constraintTop_toBottomOf="@id/header">
|
||||
</ListView>
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -3,24 +3,30 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/rounded_card"
|
||||
android:padding="10dp"
|
||||
android:paddingStart="20dp"
|
||||
android:layout_margin="2dp"
|
||||
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:autoLink="web"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:text="title"
|
||||
android:textSize="30sp" />
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/data"
|
||||
android:autoLink="web"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/dropdownListPreferredItemHeight"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="no data"
|
||||
android:textSize="30sp"
|
||||
android:visibility="gone"
|
||||
android:textSize="12sp"
|
||||
android:ellipsize="marquee"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -5,7 +5,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
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 '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
|
||||
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
|
||||
zipStorePath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
Loading…
Reference in New Issue
Block a user