From d2f04323f918379a7b375267fdf91ccd92b1e239 Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 27 Oct 2021 23:04:14 -0400 Subject: [PATCH] Menu --- app/src/main/AndroidManifest.xml | 5 ++-- .../io/heckel/ntfy/{ => ui}/AddFragment.kt | 3 ++- .../ntfy/{detail => ui}/DetailActivity.kt | 5 +--- .../io/heckel/ntfy/{ => ui}/MainActivity.kt | 27 ++++++++++++++++--- .../ntfy/{ => ui}/SubscriptionsAdapter.kt | 6 ++--- .../ntfy/{ => ui}/SubscriptionsViewModel.kt | 2 +- app/src/main/res/menu/menu.xml | 5 ++++ app/src/main/res/values/colors.xml | 7 ++--- app/src/main/res/values/strings.xml | 6 +++++ app/src/main/res/values/styles.xml | 16 +++++------ 10 files changed, 55 insertions(+), 27 deletions(-) rename app/src/main/java/io/heckel/ntfy/{ => ui}/AddFragment.kt (98%) rename app/src/main/java/io/heckel/ntfy/{detail => ui}/DetailActivity.kt (92%) rename app/src/main/java/io/heckel/ntfy/{ => ui}/MainActivity.kt (83%) rename app/src/main/java/io/heckel/ntfy/{ => ui}/SubscriptionsAdapter.kt (93%) rename app/src/main/java/io/heckel/ntfy/{ => ui}/SubscriptionsViewModel.kt (98%) create mode 100644 app/src/main/res/menu/menu.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e43ea40..11eb72c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,13 +11,12 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + - - + diff --git a/app/src/main/java/io/heckel/ntfy/AddFragment.kt b/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt similarity index 98% rename from app/src/main/java/io/heckel/ntfy/AddFragment.kt rename to app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt index e1ecdb3..69e0022 100644 --- a/app/src/main/java/io/heckel/ntfy/AddFragment.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/AddFragment.kt @@ -1,4 +1,4 @@ -package io.heckel.ntfy +package io.heckel.ntfy.ui import android.app.AlertDialog import android.app.Dialog @@ -9,6 +9,7 @@ import android.view.View import android.widget.CheckBox import androidx.fragment.app.DialogFragment import com.google.android.material.textfield.TextInputEditText +import io.heckel.ntfy.R class AddFragment(private val listener: Listener) : DialogFragment() { interface Listener { diff --git a/app/src/main/java/io/heckel/ntfy/detail/DetailActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt similarity index 92% rename from app/src/main/java/io/heckel/ntfy/detail/DetailActivity.kt rename to app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt index e7984a3..19a9613 100644 --- a/app/src/main/java/io/heckel/ntfy/detail/DetailActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.heckel.ntfy.detail +package io.heckel.ntfy.ui import android.os.Bundle import android.widget.Button @@ -22,9 +22,6 @@ import android.widget.TextView import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import io.heckel.ntfy.R -import io.heckel.ntfy.SUBSCRIPTION_ID -import io.heckel.ntfy.SubscriptionsViewModel -import io.heckel.ntfy.SubscriptionsViewModelFactory import io.heckel.ntfy.data.topicShortUrl class DetailActivity : AppCompatActivity() { diff --git a/app/src/main/java/io/heckel/ntfy/MainActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt similarity index 83% rename from app/src/main/java/io/heckel/ntfy/MainActivity.kt rename to app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt index 7f257d3..16f5797 100644 --- a/app/src/main/java/io/heckel/ntfy/MainActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainActivity.kt @@ -1,22 +1,25 @@ -package io.heckel.ntfy +package io.heckel.ntfy.ui import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent +import android.net.Uri import android.os.Build import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import android.view.View import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.recyclerview.widget.RecyclerView +import io.heckel.ntfy.R import io.heckel.ntfy.data.Notification import io.heckel.ntfy.data.Status import io.heckel.ntfy.data.Subscription import io.heckel.ntfy.data.topicShortUrl -import io.heckel.ntfy.detail.DetailActivity import kotlin.random.Random const val SUBSCRIPTION_ID = "topic_id" @@ -43,7 +46,6 @@ class MainActivity : AppCompatActivity(), AddFragment.Listener { subscriptionViewModel.list().observe(this) { it?.let { - println("new data arrived: $it") adapter.submitList(it as MutableList) } } @@ -53,6 +55,25 @@ class MainActivity : AppCompatActivity(), AddFragment.Listener { subscriptionViewModel.setListener { n -> displayNotification(n) } } + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.menu, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + return when (item.itemId) { + R.id.menu_action_source -> { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.menu_source_url)))) + true + } + R.id.menu_action_website -> { + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.menu_website_url)))) + true + } + else -> super.onOptionsItemSelected(item) + } + } + /* Opens detail view when list item is clicked. */ private fun subscriptionOnClick(subscription: Subscription) { val intent = Intent(this, DetailActivity()::class.java) diff --git a/app/src/main/java/io/heckel/ntfy/SubscriptionsAdapter.kt b/app/src/main/java/io/heckel/ntfy/ui/SubscriptionsAdapter.kt similarity index 93% rename from app/src/main/java/io/heckel/ntfy/SubscriptionsAdapter.kt rename to app/src/main/java/io/heckel/ntfy/ui/SubscriptionsAdapter.kt index bb21d33..42ea2b2 100644 --- a/app/src/main/java/io/heckel/ntfy/SubscriptionsAdapter.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/SubscriptionsAdapter.kt @@ -1,4 +1,4 @@ -package io.heckel.ntfy +package io.heckel.ntfy.ui import android.content.Context import android.view.LayoutInflater @@ -8,6 +8,7 @@ import android.widget.TextView import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView +import io.heckel.ntfy.R import io.heckel.ntfy.data.Status import io.heckel.ntfy.data.Subscription import io.heckel.ntfy.data.topicUrl @@ -32,7 +33,6 @@ class TopicsAdapter(private val onClick: (Subscription) -> Unit) : } fun bind(subscription: Subscription) { - println("bind sub: $subscription") this.topic = subscription val statusText = when (subscription.status) { Status.CONNECTING -> context.getString(R.string.status_connecting) @@ -64,12 +64,10 @@ class TopicsAdapter(private val onClick: (Subscription) -> Unit) : object TopicDiffCallback : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: Subscription, newItem: Subscription): Boolean { - println("areItemsTheSame: $oldItem.id ==? $newItem.id") return oldItem.id == newItem.id } override fun areContentsTheSame(oldItem: Subscription, newItem: Subscription): Boolean { - println("areContentsTheSame: $oldItem ==? $newItem") return oldItem == newItem } } diff --git a/app/src/main/java/io/heckel/ntfy/SubscriptionsViewModel.kt b/app/src/main/java/io/heckel/ntfy/ui/SubscriptionsViewModel.kt similarity index 98% rename from app/src/main/java/io/heckel/ntfy/SubscriptionsViewModel.kt rename to app/src/main/java/io/heckel/ntfy/ui/SubscriptionsViewModel.kt index 34db897..44b3b6c 100644 --- a/app/src/main/java/io/heckel/ntfy/SubscriptionsViewModel.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/SubscriptionsViewModel.kt @@ -1,4 +1,4 @@ -package io.heckel.ntfy +package io.heckel.ntfy.ui import androidx.lifecycle.LiveData import androidx.lifecycle.ViewModel diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml new file mode 100644 index 0000000..c67568e --- /dev/null +++ b/app/src/main/res/menu/menu.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 7951bf5..f2a0ca9 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,6 +1,7 @@ - #3949ab - #3949ab - + #3949ab + #6f74dd + #00227b + #ffffff diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 635e518..23f73ae 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,6 +14,12 @@ fab Unsubscribe + + Show source & license + https://heckel.io/ntfy-android + Visit ntfy.sh + https://ntfy.sh + Ntfy ntfy diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 07c2c42..9809a79 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,12 +1,12 @@ - -