This commit is contained in:
Philipp Heckel 2021-10-27 23:04:14 -04:00
parent e28a80d6b6
commit d2f04323f9
10 changed files with 55 additions and 27 deletions

View file

@ -11,13 +11,12 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity android:name="io.heckel.ntfy.MainActivity"> <activity android:name="io.heckel.ntfy.ui.MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="io.heckel.ntfy.add.AddTopicActivity" /> <activity android:name="io.heckel.ntfy.ui.DetailActivity" />
<activity android:name="io.heckel.ntfy.detail.DetailActivity" />
</application> </application>
</manifest> </manifest>

View file

@ -1,4 +1,4 @@
package io.heckel.ntfy package io.heckel.ntfy.ui
import android.app.AlertDialog import android.app.AlertDialog
import android.app.Dialog import android.app.Dialog
@ -9,6 +9,7 @@ import android.view.View
import android.widget.CheckBox import android.widget.CheckBox
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputEditText
import io.heckel.ntfy.R
class AddFragment(private val listener: Listener) : DialogFragment() { class AddFragment(private val listener: Listener) : DialogFragment() {
interface Listener { interface Listener {

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package io.heckel.ntfy.detail package io.heckel.ntfy.ui
import android.os.Bundle import android.os.Bundle
import android.widget.Button import android.widget.Button
@ -22,9 +22,6 @@ import android.widget.TextView
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import io.heckel.ntfy.R 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 import io.heckel.ntfy.data.topicShortUrl
class DetailActivity : AppCompatActivity() { class DetailActivity : AppCompatActivity() {

View file

@ -1,22 +1,25 @@
package io.heckel.ntfy package io.heckel.ntfy.ui
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View import android.view.View
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.heckel.ntfy.R
import io.heckel.ntfy.data.Notification import io.heckel.ntfy.data.Notification
import io.heckel.ntfy.data.Status import io.heckel.ntfy.data.Status
import io.heckel.ntfy.data.Subscription import io.heckel.ntfy.data.Subscription
import io.heckel.ntfy.data.topicShortUrl import io.heckel.ntfy.data.topicShortUrl
import io.heckel.ntfy.detail.DetailActivity
import kotlin.random.Random import kotlin.random.Random
const val SUBSCRIPTION_ID = "topic_id" const val SUBSCRIPTION_ID = "topic_id"
@ -43,7 +46,6 @@ class MainActivity : AppCompatActivity(), AddFragment.Listener {
subscriptionViewModel.list().observe(this) { subscriptionViewModel.list().observe(this) {
it?.let { it?.let {
println("new data arrived: $it")
adapter.submitList(it as MutableList<Subscription>) adapter.submitList(it as MutableList<Subscription>)
} }
} }
@ -53,6 +55,25 @@ class MainActivity : AppCompatActivity(), AddFragment.Listener {
subscriptionViewModel.setListener { n -> displayNotification(n) } 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. */ /* Opens detail view when list item is clicked. */
private fun subscriptionOnClick(subscription: Subscription) { private fun subscriptionOnClick(subscription: Subscription) {
val intent = Intent(this, DetailActivity()::class.java) val intent = Intent(this, DetailActivity()::class.java)

View file

@ -1,4 +1,4 @@
package io.heckel.ntfy package io.heckel.ntfy.ui
import android.content.Context import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
@ -8,6 +8,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.heckel.ntfy.R
import io.heckel.ntfy.data.Status import io.heckel.ntfy.data.Status
import io.heckel.ntfy.data.Subscription import io.heckel.ntfy.data.Subscription
import io.heckel.ntfy.data.topicUrl import io.heckel.ntfy.data.topicUrl
@ -32,7 +33,6 @@ class TopicsAdapter(private val onClick: (Subscription) -> Unit) :
} }
fun bind(subscription: Subscription) { fun bind(subscription: Subscription) {
println("bind sub: $subscription")
this.topic = subscription this.topic = subscription
val statusText = when (subscription.status) { val statusText = when (subscription.status) {
Status.CONNECTING -> context.getString(R.string.status_connecting) Status.CONNECTING -> context.getString(R.string.status_connecting)
@ -64,12 +64,10 @@ class TopicsAdapter(private val onClick: (Subscription) -> Unit) :
object TopicDiffCallback : DiffUtil.ItemCallback<Subscription>() { object TopicDiffCallback : DiffUtil.ItemCallback<Subscription>() {
override fun areItemsTheSame(oldItem: Subscription, newItem: Subscription): Boolean { override fun areItemsTheSame(oldItem: Subscription, newItem: Subscription): Boolean {
println("areItemsTheSame: $oldItem.id ==? $newItem.id")
return oldItem.id == newItem.id return oldItem.id == newItem.id
} }
override fun areContentsTheSame(oldItem: Subscription, newItem: Subscription): Boolean { override fun areContentsTheSame(oldItem: Subscription, newItem: Subscription): Boolean {
println("areContentsTheSame: $oldItem ==? $newItem")
return oldItem == newItem return oldItem == newItem
} }
} }

View file

@ -1,4 +1,4 @@
package io.heckel.ntfy package io.heckel.ntfy.ui
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel

View file

@ -0,0 +1,5 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_action_source"
android:title="@string/menu_source_title"/>
<item android:title="@string/menu_website_title" android:id="@+id/menu_action_website"/>
</menu>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#3949ab</color> <color name="primaryColor">#3949ab</color>
<color name="colorPrimaryDark">#3949ab</color> <color name="primaryLightColor">#6f74dd</color>
<!--<color name="colorAccent">#03DAC5</color>--> <color name="primaryDarkColor">#00227b</color>
<color name="primaryTextColor">#ffffff</color>
</resources> </resources>

View file

@ -14,6 +14,12 @@
<string name="fab_content_description">fab</string> <string name="fab_content_description">fab</string>
<string name="remove_topic">Unsubscribe</string> <string name="remove_topic">Unsubscribe</string>
<!-- Menu -->
<string name="menu_source_title">Show source &amp; license</string>
<string name="menu_source_url">https://heckel.io/ntfy-android</string>
<string name="menu_website_title">Visit ntfy.sh</string>
<string name="menu_website_url">https://ntfy.sh</string>
<!-- Notifications --> <!-- Notifications -->
<string name="notification_channel_name">Ntfy</string> <string name="notification_channel_name">Ntfy</string>
<string name="notification_channel_id">ntfy</string> <string name="notification_channel_id">ntfy</string>

View file

@ -1,12 +1,12 @@
<resources> <resources>
<!-- Base application theme. -->
<!-- No action bar, https://stackoverflow.com/a/36236700 -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar"> <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryVariant">@color/colorPrimaryDark</item> <item name="colorPrimaryVariant">@color/primaryDarkColor</item>
<!--<item name="colorSecondary">@color/colorAccent</item>--> <item name="colorAccent">@color/primaryColor</item>
<!--<item name="windowActionBar">false</item> <!--
<item name="windowNoTitle">true</item>--> <item name="windowActionBar">false</item>
<!--<item name="android:windowFullscreen">true</item>--> <item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
-->
</style> </style>
</resources> </resources>