log of past bumps updated
- clicking on log entry shows the encrypted message behind the title - anything starting with 'http' opens in the browser
This commit is contained in:
parent
0e307c947a
commit
22b2ac96b9
3
app/.gitignore
vendored
3
app/.gitignore
vendored
@ -1 +1,2 @@
|
||||
/build
|
||||
/build
|
||||
/release
|
||||
|
@ -10,8 +10,8 @@ android {
|
||||
applicationId "com.maenle.bump"
|
||||
minSdk 26
|
||||
targetSdk 30
|
||||
versionCode 3
|
||||
versionName "0.1.1"
|
||||
versionCode 4
|
||||
versionName "0.1.2"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
@ -2,28 +2,27 @@ package com.maenle.bump.ui
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidmads.library.qrgenearator.QRGContents
|
||||
import androidmads.library.qrgenearator.QRGEncoder
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
import com.google.zxing.WriterException
|
||||
import com.maenle.bump.R
|
||||
import com.maenle.bump.databinding.FragmentFirstBinding
|
||||
import com.maenle.bump.util.*
|
||||
import com.google.zxing.WriterException
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.widget.ArrayAdapter
|
||||
import androidmads.library.qrgenearator.QRGContents
|
||||
import androidmads.library.qrgenearator.QRGEncoder
|
||||
|
||||
import com.maenle.bump.util.Display
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
|
||||
class FirstFragment : Fragment() {
|
||||
|
||||
private var _binding: FragmentFirstBinding? = null
|
||||
@ -154,10 +153,36 @@ class FirstFragment : Fragment() {
|
||||
m.get("data") as String))
|
||||
texts.add(m.get("title") as String)
|
||||
}
|
||||
val adapter = ArrayAdapter(requireContext(),
|
||||
R.layout.support_simple_spinner_dropdown_item,
|
||||
texts)
|
||||
val adapter = NotificationAdapter(requireContext(), messages)
|
||||
binding.notificationList.adapter = adapter
|
||||
binding.notificationList.setOnItemClickListener { adapterView, view, i, l ->
|
||||
run {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun subscribeTopic() {
|
||||
@ -185,4 +210,8 @@ class FirstFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
class MessageItem(var header: String, var body: String) {}
|
||||
class MessageItem(public val title: String, var encode: String) {
|
||||
public var showTitle = true
|
||||
public var header: String = title
|
||||
public var message:String? = null
|
||||
}
|
@ -68,7 +68,7 @@ class BumpProcessor constructor(context: Context) {
|
||||
}
|
||||
|
||||
private fun startUpdateHandler(context: Context) {
|
||||
val delay: Long = 10_000 //milliseconds
|
||||
val delay: Long = 60_000 //milliseconds
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
|
||||
updateFromServer(context)
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.maenle.bump.util
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.TextView
|
||||
import com.maenle.bump.R
|
||||
import com.maenle.bump.ui.MessageItem
|
||||
|
||||
|
||||
class NotificationAdapter(context: Context, messages: MutableList<MessageItem>) :
|
||||
ArrayAdapter<MessageItem?>(context, 0, messages as List<MessageItem?>) {
|
||||
val bump = BumpProcessor(context)
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
|
||||
// Get the data item for this position
|
||||
var view: View? = convertView
|
||||
val message: MessageItem? = getItem(position)
|
||||
|
||||
// Check if an existing view is being reused, otherwise inflate the view
|
||||
if (view == null) {
|
||||
view = LayoutInflater.from(context).inflate(R.layout.notification_item, parent, false)
|
||||
}
|
||||
|
||||
// Lookup view for data population
|
||||
val title = view?.findViewById(R.id.title) as TextView
|
||||
val data = view.findViewById(R.id.data) as TextView
|
||||
|
||||
// Populate the data into the template view using the data object
|
||||
if (message != null) {
|
||||
title.text = message.header
|
||||
data.text = "data"
|
||||
}
|
||||
|
||||
// Return the completed view to render on screen
|
||||
return view
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ class RestSingleton constructor(context: Context){
|
||||
val url = URL + "list/"
|
||||
val data = JSONObject()
|
||||
data.put("sender", sender)
|
||||
data.put("minutes", (60*24*2).toString())
|
||||
data.put("minutes", (60*24).toString())
|
||||
val jsonRequest = JsonObjectRequest(Request.Method.POST, url,
|
||||
data,
|
||||
{ response ->
|
||||
|
@ -1,10 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp" />
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="marquee"
|
||||
android:singleLine="true"
|
||||
android:text="title"
|
||||
android:textSize="30sp" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<TextView
|
||||
android:id="@+id/data"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/dropdownListPreferredItemHeight"
|
||||
android:text="no data"
|
||||
android:textSize="30sp"
|
||||
android:visibility="gone"
|
||||
android:ellipsize="marquee"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user